Search in sources :

Example 1 with DeoptimizationReason

use of jdk.vm.ci.meta.DeoptimizationReason in project graal by oracle.

the class MethodHandleNode method maybeCastArgument.

/**
 * Inserts a node to cast the argument at index to the given type if the given type is more
 * concrete than the argument type.
 *
 * @param adder
 * @param index of the argument to be cast
 * @param type the type the argument should be cast to
 */
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
    ValueNode argument = arguments[index];
    if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
        Assumptions assumptions = adder.getAssumptions();
        TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
        /*
             * When an argument is a Word type, we can have a mismatch of primitive/object types
             * here. Not inserting a PiNode is a safe fallback, and Word types need no additional
             * type information anyway.
             */
        if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
            ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
            if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
                LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
                assert !inst.isAlive();
                if (!inst.isTautology()) {
                    inst = adder.add(inst);
                    AnchoringNode guardAnchor = adder.getGuardAnchor();
                    DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
                    DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
                    JavaConstant speculation = JavaConstant.NULL_POINTER;
                    GuardingNode guard;
                    if (guardAnchor == null) {
                        FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
                        guard = fixedGuard;
                    } else {
                        GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
                        adder.add(new ValueAnchorNode(newGuard));
                        guard = newGuard;
                    }
                    ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
                    arguments[index] = valueNode;
                }
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) AnchoringNode(org.graalvm.compiler.nodes.extended.AnchoringNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 2 with DeoptimizationReason

use of jdk.vm.ci.meta.DeoptimizationReason in project graal by oracle.

the class SnippetRuntime method deoptimize.

/**
 * Foreign call: {@link #DEOPTIMIZE}.
 */
@SubstrateForeignCallTarget
private static void deoptimize(long actionAndReason, SpeculationReason speculation) {
    Pointer sp = KnownIntrinsics.readCallerStackPointer();
    DeoptimizationAction action = Deoptimizer.decodeDeoptAction(actionAndReason);
    if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
        Log log = Log.log().string("[Deoptimization initiated").newline();
        CodePointer ip = KnownIntrinsics.readReturnAddress();
        SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(ip);
        if (installedCode != null) {
            log.string("    name: ").string(installedCode.getName()).newline();
        }
        log.string("    sp: ").hex(sp).string("  ip: ").hex(ip).newline();
        DeoptimizationReason reason = Deoptimizer.decodeDeoptReason(actionAndReason);
        log.string("    reason: ").string(reason.toString()).string("  action: ").string(action.toString()).newline();
        int debugId = Deoptimizer.decodeDebugId(actionAndReason);
        log.string("    debugId: ").signed(debugId).string("  speculation: ").string(Objects.toString(speculation)).newline();
        CodeInfoQueryResult info = CodeInfoTable.lookupCodeInfoQueryResult(ip);
        if (info != null) {
            NodeSourcePosition sourcePosition = DeoptimizationSourcePositionDecoder.decode(debugId, info);
            if (sourcePosition != null) {
                log.string("    stack trace that triggered deoptimization:").newline();
                NodeSourcePosition cur = sourcePosition;
                while (cur != null) {
                    log.string("        at ");
                    if (cur.getMethod() != null) {
                        StackTraceElement element = cur.getMethod().asStackTraceElement(cur.getBCI());
                        if (element.getFileName() != null && element.getLineNumber() >= 0) {
                            log.string(element.toString());
                        } else {
                            log.string(cur.getMethod().format("%H.%n(%p)")).string(" bci ").signed(cur.getBCI());
                        }
                    } else {
                        log.string("[unknown method]");
                    }
                    log.newline();
                    cur = cur.getCaller();
                }
            }
        }
    }
    if (action.doesInvalidateCompilation()) {
        Deoptimizer.invalidateMethodOfFrame(sp, speculation);
    } else {
        Deoptimizer.deoptimizeFrame(sp, false, speculation);
    }
    if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
        Log.log().string("]").newline();
    }
}
Also used : Log(com.oracle.svm.core.log.Log) SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodeInfoQueryResult(com.oracle.svm.core.code.CodeInfoQueryResult) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 3 with DeoptimizationReason

use of jdk.vm.ci.meta.DeoptimizationReason in project graal by oracle.

the class GraalCompilerTest method executeActualCheckDeopt.

protected Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) {
    Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class);
    ProfilingInfo profile = method.getProfilingInfo();
    for (DeoptimizationReason reason : shouldNotDeopt) {
        deoptCounts.put(reason, profile.getDeoptimizationCount(reason));
    }
    Result actual = executeActual(options, method, receiver, args);
    // profile can change after execution
    profile = method.getProfilingInfo();
    for (DeoptimizationReason reason : shouldNotDeopt) {
        Assert.assertEquals("wrong number of deopt counts for " + reason, (int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason));
    }
    return actual;
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) EnumMap(java.util.EnumMap) CompilationResult(org.graalvm.compiler.code.CompilationResult) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)

Example 4 with DeoptimizationReason

use of jdk.vm.ci.meta.DeoptimizationReason in project graal by oracle.

the class UseTrappingNullChecksPhase method tryUseTrappingNullCheck.

private static void tryUseTrappingNullCheck(MetaAccessProvider metaAccessProvider, DynamicDeoptimizeNode deopt, long implicitNullCheckLimit) {
    Node predecessor = deopt.predecessor();
    if (predecessor instanceof AbstractMergeNode) {
        AbstractMergeNode merge = (AbstractMergeNode) predecessor;
        // Process each predecessor at the merge, unpacking the reasons and speculations as
        // needed.
        ValueNode reason = deopt.getActionAndReason();
        ValuePhiNode reasonPhi = null;
        List<ValueNode> reasons = null;
        int expectedPhis = 0;
        if (reason instanceof ValuePhiNode) {
            reasonPhi = (ValuePhiNode) reason;
            if (reasonPhi.merge() != merge) {
                return;
            }
            reasons = reasonPhi.values().snapshot();
            expectedPhis++;
        } else if (!reason.isConstant()) {
            return;
        }
        ValueNode speculation = deopt.getSpeculation();
        ValuePhiNode speculationPhi = null;
        List<ValueNode> speculations = null;
        if (speculation instanceof ValuePhiNode) {
            speculationPhi = (ValuePhiNode) speculation;
            if (speculationPhi.merge() != merge) {
                return;
            }
            speculations = speculationPhi.values().snapshot();
            expectedPhis++;
        }
        if (merge.phis().count() != expectedPhis) {
            return;
        }
        int index = 0;
        for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) {
            ValueNode thisReason = reasons != null ? reasons.get(index) : reason;
            ValueNode thisSpeculation = speculations != null ? speculations.get(index++) : speculation;
            if (!thisReason.isConstant() || !thisSpeculation.isConstant() || !thisSpeculation.asConstant().equals(JavaConstant.NULL_POINTER)) {
                continue;
            }
            DeoptimizationReason deoptimizationReason = metaAccessProvider.decodeDeoptReason(thisReason.asJavaConstant());
            tryUseTrappingNullCheck(deopt, end.predecessor(), deoptimizationReason, null, implicitNullCheckLimit);
        }
    }
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DynamicDeoptimizeNode(org.graalvm.compiler.nodes.DynamicDeoptimizeNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NullCheckNode(org.graalvm.compiler.nodes.extended.NullCheckNode) Node(org.graalvm.compiler.graph.Node) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason)

Aggregations

DeoptimizationReason (jdk.vm.ci.meta.DeoptimizationReason)4 DeoptimizationAction (jdk.vm.ci.meta.DeoptimizationAction)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 CodeInfoQueryResult (com.oracle.svm.core.code.CodeInfoQueryResult)1 SubstrateInstalledCode (com.oracle.svm.core.deopt.SubstrateInstalledCode)1 Log (com.oracle.svm.core.log.Log)1 EnumMap (java.util.EnumMap)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ProfilingInfo (jdk.vm.ci.meta.ProfilingInfo)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)1 Node (org.graalvm.compiler.graph.Node)1 NodeSourcePosition (org.graalvm.compiler.graph.NodeSourcePosition)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractDeoptimizeNode (org.graalvm.compiler.nodes.AbstractDeoptimizeNode)1 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1