Skip to content

Commit 4814450

Browse files
[GR-14161] Fix exceptions printed during unittest runs.
PullRequest: graal/3025
2 parents a715617 + 8901295 commit 4814450

File tree

7 files changed

+56
-15
lines changed

7 files changed

+56
-15
lines changed

compiler/src/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/JVMCIInfopointErrorTest.java

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

27+
import static org.graalvm.compiler.debug.DebugOptions.DumpOnError;
2728
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
2829
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
2930
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
@@ -52,6 +53,7 @@
5253
import org.graalvm.compiler.nodes.StructuredGraph;
5354
import org.graalvm.compiler.nodes.spi.LIRLowerable;
5455
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
56+
import org.graalvm.compiler.options.OptionValues;
5557
import org.junit.Test;
5658

5759
import jdk.vm.ci.code.BytecodeFrame;
@@ -139,6 +141,14 @@ private void test(TestSpec spec) {
139141
test(getDebugContext(), spec);
140142
}
141143

144+
/**
145+
* Avoids dumping during tests which are expected to fail.
146+
*/
147+
private void testNoDump(TestSpec spec) {
148+
OptionValues options = new OptionValues(getInitialOptions(), DumpOnError, false);
149+
test(getDebugContext(options, null, null), spec);
150+
}
151+
142152
private void test(DebugContext debug, TestSpec spec) {
143153
ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
144154

@@ -154,7 +164,7 @@ private void test(DebugContext debug, TestSpec spec) {
154164

155165
@Test(expected = Error.class)
156166
public void testInvalidShortOop() {
157-
test((tool, state, safepoint) -> {
167+
testNoDump((tool, state, safepoint) -> {
158168
PlatformKind kind = tool.target().arch.getPlatformKind(JavaKind.Short);
159169
LIRKind lirKind = LIRKind.reference(kind);
160170

@@ -167,7 +177,7 @@ public void testInvalidShortOop() {
167177

168178
@Test(expected = Error.class)
169179
public void testInvalidShortDerivedOop() {
170-
test((tool, state, safepoint) -> {
180+
testNoDump((tool, state, safepoint) -> {
171181
Variable baseOop = tool.newVariable(LIRKind.fromJavaKind(tool.target().arch, JavaKind.Object));
172182
tool.append(new ValueDef(baseOop));
173183

compiler/src/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/util/GraphOrder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.graalvm.collections.EconomicMap;
3131
import org.graalvm.collections.Equivalence;
3232
import org.graalvm.compiler.core.common.cfg.Loop;
33+
import org.graalvm.compiler.debug.DebugContext;
3334
import org.graalvm.compiler.debug.GraalError;
3435
import org.graalvm.compiler.graph.GraalGraphError;
3536
import org.graalvm.compiler.graph.Node;
@@ -153,9 +154,10 @@ private static void visitForward(ArrayList<Node> nodes, NodeBitMap visited, Node
153154
* This method schedules the graph and makes sure that, for every node, all inputs are available
154155
* at the position where it is scheduled. This is a very expensive assertion.
155156
*/
157+
@SuppressWarnings("try")
156158
public static boolean assertSchedulableGraph(final StructuredGraph graph) {
157159
assert graph.getGuardsStage() != GuardsStage.AFTER_FSA : "Cannot use the BlockIteratorClosure after FrameState Assignment, HIR Loop Data Structures are no longer valid.";
158-
try {
160+
try (DebugContext.Scope s = graph.getDebug().scope("AssertSchedulableGraph")) {
159161
final SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
160162
final EconomicMap<LoopBeginNode, NodeBitMap> loopEntryStates = EconomicMap.create(Equivalence.IDENTITY);
161163
schedulePhase.apply(graph, false);

compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/ReplacementsParseTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.graalvm.compiler.replacements.test;
2626

27+
import static org.graalvm.compiler.debug.DebugOptions.DumpOnError;
2728
import static org.graalvm.compiler.java.BytecodeParserOptions.InlinePartialIntrinsicExitDuringParsing;
2829

2930
import java.util.function.Function;
@@ -48,9 +49,11 @@
4849
import org.graalvm.compiler.nodes.FrameState;
4950
import org.graalvm.compiler.nodes.PiNode;
5051
import org.graalvm.compiler.nodes.StructuredGraph;
52+
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
53+
import org.graalvm.compiler.nodes.StructuredGraph.Builder;
5154
import org.graalvm.compiler.nodes.ValueNode;
52-
import org.graalvm.compiler.nodes.extended.OpaqueNode;
5355
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
56+
import org.graalvm.compiler.nodes.extended.OpaqueNode;
5457
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
5558
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
5659
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver;
@@ -613,7 +616,10 @@ public static int div(int x, int y) {
613616
@Test
614617
public void testAssertionInMethodSubstitution() {
615618
try {
616-
parseEager("div", StructuredGraph.AllowAssumptions.YES);
619+
ResolvedJavaMethod method = getResolvedJavaMethod("div");
620+
// avoid dumping graphs and printing exception since and exception is expected
621+
OptionValues options = new OptionValues(getInitialOptions(), DumpOnError, false);
622+
parse(new Builder(options, getDebugContext(options, null, method), AllowAssumptions.YES).method(method).compilationId(getCompilationId(method)), getEagerGraphBuilderSuite());
617623
throw GraalError.shouldNotReachHere("BytecodeParser should have complained about using assertion in an intrinsic.");
618624
} catch (BytecodeParserError e) {
619625
// Expected behavior

compiler/src/org.graalvm.compiler.truffle.test/src/org/graalvm/compiler/truffle/test/CompilerAssertsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ public int execute(VirtualFrame frame) {
8181
}
8282

8383
@Test
84+
@SuppressWarnings("try")
8485
public void neverPartOfCompilationTest() {
8586
NeverPartOfCompilationTestNode result = new NeverPartOfCompilationTestNode();
8687
RootTestNode rootNode = new RootTestNode(new FrameDescriptor(), "neverPartOfCompilation", result);
87-
try {
88+
try (PreventDumping noDump = new PreventDumping()) {
8889
compileHelper("neverPartOfCompilation", rootNode, new Object[0]);
8990
Assert.fail("Expected bailout exception due to never part of compilation");
9091
} catch (BailoutException e) {
@@ -93,11 +94,12 @@ public void neverPartOfCompilationTest() {
9394
}
9495

9596
@Test
97+
@SuppressWarnings("try")
9698
public void compilationNonConstantTest() {
9799
FrameDescriptor descriptor = new FrameDescriptor();
98100
CompilationConstantTestNode result = new CompilationConstantTestNode(new NonConstantTestNode(5));
99101
RootTestNode rootNode = new RootTestNode(descriptor, "compilationConstant", result);
100-
try {
102+
try (PreventDumping noDump = new PreventDumping()) {
101103
compileHelper("compilationConstant", rootNode, new Object[0]);
102104
Assert.fail("Expected bailout exception because expression is not compilation constant");
103105
} catch (BailoutException e) {

compiler/src/org.graalvm.compiler.truffle.test/src/org/graalvm/compiler/truffle/test/InstrumentBranchesPhaseTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
import static org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.TruffleInstrumentBranchesFilter;
2929
import static org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.TruffleInstrumentBranchesPretty;
3030

31-
import org.graalvm.compiler.options.OptionValues;
32-
import org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase;
3331
import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions;
3432
import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.TruffleOptionsOverrideScope;
33+
import org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase;
3534
import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget;
3635
import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode;
3736
import org.graalvm.compiler.truffle.test.nodes.RootTestNode;
@@ -96,10 +95,6 @@ public void disableInstrumentAfterTests() {
9695
overrides.close();
9796
}
9897

99-
private static OptionValues getOptions() {
100-
return TruffleCompilerOptions.getOptions();
101-
}
102-
10398
@Test
10499
public void simpleIfTest() {
105100
InstrumentPhase.Instrumentation instrumentation = truffleCompiler.getPartialEvaluator().getInstrumentation();

compiler/src/org.graalvm.compiler.truffle.test/src/org/graalvm/compiler/truffle/test/PartialEvaluationTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID;
2828
import static org.graalvm.compiler.core.common.CompilationRequestIdentifier.asCompilationRequest;
29+
import static org.graalvm.compiler.debug.DebugOptions.DumpOnError;
2930

3031
import org.graalvm.compiler.core.common.CompilationIdentifier;
3132
import org.graalvm.compiler.debug.DebugContext;
@@ -144,7 +145,7 @@ protected StructuredGraph partialEval(OptimizedCallTarget compilable, Object[] a
144145
} catch (IgnoreError e) {
145146
}
146147

147-
OptionValues options = TruffleCompilerOptions.getOptions();
148+
OptionValues options = getOptions();
148149
DebugContext debug = getDebugContext(options);
149150
try (DebugContext.Scope s = debug.scope("TruffleCompilation", new TruffleDebugJavaMethod(compilable))) {
150151
TruffleInlining inliningDecision = new TruffleInlining(compilable, new DefaultInliningPolicy());
@@ -155,6 +156,30 @@ protected StructuredGraph partialEval(OptimizedCallTarget compilable, Object[] a
155156
}
156157
}
157158

159+
protected OptionValues getOptions() {
160+
OptionValues options = TruffleCompilerOptions.getOptions();
161+
if (preventDumping) {
162+
options = new OptionValues(options, DumpOnError, false);
163+
}
164+
return options;
165+
}
166+
167+
private boolean preventDumping = false;
168+
169+
protected class PreventDumping implements AutoCloseable {
170+
private final boolean previous;
171+
172+
protected PreventDumping() {
173+
previous = preventDumping;
174+
preventDumping = true;
175+
}
176+
177+
@Override
178+
public void close() {
179+
preventDumping = previous;
180+
}
181+
}
182+
158183
protected void removeFrameStates(StructuredGraph graph) {
159184
for (FrameState frameState : graph.getNodes(FrameState.TYPE)) {
160185
frameState.replaceAtUsages(null);

compiler/src/org.graalvm.compiler.truffle.test/src/org/graalvm/compiler/truffle/test/SimplePartialEvaluationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ public void addConstants() {
9999
}
100100

101101
@Test
102+
@SuppressWarnings("try")
102103
public void neverPartOfCompilationTest() {
103104
FrameDescriptor fd = new FrameDescriptor();
104105
AbstractTestNode firstTree = new NeverPartOfCompilationTestNode(new ConstantTestNode(1), 2);
105106
assertPartialEvalEquals("constant42", new RootTestNode(fd, "neverPartOfCompilationTest", firstTree));
106107

107108
AbstractTestNode secondTree = new NeverPartOfCompilationTestNode(new ConstantTestNode(1), 1);
108-
try {
109+
try (PreventDumping noDump = new PreventDumping()) {
109110
assertPartialEvalEquals("constant42", new RootTestNode(fd, "neverPartOfCompilationTest", secondTree));
110111
Assert.fail("Expected verification error!");
111112
} catch (GraalBailoutException t) {

0 commit comments

Comments
 (0)