Skip to content

Commit 5a2a9ec

Browse files
authored
Merge pull request #502 from zakkak/2023-04-26-sync-with-upstream-22.3
2023 04 26 sync with upstream 22.3
2 parents 46052c9 + e8a26b7 commit 5a2a9ec

File tree

131 files changed

+1889
-2670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1889
-2670
lines changed

common.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
"jdks": {
77
"openjdk11": {"name": "jpg-jdk", "version": "11.0.11", "build_id": "9", "open": true, "release": true, "platformspecific": true },
88
"oraclejdk11": {"name": "jpg-jdk", "version": "11.0.11", "build_id": "9", "release": true, "platformspecific": true, "extrabundles": ["static-libs"] },
9-
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.18+10-jvmci-22.3-b13", "platformspecific": true },
10-
"labsjdk-ce-11-llvm": {"name": "labsjdk", "version": "ce-11.0.18+10-jvmci-22.3-b13-sulong", "platformspecific": true },
11-
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.18+9-jvmci-22.3-b11", "platformspecific": true },
12-
"labsjdk-ee-11-llvm": {"name": "labsjdk", "version": "ee-11.0.18+9-jvmci-22.3-b11-sulong", "platformspecific": true },
9+
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.19+5-jvmci-22.3-b16", "platformspecific": true },
10+
"labsjdk-ce-11-llvm": {"name": "labsjdk", "version": "ce-11.0.19+5-jvmci-22.3-b16-sulong", "platformspecific": true },
11+
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.19+9-jvmci-22.3-b16", "platformspecific": true },
12+
"labsjdk-ee-11-llvm": {"name": "labsjdk", "version": "ee-11.0.19+9-jvmci-22.3-b16-sulong", "platformspecific": true },
1313

1414
"oraclejdk17": {"name": "jpg-jdk", "version": "17.0.1", "build_id": "12", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
15-
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.6+10-jvmci-22.3-b13", "platformspecific": true },
16-
"labsjdk-ce-17Debug": {"name": "labsjdk", "version": "ce-17.0.6+10-jvmci-22.3-b13-debug", "platformspecific": true },
17-
"labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.6+10-jvmci-22.3-b13-sulong", "platformspecific": true },
18-
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.6+9-jvmci-22.3-b11", "platformspecific": true },
19-
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.6+9-jvmci-22.3-b11-debug", "platformspecific": true },
20-
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.6+9-jvmci-22.3-b11-sulong", "platformspecific": true },
15+
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+5-jvmci-22.3-b16", "platformspecific": true },
16+
"labsjdk-ce-17Debug": {"name": "labsjdk", "version": "ce-17.0.7+5-jvmci-22.3-b16-debug", "platformspecific": true },
17+
"labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.7+5-jvmci-22.3-b16-sulong", "platformspecific": true },
18+
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.7+8-jvmci-22.3-b15", "platformspecific": true },
19+
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.7+8-jvmci-22.3-b15-debug", "platformspecific": true },
20+
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.7+8-jvmci-22.3-b15-sulong", "platformspecific": true },
2121

2222
"oraclejdk19": {"name": "jpg-jdk", "version": "19", "build_id": "26", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
2323
"labsjdk-ce-19": {"name": "labsjdk", "version": "ce-19.0.2+7-jvmci-22.3-b12", "platformspecific": true },

compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/EarlyGVNTest.java

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,24 @@
3939
import org.graalvm.compiler.core.common.GraalOptions;
4040
import org.graalvm.compiler.graph.Node;
4141
import org.graalvm.compiler.graph.NodeClass;
42+
import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
4243
import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
4344
import org.graalvm.compiler.nodes.FixedGuardNode;
4445
import org.graalvm.compiler.nodes.LoopBeginNode;
4546
import org.graalvm.compiler.nodes.StructuredGraph;
4647
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
4748
import org.graalvm.compiler.nodes.java.ArrayLengthNode;
4849
import org.graalvm.compiler.nodes.java.LoadFieldNode;
50+
import org.graalvm.compiler.nodes.java.LoadIndexedNode;
4951
import org.graalvm.compiler.nodes.java.StoreFieldNode;
5052
import org.graalvm.compiler.nodes.loop.LoopEx;
5153
import org.graalvm.compiler.nodes.loop.LoopsData;
5254
import org.graalvm.compiler.options.OptionValues;
5355
import org.graalvm.compiler.phases.BasePhase;
5456
import org.graalvm.compiler.phases.PhaseSuite;
57+
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
58+
import org.graalvm.compiler.phases.common.ConditionalEliminationPhase;
59+
import org.graalvm.compiler.phases.common.DominatorBasedGlobalValueNumberingPhase;
5560
import org.graalvm.compiler.phases.tiers.HighTierContext;
5661
import org.graalvm.compiler.phases.tiers.Suites;
5762
import org.junit.Assert;
@@ -128,28 +133,32 @@ private void checkHighTierGraph(String snippet, NodeCount... counts) {
128133

129134
@Override
130135
protected void run(@SuppressWarnings("hiding") StructuredGraph graph, HighTierContext context) {
131-
LoopsData loops = getDefaultHighTierContext().getLoopsDataProvider().getLoopsData(graph);
132-
133-
for (NodeCount count : counts) {
134-
List<Node> nodes = graph.getNodes().filter(x -> x.getNodeClass().equals(count.nodeClass)).snapshot();
135-
int realCount = nodes.size();
136-
Assert.assertEquals("Wrong node count for node class " + count.nodeClass, count.count, realCount);
137-
if (count.invariantCount != 0) {
138-
int invariantCount = count.count;
139-
for (Node node : nodes) {
140-
for (LoopEx loop : loops.loops()) {
141-
if (loop.whole().contains(node)) {
142-
invariantCount--;
143-
break;
144-
}
145-
}
136+
checkHighTierGraph(graph, counts);
137+
}
138+
});
139+
ht.apply(graph, getDefaultHighTierContext());
140+
}
141+
142+
private void checkHighTierGraph(StructuredGraph graph, NodeCount... counts) {
143+
LoopsData loops = getDefaultHighTierContext().getLoopsDataProvider().getLoopsData(graph);
144+
145+
for (NodeCount count : counts) {
146+
List<Node> nodes = graph.getNodes().filter(x -> x.getNodeClass().equals(count.nodeClass)).snapshot();
147+
int realCount = nodes.size();
148+
Assert.assertEquals("Wrong node count for node class " + count.nodeClass, count.count, realCount);
149+
if (count.invariantCount != 0) {
150+
int invariantCount = count.count;
151+
for (Node node : nodes) {
152+
for (LoopEx loop : loops.loops()) {
153+
if (loop.whole().contains(node)) {
154+
invariantCount--;
155+
break;
146156
}
147-
Assert.assertEquals("Wrong number of invariant nodes for node class " + count.nodeClass.getClazz(), count.invariantCount, invariantCount);
148157
}
149158
}
159+
Assert.assertEquals("Wrong number of invariant nodes for node class " + count.nodeClass.getClazz(), count.invariantCount, invariantCount);
150160
}
151-
});
152-
ht.apply(graph, getDefaultHighTierContext());
161+
}
153162
}
154163

155164
@MustFold()
@@ -577,4 +586,57 @@ public void testNested() {
577586
test(s, new int[0]);
578587
checkHighTierGraph(s, invariantCount(ArrayLengthNode.TYPE, 1));
579588
}
589+
590+
public static int doubleNest(int l0, int l1, int l2, Object[] arr, Object[] arr2) {
591+
int i0 = 0;
592+
int i1 = 0;
593+
int i2 = 0;
594+
int result = 0;
595+
Object[] nonNullArray = GraalDirectives.guardingNonNull(arr);
596+
if (nonNullArray.length < 10) {
597+
GraalDirectives.deoptimizeAndInvalidate();
598+
}
599+
do {
600+
Object[] proxy = null;
601+
do {
602+
if (i1 > i0) {
603+
proxy = nonNullArray;
604+
} else {
605+
proxy = arr2;
606+
}
607+
} while (i1++ < l1);
608+
do {
609+
Object o1 = proxy[0];
610+
if (o1 == null) {
611+
result *= 2;
612+
}
613+
} while (i2++ < l2);
614+
Object o2 = proxy[0];
615+
result += (Integer) o2;
616+
} while (i0++ < l0);
617+
return result;
618+
}
619+
620+
@Test
621+
public void testNested2() {
622+
String s = "doubleNest";
623+
StructuredGraph g = parseEager(getResolvedJavaMethod(s), AllowAssumptions.NO);
624+
HighTierContext highTierContext = getDefaultHighTierContext();
625+
CanonicalizerPhase c = CanonicalizerPhase.create();
626+
627+
c.apply(g, getDefaultHighTierContext());
628+
new ConvertDeoptimizeToGuardPhase(c).apply(g, highTierContext);
629+
new ConditionalEliminationPhase(false).apply(g, highTierContext);
630+
c.apply(g, getDefaultHighTierContext());
631+
new DominatorBasedGlobalValueNumberingPhase(c).apply(g, highTierContext);
632+
new ConditionalEliminationPhase(false).apply(g, highTierContext);
633+
c.apply(g, getDefaultHighTierContext());
634+
new DominatorBasedGlobalValueNumberingPhase(c).apply(g, highTierContext);
635+
636+
checkHighTierGraph(g, count(FixedGuardNode.TYPE, 4),
637+
count(LoopBeginNode.TYPE, 3),
638+
invariantCount(ArrayLengthNode.TYPE, 1),
639+
count(LoadIndexedNode.TYPE, 1));
640+
641+
}
580642
}

compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MathCopySignStampTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ public void testFloatCopySign() throws InvalidInstalledCodeException {
9090
}
9191
}
9292

93+
public static int badCopyStampGR43958(short magnitude) {
94+
/*
95+
* Previously the stamp of the copySign would be incorrect.
96+
*/
97+
return (short) Math.copySign(magnitude, -942.5804f);
98+
}
99+
100+
@Test
101+
public void testGR43958() throws InvalidInstalledCodeException {
102+
short[] shortValues = {42, -42, 95};
103+
for (short magnitude : shortValues) {
104+
InstalledCode code = getCode(getResolvedJavaMethod("badCopyStampGR43958"), null, true);
105+
Assert.assertEquals(badCopyStampGR43958(magnitude), (int) code.executeVarargs(magnitude), 0);
106+
}
107+
}
108+
93109
private static final double[] doubleValues = {
94110
0.0d,
95111
-0.0d,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.graalvm.compiler.core.test;
26+
27+
import org.graalvm.compiler.api.directives.GraalDirectives;
28+
import org.graalvm.compiler.core.common.GraalOptions;
29+
import org.graalvm.compiler.options.OptionValues;
30+
import org.junit.Test;
31+
32+
import jdk.vm.ci.code.InstalledCode;
33+
import jdk.vm.ci.meta.SpeculationLog;
34+
35+
public class SpeculativeGuardMovementTest extends GraalCompilerTest {
36+
37+
@Override
38+
protected SpeculationLog getSpeculationLog() {
39+
return getCodeCache().createSpeculationLog();
40+
}
41+
42+
public static void snippet01(int init, int limit, int offset) {
43+
for (int i = init; GraalDirectives.injectIterationCount(1000, i < limit); i++) {
44+
if (Integer.compareUnsigned(i + offset, Integer.MIN_VALUE + 5) > 0) {
45+
GraalDirectives.deoptimizeAndInvalidate();
46+
throw new IndexOutOfBoundsException();
47+
}
48+
}
49+
}
50+
51+
@Test
52+
public void testOverflowUnsignedGuard() {
53+
int init = 0;
54+
int limit = 10;
55+
int offset = Integer.MAX_VALUE;
56+
OptionValues opt = new OptionValues(getInitialOptions(), GraalOptions.PartialUnroll, false);
57+
InstalledCode code = getCode(getResolvedJavaMethod("snippet01"), opt);
58+
assertTrue(code.isValid());
59+
try {
60+
code.executeVarargs(init, limit, offset);
61+
throw new RuntimeException("should have thrown");
62+
} catch (Throwable e) {
63+
if (!(e instanceof IndexOutOfBoundsException)) {
64+
throw new RuntimeException("unexpected exception " + e);
65+
}
66+
}
67+
}
68+
}

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotG1WriteBarrierSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected int wordSize() {
8585
}
8686

8787
@Override
88-
protected int objectArrayIndexScale() {
88+
protected long objectArrayIndexScale() {
8989
return ReplacementsUtil.arrayIndexScale(INJECTED_METAACCESS, JavaKind.Object);
9090
}
9191

compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopTransformations.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,17 @@ public static EconomicMap<ValueNode, List<ControlSplitNode>> findUnswitchable(Lo
763763
return controls;
764764
}
765765

766+
/**
767+
* Check for multiple usages of the loop condition. Partial unrolling will modify the condition
768+
* in place. Any other usages of the condition would therefore compute a different condition
769+
* than before. A shared loop condition indicates that the graph isn't properly optimized, so
770+
* don't bother with partial unrolling, especially if it would break things.
771+
*/
772+
public static boolean countedLoopExitConditionHasMultipleUsages(LoopEx loop) {
773+
LogicNode condition = loop.counted().getLimitTest().condition();
774+
return condition.hasMoreThanOneUsage();
775+
}
776+
766777
public static boolean isUnrollableLoop(LoopEx loop) {
767778
if (!loop.isCounted() || !loop.counted().getLimitCheckedIV().isConstantStride() || !loop.loop().getChildren().isEmpty() || loop.loopBegin().loopEnds().count() != 1 ||
768779
loop.loopBegin().loopExits().count() > 1 || loop.counted().isInverted()) {
@@ -780,6 +791,9 @@ public static boolean isUnrollableLoop(LoopEx loop) {
780791
condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s condition unsupported %s ", loopBegin, ((CompareNode) condition).condition());
781792
return false;
782793
}
794+
if (countedLoopExitConditionHasMultipleUsages(loop)) {
795+
return false;
796+
}
783797
long stride = loop.counted().getLimitCheckedIV().constantStride();
784798
try {
785799
Math.addExact(stride, stride);

compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/SpeculativeGuardMovementPhase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ private void optimizeCompare(CompareNode compare, InductionVariable iv, ValueNod
354354
bound.getDebug().log("optimizeCompare(%s, %s, %s, %b) in %s", compare, iv, bound, mirrored, graph.method());
355355
CountedLoopInfo countedLoop = iv.getLoop().counted();
356356
GuardingNode overflowGuard = countedLoop.getOverFlowGuard();
357-
ValueNode longBound = IntegerConvertNode.convert(bound, StampFactory.forKind(JavaKind.Long), graph, NodeView.DEFAULT);
357+
final boolean zeroExtendBound = compare.condition().isUnsigned();
358+
ValueNode longBound = IntegerConvertNode.convert(bound, StampFactory.forKind(JavaKind.Long), zeroExtendBound, graph, NodeView.DEFAULT);
358359
LogicNode newCompare;
359360
ValueNode extremum = iv.extremumNode(true, StampFactory.forKind(JavaKind.Long));
360361
GuardedValueNode guardedExtremum = graph.unique(new GuardedValueNode(extremum, overflowGuard));

compiler/src/org.graalvm.compiler.loop.test/src/org/graalvm/compiler/loop/test/LoopPartialUnrollTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@
6565

6666
public class LoopPartialUnrollTest extends GraalCompilerTest {
6767

68+
boolean check = true;
69+
6870
@Override
6971
protected void checkMidTierGraph(StructuredGraph graph) {
72+
if (!check) {
73+
return;
74+
}
7075
NodeIterable<LoopBeginNode> loops = graph.getNodes().filter(LoopBeginNode.class);
7176
// Loops might be optimizable after partial unrolling
7277
if (!loops.isEmpty()) {
@@ -371,4 +376,19 @@ public void testDuplicateBody(String reference, String test) {
371376
canonicalizer.apply(referenceGraph, getDefaultMidTierContext());
372377
assertEquals(referenceGraph, testGraph);
373378
}
379+
380+
public static void twoUsages(int n) {
381+
for (int i = 0; injectIterationCount(100, i < n); i++) {
382+
GraalDirectives.blackhole(i < n ? 1 : 2);
383+
}
384+
}
385+
386+
@Test
387+
public void testUsages() {
388+
check = false;
389+
OptionValues options = new OptionValues(getInitialOptions(), GraalOptions.LoopPeeling, false);
390+
test(options, "twoUsages", 100);
391+
check = true;
392+
}
393+
374394
}

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/BeginStateSplitNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.graalvm.compiler.nodes;
2626

2727
import org.graalvm.compiler.core.common.type.Stamp;
28+
import org.graalvm.compiler.debug.GraalError;
2829
import org.graalvm.compiler.graph.NodeClass;
2930
import org.graalvm.compiler.nodeinfo.InputType;
3031
import org.graalvm.compiler.nodeinfo.NodeInfo;
@@ -57,7 +58,7 @@ public FrameState stateAfter() {
5758

5859
@Override
5960
public void setStateAfter(FrameState x) {
60-
assert x == null || x.isAlive() : "frame state must be in a graph";
61+
GraalError.guarantee(x == null || x.isAlive(), "frame state must be in a graph: %s", x);
6162
updateUsages(stateAfter, x);
6263
stateAfter = x;
6364
}

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
import org.graalvm.compiler.graph.Node;
5454
import org.graalvm.compiler.graph.NodeClass;
5555
import org.graalvm.compiler.graph.NodeSourcePosition;
56+
import org.graalvm.compiler.graph.Position;
5657
import org.graalvm.compiler.graph.iterators.NodeIterable;
5758
import org.graalvm.compiler.nodeinfo.InputType;
5859
import org.graalvm.compiler.nodeinfo.NodeInfo;
5960
import org.graalvm.compiler.nodes.GraphState.StageFlag;
6061
import org.graalvm.compiler.nodes.ProfileData.BranchProbabilityData;
6162
import org.graalvm.compiler.nodes.ProfileData.ProfileSource;
63+
import org.graalvm.compiler.nodes.VirtualState.NodePositionClosure;
6264
import org.graalvm.compiler.nodes.calc.AddNode;
6365
import org.graalvm.compiler.nodes.calc.CompareNode;
6466
import org.graalvm.compiler.nodes.calc.ConditionalNode;
@@ -2325,8 +2327,16 @@ private void connectEnds(List<EndNode> ends, ValuePhiNode phi, EconomicMap<Abstr
23252327

23262328
FrameState stateAfter = oldMerge.stateAfter();
23272329
if (stateAfter != null) {
2328-
stateAfter = stateAfter.duplicate();
2329-
stateAfter.replaceFirstInput(oldPhi, newPhi);
2330+
stateAfter = stateAfter.duplicateWithVirtualState();
2331+
stateAfter.applyToNonVirtual(new NodePositionClosure<>() {
2332+
@Override
2333+
public void apply(Node from, Position p) {
2334+
ValueNode to = (ValueNode) p.get(from);
2335+
if (to == oldPhi) {
2336+
p.set(from, newPhi);
2337+
}
2338+
}
2339+
});
23302340
newMerge.setStateAfter(stateAfter);
23312341
}
23322342

0 commit comments

Comments
 (0)