Introduce an enum for the compilation kind.
Test: test.py
Change-Id: I5329e50a6b4521933b6b171c8c0fbc618c3f67cd
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 166beef..4ea61c6 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -663,10 +663,10 @@
ArrayRef<const uint8_t> stack_map,
const std::vector<uint8_t>& debug_info,
bool is_full_debug_info,
- bool osr,
+ CompilationKind compilation_kind,
bool has_should_deoptimize_flag,
const ArenaSet<ArtMethod*>& cha_single_implementation_list) {
- DCHECK(!method->IsNative() || !osr);
+ DCHECK(!method->IsNative() || (compilation_kind != CompilationKind::kOsr));
if (!method->IsNative()) {
// We need to do this before grabbing the lock_ because it needs to be able to see the string
@@ -749,7 +749,7 @@
} else {
method_code_map_.Put(code_ptr, method);
}
- if (osr) {
+ if (compilation_kind == CompilationKind::kOsr) {
number_of_osr_compilations_++;
osr_code_map_.Put(method, code_ptr);
} else if (NeedsClinitCheckBeforeCall(method) &&
@@ -773,7 +773,7 @@
GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(code_ptr));
}
VLOG(jit)
- << "JIT added (osr=" << std::boolalpha << osr << std::noboolalpha << ") "
+ << "JIT added (kind=" << compilation_kind << ") "
<< ArtMethod::PrettyMethod(method) << "@" << method
<< " ccache_size=" << PrettySize(CodeCacheSizeLocked()) << ": "
<< " dcache_size=" << PrettySize(DataCacheSizeLocked()) << ": "
@@ -1287,32 +1287,45 @@
}
}
-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::RemoveMethodBeingCompiled(ArtMethod* method, CompilationKind kind) {
+ DCHECK(IsMethodBeingCompiled(method, kind));
+ switch (kind) {
+ case CompilationKind::kOsr:
+ current_osr_compilations_.erase(method);
+ break;
+ case CompilationKind::kBaseline:
+ current_baseline_compilations_.erase(method);
+ break;
+ case CompilationKind::kOptimized:
+ current_optimized_compilations_.erase(method);
+ break;
}
}
-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);
+void JitCodeCache::AddMethodBeingCompiled(ArtMethod* method, CompilationKind kind) {
+ DCHECK(!IsMethodBeingCompiled(method, kind));
+ switch (kind) {
+ case CompilationKind::kOsr:
+ current_osr_compilations_.insert(method);
+ break;
+ case CompilationKind::kBaseline:
+ current_baseline_compilations_.insert(method);
+ break;
+ case CompilationKind::kOptimized:
+ current_optimized_compilations_.insert(method);
+ break;
}
}
-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, CompilationKind kind) {
+ switch (kind) {
+ case CompilationKind::kOsr:
+ return ContainsElement(current_osr_compilations_, method);
+ case CompilationKind::kBaseline:
+ return ContainsElement(current_baseline_compilations_, method);
+ case CompilationKind::kOptimized:
+ return ContainsElement(current_optimized_compilations_, method);
+ }
}
bool JitCodeCache::IsMethodBeingCompiled(ArtMethod* method) {
@@ -1679,19 +1692,19 @@
bool JitCodeCache::NotifyCompilationOf(ArtMethod* method,
Thread* self,
- bool osr,
+ CompilationKind compilation_kind,
bool prejit,
- bool baseline,
JitMemoryRegion* region) {
const void* existing_entry_point = method->GetEntryPointFromQuickCompiledCode();
- if (!osr && ContainsPc(existing_entry_point)) {
+ if (compilation_kind != CompilationKind::kOsr && ContainsPc(existing_entry_point)) {
OatQuickMethodHeader* method_header =
OatQuickMethodHeader::FromEntryPoint(existing_entry_point);
- if (CodeInfo::IsBaseline(method_header->GetOptimizedCodeInfoPtr()) == baseline) {
+ bool is_baseline = (compilation_kind == CompilationKind::kBaseline);
+ if (CodeInfo::IsBaseline(method_header->GetOptimizedCodeInfoPtr()) == is_baseline) {
VLOG(jit) << "Not compiling "
<< method->PrettyMethod()
<< " because it has already been compiled"
- << " baseline=" << std::boolalpha << baseline;
+ << " kind=" << compilation_kind;
return false;
}
}
@@ -1719,7 +1732,7 @@
}
}
- if (osr) {
+ if (compilation_kind == CompilationKind::kOsr) {
MutexLock mu(self, *Locks::jit_lock_);
if (osr_code_map_.find(method) != osr_code_map_.end()) {
return false;
@@ -1756,7 +1769,9 @@
return new_compilation;
} else {
ProfilingInfo* info = method->GetProfilingInfo(kRuntimePointerSize);
- if (CanAllocateProfilingInfo() && baseline && info == nullptr) {
+ if (CanAllocateProfilingInfo() &&
+ (compilation_kind == CompilationKind::kBaseline) &&
+ (info == nullptr)) {
// We can retry allocation here as we're the JIT thread.
if (ProfilingInfo::Create(self, method, /* retry_allocation= */ true)) {
info = method->GetProfilingInfo(kRuntimePointerSize);
@@ -1773,10 +1788,10 @@
}
}
MutexLock mu(self, *Locks::jit_lock_);
- if (IsMethodBeingCompiled(method, osr, baseline)) {
+ if (IsMethodBeingCompiled(method, compilation_kind)) {
return false;
}
- AddMethodBeingCompiled(method, osr, baseline);
+ AddMethodBeingCompiled(method, compilation_kind);
return true;
}
}
@@ -1800,7 +1815,9 @@
info->DecrementInlineUse();
}
-void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self, bool osr, bool baseline) {
+void JitCodeCache::DoneCompiling(ArtMethod* method,
+ Thread* self,
+ CompilationKind compilation_kind) {
DCHECK_EQ(Thread::Current(), self);
MutexLock mu(self, *Locks::jit_lock_);
if (UNLIKELY(method->IsNative())) {
@@ -1813,7 +1830,7 @@
jni_stubs_map_.erase(it); // Remove the entry added in NotifyCompilationOf().
} // else Commit() updated entrypoints of all methods in the JniStubData.
} else {
- RemoveMethodBeingCompiled(method, osr, baseline);
+ RemoveMethodBeingCompiled(method, compilation_kind);
}
}