use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class AllocationReporterPartialEvaluationTest method testConsistentAssertions.
@Test
public void testConsistentAssertions() {
// Test that onEnter()/onReturnValue() are not broken
// when only one of them is compiled with PE.
Context context = Context.newBuilder(AllocationReporterLanguage.ID).build();
context.initialize(AllocationReporterLanguage.ID);
final TestAllocationReporter tester = context.getEngine().getInstruments().get(TestAllocationReporter.ID).lookup(TestAllocationReporter.class);
assertNotNull(tester);
final AllocationReporter reporter = (AllocationReporter) context.getPolyglotBindings().getMember(AllocationReporter.class.getSimpleName()).asHostObject();
final Long[] value = new Long[] { 1L };
OptimizedCallTarget enterTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
reporter.onEnter(value[0], 4, 8);
return null;
}
});
OptimizedCallTarget returnTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
reporter.onReturnValue(value[0], 4, 8);
return null;
}
});
// Interpret both:
assertNotCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
long expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
for (int j = 0; j < 2; j++) {
// Compile both:
for (int i = 0; i < 5; i++) {
assertCompiled(enterTarget);
enterTarget.call();
assertCompiled(returnTarget);
returnTarget.call();
value[0]++;
}
expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
// Deoptimize enter:
enterTarget.invalidate(this, "test");
assertNotCompiled(enterTarget);
enterTarget.call();
assertCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Deoptimize return:
returnTarget.invalidate(this, "test");
assertCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Deoptimize both:
enterTarget.invalidate(this, "test");
returnTarget.invalidate(this, "test");
assertNotCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
}
// Check that the allocation calls happened:
expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Verify that the assertions work in the compiled code:
value[0] = null;
boolean expectedFailure = true;
// Deoptimize for assertions to be active
enterTarget.invalidate(this, "test");
try {
enterTarget.call();
expectedFailure = false;
} catch (AssertionError err) {
// O.K.
}
assertTrue("onEnter(null) did not fail!", expectedFailure);
// Deoptimize for assertions to be active
returnTarget.invalidate(this, "test");
value[0] = Long.MIN_VALUE;
try {
returnTarget.call();
expectedFailure = false;
} catch (AssertionError err) {
// O.K.
}
assertTrue("onReturn(<unseen value>) did not fail!", expectedFailure);
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class AssumptionPartialEvaluationTest method constantValue.
@Test
public void constantValue() {
Assumption assumption = Truffle.getRuntime().createAssumption();
AbstractTestNode result = new ConstantWithAssumptionTestNode(assumption, 42);
RootTestNode rootNode = new RootTestNode(new FrameDescriptor(), "constantValue", result);
OptimizedCallTarget callTarget = assertPartialEvalEquals("constant42", rootNode);
Assert.assertTrue(callTarget.isValid());
assertDeepEquals(42, callTarget.call());
Assert.assertTrue(callTarget.isValid());
try {
assumption.check();
} catch (InvalidAssumptionException e) {
Assert.fail("Assumption must not have been invalidated.");
}
assumption.invalidate();
try {
assumption.check();
Assert.fail("Assumption must have been invalidated.");
} catch (InvalidAssumptionException e) {
}
Assert.assertFalse(callTarget.isValid());
assertDeepEquals(43, callTarget.call());
}
Aggregations