Search in sources :

Example 11 with DeoptimizeNode

use of org.graalvm.compiler.nodes.DeoptimizeNode in project graal by oracle.

the class BytecodeParser method genNewInstance.

void genNewInstance(JavaType type) {
    if (!(type instanceof ResolvedJavaType)) {
        handleUnresolvedNewInstance(type);
        return;
    }
    ResolvedJavaType resolvedType = (ResolvedJavaType) type;
    ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
    if (!resolvedType.isInitialized() && classInitializationPlugin == null) {
        handleUnresolvedNewInstance(type);
        return;
    }
    ResolvedJavaType[] skippedExceptionTypes = this.graphBuilderConfig.getSkippedExceptionTypes();
    if (skippedExceptionTypes != null) {
        for (ResolvedJavaType exceptionType : skippedExceptionTypes) {
            if (exceptionType.isAssignableFrom(resolvedType)) {
                append(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, RuntimeConstraint));
                return;
            }
        }
    }
    if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedType)) {
        FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
        classInitializationPlugin.apply(this, resolvedType, stateBefore);
    }
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleNewInstance(this, resolvedType)) {
            return;
        }
    }
    frameState.push(JavaKind.Object, append(createNewInstance(resolvedType, true)));
}
Also used : NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ClassInitializationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 12 with DeoptimizeNode

use of org.graalvm.compiler.nodes.DeoptimizeNode in project graal by oracle.

the class BytecodeParser method handleUnresolvedExceptionType.

/**
 * @param type
 */
protected void handleUnresolvedExceptionType(JavaType type) {
    assert !graphBuilderConfig.unresolvedIsError();
    DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
    deopt.updateNodeSourcePosition(() -> createBytecodePosition());
}
Also used : DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode)

Example 13 with DeoptimizeNode

use of org.graalvm.compiler.nodes.DeoptimizeNode in project graal by oracle.

the class BytecodeParser method handleUnresolvedInstanceOf.

/**
 * @param type the unresolved type of the type check
 * @param object the object value whose type is being checked against {@code type}
 */
protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) {
    assert !graphBuilderConfig.unresolvedIsError();
    AbstractBeginNode successor = graph.add(new BeginNode());
    DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved));
    deopt.updateNodeSourcePosition(() -> createBytecodePosition());
    append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1));
    lastInstr = successor;
    frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0));
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 14 with DeoptimizeNode

use of org.graalvm.compiler.nodes.DeoptimizeNode in project graal by oracle.

the class DefaultLoopPolicies method shouldUnswitch.

@Override
public boolean shouldUnswitch(LoopEx loop, List<ControlSplitNode> controlSplits) {
    int phis = 0;
    StructuredGraph graph = loop.loopBegin().graph();
    DebugContext debug = graph.getDebug();
    NodeBitMap branchNodes = graph.createNodeBitMap();
    for (ControlSplitNode controlSplit : controlSplits) {
        for (Node successor : controlSplit.successors()) {
            AbstractBeginNode branch = (AbstractBeginNode) successor;
            // this may count twice because of fall-through in switches
            loop.nodesInLoopBranch(branchNodes, branch);
        }
        Block postDomBlock = loop.loopsData().getCFG().blockFor(controlSplit).getPostdominator();
        if (postDomBlock != null) {
            IsolatedInitialization.UNSWITCH_SPLIT_WITH_PHIS.increment(debug);
            phis += ((MergeNode) postDomBlock.getBeginNode()).phis().count();
        }
    }
    int inBranchTotal = branchNodes.count();
    CountingClosure stateNodesCount = new CountingClosure();
    double loopFrequency = loop.loopBegin().loopFrequency();
    OptionValues options = loop.loopBegin().getOptions();
    int maxDiff = Options.LoopUnswitchTrivial.getValue(options) + (int) (Options.LoopUnswitchFrequencyBoost.getValue(options) * (loopFrequency - 1.0 + phis));
    maxDiff = Math.min(maxDiff, Options.LoopUnswitchMaxIncrease.getValue(options));
    int remainingGraphSpace = MaximumDesiredSize.getValue(options) - graph.getNodeCount();
    maxDiff = Math.min(maxDiff, remainingGraphSpace);
    loop.loopBegin().stateAfter().applyToVirtual(stateNodesCount);
    int loopTotal = loop.size() - loop.loopBegin().phis().count() - stateNodesCount.count - 1;
    int actualDiff = (loopTotal - inBranchTotal);
    ControlSplitNode firstSplit = controlSplits.get(0);
    if (firstSplit instanceof TypeSwitchNode) {
        int copies = firstSplit.successors().count() - 1;
        for (Node succ : firstSplit.successors()) {
            FixedNode current = (FixedNode) succ;
            while (current instanceof FixedWithNextNode) {
                current = ((FixedWithNextNode) current).next();
            }
            if (current instanceof DeoptimizeNode) {
                copies--;
            }
        }
        actualDiff = actualDiff * copies;
    }
    debug.log("shouldUnswitch(%s, %s) : delta=%d (%.2f%% inside of branches), max=%d, f=%.2f, phis=%d -> %b", loop, controlSplits, actualDiff, (double) (inBranchTotal) / loopTotal * 100, maxDiff, loopFrequency, phis, actualDiff <= maxDiff);
    if (actualDiff <= maxDiff) {
        // check whether we're allowed to unswitch this loop
        return loop.canDuplicateLoop();
    } else {
        return false;
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) OptionValues(org.graalvm.compiler.options.OptionValues) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Block(org.graalvm.compiler.nodes.cfg.Block) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode)

Example 15 with DeoptimizeNode

use of org.graalvm.compiler.nodes.DeoptimizeNode 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)

Aggregations

DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)32 FixedNode (org.graalvm.compiler.nodes.FixedNode)11 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)10 ValueNode (org.graalvm.compiler.nodes.ValueNode)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 BeginNode (org.graalvm.compiler.nodes.BeginNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 Node (org.graalvm.compiler.graph.Node)6 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)6 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)6 FrameState (org.graalvm.compiler.nodes.FrameState)5 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)5 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)5 JavaKind (jdk.vm.ci.meta.JavaKind)4 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)4 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)4