summaryrefslogtreecommitdiff
path: root/runtime/jit/jit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/jit/jit.cc')
-rw-r--r--runtime/jit/jit.cc105
1 files changed, 67 insertions, 38 deletions
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 846ca4d795..bb421e6b20 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -1472,7 +1472,7 @@ uint32_t Jit::CompileMethodsFromProfile(
}
bool Jit::IgnoreSamplesForMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
- if (method->IsClassInitializer() || !method->IsCompilable()) {
+ if (method->IsClassInitializer() || !method->IsCompilable() || method->IsPreCompiled()) {
// We do not want to compile such methods.
return true;
}
@@ -1492,6 +1492,64 @@ bool Jit::IgnoreSamplesForMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutat
return false;
}
+bool Jit::MaybeCompileMethod(Thread* self,
+ ArtMethod* method,
+ uint32_t old_count,
+ uint32_t new_count,
+ bool with_backedges) {
+ if (thread_pool_ == nullptr) {
+ return false;
+ }
+ if (UNLIKELY(method->IsPreCompiled()) && !with_backedges /* don't check for OSR */) {
+ if (!NeedsClinitCheckBeforeCall(method) ||
+ method->GetDeclaringClass()->IsVisiblyInitialized()) {
+ const void* entry_point = code_cache_->GetSavedEntryPointOfPreCompiledMethod(method);
+ if (entry_point != nullptr) {
+ Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(method, entry_point);
+ return true;
+ }
+ }
+ }
+
+ if (IgnoreSamplesForMethod(method)) {
+ return false;
+ }
+ if (HotMethodThreshold() == 0) {
+ // Tests might request JIT on first use (compiled synchronously in the interpreter).
+ return false;
+ }
+ DCHECK_GT(WarmMethodThreshold(), 0);
+ DCHECK_GT(HotMethodThreshold(), WarmMethodThreshold());
+ DCHECK_GT(OSRMethodThreshold(), HotMethodThreshold());
+ DCHECK_GE(PriorityThreadWeight(), 1);
+ DCHECK_LE(PriorityThreadWeight(), HotMethodThreshold());
+
+ if (UseJitCompilation()) {
+ if (old_count < HotMethodThreshold() && new_count >= HotMethodThreshold()) {
+ if (!code_cache_->ContainsPc(method->GetEntryPointFromQuickCompiledCode())) {
+ DCHECK(thread_pool_ != nullptr);
+ thread_pool_->AddTask(
+ self,
+ new JitCompileTask(
+ method, JitCompileTask::TaskKind::kCompile, CompilationKind::kBaseline));
+ }
+ }
+ if (old_count < OSRMethodThreshold() && new_count >= OSRMethodThreshold()) {
+ if (!with_backedges) {
+ return false;
+ }
+ DCHECK(!method->IsNative()); // No back edges reported for native methods.
+ if (!code_cache_->IsOsrCompiled(method)) {
+ DCHECK(thread_pool_ != nullptr);
+ thread_pool_->AddTask(
+ self,
+ new JitCompileTask(method, JitCompileTask::TaskKind::kCompile, CompilationKind::kOsr));
+ }
+ }
+ }
+ return true;
+}
+
void Jit::EnqueueOptimizedCompilation(ArtMethod* method, Thread* self) {
if (thread_pool_ == nullptr) {
return;
@@ -1540,7 +1598,7 @@ void Jit::MethodEntered(Thread* thread, ArtMethod* method) {
return;
}
- AddSamples(thread, method);
+ AddSamples(thread, method, 1, /* with_backedges= */false);
}
void Jit::WaitForCompilationToFinish(Thread* self) {
@@ -1734,48 +1792,19 @@ bool Jit::CanAssumeInitialized(ObjPtr<mirror::Class> cls, bool is_for_shared_reg
}
}
-void Jit::EnqueueCompilation(ArtMethod* method, Thread* self) {
+void Jit::EnqueueCompilationFromNterp(ArtMethod* method, Thread* self) {
if (thread_pool_ == nullptr) {
return;
}
-
- if (JitAtFirstUse()) {
- // Tests might request JIT on first use (compiled synchronously in the interpreter).
- return;
- }
-
- if (!UseJitCompilation()) {
- return;
- }
-
if (GetCodeCache()->ContainsPc(method->GetEntryPointFromQuickCompiledCode())) {
- if (!method->IsNative() && !code_cache_->IsOsrCompiled(method)) {
- // If we already have compiled code for it, nterp may be stuck in a loop.
- // Compile OSR.
- thread_pool_->AddTask(
- self,
- new JitCompileTask(method, JitCompileTask::TaskKind::kCompile, CompilationKind::kOsr));
- }
- return;
- }
-
- // Check if we have precompiled this method.
- if (UNLIKELY(method->IsPreCompiled())) {
- if (!NeedsClinitCheckBeforeCall(method) ||
- method->GetDeclaringClass()->IsVisiblyInitialized()) {
- const void* entry_point = code_cache_->GetSavedEntryPointOfPreCompiledMethod(method);
- if (entry_point != nullptr) {
- Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(method, entry_point);
- }
- }
- return;
- }
-
- if (IgnoreSamplesForMethod(method)) {
+ // If we already have compiled code for it, nterp may be stuck in a loop.
+ // Compile OSR.
+ thread_pool_->AddTask(
+ self,
+ new JitCompileTask(method, JitCompileTask::TaskKind::kCompile, CompilationKind::kOsr));
return;
}
-
- if (!method->IsNative() && GetCodeCache()->CanAllocateProfilingInfo()) {
+ if (GetCodeCache()->CanAllocateProfilingInfo()) {
thread_pool_->AddTask(
self,
new JitCompileTask(method, JitCompileTask::TaskKind::kCompile, CompilationKind::kBaseline));