ART: Pass current Thread* to Jit::ShouldUsePriorityThreadWeight().
And avoid some instructions from REFRESH_IBASE on x86-64.
Test: testrunner.py --host --interpreter --jit
Test: testrunner.py --target --interpreter --jit on Nexus 6P
Change-Id: Id42545d0d8fb8db0659b6c937ed7e8106d1dcfdb
diff --git a/runtime/interpreter/mterp/arm/entry.S b/runtime/interpreter/mterp/arm/entry.S
index e53c054..ce14b54 100644
--- a/runtime/interpreter/mterp/arm/entry.S
+++ b/runtime/interpreter/mterp/arm/entry.S
@@ -67,6 +67,7 @@
/* Set up for backwards branches & osr profiling */
ldr r0, [rFP, #OFF_FP_METHOD]
add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rSELF
bl MterpSetUpHotnessCountdown
mov rPROFILE, r0 @ Starting hotness countdown to rPROFILE
diff --git a/runtime/interpreter/mterp/arm64/entry.S b/runtime/interpreter/mterp/arm64/entry.S
index 441c1a1..73c5a88 100644
--- a/runtime/interpreter/mterp/arm64/entry.S
+++ b/runtime/interpreter/mterp/arm64/entry.S
@@ -60,6 +60,7 @@
/* Set up for backwards branches & osr profiling */
ldr x0, [xFP, #OFF_FP_METHOD]
add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xSELF
bl MterpSetUpHotnessCountdown
mov wPROFILE, w0 // Starting hotness countdown to xPROFILE
diff --git a/runtime/interpreter/mterp/mips/entry.S b/runtime/interpreter/mterp/mips/entry.S
index c806a67..f617a4d 100644
--- a/runtime/interpreter/mterp/mips/entry.S
+++ b/runtime/interpreter/mterp/mips/entry.S
@@ -63,7 +63,8 @@
/* Set up for backwards branches & osr profiling */
lw a0, OFF_FP_METHOD(rFP)
addu a1, rFP, OFF_FP_SHADOWFRAME
- JAL(MterpSetUpHotnessCountdown) # (method, shadow_frame)
+ move a2, rSELF
+ JAL(MterpSetUpHotnessCountdown) # (method, shadow_frame, self)
move rPROFILE, v0 # Starting hotness countdown to rPROFILE
/* start executing the instruction at rPC */
diff --git a/runtime/interpreter/mterp/mips64/entry.S b/runtime/interpreter/mterp/mips64/entry.S
index cc48d45..5536966 100644
--- a/runtime/interpreter/mterp/mips64/entry.S
+++ b/runtime/interpreter/mterp/mips64/entry.S
@@ -82,6 +82,7 @@
/* Set up for backwards branches & osr profiling */
ld a0, OFF_FP_METHOD(rFP)
daddu a1, rFP, OFF_FP_SHADOWFRAME
+ move a2, rSELF
jal MterpSetUpHotnessCountdown
move rPROFILE, v0 # Starting hotness countdown to rPROFILE
diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc
index b8a7a2a..6c24753 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -888,7 +888,9 @@
* to the full instrumentation via MterpAddHotnessBatch. Called once on entry to the method,
* and regenerated following batch updates.
*/
-extern "C" ssize_t MterpSetUpHotnessCountdown(ArtMethod* method, ShadowFrame* shadow_frame)
+extern "C" ssize_t MterpSetUpHotnessCountdown(ArtMethod* method,
+ ShadowFrame* shadow_frame,
+ Thread* self)
REQUIRES_SHARED(Locks::mutator_lock_) {
uint16_t hotness_count = method->GetCounter();
int32_t countdown_value = jit::kJitHotnessDisabled;
@@ -906,7 +908,7 @@
} else {
countdown_value = jit::kJitCheckForOSR;
}
- if (jit::Jit::ShouldUsePriorityThreadWeight()) {
+ if (jit::Jit::ShouldUsePriorityThreadWeight(self)) {
int32_t priority_thread_weight = jit->PriorityThreadWeight();
countdown_value = std::min(countdown_value, countdown_value / priority_thread_weight);
}
@@ -935,7 +937,7 @@
int16_t count = shadow_frame->GetCachedHotnessCountdown() - shadow_frame->GetHotnessCountdown();
jit->AddSamples(self, method, count, /*with_backedges*/ true);
}
- return MterpSetUpHotnessCountdown(method, shadow_frame);
+ return MterpSetUpHotnessCountdown(method, shadow_frame, self);
}
extern "C" size_t MterpMaybeDoOnStackReplacement(Thread* self,
diff --git a/runtime/interpreter/mterp/out/mterp_arm.S b/runtime/interpreter/mterp/out/mterp_arm.S
index e2b693f..d6a27b8 100644
--- a/runtime/interpreter/mterp/out/mterp_arm.S
+++ b/runtime/interpreter/mterp/out/mterp_arm.S
@@ -386,6 +386,7 @@
/* Set up for backwards branches & osr profiling */
ldr r0, [rFP, #OFF_FP_METHOD]
add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rSELF
bl MterpSetUpHotnessCountdown
mov rPROFILE, r0 @ Starting hotness countdown to rPROFILE
diff --git a/runtime/interpreter/mterp/out/mterp_arm64.S b/runtime/interpreter/mterp/out/mterp_arm64.S
index ef5a4da..3d05996 100644
--- a/runtime/interpreter/mterp/out/mterp_arm64.S
+++ b/runtime/interpreter/mterp/out/mterp_arm64.S
@@ -401,6 +401,7 @@
/* Set up for backwards branches & osr profiling */
ldr x0, [xFP, #OFF_FP_METHOD]
add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xSELF
bl MterpSetUpHotnessCountdown
mov wPROFILE, w0 // Starting hotness countdown to xPROFILE
diff --git a/runtime/interpreter/mterp/out/mterp_mips.S b/runtime/interpreter/mterp/out/mterp_mips.S
index 6362897..144c8e5 100644
--- a/runtime/interpreter/mterp/out/mterp_mips.S
+++ b/runtime/interpreter/mterp/out/mterp_mips.S
@@ -797,7 +797,8 @@
/* Set up for backwards branches & osr profiling */
lw a0, OFF_FP_METHOD(rFP)
addu a1, rFP, OFF_FP_SHADOWFRAME
- JAL(MterpSetUpHotnessCountdown) # (method, shadow_frame)
+ move a2, rSELF
+ JAL(MterpSetUpHotnessCountdown) # (method, shadow_frame, self)
move rPROFILE, v0 # Starting hotness countdown to rPROFILE
/* start executing the instruction at rPC */
diff --git a/runtime/interpreter/mterp/out/mterp_mips64.S b/runtime/interpreter/mterp/out/mterp_mips64.S
index bc0d90c..28f1887 100644
--- a/runtime/interpreter/mterp/out/mterp_mips64.S
+++ b/runtime/interpreter/mterp/out/mterp_mips64.S
@@ -383,6 +383,7 @@
/* Set up for backwards branches & osr profiling */
ld a0, OFF_FP_METHOD(rFP)
daddu a1, rFP, OFF_FP_SHADOWFRAME
+ move a2, rSELF
jal MterpSetUpHotnessCountdown
move rPROFILE, v0 # Starting hotness countdown to rPROFILE
@@ -3764,7 +3765,6 @@
GOTO_OPCODE v0 # jump to next instruction
-
/* ------------------------------ */
.balign 128
.L_op_float_to_double: /* 0x89 */
diff --git a/runtime/interpreter/mterp/out/mterp_x86.S b/runtime/interpreter/mterp/out/mterp_x86.S
index 21d9671..169501d 100644
--- a/runtime/interpreter/mterp/out/mterp_x86.S
+++ b/runtime/interpreter/mterp/out/mterp_x86.S
@@ -387,6 +387,8 @@
movl %eax, OUT_ARG0(%esp)
leal OFF_FP_SHADOWFRAME(rFP), %ecx
movl %ecx, OUT_ARG1(%esp)
+ movl rSELF, %eax
+ movl %eax, OUT_ARG2(%esp)
call SYMBOL(MterpSetUpHotnessCountdown)
/* Starting ibase */
diff --git a/runtime/interpreter/mterp/out/mterp_x86_64.S b/runtime/interpreter/mterp/out/mterp_x86_64.S
index b5a5ae5..b643072 100644
--- a/runtime/interpreter/mterp/out/mterp_x86_64.S
+++ b/runtime/interpreter/mterp/out/mterp_x86_64.S
@@ -198,9 +198,12 @@
* restore it in such cases also.
*
*/
+.macro REFRESH_IBASE_REG self_reg
+ movq THREAD_CURRENT_IBASE_OFFSET(\self_reg), rIBASE
+.endm
.macro REFRESH_IBASE
movq rSELF, rIBASE
- movq THREAD_CURRENT_IBASE_OFFSET(rIBASE), rIBASE
+ REFRESH_IBASE_REG rIBASE
.endm
/*
@@ -364,9 +367,10 @@
/* Starting ibase */
movq IN_ARG0, rSELF
- REFRESH_IBASE
+ REFRESH_IBASE_REG IN_ARG0
/* Set up for backwards branches & osr profiling */
+ movq IN_ARG0, OUT_ARG2 /* Set up OUT_ARG2 before clobbering IN_ARG0 */
movq OFF_FP_METHOD(rFP), OUT_ARG0
leaq OFF_FP_SHADOWFRAME(rFP), OUT_ARG1
call SYMBOL(MterpSetUpHotnessCountdown)
@@ -11908,7 +11912,7 @@
.L_resume_backward_branch:
movq rSELF, %rax
testl $(THREAD_SUSPEND_OR_CHECKPOINT_REQUEST), THREAD_FLAGS_OFFSET(%rax)
- REFRESH_IBASE
+ REFRESH_IBASE_REG %rax
leaq (rPC, rINSTq, 2), rPC
FETCH_INST
jnz .L_suspend_request_pending
diff --git a/runtime/interpreter/mterp/x86/entry.S b/runtime/interpreter/mterp/x86/entry.S
index 384dd9a..34adf53 100644
--- a/runtime/interpreter/mterp/x86/entry.S
+++ b/runtime/interpreter/mterp/x86/entry.S
@@ -69,6 +69,8 @@
movl %eax, OUT_ARG0(%esp)
leal OFF_FP_SHADOWFRAME(rFP), %ecx
movl %ecx, OUT_ARG1(%esp)
+ movl rSELF, %eax
+ movl %eax, OUT_ARG2(%esp)
call SYMBOL(MterpSetUpHotnessCountdown)
/* Starting ibase */
diff --git a/runtime/interpreter/mterp/x86_64/entry.S b/runtime/interpreter/mterp/x86_64/entry.S
index d992956..0f969eb 100644
--- a/runtime/interpreter/mterp/x86_64/entry.S
+++ b/runtime/interpreter/mterp/x86_64/entry.S
@@ -63,9 +63,10 @@
/* Starting ibase */
movq IN_ARG0, rSELF
- REFRESH_IBASE
+ REFRESH_IBASE_REG IN_ARG0
/* Set up for backwards branches & osr profiling */
+ movq IN_ARG0, OUT_ARG2 /* Set up OUT_ARG2 before clobbering IN_ARG0 */
movq OFF_FP_METHOD(rFP), OUT_ARG0
leaq OFF_FP_SHADOWFRAME(rFP), OUT_ARG1
call SYMBOL(MterpSetUpHotnessCountdown)
diff --git a/runtime/interpreter/mterp/x86_64/footer.S b/runtime/interpreter/mterp/x86_64/footer.S
index ed5e5ea..ac6cd19 100644
--- a/runtime/interpreter/mterp/x86_64/footer.S
+++ b/runtime/interpreter/mterp/x86_64/footer.S
@@ -152,7 +152,7 @@
.L_resume_backward_branch:
movq rSELF, %rax
testl $$(THREAD_SUSPEND_OR_CHECKPOINT_REQUEST), THREAD_FLAGS_OFFSET(%rax)
- REFRESH_IBASE
+ REFRESH_IBASE_REG %rax
leaq (rPC, rINSTq, 2), rPC
FETCH_INST
jnz .L_suspend_request_pending
diff --git a/runtime/interpreter/mterp/x86_64/header.S b/runtime/interpreter/mterp/x86_64/header.S
index 7699fc4..f229e84 100644
--- a/runtime/interpreter/mterp/x86_64/header.S
+++ b/runtime/interpreter/mterp/x86_64/header.S
@@ -191,9 +191,12 @@
* restore it in such cases also.
*
*/
+.macro REFRESH_IBASE_REG self_reg
+ movq THREAD_CURRENT_IBASE_OFFSET(\self_reg), rIBASE
+.endm
.macro REFRESH_IBASE
movq rSELF, rIBASE
- movq THREAD_CURRENT_IBASE_OFFSET(rIBASE), rIBASE
+ REFRESH_IBASE_REG rIBASE
.endm
/*
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 7abf52e..8c27bfe 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -144,9 +144,8 @@
return jit_options;
}
-bool Jit::ShouldUsePriorityThreadWeight() {
- return Runtime::Current()->InJankPerceptibleProcessState()
- && Thread::Current()->IsJitSensitiveThread();
+bool Jit::ShouldUsePriorityThreadWeight(Thread* self) {
+ return self->IsJitSensitiveThread() && Runtime::Current()->InJankPerceptibleProcessState();
}
void Jit::DumpInfo(std::ostream& os) {
@@ -653,7 +652,7 @@
DCHECK_LE(priority_thread_weight_, hot_method_threshold_);
int32_t starting_count = method->GetCounter();
- if (Jit::ShouldUsePriorityThreadWeight()) {
+ if (Jit::ShouldUsePriorityThreadWeight(self)) {
count *= priority_thread_weight_;
}
int32_t new_count = starting_count + count; // int32 here to avoid wrap-around;
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 51e49ec..791c338 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -152,7 +152,7 @@
bool CanInvokeCompiledCode(ArtMethod* method);
// Return whether the runtime should use a priority thread weight when sampling.
- static bool ShouldUsePriorityThreadWeight();
+ static bool ShouldUsePriorityThreadWeight(Thread* self);
// If an OSR compiled version is available for `method`,
// and `dex_pc + dex_pc_offset` is an entry point of that compiled