Java源码示例:com.oracle.truffle.api.frame.Frame

示例1
public static FrameSlotReadNode create(final Frame frame, final int index) {
    // Only clear stack values, not receiver, arguments, or temporary variables.
    final CompiledCodeObject code;
    final int initialSP;
    final BlockClosureObject closure = FrameAccess.getClosure(frame);
    if (closure == null) {
        code = FrameAccess.getMethod(frame);
        initialSP = code.getNumTemps();
    } else {
        code = closure.getCompiledBlock();
        initialSP = code.getNumArgsAndCopied();
    }
    if (index >= initialSP) {
        return FrameSlotReadClearNodeGen.create(code.getStackSlot(index));
    } else {
        return FrameSlotReadNoClearNodeGen.create(code.getStackSlot(index));
    }
}
 
示例2
@Specialization(replaces = {"readBoolean", "readLong", "readDouble"})
protected final Object readObject(final Frame frame) {
    if (!frame.isObject(getSlot())) {
        /*
         * The FrameSlotKind has been set to Object, so from now on all writes to the slot
         * will be Object writes. However, now we are in a frame that still has an old
         * non-Object value. This is a slow-path operation: we read the non-Object value,
         * and write it immediately as an Object value so that we do not hit this path again
         * multiple times for the same slot of the same frame.
         */
        CompilerDirectives.transferToInterpreter();
        final Object value = frame.getValue(getSlot());
        assert value != null : "Unexpected `null` value";
        frame.setObject(getSlot(), value);
        return value;
    } else {
        return FrameUtil.getObjectSafe(frame, getSlot());
    }
}
 
示例3
@Specialization(replaces = {"readBoolean", "readLong", "readDouble"})
protected final Object readAndClearObject(final Frame frame) {
    final Object value;
    if (!frame.isObject(getSlot())) {
        /*
         * The FrameSlotKind has been set to Object, so from now on all writes to the slot
         * will be Object writes. However, now we are in a frame that still has an old
         * non-Object value. This is a slow-path operation: we read the non-Object value,
         * and clear it immediately as an Object value so that we do not hit this path again
         * multiple times for the same slot of the same frame.
         */
        CompilerDirectives.transferToInterpreter();
        value = frame.getValue(getSlot());
    } else {
        value = FrameUtil.getObjectSafe(frame, getSlot());
    }
    frame.setObject(getSlot(), null);
    return value;
}
 
示例4
/** Write to a frame slot (slow operation), prefer {@link FrameStackPushNode}. */
public static void setStackSlot(final Frame frame, final FrameSlot frameSlot, final Object value) {
    final FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
    assert frame.getFrameDescriptor().getSlots().contains(frameSlot);
    final FrameSlotKind frameSlotKind = frameDescriptor.getFrameSlotKind(frameSlot);
    final boolean isIllegal = frameSlotKind == FrameSlotKind.Illegal;
    if (value instanceof Boolean && (isIllegal || frameSlotKind == FrameSlotKind.Boolean)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Boolean);
        frame.setBoolean(frameSlot, (boolean) value);
    } else if (value instanceof Long && (isIllegal || frameSlotKind == FrameSlotKind.Long)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Long);
        frame.setLong(frameSlot, (long) value);
    } else if (value instanceof Double && (isIllegal || frameSlotKind == FrameSlotKind.Double)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Double);
        frame.setDouble(frameSlot, (double) value);
    } else {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Object);
        frame.setObject(frameSlot, value);
    }
}
 
示例5
@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();
    }
}
 
示例6
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;
    });
}
 
示例7
@Override
public Iterable<Scope> findLocalScopes(HashemContext context, Node node, Frame frame) {
    final HashemLexicalScope scope = HashemLexicalScope.createScope(node);
    return new Iterable<Scope>() {
        @Override
        public Iterator<Scope> iterator() {
            return new Iterator<Scope>() {
                private HashemLexicalScope previousScope;
                private HashemLexicalScope nextScope = scope;

                @Override
                public boolean hasNext() {
                    if (nextScope == null) {
                        nextScope = previousScope.findParent();
                    }
                    return nextScope != null;
                }

                @Override
                public Scope next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    Object functionObject = findFunctionObject();
                    Scope vscope = Scope.newBuilder(nextScope.getName(), nextScope.getVariables(frame)).node(nextScope.getNode()).arguments(nextScope.getArguments(frame)).rootInstance(
                            functionObject).build();
                    previousScope = nextScope;
                    nextScope = null;
                    return vscope;
                }

                private Object findFunctionObject() {
                    String name = node.getRootNode().getName();
                    return context.getFunctionRegistry().getFunction(name);
                }
            };
        }
    };
}
 
示例8
public Object getVariables(Frame frame) {
    Map<String, FrameSlot> vars = getVars();
    Object[] args = null;
    // Use arguments when the current node is above the block
    if (current == null) {
        args = (frame != null) ? frame.getArguments() : null;
    }
    return new VariablesMapObject(vars, args, frame);
}
 
示例9
public Object getArguments(Frame frame) {
    if (root == null) {
        // No arguments for block scope
        return null;
    }
    // The slots give us names of the arguments:
    Map<String, FrameSlot> argSlots = collectArgs(block);
    // The frame's arguments array give us the argument values:
    Object[] args = (frame != null) ? frame.getArguments() : null;
    // Create a TruffleObject having the arguments as properties:
    return new VariablesMapObject(argSlots, args, frame);
}
 
示例10
@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();
}
 
示例11
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;
}
 
示例12
@Override
protected Iterable<Scope> findLocalScopes(final SqueakImageContext context, final Node node, final Frame frame) {
    // TODO: support access at parse time (frame == null).
    if (!FrameAccess.isTruffleSqueakFrame(frame)) {
        return super.findLocalScopes(context, node, frame);
    }
    final CompiledCodeObject blockOrMethod = FrameAccess.getBlockOrMethod(frame);
    final String name = blockOrMethod.toString();
    final Object receiver = FrameAccess.getReceiver(frame);
    final ContextObjectInfo variables = new ContextObjectInfo(frame);
    final InteropArray arguments = new InteropArray(frame.getArguments());
    return Collections.singletonList(Scope.newBuilder(name, variables).node(node).receiver(receiver.toString(), receiver).arguments(arguments).build());
}
 
示例13
public ContextObjectInfo(final Frame frame) {
    this.frame = frame;
    final CompiledCodeObject code = FrameAccess.getBlockOrMethod(frame);
    for (final FrameSlot slot : code.getStackSlotsUnsafe()) {
        if (slot == null) {
            break;
        }
        slots.put(Objects.toString(slot.getIdentifier()), slot);
    }
}
 
示例14
@Specialization(guards = "isBooleanOrIllegal(frame)")
protected final void writeBool(final Frame frame, final boolean value) {
    /* Initialize type on first write. No-op if kind is already Boolean. */
    frame.getFrameDescriptor().setFrameSlotKind(getSlot(), FrameSlotKind.Boolean);

    frame.setBoolean(getSlot(), value);
}
 
示例15
@Specialization(guards = "isLongOrIllegal(frame)")
protected final void writeLong(final Frame frame, final long value) {
    /* Initialize type on first write. No-op if kind is already Long. */
    frame.getFrameDescriptor().setFrameSlotKind(getSlot(), FrameSlotKind.Long);

    frame.setLong(getSlot(), value);
}
 
示例16
@Specialization(guards = "isDoubleOrIllegal(frame)")
protected final void writeDouble(final Frame frame, final double value) {
    /* Initialize type on first write. No-op if kind is already Double. */
    frame.getFrameDescriptor().setFrameSlotKind(getSlot(), FrameSlotKind.Double);

    frame.setDouble(getSlot(), value);
}
 
示例17
@Specialization(replaces = {"writeBool", "writeLong", "writeDouble"})
protected final void writeObject(final Frame frame, final Object value) {
    /* Initialize type on first write. No-op if kind is already Object. */
    frame.getFrameDescriptor().setFrameSlotKind(getSlot(), FrameSlotKind.Object);

    assert !isNullOrIllegalPrimitive(value) : "Propagation of illegal value detected: " + value;
    frame.setObject(getSlot(), value);
}
 
示例18
public static final ContextObject getOrCreateFromActiveProcessUncached(final Frame frame) {
    CompilerAsserts.neverPartOfCompilation();
    final CompiledCodeObject code = FrameAccess.getBlockOrMethod(frame);
    final ContextObject context = FrameAccess.getContext(frame, code);
    if (context != null) {
        return context;
    } else {
        final ContextObject result = ContextObject.create(frame.materialize(), code);
        result.setProcess(GetActiveProcessNode.getUncached().execute());
        return result;
    }
}
 
示例19
public Object execute(final Frame frame) {
    if (readNode == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        final int stackPointer = FrameAccess.getStackPointerSlow(frame) - 1;
        readNode = FrameSlotReadNode.create(FrameAccess.getStackSlot(frame, stackPointer));
    }
    return readNode.executeRead(frame);
}
 
示例20
public static void setArgumentIfInRange(final Frame frame, final int index, final Object value) {
    assert index >= 0;
    final Object[] frameArguments = frame.getArguments();
    final int argumentIndex = ArgumentIndicies.ARGUMENTS_START.ordinal() + index;
    if (argumentIndex < frameArguments.length) {
        frameArguments[argumentIndex] = value;
    }
}
 
示例21
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]);
    }
}
 
示例22
protected static MaterializedFrame getLexicalScope(Frame frame) {
    Object[] args = frame.getArguments();
    if (args.length > 0) {
        return (MaterializedFrame) frame.getArguments()[0];
    } else {
        return null;
    }
}
 
示例23
@ExplodeLoop
public <T> T readUpStack(FrameGet<T> getter, Frame frame)
        throws FrameSlotTypeException {

    Frame lookupFrame = frame;
    for (int i = 0; i < this.getDepth(); i++) {
        lookupFrame = getLexicalScope(lookupFrame);
    }
    return getter.get(lookupFrame, this.getSlot());
}
 
示例24
@Specialization(replaces = { "readLong", "readBoolean", "readObject" })
protected Object read(VirtualFrame virtualFrame) {
    try {
        return this.readUpStack(Frame::getValue, virtualFrame);
    } catch (FrameSlotTypeException e) {
        // FrameSlotTypeException not thrown
    }
    return null;
}
 
示例25
private VariablesMapObject(Map<String, ? extends FrameSlot> slots, Object[] args, Frame frame) {
    this.slots = slots;
    this.args = args;
    this.frame = frame;
}
 
示例26
public static ContextObject create(final FrameInstance frameInstance) {
    final Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
    return create(frame.materialize(), FrameAccess.getBlockOrMethod(frame));
}
 
示例27
protected final boolean isBooleanOrIllegal(final Frame frame) {
    final FrameSlotKind kind = frame.getFrameDescriptor().getFrameSlotKind(getSlot());
    return kind == FrameSlotKind.Boolean || kind == FrameSlotKind.Illegal;
}
 
示例28
protected final boolean isLongOrIllegal(final Frame frame) {
    final FrameSlotKind kind = frame.getFrameDescriptor().getFrameSlotKind(getSlot());
    return kind == FrameSlotKind.Long || kind == FrameSlotKind.Illegal;
}
 
示例29
protected final boolean isDoubleOrIllegal(final Frame frame) {
    final FrameSlotKind kind = frame.getFrameDescriptor().getFrameSlotKind(getSlot());
    return kind == FrameSlotKind.Double || kind == FrameSlotKind.Illegal;
}
 
示例30
public final Object executeRead(final Frame frame) {
    final Object value = executeReadUnsafe(frame);
    assert value != null : "Unexpected `null` value";
    return value;
}