Search in sources :

Example 11 with Snippet

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

the class CFunctionSnippets method prologueSnippet.

@Snippet
private static void prologueSnippet() {
    // Push a Java frame anchor.
    JavaFrameAnchor anchor = (JavaFrameAnchor) StackValueNode.stackValue(1, SizeOf.get(JavaFrameAnchor.class), frameAnchorIdentity);
    anchor.setLastJavaSP(KnownIntrinsics.readStackPointer());
    JavaFrameAnchors.pushFrameAnchor(anchor);
    if (SubstrateOptions.MultiThreaded.getValue()) {
        // Change the VMThread status from Java to native.
        VMThreads.StatusSupport.setStatusNative();
    }
}
Also used : JavaFrameAnchor(com.oracle.svm.core.stack.JavaFrameAnchor) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 12 with Snippet

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

the class NewArrayStub method newArray.

/**
 * Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to
 * -XX:-UseTLAB).
 *
 * @param hub the hub of the object to be allocated
 * @param length the length of the array
 * @param fillContents Should the array be filled with zeroes?
 * @param intArrayHub the hub for {@code int[].class}
 */
@Snippet
private static Object newArray(KlassPointer hub, int length, boolean fillContents, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister, @ConstantParameter OptionValues options) {
    int layoutHelper = readLayoutHelper(hub);
    int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
    int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
    int elementKind = (layoutHelper >> layoutHelperElementTypeShift(INJECTED_VMCONFIG)) & layoutHelperElementTypeMask(INJECTED_VMCONFIG);
    int sizeInBytes = arrayAllocationSize(length, headerSize, log2ElementSize);
    if (logging(options)) {
        printf("newArray: element kind %d\n", elementKind);
        printf("newArray: array length %d\n", length);
        printf("newArray: array size %d\n", sizeInBytes);
        printf("newArray: hub=%p\n", hub.asWord().rawValue());
    }
    // check that array length is small enough for fast path.
    Word thread = registerAsWord(threadRegister);
    boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported();
    if (inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG) && length >= 0 && length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) {
        Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
        if (memory.notEqual(0)) {
            if (logging(options)) {
                printf("newArray: allocated new array at %p\n", memory.rawValue());
            }
            return verifyObject(formatArray(hub, sizeInBytes, length, headerSize, memory, WordFactory.unsigned(arrayPrototypeMarkWord(INJECTED_VMCONFIG)), fillContents, false, null));
        }
    }
    if (logging(options)) {
        printf("newArray: calling new_array_c\n");
    }
    newArrayC(NEW_ARRAY_C, thread, hub, length);
    handlePendingException(thread, true);
    return verifyObject(getAndClearObjectResult(thread));
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.arrayPrototypeMarkWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 13 with Snippet

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

the class AllocationSnippets method newPinnedArraySnippet.

@Snippet
public static Object newPinnedArraySnippet(PinnedAllocatorImpl pinnedAllocator, DynamicHub hub, int length, @ConstantParameter int layoutEncoding, @ConstantParameter boolean fillContents, AllocationCounter counter) {
    pinnedAllocator.ensureOpen();
    UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
    profileAllocation(size, counter);
    Pointer memory = WordFactory.nullPointer();
    if (size.belowOrEqual(HeapPolicy.getLargeArrayThreshold()) && length >= 0) {
        memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.pinnedTLAB.getAddress(), size);
    }
    Object result = null;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        result = formatArrayImpl(memory, hub, length, layoutEncoding, size, fillContents, false, false);
    } else {
        result = callSlowNewPinnedArray(SLOW_NEW_PINNED_ARRAY, pinnedAllocator, hub.asClass(), length);
    }
    return PiArrayNode.piArrayCastToSnippetReplaceeStamp(result, length);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 14 with Snippet

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

the class AllocationSnippets method arraysCopyOfSnippet.

@Snippet
public static Object arraysCopyOfSnippet(DynamicHub hub, Object original, int originalLength, int newLength, AllocationCounter counter) {
    int layoutEncoding = hub.getLayoutEncoding();
    // allocate new array without initializing the new array
    Object copy = newArraySnippet(hub, newLength, layoutEncoding, false, counter);
    // copy elements from original
    // The length of the copied section
    int length = originalLength < newLength ? originalLength : newLength;
    // The size of the copied section(obtained from the length of the copied section)
    UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
    // The size of the new array (obtained from the length of the new array)
    UnsignedWord newSize = LayoutEncoding.getArraySize(layoutEncoding, newLength);
    // We know that the offset is always word aligned
    UnsignedWord offset = LayoutEncoding.getArrayBaseOffset(layoutEncoding);
    while (offset.belowThan(size)) {
        Object val = ObjectAccess.readObject(original, offset);
        ObjectAccess.writeObject(copy, offset, val, LocationIdentity.INIT_LOCATION);
        offset = offset.add(ConfigurationValues.getTarget().wordSize);
    }
    while (offset.belowThan(newSize)) {
        ObjectAccess.writeObject(copy, offset, null, LocationIdentity.INIT_LOCATION);
        offset = offset.add(ConfigurationValues.getTarget().wordSize);
    }
    return FixedValueAnchorNode.getObject(copy);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 15 with Snippet

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

the class AllocationSnippets method formatArraySnippet.

@Snippet
public static Object formatArraySnippet(Word memory, DynamicHub hub, int length, boolean rememberedSet, boolean unaligned) {
    DynamicHub hubNonNull = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
    int layoutEncoding = hubNonNull.getLayoutEncoding();
    UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
    emitPrefetchAllocate(memory, true);
    return formatArrayImpl(memory, hubNonNull, length, layoutEncoding, size, true, rememberedSet, unaligned);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) 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