Search in sources :

Example 1 with ObjectHeader

use of com.oracle.svm.core.heap.ObjectHeader 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)

Aggregations

AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)1 ObjectHeader (com.oracle.svm.core.heap.ObjectHeader)1 Log (com.oracle.svm.core.log.Log)1 Pointer (org.graalvm.word.Pointer)1 UnsignedWord (org.graalvm.word.UnsignedWord)1