Skip to content

Commit 43f3723

Browse files
committed
[GR-64060] MonitorEnterNode frame state verification should consider non-eliminated MonitorIdNode with a virtual state as eliminated.
PullRequest: graal/20491
2 parents 3c66191 + 4a2e50f commit 43f3723

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/MonitorPEATest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,23 @@ public static void snippet19(boolean deoptimize) {
446446
public void testSnippet19() {
447447
test("snippet19", true);
448448
}
449+
450+
public static void snippet20(Object o) {
451+
synchronized (A.class) {
452+
synchronized ((new Object())) {
453+
synchronized ((new Object())) {
454+
staticObj = o;
455+
}
456+
// The following monitorenter's stateBefore will contain the preceding eliminated
457+
// lock, whose monitor ID is not marked as eliminated
458+
synchronized (B.class) {
459+
}
460+
}
461+
}
462+
}
463+
464+
@Test
465+
public void testSnippet20() {
466+
test("snippet20", new Object());
467+
}
449468
}

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import jdk.graal.compiler.core.common.type.ObjectStamp;
115115
import jdk.graal.compiler.core.common.type.StampFactory;
116116
import jdk.graal.compiler.core.common.type.StampPair;
117+
import jdk.graal.compiler.debug.Assertions;
117118
import jdk.graal.compiler.debug.GraalError;
118119
import jdk.graal.compiler.graph.Node.ConstantNodeParameter;
119120
import jdk.graal.compiler.graph.Node.NodeIntrinsic;
@@ -144,8 +145,12 @@
144145
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
145146
import jdk.graal.compiler.nodes.java.MonitorEnterNode;
146147
import jdk.graal.compiler.nodes.java.MonitorExitNode;
148+
import jdk.graal.compiler.nodes.java.MonitorIdNode;
147149
import jdk.graal.compiler.nodes.spi.LoweringTool;
148150
import jdk.graal.compiler.nodes.type.StampTool;
151+
import jdk.graal.compiler.nodes.virtual.EscapeObjectState;
152+
import jdk.graal.compiler.nodes.virtual.VirtualObjectNode;
153+
import jdk.graal.compiler.nodes.virtual.VirtualObjectState;
149154
import jdk.graal.compiler.options.OptionValues;
150155
import jdk.graal.compiler.phases.common.inlining.InliningUtil;
151156
import jdk.graal.compiler.replacements.SnippetCounter;
@@ -919,13 +924,36 @@ public void lower(CheckFastPathMonitorEnterNode checkFastPathMonitorEnterNode, H
919924
template(tool, checkFastPathMonitorEnterNode, args).instantiate(tool.getMetaAccess(), checkFastPathMonitorEnterNode, DEFAULT_REPLACER, args);
920925
}
921926

927+
private static boolean isVirtualLock(FrameState frameState, int lockIdx) {
928+
MonitorIdNode monitorIdNode = frameState.monitorIdAt(lockIdx);
929+
if (monitorIdNode.isEliminated()) {
930+
return true;
931+
}
932+
933+
ValueNode lock = frameState.lockAt(lockIdx);
934+
if (lock instanceof VirtualObjectNode virtualObject) {
935+
FrameState current = frameState;
936+
do {
937+
if (current.virtualObjectMappingCount() > 0) {
938+
for (EscapeObjectState state : current.virtualObjectMappings()) {
939+
if (state instanceof VirtualObjectState && virtualObject == state.object()) {
940+
return true;
941+
}
942+
}
943+
}
944+
current = current.outerFrameState();
945+
} while (current != null);
946+
}
947+
return false;
948+
}
949+
922950
private boolean verifyLockOrder(MonitorEnterNode monitorenterNode) {
923-
if (requiresStrictLockOrder) {
951+
if (Assertions.assertionsEnabled() && requiresStrictLockOrder) {
924952
FrameState state = monitorenterNode.stateAfter();
925953
boolean subsequentLocksMustBeEliminated = false;
926954
for (int lockIdx = 0; lockIdx < state.locksSize(); lockIdx++) {
927955
if (subsequentLocksMustBeEliminated) {
928-
if (!state.monitorIdAt(lockIdx).isEliminated()) {
956+
if (!isVirtualLock(state, lockIdx)) {
929957
return false;
930958
}
931959
}

0 commit comments

Comments
 (0)