Skip to content

Commit e99852b

Browse files
Merge remote-tracking branch 'origin/master' into labsjdk/adopt-26+12-master
2 parents 82fcbc2 + dfbe2f1 commit e99852b

File tree

168 files changed

+4484
-6150
lines changed

Some content is hidden

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

168 files changed

+4484
-6150
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/replaycomp/test/ReplayCompilationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
import org.graalvm.collections.EconomicMap;
4040
import org.graalvm.collections.EconomicSet;
41+
import org.junit.AfterClass;
42+
import org.junit.BeforeClass;
4143
import org.junit.Test;
4244

4345
import com.oracle.truffle.api.Truffle;
@@ -46,6 +48,7 @@
4648
import jdk.graal.compiler.core.CompilationWrapper;
4749
import jdk.graal.compiler.core.GraalCompilerOptions;
4850
import jdk.graal.compiler.core.test.GraalCompilerTest;
51+
import jdk.graal.compiler.debug.DebugCloseable;
4952
import jdk.graal.compiler.debug.DebugOptions;
5053
import jdk.graal.compiler.debug.GlobalMetrics;
5154
import jdk.graal.compiler.debug.LogStream;
@@ -54,9 +57,11 @@
5457
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
5558
import jdk.graal.compiler.hotspot.HotSpotGraalCompiler;
5659
import jdk.graal.compiler.hotspot.HotSpotGraalCompilerFactory;
60+
import jdk.graal.compiler.hotspot.HotSpotReplacementsImpl;
5761
import jdk.graal.compiler.hotspot.replaycomp.CompilerInterfaceDeclarations;
5862
import jdk.graal.compiler.hotspot.replaycomp.ReplayCompilationRunner;
5963
import jdk.graal.compiler.options.OptionValues;
64+
import jdk.graal.compiler.phases.util.Providers;
6065
import jdk.graal.compiler.runtime.RuntimeProvider;
6166
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
6267
import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
@@ -69,6 +74,25 @@
6974
* Tests for compilation recording and replay.
7075
*/
7176
public class ReplayCompilationTest extends GraalCompilerTest {
77+
/**
78+
* A separate encoded snippet scope is necessary in case the global encoded snippets have cache
79+
* replacements.
80+
*/
81+
private static DebugCloseable snippetScope;
82+
83+
@BeforeClass
84+
public static void setup() {
85+
Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders();
86+
HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements();
87+
snippetScope = replacements.suppressEncodedSnippets();
88+
replacements.encode(getInitialOptions());
89+
}
90+
91+
@AfterClass
92+
public static void teardown() {
93+
snippetScope.close();
94+
}
95+
7296
private static int[] lengthsSquared(List<String> strings) {
7397
return strings.stream().mapToInt(String::length).map(i -> i * i).toArray();
7498
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/util/CompilationAlarm.java

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ public static class Options {
7171
private final CompilationAlarm previous;
7272

7373
@SuppressWarnings("this-escape")
74-
private CompilationAlarm(double period) {
74+
private CompilationAlarm(double period, boolean skipZeros) {
7575
this.previous = currentAlarm.get();
7676
reset(period);
7777
JMXService.GCTimeStatistics timing = null;
7878
if (period != 0) {
7979
timing = GraalServices.getGCTimeStatistics();
8080
}
8181
this.gcTiming = timing;
82+
this.skipZeros = skipZeros;
8283
}
8384

8485
/**
@@ -113,7 +114,7 @@ public static double scaleExpirationPeriod(double period, OptionValues options)
113114
*/
114115
private static final ThreadLocal<CompilationAlarm> currentAlarm = new ThreadLocal<>();
115116

116-
private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm(0);
117+
private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm(0, false);
117118

118119
/**
119120
* Gets the current compilation alarm. If there is no current alarm, a non-null value is
@@ -183,7 +184,8 @@ public boolean isEnabled() {
183184
public void checkExpiration() {
184185
if (hasExpired()) {
185186

186-
setCurrentNodeDuration(currentNode.name);
187+
// also set all parent node times
188+
setCurrentNodeDuration(currentNode.name, true);
187189

188190
/*
189191
* We clone the phase tree here for the sake of the error message. We want to fix up the
@@ -194,7 +196,7 @@ public void checkExpiration() {
194196
StringBuilder sb = new StringBuilder();
195197
// also update the root time to be consistent for the error message
196198
cloneTree.durationNS = elapsed();
197-
printTree("", sb, cloneTree, true);
199+
printTree("", sb, cloneTree, true, skipZeros);
198200

199201
// Include information about time spent in the GC if it's available.
200202
String gcMessage = "";
@@ -227,6 +229,11 @@ public void close() {
227229
*/
228230
private final JMXService.GCTimeStatistics gcTiming;
229231

232+
/**
233+
* On timeout skip zero entries.
234+
*/
235+
private final boolean skipZeros;
236+
230237
/**
231238
* Signal the execution of the phase identified by {@code name} starts.
232239
*/
@@ -296,7 +303,7 @@ public void exitPhase(CharSequence name, StructuredGraph graph) {
296303
currentNode = currentNode.parent;
297304
}
298305
assert currentNode.name.equals(name) : Assertions.errorMessage("Must see the same phase that was opened in the close operation", name, elapsedPhaseTreeAsString());
299-
setCurrentNodeDuration(name);
306+
setCurrentNodeDuration(name, false);
300307
currentNode.closed = true;
301308
if (graph != null) {
302309
currentNode.graphSizeAfter = graph.getNodeCount();
@@ -316,9 +323,17 @@ private boolean graphMarksIntermediateRootEnd(StructuredGraph graph) {
316323
return currentNode instanceof PhaseTreeIntermediateRoot && currentNode.graph != null && graph != null && !currentNode.graph.equals(graph);
317324
}
318325

319-
private void setCurrentNodeDuration(CharSequence name) {
326+
private void setCurrentNodeDuration(CharSequence name, boolean setParentTime) {
320327
assert currentNode.startTimeNS >= 0 : Assertions.errorMessage("Must have a positive start time", name, elapsedPhaseTreeAsString());
321-
currentNode.durationNS = System.nanoTime() - currentNode.startTimeNS;
328+
long currentTimeNano = System.nanoTime();
329+
currentNode.durationNS = currentTimeNano - currentNode.startTimeNS;
330+
if (setParentTime) {
331+
PhaseTreeNode node = currentNode.parent;
332+
while (node != null) {
333+
node.durationNS = currentTimeNano - node.startTimeNS;
334+
node = node.parent;
335+
}
336+
}
322337
}
323338

324339
/**
@@ -413,6 +428,10 @@ public String toString() {
413428
"->" + graphSizeAfter + "]";
414429
}
415430

431+
private boolean durationZeroInMS() {
432+
return TimeUnit.NANOSECONDS.toMillis(durationNS) == 0;
433+
}
434+
416435
}
417436

418437
private static class PhaseTreeIntermediateRoot extends PhaseTreeNode {
@@ -449,27 +468,34 @@ private PhaseTreeNode cloneTree(PhaseTreeNode clonee, PhaseTreeNode parent) {
449468
/**
450469
* Recursively print the phase tree represented by {@code node}.
451470
*/
452-
private void printTree(String indent, StringBuilder sb, PhaseTreeNode node, boolean printRoot) {
471+
private void printTree(String indent, StringBuilder sb, PhaseTreeNode node, boolean printRoot, boolean skipPrintingZeroSubTree) {
453472
if (root == null) {
454473
return;
455474
}
456-
sb.append(indent);
475+
boolean skip = skipPrintingZeroSubTree && node.durationZeroInMS();
476+
if (!skip) {
477+
sb.append(indent);
478+
}
457479
if (!printRoot && node == root) {
458480
sb.append(node.name);
459481
} else {
460-
sb.append(node);
482+
if (!skip) {
483+
sb.append(node);
484+
}
485+
}
486+
if (!skip) {
487+
sb.append(System.lineSeparator());
461488
}
462-
sb.append(System.lineSeparator());
463-
if (node.children != null) {
489+
if (node.children != null && !skip) {
464490
for (int i = 0; i < node.childIndex; i++) {
465-
printTree(indent + "\t", sb, node.children[i], printRoot);
491+
printTree(indent + "\t", sb, node.children[i], printRoot, skipPrintingZeroSubTree);
466492
}
467493
}
468494
}
469495

470496
public StringBuilder elapsedPhaseTreeAsString() {
471497
StringBuilder sb = new StringBuilder();
472-
printTree("", sb, root, false);
498+
printTree("", sb, root, false, false);
473499
return sb;
474500
}
475501

@@ -493,7 +519,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
493519
}
494520
CompilationAlarm current = currentAlarm.get();
495521
if (current == null) {
496-
current = new CompilationAlarm(period);
522+
current = new CompilationAlarm(period, true/* skip 0 entries */);
497523
currentAlarm.set(current);
498524
return current;
499525
}
@@ -506,7 +532,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
506532
* statement to restore the previous alarm state.
507533
*/
508534
public static CompilationAlarm disable() {
509-
CompilationAlarm current = new CompilationAlarm(0);
535+
CompilationAlarm current = new CompilationAlarm(0, false);
510536
currentAlarm.set(current);
511537
return current;
512538
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/EncodedSnippets.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import jdk.graal.compiler.core.common.type.StampPair;
4848
import jdk.graal.compiler.core.common.type.SymbolicJVMCIReference;
4949
import jdk.graal.compiler.debug.DebugContext;
50+
import jdk.graal.compiler.debug.DebugOptions;
5051
import jdk.graal.compiler.debug.GraalError;
5152
import jdk.graal.compiler.nodeinfo.Verbosity;
5253
import jdk.graal.compiler.nodes.ConstantNode;
@@ -250,12 +251,14 @@ StructuredGraph getEncodedSnippet(ResolvedJavaMethod method, ResolvedJavaMethod
250251
declaringClass = replacements.getProviders().getMetaAccess().lookupJavaType(Object.class);
251252
}
252253
/*
253-
* If this is a recorded/replayed compilation, we must not mutate the snippet objects. This
254-
* ensures we record all relevant operations during recording and no proxies are stored in
255-
* the snippet objects during replay.
254+
* If there is a possibility of a recorded/replayed compilation, we must not mutate the
255+
* snippet objects. During recording, this ensures that we record all relevant operations
256+
* and the cached objects are resolved to proxies. During replay, this ensures that no
257+
* proxies are stored in the snippet objects.
256258
*/
257259
boolean allowCacheReplacements = replacements.getProviders().getReplayCompilationSupport() == null &&
258-
GraalCompilerOptions.CompilationFailureAction.getValue(options) != CompilationWrapper.ExceptionAction.Diagnose;
260+
GraalCompilerOptions.CompilationFailureAction.getValue(options) != CompilationWrapper.ExceptionAction.Diagnose &&
261+
!DebugOptions.RecordForReplay.hasBeenSet(options);
259262
SymbolicEncodedGraph encodedGraph = new SymbolicEncodedGraph(snippetEncoding, startOffset, snippetObjects, allowCacheReplacements,
260263
snippetNodeClasses, data.originalMethod, declaringClass);
261264
return decodeSnippetGraph(encodedGraph, method, original, replacements, args, allowAssumptions, options, true);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
790790
}
791791

792792
// @formatter:off
793-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/0ad919c1e54895b000b58f6a1b54d79f76970845/src/hotspot/share/opto/library_call.cpp#L3016-L3070",
793+
@SyncPort(from = "https://github.com/openjdk/jdk/blob/8e4485699235caff0074c4d25ee78539e57da63a/src/hotspot/share/opto/library_call.cpp#L3029-L3083",
794794
sha1 = "353e0d45b0f63ac58af86dcab5b19777950da7e2")
795795
// @formatter:on
796796
private static void inlineNativeNotifyJvmtiFunctions(GraalHotSpotVMConfig config, GraphBuilderContext b, ResolvedJavaMethod targetMethod, ForeignCallDescriptor descriptor,
@@ -839,7 +839,7 @@ private static void inlineNativeNotifyJvmtiFunctions(GraalHotSpotVMConfig config
839839
}
840840

841841
// @formatter:off
842-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/0ad919c1e54895b000b58f6a1b54d79f76970845/src/hotspot/share/opto/library_call.cpp#L3835-L3919",
842+
@SyncPort(from = "https://github.com/openjdk/jdk/blob/8e4485699235caff0074c4d25ee78539e57da63a/src/hotspot/share/opto/library_call.cpp#L3848-L3932",
843843
sha1 = "3e9cfba4d9554f7cd9ab392f0826a31ae6396193")
844844
// @formatter:on
845845
private static class ContinuationPinningPlugin extends InvocationPlugin {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/AssertionSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void lower(AssertionNode assertionNode, LoweringTool tool) {
9090
Arguments args = new Arguments(graph.start() instanceof StubStartNode ? stubAssertion : assertion, graph, tool.getLoweringStage());
9191
args.add("condition", assertionNode.condition());
9292
args.add("message",
93-
graph.unique(new ConstantNode(new CStringConstant("failed runtime assertion in snippet/stub: " + assertionNode.message() + " (" + graph.method() + ")"),
93+
graph.unique(new ConstantNode(new CStringConstant("failed runtime assertion in snippet/stub: " + assertionNode.message() + " (" + graph.method().format("%H.%n(%p)") + ")"),
9494
StampFactory.pointer())));
9595
args.add("l1", assertionNode.getL1());
9696
args.add("l2", assertionNode.getL2());

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/HotSpotHashCodeSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import jdk.graal.compiler.word.Word;
4444

4545
// @formatter:off
46-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/0ad919c1e54895b000b58f6a1b54d79f76970845/src/hotspot/share/opto/library_call.cpp#L4710-L4844",
46+
@SyncPort(from = "https://github.com/openjdk/jdk/blob/8e4485699235caff0074c4d25ee78539e57da63a/src/hotspot/share/opto/library_call.cpp#L4723-L4857",
4747
sha1 = "c212d1dbff26d02d4d749e085263d4104895f1ba")
4848
// @formatter:on
4949
public class HotSpotHashCodeSnippets extends IdentityHashCodeSnippets {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replacements/VirtualThreadUpdateJFRSnippets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* Snippet for updating JFR thread local data on {@code Thread#setCurrentThread} events.
6565
*/
6666
// @formatter:off
67-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/0ad919c1e54895b000b58f6a1b54d79f76970845/src/hotspot/share/opto/library_call.cpp#L3621-L3749",
67+
@SyncPort(from = "https://github.com/openjdk/jdk/blob/8e4485699235caff0074c4d25ee78539e57da63a/src/hotspot/share/opto/library_call.cpp#L3634-L3762",
6868
sha1 = "59f07096cdbe1aac79b1248db345e9616b54f4a4")
6969
// @formatter:on
7070
public class VirtualThreadUpdateJFRSnippets implements Snippets {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/CompilerInterfaceDeclarations.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESPECIAL;
3131
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKESTATIC;
3232
import static jdk.graal.compiler.bytecode.Bytecodes.INVOKEVIRTUAL;
33+
import static jdk.graal.compiler.hotspot.HotSpotReplacementsImpl.isGraalClass;
3334
import static jdk.graal.compiler.java.StableMethodNameFormatter.isMethodHandle;
3435

3536
import java.lang.reflect.Proxy;
@@ -48,6 +49,7 @@
4849
import jdk.graal.compiler.core.common.CompilerProfiler;
4950
import jdk.graal.compiler.debug.DebugContext;
5051
import jdk.graal.compiler.debug.GraalError;
52+
import jdk.graal.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider;
5153
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxy;
5254
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilationProxyBase;
5355
import jdk.graal.compiler.hotspot.replaycomp.proxy.CompilerProfilerProxy;
@@ -66,6 +68,7 @@
6668
import jdk.graal.compiler.hotspot.replaycomp.proxy.SignatureProxy;
6769
import jdk.graal.compiler.hotspot.replaycomp.proxy.SpeculationLogProxy;
6870
import jdk.graal.compiler.java.LambdaUtils;
71+
import jdk.graal.compiler.options.ExcludeFromJacocoGeneratedReport;
6972
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
7073
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
7174
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
@@ -703,6 +706,7 @@ public static CompilerInterfaceDeclarations build() {
703706
}
704707
return List.of();
705708
})
709+
.setFallbackInvocationHandler(HotSpotResolvedObjectTypeProxy.isInstanceMethod, CompilerInterfaceDeclarations::objectTypeIsInstanceFallback)
706710
.register(declarations);
707711
// Must come after HotSpotResolvedObjectType. Needed for HotSpotResolvedPrimitiveType.
708712
new RegistrationBuilder<>(HotSpotResolvedJavaType.class)
@@ -921,4 +925,27 @@ private static ResolvedJavaType javaLangObjectSupplier(Object proxy, Compilation
921925
MetaAccessProvider metaAccess = (MetaAccessProvider) singletonObjects.get(MetaAccessProvider.class);
922926
return metaAccess.lookupJavaType(Object.class);
923927
}
928+
929+
/**
930+
* Implements a fallback for {@link HotSpotResolvedObjectType#isInstance} calls performed by
931+
* {@link HotSpotGraalConstantFieldProvider} when replaying a libgraal compilation on jargraal.
932+
* <p>
933+
* The provider performs checks like {@code getHotSpotVMConfigType().isInstance(receiver)},
934+
* which use snippet types on libgraal and HotSpot types on jargraal. Replay on jargraal needs
935+
* to answer these queries when the receiver and argument are HotSpot proxies.
936+
*/
937+
@SuppressWarnings("unused")
938+
@ExcludeFromJacocoGeneratedReport("related to replay of libgraal compilations on jargraal")
939+
private static boolean objectTypeIsInstanceFallback(Object proxy, CompilationProxy.SymbolicMethod method, Object[] args, EconomicMap<Class<?>, Object> singletonObjects) {
940+
HotSpotResolvedObjectType receiverType = (HotSpotResolvedObjectType) proxy;
941+
if (!(args[0] instanceof HotSpotObjectConstant objectConstant)) {
942+
return false;
943+
}
944+
HotSpotResolvedObjectType constantType = objectConstant.getType();
945+
if (isGraalClass(receiverType) && !isGraalClass(constantType)) {
946+
// Assumes that only a Graal class can subtype a Graal class.
947+
return false;
948+
}
949+
return receiverType.isAssignableFrom(constantType);
950+
}
924951
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/proxy/HotSpotResolvedJavaTypeProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public final boolean isAssignableFrom(ResolvedJavaType other) {
241241
return (boolean) handle(isAssignableFromMethod, isAssignableFromInvokable, other);
242242
}
243243

244-
private static final SymbolicMethod isInstanceMethod = method("isInstance", JavaConstant.class);
244+
public static final SymbolicMethod isInstanceMethod = method("isInstance", JavaConstant.class);
245245
private static final InvokableMethod isInstanceInvokable = (receiver, args) -> ((HotSpotResolvedJavaType) receiver).isInstance((JavaConstant) args[0]);
246246

247247
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/aarch64/AArch64EncodeArrayOp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
import jdk.vm.ci.meta.Value;
5252

5353
// @formatter:off
54-
@SyncPort(from = "https://github.com/openjdk/jdk/blob/c2d76f9844aadf77a0b213a9169a7c5c8c8f1ffb/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L6422-L6535",
55-
sha1 = "80e6323172af5e8a33625b4eb14629cdad500a0f")
54+
@SyncPort(from = "https://github.com/openjdk/jdk/blob/8e4485699235caff0074c4d25ee78539e57da63a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L6422-L6539",
55+
sha1 = "7ec995886d9acb20550c9ed4a7fdbe9051043589")
5656
// @formatter:on
5757
@Opcode("AArch64_ENCODE_ARRAY")
5858
public final class AArch64EncodeArrayOp extends AArch64ComplexVectorOp {

0 commit comments

Comments
 (0)