com.oracle.truffle.api.frame.FrameInstance Java Examples

The following examples show how to use com.oracle.truffle.api.frame.FrameInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrameAccess.java    From trufflesqueak with MIT License 6 votes vote down vote up
@TruffleBoundary
public static MaterializedFrame findFrameForMarker(final FrameMarker frameMarker) {
    CompilerDirectives.bailout("Finding materializable frames should never be part of compiled code as it triggers deopts");
    LogUtils.ITERATE_FRAMES.fine("Iterating frames to find a marker...");
    final Frame frame = Truffle.getRuntime().iterateFrames(frameInstance -> {
        final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
        if (!isTruffleSqueakFrame(current)) {
            return null;
        }
        LogUtils.ITERATE_FRAMES.fine(() -> "..." + FrameAccess.getMethod(current).toString());
        if (frameMarker == getMarker(current)) {
            return frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
        }
        return null;
    });
    if (frame == null) {
        throw SqueakException.create("Could not find frame for:", frameMarker);
    } else {
        return frame.materialize();
    }
}
 
Example #2
Source File: ObjectGraphUtils.java    From trufflesqueak with MIT License 6 votes vote down vote up
private void addObjectsFromTruffleFrames() {
    CompilerAsserts.neverPartOfCompilation();
    Truffle.getRuntime().iterateFrames(frameInstance -> {
        final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
        if (!FrameAccess.isTruffleSqueakFrame(current)) {
            return null;
        }
        for (final Object argument : current.getArguments()) {
            addIfUnmarked(argument);
        }
        final CompiledCodeObject blockOrMethod = FrameAccess.getBlockOrMethod(current);
        addIfUnmarked(FrameAccess.getContext(current, blockOrMethod));
        for (final FrameSlot slot : blockOrMethod.getStackSlotsUnsafe()) {
            if (slot == null) {
                return null; // Stop here, slot has not (yet) been created.
            }
            if (current.isObject(slot)) {
                addIfUnmarked(FrameUtil.getObjectSafe(current, slot));
            }
        }
        return null;
    });
}
 
Example #3
Source File: HashemStackTraceBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@TruffleBoundary
private static String createStackTrace() {
    final StringBuilder str = new StringBuilder();

    Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {
        private int skip = 1; // skip stack trace builtin

        @Override
        public Integer visitFrame(FrameInstance frameInstance) {
            if (skip > 0) {
                skip--;
                return null;
            }
            CallTarget callTarget = frameInstance.getCallTarget();
            Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY);
            RootNode rn = ((RootCallTarget) callTarget).getRootNode();
            // ignore internal or interop stack frames
            if (rn.isInternal() || rn.getLanguageInfo() == null) {
                return 1;
            }
            if (str.length() > 0) {
                str.append(System.getProperty("line.separator"));
            }
            str.append("Frame: ").append(rn.toString());
            FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
            for (FrameSlot s : frameDescriptor.getSlots()) {
                str.append(", ").append(s.getIdentifier()).append("=").append(frame.getValue(s));
            }
            return null;
        }
    });
    return str.toString();
}
 
Example #4
Source File: TruffleAST.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Object[] getRawSlots() {
    Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
    List<? extends FrameSlot> slots = frame.getFrameDescriptor().getSlots();
    int n = slots.size();
    Object[] slotInfo = new Object[2*n];
    for (int i = 0; i < n; i++) {
        FrameSlot slot = slots.get(i);
        slotInfo[2*i] = slot.getIdentifier();
        slotInfo[2*i + 1] = frame.getValue(slot);
    }
    return slotInfo;
}
 
Example #5
Source File: DebugUtils.java    From trufflesqueak with MIT License 5 votes vote down vote up
public static void printSqStackTrace() {
    CompilerAsserts.neverPartOfCompilation("For debugging purposes only");
    final boolean isCIBuild = System.getenv().containsKey("GITHUB_ACTIONS");
    final int[] depth = new int[1];
    final Object[] lastSender = new Object[]{null};
    final PrintWriter err = SqueakLanguage.getContext().getError();
    err.println("== Truffle stack trace ===========================================================");
    Truffle.getRuntime().iterateFrames(frameInstance -> {
        if (depth[0]++ > 50 && isCIBuild) {
            return null;
        }
        final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
        if (!FrameAccess.isTruffleSqueakFrame(current)) {
            return null;
        }
        final CompiledMethodObject method = FrameAccess.getMethod(current);
        lastSender[0] = FrameAccess.getSender(current);
        final Object marker = FrameAccess.getMarker(current, method);
        final Object context = FrameAccess.getContext(current, method);
        final String prefix = FrameAccess.getClosure(current) == null ? "" : "[] in ";
        final String argumentsString = ArrayUtils.toJoinedString(", ", FrameAccess.getReceiverAndArguments(current));
        err.println(MiscUtils.format("%s%s #(%s) [marker: %s, context: %s, sender: %s]", prefix, method, argumentsString, marker, context, lastSender[0]));
        return null;
    });
    if (lastSender[0] instanceof ContextObject) {
        err.println("== Squeak frames ================================================================");
        printSqStackTrace((ContextObject) lastSender[0]);
    }
}
 
Example #6
Source File: TruffleAST.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private TruffleAST(FrameInstance frameInstance) {
    this.frameInstance = frameInstance;
}
 
Example #7
Source File: TruffleAST.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Object[] getRawArguments() {
    return frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE).getArguments();
}
 
Example #8
Source File: ContextObject.java    From trufflesqueak with MIT License 4 votes vote down vote up
public static ContextObject create(final FrameInstance frameInstance) {
    final Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
    return create(frame.materialize(), FrameAccess.getBlockOrMethod(frame));
}
 
Example #9
Source File: ContextPrimitives.java    From trufflesqueak with MIT License 4 votes vote down vote up
@TruffleBoundary
@Specialization(guards = {"!receiver.hasMaterializedSender()"})
protected final AbstractSqueakObject findNextAvoidingMaterialization(final ContextObject receiver) {
    final boolean[] foundMyself = new boolean[1];
    final Object[] lastSender = new Object[1];
    final ContextObject result = Truffle.getRuntime().iterateFrames(frameInstance -> {
        final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
        if (!FrameAccess.isTruffleSqueakFrame(current)) {
            final RootNode rootNode = ((RootCallTarget) frameInstance.getCallTarget()).getRootNode();
            if (rootNode.isInternal() || rootNode.getLanguageInfo().getId().equals(SqueakLanguageConfig.ID)) {
                /* Skip internal and all other nodes that belong to TruffleSqueak. */
                return null;
            } else {
                /*
                 * Found a frame of another language. Stop here by returning the receiver
                 * context. This special case will be handled later on.
                 */
                return receiver;
            }
        }
        final ContextObject context = FrameAccess.getContext(current);
        if (!foundMyself[0]) {
            if (context == receiver) {
                foundMyself[0] = true;
            }
        } else {
            if (FrameAccess.getMethod(current).isExceptionHandlerMarked()) {
                if (context != null) {
                    return context;
                } else {
                    return ContextObject.create(frameInstance);
                }
            } else {
                lastSender[0] = FrameAccess.getSender(current);
            }
        }
        return null;
    });
    if (result == receiver) {
        /*
         * Foreign frame found during frame iteration. Inject a fake context which will
         * throw the Smalltalk exception as polyglot exception.
         */
        return getInteropExceptionThrowingContext();
    } else if (result == null) {
        if (!foundMyself[0]) {
            return findNext(receiver); // Fallback to other version.
        }
        if (lastSender[0] instanceof ContextObject) {
            return findNext((ContextObject) lastSender[0]);
        } else {
            return NilObject.SINGLETON;
        }
    } else {
        return result;
    }
}