Search in sources :

Example 1 with AlwaysInline

use of com.oracle.svm.core.annotate.AlwaysInline in project graal by oracle.

the class JavaStackWalker method walkThread.

@AlwaysInline("avoid virtual call to visitor")
public static boolean walkThread(IsolateThread thread, StackFrameVisitor visitor) {
    JavaFrameAnchor anchor = JavaFrameAnchors.getFrameAnchor(thread);
    Pointer sp = WordFactory.nullPointer();
    CodePointer ip = WordFactory.nullPointer();
    if (anchor.isNonNull()) {
        sp = anchor.getLastJavaSP();
        ip = FrameAccess.readReturnAddress(sp);
    }
    // always call doWalk() to invoke visitor's methods
    return doWalk(anchor, sp, ip, visitor);
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 2 with AlwaysInline

use of com.oracle.svm.core.annotate.AlwaysInline 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 3 with AlwaysInline

use of com.oracle.svm.core.annotate.AlwaysInline 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 4 with AlwaysInline

use of com.oracle.svm.core.annotate.AlwaysInline in project graal by oracle.

the class GreyToBlackObjectVisitor method visitObjectInline.

@Override
@AlwaysInline("GC performance")
public boolean visitObjectInline(final Object o) {
    final Log trace = Log.noopLog();
    // TODO: Why would this be passed a null Object?
    if (o == null) {
        return true;
    }
    trace.string("[GreyToBlackObjectVisitor:").string("  o: ").object(o);
    DiscoverableReferenceProcessing.discoverDiscoverableReference(o);
    InteriorObjRefWalker.walkObjectInline(o, objRefVisitor);
    trace.string("]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 5 with AlwaysInline

use of com.oracle.svm.core.annotate.AlwaysInline in project graal by oracle.

the class JavaStackWalker method doWalk.

@AlwaysInline("avoid virtual call to visitor")
private static boolean doWalk(JavaFrameAnchor lastAnchor, Pointer startSP, CodePointer startIP, StackFrameVisitor visitor) {
    if (!visitor.prologue()) {
        return false;
    }
    if (startSP.isNonNull() && startIP.isNonNull()) {
        JavaFrameAnchor anchor = lastAnchor;
        Pointer sp = startSP;
        CodePointer ip = startIP;
        while (true) {
            while (anchor.isNonNull() && anchor.getLastJavaSP().belowOrEqual(sp)) {
                /* Skip anchors that are in parts of the stack we are not traversing. */
                anchor = anchor.getPreviousAnchor();
            }
            long totalFrameSize;
            DeoptimizedFrame deoptFrame = Deoptimizer.checkDeoptimized(sp);
            if (deoptFrame != null) {
                totalFrameSize = deoptFrame.getSourceTotalFrameSize();
            } else {
                totalFrameSize = CodeInfoTable.lookupTotalFrameSize(ip);
            }
            if (totalFrameSize != -1) {
                /* This is a Java frame, visit it. */
                if (!visitor.visitFrame(sp, ip, deoptFrame)) {
                    return false;
                }
                /* Bump sp *up* over my frame. */
                sp = sp.add(WordFactory.unsigned(totalFrameSize));
                /* Read the return address to my caller. */
                ip = FrameAccess.readReturnAddress(sp);
            } else if (anchor.isNonNull()) {
                /*
                     * At the end of a block of Java frames, but we have more Java frames after a
                     * block of C frames.
                     */
                assert anchor.getLastJavaSP().aboveThan(sp);
                sp = anchor.getLastJavaSP();
                ip = FrameAccess.readReturnAddress(sp);
                anchor = anchor.getPreviousAnchor();
            } else {
                /* Really at the end of the stack, we are done with walking. */
                break;
            }
        }
    } else {
    /*
             * It is fine for a thread to have no Java frames, for example in the case of a native
             * thread that was attached via JNI, but is currently not executing any Java code.
             */
    }
    return visitor.epilogue();
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizedFrame(com.oracle.svm.core.deopt.DeoptimizedFrame) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Aggregations

AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)6 Pointer (org.graalvm.word.Pointer)5 UnsignedWord (org.graalvm.word.UnsignedWord)3 Log (com.oracle.svm.core.log.Log)2 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)2 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)1 ObjectHeader (com.oracle.svm.core.heap.ObjectHeader)1