use of org.graalvm.word.Pointer in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method verifyRememberedSet.
/**
* Verify the remembered set of the given chunk.
*/
private static boolean verifyRememberedSet(UnalignedHeader that) {
// Only chunks in the old from space have a remembered set.
final HeapImpl heap = HeapImpl.getHeapImpl();
final OldGeneration oldGen = heap.getOldGeneration();
if (that.getSpace() == oldGen.getFromSpace()) {
// Check if there are cross-generational pointers ...
final Pointer objStart = getUnalignedStart(that);
final Object obj = objStart.toObject();
final boolean containsYoungReferences = CardTable.containsReferenceToYoungSpace(obj);
// ... and if so, that the chunk is marked as dirty.
if (containsYoungReferences) {
final Pointer rememberedSet = getCardTableStart(that);
final UnsignedWord objectIndex = getObjectIndex();
final boolean isDirty = CardTable.isDirtyEntryAtIndex(rememberedSet, objectIndex);
if (!isDirty) {
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
witness.string(" that: ").hex(that);
witness.string(" containsYoungReferences implies isDirty").string("]").newline();
return false;
}
}
}
return true;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method verifyUnalignedHeapChunk.
/**
* Verify an UnalignedHeapChunk, called from sub-class verify methods.
*/
private static boolean verifyUnalignedHeapChunk(UnalignedHeader that, Pointer start) {
VMOperation.guaranteeInProgress("Should only be called as a VMOperation.");
// The object in this chunk should not be forwarded,
// and should be the only object in the chunk.
final Log trace = HeapImpl.getHeapImpl().getHeapVerifierImpl().getTraceLog().string("[UnalignedHeapChunk.verifyUnalignedHeapChunk");
trace.string(" that: ").hex(that).string(" start: ").hex(start).string(" top: ").hex(that.getTop()).string(" end: ").hex(that.getEnd()).newline();
final UnsignedWord objHeader = ObjectHeader.readHeaderFromPointer(start);
final ObjectHeaderImpl ohi = ObjectHeaderImpl.getObjectHeaderImpl();
// The object should not be forwarded.
if (ohi.isForwardedHeader(objHeader)) {
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.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(" objHeader: ").string(ohi.toStringFromHeader(objHeader));
witness.string(" should not be forwarded").string("]").newline();
return false;
}
// The object should be marked as being unaligned.
if (!ohi.isUnalignedHeader(objHeader)) {
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
witness.string(" that: ").hex(that).string(" start: ").hex(start).string(" end: ").hex(that.getEnd());
witness.string(" space: ").string(that.getSpace().getName());
witness.string(" obj: ").hex(start).string(" objHeader: ").hex(objHeader);
witness.string(" does not have an unaligned header").string("]").newline();
return false;
}
// The object should be the only object in the chunk.
final Object obj = start.toObject();
final Pointer objEnd = LayoutEncoding.getObjectEnd(obj);
if (objEnd.notEqual(that.getTop())) {
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeapChunk.verify:");
witness.string(" that: ").hex(that).string(" start: ").hex(start).string(" end: ").hex(that.getEnd());
witness.string(" space: ").string(that.getSpace().getName());
witness.string(" obj: ").object(obj).string(" objEnd: ").hex(objEnd);
witness.string(" should be the only object in the chunk").string("]").newline();
return false;
}
if (!verifyRememberedSet(that)) {
final Log witnessLog = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[UnalignedHeadChunk remembered set fails to verify");
witnessLog.string(" that: ").hex(that).string(" remembered set fails to verify.").string("]").newline();
}
// Verify the super-class.
final boolean result = verifyHeapChunk(that, start);
trace.string(" returns: ").bool(result).string("]").newline();
return result;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method walkDirtyObjectsOfUnalignedHeapChunk.
/**
* Walk the dirty Objects in this chunk, passing each to a Visitor.
*/
public static boolean walkDirtyObjectsOfUnalignedHeapChunk(UnalignedHeader that, ObjectVisitor visitor, boolean clean) {
final Log trace = Log.noopLog().string("[UnalignedHeapChunk.walkDirtyObjects:");
trace.string(" clean: ").bool(clean).string(" that: ").hex(that).string(" ");
boolean result = true;
final Pointer rememberedSetStart = getCardTableStart(that);
final UnsignedWord objectIndex = getObjectIndex();
trace.string(" rememberedSetStart: ").hex(rememberedSetStart).string(" objectIndex: ").unsigned(objectIndex);
// If the card for this chunk is dirty, visit the object.
if (CardTable.isDirtyEntryAtIndex(rememberedSetStart, objectIndex)) {
final Pointer objectsStart = getUnalignedStart(that);
final Object obj = objectsStart.toObject();
trace.string(" obj: ").object(obj);
// Visit the object.
if (!visitor.visitObjectInline(obj)) {
result = false;
}
if (clean) {
CardTable.cleanEntryAtIndex(rememberedSetStart, objectIndex);
}
}
trace.string(" returns: ").bool(result).string("]").newline();
return result;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method getEnclosingUnalignedHeapChunkFromPointer.
/**
* Map from a Pointer to an object to the enclosing chunk.
*/
private static UnalignedHeader getEnclosingUnalignedHeapChunkFromPointer(Pointer objPointer) {
// This only works because there is only one object in an unaligned chunk.
// Where does the object start in an unaligned chunk?
final UnsignedWord startOffset = getObjectStartOffset();
// Back the Object pointer up to the beginning of the UnalignedHeapChunk.
final Pointer chunkPointer = objPointer.subtract(startOffset);
final UnalignedHeader result = (UnalignedHeader) chunkPointer;
return result;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class AllocationSnippets method newPinnedArraySnippet.
@Snippet
public static Object newPinnedArraySnippet(PinnedAllocatorImpl pinnedAllocator, DynamicHub hub, int length, @ConstantParameter int layoutEncoding, @ConstantParameter boolean fillContents, AllocationCounter counter) {
pinnedAllocator.ensureOpen();
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
profileAllocation(size, counter);
Pointer memory = WordFactory.nullPointer();
if (size.belowOrEqual(HeapPolicy.getLargeArrayThreshold()) && length >= 0) {
memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.pinnedTLAB.getAddress(), size);
}
Object result = null;
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
result = formatArrayImpl(memory, hub, length, layoutEncoding, size, fillContents, false, false);
} else {
result = callSlowNewPinnedArray(SLOW_NEW_PINNED_ARRAY, pinnedAllocator, hub.asClass(), length);
}
return PiArrayNode.piArrayCastToSnippetReplaceeStamp(result, length);
}
Aggregations