Merge "ART: Some runtime cleanup"
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index d506cc2..257406a 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -179,7 +179,7 @@
   method_inliner_map_.reset(new DexFileToMethodInlinerMap);
   callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
                                               method_inliner_map_.get(),
-                                              false));
+                                              CompilerCallbacks::CallbackMode::kCompileApp));
   options->push_back(std::make_pair("compilercallbacks", callbacks_.get()));
 }
 
diff --git a/compiler/dex/quick_compiler_callbacks.h b/compiler/dex/quick_compiler_callbacks.h
index 56706e3..d692d26 100644
--- a/compiler/dex/quick_compiler_callbacks.h
+++ b/compiler/dex/quick_compiler_callbacks.h
@@ -28,8 +28,8 @@
   public:
     QuickCompilerCallbacks(VerificationResults* verification_results,
                            DexFileToMethodInlinerMap* method_inliner_map,
-                           bool boot_image)
-        : CompilerCallbacks(boot_image), verification_results_(verification_results),
+                           CompilerCallbacks::CallbackMode mode)
+        : CompilerCallbacks(mode), verification_results_(verification_results),
           method_inliner_map_(method_inliner_map) {
       CHECK(verification_results != nullptr);
       CHECK(method_inliner_map != nullptr);
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index d034736..df5d5cc 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -90,7 +90,7 @@
   method_inliner_map_.reset(new DexFileToMethodInlinerMap);
   callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
                                               method_inliner_map_.get(),
-                                              false));
+                                              CompilerCallbacks::CallbackMode::kCompileApp));
   compiler_driver_.reset(new CompilerDriver(
       compiler_options_.get(), verification_results_.get(), method_inliner_map_.get(),
       Compiler::kQuick, instruction_set, instruction_set_features_.get(), false,
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 440c1b6..d59ad6c 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -87,7 +87,7 @@
   method_inliner_map_.reset(new DexFileToMethodInlinerMap);
   callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
                                               method_inliner_map_.get(),
-                                              false));
+                                              CompilerCallbacks::CallbackMode::kCompileApp));
   timer_.reset(new CumulativeLogger("Compilation times"));
   compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
                                             verification_results_.get(),
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index f1cd30a..2e1b7ae 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1053,9 +1053,12 @@
     }
 
     verification_results_.reset(new VerificationResults(compiler_options_.get()));
-    callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(),
-                                                &method_inliner_map_,
-                                                image_));
+    callbacks_.reset(new QuickCompilerCallbacks(
+        verification_results_.get(),
+        &method_inliner_map_,
+        image_ ?
+            CompilerCallbacks::CallbackMode::kCompileBootImage :
+            CompilerCallbacks::CallbackMode::kCompileApp));
     runtime_options.push_back(std::make_pair("compilercallbacks", callbacks_.get()));
     runtime_options.push_back(
         std::make_pair("imageinstructionset", GetInstructionSetString(instruction_set_)));
diff --git a/runtime/compiler_callbacks.h b/runtime/compiler_callbacks.h
index 3fabe3e..b296e39 100644
--- a/runtime/compiler_callbacks.h
+++ b/runtime/compiler_callbacks.h
@@ -29,27 +29,32 @@
 }  // namespace verifier
 
 class CompilerCallbacks {
-  public:
-    virtual ~CompilerCallbacks() { }
+ public:
+  enum class CallbackMode {  // private
+    kCompileBootImage,
+    kCompileApp
+  };
 
-    virtual bool MethodVerified(verifier::MethodVerifier* verifier)
-        SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
-    virtual void ClassRejected(ClassReference ref) = 0;
+  virtual ~CompilerCallbacks() { }
 
-    // Return true if we should attempt to relocate to a random base address if we have not already
-    // done so. Return false if relocating in this way would be problematic.
-    virtual bool IsRelocationPossible() = 0;
+  virtual bool MethodVerified(verifier::MethodVerifier* verifier)
+  SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
+  virtual void ClassRejected(ClassReference ref) = 0;
 
-    bool IsBootImage() {
-      return boot_image_;
-    }
+  // Return true if we should attempt to relocate to a random base address if we have not already
+  // done so. Return false if relocating in this way would be problematic.
+  virtual bool IsRelocationPossible() = 0;
 
-  protected:
-    explicit CompilerCallbacks(bool boot_image) : boot_image_(boot_image) { }
+  bool IsBootImage() {
+    return mode_ == CallbackMode::kCompileBootImage;
+  }
 
-  private:
-    // Whether the compiler is creating a boot image.
-    const bool boot_image_;
+ protected:
+  explicit CompilerCallbacks(CallbackMode mode) : mode_(mode) { }
+
+ private:
+  // Whether the compiler is creating a boot image.
+  const CallbackMode mode_;
 };
 
 }  // namespace art
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index 566b097..9a71ba4 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -167,7 +167,7 @@
     // If so, CommonCompilerTest should have marked the runtime as a compiler not compiling an
     // image.
     CHECK(Runtime::Current()->IsAotCompiler());
-    CHECK(!Runtime::Current()->GetCompilerCallbacks()->IsBootImage());
+    CHECK(!Runtime::Current()->IsCompilingBootImage());
     return class_loader;
   }
   // Use the BOOTCLASSPATH.
diff --git a/runtime/mirror/art_field.cc b/runtime/mirror/art_field.cc
index 5d543a1..4c36753 100644
--- a/runtime/mirror/art_field.cc
+++ b/runtime/mirror/art_field.cc
@@ -45,7 +45,7 @@
 void ArtField::SetOffset(MemberOffset num_bytes) {
   DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
   if (kIsDebugBuild && Runtime::Current()->IsAotCompiler() &&
-      Runtime::Current()->GetCompilerCallbacks()->IsBootImage()) {
+      Runtime::Current()->IsCompilingBootImage()) {
     Primitive::Type type = GetTypeAsPrimitiveType();
     if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) {
       DCHECK_ALIGNED(num_bytes.Uint32Value(), 8);
diff --git a/runtime/noop_compiler_callbacks.h b/runtime/noop_compiler_callbacks.h
index a40659e..1cbf2bb 100644
--- a/runtime/noop_compiler_callbacks.h
+++ b/runtime/noop_compiler_callbacks.h
@@ -23,7 +23,7 @@
 
 class NoopCompilerCallbacks FINAL : public CompilerCallbacks {
  public:
-  NoopCompilerCallbacks() : CompilerCallbacks(false) {}
+  NoopCompilerCallbacks() : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp) {}
   ~NoopCompilerCallbacks() {}
 
   bool MethodVerified(verifier::MethodVerifier* verifier ATTRIBUTE_UNUSED) OVERRIDE {
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index ffe3dc6..c462153 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -50,9 +50,11 @@
 #include "arch/x86_64/registers_x86_64.h"
 #include "asm_support.h"
 #include "atomic.h"
+#include "base/arena_allocator.h"
 #include "base/dumpable.h"
 #include "base/unix_file/fd_file.h"
 #include "class_linker.h"
+#include "compiler_callbacks.h"
 #include "debugger.h"
 #include "elf_file.h"
 #include "entrypoints/runtime_asm_entrypoints.h"
@@ -1653,4 +1655,12 @@
   }
 }
 
+bool Runtime::CanRelocate() const {
+  return !IsAotCompiler() || compiler_callbacks_->IsRelocationPossible();
+}
+
+bool Runtime::IsCompilingBootImage() const {
+  return IsCompiler() && compiler_callbacks_->IsBootImage();
+}
+
 }  // namespace art
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 7181097..085335f 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -27,10 +27,7 @@
 #include <vector>
 
 #include "arch/instruction_set.h"
-#include "base/allocator.h"
-#include "base/arena_allocator.h"
 #include "base/macros.h"
-#include "compiler_callbacks.h"
 #include "gc_root.h"
 #include "instrumentation.h"
 #include "jobject_comparator.h"
@@ -43,6 +40,9 @@
 
 namespace art {
 
+class ArenaPool;
+class CompilerCallbacks;
+
 namespace gc {
   class Heap;
   namespace collector {
@@ -112,9 +112,10 @@
     return compiler_callbacks_ != nullptr;
   }
 
-  bool CanRelocate() const {
-    return !IsAotCompiler() || compiler_callbacks_->IsRelocationPossible();
-  }
+  // If a compiler, are we compiling a boot image?
+  bool IsCompilingBootImage() const;
+
+  bool CanRelocate() const;
 
   bool ShouldRelocate() const {
     return must_relocate_ && CanRelocate();