Skip to content

Commit

Permalink
[GR-58634] Fix error message when prepareOSR long overload is not imp…
Browse files Browse the repository at this point in the history
…lemented

PullRequest: graal/18950
  • Loading branch information
DSouzaM committed Oct 4, 2024
2 parents 9f2747b + 6a117ba commit 735bdfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package jdk.graal.compiler.truffle.test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -709,7 +712,7 @@ public void testLongTargetBadOverload1() {
FixedIterationLoopLongTargetLoopBadOverload1 osrNode = new FixedIterationLoopLongTargetLoopBadOverload1(frameBuilder);
RootNode rootNode = new Program(osrNode, frameBuilder.build());
OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget();
Assert.assertThrows("long target used without implementing long overload of prepareOSR", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
assertThrowsWithMessage("long target used without implementing long overload of prepareOSR", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
}

@Test
Expand All @@ -718,7 +721,7 @@ public void testLongTargetBadOverload2() {
FixedIterationLoopLongTargetLoopBadOverload2 osrNode = new FixedIterationLoopLongTargetLoopBadOverload2(frameBuilder);
RootNode rootNode = new Program(osrNode, frameBuilder.build());
OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget();
Assert.assertThrows("long target used without implementing long overload of copyIntoOSRFrame", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
assertThrowsWithMessage("long target used without implementing long overload of copyIntoOSRFrame", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
}

@Test
Expand All @@ -727,7 +730,18 @@ public void testLongTargetBadOverload3() {
FixedIterationLoopLongTargetLoopBadOverload3 osrNode = new FixedIterationLoopLongTargetLoopBadOverload3(frameBuilder);
RootNode rootNode = new Program(osrNode, frameBuilder.build());
OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget();
Assert.assertThrows("long target used without implementing long overload of executeOSR", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
assertThrowsWithMessage("long target used without implementing long overload of executeOSR", AssertionError.class, () -> target.call(OSR_THRESHOLD + 1));
}

private static void assertThrowsWithMessage(String errorMessage, Class<?> expectedThrowable, Runnable runnable) {
try {
runnable.run();
} catch (Throwable t) {
assertTrue(expectedThrowable.isInstance(t));
assertTrue(t.getMessage().contains(errorMessage));
return;
}
fail("No exception was thrown.");
}

public static class Program extends RootNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ default void prepareOSR(int target) {
default void prepareOSR(long target) {
int intTarget = (int) target;
if (intTarget != target) {
throw CompilerDirectives.shouldNotReachHere("long target used without implementing long overload of executeOSR");
throw CompilerDirectives.shouldNotReachHere("long target used without implementing long overload of prepareOSR");
}
prepareOSR(intTarget);
}
Expand Down

0 comments on commit 735bdfa

Please sign in to comment.