Fix races in small mode compiler filters setup

Fixes host tests in small art mode.

Change-Id: I2579f872583f425607f91c1e58df68b05b5098bb
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index ac2c1a9..25cfda6 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -851,7 +851,6 @@
   options.push_back(std::make_pair("-sea_ir", reinterpret_cast<void*>(NULL)));
 #endif
 
-
   Dex2Oat* p_dex2oat;
   if (!Dex2Oat::Create(&p_dex2oat, options, compiler_backend, instruction_set, thread_count)) {
     LOG(ERROR) << "Failed to create dex2oat";
@@ -861,6 +860,11 @@
   // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
   // give it away now and then switch to a more managable ScopedObjectAccess.
   Thread::Current()->TransitionFromRunnableToSuspended(kNative);
+  // If we're doing the image, override the compiler filter to force full compilation. Must be
+  // done ahead of WellKnownClasses::Init that causes verification.
+  if (image && Runtime::Current()->GetCompilerFilter() == Runtime::kInterpretOnly) {
+    Runtime::Current()->SetCompilerFilter(Runtime::kSpeed);
+  }
   // Whilst we're in native take the opportunity to initialize well known classes.
   WellKnownClasses::Init(Thread::Current()->GetJniEnv());
   ScopedObjectAccess soa(Thread::Current());
@@ -905,11 +909,6 @@
     }
   }
 
-  // If we're doing the image, override the compiler filter to force full compilation.
-  if (image && Runtime::Current()->GetCompilerFilter() == Runtime::kInterpretOnly) {
-    Runtime::Current()->SetCompilerFilter(Runtime::kSpeed);
-  }
-
   /*
    * If we're not in interpret-only mode, go ahead and compile small applications. Don't
    * bother to check if we're doing the image.
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 1e21736..bd36a6c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -70,10 +70,6 @@
 
 namespace art {
 
-extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
-                                           const DexFile::CodeItem* code_item,
-                                           ShadowFrame* shadow_frame, JValue* result);
-
 static void ThrowNoClassDefFoundError(const char* fmt, ...)
     __attribute__((__format__(__printf__, 1, 2)))
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
diff --git a/runtime/common_test.h b/runtime/common_test.h
index ced2af9..e2dda86 100644
--- a/runtime/common_test.h
+++ b/runtime/common_test.h
@@ -35,6 +35,7 @@
 #include "gc/heap.h"
 #include "gtest/gtest.h"
 #include "instruction_set.h"
+#include "interpreter/interpreter.h"
 #include "mirror/class_loader.h"
 #include "oat_file.h"
 #include "object_utils.h"
@@ -192,7 +193,6 @@
       compiled_method =
           compiler_driver_->GetCompiledMethod(MethodReference(&dex_file,
                                                               method->GetDexMethodIndex()));
-      CHECK(compiled_method != NULL) << PrettyMethod(method);
     }
     if (compiled_method != NULL) {
       const std::vector<uint8_t>& code = compiled_method->GetCode();
@@ -208,6 +208,7 @@
                                                       &compiled_method->GetVmapTable()[0],
                                                       NULL);
       oat_method.LinkMethod(method);
+      method->SetEntryPointFromInterpreter(artInterpreterToCompiledCodeBridge);
     } else {
       const void* method_code;
       // No code? You must mean to go into the interpreter.
@@ -221,6 +222,7 @@
                                                       NULL,
                                                       NULL);
       oat_method.LinkMethod(method);
+      method->SetEntryPointFromInterpreter(interpreter::artInterpreterToInterpreterBridge);
     }
   }
 
diff --git a/runtime/entrypoints/interpreter/interpreter_entrypoints.cc b/runtime/entrypoints/interpreter/interpreter_entrypoints.cc
index f319a00..ecf98bc 100644
--- a/runtime/entrypoints/interpreter/interpreter_entrypoints.cc
+++ b/runtime/entrypoints/interpreter/interpreter_entrypoints.cc
@@ -27,8 +27,7 @@
 
 extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
                                                    const DexFile::CodeItem* code_item,
-                                                   ShadowFrame* shadow_frame, JValue* result)
-    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+                                                   ShadowFrame* shadow_frame, JValue* result) {
   mirror::ArtMethod* method = shadow_frame->GetMethod();
   // Ensure static methods are initialized.
   if (method->IsStatic()) {
diff --git a/runtime/interpreter/interpreter.h b/runtime/interpreter/interpreter.h
index 49e8de0..efe11fc 100644
--- a/runtime/interpreter/interpreter.h
+++ b/runtime/interpreter/interpreter.h
@@ -53,6 +53,12 @@
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
 }  // namespace interpreter
+
+extern "C" void artInterpreterToCompiledCodeBridge(Thread* self, MethodHelper& mh,
+                                                   const DexFile::CodeItem* code_item,
+                                                   ShadowFrame* shadow_frame, JValue* result)
+    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
 }  // namespace art
 
 #endif  // ART_RUNTIME_INTERPRETER_INTERPRETER_H_
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index cc0559d..dcc9f90 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -4095,13 +4095,10 @@
   DCHECK(Runtime::Current()->IsCompiler());
   ReaderMutexLock mu(Thread::Current(), *dex_gc_maps_lock_);
   DexGcMapTable::const_iterator it = dex_gc_maps_->find(ref);
-  if (it == dex_gc_maps_->end()) {
-    LOG(WARNING) << "Didn't find GC map for: " << PrettyMethod(ref.dex_method_index, *ref.dex_file);
-    return NULL;
-  } else {
-    CHECK(it->second != NULL);
-    return it->second;
-  }
+  CHECK(it != dex_gc_maps_->end())
+    << "Didn't find GC map for: " << PrettyMethod(ref.dex_method_index, *ref.dex_file);
+  CHECK(it->second != NULL);
+  return it->second;
 }
 
 void  MethodVerifier::SetDevirtMap(MethodReference ref,