Search in sources :

Example 26 with Pointer

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

the class AllocationSnippets method doCloneUninterruptibly.

@Uninterruptible(reason = "Copies via Pointers")
private static // TODO: What if the bytes being written need remembered set operations?
Object doCloneUninterruptibly(Object thisObject, Object thatObject, UnsignedWord firstFieldOffset, UnsignedWord size) {
    Pointer thatMemory = Word.objectToUntrackedPointer(thatObject);
    /*
         * Copy the thisObj over thatMemory. Excluding the hub to make sure that no GC-relevant
         * header bits are transfered from thisObj to the clone.
         */
    Pointer thisMemory = Word.objectToUntrackedPointer(thisObject);
    UnsignedWord offset = firstFieldOffset;
    while (offset.belowThan(size)) {
        thatMemory.writeWord(offset, thisMemory.readWord(offset));
        offset = offset.add(ConfigurationValues.getTarget().wordSize);
    }
    final Object result = thatMemory.toObjectNonNull();
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 27 with Pointer

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

the class AllocationSnippets method newInstance.

public static Object newInstance(DynamicHub hub, int encoding, @ConstantParameter boolean constantSize, @ConstantParameter boolean fillContents, AllocationCounter counter) {
    checkHub(hub);
    UnsignedWord size = LayoutEncoding.getInstanceSize(encoding);
    profileAllocation(size, counter);
    Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
    Object result;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        result = formatObjectImpl(memory, hub, size, constantSize, fillContents, false);
    } else {
        result = callSlowNewInstance(SLOW_NEW_INSTANCE, hub.asClass());
    }
    return PiNode.piCastToSnippetReplaceeStamp(result);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Example 28 with Pointer

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

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

the class HeapChunk method getNextObject.

/**
 * Given an Object, return the next Object in this HeapChunk, or null.
 */
private static Object getNextObject(Header<?> that, Object obj) {
    final Log trace = Log.noopLog().string("[HeapChunk.getNextObject:").newline();
    final Pointer objEnd = LayoutEncoding.getObjectEnd(obj);
    trace.string("  o: ").object(obj).string("  objEnd: ").hex(objEnd).string("  top: ").hex(that.getTop()).newline();
    /* Check if top is below the proposed next object. */
    if (that.getTop().belowOrEqual(objEnd)) {
        trace.string("  returns null").string("]").newline();
        return null;
    }
    final Object result = objEnd.toObject();
    /* TODO: How do I assert that result is an Object? */
    trace.string(" returns ").object(result).string("]").newline();
    return result;
}
Also used : Log(com.oracle.svm.core.log.Log) Pointer(org.graalvm.word.Pointer)

Example 30 with Pointer

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

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