Fix JIT creation so it picks up runtime flags.
bug: 119063276
Test: benchmarks, take a bugreport, check that JIT is enabled.
Test: atest ZenModeFilteringTest with libartd and JIT at first use.
Change-Id: Id9f0be316467064dc21edfb0a0493149678630e0
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index e876a1b..d67d9dc 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -60,7 +60,6 @@
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;
struct StressModeHelper {
DECLARE_RUNTIME_DEBUG_FLAG(kSlowMode);
@@ -176,11 +175,24 @@
lock_("JIT memory use lock") {}
Jit* Jit::Create(JitCodeCache* code_cache, JitOptions* options) {
- CHECK(jit_compiler_handle_ != nullptr) << "Jit::LoadLibrary() needs to be called first";
- std::unique_ptr<Jit> jit(new Jit(code_cache, options));
- if (jit_compiler_handle_ == nullptr) {
+ if (jit_load_ == nullptr) {
+ LOG(WARNING) << "Not creating JIT: library not loaded";
return nullptr;
}
+ bool will_generate_debug_symbols = false;
+ jit_compiler_handle_ = (jit_load_)(&will_generate_debug_symbols);
+ if (jit_compiler_handle_ == nullptr) {
+ LOG(WARNING) << "Not creating JIT: failed to allocate a compiler";
+ return nullptr;
+ }
+ std::unique_ptr<Jit> jit(new Jit(code_cache, options));
+ jit->generate_debug_info_ = will_generate_debug_symbols;
+
+ // With 'perf', we want a 1-1 mapping between an address and a method.
+ // We aren't able to keep method pointers live during the instrumentation method entry trampoline
+ // so we will just disable jit-gc if we are doing that.
+ code_cache->SetGarbageCollectCode(!jit->generate_debug_info_ &&
+ !Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled());
VLOG(jit) << "JIT created with initial_capacity="
<< PrettySize(options->GetCodeCacheInitialCapacity())
@@ -195,7 +207,7 @@
return jit.release();
}
-bool Jit::BindCompilerMethods(std::string* error_msg) {
+bool Jit::LoadCompilerLibrary(std::string* error_msg) {
jit_library_handle_ = dlopen(
kIsDebugBuild ? "libartd-compiler.so" : "libart-compiler.so", RTLD_NOW);
if (jit_library_handle_ == nullptr) {
@@ -234,23 +246,6 @@
return true;
}
-bool Jit::LoadCompiler(std::string* error_msg) {
- if (jit_library_handle_ == nullptr && !BindCompilerMethods(error_msg)) {
- return false;
- }
- bool will_generate_debug_symbols = false;
- VLOG(jit) << "Calling JitLoad interpreter_only="
- << Runtime::Current()->GetInstrumentation()->InterpretOnly();
- jit_compiler_handle_ = (jit_load_)(&will_generate_debug_symbols);
- if (jit_compiler_handle_ == nullptr) {
- dlclose(jit_library_handle_);
- *error_msg = "JIT couldn't load compiler";
- return false;
- }
- generate_debug_info_ = will_generate_debug_symbols;
- return true;
-}
-
bool Jit::CompileMethod(ArtMethod* method, Thread* self, bool osr) {
DCHECK(Runtime::Current()->UseJitCompilation());
DCHECK(!method->IsRuntimeMethod());
@@ -300,11 +295,6 @@
return success;
}
-bool Jit::ShouldGenerateDebugInfo() {
- CHECK(CompilerIsLoaded());
- return generate_debug_info_;
-}
-
void Jit::CreateThreadPool() {
// There is a DCHECK in the 'AddSamples' method to ensure the tread pool
// is not null when we instrument.
@@ -385,7 +375,7 @@
return;
}
jit::Jit* jit = Runtime::Current()->GetJit();
- if (generate_debug_info_) {
+ if (jit->generate_debug_info_) {
DCHECK(jit->jit_types_loaded_ != nullptr);
jit->jit_types_loaded_(jit->jit_compiler_handle_, &type, 1);
}