Revert^2 "Prevent overflow for AOT hotness counters"
Fixed bug where sbc usage was incorrect. sbc does -1 + carry.
Test: test/run-test --always-clean --runtime-option -Xcheck:jni --64 674-hotness-compiled
Test: test/run-test --always-clean --runtime-option -Xcheck:jni 674-hotness-compiled
Bug: 139883463
This reverts commit 7ab07777b08db86dda2891f3e7ae15df8f25a599.
Change-Id: I6f8ac0320592a94314386b04cdb0c7e0e6da6994
diff --git a/compiler/optimizing/code_generator_arm_vixl.cc b/compiler/optimizing/code_generator_arm_vixl.cc
index b3141bf..02286d8 100644
--- a/compiler/optimizing/code_generator_arm_vixl.cc
+++ b/compiler/optimizing/code_generator_arm_vixl.cc
@@ -2087,8 +2087,12 @@
if (GetCompilerOptions().CountHotnessInCompiledCode()) {
UseScratchRegisterScope temps(GetVIXLAssembler());
vixl32::Register temp = temps.Acquire();
+ static_assert(ArtMethod::MaxCounter() == 0xFFFF, "asm is probably wrong");
+ // Load with sign extend to set the high bits for integer overflow check.
__ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value()));
__ Add(temp, temp, 1);
+ // Subtract one if the counter would overflow.
+ __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16));
__ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value()));
}
@@ -2497,8 +2501,11 @@
vixl32::Register temp = temps.Acquire();
__ Push(vixl32::Register(kMethodRegister));
GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize);
+ // Load with sign extend to set the high bits for integer overflow check.
__ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value()));
__ Add(temp, temp, 1);
+ // Subtract one if the counter would overflow.
+ __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16));
__ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value()));
__ Pop(vixl32::Register(kMethodRegister));
}