diff options
author | 2024-10-17 12:42:52 +0000 | |
---|---|---|
committer | 2024-10-23 08:39:45 +0000 | |
commit | 398bedca50a44d26edc84e24a1c1b587cefaf8de (patch) | |
tree | d7327d8e0dfc4b600de34dfe704208beb0de3333 | |
parent | 003071c7fc8f19cefe82b4f95bffeeec88b0658c (diff) |
Revert^2 "IsMemorySharedMethod fix for intrinsics"
This reverts commit d96190b790e4cde51e992d7613e6df1af63a9b35.
Reason for revert: Hotness counter fix
Test: art/test/testrunner/testrunner.py --host --64 -b --jit
Test: Build and boot an eng build without the hotness counter error
Test: LUCI run https://ci.chromium.org/b/8733734597298578033
Bug: 78151261
Bug: 162110941
Bug: 373966864
Change-Id: I3dc6bb2fdeb811a94726b70ec4e678bc51aaa405
-rw-r--r-- | runtime/art_method.h | 8 | ||||
-rw-r--r-- | runtime/interpreter/mterp/arm64ng/main.S | 2 | ||||
-rw-r--r-- | runtime/interpreter/mterp/armng/main.S | 3 | ||||
-rw-r--r-- | runtime/interpreter/mterp/nterp.cc | 7 | ||||
-rw-r--r-- | runtime/interpreter/mterp/riscv64/main.S | 5 | ||||
-rw-r--r-- | runtime/interpreter/mterp/x86_64ng/main.S | 3 | ||||
-rw-r--r-- | runtime/interpreter/mterp/x86ng/main.S | 3 | ||||
-rw-r--r-- | runtime/jit/jit-inl.h | 11 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 3 | ||||
-rw-r--r-- | tools/cpp-define-generator/art_method.def | 4 |
10 files changed, 41 insertions, 8 deletions
diff --git a/runtime/art_method.h b/runtime/art_method.h index 30dc09f67f..51520ddd4c 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -356,6 +356,14 @@ class EXPORT ArtMethod final { } static bool IsMemorySharedMethod(uint32_t access_flags) { + // There's an overlap with `kAccMemorySharedMethod` and `kAccIntrinsicBits` but that's OK as + // intrinsics are always in the boot image and therefore memory shared. + static_assert((kAccMemorySharedMethod & kAccIntrinsicBits) != 0, + "kAccMemorySharedMethod deliberately overlaps intrinsic bits"); + if (IsIntrinsic(access_flags)) { + return true; + } + return (access_flags & kAccMemorySharedMethod) != 0; } diff --git a/runtime/interpreter/mterp/arm64ng/main.S b/runtime/interpreter/mterp/arm64ng/main.S index 7d83edbad1..995ff86f18 100644 --- a/runtime/interpreter/mterp/arm64ng/main.S +++ b/runtime/interpreter/mterp/arm64ng/main.S @@ -1541,6 +1541,8 @@ END \name .macro CHECK_AND_UPDATE_SHARED_MEMORY_METHOD if_hot, if_not_hot ldr wip, [x0, #ART_METHOD_ACCESS_FLAGS_OFFSET] tbz wip, #ART_METHOD_IS_MEMORY_SHARED_FLAG_BIT, \if_hot + // Intrinsics are always in the boot image and considered hot. + tbnz wip, #ART_METHOD_IS_INTRINSIC_FLAG_BIT, \if_hot ldr wip, [xSELF, #THREAD_SHARED_METHOD_HOTNESS_OFFSET] cbz wip, \if_hot add wip, wip, #-1 diff --git a/runtime/interpreter/mterp/armng/main.S b/runtime/interpreter/mterp/armng/main.S index 906536654b..5298840f92 100644 --- a/runtime/interpreter/mterp/armng/main.S +++ b/runtime/interpreter/mterp/armng/main.S @@ -1544,6 +1544,9 @@ END \name ldr ip, [r0, #ART_METHOD_ACCESS_FLAGS_OFFSET] tst ip, #ART_METHOD_IS_MEMORY_SHARED_FLAG beq \if_hot + // Intrinsics are always in the boot image and considered hot. + tst ip, #ART_METHOD_IS_INTRINSIC_FLAG + bne \if_hot ldr ip, [rSELF, #THREAD_SHARED_METHOD_HOTNESS_OFFSET] cmp ip, #0 beq \if_hot diff --git a/runtime/interpreter/mterp/nterp.cc b/runtime/interpreter/mterp/nterp.cc index a69dd8c4c7..2fe9c24fa6 100644 --- a/runtime/interpreter/mterp/nterp.cc +++ b/runtime/interpreter/mterp/nterp.cc @@ -695,8 +695,11 @@ extern "C" jit::OsrData* NterpHotMethod(ArtMethod* method, uint16_t* dex_pc_ptr, ScopedAssertNoThreadSuspension sants("In nterp"); Runtime* runtime = Runtime::Current(); if (method->IsMemorySharedMethod()) { - DCHECK_EQ(Thread::Current()->GetSharedMethodHotness(), 0u); - Thread::Current()->ResetSharedMethodHotness(); + if (!method->IsIntrinsic()) { + // Intrinsics are special and will be considered hot from the first call. + DCHECK_EQ(Thread::Current()->GetSharedMethodHotness(), 0u); + Thread::Current()->ResetSharedMethodHotness(); + } } else { // Move the counter to the initial threshold in case we have to re-JIT it. method->ResetCounter(runtime->GetJITOptions()->GetWarmupThreshold()); diff --git a/runtime/interpreter/mterp/riscv64/main.S b/runtime/interpreter/mterp/riscv64/main.S index a9b917ad35..11428646ad 100644 --- a/runtime/interpreter/mterp/riscv64/main.S +++ b/runtime/interpreter/mterp/riscv64/main.S @@ -249,9 +249,12 @@ END \name // - xSELF // Clobbers: t0 .macro CHECK_AND_UPDATE_SHARED_MEMORY_METHOD if_hot, if_not_hot + // TODO(solanes): Figure out if there's a way to load t0 only once. lwu t0, ART_METHOD_ACCESS_FLAGS_OFFSET(a0) BRANCH_IF_BIT_CLEAR t0, t0, ART_METHOD_IS_MEMORY_SHARED_FLAG_BIT, \if_hot - + lwu t0, ART_METHOD_ACCESS_FLAGS_OFFSET(a0) + // Intrinsics are always in the boot image and considered hot. + BRANCH_IF_BIT_SET t0, t0, ART_METHOD_IS_INTRINSIC_FLAG_BIT, \if_hot lwu t0, THREAD_SHARED_METHOD_HOTNESS_OFFSET(xSELF) // t0 := hotness beqz t0, \if_hot diff --git a/runtime/interpreter/mterp/x86_64ng/main.S b/runtime/interpreter/mterp/x86_64ng/main.S index f6f48ffcc3..8a66a91b38 100644 --- a/runtime/interpreter/mterp/x86_64ng/main.S +++ b/runtime/interpreter/mterp/x86_64ng/main.S @@ -1608,8 +1608,11 @@ END_FUNCTION \name .endm .macro CHECK_AND_UPDATE_SHARED_MEMORY_METHOD if_hot, if_not_hot + // Intrinsics are always in the boot image and considered hot. testl $$ART_METHOD_IS_MEMORY_SHARED_FLAG, ART_METHOD_ACCESS_FLAGS_OFFSET(%rdi) jz \if_hot + testl $$ART_METHOD_IS_INTRINSIC_FLAG, ART_METHOD_ACCESS_FLAGS_OFFSET(%rdi) + jnz \if_hot movzwl rSELF:THREAD_SHARED_METHOD_HOTNESS_OFFSET, %esi testl %esi, %esi je \if_hot diff --git a/runtime/interpreter/mterp/x86ng/main.S b/runtime/interpreter/mterp/x86ng/main.S index 65a6a75df1..e39849a885 100644 --- a/runtime/interpreter/mterp/x86ng/main.S +++ b/runtime/interpreter/mterp/x86ng/main.S @@ -1685,8 +1685,11 @@ END_FUNCTION \name .endm .macro CHECK_AND_UPDATE_SHARED_MEMORY_METHOD if_hot, if_not_hot + // Intrinsics are always in the boot image and considered hot. testl $$ART_METHOD_IS_MEMORY_SHARED_FLAG, ART_METHOD_ACCESS_FLAGS_OFFSET(%eax) jz \if_hot + testl $$ART_METHOD_IS_INTRINSIC_FLAG, ART_METHOD_ACCESS_FLAGS_OFFSET(%eax) + jnz \if_hot movzwl rSELF:THREAD_SHARED_METHOD_HOTNESS_OFFSET, %ecx testl %ecx, %ecx je \if_hot diff --git a/runtime/jit/jit-inl.h b/runtime/jit/jit-inl.h index 52099c2e1d..e1f331df73 100644 --- a/runtime/jit/jit-inl.h +++ b/runtime/jit/jit-inl.h @@ -30,10 +30,13 @@ namespace jit { inline void Jit::AddSamples(Thread* self, ArtMethod* method) { if (method->CounterIsHot()) { if (method->IsMemorySharedMethod()) { - if (self->DecrementSharedMethodHotness() == 0) { - self->ResetSharedMethodHotness(); - } else { - return; + // Intrinsics are special and will be considered hot from the first call. + if (!method->IsIntrinsic()) { + if (self->DecrementSharedMethodHotness() == 0) { + self->ResetSharedMethodHotness(); + } else { + return; + } } } else { method->ResetCounter(Runtime::Current()->GetJITOptions()->GetWarmupThreshold()); diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index de19b16e4f..5b048ee57a 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -1711,7 +1711,8 @@ void Jit::MaybeEnqueueCompilation(ArtMethod* method, Thread* self) { } static constexpr size_t kIndividualSharedMethodHotnessThreshold = 0x3f; - if (method->IsMemorySharedMethod()) { + // Intrinsics are always in the boot image and considered hot. + if (method->IsMemorySharedMethod() && !method->IsIntrinsic()) { MutexLock mu(self, lock_); auto it = shared_method_counters_.find(method); if (it == shared_method_counters_.end()) { diff --git a/tools/cpp-define-generator/art_method.def b/tools/cpp-define-generator/art_method.def index d5ba59998d..3c34247ec2 100644 --- a/tools/cpp-define-generator/art_method.def +++ b/tools/cpp-define-generator/art_method.def @@ -21,6 +21,10 @@ ASM_DEFINE(ART_METHOD_ACCESS_FLAGS_OFFSET, art::ArtMethod::AccessFlagsOffset().Int32Value()) +ASM_DEFINE(ART_METHOD_IS_INTRINSIC_FLAG, + art::kAccIntrinsic) +ASM_DEFINE(ART_METHOD_IS_INTRINSIC_FLAG_BIT, + art::MostSignificantBit(art::kAccIntrinsic)) ASM_DEFINE(ART_METHOD_IS_MEMORY_SHARED_FLAG, art::kAccMemorySharedMethod) ASM_DEFINE(ART_METHOD_IS_MEMORY_SHARED_FLAG_BIT, |