Introduce a kTieredHotnessMask.
To be used by the baseline compiler for when to trigger optimized
compilation. Before we were using the nterp threshold, but there may be
a need to have different ones.
Test: test.py
Bug: 112676029
Change-Id: I98e97ad8cfa50a6546c927960fad1567263a7354
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index b8f4011..ced16fb 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -30,6 +30,7 @@
#include "gc/accounting/card_table.h"
#include "gc/space/image_space.h"
#include "heap_poisoning.h"
+#include "interpreter/mterp/nterp.h"
#include "intrinsics.h"
#include "intrinsics_arm64.h"
#include "linker/linker_patch.h"
@@ -1153,9 +1154,9 @@
__ Mov(temp, address);
__ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()));
__ Add(counter, counter, 1);
+ __ And(counter, counter, interpreter::kTieredHotnessMask);
__ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()));
- __ Tst(counter, 0xffff);
- __ B(ne, &done);
+ __ Cbnz(counter, &done);
if (is_frame_entry) {
if (HasEmptyFrame()) {
// The entrypoint expects the method at the bottom of the stack. We
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 37265ec..0ed982a 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -25,6 +25,7 @@
#include "gc/accounting/card_table.h"
#include "gc/space/image_space.h"
#include "heap_poisoning.h"
+#include "interpreter/mterp/nterp.h"
#include "intrinsics.h"
#include "intrinsics_x86_64.h"
#include "jit/profiling_info.h"
@@ -1425,7 +1426,9 @@
__ movq(CpuRegister(TMP), Immediate(address));
__ addw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()),
Immediate(1));
- __ j(kCarryClear, &done);
+ __ andw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()),
+ Immediate(interpreter::kTieredHotnessMask));
+ __ j(kNotZero, &done);
if (HasEmptyFrame()) {
CHECK(is_frame_entry);
// Frame alignment, and the stub expects the method on the stack.
diff --git a/runtime/interpreter/mterp/nterp.cc b/runtime/interpreter/mterp/nterp.cc
index 62f0626..b63f892 100644
--- a/runtime/interpreter/mterp/nterp.cc
+++ b/runtime/interpreter/mterp/nterp.cc
@@ -80,6 +80,8 @@
<< "(did an instruction handler exceed " << width << " bytes?)";
}
static_assert(IsPowerOfTwo(kNterpHotnessMask + 1), "Hotness mask must be a (power of 2) - 1");
+ static_assert(IsPowerOfTwo(kTieredHotnessMask + 1),
+ "Tiered 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/nterp.h b/runtime/interpreter/mterp/nterp.h
index a1bf941..fac30d9 100644
--- a/runtime/interpreter/mterp/nterp.h
+++ b/runtime/interpreter/mterp/nterp.h
@@ -37,6 +37,10 @@
// The hotness threshold where we trigger JIT compilation or OSR.
constexpr uint16_t kNterpHotnessMask = 0xffff;
+// The hotness threshold for the baseline compiler to trigger optimized
+// compilation.
+constexpr uint16_t kTieredHotnessMask = 0xffff;
+
// The maximum we allow an nterp frame to be.
constexpr size_t kNterpMaxFrame = 3 * KB;