private OSRRootNode createRootNodeImpl(RootNode root, Class<? extends VirtualFrame> frameClass) { return createRootNode(root == null ? null : root.getFrameDescriptor(), frameClass); }
@Override public String getName() { return root.getName(); }
protected DefaultCallTarget(RootNode function) { this.rootNode = function; this.rootNode.adoptChildren(); this.rootNode.applyInstrumentation(); }
/** * A description of the trace element. If the language does not provide such a description then * <code>null</code> is returned. * * @since 1.0 */ public String getName() { RootNode root = findCurrentRoot(); if (root == null) { return null; } try { return root.getName(); } catch (ThreadDeath td) { throw td; } catch (Throwable ex) { throw new DebugException(session, ex, root.getLanguageInfo(), null, true, null); } }
@Override public CallTarget accessIsExecutable() { return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false)); } @Override
@Override public Object call(Object... args) { final VirtualFrame frame = new DefaultVirtualFrame(getRootNode().getFrameDescriptor(), args); FrameInstance oldCurrentFrame = defaultTruffleRuntime().setCurrentFrame(new FrameInstance() { public Frame getFrame(FrameAccess access, boolean slowPath) { return frame; } public boolean isVirtualFrame() { return false; } public Node getCallNode() { return null; } public CallTarget getCallTarget() { return DefaultCallTarget.this; } }); try { return getRootNode().execute(frame); } finally { defaultTruffleRuntime().setCurrentFrame(oldCurrentFrame); } }
/** * Reports the execution count of a loop that is a child of this node. The optimization * heuristics can use the loop count to guide compilation and inlining. */ public final void reportLoopCount(int count) { if (getCallTarget() instanceof LoopCountReceiver) { ((LoopCountReceiver) getCallTarget()).reportLoopCount(count); } }
@Override boolean isInstrumentableRoot(RootNode node) { LanguageInfo langInfo = node.getLanguageInfo(); if (langInfo == null) { return false; } if (langInfo != languageInfo) { return false; } return true; }
private void visitRoot(RootNode root, final Node node, final AbstractNodeVisitor visitor, boolean forceRootBitComputation) { if (TRACE) { trace("BEGIN: Visit root %s for %s%n", root.toString(), visitor); } visitor.root = root; visitor.providedTags = getProvidedTags(root); visitor.rootSourceSection = root.getSourceSection(); visitor.rootBits = RootNodeBits.get(visitor.root); if (visitor.shouldVisit() || forceRootBitComputation) { if (forceRootBitComputation) { visitor.computingRootNodeBits = RootNodeBits.isUninitialized(visitor.rootBits) ? RootNodeBits.getAll() : visitor.rootBits; } else if (RootNodeBits.isUninitialized(visitor.rootBits)) { visitor.computingRootNodeBits = RootNodeBits.getAll(); } if (TRACE) { trace("BEGIN: Traverse root %s for %s%n", root.toString(), visitor); } visitor.visit(node); if (TRACE) { trace("END: Traverse root %s for %s%n", root.toString(), visitor); } if (!RootNodeBits.isUninitialized(visitor.computingRootNodeBits)) { RootNodeBits.set(visitor.root, visitor.computingRootNodeBits); } } if (TRACE) { trace("END: Visited root %s for %s%n", root.toString(), visitor); } }
@Override public String toString() { return rootNode.toString(); }
@Override public RootCallTarget createCallTarget(RootNode rootNode) { DefaultCallTarget target = new DefaultCallTarget(rootNode); rootNode.setCallTarget(target); callTargets.put(target, null); return target; }
LanguageInfo info = rootNode.getLanguageInfo(); if (info == null) { throw new IllegalArgumentException("Cannot evaluate in context using a without an associated TruffleLanguage."); if (target instanceof RootCallTarget) { RootNode exec = ((RootCallTarget) target).getRootNode(); return exec.execute(mFrame); } else { throw new IllegalStateException("" + target);
/** * Returns <code>true</code> if this root node should be considered internal and not be shown to * a guest language programmer. This method has effect on tools and guest language stack traces. * By default a {@link RootNode} is internal if no language was passed in the constructor or if * the {@link #getSourceSection() root source section} is set and points to an internal source. * This method is intended to be overwritten by guest languages, when the node's source is * internal, the implementation should respect that. Can be called on any thread and without a * language context. * * @since 0.27 */ public boolean isInternal() { if (getLanguageInfo() == null) { return true; } SourceSection sc = getSourceSection(); if (sc != null) { return sc.getSource().isInternal(); } return false; }
@Override public Object evalInContext(Source source, Node node, final MaterializedFrame mFrame) { CallTarget target = API.nodes().getLanguage(node.getRootNode()).parse(source, node, mFrame); try { if (target instanceof RootCallTarget) { RootNode exec = ((RootCallTarget) target).getRootNode(); return exec.execute(mFrame); } else { throw new IllegalStateException("" + target); } } catch (Exception ex) { if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } throw new RuntimeException(ex); } }
/** * Get compiler options specific to this <code>RootNode</code>. */ public CompilerOptions getCompilerOptions() { final ExecutionContext context = getExecutionContext(); if (context == null) { return DefaultCompilerOptions.INSTANCE; } else { return context.getCompilerOptions(); } }
DefaultCallTarget(RootNode function) { this.rootNode = function; this.rootNode.adoptChildren(); }
@Override public CallTarget accessIsInstantiable() { return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false)); } @Override
Object callDirectOrIndirect(final Node callNode, Object... args) { if (!this.initialized) { initialize(); } final DefaultVirtualFrame frame = new DefaultVirtualFrame(getRootNode().getFrameDescriptor(), args); getRuntime().pushFrame(frame, this, callNode); try { return getRootNode().execute(frame); } catch (Throwable t) { getRuntime().getTvmci().onThrowable(callNode, this, t, frame); throw t; } finally { getRuntime().popFrame(); } }
public String displayMethodName(Node node) { if (node == null) { return null; } RootNode root = node.getRootNode(); if (root == null) { return "unknown"; } return root.getCallTarget().toString(); }