Skip to content

Commit b64252f

Browse files
committed
Merge with upstream
2 parents e169eb7 + 7a64ba9 commit b64252f

File tree

107 files changed

+23859
-536
lines changed

Some content is hidden

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

107 files changed

+23859
-536
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/GraalCompilerTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,28 +1773,28 @@ protected CanonicalizerPhase createCanonicalizerPhase() {
17731773
public static final String SEED_PROPERTY_NAME = "test.graal.random.seed";
17741774

17751775
/**
1776-
* Globally shared, lazily initialized random generator.
1776+
* Globally shared, lazily initialized random seed.
17771777
*/
1778-
private static volatile Random randomGenerator;
1778+
private static volatile Long randomSeed;
17791779

17801780
/**
1781-
* Returns a global {@link java.util.Random} generator. The generator is seeded with the value
1782-
* specified by {@link #SEED_PROPERTY_NAME} if it exists.
1781+
* Returns a {@link java.util.Random} generator with a global seed specified by
1782+
* {@link #SEED_PROPERTY_NAME} if it exists.
17831783
*
17841784
* The used seed printed to stdout for reproducing test failures.
17851785
*/
17861786
public static Random getRandomInstance() {
1787-
if (randomGenerator == null) {
1787+
if (randomSeed == null) {
17881788
synchronized (GraalCompilerTest.class) {
1789-
if (randomGenerator == null) {
1789+
if (randomSeed == null) {
17901790
var seedLong = Long.getLong(SEED_PROPERTY_NAME);
17911791
var seed = seedLong != null ? seedLong : new Random().nextLong();
17921792
System.out.printf("Random generator seed: %d%n", seed);
17931793
System.out.printf("To re-run test with same seed, set \"-D%s=%d\" on command line.%n", SEED_PROPERTY_NAME, seed);
1794-
randomGenerator = new Random(seed);
1794+
randomSeed = seed;
17951795
}
17961796
}
17971797
}
1798-
return randomGenerator;
1798+
return new Random(randomSeed);
17991799
}
18001800
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2024, 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 jdk.graal.compiler.core.test.ea;
26+
27+
import org.junit.Assert;
28+
import org.junit.Test;
29+
30+
import jdk.graal.compiler.core.test.GraalCompilerTest;
31+
import jdk.graal.compiler.nodes.StructuredGraph;
32+
import jdk.graal.compiler.nodes.StructuredGraph.AllowAssumptions;
33+
import jdk.graal.compiler.nodes.java.LoadFieldNode;
34+
import jdk.graal.compiler.virtual.phases.ea.ReadEliminationPhase;
35+
36+
public class FinalReadEliminationTest extends GraalCompilerTest {
37+
38+
static class A {
39+
final int x;
40+
41+
A(int x) {
42+
this.x = x;
43+
}
44+
}
45+
46+
static volatile int accross;
47+
48+
static int S;
49+
50+
public static int snippetAccessVolatile1(A a) {
51+
int load1 = a.x;
52+
S = accross;
53+
int load2 = a.x;
54+
return load1 + load2;
55+
}
56+
57+
@Test
58+
public void testAccrossVolatile01() {
59+
StructuredGraph g = parseEager(getResolvedJavaMethod("snippetAccessVolatile1"), AllowAssumptions.NO);
60+
createCanonicalizerPhase().apply(g, getDefaultHighTierContext());
61+
new ReadEliminationPhase(createCanonicalizerPhase()).apply(g, getDefaultHighTierContext());
62+
Assert.assertEquals(1, g.getNodes().filter(LoadFieldNode.class).filter(x -> !((LoadFieldNode) x).field().isVolatile()).count());
63+
}
64+
65+
public static int snippetAccessVolatile2(A a) {
66+
int load1 = a.x;
67+
accross = load1;
68+
int load2 = a.x;
69+
return load1 + load2;
70+
}
71+
72+
@Test
73+
public void testAccrossVolatile02() {
74+
StructuredGraph g = parseEager(getResolvedJavaMethod("snippetAccessVolatile2"), AllowAssumptions.NO);
75+
createCanonicalizerPhase().apply(g, getDefaultHighTierContext());
76+
new ReadEliminationPhase(createCanonicalizerPhase()).apply(g, getDefaultHighTierContext());
77+
Assert.assertEquals(2, g.getNodes().filter(LoadFieldNode.class).filter(x -> !((LoadFieldNode) x).field().isVolatile()).count());
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2024, 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 jdk.graal.compiler.core.test.ea;
26+
27+
import java.io.IOException;
28+
import java.lang.reflect.InvocationTargetException;
29+
import java.lang.reflect.Method;
30+
31+
import org.junit.Test;
32+
33+
import jdk.graal.compiler.core.test.SubprocessTest;
34+
import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
35+
import jdk.graal.compiler.hotspot.HotSpotBackend;
36+
import jdk.graal.compiler.test.SubprocessUtil;
37+
import jdk.vm.ci.code.InstalledCode;
38+
import jdk.vm.ci.code.InvalidInstalledCodeException;
39+
40+
public class ReadEliminationCodeEmissionTest extends SubprocessTest {
41+
42+
static class A {
43+
final int x;
44+
45+
A(int x) {
46+
this.x = x;
47+
}
48+
}
49+
50+
static volatile int accross;
51+
52+
static int S;
53+
54+
public static int accessVolatile1Snippet(A a) {
55+
int load1 = a.x;
56+
S = accross;
57+
int load2 = a.x;
58+
return load1 + load2;
59+
}
60+
61+
@Test
62+
public void accessVolatile1() {
63+
runTest("accessVolatile1", new A(12));
64+
}
65+
66+
public void runTest(String baseName, Object... args) {
67+
String snippetName = baseName + "Snippet";
68+
String methodSpec = getClass().getName() + "::" + snippetName;
69+
Method m = getMethod(snippetName);
70+
71+
Runnable run = () -> {
72+
// Force compilation with HotSpot
73+
for (int i = 0; i < 100000; i++) {
74+
try {
75+
Object[] finalArgs = applyArgSuppliers(args);
76+
m.invoke(null, finalArgs);
77+
} catch (IllegalAccessException | InvocationTargetException e) {
78+
throw new RuntimeException(e);
79+
}
80+
}
81+
if (args.length != 0) {
82+
Object[] nullArgs = args.clone();
83+
for (int i = 0; i < nullArgs.length; i++) {
84+
nullArgs[i] = null;
85+
}
86+
test(snippetName, nullArgs);
87+
}
88+
// Now generate JVMCI code
89+
InstalledCode code = getCode(getResolvedJavaMethod(snippetName));
90+
for (int i = 0; i < 100000; i++) {
91+
try {
92+
Object[] finalArgs = applyArgSuppliers(args);
93+
code.executeVarargs(finalArgs);
94+
if (i % 1000 == 0) {
95+
System.gc();
96+
}
97+
} catch (InvalidInstalledCodeException e) {
98+
throw new RuntimeException(e);
99+
}
100+
}
101+
102+
};
103+
104+
GraalHotSpotVMConfig config = ((HotSpotBackend) getBackend()).getRuntime().getVMConfig();
105+
SubprocessUtil.Subprocess subprocess = null;
106+
String logName = null;
107+
String[] vmArgs = new String[0];
108+
boolean print = Boolean.getBoolean("debug." + this.getClass().getName() + ".print");
109+
if (print) {
110+
logName = config.gc.name() + "_" + baseName + ".log";
111+
vmArgs = new String[]{"-XX:CompileCommand=print," + methodSpec,
112+
"-XX:CompileCommand=dontinline," + methodSpec,
113+
"-XX:+UnlockDiagnosticVMOptions",
114+
"-XX:-DisplayVMOutput",
115+
"-XX:-TieredCompilation",
116+
"-XX:+LogVMOutput",
117+
"-XX:+PreserveFramePointer",
118+
"-Xbatch",
119+
"-XX:LogFile=" + logName,
120+
"-Dgraal.Dump=:5"};
121+
}
122+
try {
123+
subprocess = launchSubprocess(baseName, run, vmArgs);
124+
} catch (InterruptedException | IOException e) {
125+
throw new RuntimeException(e);
126+
}
127+
if (subprocess != null && logName != null) {
128+
System.out.println("HotSpot output saved in " + logName);
129+
}
130+
}
131+
}

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public void testSquareToLen() {
121121
BigInteger big2 = randomBig(i);
122122

123123
// squareToLen is exercised via the call path modPow -> oddModPow -> montgomerySquare
124-
expectedResults.put(Pair.create(big1, big2), big1.modPow(bigTwo, big2));
124+
if (big2.signum() > 0) {
125+
expectedResults.put(Pair.create(big1, big2), big1.modPow(bigTwo, big2));
126+
}
125127
}
126128

127129
InstalledCode intrinsic = getCode(getResolvedJavaMethod(BigInteger.class, "squareToLen"), null, true, true, GraalCompilerTest.getInitialOptions());
@@ -151,19 +153,21 @@ public void testMontgomery() throws ClassNotFoundException {
151153
BigInteger big1 = randomBig(i);
152154
BigInteger big2 = randomBig(i);
153155

154-
// Invoke BigInteger BigInteger.modPow(BigExp, BigInteger)
155-
BigInteger res1 = (BigInteger) tin.invokeJava(big1, bigTwo, big2);
156+
if (big2.signum() > 0) {
157+
// Invoke BigInteger BigInteger.modPow(BigExp, BigInteger)
158+
BigInteger res1 = (BigInteger) tin.invokeJava(big1, bigTwo, big2);
156159

157-
// Invoke BigInteger testMontgomeryAux(BigInteger, BigExp, BigInteger)
158-
BigInteger res2 = (BigInteger) tin.invokeTest(big1, bigTwo, big2);
160+
// Invoke BigInteger testMontgomeryAux(BigInteger, BigExp, BigInteger)
161+
BigInteger res2 = (BigInteger) tin.invokeTest(big1, bigTwo, big2);
159162

160-
assertDeepEquals(res1, res2);
163+
assertDeepEquals(res1, res2);
161164

162-
// Invoke BigInteger testMontgomeryAux(BigInteger, BigExp, BigInteger)
163-
// through code handle.
164-
BigInteger res3 = (BigInteger) tin.invokeCode(big1, bigTwo, big2);
165+
// Invoke BigInteger testMontgomeryAux(BigInteger, BigExp, BigInteger)
166+
// through code handle.
167+
BigInteger res3 = (BigInteger) tin.invokeCode(big1, bigTwo, big2);
165168

166-
assertDeepEquals(res1, res3);
169+
assertDeepEquals(res1, res3);
170+
}
167171
}
168172
}
169173

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2024, 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 jdk.graal.compiler.truffle.test.strings;
26+
27+
import java.lang.invoke.MethodHandle;
28+
import java.lang.invoke.MethodHandles;
29+
import java.lang.reflect.Method;
30+
31+
import org.junit.Test;
32+
33+
import jdk.graal.compiler.nodes.StructuredGraph;
34+
import jdk.graal.compiler.replacements.nodes.CalcStringAttributesNode;
35+
36+
public class TStringOpsCalcStringAttributesMixedConstantTest extends TStringOpsConstantTest<CalcStringAttributesNode> {
37+
38+
private static final MethodHandle calcLatin1;
39+
private static final MethodHandle calcUTF16;
40+
41+
static {
42+
try {
43+
Method methodLatin1 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesLatin1", com.oracle.truffle.api.nodes.Node.class, Object.class, int.class, int.class);
44+
methodLatin1.setAccessible(true);
45+
calcLatin1 = MethodHandles.lookup().unreflect(methodLatin1);
46+
Method methodUTF16 = T_STRING_OPS_CLASS.getDeclaredMethod("calcStringAttributesUTF16", com.oracle.truffle.api.nodes.Node.class, Object.class, int.class, int.class, boolean.class);
47+
methodUTF16.setAccessible(true);
48+
calcUTF16 = MethodHandles.lookup().unreflect(methodUTF16);
49+
} catch (NoSuchMethodException | IllegalAccessException e) {
50+
throw new RuntimeException(e);
51+
}
52+
}
53+
54+
public TStringOpsCalcStringAttributesMixedConstantTest() {
55+
super(CalcStringAttributesNode.class, new byte[]{'a', 'b', 'c'}, 0, 3);
56+
}
57+
58+
@Test
59+
public void testMixed() throws Throwable {
60+
setConstantArgs(arrayA, offsetA, lengthA);
61+
runTestMethod(arrayA, offsetA, lengthA, false);
62+
runTestMethod(arrayA, offsetA, 1, true);
63+
test("runTestMethod", arrayA, offsetA, lengthA, false);
64+
}
65+
66+
public static long runTestMethod(Object array, int offset, int length, boolean condition) throws Throwable {
67+
if (condition) {
68+
return (long) calcUTF16.invokeExact(DUMMY_LOCATION, array, offset, length, false);
69+
} else {
70+
return (int) calcLatin1.invokeExact(DUMMY_LOCATION, array, offset, length);
71+
}
72+
}
73+
74+
@Override
75+
protected void checkLowTierGraph(StructuredGraph graph) {
76+
}
77+
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringOpsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class TStringOpsTest<T extends Node> extends TStringTest {
4949
protected static final com.oracle.truffle.api.nodes.Node DUMMY_LOCATION = new com.oracle.truffle.api.nodes.Node() {
5050
};
5151

52-
private static final Class<?> T_STRING_OPS_CLASS;
52+
protected static final Class<?> T_STRING_OPS_CLASS;
5353
private static final Constructor<?> T_STRING_NATIVE_POINTER_CONSTRUCTOR;
5454
private static final long byteBufferAddressOffset;
5555

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/util/ConstantReflectionUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ public static boolean shouldConstantFoldArrayOperation(CanonicalizerTool tool, i
8484
* @param arrayKind actual array kind, e.g. {@link JavaKind#Byte} for a {@code byte} array we
8585
* want to read a {@code char} from.
8686
*/
87-
public static void boundsCheckTypePunned(int typePunnedLength, Stride typePunnedStride, int arrayLength, JavaKind arrayKind) {
88-
GraalError.guarantee(typePunnedLength * typePunnedStride.value <= arrayLength * arrayKind.getByteCount(), Assertions.errorMessageContext(
87+
public static boolean boundsCheckTypePunned(int typePunnedLength, Stride typePunnedStride, int arrayLength, JavaKind arrayKind) {
88+
return typePunnedLength * typePunnedStride.value <= arrayLength * arrayKind.getByteCount();
89+
}
90+
91+
public static void boundsCheckTypePunnedGuarantee(int typePunnedLength, Stride typePunnedStride, int arrayLength, JavaKind arrayKind) {
92+
GraalError.guarantee(boundsCheckTypePunned(typePunnedLength, typePunnedStride, arrayLength, arrayKind), Assertions.errorMessageContext(
8993
"typePunnedLength", typePunnedLength,
9094
"typePunnedStride", typePunnedStride.value,
9195
"arrayLength", arrayLength,

0 commit comments

Comments
 (0)