Fix a braino when marking a method as being compiled.
We now compile without having ProfilingInfos. Move the flag of being
compiled from the ProfilingInfo to sets in the JitCodeCache.
Test: test.py jit-at-first-use
Bug: 147207937
Change-Id: I1a372bb5534764278f5e9df674783cf918c690b3
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index cf07fe5..166beef 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -1287,6 +1287,40 @@
}
}
+void JitCodeCache::RemoveMethodBeingCompiled(ArtMethod* method, bool osr, bool baseline) {
+ DCHECK(IsMethodBeingCompiled(method, osr, baseline));
+ if (osr) {
+ current_osr_compilations_.erase(method);
+ } else if (baseline) {
+ current_baseline_compilations_.erase(method);
+ } else {
+ current_optimized_compilations_.erase(method);
+ }
+}
+
+void JitCodeCache::AddMethodBeingCompiled(ArtMethod* method, bool osr, bool baseline) {
+ DCHECK(!IsMethodBeingCompiled(method, osr, baseline));
+ if (osr) {
+ current_osr_compilations_.insert(method);
+ } else if (baseline) {
+ current_baseline_compilations_.insert(method);
+ } else {
+ current_optimized_compilations_.insert(method);
+ }
+}
+
+bool JitCodeCache::IsMethodBeingCompiled(ArtMethod* method, bool osr, bool baseline) {
+ return osr ? ContainsElement(current_osr_compilations_, method)
+ : baseline ? ContainsElement(current_baseline_compilations_, method)
+ : ContainsElement(current_optimized_compilations_, method);
+}
+
+bool JitCodeCache::IsMethodBeingCompiled(ArtMethod* method) {
+ return ContainsElement(current_optimized_compilations_, method) ||
+ ContainsElement(current_osr_compilations_, method) ||
+ ContainsElement(current_baseline_compilations_, method);
+}
+
void JitCodeCache::DoCollection(Thread* self, bool collect_profiling_info) {
ScopedTrace trace(__FUNCTION__);
{
@@ -1317,7 +1351,10 @@
// Also remove the saved entry point from the ProfilingInfo objects.
for (ProfilingInfo* info : profiling_infos_) {
const void* ptr = info->GetMethod()->GetEntryPointFromQuickCompiledCode();
- if (!ContainsPc(ptr) && !info->IsInUseByCompiler() && !IsInZygoteDataSpace(info)) {
+ if (!ContainsPc(ptr) &&
+ !IsMethodBeingCompiled(info->GetMethod()) &&
+ !info->IsInUseByCompiler() &&
+ !IsInZygoteDataSpace(info)) {
info->GetMethod()->SetProfilingInfo(nullptr);
}
@@ -1734,13 +1771,12 @@
ClearMethodCounter(method, /*was_warm=*/ false);
return false;
}
- } else {
- MutexLock mu(self, *Locks::jit_lock_);
- if (info->IsMethodBeingCompiled(osr)) {
- return false;
- }
- info->SetIsMethodBeingCompiled(true, osr);
}
+ MutexLock mu(self, *Locks::jit_lock_);
+ if (IsMethodBeingCompiled(method, osr, baseline)) {
+ return false;
+ }
+ AddMethodBeingCompiled(method, osr, baseline);
return true;
}
}
@@ -1764,7 +1800,7 @@
info->DecrementInlineUse();
}
-void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self, bool osr) {
+void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self, bool osr, bool baseline) {
DCHECK_EQ(Thread::Current(), self);
MutexLock mu(self, *Locks::jit_lock_);
if (UNLIKELY(method->IsNative())) {
@@ -1777,11 +1813,7 @@
jni_stubs_map_.erase(it); // Remove the entry added in NotifyCompilationOf().
} // else Commit() updated entrypoints of all methods in the JniStubData.
} else {
- ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
- if (info != nullptr) {
- DCHECK(info->IsMethodBeingCompiled(osr));
- info->SetIsMethodBeingCompiled(false, osr);
- }
+ RemoveMethodBeingCompiled(method, osr, baseline);
}
}