diff options
| -rw-r--r-- | runtime/jit/jit.cc | 23 | ||||
| -rw-r--r-- | runtime/jit/jit.h | 17 | ||||
| -rw-r--r-- | runtime/runtime.cc | 14 |
3 files changed, 33 insertions, 21 deletions
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 7e73e5c7f1..bfe8d9a32d 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -38,6 +38,15 @@ namespace jit { static constexpr bool kEnableOnStackReplacement = true; +// JIT compiler +void* Jit::jit_library_handle_= nullptr; +void* Jit::jit_compiler_handle_ = nullptr; +void* (*Jit::jit_load_)(bool*) = nullptr; +void (*Jit::jit_unload_)(void*) = nullptr; +bool (*Jit::jit_compile_method_)(void*, ArtMethod*, Thread*, bool) = nullptr; +void (*Jit::jit_types_loaded_)(void*, mirror::Class**, size_t count) = nullptr; +bool Jit::generate_debug_info_ = false; + JitOptions* JitOptions::CreateFromRuntimeArguments(const RuntimeArgumentMap& options) { auto* jit_options = new JitOptions; jit_options->use_jit_ = options.GetOrDefault(RuntimeArgumentMap::UseJIT); @@ -91,22 +100,16 @@ void Jit::AddTimingLogger(const TimingLogger& logger) { cumulative_timings_.AddLogger(logger); } -Jit::Jit() : jit_library_handle_(nullptr), - jit_compiler_handle_(nullptr), - jit_load_(nullptr), - jit_compile_method_(nullptr), - dump_info_on_shutdown_(false), +Jit::Jit() : dump_info_on_shutdown_(false), cumulative_timings_("JIT timings"), memory_use_("Memory used for compilation", 16), lock_("JIT memory use lock"), - save_profiling_info_(false), - generate_debug_info_(false) { -} + save_profiling_info_(false) {} Jit* Jit::Create(JitOptions* options, std::string* error_msg) { std::unique_ptr<Jit> jit(new Jit); jit->dump_info_on_shutdown_ = options->DumpJitInfoOnShutdown(); - if (!jit->LoadCompiler(error_msg)) { + if (jit_compiler_handle_ == nullptr && !LoadCompiler(error_msg)) { return nullptr; } jit->code_cache_.reset(JitCodeCache::Create( @@ -247,9 +250,11 @@ Jit::~Jit() { DeleteThreadPool(); if (jit_compiler_handle_ != nullptr) { jit_unload_(jit_compiler_handle_); + jit_compiler_handle_ = nullptr; } if (jit_library_handle_ != nullptr) { dlclose(jit_library_handle_); + jit_library_handle_ = nullptr; } } diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h index 37d0bdb129..b98c6d39c0 100644 --- a/runtime/jit/jit.h +++ b/runtime/jit/jit.h @@ -112,17 +112,18 @@ class Jit { JValue* result) SHARED_REQUIRES(Locks::mutator_lock_); + static bool LoadCompiler(std::string* error_msg); + private: Jit(); - bool LoadCompiler(std::string* error_msg); // JIT compiler - void* jit_library_handle_; - void* jit_compiler_handle_; - void* (*jit_load_)(bool*); - void (*jit_unload_)(void*); - bool (*jit_compile_method_)(void*, ArtMethod*, Thread*, bool); - void (*jit_types_loaded_)(void*, mirror::Class**, size_t count); + static void* jit_library_handle_; + static void* jit_compiler_handle_; + static void* (*jit_load_)(bool*); + static void (*jit_unload_)(void*); + static bool (*jit_compile_method_)(void*, ArtMethod*, Thread*, bool); + static void (*jit_types_loaded_)(void*, mirror::Class**, size_t count); // Performance monitoring. bool dump_info_on_shutdown_; @@ -134,7 +135,7 @@ class Jit { std::unique_ptr<jit::JitCodeCache> code_cache_; bool save_profiling_info_; - bool generate_debug_info_; + static bool generate_debug_info_; DISALLOW_COPY_AND_ASSIGN(Jit); }; diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 96f41b3d62..a9ff0880a2 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -567,10 +567,16 @@ bool Runtime::Start() { } } - // If we are the zygote then we need to wait until after forking to create the code cache - // due to SELinux restrictions on r/w/x memory regions. - if (!IsZygote() && jit_options_->UseJIT()) { - CreateJit(); + if (jit_options_->UseJIT()) { + std::string error_msg; + if (!IsZygote()) { + // If we are the zygote then we need to wait until after forking to create the code cache + // due to SELinux restrictions on r/w/x memory regions. + CreateJit(); + } else if (!jit::Jit::LoadCompiler(&error_msg)) { + // Try to load compiler pre zygote to reduce PSS. b/27744947 + LOG(WARNING) << "Failed to load JIT compiler with error " << error_msg; + } } if (!IsImageDex2OatEnabled() || !GetHeap()->HasBootImageSpace()) { |