Revert "Change hotness counting."
This reverts commit c86869ab894c05e3181e7d15eb1893fa8a3fcd47.
Reason for revert: App startup performance regression.
Bug: 203810169
Change-Id: Ie816969fffd7740fcdfa330aeb645399f5351865
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 7545829..9d9a7d3 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -615,7 +615,12 @@
if (was_warm) {
method->SetPreviouslyWarm();
}
- method->ResetCounter();
+ // We reset the counter to 1 so that the profile knows that the method was executed at least once.
+ // This is required for layout purposes.
+ // We also need to make sure we'll pass the warmup threshold again, so we set to 0 if
+ // the warmup threshold is 1.
+ uint16_t jit_warmup_threshold = Runtime::Current()->GetJITOptions()->GetWarmupThreshold();
+ method->SetCounter(std::min(jit_warmup_threshold - 1, 1));
}
void JitCodeCache::WaitForPotentialCollectionToCompleteRunnable(Thread* self) {
@@ -789,7 +794,7 @@
return false;
}
- ClearMethodCounter(method, /* was_warm= */ false);
+ method->SetCounter(0);
Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
method, GetQuickToInterpreterBridge());
VLOG(jit)
@@ -1163,13 +1168,14 @@
if (!data.IsCompiled() || IsInZygoteExecSpace(data.GetCode())) {
continue;
}
+ // Make sure a single invocation of the GenericJNI trampoline tries to recompile.
+ uint16_t new_counter = Runtime::Current()->GetJit()->HotMethodThreshold() - 1u;
const OatQuickMethodHeader* method_header =
OatQuickMethodHeader::FromCodePointer(data.GetCode());
for (ArtMethod* method : data.GetMethods()) {
if (method->GetEntryPointFromQuickCompiledCode() == method_header->GetEntryPoint()) {
// Don't call Instrumentation::UpdateMethodsCode(), same as for normal methods above.
- // Make sure a single invocation of the GenericJNI trampoline tries to recompile.
- method->SetHotCounter();
+ method->SetCounter(new_counter);
method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());
}
}
@@ -1294,7 +1300,6 @@
OatQuickMethodHeader* method_header =
OatQuickMethodHeader::FromEntryPoint(entry_point);
if (CodeInfo::IsBaseline(method_header->GetOptimizedCodeInfoPtr())) {
- info->GetMethod()->ResetCounter();
info->GetMethod()->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
}
}
@@ -1484,6 +1489,7 @@
WaitUntilInlineCacheAccessible(self);
MutexLock mu(self, *Locks::jit_lock_);
ScopedTrace trace(__FUNCTION__);
+ uint16_t jit_compile_threshold = Runtime::Current()->GetJITOptions()->GetCompileThreshold();
for (auto it : profiling_infos_) {
ProfilingInfo* info = it.second;
ArtMethod* method = info->GetMethod();
@@ -1495,13 +1501,10 @@
}
std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches;
- // If the method is still baseline compiled, don't save the inline caches.
+ // If the method didn't reach the compilation threshold don't save the inline caches.
// They might be incomplete and cause unnecessary deoptimizations.
// If the inline cache is empty the compiler will generate a regular invoke virtual/interface.
- const void* entry_point = method->GetEntryPointFromQuickCompiledCode();
- if (ContainsPc(entry_point) &&
- CodeInfo::IsBaseline(
- OatQuickMethodHeader::FromEntryPoint(entry_point)->GetOptimizedCodeInfoPtr())) {
+ if (method->GetCounter() < jit_compile_threshold) {
methods.emplace_back(/*ProfileMethodInfo*/
MethodReference(dex_file, method->GetDexMethodIndex()), inline_caches);
continue;