Add the compiler filter to InMemoryDexClassLoader backed by oat files.
OatHeader::GetCompilerFilter requires it.
Bug: 143155012
Bug: 150856296
Test: 692-vdex-inmem-loader
Change-Id: I96c3aa38361e01b7f109d91a0f5c634f7dae0278
(cherry picked from commit dee09f90d1b445c3a133c392a0afc03c62d75ef1)
diff --git a/test/692-vdex-inmem-loader/src/Main.java b/test/692-vdex-inmem-loader/src/Main.java
index 53f4c36..3ebe2c1 100644
--- a/test/692-vdex-inmem-loader/src/Main.java
+++ b/test/692-vdex-inmem-loader/src/Main.java
@@ -57,6 +57,13 @@
if (invokeMethod) {
loader.loadClass("art.ClassB").getDeclaredMethod("printHello").invoke(null);
+
+ if (expectedBackedByOat) {
+ String filter = getCompilerFilter(loader.loadClass("art.ClassB"));
+ if (!("verify".equals(filter))) {
+ throw new Error("Expected verify, got " + filter);
+ }
+ }
}
}
@@ -118,6 +125,7 @@
private static native boolean hasVdexFile(ClassLoader loader);
private static native boolean isBackedByOatFile(ClassLoader loader);
private static native boolean areClassesPreverified(ClassLoader loader);
+ private static native String getCompilerFilter(Class cls);
// Defined in 674-hiddenapi.
private static native void appendToBootClassLoader(String dexPath, boolean isCorePlatform);
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index a0b2f1e..ba2d46e 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -66,6 +66,24 @@
return (oat_dex_file != nullptr) ? JNI_TRUE : JNI_FALSE;
}
+extern "C" JNIEXPORT jobject JNICALL Java_Main_getCompilerFilter(JNIEnv* env,
+ jclass caller ATTRIBUTE_UNUSED,
+ jclass cls) {
+ ScopedObjectAccess soa(env);
+
+ ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(cls);
+ const DexFile& dex_file = klass->GetDexFile();
+ const OatDexFile* oat_dex_file = dex_file.GetOatDexFile();
+ if (oat_dex_file == nullptr) {
+ return nullptr;
+ }
+
+ std::string filter =
+ CompilerFilter::NameOfFilter(oat_dex_file->GetOatFile()->GetCompilerFilter());
+ return soa.AddLocalReference<jobject>(
+ mirror::String::AllocFromModifiedUtf8(soa.Self(), filter.c_str()));
+}
+
// public static native boolean runtimeIsSoftFail();
extern "C" JNIEXPORT jboolean JNICALL Java_Main_runtimeIsSoftFail(JNIEnv* env ATTRIBUTE_UNUSED,