From 2535abe7d1fcdd0e6aca782b1f1932a703ed50a4 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Tue, 17 Feb 2015 10:38:49 -0800 Subject: Add JIT Currently disabled by default unless -Xjit is passed in. The proposed JIT is a method JIT which works by utilizing interpreter instrumentation to request compilation of hot methods async during runtime. JIT options: -Xjit / -Xnojit -Xjitcodecachesize:N -Xjitthreshold:integervalue The JIT has a shared copy of a compiler driver which is accessed by worker threads to compile individual methods. Added JIT code cache and data cache, currently sized at 2 MB capacity by default. Most apps will only fill a small fraction of this cache however. Added support to the compiler for compiling interpreter quickened byte codes. Added test target ART_TEST_JIT=TRUE and --jit for run-test. TODO: Clean up code cache. Delete compiled methods after they are added to code cache. Add more optimizations related to runtime checks e.g. direct pointers for invokes. Add method recompilation. Move instrumentation to DexFile to improve performance and reduce memory usage. Bug: 17950037 Change-Id: Ifa5b2684a2d5059ec5a5210733900aafa3c51bca --- runtime/runtime.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'runtime/runtime.h') diff --git a/runtime/runtime.h b/runtime/runtime.h index fb9ca401ac..3b6df51369 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -48,6 +48,12 @@ namespace gc { class GarbageCollector; } // namespace collector } // namespace gc + +namespace jit { + class Jit; + class JitOptions; +} // namespace jit + namespace mirror { class ArtMethod; class ClassLoader; @@ -95,12 +101,18 @@ class Runtime { static bool Create(const RuntimeOptions& options, bool ignore_unrecognized) SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); + // IsAotCompiler for compilers that don't have a running runtime. Only dex2oat currently. + bool IsAotCompiler() const { + return !UseJit() && IsCompiler(); + } + + // IsCompiler is any runtime which has a running compiler, either dex2oat or JIT. bool IsCompiler() const { return compiler_callbacks_ != nullptr; } bool CanRelocate() const { - return !IsCompiler() || compiler_callbacks_->IsRelocationPossible(); + return !IsAotCompiler() || compiler_callbacks_->IsRelocationPossible(); } bool ShouldRelocate() const { @@ -339,9 +351,7 @@ class Runtime { return !imt_conflict_method_.IsNull(); } - void SetImtConflictMethod(mirror::ArtMethod* method) { - imt_conflict_method_ = GcRoot(method); - } + void SetImtConflictMethod(mirror::ArtMethod* method); void SetImtUnimplementedMethod(mirror::ArtMethod* method) { imt_unimplemented_method_ = GcRoot(method); } @@ -421,6 +431,14 @@ class Runtime { kUnload, kInitialize }; + + jit::Jit* GetJit() { + return jit_.get(); + } + bool UseJit() const { + return jit_.get() != nullptr; + } + void PreZygoteFork(); bool InitZygote(); void DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const char* isa); @@ -521,6 +539,8 @@ class Runtime { return zygote_max_failed_boots_; } + void CreateJit(); + private: static void InitPlatformSignalHandlers(); @@ -600,6 +620,9 @@ class Runtime { JavaVMExt* java_vm_; + std::unique_ptr jit_; + std::unique_ptr jit_options_; + // Fault message, printed when we get a SIGSEGV. Mutex fault_message_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; std::string fault_message_ GUARDED_BY(fault_message_lock_); -- cgit v1.2.3