Search in sources :

Example 6 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class ArrayCopySnippets method checkcastArraycopyWithSlowPathWork.

@Snippet(allowPartialIntrinsicArgumentMismatch = true)
public static void checkcastArraycopyWithSlowPathWork(Object src, int srcPos, Object dest, int destPos, int length, @ConstantParameter Counters counters) {
    if (probability(FREQUENT_PROBABILITY, length > 0)) {
        Object nonNullSrc = PiNode.asNonNullObject(src);
        Object nonNullDest = PiNode.asNonNullObject(dest);
        KlassPointer srcKlass = loadHub(nonNullSrc);
        KlassPointer destKlass = loadHub(nonNullDest);
        if (probability(LIKELY_PROBABILITY, srcKlass == destKlass)) {
            // no storecheck required.
            counters.objectCheckcastSameTypeCounter.inc();
            counters.objectCheckcastSameTypeCopiedCounter.add(length);
            ArrayCopyCallNode.arraycopyObjectKillsAny(nonNullSrc, srcPos, nonNullDest, destPos, length);
        } else {
            KlassPointer destElemKlass = destKlass.readKlassPointer(arrayClassElementOffset(INJECTED_VMCONFIG), OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION);
            Word superCheckOffset = WordFactory.signed(destElemKlass.readInt(superCheckOffsetOffset(INJECTED_VMCONFIG), KLASS_SUPER_CHECK_OFFSET_LOCATION));
            counters.objectCheckcastDifferentTypeCounter.inc();
            counters.objectCheckcastDifferentTypeCopiedCounter.add(length);
            int copiedElements = CheckcastArrayCopyCallNode.checkcastArraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, superCheckOffset, destElemKlass, false);
            if (probability(SLOW_PATH_PROBABILITY, copiedElements != 0)) {
                /*
                     * the stub doesn't throw the ArrayStoreException, but returns the number of
                     * copied elements (xor'd with -1).
                     */
                copiedElements ^= -1;
                System.arraycopy(nonNullSrc, srcPos + copiedElements, nonNullDest, destPos + copiedElements, length - copiedElements);
            }
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 7 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class InstanceOfSnippets method instanceofSecondary.

/**
 * A test against a restricted secondary type type.
 */
@Snippet
public static Object instanceofSecondary(KlassPointer hub, Object object, @VarargsParameter KlassPointer[] hints, @VarargsParameter boolean[] hintIsPositive, 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 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(NOT_FREQUENT_PROBABILITY, hintHub.equal(objectHub))) {
            counters.hintsHit.inc();
            return positive ? trueValue : falseValue;
        }
    }
    counters.hintsMiss.inc();
    if (!checkSecondarySubType(hub, objectHub, counters)) {
        return falseValue;
    }
    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 8 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class InstanceOfSnippets method isAssignableFrom.

@Snippet
public static Object isAssignableFrom(@NonNullParameter Class<?> thisClassNonNull, Class<?> otherClass, Object trueValue, Object falseValue, @ConstantParameter Counters counters) {
    if (otherClass == null) {
        DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException);
        return false;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    Class<?> otherClassNonNull = PiNode.piCastNonNullClass(otherClass, anchorNode);
    if (BranchProbabilityNode.probability(BranchProbabilityNode.NOT_LIKELY_PROBABILITY, thisClassNonNull == otherClassNonNull)) {
        return trueValue;
    }
    KlassPointer thisHub = ClassGetHubNode.readClass(thisClassNonNull);
    KlassPointer otherHub = ClassGetHubNode.readClass(otherClassNonNull);
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, !thisHub.isNull())) {
        if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, !otherHub.isNull())) {
            GuardingNode guardNonNull = SnippetAnchorNode.anchor();
            KlassPointer nonNullOtherHub = ClassGetHubNode.piCastNonNull(otherHub, guardNonNull);
            if (TypeCheckSnippetUtils.checkUnknownSubType(thisHub, nonNullOtherHub, counters)) {
                return trueValue;
            }
        }
    }
    // equal, return false.
    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 9 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class LoadExceptionObjectSnippets method loadException.

@Snippet
public static Object loadException(@ConstantParameter Register threadRegister) {
    Word thread = registerAsWord(threadRegister);
    Object exception = readExceptionOop(thread);
    writeExceptionOop(thread, null);
    writeExceptionPc(thread, WordFactory.zero());
    return piCastToSnippetReplaceeStamp(exception);
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 10 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class PosixAMD64VaListSnippets method vaArgLongSnippet.

@Snippet
protected static long vaArgLongSnippet(Pointer vaList) {
    int gpOffset = vaList.readInt(GP_OFFSET_LOCATION);
    if (gpOffset < MAX_GP_OFFSET) {
        Pointer regSaveArea = vaList.readWord(REG_SAVE_AREA_LOCATION);
        long v = regSaveArea.readLong(gpOffset);
        vaList.writeInt(GP_OFFSET_LOCATION, gpOffset + 8);
        return v;
    } else {
        Pointer overflowArgArea = vaList.readWord(OVERFLOW_ARG_AREA_LOCATION);
        long v = overflowArgArea.readLong(0);
        vaList.writeWord(OVERFLOW_ARG_AREA_LOCATION, overflowArgArea.add(OVERFLOW_ARG_AREA_ALIGNMENT));
        return v;
    }
}
Also used : Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Aggregations

Snippet (org.graalvm.compiler.api.replacements.Snippet)47 Word (org.graalvm.compiler.word.Word)22 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)17 Pointer (org.graalvm.word.Pointer)14 UnsignedWord (org.graalvm.word.UnsignedWord)12 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)9 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)6 DynamicHub (com.oracle.svm.core.hub.DynamicHub)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 Safepoint (com.oracle.svm.core.thread.Safepoint)2 ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)2 WordBase (org.graalvm.word.WordBase)2 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)1 JavaFrameAnchor (com.oracle.svm.core.stack.JavaFrameAnchor)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)1