Don't update the compiler filter when using a runtime image.
Before this change, the runtime reports the compiler filter being
"speed-profile" when using a runtime image. This was originally for
reporting the app startup metric under a unique pair of dimension
values (speed-profile, vdex).
However, it turns out that the code that reports the app startup metric
doesn't get the compiler filter from the runtime. Besides, the compiler
filter change can have surprising side-effects. For example, when an app
gets its own optimization status from the Java API
`ApplicationRuntime.getBaseApkOptimizationInfo()`, it may find itself
being in (speed-profile, install) even though its baseline profile is
not used during app install.
Bug: 260557058
Change-Id: I46eb5015f2a382f5363b2bfab15be8c6a86a2f73
Test: Presubmit
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index fcfda96..bd31651 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -338,13 +338,6 @@
for (const auto& dex_file : dex_files) {
dex::tracking::RegisterDexFile(dex_file.get());
}
-
- if (!compilation_enabled) {
- // Update the filter we are going to report to 'speed-profile'.
- // Ideally, we would also update the compiler filter of the odex
- // file, but at this point it's just too late.
- compilation_filter = CompilerFilter::NameOfFilter(CompilerFilter::kSpeedProfile);
- }
} else {
LOG(INFO) << "Failed to add image file: " << temp_error_msg;
dex_files.clear();
diff --git a/test/845-data-image/src-art/Main.java b/test/845-data-image/src-art/Main.java
index 36cc9d0..eb217d8 100644
--- a/test/845-data-image/src-art/Main.java
+++ b/test/845-data-image/src-art/Main.java
@@ -162,7 +162,7 @@
if (args.length == 2 && "--second-run".equals(args[1])) {
DexFile.OptimizationInfo info = VMRuntime.getBaseApkOptimizationInfo();
- if (!info.isOptimized()) {
+ if (!info.isOptimized() && !isInImageSpace(Main.class)) {
throw new Error("Expected image to be loaded");
}
}
@@ -336,6 +336,7 @@
private static native boolean hasOatFile();
private static native boolean hasImage();
private static native String getCompilerFilter(Class<?> cls);
+ private static native boolean isInImageSpace(Class<?> cls);
private static final String TEMP_FILE_NAME_PREFIX = "temp";
private static final String TEMP_FILE_NAME_SUFFIX = "-file";
diff --git a/test/846-multidex-data-image/src-art/Main.java b/test/846-multidex-data-image/src-art/Main.java
index aea92a4..8e425d1 100644
--- a/test/846-multidex-data-image/src-art/Main.java
+++ b/test/846-multidex-data-image/src-art/Main.java
@@ -48,7 +48,7 @@
if (args.length == 2 && "--second-run".equals(args[1])) {
DexFile.OptimizationInfo info = VMRuntime.getBaseApkOptimizationInfo();
- if (!info.isOptimized()) {
+ if (!info.isOptimized() && !isInImageSpace(Main.class)) {
throw new Error("Expected image to be loaded");
}
}
@@ -77,6 +77,7 @@
private static native boolean hasOatFile();
private static native boolean hasImage();
private static native String getCompilerFilter(Class<?> cls);
+ private static native boolean isInImageSpace(Class<?> cls);
private static final String TEMP_FILE_NAME_PREFIX = "temp";
private static final String TEMP_FILE_NAME_SUFFIX = "-file";
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index 517eeae..635feff 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-#include "jni.h"
-
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <sys/resource.h>
@@ -25,10 +23,12 @@
#include "base/enums.h"
#include "common_throws.h"
#include "dex/dex_file-inl.h"
+#include "gc/heap.h"
#include "instrumentation.h"
#include "jit/jit.h"
#include "jit/jit_code_cache.h"
#include "jit/profiling_info.h"
+#include "jni.h"
#include "jni/jni_internal.h"
#include "mirror/class-inl.h"
#include "mirror/class.h"
@@ -469,4 +469,18 @@
setrlimit(RLIMIT_NOFILE, &limit);
}
+extern "C" JNIEXPORT jboolean JNICALL Java_Main_isInImageSpace(JNIEnv* env,
+ [[maybe_unused]] jclass caller,
+ jclass cls) {
+ ScopedObjectAccess soa(env);
+
+ ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
+ gc::space::Space* space =
+ Runtime::Current()->GetHeap()->FindSpaceFromObject(klass, /*fail_ok=*/true);
+ if (space == nullptr) {
+ return JNI_FALSE;
+ }
+ return space->IsImageSpace() ? JNI_TRUE : JNI_FALSE;
+}
+
} // namespace art