Fix memory leak in JIT cache
When adding code to the JIT cache it is possible for CHA assumptions
to be invalidated and for the generated code to be invalid. The path
for handling this should release the JIT cache memory holding the
code.
Test: for i in {1..100} ; do art/test.py --host --jit -r -t 044 ; done
Change-Id: Ia6213647064a3db0c4d11bf1181c325375282528
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 2edf770..d90bdcb 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -792,8 +792,11 @@
}
// Discard the code if any single-implementation assumptions are now invalid.
- if (!single_impl_still_valid) {
+ if (UNLIKELY(!single_impl_still_valid)) {
VLOG(jit) << "JIT discarded jitted code due to invalid single-implementation assumptions.";
+ ScopedCodeCacheWrite ccw(*region);
+ uintptr_t allocation = FromCodeToAllocation(code_ptr);
+ region->FreeCode(reinterpret_cast<uint8_t*>(allocation));
return nullptr;
}
DCHECK(cha_single_implementation_list.empty() || !Runtime::Current()->IsJavaDebuggable())