diff options
author | Andreas Gampe <agampe@google.com> | 2015-03-27 23:45:15 -0700 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2015-03-27 23:46:09 -0700 |
commit | 4585f876eb5dfb936bd0d6cb6acd78a1f2182ba6 (patch) | |
tree | e9dfed086f56245e74862caa813c708bc4f500f9 | |
parent | e2c29f4a2717923f190c944a06e02f7d8c3ddcb6 (diff) | |
download | android_art-4585f876eb5dfb936bd0d6cb6acd78a1f2182ba6.tar.gz android_art-4585f876eb5dfb936bd0d6cb6acd78a1f2182ba6.tar.bz2 android_art-4585f876eb5dfb936bd0d6cb6acd78a1f2182ba6.zip |
ART: Some runtime cleanup
Use an enum for the compiler-callback mode.
Refactor and remove some unnecessary includes in runtime.h.
Change-Id: If2245fa470171311b8e05b677cf6bb28f209585a
-rw-r--r-- | compiler/common_compiler_test.cc | 2 | ||||
-rw-r--r-- | compiler/dex/quick_compiler_callbacks.h | 4 | ||||
-rw-r--r-- | compiler/jit/jit_compiler.cc | 2 | ||||
-rw-r--r-- | compiler/oat_test.cc | 2 | ||||
-rw-r--r-- | dex2oat/dex2oat.cc | 9 | ||||
-rw-r--r-- | runtime/compiler_callbacks.h | 37 | ||||
-rw-r--r-- | runtime/jni_internal.cc | 2 | ||||
-rw-r--r-- | runtime/mirror/art_field.cc | 2 | ||||
-rw-r--r-- | runtime/noop_compiler_callbacks.h | 2 | ||||
-rw-r--r-- | runtime/runtime.cc | 10 | ||||
-rw-r--r-- | runtime/runtime.h | 13 |
11 files changed, 52 insertions, 33 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc index d506cc21e9..257406a622 100644 --- a/compiler/common_compiler_test.cc +++ b/compiler/common_compiler_test.cc @@ -179,7 +179,7 @@ void CommonCompilerTest::SetUpRuntimeOptions(RuntimeOptions* options) { 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 56706e3e35..d692d26229 100644 --- a/compiler/dex/quick_compiler_callbacks.h +++ b/compiler/dex/quick_compiler_callbacks.h @@ -28,8 +28,8 @@ class QuickCompilerCallbacks FINAL : public CompilerCallbacks { 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 d034736f95..df5d5cca3b 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -90,7 +90,7 @@ JitCompiler::JitCompiler() : total_time_(0) { 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 440c1b634c..d59ad6c32f 100644 --- a/compiler/oat_test.cc +++ b/compiler/oat_test.cc @@ -87,7 +87,7 @@ TEST_F(OatTest, WriteRead) { 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 f1cd30a4f7..2e1b7aef04 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1053,9 +1053,12 @@ class Dex2Oat FINAL { } 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 3fabe3ed44..b296e39c5e 100644 --- a/runtime/compiler_callbacks.h +++ b/runtime/compiler_callbacks.h @@ -29,27 +29,32 @@ class MethodVerifier; } // 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 566b097a6e..9a71ba4ca7 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -167,7 +167,7 @@ static mirror::ClassLoader* GetClassLoader(const ScopedObjectAccess& soa) // 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 5d543a178c..4c36753724 100644 --- a/runtime/mirror/art_field.cc +++ b/runtime/mirror/art_field.cc @@ -45,7 +45,7 @@ void ArtField::ResetClass() { 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 a40659e66c..1cbf2bbda4 100644 --- a/runtime/noop_compiler_callbacks.h +++ b/runtime/noop_compiler_callbacks.h @@ -23,7 +23,7 @@ namespace art { 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 ffe3dc6fc9..c462153ed3 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 @@ void Runtime::CreateJit() { } } +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 7181097563..085335fd3c 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 @@ class Runtime { 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(); |