Skip to content

Commit 55b63eb

Browse files
committed
[GR-64246] Limit Truffle installed code name length and avoid metadata reference in InvokeJavaMethodStub.
PullRequest: graal/20568
2 parents 91b53d3 + 9a191f0 commit 55b63eb

File tree

13 files changed

+379
-219
lines changed

13 files changed

+379
-219
lines changed

compiler/ci/ci_common/gate.jsonnet

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
"daily-compiler-ctw_economy-labsjdk-latest-darwin-amd64": {},
272272
"daily-compiler-ctw_economy-labsjdk-latest-darwin-aarch64": {},
273273

274-
"daily-compiler-bootstrap_lite-labsjdk-latest-darwin-amd64": t("1:00:00"),
274+
"daily-compiler-bootstrap_lite-labsjdk-latest-darwin-amd64": {},
275275

276276
"daily-compiler-bootstrap_full-labsjdk-latest-linux-amd64": s.many_cores,
277277
"daily-compiler-bootstrap_full_zgc-labsjdk-latest-linux-amd64": s.many_cores
@@ -298,17 +298,18 @@
298298
notify_emails: ["[email protected]"],
299299
},
300300

301-
"weekly-compiler-benchmarktest-labsjdk-latestDebug-linux-amd64": t("3:00:00"),
301+
"weekly-compiler-benchmarktest-labsjdk-latestDebug-linux-amd64": t("6:00:00"),
302+
"weekly-compiler-benchmarktest-labsjdk-latestDebug-darwin-aarch64": t("6:00:00"),
302303

303304
"weekly-compiler-coverage*": {},
304305

305-
"weekly-compiler-test_serialgc-labsjdk-latest-linux-amd64": t("1:30:00"),
306-
"weekly-compiler-test_serialgc-labsjdk-latest-linux-aarch64": t("1:50:00"),
307-
"weekly-compiler-test_serialgc-labsjdk-latest-darwin-amd64": t("1:30:00"),
308-
"weekly-compiler-test_serialgc-labsjdk-latest-darwin-aarch64": t("1:30:00"),
306+
"weekly-compiler-test_serialgc-labsjdk-latest-linux-amd64": {},
307+
"weekly-compiler-test_serialgc-labsjdk-latest-linux-aarch64": {},
308+
"weekly-compiler-test_serialgc-labsjdk-latest-darwin-amd64": {},
309+
"weekly-compiler-test_serialgc-labsjdk-latest-darwin-aarch64": {},
309310

310-
"weekly-compiler-truffle_xcomp_serialgc-labsjdk-latest-linux-amd64": t("1:30:00"),
311-
"weekly-compiler-truffle_xcomp_serialgc-labsjdk-latest-linux-aarch64": t("1:30:00"),
311+
"weekly-compiler-truffle_xcomp_serialgc-labsjdk-latest-linux-amd64": {},
312+
"weekly-compiler-truffle_xcomp_serialgc-labsjdk-latest-linux-aarch64": {},
312313
},
313314

314315
# This map defines overrides and field extensions for monthly builds.
@@ -502,9 +503,13 @@
502503
}],
503504

504505
# Builds run on only on linux-amd64-jdk-latestDebug
505-
local linux_amd64_jdk_latestDebug_builds = [self.make_build("LatestDebug", "linux-amd64", task).build
506+
local jdk_latestDebug_builds = [self.make_build("LatestDebug", os_arch, task).build
506507
for task in [
507-
"benchmarktest",
508+
"benchmarktest"
509+
]
510+
for os_arch in [
511+
"linux-amd64",
512+
"darwin-aarch64"
508513
]
509514
],
510515

@@ -517,7 +522,7 @@
517522
style_builds +
518523
jdk_21_version_check_builds +
519524
linux_amd64_jdk_latest_builds +
520-
linux_amd64_jdk_latestDebug_builds,
525+
jdk_latestDebug_builds,
521526

522527
local _builds = if
523528
self.check_manifest(gates, all_builds, std.thisFile, "gates").result &&
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2025, 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.common.test;
26+
27+
import jdk.graal.compiler.core.common.util.Util;
28+
import org.junit.Assert;
29+
import org.junit.Test;
30+
31+
/**
32+
* Tests for {@link jdk.graal.compiler.core.common.util.Util}.
33+
*/
34+
public class UtilTest {
35+
36+
@Test
37+
public void truncateStringTest1() {
38+
for (int max = 1; max < 1024; max++) {
39+
40+
String[] inputs = {
41+
"X".repeat(max - 1),
42+
"X".repeat(max),
43+
"X".repeat(max + 1),
44+
};
45+
for (String s : inputs) {
46+
if (max <= Util.TRUNCATION_PLACEHOLDER.length()) {
47+
try {
48+
Util.truncateString(s, max);
49+
throw new AssertionError("expected " + IllegalArgumentException.class.getName());
50+
} catch (IllegalArgumentException e) {
51+
// expected
52+
}
53+
} else {
54+
String cs = Util.truncateString(s, max);
55+
if (s.length() <= max) {
56+
Assert.assertEquals(s, cs);
57+
} else {
58+
Assert.assertNotEquals(s, cs);
59+
Assert.assertTrue(cs, cs.contains("<truncated"));
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
@Test
67+
public void truncateStringTest2() {
68+
int max = 40;
69+
70+
// Tests example from javadoc
71+
String s = "123456789_123456789_123456789_123456789_123456789_";
72+
String cs = Util.truncateString(s, max);
73+
Assert.assertEquals(50, s.length());
74+
Assert.assertEquals(32, cs.length());
75+
Assert.assertEquals("123<truncated(43, c285d1fd)>789_", cs);
76+
}
77+
}

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

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@
2424
*/
2525
package jdk.graal.compiler.hotspot.test;
2626

27+
import static jdk.graal.compiler.replacements.SnippetTemplate.AbstractTemplates.findMethod;
28+
29+
import org.junit.Assume;
30+
import org.junit.Before;
31+
import org.junit.Test;
32+
2733
import jdk.graal.compiler.hotspot.meta.HotSpotForeignCallDescriptor;
2834
import jdk.graal.compiler.hotspot.meta.HotSpotHostForeignCallsProvider.TestForeignCalls;
35+
import jdk.graal.compiler.nodes.ConstantNode;
2936
import jdk.graal.compiler.nodes.ValueNode;
3037
import jdk.graal.compiler.nodes.extended.ForeignCallNode;
3138
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
3239
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
3340
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
34-
import org.junit.Assume;
35-
import org.junit.Before;
36-
import org.junit.Test;
37-
3841
import jdk.vm.ci.meta.JavaKind;
3942
import jdk.vm.ci.meta.ResolvedJavaMethod;
4043

@@ -45,12 +48,14 @@ protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
4548
for (JavaKind kind : TestForeignCalls.KINDS) {
4649
HotSpotForeignCallDescriptor desc = TestForeignCalls.createStubCallDescriptor(kind);
4750
String name = desc.getName();
48-
Class<?> argType = desc.getSignature().getArgumentTypes()[0];
51+
Class<?> argType = desc.getSignature().getArgumentTypes()[1];
4952
invocationPlugins.register(HotSpotInvokeJavaMethodTest.class, new InvocationPlugin(name, argType) {
5053
@Override
5154
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode arg) {
52-
ForeignCallNode node = new ForeignCallNode(desc, arg);
53-
b.addPush(kind, node);
55+
ResolvedJavaMethod javaMethod = findMethod(b.getMetaAccess(), HotSpotInvokeJavaMethodTest.class, desc.getName());
56+
ValueNode method = ConstantNode.forConstant(b.getStampProvider().createMethodStamp(), javaMethod.getEncoding(), b.getMetaAccess(), b.getGraph());
57+
ForeignCallNode node = new ForeignCallNode(desc, method, arg);
58+
b.add(node);
5459
return true;
5560
}
5661
});
@@ -63,132 +68,137 @@ public void before() {
6368
Assume.assumeTrue("Invoke stub helper is missing", runtime().getVMConfig().invokeJavaMethodAddress != 0);
6469
}
6570

71+
static Object passedArg;
72+
6673
static boolean[] booleanValues = new boolean[]{Boolean.TRUE, Boolean.FALSE};
6774

68-
static boolean booleanReturnsBoolean(boolean arg) {
69-
return arg;
75+
static void passingBoolean(boolean arg) {
76+
passedArg = arg;
7077
}
7178

72-
public static boolean booleanReturnsBooleanSnippet(boolean arg) {
73-
return booleanReturnsBoolean(arg);
79+
public static boolean passingBooleanSnippet(boolean arg) {
80+
passedArg = null;
81+
passingBoolean(arg);
82+
return (boolean) passedArg;
7483
}
7584

7685
@Test
77-
public void testBooleanReturnsBoolean() {
86+
public void testPassingBoolean() {
7887
for (boolean value : booleanValues) {
79-
test("booleanReturnsBooleanSnippet", value);
88+
test("passingBooleanSnippet", value);
8089
}
8190
}
8291

8392
static byte[] byteValues = new byte[]{Byte.MAX_VALUE, -1, 0, 1, Byte.MIN_VALUE};
8493

85-
static byte byteReturnsByte(byte arg) {
86-
return arg;
94+
static void passingByte(byte arg) {
95+
passedArg = arg;
8796
}
8897

89-
public static byte byteReturnsByteSnippet(byte arg) {
90-
return byteReturnsByte(arg);
98+
public static void passingByteSnippet(byte arg) {
99+
passedArg = null;
100+
passingByte(arg);
91101
}
92102

93103
@Test
94-
public void testByteReturnsByte() {
104+
public void testPassingByte() {
95105
for (byte value : byteValues) {
96-
test("byteReturnsByteSnippet", value);
106+
test("passingByteSnippet", value);
97107
}
98108
}
99109

100110
static short[] shortValues = new short[]{Short.MAX_VALUE, -1, 0, 1, Short.MIN_VALUE};
101111

102-
static short shortReturnsShort(short arg) {
103-
return arg;
112+
static void passingShort(short arg) {
113+
passedArg = arg;
104114
}
105115

106-
public static short shortReturnsShortSnippet(short arg) {
107-
return shortReturnsShort(arg);
116+
public static short passingShortSnippet(short arg) {
117+
passedArg = null;
118+
passingShort(arg);
119+
return (short) passedArg;
108120
}
109121

110122
@Test
111-
public void testShortReturnsShort() {
123+
public void testPassingShort() {
112124
for (short value : shortValues) {
113-
test("shortReturnsShortSnippet", value);
125+
test("passingShortSnippet", value);
114126
}
115127
}
116128

117129
static char[] charValues = new char[]{Character.MAX_VALUE, 1, Character.MIN_VALUE};
118130

119-
static char charReturnsChar(char arg) {
120-
return arg;
131+
static void passingChar(char arg) {
132+
passedArg = arg;
121133
}
122134

123-
public static char charReturnsCharSnippet(char arg) {
124-
return charReturnsChar(arg);
135+
public static char passingCharSnippet(char arg) {
136+
passedArg = null;
137+
passingChar(arg);
138+
return (char) passedArg;
125139
}
126140

127141
@Test
128-
public void testCharReturnsChar() {
142+
public void testPassingChar() {
129143
for (char value : charValues) {
130-
test("charReturnsCharSnippet", value);
144+
test("passingCharSnippet", value);
131145
}
132146
}
133147

134148
static int[] intValues = new int[]{Integer.MAX_VALUE, -1, 0, 1, Integer.MIN_VALUE};
135149

136-
static int intReturnsInt(int arg) {
137-
return arg;
150+
static void passingInt(int arg) {
151+
passedArg = arg;
138152
}
139153

140-
public static int intReturnsIntSnippet(int arg) {
141-
return intReturnsInt(arg);
154+
public static int passingIntSnippet(int arg) {
155+
passedArg = null;
156+
passingInt(arg);
157+
return (int) passedArg;
142158
}
143159

144160
@Test
145-
public void testIntReturnsInt() {
161+
public void testPassingInt() {
146162
for (int value : intValues) {
147-
test("intReturnsIntSnippet", value);
163+
test("passingIntSnippet", value);
148164
}
149165
}
150166

151167
static long[] longValues = new long[]{Long.MAX_VALUE, -1, 0, 1, Long.MIN_VALUE};
152168

153-
static long longReturnsLong(long arg) {
154-
return arg;
169+
static void passingLong(long arg) {
170+
passedArg = arg;
155171
}
156172

157-
public static long longReturnsLongSnippet(long arg) {
158-
return longReturnsLong(arg);
173+
public static long passingLongSnippet(long arg) {
174+
passedArg = null;
175+
passingLong(arg);
176+
return (long) passedArg;
159177
}
160178

161179
@Test
162-
public void testLongReturnsLong() {
180+
public void testPassingLong() {
163181
for (long value : longValues) {
164-
test("longReturnsLongSnippet", value);
182+
test("passingLongSnippet", value);
165183
}
166184
}
167185

168-
static float[] floatValues = new float[]{Float.MAX_VALUE, -1, 0, 1, Float.MIN_VALUE};
169-
170-
static float floatReturnsFloat(float arg) {
171-
return arg;
172-
}
173-
174-
public static float floatReturnsFloatSnippet(float arg) {
175-
return floatReturnsFloat(arg);
176-
}
177-
178186
static Object[] objectValues = new Object[]{null, "String", Integer.valueOf(-1)};
179187

180-
static Object objectReturnsObject(Object arg) {
181-
return arg;
188+
static void passingObject(Object arg) {
189+
passedArg = arg;
182190
}
183191

184-
public static Object objectReturnsObjectSnippet(Object arg) {
185-
return objectReturnsObject(arg);
192+
public static Object passingObjectSnippet(Object arg) {
193+
passedArg = null;
194+
passingObject(arg);
195+
return passedArg;
186196
}
187197

188198
@Test
189-
public void testObjectReturnsObject() {
199+
public void testPassingObject() {
190200
for (Object value : objectValues) {
191-
test("objectReturnsObjectSnippet", value);
201+
test("passingObjectSnippet", value);
192202
}
193203
}
194204
}

0 commit comments

Comments
 (0)