use of org.graalvm.word.Pointer in project graal by oracle.
the class FirstObjectTable method verify.
/**
* Verify a FirstObjectTable.
*/
protected static boolean verify(Pointer tableStart, Pointer memoryStart, Pointer memoryLimit) {
/*
* Walk the table checking that I can find the start of the object that crosses onto this
* entry.
*/
final Log trace = HeapImpl.getHeapImpl().getHeapVerifierImpl().getTraceLog().string("[FirstObjectTable.verify:");
trace.string(" tableStart: ").hex(tableStart).string(" memoryStart: ").hex(memoryStart).string(" memoryLimit: ").hex(memoryLimit);
final UnsignedWord indexLimit = getTableSizeForMemoryPointers(memoryStart, memoryLimit);
for (UnsignedWord index = WordFactory.unsigned(0); index.belowThan(indexLimit); index = index.add(1)) {
trace.newline().string(" FirstObjectTable.verify: index: ").unsigned(index).newline();
final Pointer objStart = getPreciseFirstObjectPointer(tableStart, memoryStart, memoryLimit, index);
trace.string(" objStart: ").hex(objStart).newline();
if (objStart.belowThan(memoryStart)) {
/* Map points below memory. */
trace.string(" FirstObjectTable.verify: objStart.belowThan(memoryStart) => false]").newline();
return false;
}
if (memoryLimit.belowOrEqual(objStart)) {
/* Map points above memory. */
trace.string(" FirstObjectTable.verify: memoryLimit.belowOrEqual(objStart) => false]").newline();
return false;
}
if (!HeapImpl.getHeapImpl().getHeapVerifierImpl().verifyObjectAt(objStart)) {
/* Bad object. */
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
witness.string(" tableStart: ").hex(tableStart).string(" memoryStart: ").hex(memoryStart).string(" memoryLimit: ").hex(memoryLimit);
witness.string(" objStart: ").hex(objStart).string(" fails to verify").string("]").newline();
return false;
}
/* Check that the object crosses onto this entry. */
/*
* - Things are okay if ((objStart <= entryStart) && (entryStart < objEnd)) so I need to
* return false if either of those conditions is false
*/
final Pointer entryStart = memoryStart.add(indexToMemoryOffset(index));
trace.string(" entryStart: ").hex(entryStart);
if (!(objStart.belowOrEqual(entryStart))) {
/* Object doesn't start before this entry. */
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
witness.string(" tableStart: ").hex(tableStart).string(" memoryStart: ").hex(memoryStart).string(" memoryLimit: ").hex(memoryLimit);
witness.string(" objStart: ").hex(objStart).string(" entryStart: ").hex(entryStart).string(" !(objStart.belowOrEqual(entryStart))").string("]").newline();
return false;
}
final Object obj = objStart.toObject();
final Pointer objEnd = LayoutEncoding.getObjectEnd(obj);
trace.string(" ");
trace.string(obj.getClass().getName());
trace.string(" objEnd: ").hex(objEnd);
if (!(entryStart.belowThan(objEnd))) {
/* Object doesn't continue onto this entry. */
final Log witness = HeapImpl.getHeapImpl().getHeapVerifierImpl().getWitnessLog().string("[FirstObjectTable.verify:");
witness.string(" tableStart: ").hex(tableStart).string(" memoryStart: ").hex(memoryStart).string(" memoryLimit: ").hex(memoryLimit);
witness.string(" objEnd: ").hex(objEnd).string(" entryStart: ").hex(entryStart).string(" !(entryStart.belowThan(objEnd))").string("]").newline();
return false;
}
}
trace.string(" => true]").newline();
return true;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class GarbageCollectorManagementFactory method blackenStackRoots.
@SuppressWarnings("try")
private void blackenStackRoots() {
final Log trace = Log.noopLog().string("[GCImpl.blackenStackRoots:").newline();
try (Timer bsr = blackenStackRootsTimer.open()) {
Pointer sp = readCallerStackPointer();
trace.string("[blackenStackRoots:").string(" sp: ").hex(sp);
CodePointer ip = readReturnAddress();
trace.string(" ip: ").hex(ip).newline();
JavaStackWalker.walkCurrentThread(sp, ip, frameWalker);
if (SubstrateOptions.MultiThreaded.getValue()) {
/*
* Scan the stacks of all the threads. Other threads will be blocked at a safepoint
* (or in native code) so they will each have a JavaFrameAnchor in their VMThread.
*/
for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
/*
* The current thread is already scanned by code above, so we do not have to
* do anything for it here. It might have a JavaFrameAnchor from earlier
* Java-to-C transitions, but certainly not at the top of the stack since it
* is running this code, so just this scan would be incomplete.
*/
continue;
}
JavaStackWalker.walkThread(vmThread, frameWalker);
trace.newline();
}
}
trace.string("]").newline();
}
trace.string("]").newline();
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class Space method copyAlignedObject.
/**
* Copy an Object into the given memory.
*/
private Object copyAlignedObject(Object originalObj) {
VMOperation.guaranteeInProgress("Should only be called from the collector.");
assert ObjectHeaderImpl.getObjectHeaderImpl().isAlignedObject(originalObj);
final Log trace = Log.noopLog().string("[SpaceImpl.copyAlignedObject:");
trace.string(" originalObj: ").object(originalObj);
/* ObjectAccess.writeWord needs an Object as a 0th argument. */
/* - Allocate memory for the copy in this Space. */
final UnsignedWord copySize = LayoutEncoding.getSizeFromObject(originalObj);
trace.string(" copySize: ").unsigned(copySize);
final Pointer copyMemory = allocateMemory(copySize);
trace.string(" copyMemory: ").hex(copyMemory);
if (copyMemory.isNull()) {
/* TODO: Promotion failure! */
final Log failureLog = Log.log().string("[!SpaceImpl.copyAlignedObject:");
failureLog.string(" failure to allocate ").unsigned(copySize).string(" bytes").string("!]").newline();
return null;
}
/* - Copy the Object. */
final Pointer originalMemory = Word.objectToUntrackedPointer(originalObj);
UnsignedWord offset = WordFactory.zero();
while (offset.belowThan(copySize)) {
/*
* This copies words, without regard to whether they are pointers and so need to dirty
* remembered sets, etc. That's okay, because when the dust settles, anything the copy
* references will be in the old Space, so any card remembered sets for the object can
* be "clean". This writes the hub from the original over the hub installed by the
* allocateArray or allocateObject. That shouldn't be an issue, here.
*/
copyMemory.writeWord(offset, originalMemory.readWord(offset));
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
final Object copyObj = copyMemory.toObject();
/* Note that the object needs a remembered set. */
setAlignedRememberedSet(copyObj);
trace.string(" copyObj: ").object(copyObj).string("]").newline();
return copyObj;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class ThreadLocalAllocation method allocateMemory.
/**
* The implementation of the AllocationSnippets.fastAllocateImpl(Unsigned).
* <p>
* This is bump-pointer allocation for the young generation, using a cached "top" and "end".
* <p>
* Since this is called from a snippet, it and all the methods it calls, must be able to be
* inlined. The easy way to do that is to make this method, and all the methods it calls, final
* or static.
* <p>
* This allocates *memory*, not an Object. The rest of the allocation path takes care of turning
* the memory into an Object.
* <p>
* See also
* {@linkplain AlignedHeapChunk#allocateMemory(AlignedHeapChunk.AlignedHeader, UnsignedWord)}.
*/
@Uninterruptible(reason = "returns uninitialized memory, modifies TLAB", callerMustBe = true)
public static Pointer allocateMemory(Descriptor allocator, UnsignedWord size) {
Pointer top = KnownIntrinsics.nonNullPointer(allocator.getAllocationTop(TOP_IDENTITY));
Pointer end = KnownIntrinsics.nonNullPointer(allocator.getAllocationEnd(END_IDENTITY));
UnsignedWord available = end.subtract(top);
if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, size.belowOrEqual(available))) {
allocator.setAllocationTop(top.add(size), TOP_IDENTITY);
return top;
} else {
return WordFactory.nullPointer();
}
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method allocateMemory.
/*
* Methods on UnalignedHeapChunk.
*/
/**
* Allocate memory within this AlignedHeapChunk. No initialization of the memory happens here.
*/
@Uninterruptible(reason = "Returns uninitialized memory.", callerMustBe = true)
public static Pointer allocateMemory(UnalignedHeader that, UnsignedWord size) {
final UnsignedWord available = availableObjectMemory(that);
// Is memory available for the requested size?
Pointer result = WordFactory.nullPointer();
if (size.belowOrEqual(available)) {
// Returned memory is at the start,
result = that.getTop();
final Pointer newTop = result.add(size);
setTopCarefully(that, newTop);
}
return result;
}
Aggregations