Change detection of counter overflow in nterp x64.
To better play with different thresholds (currently changing the counter
in the source, but soon through command line), 'and' the counter with the
hotness before comparing to zero.
Test: test.py
Bug: 112676029
Change-Id: I1f85a3dbd7423b08f69839301465e1ebbcc8d69a
diff --git a/runtime/interpreter/mterp/nterp.cc b/runtime/interpreter/mterp/nterp.cc
index 2ec142f..62f0626 100644
--- a/runtime/interpreter/mterp/nterp.cc
+++ b/runtime/interpreter/mterp/nterp.cc
@@ -79,6 +79,7 @@
LOG(FATAL) << "ERROR: unexpected asm interp size " << interp_size
<< "(did an instruction handler exceed " << width << " bytes?)";
}
+ static_assert(IsPowerOfTwo(kNterpHotnessMask + 1), "Hotness mask must be a (power of 2) - 1");
}
inline void UpdateHotness(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
diff --git a/runtime/interpreter/mterp/x86_64ng/main.S b/runtime/interpreter/mterp/x86_64ng/main.S
index d5de6c5..8966490 100644
--- a/runtime/interpreter/mterp/x86_64ng/main.S
+++ b/runtime/interpreter/mterp/x86_64ng/main.S
@@ -254,12 +254,10 @@
GOTO_NEXT
3:
movq (%rsp), %rdi
-#if (NTERP_HOTNESS_MASK != 0xffff)
-#error "Nterp x86_64 expects Nterp hotness mask to be 0xffff"
-#endif
addw $$1, ART_METHOD_HOTNESS_COUNT_OFFSET(%rdi)
+ andw $$(NTERP_HOTNESS_MASK), ART_METHOD_HOTNESS_COUNT_OFFSET(%rdi)
// If the counter overflows, handle this in the runtime.
- jo NterpHandleHotnessOverflow
+ jz NterpHandleHotnessOverflow
// Otherwise, do a suspend check.
testl $$(THREAD_SUSPEND_OR_CHECKPOINT_REQUEST), rSELF:THREAD_FLAGS_OFFSET
jz 2b
@@ -743,11 +741,9 @@
// Increase method hotness and do suspend check before starting executing the method.
.macro START_EXECUTING_INSTRUCTIONS
movq (%rsp), %rdi
-#if (NTERP_HOTNESS_MASK != 0xffff)
-#error "Nterp x86_64 expects Nterp hotness mask to be 0xffff"
-#endif
addw $$1, ART_METHOD_HOTNESS_COUNT_OFFSET(%rdi)
- jo 2f
+ andw $$(NTERP_HOTNESS_MASK), ART_METHOD_HOTNESS_COUNT_OFFSET(%rdi)
+ jz 2f
testl $$(THREAD_SUSPEND_OR_CHECKPOINT_REQUEST), rSELF:THREAD_FLAGS_OFFSET
jz 1f
EXPORT_PC