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.