Fix thread race when fetching the ProfilingInfo object.
Problem is:
1) Compiler fetches the ProfilingInfo of A, it's null.
2) Mutator creates the ProfilingInfo.
3) Compiler notifies it's not using A anymore, calls
ProfilingInfo::DecrementInlineUse -> Crash as we expected
ProfilingInfo::IncrementUse to be called before.
Also update some namings to better reflect what is going on.
Change-Id: I55ea4c5d81988131467095e18a0d13a8be9d0ef7
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 050bb68..af47da6 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -928,20 +928,20 @@
return true;
}
-void JitCodeCache::NotifyInliningOf(ArtMethod* method, Thread* self) {
+ProfilingInfo* JitCodeCache::NotifyCompilerUse(ArtMethod* method, Thread* self) {
MutexLock mu(self, lock_);
ProfilingInfo* info = method->GetProfilingInfo(sizeof(void*));
if (info != nullptr) {
info->IncrementInlineUse();
}
+ return info;
}
-void JitCodeCache::DoneInlining(ArtMethod* method, Thread* self) {
+void JitCodeCache::DoneCompilerUse(ArtMethod* method, Thread* self) {
MutexLock mu(self, lock_);
ProfilingInfo* info = method->GetProfilingInfo(sizeof(void*));
- if (info != nullptr) {
- info->DecrementInlineUse();
- }
+ DCHECK(info != nullptr);
+ info->DecrementInlineUse();
}
void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED) {
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index 113bebf..98dd70d 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -71,7 +71,11 @@
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
- void NotifyInliningOf(ArtMethod* method, Thread* self)
+ // Notify to the code cache that the compiler wants to use the
+ // profiling info of `method` to drive optimizations,
+ // and therefore ensure the returned profiling info object is not
+ // collected.
+ ProfilingInfo* NotifyCompilerUse(ArtMethod* method, Thread* self)
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
@@ -79,7 +83,7 @@
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
- void DoneInlining(ArtMethod* method, Thread* self)
+ void DoneCompilerUse(ArtMethod* method, Thread* self)
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
diff --git a/runtime/jit/profiling_info.h b/runtime/jit/profiling_info.h
index 73c1a1e..55d627a 100644
--- a/runtime/jit/profiling_info.h
+++ b/runtime/jit/profiling_info.h
@@ -56,10 +56,11 @@
mirror::Class* GetMonomorphicType() const SHARED_REQUIRES(Locks::mutator_lock_) {
// Note that we cannot ensure the inline cache is actually monomorphic
// at this point, as other threads may have updated it.
+ DCHECK(!classes_[0].IsNull());
return classes_[0].Read();
}
- bool IsUnitialized() const {
+ bool IsUninitialized() const {
return classes_[0].IsNull();
}