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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations