Search in sources :

Example 21 with Pointer

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

the class UnalignedHeapChunkMemoryWalkerAccessFeature method verifyRememberedSet.

/**
 * Verify the remembered set of the given chunk.
 */
private static boolean verifyRememberedSet(UnalignedHeader that) {
    // Only chunks in the old from space have a remembered set.
    final HeapImpl heap = HeapImpl.getHeapImpl();
    final OldGeneration oldGen = heap.getOldGeneration();
    if (that.getSpace() == oldGen.getFromSpace()) {
        // Check if there are cross-generational pointers ...
        final Pointer objStart = getUnalignedStart(that);
        final Object obj = objStart.toObject();
        final boolean containsYoungReferences = CardTable.containsReferenceToYoungSpace(obj);
        // ... and if so, that the chunk is marked as dirty.
        if (containsYoungReferences) {
            final Pointer rememberedSet = getCardTableStart(that);
            final UnsignedWord objectIndex = getObjectIndex();
            final boolean isDirty = CardTable.isDirtyEntryAtIndex(rememberedSet, objectIndex);
            if (!isDirty) {
                final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
                witness.string("  that: ").hex(that);
                witness.string("  containsYoungReferences implies isDirty").string("]").newline();
                return false;
            }
        }
    }
    return true;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Log(com.oracle.svm.core.log.Log) Pointer(org.graalvm.word.Pointer)

Example 22 with Pointer

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

the class UnalignedHeapChunkMemoryWalkerAccessFeature method verifyUnalignedHeapChunk.

/**
 * Verify an UnalignedHeapChunk, called from sub-class verify methods.
 */
private static boolean verifyUnalignedHeapChunk(UnalignedHeader that, Pointer start) {
    VMOperation.guaranteeInProgress("Should only be called as a VMOperation.");
    // The object in this chunk should not be forwarded,
    // and should be the only object in the chunk.
    final Log trace = HeapImpl.getHeapImpl().getHeapVerifierImpl().getTraceLog().string("[UnalignedHeapChunk.verifyUnalignedHeapChunk");
    trace.string("  that: ").hex(that).string("  start: ").hex(start).string("  top: ").hex(that.getTop()).string("  end: ").hex(that.getEnd()).newline();
    final UnsignedWord objHeader = ObjectHeader.readHeaderFromPointer(start);
    final ObjectHeaderImpl ohi = ObjectHeaderImpl.getObjectHeaderImpl();
    // The object should not be forwarded.
    if (ohi.isForwardedHeader(objHeader)) {
        final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
        witness.string("  that: ").hex(that).string("  start: ").hex(start).string("  top: ").hex(that.getTop()).string("  end: ").hex(that.getEnd());
        witness.string("  space: ").string(that.getSpace().getName());
        witness.string("  objHeader: ").string(ohi.toStringFromHeader(objHeader));
        witness.string("  should not be forwarded").string("]").newline();
        return false;
    }
    // The object should be marked as being unaligned.
    if (!ohi.isUnalignedHeader(objHeader)) {
        final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
        witness.string("  that: ").hex(that).string("  start: ").hex(start).string("  end: ").hex(that.getEnd());
        witness.string("  space: ").string(that.getSpace().getName());
        witness.string("  obj: ").hex(start).string("  objHeader: ").hex(objHeader);
        witness.string("  does not have an unaligned header").string("]").newline();
        return false;
    }
    // The object should be the only object in the chunk.
    final Object obj = start.toObject();
    final Pointer objEnd = LayoutEncoding.getObjectEnd(obj);
    if (objEnd.notEqual(that.getTop())) {
        final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
        witness.string("  that: ").hex(that).string("  start: ").hex(start).string("  end: ").hex(that.getEnd());
        witness.string("  space: ").string(that.getSpace().getName());
        witness.string("  obj: ").object(obj).string("  objEnd: ").hex(objEnd);
        witness.string("  should be the only object in the chunk").string("]").newline();
        return false;
    }
    if (!verifyRememberedSet(that)) {
        final Log witnessLog = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeadChunk remembered set fails to verify");
        witnessLog.string("  that: ").hex(that).string("  remembered set fails to verify.").string("]").newline();
    }
    // Verify the super-class.
    final boolean result = verifyHeapChunk(that, start);
    trace.string("  returns: ").bool(result).string("]").newline();
    return result;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 23 with Pointer

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

the class UnalignedHeapChunkMemoryWalkerAccessFeature method walkDirtyObjectsOfUnalignedHeapChunk.

/**
 * Walk the dirty Objects in this chunk, passing each to a Visitor.
 */
public static boolean walkDirtyObjectsOfUnalignedHeapChunk(UnalignedHeader that, ObjectVisitor visitor, boolean clean) {
    final Log trace = Log.noopLog().string("[UnalignedHeapChunk.walkDirtyObjects:");
    trace.string("  clean: ").bool(clean).string("  that: ").hex(that).string("  ");
    boolean result = true;
    final Pointer rememberedSetStart = getCardTableStart(that);
    final UnsignedWord objectIndex = getObjectIndex();
    trace.string("  rememberedSetStart: ").hex(rememberedSetStart).string("  objectIndex: ").unsigned(objectIndex);
    // If the card for this chunk is dirty, visit the object.
    if (CardTable.isDirtyEntryAtIndex(rememberedSetStart, objectIndex)) {
        final Pointer objectsStart = getUnalignedStart(that);
        final Object obj = objectsStart.toObject();
        trace.string("  obj: ").object(obj);
        // Visit the object.
        if (!visitor.visitObjectInline(obj)) {
            result = false;
        }
        if (clean) {
            CardTable.cleanEntryAtIndex(rememberedSetStart, objectIndex);
        }
    }
    trace.string("  returns: ").bool(result).string("]").newline();
    return result;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 24 with Pointer

use of org.graalvm.word.Pointer 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 25 with Pointer

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

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