Search in sources :

Example 41 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet 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 42 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet 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)

Example 43 with Snippet

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

the class AllocationSnippets method newPinnedInstanceSnippet.

@Snippet
public static Object newPinnedInstanceSnippet(PinnedAllocatorImpl pinnedAllocator, DynamicHub hub, @ConstantParameter int encoding, @ConstantParameter boolean fillContents, AllocationCounter counter) {
    pinnedAllocator.ensureOpen();
    UnsignedWord size = LayoutEncoding.getInstanceSize(encoding);
    profileAllocation(size, counter);
    Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.pinnedTLAB.getAddress(), size);
    Object result;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        result = formatObjectImpl(memory, hub, size, true, fillContents, false);
    } else {
        result = callSlowNewPinnedInstance(SLOW_NEW_PINNED_INSTANCE, pinnedAllocator, hub.asClass());
    }
    return PiNode.piCastToSnippetReplaceeStamp(result);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 44 with Snippet

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

the class AllocationSnippets method newMultiArraySnippet.

@Snippet
public static Object newMultiArraySnippet(DynamicHub hub, @ConstantParameter int rank, @VarargsParameter int[] dimensions, AllocationCounter counter) {
    Pointer dims = DimensionsNode.allocaDimsArray(rank);
    ExplodeLoopNode.explodeLoop();
    for (int i = 0; i < rank; i++) {
        dims.writeInt(i * sizeOfDimensionElement, dimensions[i], LocationIdentity.INIT_LOCATION);
    }
    return callNewMultiArray(NEW_MULTI_ARRAY, hub.asClass(), rank, dims, counter);
}
Also used : Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 45 with Snippet

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

the class AllocationSnippets method doCloneSnippet.

/**
 * The actual implementation of {@link Object#clone}.
 */
@Snippet
private static Object doCloneSnippet(Object thisObj, AllocationCounter counter) throws CloneNotSupportedException {
    if (!(thisObj instanceof Cloneable)) {
        throw CLONE_NOT_SUPPORTED_EXCEPTION;
    }
    DynamicHub hub = KnownIntrinsics.readHub(thisObj);
    int layoutEncoding = hub.getLayoutEncoding();
    UnsignedWord size = LayoutEncoding.getSizeFromObject(thisObj);
    profileAllocation(size, counter);
    /*
         * The size of the clone is the same as the size of the original object. On the fast path we
         * try to allocate aligned memory, i.e., a block inside an aligned chunks, for the clone and
         * don't need to distinguish instance objects from arrays. If we fail, i.e., the returned
         * memory is null, then either the instance object or small array didn't fit in the
         * available space or it is a large array. In either case we go on the slow path.
         */
    Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
    Object thatObject = null;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, false, false);
        memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
        /*
             * For arrays the length initialization is handled by doCloneUninterruptibly since the
             * array length offset is the same as the first field offset.
             */
        thatObject = memory.toObjectNonNull();
    } else {
        if (LayoutEncoding.isArray(layoutEncoding)) {
            int length = KnownIntrinsics.readArrayLength(thisObj);
            thatObject = callSlowNewArray(SLOW_NEW_ARRAY, hub.asClass(), length);
        } else {
            thatObject = callSlowNewInstance(SLOW_NEW_INSTANCE, hub.asClass());
        }
    }
    if (LayoutEncoding.isArray(layoutEncoding)) {
        int length = KnownIntrinsics.readArrayLength(thisObj);
        thatObject = PiArrayNode.piArrayCastToSnippetReplaceeStamp(thatObject, length);
    } else {
        thatObject = PiNode.piCastToSnippetReplaceeStamp(thatObject);
    }
    UnsignedWord firstFieldOffset = WordFactory.signed(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
    return doCloneUninterruptibly(thisObj, thatObject, firstFieldOffset, size);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) WordBase(org.graalvm.word.WordBase) 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