use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.
the class OptimizedCallTargetTest method testInCompilationRootDirective.
@Ignore
@Test
public void testInCompilationRootDirective() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
int[] outerExecute = { 0 };
int[] outerMethod = { 0 };
int[] outerBoundary = { 0 };
int[] innerExecute = { 0 };
int[] innerMethod = { 0 };
int[] innerBoundary = { 0 };
final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "inner";
}
@Override
public Object execute(VirtualFrame frame) {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerExecute[0]++;
}
innerMethod();
return null;
}
@CompilerDirectives.TruffleBoundary
void innerMethod() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerMethod[0]++;
}
}
@CompilerDirectives.TruffleBoundary
void innerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerBoundary[0] = 1;
}
}
});
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "outer";
}
@Child
private DirectCallNode child = runtime.createDirectCallNode(innerTarget);
@Override
public Object execute(VirtualFrame frame) {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerExecute[0]++;
}
outerMethod();
return child.call(new Object[0]);
}
void outerMethod() {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerMethod[0]++;
outerBoundary();
}
}
@CompilerDirectives.TruffleBoundary
void outerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
outerBoundary[0]++;
}
}
});
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call();
}
assertCompiled(outerTarget);
final int executionCount = 10;
for (int i = 0; i < executionCount; i++) {
outerTarget.call();
}
Assert.assertEquals(executionCount, outerExecute[0]);
Assert.assertEquals(executionCount, outerMethod[0]);
Assert.assertEquals(0, outerBoundary[0]);
Assert.assertEquals(0, innerExecute[0]);
Assert.assertEquals(0, innerMethod[0]);
Assert.assertEquals(0, innerBoundary[0]);
}
use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.
the class InteropAccessNode method createInlinedCallNode.
protected static DirectCallNode createInlinedCallNode(CallTarget target) {
if (target == null) {
return null;
}
DirectCallNode callNode = DirectCallNode.create(target);
callNode.forceInlining();
return callNode;
}
use of com.oracle.truffle.api.nodes.DirectCallNode 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.DirectCallNode 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.nodes.DirectCallNode in project graal by oracle.
the class SLGraalRuntimeBuiltin method findCallsTo.
/**
* Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in a
* given {@link RootNode}.
*/
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(RootNode root, OptimizedCallTarget originalCallTarget) {
final Set<DirectCallNode> allCallNodes = new HashSet<>();
root.accept(new NodeVisitor() {
@Override
public boolean visit(Node node) {
if (node instanceof DirectCallNode) {
DirectCallNode callNode = (DirectCallNode) node;
if (callNode.getCallTarget() == originalCallTarget || callNode.getClonedCallTarget() == originalCallTarget) {
allCallNodes.add(callNode);
}
}
return true;
}
});
return allCallNodes;
}
Aggregations