Search in sources :

Example 11 with Pointer

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

the class ReferenceMapDecoder method walkOffsetsFromPointer.

/**
 * Walk the reference map encoding from a Pointer, applying a visitor to each Object reference.
 *
 * @param baseAddress A Pointer to a collections of primitives and Object references.
 * @param referenceMapEncoding The encoding for the Object references in the collection.
 * @param referenceMapIndex The start index for the particular reference map in the encoding.
 * @param visitor The ObjectRefernceVisitor to be applied to each Object reference.
 * @return false if any of the visits returned false, true otherwise.
 */
@AlwaysInline("de-virtualize calls to ObjectReferenceVisitor")
public static boolean walkOffsetsFromPointer(PointerBase baseAddress, byte[] referenceMapEncoding, long referenceMapIndex, ObjectReferenceVisitor visitor) {
    assert referenceMapIndex != CodeInfoQueryResult.NO_REFERENCE_MAP;
    assert referenceMapEncoding != null;
    UnsignedWord uncompressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getReferenceSize());
    UnsignedWord compressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getCompressedReferenceSize());
    UnsignedWord slotSize = WordFactory.unsigned(SubstrateReferenceMap.getSlotSizeInBytes());
    Pointer objRef = (Pointer) baseAddress;
    long idx = referenceMapIndex;
    while (true) {
        int gap = ByteArrayReader.getU1(referenceMapEncoding, idx);
        if (gap == GAP_END_OF_TABLE) {
            break;
        }
        int count = ByteArrayReader.getS1(referenceMapEncoding, idx + 1);
        // Skip a gap.
        objRef = objRef.add(slotSize.multiply(gap));
        // Visit the offsets.
        boolean compressed = (count < 0);
        UnsignedWord refSize = compressed ? compressedSize : uncompressedSize;
        count = (count < 0) ? -count : count;
        for (int c = 0; c < count; c += 1) {
            final boolean visitResult = visitor.visitObjectReferenceInline(objRef, compressed);
            if (!visitResult) {
                return false;
            }
            objRef = objRef.add(refSize);
        }
        idx += 2;
    }
    return true;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 12 with Pointer

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

the class StubUtil method verifyObject.

/**
 * Verifies that a given object value is well formed if {@code -XX:+VerifyOops} is enabled.
 */
public static Object verifyObject(Object object) {
    if (verifyOops(INJECTED_VMCONFIG)) {
        Word verifyOopCounter = WordFactory.unsigned(verifyOopCounterAddress(INJECTED_VMCONFIG));
        verifyOopCounter.writeInt(0, verifyOopCounter.readInt(0) + 1);
        Pointer oop = Word.objectToTrackedPointer(object);
        if (object != null) {
            GuardingNode anchorNode = SnippetAnchorNode.anchor();
            // make sure object is 'reasonable'
            if (!oop.and(WordFactory.unsigned(verifyOopMask(INJECTED_VMCONFIG))).equal(WordFactory.unsigned(verifyOopBits(INJECTED_VMCONFIG)))) {
                fatal("oop not in heap: %p", oop.rawValue());
            }
            KlassPointer klass = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
            if (klass.isNull()) {
                fatal("klass for oop %p is null", oop.rawValue());
            }
        }
    }
    return object;
}
Also used : Word(org.graalvm.compiler.word.Word) Pointer(org.graalvm.word.Pointer) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 13 with Pointer

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

the class Space method allocateMemory.

/**
 * Allocate memory from an AlignedHeapChunk in this Space.
 *
 * This is "slow-path" memory allocation.
 */
private Pointer allocateMemory(UnsignedWord objectSize) {
    final Log trace = Log.noopLog().string("[SpaceImpl.allocateMemory:").string("  space: ").string(getName()).string("  size: ").unsigned(objectSize).newline();
    Pointer result = WordFactory.nullPointer();
    /* First try allocating in the last chunk. */
    final AlignedHeapChunk.AlignedHeader oldChunk = getLastAlignedHeapChunk();
    trace.string("  oldChunk: ").hex(oldChunk);
    if (oldChunk.isNonNull()) {
        result = AlignedHeapChunk.allocateMemory(oldChunk, objectSize);
        trace.string("  oldChunk provides: ").hex(result);
    }
    /* If oldChunk did not provide, try allocating a new chunk for the requested memory. */
    if (result.isNull()) {
        final AlignedHeapChunk.AlignedHeader newChunk = requestAlignedHeapChunk();
        trace.string("  newChunk: ").hex(newChunk);
        if (newChunk.isNonNull()) {
            /* Allocate the Object within the new chunk. */
            result = AlignedHeapChunk.allocateMemory(newChunk, objectSize);
            trace.string("  newChunk provides: ").hex(result);
        }
    }
    trace.string("  returns: ").hex(result).string("]").newline();
    return result;
}
Also used : Log(com.oracle.svm.core.log.Log) Pointer(org.graalvm.word.Pointer)

Example 14 with Pointer

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

the class ThreadLocalAllocation method allocateLargeArray.

@Uninterruptible(reason = "Holds uninitialized memory, modifies TLAB")
private static Object allocateLargeArray(DynamicHub hub, int length, UnsignedWord size, UnalignedHeapChunk.UnalignedHeader uChunk, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet) {
    /* Register the new chunk in the TLAB linked list of unaligned chunks. */
    uChunk.setNext(tlab.getUnalignedChunk());
    tlab.setUnalignedChunk(uChunk);
    /* Allocate the memory. We must have a chunk, otherwise we already threw an exception. */
    Pointer memory = UnalignedHeapChunk.allocateMemory(uChunk, size);
    assert memory.isNonNull();
    /* Install the DynamicHub and length, and zero the elements. */
    return KnownIntrinsics.formatArray(memory, hub.asClass(), length, rememberedSet, true);
}
Also used : Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 15 with Pointer

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

the class ThreadLocalAllocation method allocateSmallArray.

@Uninterruptible(reason = "Holds uninitialized memory, modifies TLAB")
private static Object allocateSmallArray(DynamicHub hub, int length, UnsignedWord size, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet, AlignedHeader newChunk) {
    registerNewAllocationChunk(tlab, newChunk);
    /*
         * Allocate the memory. We must have a chunk, because we just registered one and we are
         * still in the same block of uninterruptible code.
         */
    Pointer memory = allocateMemory(tlab, size);
    assert memory.isNonNull();
    /* Install the DynamicHub and length, and zero the elements. */
    return KnownIntrinsics.formatArray(memory, hub.asClass(), length, rememberedSet, false);
}
Also used : Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Aggregations

Pointer (org.graalvm.word.Pointer)103 UnsignedWord (org.graalvm.word.UnsignedWord)45 Log (com.oracle.svm.core.log.Log)30 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)17 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)15 Snippet (org.graalvm.compiler.api.replacements.Snippet)14 Word (org.graalvm.compiler.word.Word)12 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)9 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)7 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)5 NeverInline (com.oracle.svm.core.annotate.NeverInline)5 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3 SignedWord (org.graalvm.word.SignedWord)3 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2