Search in sources :

Example 26 with UnsignedWord

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

the class GreyToBlackObjRefVisitor method visitObjectReferenceInline.

/**
 * This visitor is deals in *Pointers to Object references*. As such it uses Pointer.readObject
 * and Pointer.writeObject on the Pointer, not Pointer.toObject and Word.fromObject(o).
 */
@Override
@AlwaysInline("GC performance")
public boolean visitObjectReferenceInline(final Pointer objRef, boolean compressed) {
    getCounters().noteObjRef();
    final Log trace = Log.noopLog().string("[GreyToBlackObjRefVisitor.visitObjectReferenceInline:").string("  objRef: ").hex(objRef);
    if (objRef.isNull()) {
        getCounters().noteNullObjRef();
        trace.string(" null objRef ").hex(objRef).string("]").newline();
        return true;
    }
    // Read the referenced Object, carefully.
    final Pointer p = ReferenceAccess.singleton().readObjectAsUntrackedPointer(objRef, compressed);
    trace.string("  p: ").hex(p);
    // It might be null.
    if (p.isNull()) {
        getCounters().noteNullReferent();
        // Nothing to do.
        trace.string(" null").string("]").newline();
        return true;
    }
    final UnsignedWord header = ObjectHeader.readHeaderFromPointer(p);
    final ObjectHeader ohi = HeapImpl.getHeapImpl().getObjectHeader();
    // It might be a forwarding pointer.
    if (ohi.isForwardedHeader(header)) {
        getCounters().noteForwardedReferent();
        trace.string("  forwards to ");
        // Update the reference to point to the forwarded Object.
        final Object obj = ohi.getForwardedObject(header);
        ReferenceAccess.singleton().writeObjectAt(objRef, obj, compressed);
        trace.object(obj);
        if (trace.isEnabled()) {
            trace.string("  objectHeader: ").string(ohi.toStringFromObject(obj)).string("]").newline();
        }
        return true;
    }
    // It might be a real Object.
    final Object obj = p.toObject();
    // If the object is not a heap object there's nothing to do.
    if (ohi.isNonHeapAllocatedHeader(header)) {
        getCounters().noteNonHeapReferent();
        // Non-heap objects do not get promoted.
        trace.string("  Non-heap obj: ").object(obj);
        if (trace.isEnabled()) {
            trace.string("  objectHeader: ").string(ohi.toStringFromObject(obj)).string("]").newline();
        }
        return true;
    }
    // Otherwise, promote it if necessary, and update the Object reference.
    trace.string(" ").object(obj);
    if (trace.isEnabled()) {
        trace.string("  objectHeader: ").string(ohi.toStringFromObject(obj)).newline();
    }
    // Promote the Object if necessary, making it at least grey, and ...
    final Object copy = HeapImpl.getHeapImpl().promoteObject(obj);
    trace.string("  copy: ").object(copy);
    if (trace.isEnabled()) {
        trace.string("  objectHeader: ").string(ohi.toStringFromObject(copy));
    }
    // ... update the reference to point to the copy, making the reference black.
    if (copy != obj) {
        getCounters().noteCopiedReferent();
        trace.string(" updating objRef: ").hex(objRef).string(" with copy: ").object(copy);
        ReferenceAccess.singleton().writeObjectAt(objRef, copy, compressed);
    } else {
        getCounters().noteUnmodifiedReference();
    }
    trace.string("]").newline();
    return true;
}
Also used : ObjectHeader(com.oracle.svm.core.heap.ObjectHeader) Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 27 with UnsignedWord

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

the class HeapChunk method verifyHeapChunk.

/*
     * Verification.
     */
/**
 * Verify a chunk.
 */
static boolean verifyHeapChunk(Header<?> that, Pointer start) {
    /* Verify all the objects in this chunk. */
    final Log trace = HeapImpl.getHeapImpl().getHeapVerifierImpl().getTraceLog().string("[HeapChunk.verify:");
    trace.string("  that:  ").hex(that).string("  start: ").hex(start).string("  top: ").hex(that.getTop()).string("  end: ").hex(that.getEnd());
    Pointer p = start;
    while (p.belowThan(that.getTop())) {
        if (!HeapImpl.getHeapImpl().getHeapVerifierImpl().verifyObjectAt(p)) {
            final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[HeapChunk.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("  object at p: ").hex(p).string("  fails to verify").string("]").newline();
            trace.string("  returns false]").newline();
            return false;
        }
        /* Step carefully over the object. */
        final UnsignedWord header = ObjectHeaderImpl.readHeaderFromPointerCarefully(p);
        final Object o;
        if (ObjectHeaderImpl.getObjectHeaderImpl().isForwardedHeaderCarefully(header)) {
            /* Use the forwarded object to get the size. */
            o = ObjectHeaderImpl.getObjectHeaderImpl().getForwardedObject(header);
        } else {
            /* Use the object to get the size. */
            o = p.toObject();
        }
        p = p.add(LayoutEncoding.getSizeFromObject(o));
    }
    trace.string("  returns true]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 28 with UnsignedWord

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

the class HeapChunkProvider method consumeUnalignedChunk.

/**
 * Recycle an UnalignedHeapChunk back to the operating system. They are never recycled to a free
 * list.
 */
void consumeUnalignedChunk(UnalignedHeader chunk) {
    final UnsignedWord chunkSize = chunk.getEnd().subtract(HeapChunk.asPointer(chunk));
    log().string("[HeapChunkProvider.consumeUnalignedChunk  chunk: ").hex(chunk).string("  chunkSize: ").hex(chunkSize).newline();
    ConfigurationValues.getOSInterface().freeVirtualMemory(chunk, chunkSize);
    log().string(" ]").newline();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 29 with UnsignedWord

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

the class HeapChunkProvider method keepAlignedChunk.

/**
 * Should I keep another aligned chunk on the free list?
 */
private boolean keepAlignedChunk() {
    final Log trace = Log.noopLog().string("[HeapChunkProvider.keepAlignedChunk:");
    final UnsignedWord minimumHeapSize = HeapPolicy.getMinimumHeapSize();
    final UnsignedWord heapChunkBytes = HeapImpl.getHeapImpl().getUsedChunkBytes();
    final UnsignedWord unusedChunkBytes = bytesInUnusedAlignedChunks.get();
    final UnsignedWord bytesInUse = heapChunkBytes.add(unusedChunkBytes);
    /* If I am under the minimum heap size, then I can keep this chunk. */
    final boolean result = bytesInUse.belowThan(minimumHeapSize);
    trace.string("  minimumHeapSize: ").unsigned(minimumHeapSize).string("  heapChunkBytes: ").unsigned(heapChunkBytes).string("  unusedBytes: ").unsigned(unusedChunkBytes).string("  bytesInUse: ").unsigned(bytesInUse).string("  returns: ").bool(result).string(" ]").newline();
    return result;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord)

Example 30 with UnsignedWord

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

the class Target_java_lang_Runtime method getUsedChunkBytes.

/**
 * Returns the size (in bytes) of the heap currently used for aligned and unaligned chunks. It
 * excludes chunks that are unused.
 */
UnsignedWord getUsedChunkBytes() {
    final UnsignedWord youngBytes = getYoungUsedChunkBytes();
    final UnsignedWord oldBytes = getOldUsedChunkBytes();
    return youngBytes.add(oldBytes);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

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