Search in sources :

Example 16 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class UnalignedHeapChunkMemoryWalkerAccessFeature method getEnclosingUnalignedHeapChunkFromPointer.

/**
 * Map from a Pointer to an object to the enclosing chunk.
 */
private static UnalignedHeader getEnclosingUnalignedHeapChunkFromPointer(Pointer objPointer) {
    // This only works because there is only one object in an unaligned chunk.
    // Where does the object start in an unaligned chunk?
    final UnsignedWord startOffset = getObjectStartOffset();
    // Back the Object pointer up to the beginning of the UnalignedHeapChunk.
    final Pointer chunkPointer = objPointer.subtract(startOffset);
    final UnalignedHeader result = (UnalignedHeader) chunkPointer;
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 17 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class UnalignedHeapChunkMemoryWalkerAccessFeature method getObjectStartOffset.

/**
 * Where does the Object start?
 */
@Fold
static UnsignedWord getObjectStartOffset() {
    final UnsignedWord cardTableLimitOffset = getCardTableLimitOffset();
    final UnsignedWord alignment = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getAlignment());
    final UnsignedWord result = UnsignedUtils.roundUp(cardTableLimitOffset, alignment);
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Fold(org.graalvm.compiler.api.replacements.Fold)

Example 18 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class AllocationSnippets method formatObjectImpl.

private static Object formatObjectImpl(Pointer memory, DynamicHub hub, UnsignedWord size, @ConstantParameter boolean constantSize, @ConstantParameter boolean fillContents, boolean rememberedSet) {
    if (fillContents) {
        emitPrefetchAllocate(memory, false);
    }
    WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, rememberedSet, false);
    memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
    if (fillContents) {
        UnsignedWord offset = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
        if (constantSize && ((size.subtract(offset).unsignedDivide(ConfigurationValues.getTarget().wordSize)).belowOrEqual(SubstrateOptions.MaxUnrolledObjectZeroingStores.getValue()))) {
            ExplodeLoopNode.explodeLoop();
        }
        while (offset.belowThan(size)) {
            memory.writeWord(offset, WordFactory.zero(), LocationIdentity.INIT_LOCATION);
            offset = offset.add(ConfigurationValues.getTarget().wordSize);
        }
    }
    return memory.toObjectNonNull();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase)

Example 19 with UnsignedWord

use of org.graalvm.word.UnsignedWord 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 20 with UnsignedWord

use of org.graalvm.word.UnsignedWord 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)

Aggregations

UnsignedWord (org.graalvm.word.UnsignedWord)137 Pointer (org.graalvm.word.Pointer)43 Log (com.oracle.svm.core.log.Log)30 DynamicHub (com.oracle.svm.core.hub.DynamicHub)11 Fold (org.graalvm.compiler.api.replacements.Fold)11 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)9 Snippet (org.graalvm.compiler.api.replacements.Snippet)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)6 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)4 WordBase (org.graalvm.word.WordBase)4 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)3 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 UnalignedHeader (com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)3 XOptions (com.oracle.svm.core.option.XOptions)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)2 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaKind (jdk.vm.ci.meta.JavaKind)2