From e810fb7df3381b63e1257d1cd5f95bd7095fae9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Wed, 6 Sep 2023 19:05:09 +0200 Subject: [PATCH 1/6] Fix #7359 by throwing `UnsupportedMessageException` as required by the `InteropLibrary` --- .../api/exception/DefaultStackTraceElementObject.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/truffle/src/com.oracle.truffle.api.exception/src/com/oracle/truffle/api/exception/DefaultStackTraceElementObject.java b/truffle/src/com.oracle.truffle.api.exception/src/com/oracle/truffle/api/exception/DefaultStackTraceElementObject.java index 2d8249efda3e..953a7aa45da1 100644 --- a/truffle/src/com.oracle.truffle.api.exception/src/com/oracle/truffle/api/exception/DefaultStackTraceElementObject.java +++ b/truffle/src/com.oracle.truffle.api.exception/src/com/oracle/truffle/api/exception/DefaultStackTraceElementObject.java @@ -69,8 +69,12 @@ boolean hasExecutableName() { @ExportMessage @TruffleBoundary - Object getExecutableName() { - return rootNode.getName(); + Object getExecutableName() throws UnsupportedMessageException { + String name = rootNode.getName(); + if (name == null) { + throw UnsupportedMessageException.create(); + } + return name; } @ExportMessage From bb108fa60bf726c0bd628115164df01c8cddc8ae Mon Sep 17 00:00:00 2001 From: Jakub Chaloupka Date: Thu, 14 Sep 2023 16:25:53 +0200 Subject: [PATCH 2/6] Add test. --- .../src/com/oracle/truffle/api/test/RootNodeTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/RootNodeTest.java b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/RootNodeTest.java index 006f8c588d94..9686979ef680 100644 --- a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/RootNodeTest.java +++ b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/RootNodeTest.java @@ -264,6 +264,8 @@ static void verifyStackTraceElementGuestObject(Object guestObject) throws Unsupp if (interop.hasExecutableName(guestObject)) { Object executableName = interop.getExecutableName(guestObject); Assert.assertTrue(interop.isString(executableName)); + } else { + AbstractPolyglotTest.assertFails(() -> interop.getExecutableName(guestObject), UnsupportedMessageException.class); } if (interop.hasDeclaringMetaObject(guestObject)) { Object metaObject = interop.getDeclaringMetaObject(guestObject); From d951f72b999766b337a7254105b24a45e23b103a Mon Sep 17 00:00:00 2001 From: Tom Rodriguez Date: Fri, 22 Sep 2023 00:15:01 -0700 Subject: [PATCH 3/6] Support CompilationWrapper.dumpOnError with truffle --- .../truffle/compiler/TruffleCompilerImpl.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java index 515a7bb0a835..ecd1c19f05f8 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java @@ -60,6 +60,7 @@ import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DebugContext.Builder; import org.graalvm.compiler.debug.DebugContext.Scope; +import org.graalvm.compiler.debug.DebugDumpScope; import org.graalvm.compiler.debug.DiagnosticsOutputDirectory; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.debug.Indent; @@ -540,6 +541,9 @@ private StructuredGraph truffleTier(TruffleCompilationWrapper wrapper, DebugCont wrapper.compilationId, TruffleTierContext.getSpeculationLog(wrapper), wrapper.task, handler); + // Save the graph so it can dumped into the graal_diagnostics zip + wrapper.graph = context.graph; + try (Scope s = context.debug.scope("CreateGraph", context.graph); Indent indent = context.debug.logAndIndent("evaluate %s", context.graph);) { truffleTier.apply(context.graph, context); @@ -676,6 +680,7 @@ final class TruffleCompilationWrapper extends CompilationWrapper { final CompilationIdentifier compilationId; final ExpansionStatistics statistics; final OptionValues compilerOptions; + StructuredGraph graph; boolean silent; private TruffleCompilationWrapper( @@ -700,6 +705,18 @@ public String toString() { return compilable.toString(); } + @SuppressWarnings("try") + @Override + protected void dumpOnError(DebugContext errorContext, Throwable cause) { + if (graph != null) { + try (DebugContext.Scope s = errorContext.scope("DumpOnError", graph, compilationId, new DebugDumpScope("Original failure"))) { + errorContext.forceDump(graph, "Exception: %s", cause); + } catch (Throwable t) { + throw errorContext.handle(t); + } + } + } + @Override protected ExceptionAction lookupAction(OptionValues options, Throwable cause) { // Respect current action if it has been explicitly set. From f388add62ad520f8b07d97427bf338b9bf12b54b Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 18 Sep 2023 11:11:51 +0200 Subject: [PATCH 4/6] Rerun `DefaultOptionsHolder` class initializers. Fixes #6457. --- .../src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java index 013049b618da..08384d7a5b47 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationJavaNio.java @@ -68,6 +68,8 @@ public void duringSetup(DuringSetupAccess a) { rerunClassInit(a, "sun.nio.ch.IOUtil", "sun.nio.ch.ServerSocketChannelImpl", "sun.nio.ch.DatagramChannelImpl", "sun.nio.ch.FileChannelImpl", "sun.nio.ch.FileKey"); rerunClassInit(a, "java.nio.file.Files$FileTypeDetectors"); rerunClassInit(a, "sun.nio.ch.Net", "sun.nio.ch.SocketOptionRegistry$LazyInitialization"); + rerunClassInit(a, "sun.nio.ch.AsynchronousSocketChannelImpl$DefaultOptionsHolder", "sun.nio.ch.AsynchronousServerSocketChannelImpl$DefaultOptionsHolder", + "sun.nio.ch.DatagramChannelImpl$DefaultOptionsHolder", "sun.nio.ch.ServerSocketChannelImpl$DefaultOptionsHolder", "sun.nio.ch.SocketChannelImpl$DefaultOptionsHolder"); /* Ensure that the interrupt signal handler is initialized at runtime. */ rerunClassInit(a, "sun.nio.ch.NativeThread"); rerunClassInit(a, "sun.nio.ch.FileDispatcherImpl", "sun.nio.ch.FileChannelImpl$Unmapper"); From 009e43ca25c7201f054bcc4e47a080107adae155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C3=B6=20Barany?= Date: Fri, 15 Sep 2023 15:49:10 +0200 Subject: [PATCH 5/6] Don't try to incorrectly move virtual state inputs out of loops --- .../phases/schedule/SchedulePhase.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/schedule/SchedulePhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/schedule/SchedulePhase.java index 63d0eb568c1b..135d1a02116e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/schedule/SchedulePhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/schedule/SchedulePhase.java @@ -585,7 +585,7 @@ protected void calcLatestBlock(HIRBlock earliestBlock, SchedulingStrategy strate */ continue; } - latestBlock = calcBlockForUsage(currentNode, usage, latestBlock, currentNodeMap, moveInputsIntoDominator); + latestBlock = calcLatestBlockForUsage(currentNode, usage, earliestBlock, latestBlock, currentNodeMap, moveInputsIntoDominator); checkLatestEarliestRelation(currentNode, earliestBlock, latestBlock, usage); } @@ -687,9 +687,10 @@ private static Node getUnproxifiedUncompressed(Node node) { return result; } - private static HIRBlock calcBlockForUsage(Node node, Node usage, HIRBlock startBlock, NodeMap currentNodeMap, NodeBitMap moveInputsToDominator) { + private static HIRBlock calcLatestBlockForUsage(Node node, Node usage, HIRBlock earliestBlock, HIRBlock initialLatestBlock, NodeMap currentNodeMap, + NodeBitMap moveInputsToDominator) { assert !(node instanceof PhiNode); - HIRBlock currentBlock = startBlock; + HIRBlock currentBlock = initialLatestBlock; if (usage instanceof PhiNode) { // An input to a PhiNode is used at the end of the predecessor block that // corresponds to the PhiNode input. One PhiNode can use an input multiple times. @@ -711,7 +712,16 @@ private static HIRBlock calcBlockForUsage(Node node, Node usage, HIRBlock startB } if (!(node instanceof VirtualState) && !moveInputsToDominator.isNew(usage) && moveInputsToDominator.isMarked(usage)) { - otherBlock = otherBlock.getDominator(); + /* + * The usage is marked as forcing its inputs into the dominator. Respect that if + * we can, but the dominator might not be a legal position for the node. This is + * the case for loop-variant floating nodes between a loop phi and a virtual + * state on the loop begin. + */ + HIRBlock dominator = otherBlock.getDominator(); + if (AbstractControlFlowGraph.dominates(earliestBlock, dominator)) { + otherBlock = dominator; + } GraalError.guarantee(otherBlock != null, "Dominators need to be computed in the CFG"); } From 88d24368239407260a0e316e2a8f63783f8833ec Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Fri, 11 Aug 2023 13:10:35 +0200 Subject: [PATCH 6/6] graph order: run some form of schedule verification in all tiers if possible --- .../graalvm/compiler/phases/util/GraphOrder.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/util/GraphOrder.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/util/GraphOrder.java index 5dd05724f255..ffe9c02843e0 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/util/GraphOrder.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/util/GraphOrder.java @@ -29,6 +29,7 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; +import org.graalvm.compiler.debug.Assertions; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.GraalGraphError; @@ -150,12 +151,24 @@ private static void visitForward(ArrayList nodes, NodeBitMap visited, Node } } + public static boolean assertSchedulableGraph(StructuredGraph g) { + assert GraphOrder.assertNonCyclicGraph(g); + assert g.getGuardsStage() == GuardsStage.AFTER_FSA || GraphOrder.assertScheduleableBeforeFSA(g); + if (g.getGuardsStage() == GuardsStage.AFTER_FSA && Assertions.detailedAssertionsEnabled(g.getOptions())) { + // we still want to do a memory verification of the schedule even if we can + // no longer use assertSchedulableGraph after the floating reads phase + SchedulePhase.runWithoutContextOptimizations(g, SchedulePhase.SchedulingStrategy.LATEST_OUT_OF_LOOPS, true); + } + assert g.verify(); + return true; + } + /** * This method schedules the graph and makes sure that, for every node, all inputs are available * at the position where it is scheduled. This is a very expensive assertion. */ @SuppressWarnings("try") - public static boolean assertSchedulableGraph(final StructuredGraph graph) { + private static boolean assertScheduleableBeforeFSA(final StructuredGraph graph) { assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid."; try (DebugContext.Scope s = graph.getDebug().scope("AssertSchedulableGraph")) { SchedulePhase.runWithoutContextOptimizations(graph, getSchedulingPolicy(graph), true);