ART: Add Runtime::IsSafeMode
Ensure that the safe mode can only be checked in non-zygote
processes.
Bug: 119063276
Test: m test-art-host
Test: device boots
Change-Id: Ibe5bf113c042dfb572c8a94ab17406cb8933ee62
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index e577266..3dfa0c4 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -786,7 +786,7 @@
// TODO(calin): We use the JIT class as a proxy for JIT compilation and for
// recoding profiles. Maybe we should consider changing the name to be more clear it's
// not only about compiling. b/28295073.
- if (!safe_mode_ && (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo())) {
+ if (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo()) {
// Try to load compiler pre zygote to reduce PSS. b/27744947
std::string error_msg;
if (!jit::Jit::LoadCompilerLibrary(&error_msg)) {
@@ -2490,7 +2490,7 @@
DCHECK(!jit_options_->UseJitCompilation());
}
- if (safe_mode_ || (!jit_options_->UseJitCompilation() && !jit_options_->GetSaveProfilingInfo())) {
+ if (!jit_options_->UseJitCompilation() && !jit_options_->GetSaveProfilingInfo()) {
return;
}
@@ -2511,7 +2511,16 @@
}
void Runtime::CreateJit() {
+ DCHECK(jit_ == nullptr);
if (jit_code_cache_.get() == nullptr) {
+ if (!IsSafeMode()) {
+ LOG(WARNING) << "Missing code cache, cannot create JIT.";
+ }
+ return;
+ }
+ if (IsSafeMode()) {
+ LOG(INFO) << "Not creating JIT because of SafeMode.";
+ jit_code_cache_.reset();
return;
}
@@ -2520,7 +2529,7 @@
if (jit == nullptr) {
LOG(WARNING) << "Failed to allocate JIT";
// Release JIT code cache resources (several MB of memory).
- jit_code_cache_.reset(nullptr);
+ jit_code_cache_.reset();
}
}
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 4bc16e2..ad4d3bb 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -713,6 +713,11 @@
double GetHashTableMinLoadFactor() const;
double GetHashTableMaxLoadFactor() const;
+ bool IsSafeMode() const {
+ CHECK(!is_zygote_);
+ return safe_mode_;
+ }
+
void SetSafeMode(bool mode) {
safe_mode_ = mode;
}