use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoCatchTransferFalse.
@Test
public void testExceptionOnTruffleBoundaryWithNoCatchTransferFalse() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {
protected DeoptCountingExceptionOverBoundaryRootNode() {
super(null);
}
int deopCounter = 0;
@Override
public Object execute(VirtualFrame frame) {
boolean startedCompiled = CompilerDirectives.inCompiledCode();
throwExceptionBoundary();
if (startedCompiled && CompilerDirectives.inInterpreter()) {
deopCounter++;
}
return null;
}
@CompilerDirectives.TruffleBoundary(transferToInterpreterOnException = false)
public void throwExceptionBoundary() {
throw new RuntimeException();
}
}
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
for (int i = 0; i < compilationThreshold; i++) {
try {
outerTarget.call();
} catch (RuntimeException e) {
// do nothing
}
}
assertCompiled(outerTarget);
final int execCount = 10;
for (int i = 0; i < execCount; i++) {
try {
outerTarget.call();
} catch (RuntimeException e) {
// do nothing
}
}
int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
Assert.assertEquals("Incorrect number of deops detected!", 0, deopCount);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TruffleDirectCallNodeTest method testCanBeClonedWithoutParent.
@Test
public void testCanBeClonedWithoutParent() {
final RootNode rootNode = new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return 42;
}
@Override
public boolean isCloningAllowed() {
return true;
}
};
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final DirectCallNode callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
assertTrue(callNode.isCallTargetCloningAllowed());
assertTrue(callNode.cloneCallTarget());
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class PhiStampInferencePartialEvaluationTest method ifPhiStamp.
@Test
public void ifPhiStamp() {
/*
* The stamp of a phi should be inferred during partial evaluation so that its type
* information can be used to devirtualize method calls.
*/
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new IfPhiStampTestNode();
RootNode rootNode = new RootTestNode(fd, "ifPhiStamp", result);
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
callTarget.call(new Object[] { true });
callTarget.call(new Object[] { false });
// ensure method cannot be statically bound without receiver type info
new D().get();
assertPartialEvalNoInvokes(callTarget, new Object[] { true });
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SLDisableSplittingBuiltin method disableSplitting.
@Specialization
@TruffleBoundary
public SLNull disableSplitting(@SuppressWarnings("unused") SLNull argument) {
RootNode parentRoot = Truffle.getRuntime().getCallerFrame().getCallNode().getRootNode();
((SLRootNode) parentRoot).setCloningAllowed(false);
return SLNull.SINGLETON;
}
use of com.oracle.truffle.api.nodes.RootNode in project sulong by graalvm.
the class LazyToTruffleConverterImpl method convert.
@Override
public RootCallTarget convert() {
CompilerAsserts.neverPartOfCompilation();
// parse the function block
parser.parse(diProcessor, source);
// prepare the phis
final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
// setup the frameDescriptor
final FrameDescriptor frame = StackManager.createFrame(method);
LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(frame, context, phis, method);
LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, frame);
List<FrameSlot> notNullable = new ArrayList<>();
LLVMRuntimeDebugInformation dbgInfoHandler = new LLVMRuntimeDebugInformation(frame, nodeFactory, context, notNullable, symbols, runtime);
dbgInfoHandler.registerStaticDebugSymbols(method);
LLVMBitcodeFunctionVisitor visitor = new LLVMBitcodeFunctionVisitor(runtime, frame, phis, nodeFactory, method.getParameters().size(), symbols, method, liveness, notNullable, dbgInfoHandler);
method.accept(visitor);
FrameSlot[][] nullableBeforeBlock = getNullableFrameSlots(frame, liveness.getNullableBeforeBlock(), notNullable);
FrameSlot[][] nullableAfterBlock = getNullableFrameSlots(frame, liveness.getNullableAfterBlock(), notNullable);
LLVMSourceLocation location = method.getLexicalScope();
List<LLVMExpressionNode> copyArgumentsToFrame = copyArgumentsToFrame(frame);
LLVMExpressionNode[] copyArgumentsToFrameArray = copyArgumentsToFrame.toArray(new LLVMExpressionNode[copyArgumentsToFrame.size()]);
LLVMExpressionNode body = nodeFactory.createFunctionBlockNode(runtime, frame.findFrameSlot(LLVMException.FRAME_SLOT_ID), visitor.getBlocks(), nullableBeforeBlock, nullableAfterBlock, location, copyArgumentsToFrameArray);
RootNode rootNode = nodeFactory.createFunctionStartNode(runtime, body, method.getSourceSection(), frame, method, source, location);
return Truffle.getRuntime().createCallTarget(rootNode);
}
Aggregations