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