use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.
the class DFAPartialEvaluationTest method createRootNode.
private RootNode createRootNode(int initialState, DFAStateNode[] states) {
FrameDescriptor frameDescriptor = new FrameDescriptor();
TRegexDFAExecutorNode executorNode = new TRegexDFAExecutorNode(initialState, states);
return new TRegexRootNode(frameDescriptor, executorNode);
}
use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.
the class EnumPartialEvaluationTest method enumValuesConstant.
@Ignore("Currently only works if compiled with ecj")
@Test
public void enumValuesConstant() {
AbstractTestNode result = new AbstractTestNode() {
@Override
public int execute(VirtualFrame frame) {
return TestEnum.values()[0].ordinal();
}
};
assertPartialEvalEquals("constant0", new RootTestNode(new FrameDescriptor(), "enumValuesConstant", result));
}
use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.
the class EnumPartialEvaluationTest method enumSwitchConstantFolding.
@Test
public void enumSwitchConstantFolding() {
AbstractTestNode result = new SwitchTestNode(TestEnum.Test0);
assertPartialEvalEquals("constant42", new RootTestNode(new FrameDescriptor(), "enumSwitchConstantFolding", result));
}
use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.
the class EnumPartialEvaluationTest method enumOrdinalConstant.
@Test
public void enumOrdinalConstant() {
AbstractTestNode result = new AbstractTestNode() {
@Override
public int execute(VirtualFrame frame) {
return TestEnum.Test0.ordinal();
}
};
assertPartialEvalEquals("constant0", new RootTestNode(new FrameDescriptor(), "enumOrdinalConstant", result));
}
use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.
the class OptimizedCallTargetTest method testRewriteAssumption.
@Test
public void testRewriteAssumption() {
String testName = "testRewriteAssumption";
assertTrue("test only works with inlining enabled", TruffleCompilerOptions.getValue(TruffleFunctionInlining));
try (TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleCompilationThreshold, 20)) {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
assertTrue(compilationThreshold >= 2);
OptimizedCallTarget innermostCallTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 0, new AbstractTestNode() {
@Child
private AbstractTestNode child = new ConstantTestNode(42);
@Child
private AbstractTestNode dummy = new ConstantTestNode(17);
@Override
public int execute(VirtualFrame frame) {
int k = (int) frame.getArguments()[0];
if (k > compilationThreshold) {
CompilerDirectives.transferToInterpreter();
dummy.replace(new ConstantTestNode(k));
}
return child.execute(frame);
}
}));
OptimizedCallTarget ct = innermostCallTarget;
ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 1, new CallTestNode(ct)));
ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 2, new CallTestNode(ct)));
final OptimizedCallTarget outermostCallTarget = ct;
assertNull("assumption is initially null", getRewriteAssumption(innermostCallTarget));
IntStream.range(0, compilationThreshold / 2).parallel().forEach(k -> {
assertEquals(42, outermostCallTarget.call(k));
assertNull("assumption stays null in the interpreter", getRewriteAssumption(innermostCallTarget));
});
outermostCallTarget.compile();
assertCompiled(outermostCallTarget);
Assumption firstRewriteAssumption = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", firstRewriteAssumption);
assertTrue(firstRewriteAssumption.isValid());
List<Assumption> rewriteAssumptions = IntStream.range(0, 2 * compilationThreshold).parallel().mapToObj(k -> {
assertEquals(42, outermostCallTarget.call(k));
Assumption rewriteAssumptionAfter = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", rewriteAssumptionAfter);
return rewriteAssumptionAfter;
}).collect(Collectors.toList());
Assumption finalRewriteAssumption = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", finalRewriteAssumption);
assertNotSame(firstRewriteAssumption, finalRewriteAssumption);
assertFalse(firstRewriteAssumption.isValid());
assertTrue(finalRewriteAssumption.isValid());
assertFalse(rewriteAssumptions.stream().filter(a -> a != finalRewriteAssumption).anyMatch(Assumption::isValid));
}
}
Aggregations