Search in sources :

Example 1 with KlassPointer

use of org.graalvm.compiler.hotspot.word.KlassPointer in project graal by oracle.

the class NewObjectSnippets method allocateArrayDynamicImpl.

private static Object allocateArrayDynamicImpl(Class<?> elementType, Class<?> voidClass, int length, boolean fillContents, Register threadRegister, JavaKind knownElementKind, int knownLayoutHelper, Word prototypeMarkWord, OptionValues options, Counters counters) {
    /*
         * We only need the dynamic check for void when we have no static information from
         * knownElementKind.
         */
    staticAssert(knownElementKind != JavaKind.Void, "unsupported knownElementKind");
    if (knownElementKind == JavaKind.Illegal && probability(SLOW_PATH_PROBABILITY, elementType == null || DynamicNewArrayNode.throwsIllegalArgumentException(elementType, voidClass))) {
        DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
    }
    KlassPointer klass = loadKlassFromObject(elementType, arrayKlassOffset(INJECTED_VMCONFIG), CLASS_ARRAY_KLASS_LOCATION);
    if (klass.isNull()) {
        DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
    }
    KlassPointer nonNullKlass = ClassGetHubNode.piCastNonNull(klass, SnippetAnchorNode.anchor());
    if (length < 0) {
        DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
    }
    int layoutHelper;
    if (knownElementKind == JavaKind.Illegal) {
        layoutHelper = readLayoutHelper(nonNullKlass);
    } else {
        runtimeAssert(knownLayoutHelper == readLayoutHelper(nonNullKlass), "layout mismatch");
        layoutHelper = knownLayoutHelper;
    }
    // @formatter:off
    // from src/share/vm/oops/klass.hpp:
    // 
    // For arrays, layout helper is a negative number, containing four
    // distinct bytes, as follows:
    // MSB:[tag, hsz, ebt, log2(esz)]:LSB
    // where:
    // tag is 0x80 if the elements are oops, 0xC0 if non-oops
    // hsz is array header size in bytes (i.e., offset of first element)
    // ebt is the BasicType of the elements
    // esz is the element size in bytes
    // @formatter:on
    int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
    int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
    Object result = allocateArrayImpl(nonNullKlass, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents, threadRegister, false, "dynamic type", true, options, counters);
    return piArrayCastToSnippetReplaceeStamp(verifyOop(result), length);
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) HotSpotReplacementsUtil.loadKlassFromObject(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)

Example 2 with KlassPointer

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

use of org.graalvm.compiler.hotspot.word.KlassPointer in project graal by oracle.

the class ArrayCopySnippets method checkArrayTypes.

private static void checkArrayTypes(Object nonNullSrc, Object nonNullDest, ArrayCopyTypeCheck arrayTypeCheck) {
    if (arrayTypeCheck == ArrayCopyTypeCheck.NO_ARRAY_TYPE_CHECK) {
    // nothing to do
    } else if (arrayTypeCheck == ArrayCopyTypeCheck.HUB_BASED_ARRAY_TYPE_CHECK) {
        KlassPointer srcHub = loadHub(nonNullSrc);
        KlassPointer destHub = loadHub(nonNullDest);
        if (probability(SLOW_PATH_PROBABILITY, srcHub != destHub)) {
            DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
        }
    } else if (arrayTypeCheck == ArrayCopyTypeCheck.LAYOUT_HELPER_BASED_ARRAY_TYPE_CHECK) {
        KlassPointer srcHub = loadHub(nonNullSrc);
        KlassPointer destHub = loadHub(nonNullDest);
        if (probability(SLOW_PATH_PROBABILITY, readLayoutHelper(srcHub) != readLayoutHelper(destHub))) {
            DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
        }
    } else {
        ReplacementsUtil.staticAssert(false, "unknown array type check");
    }
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer)

Example 4 with KlassPointer

use of org.graalvm.compiler.hotspot.word.KlassPointer in project graal by oracle.

the class HotSpotClassSubstitutions method getSuperclass.

@MethodSubstitution(isStatic = false)
public static Class<?> getSuperclass(final Class<?> thisObj) {
    KlassPointer klass = ClassGetHubNode.readClass(thisObj);
    if (!klass.isNull()) {
        KlassPointer klassNonNull = ClassGetHubNode.piCastNonNull(klass, SnippetAnchorNode.anchor());
        int accessFlags = klassNonNull.readInt(klassAccessFlagsOffset(INJECTED_VMCONFIG), KLASS_ACCESS_FLAGS_LOCATION);
        if ((accessFlags & Modifier.INTERFACE) == 0) {
            if (klassIsArray(klassNonNull)) {
                return Object.class;
            } else {
                KlassPointer superKlass = klassNonNull.readKlassPointer(klassSuperKlassOffset(INJECTED_VMCONFIG), KLASS_SUPER_KLASS_LOCATION);
                if (superKlass.isNull()) {
                    return null;
                } else {
                    KlassPointer superKlassNonNull = ClassGetHubNode.piCastNonNull(superKlass, SnippetAnchorNode.anchor());
                    return HubGetClassNode.readClass(superKlassNonNull);
                }
            }
        }
    } else {
    // Class for primitive type
    }
    return null;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 5 with KlassPointer

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

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