Reland "Change hotness counting."
This reverts commit ce131feb7c60ffdf28c315c5d67f9cac33a077ce.
Bug: 203810169
Test: test.py
Test: health/microbench/startup/hscapps/compile-speed-profile/open-clock
Reason for revert: Kept logic from before on what methods to save in the
profile.
Change-Id: Id67cd47a9fe31b4c6b154db20f632015238016d2
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 9d9a7d3..e05ca11 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -615,12 +615,10 @@
if (was_warm) {
method->SetPreviouslyWarm();
}
- // We reset the counter to 1 so that the profile knows that the method was executed at least once.
+ method->ResetCounter();
+ // We add one sample 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));
+ method->UpdateCounter(/* new_samples= */ 1);
}
void JitCodeCache::WaitForPotentialCollectionToCompleteRunnable(Thread* self) {
@@ -794,7 +792,7 @@
return false;
}
- method->SetCounter(0);
+ ClearMethodCounter(method, /* was_warm= */ false);
Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
method, GetQuickToInterpreterBridge());
VLOG(jit)
@@ -1168,14 +1166,13 @@
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.
- method->SetCounter(new_counter);
+ // Make sure a single invocation of the GenericJNI trampoline tries to recompile.
+ method->SetHotCounter();
method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());
}
}
@@ -1300,6 +1297,7 @@
OatQuickMethodHeader* method_header =
OatQuickMethodHeader::FromEntryPoint(entry_point);
if (CodeInfo::IsBaseline(method_header->GetOptimizedCodeInfoPtr())) {
+ info->GetMethod()->ResetCounter();
info->GetMethod()->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
}
}
@@ -1489,7 +1487,6 @@
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();
@@ -1501,10 +1498,13 @@
}
std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches;
- // If the method didn't reach the compilation threshold don't save the inline caches.
+ // If the method is still baseline compiled, 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.
- if (method->GetCounter() < jit_compile_threshold) {
+ const void* entry_point = method->GetEntryPointFromQuickCompiledCode();
+ if (ContainsPc(entry_point) &&
+ CodeInfo::IsBaseline(
+ OatQuickMethodHeader::FromEntryPoint(entry_point)->GetOptimizedCodeInfoPtr())) {
methods.emplace_back(/*ProfileMethodInfo*/
MethodReference(dex_file, method->GetDexMethodIndex()), inline_caches);
continue;