summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/jit/jit_code_cache.h10
-rw-r--r--test/common/runtime_state.cc3
2 files changed, 11 insertions, 2 deletions
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index 33a792fe75..c970979eaa 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -229,6 +229,12 @@ class JitCodeCache {
void MoveObsoleteMethod(ArtMethod* old_method, ArtMethod* new_method)
REQUIRES(!lock_) REQUIRES(Locks::mutator_lock_);
+ // Dynamically change whether we want to garbage collect code. Should only be used
+ // by tests.
+ void SetGarbageCollectCode(bool value) {
+ garbage_collect_code_ = value;
+ }
+
private:
// Take ownership of maps.
JitCodeCache(MemMap* code_map,
@@ -359,8 +365,8 @@ class JitCodeCache {
// It is atomic to avoid locking when reading it.
Atomic<uint64_t> last_update_time_ns_;
- // Whether we can do garbage collection.
- const bool garbage_collect_code_;
+ // Whether we can do garbage collection. Not 'const' as tests may override this.
+ bool garbage_collect_code_;
// The size in bytes of used memory for the data portion of the code cache.
size_t used_memory_for_data_ GUARDED_BY(lock_);
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index a841f9e6a2..c7a57cefb6 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -180,6 +180,9 @@ extern "C" JNIEXPORT void JNICALL Java_Main_ensureJitCompiled(JNIEnv* env,
}
jit::JitCodeCache* code_cache = jit->GetCodeCache();
+ // Update the code cache to make sure the JIT code does not get deleted.
+ // Note: this will apply to all JIT compilations.
+ code_cache->SetGarbageCollectCode(false);
while (true) {
const void* pc = method->GetEntryPointFromQuickCompiledCode();
if (code_cache->ContainsPc(pc)) {