Skip to content

Commit 8295f0a

Browse files
committed
Fix MonitorSnippets branch probability.
1 parent 3fdf168 commit 8295f0a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/MonitorSnippets.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassAccessFlagsOffset;
6161
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassMiscFlagsOffset;
6262
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadWordFromObject;
63-
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.markWordLockMaskInPlace;
6463
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.lockMetadataOffset;
6564
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.markOffset;
65+
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.markWordLockMaskInPlace;
6666
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.monitorValue;
6767
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.objectMonitorCxqOffset;
6868
import static jdk.graal.compiler.hotspot.replacements.HotSpotReplacementsUtil.objectMonitorEntryListOffset;
@@ -205,6 +205,16 @@
205205
// @formatter:on
206206
public class MonitorSnippets implements Snippets {
207207

208+
/**
209+
* This helper method is for bypassing the mandatory branch probabilities for snippets.
210+
*
211+
* See also {@code jdk.graal.compiler.core.test.VerifySnippetProbabilities}
212+
*/
213+
@Fold
214+
public static boolean isJDK21() {
215+
return JavaVersionUtil.JAVA_SPEC == 21;
216+
}
217+
208218
/**
209219
* The monitorenter snippet is slightly different from the HotSpot code:
210220
*
@@ -240,7 +250,7 @@ public static void monitorenter(Object object, KlassPointer hub, @ConstantParame
240250
}
241251

242252
if (tryFastPathLocking(object, stackPointerRegister, trace, counters, mark, lock, thread)) {
243-
if (JavaVersionUtil.JAVA_SPEC == 21 || useStackLocking(INJECTED_VMCONFIG)) {
253+
if (isJDK21() || useStackLocking(INJECTED_VMCONFIG)) {
244254
incrementHeldMonitorCount(thread);
245255
}
246256
} else {
@@ -313,7 +323,7 @@ private static boolean tryEnterInflated(Object object, Word lock, Word mark, Wor
313323

314324
int ownerOffset = objectMonitorOwnerOffset(INJECTED_VMCONFIG);
315325
Word owner = monitor.readWord(ownerOffset, OBJECT_MONITOR_OWNER_LOCATION);
316-
Word newOwner = JavaVersionUtil.JAVA_SPEC == 21 ? thread : thread.readWord(javaThreadLockIDOffset(INJECTED_VMCONFIG), JAVA_THREAD_LOCK_ID_LOCATION);
326+
Word newOwner = isJDK21() ? thread : thread.readWord(javaThreadLockIDOffset(INJECTED_VMCONFIG), JAVA_THREAD_LOCK_ID_LOCATION);
317327

318328
// The following owner null check is essential. In the case where the null check fails, it
319329
// avoids the subsequent bound-to-fail CAS operation, which would have caused the
@@ -480,7 +490,7 @@ public static void monitorexit(Object object, @ConstantParameter int lockDepth,
480490
trace(trace, " lock: 0x%016lx\n", lock);
481491

482492
if (tryFastPathUnlocking(object, trace, counters, thread, lock)) {
483-
if (JavaVersionUtil.JAVA_SPEC == 21 || useStackLocking(INJECTED_VMCONFIG)) {
493+
if (isJDK21() || useStackLocking(INJECTED_VMCONFIG)) {
484494
decrementHeldMonitorCount(thread);
485495
}
486496
} else {
@@ -614,7 +624,7 @@ private static boolean tryExitInflated(Object object, Word mark, Word thread, Wo
614624
int recursionsOffset = objectMonitorRecursionsOffset(INJECTED_VMCONFIG);
615625
Word recursions = monitor.readWord(recursionsOffset, OBJECT_MONITOR_RECURSION_LOCATION);
616626
if (probability(FAST_PATH_PROBABILITY, recursions.equal(0))) {
617-
if (JavaVersionUtil.JAVA_SPEC == 21) {
627+
if (isJDK21()) {
618628
// recursions == 0
619629
Word entryList = monitor.readWord(objectMonitorEntryListOffset(INJECTED_VMCONFIG), OBJECT_MONITOR_ENTRY_LIST_LOCATION);
620630
Word cxq = monitor.readWord(objectMonitorCxqOffset(INJECTED_VMCONFIG), OBJECT_MONITOR_CXQ_LOCATION);

0 commit comments

Comments
 (0)