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/runtime/oat_file.cc b/runtime/oat_file.cc
index 05015e3..54dae10 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -1425,13 +1425,17 @@
     // SetVdex will take ownership of the VdexFile.
     SetVdex(vdex_file.release());
 
-    // Create a dummy OatHeader.
+    // Create a dummy OatHeader with a key store containing only the compiler
+    // filter (it helps debugging and is required by
+    // OatHeader::GetCompilerFilter).
     std::unique_ptr<const InstructionSetFeatures> isa_features =
         InstructionSetFeatures::FromCppDefines();
+    SafeMap<std::string, std::string> store;
+    store.Put(OatHeader::kCompilerFilter, CompilerFilter::NameOfFilter(CompilerFilter::kVerify));
     oat_header_.reset(OatHeader::Create(kRuntimeISA,
                                         isa_features.get(),
                                         dex_files.size(),
-                                        nullptr));
+                                        &store));
     const uint8_t* begin = reinterpret_cast<const uint8_t*>(oat_header_.get());
     SetBegin(begin);
     SetEnd(begin + oat_header_->GetHeaderSize());
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,