Search in sources :

Example 11 with GuardingNode

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

the class DefaultJavaLoweringProvider method lowerLoadIndexedNode.

protected void lowerLoadIndexedNode(LoadIndexedNode loadIndexed, LoweringTool tool) {
    StructuredGraph graph = loadIndexed.graph();
    ValueNode array = loadIndexed.array();
    array = createNullCheckedValue(array, loadIndexed, tool);
    JavaKind elementKind = loadIndexed.elementKind();
    Stamp loadStamp = loadStamp(loadIndexed.stamp(NodeView.DEFAULT), elementKind);
    GuardingNode boundsCheck = getBoundsCheck(loadIndexed, array, tool);
    AddressNode address = createArrayIndexAddress(graph, array, elementKind, loadIndexed.index(), boundsCheck);
    ReadNode memoryRead = graph.add(new ReadNode(address, NamedLocationIdentity.getArrayLocation(elementKind), loadStamp, BarrierType.NONE));
    memoryRead.setGuard(boundsCheck);
    ValueNode readValue = implicitLoadConvert(graph, elementKind, memoryRead);
    loadIndexed.replaceAtUsages(readValue);
    graph.replaceFixed(loadIndexed, memoryRead);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 12 with GuardingNode

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

the class InstanceOfSnippets method instanceofExact.

/**
 * A test against a final type.
 */
@Snippet
public static Object instanceofExact(Object object, KlassPointer exactHub, Object trueValue, Object falseValue, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        return falseValue;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    if (probability(LIKELY_PROBABILITY, objectHub.notEqual(exactHub))) {
        counters.exactMiss.inc();
        return falseValue;
    }
    counters.exactHit.inc();
    return trueValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 13 with GuardingNode

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

the class InstanceOfSnippets method instanceofWithProfile.

/**
 * A test against a set of hints derived from a profile with 100% precise coverage of seen
 * types. This snippet deoptimizes on hint miss paths.
 */
@Snippet
public static Object instanceofWithProfile(Object object, @VarargsParameter KlassPointer[] hints, @VarargsParameter boolean[] hintIsPositive, Object trueValue, Object falseValue, @ConstantParameter boolean nullSeen, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        if (!nullSeen) {
            // See comment below for other deoptimization path; the
            // same reasoning applies here.
            DeoptimizeNode.deopt(InvalidateReprofile, OptimizedTypeCheckViolated);
        }
        return falseValue;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    // if we get an exact match: succeed immediately
    ExplodeLoopNode.explodeLoop();
    for (int i = 0; i < hints.length; i++) {
        KlassPointer hintHub = hints[i];
        boolean positive = hintIsPositive[i];
        if (probability(LIKELY_PROBABILITY, hintHub.equal(objectHub))) {
            counters.hintsHit.inc();
            return positive ? trueValue : falseValue;
        }
        counters.hintsMiss.inc();
    }
    // This maybe just be a rare event but it might also indicate a phase change
    // in the application. Ideally we want to use DeoptimizationAction.None for
    // the former but the cost is too high if indeed it is the latter. As such,
    // we defensively opt for InvalidateReprofile.
    DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, OptimizedTypeCheckViolated);
    return falseValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 14 with GuardingNode

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

the class InstanceOfSnippets method instanceofDynamic.

/**
 * Type test used when the type being tested against is not known at compile time.
 */
@Snippet
public static Object instanceofDynamic(KlassPointer hub, Object object, Object trueValue, Object falseValue, @ConstantParameter boolean allowNull, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        if (allowNull) {
            return trueValue;
        } else {
            return falseValue;
        }
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer nonNullObjectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    // The hub of a primitive type can be null => always return false in this case.
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, !hub.isNull())) {
        if (checkUnknownSubType(hub, nonNullObjectHub, counters)) {
            return trueValue;
        }
    }
    return falseValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 15 with GuardingNode

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

the class InstanceOfSnippets method instanceofPrimary.

/**
 * A test against a primary type.
 */
@Snippet
public static Object instanceofPrimary(KlassPointer hub, Object object, @ConstantParameter int superCheckOffset, Object trueValue, Object falseValue, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        return falseValue;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    if (probability(NOT_LIKELY_PROBABILITY, objectHub.readKlassPointer(superCheckOffset, PRIMARY_SUPERS_LOCATION).notEqual(hub))) {
        counters.displayMiss.inc();
        return falseValue;
    }
    counters.displayHit.inc();
    return trueValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Aggregations

GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)15 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)7 Snippet (org.graalvm.compiler.api.replacements.Snippet)6 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)4 JavaKind (jdk.vm.ci.meta.JavaKind)3 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)3 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)3 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)2 GuardNode (org.graalvm.compiler.nodes.GuardNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)2 Assumptions (jdk.vm.ci.meta.Assumptions)1 DeoptimizationAction (jdk.vm.ci.meta.DeoptimizationAction)1 DeoptimizationReason (jdk.vm.ci.meta.DeoptimizationReason)1