use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class FirstObjectTable method getPointerAtOffset.
/**
* Turn an entry from the table into a Pointer into a memory region.
*/
private static Pointer getPointerAtOffset(Pointer memory, UnsignedWord currentIndex, int currentEntry) {
/* This does not need the table because I've already read the entry from it. */
assert isMemoryOffsetEntry(currentEntry) : "Entry out of bounds.";
final UnsignedWord indexOffset = indexToMemoryOffset(currentIndex);
final UnsignedWord entryOffset = entryToMemoryOffset(currentEntry);
return memory.add(indexOffset).subtract(entryOffset);
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class FirstObjectTable method memoryOffsetToEntry.
/**
* Turn a memory offset into a table entry.
*/
private static int memoryOffsetToEntry(UnsignedWord memoryOffset) {
assert memoryOffset.belowThan(MEMORY_BYTES_PER_ENTRY) : "Offset out of bounds.";
/* Scale the offset and negate it to produce an entry. */
final UnsignedWord scaledOffset = memoryOffset.unsignedDivide(memoryOffsetScale());
assert scaledOffset.multiply(memoryOffsetScale()).equal(memoryOffset) : "Not a multiple.";
final long result = (-scaledOffset.rawValue());
assert ((MEMORY_OFFSET_MIN <= result) && (result <= MEMORY_OFFSET_MAX)) : "Scaled offset out of bounds.";
return (int) result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class GarbageCollectorManagementFactory method collect.
/*
* Collection methods.
*/
@Override
public void collect(String cause) {
final UnsignedWord requestingEpoch = possibleCollectionPrologue();
/* Collect without allocating. */
collectWithoutAllocating(cause);
/* Do anything necessary now that allocation, etc., is allowed. */
possibleCollectionEpilogue(requestingEpoch);
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class GarbageCollectorManagementFactory method printGCAfter.
private void printGCAfter(String cause) {
final Log verboseGCLog = Log.log();
final HeapImpl heap = HeapImpl.getHeapImpl();
if (SubstrateOptions.PrintGC.getValue() || SubstrateOptions.VerboseGC.getValue()) {
if (SubstrateOptions.PrintGC.getValue()) {
final Log printGCLog = Log.log();
final UnsignedWord sizeAfter = heap.getUsedChunkBytes();
printGCLog.string("[");
if (SubstrateOptions.PrintGCTimeStamps.getValue()) {
final long finishNanos = collectionTimer.getFinish();
printGCLog.unsigned(TimeUtils.roundNanosToMillis(Timer.getTimeSinceFirstAllocation(finishNanos))).string(" msec: ");
}
printGCLog.string(completeCollection ? "Full GC" : "Incremental GC");
printGCLog.string(" (").string(cause).string(") ");
printGCLog.unsigned(sizeBefore.unsignedDivide(1024));
printGCLog.string("K->");
printGCLog.unsigned(sizeAfter.unsignedDivide(1024)).string("K, ");
printGCLog.rational(collectionTimer.getCollectedNanos(), TimeUtils.nanosPerSecond, DECIMALS_IN_TIME_PRINTING).string(" secs");
printGCLog.string("]").newline();
}
if (SubstrateOptions.VerboseGC.getValue()) {
verboseGCLog.string(" [");
final long finishNanos = collectionTimer.getFinish();
if (SubstrateOptions.PrintGCTimeStamps.getValue()) {
verboseGCLog.unsigned(TimeUtils.roundNanosToMillis(Timer.getTimeSinceFirstAllocation(finishNanos))).string(" msec: ");
} else {
verboseGCLog.unsigned(finishNanos);
}
verboseGCLog.string(" GC:").string(" after ").string(" epoch: ").unsigned(getCollectionEpoch()).string(" cause: ").string(cause);
verboseGCLog.string(" policy: ");
getPolicy().nameToLog(verboseGCLog);
verboseGCLog.string(" type: ").string(completeCollection ? "complete" : "incremental");
if (HeapOptions.PrintHeapShape.getValue()) {
heap.report(verboseGCLog);
}
if (!HeapOptions.PrintGCTimes.getValue()) {
verboseGCLog.newline();
verboseGCLog.string(" collection time: ").unsigned(collectionTimer.getCollectedNanos()).string(" nanoSeconds");
} else {
logGCTimers(verboseGCLog);
}
verboseGCLog.string("]");
verboseGCLog.string("]").newline();
}
}
}
use of org.graalvm.word.UnsignedWord 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;
}
Aggregations