Search in sources :

Example 1 with BytecodePosition

use of jdk.vm.ci.code.BytecodePosition in project graal by oracle.

the class GraphUtil method approxSourceStackTraceElement.

/**
 * Gets approximate stack trace elements for a bytecode position.
 */
public static StackTraceElement[] approxSourceStackTraceElement(BytecodePosition bytecodePosition) {
    ArrayList<StackTraceElement> elements = new ArrayList<>();
    BytecodePosition position = bytecodePosition;
    while (position != null) {
        ResolvedJavaMethod method = position.getMethod();
        if (method != null) {
            elements.add(method.asStackTraceElement(position.getBCI()));
        }
        position = position.getCaller();
    }
    return elements.toArray(new StackTraceElement[0]);
}
Also used : BytecodePosition(jdk.vm.ci.code.BytecodePosition) ArrayList(java.util.ArrayList) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with BytecodePosition

use of jdk.vm.ci.code.BytecodePosition in project graal by oracle.

the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.

private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, GraalDirectives.class);
    r.register0("deoptimize", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
            return true;
        }
    });
    r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
            return true;
        }
    });
    r.register0("deoptimizeAndInvalidateWithSpeculation", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            GraalError.guarantee(b.getGraph().getSpeculationLog() != null, "A speculation log is need to use `deoptimizeAndInvalidateWithSpeculation`");
            BytecodePosition pos = new BytecodePosition(null, b.getMethod(), b.bci());
            DirectiveSpeculationReason reason = new DirectiveSpeculationReason(pos);
            JavaConstant speculation;
            if (b.getGraph().getSpeculationLog().maySpeculate(reason)) {
                speculation = b.getGraph().getSpeculationLog().speculate(reason);
            } else {
                speculation = JavaConstant.defaultForKind(JavaKind.Object);
            }
            b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter, speculation));
            return true;
        }
    });
    r.register0("inCompiledCode", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            return true;
        }
    });
    r.register0("controlFlowAnchor", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new ControlFlowAnchorNode());
            return true;
        }
    });
    r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
            b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
            return true;
        }
    });
    InvocationPlugin blackholePlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new BlackholeNode(value));
            return true;
        }
    };
    InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new BindToRegisterNode(value));
            return true;
        }
    };
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
            r.register1("blackhole", javaClass, blackholePlugin);
            r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
            r.register1("opaque", javaClass, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(kind, new OpaqueNode(value));
                    return true;
                }
            });
        }
    }
    InvocationPlugin spillPlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new SpillRegistersNode());
            return true;
        }
    };
    r.register0("spillRegisters", spillPlugin);
    r.register1("guardingNonNull", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.addPush(value.getStackKind(), b.nullCheckedValue(value));
            return true;
        }
    });
    r.register1("ensureVirtualized", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, false));
            return true;
        }
    });
    r.register1("ensureVirtualizedHere", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, true));
            return true;
        }
    });
}
Also used : BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) BytecodePosition(jdk.vm.ci.code.BytecodePosition) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 3 with BytecodePosition

use of jdk.vm.ci.code.BytecodePosition in project graal by oracle.

the class CompilationPrinter method debugInfoToString.

/**
 * Formats given debug info as a multi line string.
 */
protected String debugInfoToString(BytecodePosition codePos, ReferenceMap refMap, IndexedValueMap liveBasePointers, RegisterSaveLayout calleeSaveInfo) {
    StringBuilder sb = new StringBuilder();
    if (refMap != null) {
        sb.append("reference-map: ");
        sb.append(refMap.toString());
        sb.append("\n");
    }
    if (liveBasePointers != null) {
        sb.append("live-base-pointers: ");
        sb.append(liveBasePointers);
        sb.append("\n");
    }
    if (calleeSaveInfo != null) {
        sb.append("callee-save-info:");
        for (Map.Entry<Register, Integer> e : calleeSaveInfo.registersToSlots(true).entrySet()) {
            sb.append(" " + e.getKey() + " -> s" + e.getValue());
        }
        sb.append("\n");
    }
    if (codePos != null) {
        BytecodePosition curCodePos = codePos;
        List<VirtualObject> virtualObjects = new ArrayList<>();
        do {
            sb.append(MetaUtil.toLocation(curCodePos.getMethod(), curCodePos.getBCI()));
            sb.append('\n');
            if (curCodePos instanceof BytecodeFrame) {
                BytecodeFrame frame = (BytecodeFrame) curCodePos;
                if (frame.numStack > 0) {
                    sb.append("stack: ");
                    for (int i = 0; i < frame.numStack; i++) {
                        sb.append(valueToString(frame.getStackValue(i), virtualObjects)).append(' ');
                    }
                    sb.append("\n");
                }
                sb.append("locals: ");
                for (int i = 0; i < frame.numLocals; i++) {
                    sb.append(valueToString(frame.getLocalValue(i), virtualObjects)).append(' ');
                }
                sb.append("\n");
                if (frame.numLocks > 0) {
                    sb.append("locks: ");
                    for (int i = 0; i < frame.numLocks; ++i) {
                        sb.append(valueToString(frame.getLockValue(i), virtualObjects)).append(' ');
                    }
                    sb.append("\n");
                }
            }
            curCodePos = curCodePos.getCaller();
        } while (curCodePos != null);
        for (int i = 0; i < virtualObjects.size(); i++) {
            VirtualObject obj = virtualObjects.get(i);
            sb.append(obj).append(" ").append(obj.getType().getName()).append(" ");
            for (int j = 0; j < obj.getValues().length; j++) {
                sb.append(valueToString(obj.getValues()[j], virtualObjects)).append(' ');
            }
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) BytecodePosition(jdk.vm.ci.code.BytecodePosition) Register(jdk.vm.ci.code.Register) VirtualObject(jdk.vm.ci.code.VirtualObject) ArrayList(java.util.ArrayList) ReferenceMap(jdk.vm.ci.code.ReferenceMap) IndexedValueMap(org.graalvm.compiler.lir.util.IndexedValueMap) Map(java.util.Map)

Aggregations

BytecodePosition (jdk.vm.ci.code.BytecodePosition)3 ArrayList (java.util.ArrayList)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Map (java.util.Map)1 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)1 ReferenceMap (jdk.vm.ci.code.ReferenceMap)1 Register (jdk.vm.ci.code.Register)1 VirtualObject (jdk.vm.ci.code.VirtualObject)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 IndexedValueMap (org.graalvm.compiler.lir.util.IndexedValueMap)1 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 BindToRegisterNode (org.graalvm.compiler.nodes.debug.BindToRegisterNode)1 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)1 ControlFlowAnchorNode (org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode)1 OpaqueNode (org.graalvm.compiler.nodes.debug.OpaqueNode)1 SpillRegistersNode (org.graalvm.compiler.nodes.debug.SpillRegistersNode)1 BranchProbabilityNode (org.graalvm.compiler.nodes.extended.BranchProbabilityNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1