use of com.oracle.truffle.api.frame.VirtualFrame 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.frame.VirtualFrame in project graal by oracle.
the class OptimizedOSRLoopNodeTest method testTransferToInterpreter.
/*
* Test that calling CompilerDirectives.transferToInterpreter does not invalidate the target.
*/
@Test
public void testTransferToInterpreter() {
OSRLoopFactory factory = CONFIGURED;
class TransferToInterpreterTestRepeatingNode extends TestRepeatingNode {
@Override
public boolean executeRepeating(VirtualFrame frame) {
try {
if (CompilerDirectives.inCompiledCode()) {
CompilerDirectives.transferToInterpreter();
}
int counter = frame.getInt(param1);
frame.setInt(param1, counter - 1);
return counter != 0;
} catch (FrameSlotTypeException e) {
return false;
}
}
}
TestRootNode rootNode = new TestRootNode(factory, new TransferToInterpreterTestRepeatingNode());
CallTarget target = runtime.createCallTarget(rootNode);
target.call(OSR_THRESHOLD + 1);
try {
// Invalidation is asynchronous.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertNotNull(rootNode.getOSRTarget());
}
use of com.oracle.truffle.api.frame.VirtualFrame in project TrufflePascal by Aspect26.
the class PascalLanguage method createUnitFrame.
public VirtualFrame createUnitFrame(String unitIdentifier, FrameDescriptor frameDescriptor) {
VirtualFrame unitFrame = Truffle.getRuntime().createVirtualFrame(new Object[0], frameDescriptor);
this.unitFrames.put(unitIdentifier, unitFrame);
return unitFrame;
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class SplittingStrategyTest method testDefaultStrategyStabilises.
@Test
@SuppressWarnings("try")
public void testDefaultStrategyStabilises() {
try (TruffleCompilerOptions.TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleSplittingMaxNumberOfSplitNodes, fallbackSplitInfo.getSplitLimit() + 1000)) {
createDummyTargetsToBoostGrowingSplitLimit();
class InnerRootNode extends SplittableRootNode {
OptimizedCallTarget target;
@Child
private DirectCallNode callNode1;
@Child
private Node polymorphic = new Node() {
@Override
public NodeCost getCost() {
return NodeCost.POLYMORPHIC;
}
};
protected InnerRootNode() {
super();
}
@Override
public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
if (callNode1 == null) {
callNode1 = runtime.createDirectCallNode(target);
adoptChildren();
}
if (frame.getArguments().length > 0) {
if ((Integer) frame.getArguments()[0] < 100) {
callNode1.call(frame.getArguments());
}
}
return null;
}
@Override
public String toString() {
return "INNER";
}
}
final InnerRootNode innerRootNode = new InnerRootNode();
final OptimizedCallTarget inner = (OptimizedCallTarget) runtime.createCallTarget(innerRootNode);
final OptimizedCallTarget mid = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {
@Child
private DirectCallNode callNode = null;
@Child
private Node polymorphic = new Node() {
@Override
public NodeCost getCost() {
return NodeCost.POLYMORPHIC;
}
};
@Override
public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
if (callNode == null) {
callNode = runtime.createDirectCallNode(inner);
adoptChildren();
}
Object[] arguments = frame.getArguments();
if ((Integer) arguments[0] < 100) {
callNode.call(new Object[] { ((Integer) arguments[0]) + 1 });
}
return null;
}
@Override
public String toString() {
return "MID";
}
});
OptimizedCallTarget outside = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {
// runtime.createDirectCallNode(mid);
@Child
private DirectCallNode outsideCallNode = null;
@Override
public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
// Emulates builtin i.e. Split immediately
if (outsideCallNode == null) {
outsideCallNode = runtime.createDirectCallNode(mid);
adoptChildren();
outsideCallNode.cloneCallTarget();
}
return outsideCallNode.call(frame.getArguments());
}
@Override
public String toString() {
return "OUTSIDE";
}
});
innerRootNode.target = outside;
createDummyTargetsToBoostGrowingSplitLimit();
final int baseSplitCount = listener.splitCount;
outside.call(1);
// Expected 14
// OUTSIDE MID
// MID <split> INNER
// INNER <split> OUTSIDE
// OUTSIDE <split> MID
// INNER OUTSIDE
// OUTSIDE <split> MID
// MID <split> INNER
// MID <split> INNER
// INNER <split> OUTSIDE
// OUTSIDE <split> MID
// INNER <split> OUTSIDE
// OUTSIDE <split> MID
// MID <split> INNER
Assert.assertEquals("Not the right number of splits.", baseSplitCount + 13, listener.splitCount);
}
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoCatch.
@Test
public void testExceptionOnTruffleBoundaryWithNoCatch() {
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
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);
}
Aggregations