Skip to content

Commit 6b385f0

Browse files
committed
[GR-68172] Fix MonitorEnter virtualization issues
PullRequest: graal/21678
2 parents ea936c8 + 7facb55 commit 6b385f0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/java/MonitorEnterNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import jdk.graal.compiler.nodes.spi.PlatformConfigurationProvider;
4242
import jdk.graal.compiler.nodes.spi.Virtualizable;
4343
import jdk.graal.compiler.nodes.spi.VirtualizerTool;
44+
import jdk.graal.compiler.nodes.virtual.AllocatedObjectNode;
4445
import jdk.graal.compiler.nodes.virtual.VirtualObjectNode;
4546
import jdk.graal.compiler.serviceprovider.SpeculationReasonGroup;
4647
import jdk.vm.ci.meta.SpeculationLog;
@@ -107,6 +108,14 @@ public void virtualize(VirtualizerTool tool) {
107108
if (virtual.hasIdentity() && tool.canVirtualizeLock(virtual, getMonitorId())) {
108109
tool.addLock(virtual, getMonitorId());
109110
if (!tool.getPlatformConfigurationProvider().areLocksSideEffectFree()) {
111+
if (object() instanceof AllocatedObjectNode) {
112+
/*
113+
* Don't let the allocation sink past the state split proxy, otherwise we
114+
* end up with a virtual object in the state instead of the actual allocated
115+
* one.
116+
*/
117+
tool.ensureMaterialized(virtual);
118+
}
110119
// Ensure that the locks appear to have been acquired in the nearest FrameState.
111120
tool.ensureAdded(new StateSplitProxyNode(stateAfter));
112121
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/virtual/phases/ea/GraphEffectList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -117,9 +117,9 @@ public void apply(StructuredGraph graph) {
117117
assert position == null || position.isAlive();
118118
if (!node.isAlive()) {
119119
graph.addWithoutUniqueWithInputs(node);
120-
if (node instanceof FixedWithNextNode) {
121-
graph.addBeforeFixed(position, (FixedWithNextNode) node);
122-
}
120+
}
121+
if (node instanceof FixedWithNextNode fixedWithNextNode && fixedWithNextNode.next() == null) {
122+
graph.addBeforeFixed(position, fixedWithNextNode);
123123
}
124124
}
125125

0 commit comments

Comments
 (0)