Search in sources :

Example 86 with Pointer

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

the class AllocationSnippets method fastNewArrayUninterruptibly.

@Uninterruptible(reason = "Holds uninitialized memory from allocateMemory through formatArryImpl")
private static Object fastNewArrayUninterruptibly(DynamicHub hub, int length, int layoutEncoding, boolean fillContents, UnsignedWord size) {
    Pointer memory = WordFactory.nullPointer();
    if (size.belowOrEqual(HeapPolicy.getLargeArrayThreshold()) && length >= 0) {
        memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
    }
    Object result = null;
    if (memory.isNonNull()) {
        result = formatArrayImpl(memory, hub, length, layoutEncoding, size, fillContents, false, false);
    }
    return result;
}
Also used : Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 87 with Pointer

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

the class HeapVerifierImpl method slowlyFindPointerInSpace.

static boolean slowlyFindPointerInSpace(Space space, Pointer p, HeapVerifierImpl.ChunkLimit chunkLimit) {
    /* Look through all the chunks in the space. */
    /* - The aligned chunks. */
    AlignedHeapChunk.AlignedHeader aChunk = space.getFirstAlignedHeapChunk();
    while (aChunk.isNonNull()) {
        final Pointer start = AlignedHeapChunk.getAlignedHeapChunkStart(aChunk);
        final Pointer limit = (chunkLimit == ChunkLimit.top ? aChunk.getTop() : aChunk.getEnd());
        final boolean atLeast = start.belowOrEqual(p);
        final boolean atMost = p.belowThan(limit);
        if (atLeast && atMost) {
            return true;
        }
        aChunk = aChunk.getNext();
    }
    /* - The unaligned chunks. */
    UnalignedHeapChunk.UnalignedHeader uChunk = space.getFirstUnalignedHeapChunk();
    while (uChunk.isNonNull()) {
        final Pointer start = UnalignedHeapChunk.getUnalignedHeapChunkStart(uChunk);
        final Pointer limit = (chunkLimit == ChunkLimit.top ? uChunk.getTop() : uChunk.getEnd());
        final boolean atLeast = start.belowOrEqual(p);
        final boolean atMost = p.belowThan(limit);
        if (atLeast && atMost) {
            return true;
        }
        uChunk = uChunk.getNext();
    }
    return false;
}
Also used : Pointer(org.graalvm.word.Pointer)

Example 88 with Pointer

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

the class HeapVerifierImpl method verifyBootImageObjects.

private boolean verifyBootImageObjects(Object firstObject, Object lastObject) {
    final Log trace = getTraceLog();
    trace.string("[HeapVerifierImpl.verifyBootImageObjects:").newline();
    final Pointer firstPointer = Word.objectToUntrackedPointer(firstObject);
    final Pointer lastPointer = Word.objectToUntrackedPointer(lastObject);
    trace.string("  [ firstPointer: ").hex(firstPointer).string("  .. lastPointer: ").hex(lastPointer).string(" ]").newline();
    if ((firstObject == null) || (lastObject == null)) {
        trace.string("  returns: true because boundary object is null").string("]").newline();
        return true;
    }
    boolean result = true;
    Pointer currentPointer = firstPointer;
    while (currentPointer.belowOrEqual(lastPointer)) {
        final Object currentObject = currentPointer.toObject();
        /* Make sure obj is marked as a SystemType object. */
        if (!ObjectHeaderImpl.getObjectHeaderImpl().isNonHeapAllocatedCarefully(currentObject)) {
            result = false;
            try (Log witness = getWitnessLog()) {
                witness.string("[HeapVerifierImpl.verifyBootImageObjects:").string("  [ firstPointer: ").hex(firstPointer).string("  .. lastPointer: ").hex(lastPointer).string(" ]");
                witness.string("  current: ").hex(currentPointer).string("  object is not NonHeapAllocated").string("]").newline();
            }
        }
        /* Make sure obj is an object. */
        if (!verifyObjectAt(currentPointer)) {
            result = false;
            try (Log witness = getWitnessLog()) {
                witness.string("[HeapVerifierImpl.verifyBootImageObjects:").string("  [ firstPointer: ").hex(firstPointer).string("  .. lastPointer: ").hex(lastPointer).string(" ]");
                witness.string("  current: ").hex(currentPointer).string("  object does not verify").string("]").newline();
            }
        }
        currentPointer = LayoutEncoding.getObjectEnd(currentObject);
    }
    trace.string("  returns: ").bool(result).string("]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) Pointer(org.graalvm.word.Pointer)

Example 89 with Pointer

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

the class HeapVerifierImpl method verifyObjectAt.

/* TODO: This is probably not the right place for this method. */
/* TODO: This method could return true if I wanted to find more than just the first failure. */
/* TODO: add a name field to the heap and use that in logs */
/**
 * Whatever it takes to verify an Object.
 */
@Override
public boolean verifyObjectAt(Pointer ptr) {
    VMOperation.guaranteeInProgress("Can only verify from a VMOperation.");
    final Log trace = getTraceLog();
    trace.string("[HeapVerifierImpl.verifyObjectAt:").string("  ptr: ").hex(ptr);
    /* I should not be asked to verify null references. */
    if (ptr.isNull()) {
        getWitnessLog().string("[verifyObjectAt(objRef: ").hex(ptr).string(")").string("  null ptr").string("]").newline();
        /* Nothing else to do. */
        return false;
    }
    /* I should be able to find the pointed-to object in the heap. */
    if (!slowlyFindPointer(ptr)) {
        getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt:").string("  ptr: ").hex(ptr).string("  is not in heap.").string("]").newline();
        /* No point in examining the object further. */
        return false;
    }
    final UnsignedWord header = ObjectHeaderImpl.readHeaderFromPointerCarefully(ptr);
    trace.string("  header: ").hex(header);
    final ObjectHeaderImpl ohi = ObjectHeaderImpl.getObjectHeaderImpl();
    if (ohi.isForwardedHeader(header)) {
        final Object obj = ohi.getForwardedObject(header);
        final Pointer op = Word.objectToUntrackedPointer(obj);
        trace.string("  forwards to ").hex(op).newline();
        if (!verifyObjectAt(op)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  forwarded object fails to verify").string("]").newline();
            return false;
        }
    } else {
        final Object obj = ptr.toObject();
        trace.string("  obj: ").hex(Word.objectToUntrackedPointer(obj)).string("  obj.getClass: ").string(obj.getClass().getName()).string("  objectHeader: ").string(ohi.toStringFromObject(obj));
        final DynamicHub hub = ObjectHeaderImpl.readDynamicHubFromObjectCarefully(obj);
        if (!(hub.getClass().getName().equals("java.lang.Class"))) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  hub is not a class").string("]").newline();
            return false;
        }
        if (slowlyFindObjectInBootImage(obj)) {
            if (!ohi.isBootImageCarefully(obj)) {
                try (Log witness = getWitnessLog()) {
                    witness.string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  obj: ").object(obj);
                    witness.string("  header: ").string(ohi.toStringFromHeader(header)).string("  native image object but not native image object header").string("]").newline();
                }
                return false;
            }
        } else {
            if (ohi.isNonHeapAllocatedCarefully(obj)) {
                try (Log witness = getWitnessLog()) {
                    witness.string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  obj: ").object(obj);
                    witness.string("  header: ").string(ohi.toStringFromHeader(header)).string("  Not native image, but not heap allocated.").string("]").newline();
                }
                return false;
            }
        }
        trace.newline();
        /*
             * Walk the interior pointers of this object looking for breakage. First make sure the
             * references are valid, ...
             */
        if (!noReferencesOutsideHeap(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  contains references outside the heap").string("]").newline();
            return false;
        }
        /* ... then ask specific questions about them. */
        if (!noReferencesToForwardedObjectsVerifier(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  contains references to forwarded objects").string("]").newline();
            return false;
        }
        if (!verifyDiscoverableReference(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  DiscoverableReference fails to verify.").string("]").newline();
            return false;
        }
    }
    trace.string("  returns true]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Pointer(org.graalvm.word.Pointer)

Example 90 with Pointer

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

the class ObjectHeaderImpl method getForwardingPointer.

/**
 * Extract a forwarding Pointer from a header.
 */
@Override
public Pointer getForwardingPointer(UnsignedWord header) {
    final UnsignedWord pointerBits = clearBits(header);
    final Pointer result = (Pointer) pointerBits;
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

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