Search in sources :

Example 11 with KlassPointer

use of org.graalvm.compiler.hotspot.word.KlassPointer 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 12 with KlassPointer

use of org.graalvm.compiler.hotspot.word.KlassPointer 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 13 with KlassPointer

use of org.graalvm.compiler.hotspot.word.KlassPointer 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

KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)13 Snippet (org.graalvm.compiler.api.replacements.Snippet)8 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)7 Word (org.graalvm.compiler.word.Word)4 Pointer (org.graalvm.word.Pointer)3 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)2 MethodSubstitution (org.graalvm.compiler.api.replacements.MethodSubstitution)1 HotSpotReplacementsUtil.loadKlassFromObject (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)1