use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class PolyglotNativeAPI method polyglot_get_callback_info.
@CEntryPoint(name = "polyglot_get_callback_info")
public static PolyglotStatus polyglot_get_callback_info(IsolateThread isolate_thread, PolyglotCallbackInfo callback_info, SizeTPointer argc, PolyglotValuePointerPointer argv, WordPointer data) {
return withHandledErrors(() -> {
PolyglotCallbackInfoInternal callbackInfo = fetchHandle(callback_info);
UnsignedWord numberOfArguments = WordFactory.unsigned(callbackInfo.arguments.length);
UnsignedWord bufferSize = argc.read();
UnsignedWord size = bufferSize.belowThan(numberOfArguments) ? bufferSize : numberOfArguments;
argc.write(size);
for (UnsignedWord i = WordFactory.zero(); i.belowThan(size); i = i.add(1)) {
int index = (int) i.rawValue();
ObjectHandle argument = callbackInfo.arguments[index];
argv.write(index, argument);
}
data.write(callbackInfo.data);
});
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class Space method getUnalignedObjectBytes.
/**
* Aggregate the bytes in Object in unaligned chunks.
*/
private UnsignedWord getUnalignedObjectBytes() {
UnsignedWord result = WordFactory.zero();
UnalignedHeapChunk.UnalignedHeader uChunk = getFirstUnalignedHeapChunk();
while (uChunk.isNonNull()) {
final UnsignedWord allocatedBytes = uChunk.getTop().subtract(UnalignedHeapChunk.getObjectStart(uChunk));
result = result.add(allocatedBytes);
uChunk = uChunk.getNext();
}
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ThreadLocalAllocation method allocateNewInstance.
static Object allocateNewInstance(DynamicHub hub, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet) {
DeoptTester.disableDeoptTesting();
log().string("[ThreadLocalAllocation.allocateNewInstance: ").string(hub.asClass().getName()).string(" in tlab ").hex(tlab).newline();
// Slow-path check if allocation is disallowed.
HeapImpl.exitIfAllocationDisallowed("ThreadLocalAllocation.allocateNewInstance", hub.asClass().getName());
// Policy: Possibly collect before this allocation.
HeapImpl.getHeapImpl().getHeapPolicy().getCollectOnAllocationPolicy().maybeCauseCollection();
/*
* On this path allocation failed in the 'allocation chunk', thus we refill it, i.e.., add a
* new allocation chunk at the front of the TLAB's aligned chunks.
*/
AlignedHeader newChunk = prepareNewAllocationChunk(tlab);
UnsignedWord size = LayoutEncoding.getInstanceSize(hub.getLayoutEncoding());
Object result = allocateNewInstanceUninterruptibly(hub, tlab, rememberedSet, size, newChunk);
log().string(" ThreadLocalAllocation.allocateNewInstance returns ").object(result).string(" .. ").hex(LayoutEncoding.getObjectEnd(result)).string("]").newline();
DeoptTester.enableDeoptTesting();
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ThreadLocalAllocation method getObjectBytes.
/**
* Returns the total memory used by the TLAB in bytes. It counts only the memory actually used,
* not the total committed memory.
*/
public static UnsignedWord getObjectBytes(Descriptor tlab) {
Log log = log();
log.newline();
log.string("[ThreadLocalAllocator.usedMemory: tlab ").hex(tlab).newline();
AlignedHeader aChunk = tlab.getAlignedChunk();
UnsignedWord alignedUsedMemory = WordFactory.zero();
while (aChunk.isNonNull()) {
AlignedHeader next = aChunk.getNext();
Pointer start = AlignedHeapChunk.getAlignedHeapChunkStart(aChunk);
/* The allocation top has a null top; the TLAB is the one advancing the top pointer. */
Pointer top = aChunk.getTop().isNull() ? tlab.getAllocationTop(TOP_IDENTITY) : aChunk.getTop();
UnsignedWord aChunkUsedMemory = top.subtract(start);
alignedUsedMemory = alignedUsedMemory.add(aChunkUsedMemory);
log.string(" aligned chunk: ").hex(aChunk).string(" | used memory: ").unsigned(aChunkUsedMemory).newline();
aChunk = next;
}
UnsignedWord unalignedUsedMemory = WordFactory.zero();
UnalignedHeader uChunk = tlab.getUnalignedChunk();
while (uChunk.isNonNull()) {
UnalignedHeader next = uChunk.getNext();
UnsignedWord uChunkUsedMemory = UnalignedHeapChunk.usedObjectMemoryOfUnalignedHeapChunk(uChunk);
unalignedUsedMemory = unalignedUsedMemory.add(uChunkUsedMemory);
log.string(" unaligned chunk ").hex(uChunk).string(" | used memory: ").unsigned(uChunkUsedMemory).newline();
uChunk = next;
}
UnsignedWord tlabUsedMemory = alignedUsedMemory.add(unalignedUsedMemory);
log.newline();
log.string(" aligned used memory: ").unsigned(alignedUsedMemory).newline();
log.string(" unaligned used memory: ").unsigned(unalignedUsedMemory).newline();
log.string(" TLAB used memory: ").unsigned(tlabUsedMemory).newline();
log.string(" ]").newline();
return tlabUsedMemory;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method dirtyCardForObjectOfUnalignedHeapChunk.
/**
* Dirty the card corresponding to the given Object.
*
* This has to be fast, because it is used by the post-write barrier.
*/
public static void dirtyCardForObjectOfUnalignedHeapChunk(Object obj) {
final UnalignedHeader chunk = getEnclosingUnalignedHeapChunk(obj);
final Pointer rememberedSetStart = getCardTableStart(chunk);
final UnsignedWord objectIndex = getObjectIndex();
CardTable.dirtyEntryAtIndex(rememberedSetStart, objectIndex);
}
Aggregations