Skip to content

Commit 65eea93

Browse files
authored
Merge pull request #55 from zakkak/2025-03-13-backports-23.1.5-batch8
2 parents a01d2fd + 2769491 commit 65eea93

File tree

21 files changed

+271
-236
lines changed

21 files changed

+271
-236
lines changed

common.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.8+2-jvmci-23.1-b02-sulong", "platformspecific": true },
2020

2121
"oraclejdk21": {"name": "jpg-jdk", "version": "21", "build_id": "33", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
22-
"labsjdk-ce-21": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46", "platformspecific": true },
23-
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46-debug", "platformspecific": true },
24-
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46-sulong", "platformspecific": true },
25-
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46", "platformspecific": true },
26-
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46-debug", "platformspecific": true },
27-
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.5+7-jvmci-23.1-b46-sulong", "platformspecific": true },
22+
"labsjdk-ce-21": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48", "platformspecific": true },
23+
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48-debug", "platformspecific": true },
24+
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48-sulong", "platformspecific": true },
25+
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48", "platformspecific": true },
26+
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48-debug", "platformspecific": true },
27+
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.5+9-jvmci-23.1-b48-sulong", "platformspecific": true },
2828

2929
"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "2", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
3030
},

compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/SubprocessTest.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
*/
2525
package org.graalvm.compiler.core.test;
2626

27+
import static org.graalvm.compiler.test.SubprocessUtil.getProcessCommandLine;
2728
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
2829
import static org.graalvm.compiler.test.SubprocessUtil.java;
2930
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
3031

3132
import java.io.IOException;
3233
import java.util.Arrays;
34+
import java.util.LinkedList;
3335
import java.util.List;
3436
import java.util.function.Predicate;
3537

@@ -38,6 +40,23 @@
3840
import org.junit.Assume;
3941
import org.junit.Before;
4042

43+
/**
44+
* Utility class for executing Graal compiler tests in a subprocess. This can be useful for tests
45+
* that need special VM arguments or that produce textual output or a special process termination
46+
* status that need to be analyzed. The class to be executed may be the current class or any other
47+
* unit test class.
48+
* <p/>
49+
* If the test class contains multiple {@code @Test} methods, they will all be executed in the
50+
* subprocess, except when using one of the methods that take a {@code testSelector} argument. All
51+
* methods in this class take a {@link Runnable} argument. If the test class is the same as the
52+
* calling class, this runnable defines the operation to be executed in the subprocess. If the test
53+
* class is not the same as the calling class, the runnable is irrelevant and can be a nop.
54+
* <p/>
55+
* The subprocess will inherit any {@code -JUnitVerbose} flag (typically set through
56+
* {@code mx unittest --verbose}) from the parent process. If this flag is set, the standard output
57+
* of the child process will be echoed to the standard output of the parent process. If the child
58+
* process terminates with an error, its standard output will always be printed.
59+
*/
4160
public abstract class SubprocessTest extends GraalCompilerTest {
4261

4362
@Before
@@ -54,16 +73,24 @@ public void checkJavaAgent() {
5473
* {@link Subprocess} instance describing the process after its successful termination.
5574
*/
5675
public SubprocessUtil.Subprocess launchSubprocess(Runnable runnable, String... args) throws InterruptedException, IOException {
57-
return launchSubprocess(null, true, getClass(), runnable, args);
76+
return launchSubprocess(null, true, getClass(), null, runnable, args);
5877
}
5978

6079
public static SubprocessUtil.Subprocess launchSubprocess(Class<? extends GraalCompilerTest> testClass, Runnable runnable, String... args) throws InterruptedException, IOException {
61-
return launchSubprocess(null, true, testClass, runnable, args);
80+
return launchSubprocess(null, true, testClass, null, runnable, args);
81+
}
82+
83+
public void launchSubprocess(String testSelector, Runnable runnable, String... args) throws InterruptedException, IOException {
84+
launchSubprocess(null, true, getClass(), testSelector, runnable, args);
85+
}
86+
87+
public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>> testPredicate, boolean expectNormalExit, Class<? extends GraalCompilerTest> testClass,
88+
Runnable runnable, String... args) throws InterruptedException, IOException {
89+
return launchSubprocess(testPredicate, expectNormalExit, testClass, null, runnable, args);
6290
}
6391

64-
public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>> testPredicate, boolean expectNormalExit, Class<? extends GraalCompilerTest> testClass, Runnable runnable,
65-
String... args)
66-
throws InterruptedException, IOException {
92+
public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>> testPredicate, boolean expectNormalExit, Class<? extends GraalCompilerTest> testClass, String testSelector,
93+
Runnable runnable, String... args) throws InterruptedException, IOException {
6794
String recursionPropName = testClass.getSimpleName() + ".Subprocess";
6895
if (Boolean.getBoolean(recursionPropName)) {
6996
runnable.run();
@@ -77,7 +104,18 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
77104
if (verbose) {
78105
System.err.println(String.join(" ", vmArgs));
79106
}
80-
SubprocessUtil.Subprocess proc = java(vmArgs, "com.oracle.mxtool.junit.MxJUnitWrapper", testClass.getName());
107+
List<String> mainClassAndArgs = new LinkedList<>();
108+
mainClassAndArgs.add("com.oracle.mxtool.junit.MxJUnitWrapper");
109+
String testName = testClass.getName();
110+
if (testSelector != null) {
111+
testName += "#" + testSelector;
112+
}
113+
mainClassAndArgs.add(testName);
114+
boolean junitVerbose = getProcessCommandLine().contains("-JUnitVerbose");
115+
if (junitVerbose) {
116+
mainClassAndArgs.add("-JUnitVerbose");
117+
}
118+
SubprocessUtil.Subprocess proc = java(vmArgs, mainClassAndArgs);
81119
if (testPredicate != null) {
82120
assertTrue(testPredicate.test(proc.output), proc.toString() + " produced unexpected output:\n\n" + String.join("\n", proc.output));
83121
}
@@ -91,6 +129,13 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
91129
} else {
92130
assertTrue(proc.exitCode != 0, proc.toString() + " produced normal exit code " + proc.exitCode + ", but expected abnormal exit.");
93131
}
132+
if (junitVerbose) {
133+
System.out.println("--- subprocess output:");
134+
for (String line : proc.output) {
135+
System.out.println(line);
136+
}
137+
System.out.println("--- end subprocess output");
138+
}
94139
return proc;
95140
}
96141
}

compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyFoldableMethods.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
package org.graalvm.compiler.core.test;
2626

2727
import java.util.Map;
28+
import java.util.Set;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.stream.Collectors;
3031

3132
import org.graalvm.compiler.api.replacements.Fold;
33+
import org.graalvm.compiler.nodes.PluginReplacementNode;
3234
import org.graalvm.compiler.nodes.StructuredGraph;
3335
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
3436
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
@@ -39,7 +41,9 @@
3941
import jdk.vm.ci.meta.ResolvedJavaType;
4042

4143
/**
42-
* Verifies that all {@link Fold} annotated methods have at least one caller.
44+
* Verifies that all {@link Fold} annotated methods have at least one caller from non-generated
45+
* code. Ideally, the class should verify that foldable methods are only called from snippets but
46+
* that requires a more global analysis (i.e., to know whether a caller is used within a snippet).
4347
*/
4448
public class VerifyFoldableMethods extends VerifyPhase<CoreProviders> {
4549

@@ -48,32 +52,59 @@ public boolean checkContract() {
4852
return false;
4953
}
5054

51-
private final Map<ResolvedJavaMethod, Boolean> foldables = new ConcurrentHashMap<>();
52-
ResolvedJavaType generatedInvocationPluginType;
55+
/**
56+
* Map from a foldable method to one of its callers. The absence of a caller is represented a
57+
* foldable method mapping to itself.
58+
*/
59+
private final Map<ResolvedJavaMethod, ResolvedJavaMethod> foldableCallers = new ConcurrentHashMap<>();
60+
61+
/*
62+
* Super types or interfaces for generated classes. Calls from methods in these classes are
63+
* ignored.
64+
*/
65+
Set<ResolvedJavaType> generatedClassSupertypes;
66+
67+
/**
68+
* Determines if {@code method} is in a generated class.
69+
*/
70+
private boolean isGenerated(ResolvedJavaMethod method, CoreProviders context) {
71+
if (generatedClassSupertypes == null) {
72+
generatedClassSupertypes = Set.of(
73+
context.getMetaAccess().lookupJavaType(GeneratedInvocationPlugin.class),
74+
context.getMetaAccess().lookupJavaType(PluginReplacementNode.ReplacementFunction.class));
75+
}
76+
ResolvedJavaType declaringClass = method.getDeclaringClass();
77+
for (ResolvedJavaType t : generatedClassSupertypes) {
78+
if (t.isAssignableFrom(declaringClass)) {
79+
return true;
80+
}
81+
}
82+
return false;
83+
}
5384

5485
@Override
5586
protected void verify(StructuredGraph graph, CoreProviders context) {
5687
ResolvedJavaMethod method = graph.method();
5788
if (method.getAnnotation(Fold.class) != null) {
58-
foldables.putIfAbsent(method, false);
89+
foldableCallers.putIfAbsent(method, method);
5990
} else {
60-
if (generatedInvocationPluginType == null) {
61-
generatedInvocationPluginType = context.getMetaAccess().lookupJavaType(GeneratedInvocationPlugin.class);
62-
}
63-
if (!generatedInvocationPluginType.isAssignableFrom(method.getDeclaringClass())) {
91+
if (!isGenerated(method, context)) {
6492
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
6593
ResolvedJavaMethod callee = t.targetMethod();
6694
if (callee.getAnnotation(Fold.class) != null) {
67-
foldables.put(callee, true);
95+
foldableCallers.put(callee, method);
6896
}
6997
}
7098
}
7199
}
72100
}
73101

74102
public void finish() {
75-
String uncalled = foldables.entrySet().stream().filter(e -> e.getValue() == false).map(e -> e.getKey().format("%H.%n(%p)")).collect(Collectors.joining(System.lineSeparator() + " "));
76-
if (uncalled.length() != 0) {
103+
String uncalled = foldableCallers.entrySet().stream()//
104+
.filter(e -> e.getValue() == e.getKey())//
105+
.map(e -> e.getKey().format("%H.%n(%p)"))//
106+
.collect(Collectors.joining(System.lineSeparator() + " "));
107+
if (!uncalled.isEmpty()) {
77108
throw new VerificationError(String.format("Methods annotated with @" + Fold.class.getSimpleName() + " appear to have no usages:%n %s", uncalled));
78109
}
79110
}

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,6 @@ private static String markWordField(String simpleName) {
484484

485485
public final int methodCompiledEntryOffset = getFieldOffset("Method::_from_compiled_entry", Integer.class, "address");
486486

487-
public final int invocationCounterOffset = getFieldOffset("MethodCounters::_invocation_counter", Integer.class, "InvocationCounter");
488-
public final int backedgeCounterOffset = getFieldOffset("MethodCounters::_backedge_counter", Integer.class, "InvocationCounter");
489-
public final int invocationCounterIncrement = getConstant("InvocationCounter::count_increment", Integer.class);
490-
public final int invocationCounterShift = getConstant("InvocationCounter::count_shift", Integer.class);
491-
492487
public final int compilationLevelFullOptimization = getConstant("CompLevel_full_optimization", Integer.class);
493488

494489
public final int heapWordSize = getConstant("HeapWordSize", Integer.class);

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/replacements/HotSpotG1WriteBarrierSnippets.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
import jdk.vm.ci.code.Register;
6060
import jdk.vm.ci.meta.JavaKind;
61-
import jdk.vm.ci.meta.ResolvedJavaType;
6261

6362
public final class HotSpotG1WriteBarrierSnippets extends G1WriteBarrierSnippets {
6463
public static final HotSpotForeignCallDescriptor G1WBPRECALL = new HotSpotForeignCallDescriptor(LEAF_NO_VZERO, REEXECUTABLE, KILLED_PRE_WRITE_BARRIER_STUB_LOCATIONS, "write_barrier_pre",
@@ -176,16 +175,6 @@ protected ForeignCallDescriptor printfCallDescriptor() {
176175
return Log.LOG_PRINTF;
177176
}
178177

179-
@Override
180-
protected ResolvedJavaType referenceType() {
181-
return HotSpotReplacementsUtil.referenceType(INJECTED_METAACCESS);
182-
}
183-
184-
@Override
185-
protected long referentOffset() {
186-
return HotSpotReplacementsUtil.referentOffset(INJECTED_METAACCESS);
187-
}
188-
189178
public static class Templates extends AbstractTemplates {
190179
private final SnippetInfo g1PreWriteBarrier;
191180
private final SnippetInfo g1ReferentReadBarrier;

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/replacements/HotSpotReplacementsUtil.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -383,26 +383,6 @@ public static int allocatePrefetchStepSize(@InjectedParameter GraalHotSpotVMConf
383383
return config.allocatePrefetchStepSize;
384384
}
385385

386-
@Fold
387-
public static int invocationCounterIncrement(@InjectedParameter GraalHotSpotVMConfig config) {
388-
return config.invocationCounterIncrement;
389-
}
390-
391-
@Fold
392-
public static int invocationCounterOffset(@InjectedParameter GraalHotSpotVMConfig config) {
393-
return config.invocationCounterOffset;
394-
}
395-
396-
@Fold
397-
public static int backedgeCounterOffset(@InjectedParameter GraalHotSpotVMConfig config) {
398-
return config.backedgeCounterOffset;
399-
}
400-
401-
@Fold
402-
public static int invocationCounterShift(@InjectedParameter GraalHotSpotVMConfig config) {
403-
return config.invocationCounterShift;
404-
}
405-
406386
@NodeIntrinsic(value = KlassLayoutHelperNode.class)
407387
public static native int readLayoutHelper(KlassPointer object);
408388

@@ -833,11 +813,6 @@ static Word readInstanceKlassInitThread(KlassPointer hub) {
833813

834814
public static final LocationIdentity KLASS_MODIFIER_FLAGS_LOCATION = NamedLocationIdentity.immutable("Klass::_modifier_flags");
835815

836-
@Fold
837-
public static int klassModifierFlagsOffset(@InjectedParameter GraalHotSpotVMConfig config) {
838-
return config.klassModifierFlagsOffset;
839-
}
840-
841816
public static final LocationIdentity CLASS_KLASS_LOCATION = new HotSpotOptimizingLocationIdentity("Class._klass") {
842817
@Override
843818
public ValueNode canonicalizeRead(ValueNode read, ValueNode object, ValueNode location, CoreProviders tool) {
@@ -936,19 +911,12 @@ public static String referentFieldName() {
936911
return "referent";
937912
}
938913

939-
@Fold
940914
public static long referentOffset(@InjectedParameter MetaAccessProvider metaAccessProvider) {
941915
return referentField(metaAccessProvider).getOffset();
942916
}
943917

944-
@Fold
945918
public static ResolvedJavaField referentField(@InjectedParameter MetaAccessProvider metaAccessProvider) {
946-
return getField(referenceType(metaAccessProvider), referentFieldName());
947-
}
948-
949-
@Fold
950-
public static ResolvedJavaType referenceType(@InjectedParameter MetaAccessProvider metaAccessProvider) {
951-
return metaAccessProvider.lookupJavaType(Reference.class);
919+
return getField(metaAccessProvider.lookupJavaType(Reference.class), referentFieldName());
952920
}
953921

954922
public static final LocationIdentity OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION = new HotSpotOptimizingLocationIdentity("ObjArrayKlass::_element_klass") {

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/stubs/ForeignCallSnippets.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ public static Object verifyObject(Object object) {
111111
return object;
112112
}
113113

114-
@Fold
115-
static long verifyOopMask(@InjectedParameter GraalHotSpotVMConfig config) {
116-
return config.verifyOopMask;
117-
}
118-
119-
@Fold
120-
static long verifyOopBits(@InjectedParameter GraalHotSpotVMConfig config) {
121-
return config.verifyOopBits;
122-
}
123-
124114
/**
125115
* Gets and clears the object result from a runtime call stored in a thread local.
126116
*

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/replacements/ReplacementsUtil.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public static int getArrayBaseOffset(@InjectedParameter MetaAccessProvider metaA
8080
return metaAccessProvider.getArrayBaseOffset(elementKind);
8181
}
8282

83-
@Fold
84-
public static int charArrayBaseOffset(@InjectedParameter MetaAccessProvider metaAccess) {
85-
return metaAccess.getArrayBaseOffset(JavaKind.Char);
86-
}
87-
8883
@Fold
8984
public static long charArrayIndexScale(@InjectedParameter MetaAccessProvider metaAccess) {
9085
return metaAccess.getArrayIndexScale(JavaKind.Char);

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/replacements/gc/G1WriteBarrierSnippets.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@
6969
import org.graalvm.word.UnsignedWord;
7070
import org.graalvm.word.WordFactory;
7171

72-
import jdk.vm.ci.meta.ResolvedJavaType;
73-
7472
/**
7573
* Implementation of the write barriers for the G1 garbage collector.
7674
*/
@@ -374,10 +372,6 @@ public void g1ArrayRangePostWriteBarrier(Address address, long length, @Constant
374372

375373
protected abstract ForeignCallDescriptor printfCallDescriptor();
376374

377-
protected abstract ResolvedJavaType referenceType();
378-
379-
protected abstract long referentOffset();
380-
381375
protected boolean isTracingActive(int traceStartCycle) {
382376
return traceStartCycle > 0 && ((Pointer) WordFactory.pointer(gcTotalCollectionsAddress())).readInt(0) > traceStartCycle;
383377
}

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/KnownTruffleTypes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public class KnownTruffleTypes extends AbstractKnownTruffleTypes {
166166
public final ResolvedJavaField OptimizedCallTarget_rootNode = findField(OptimizedCallTarget, "rootNode");
167167

168168
public final ResolvedJavaType OptimizedDirectCallNode = lookupTypeCached("com.oracle.truffle.runtime.OptimizedDirectCallNode");
169-
public final ResolvedJavaField OptimizedDirectCallNode_currentCallTarget = findField(OptimizedDirectCallNode, "currentCallTarget");
170169
public final ResolvedJavaField OptimizedDirectCallNode_inliningForced = findField(OptimizedDirectCallNode, "inliningForced");
171170
public final ResolvedJavaField OptimizedDirectCallNode_callCount = findField(OptimizedDirectCallNode, "callCount");
172171

0 commit comments

Comments
 (0)