use of org.graalvm.word.Pointer in project graal by oracle.
the class ReferenceMapDecoder method walkOffsetsFromPointer.
/**
* Walk the reference map encoding from a Pointer, applying a visitor to each Object reference.
*
* @param baseAddress A Pointer to a collections of primitives and Object references.
* @param referenceMapEncoding The encoding for the Object references in the collection.
* @param referenceMapIndex The start index for the particular reference map in the encoding.
* @param visitor The ObjectRefernceVisitor to be applied to each Object reference.
* @return false if any of the visits returned false, true otherwise.
*/
@AlwaysInline("de-virtualize calls to ObjectReferenceVisitor")
public static boolean walkOffsetsFromPointer(PointerBase baseAddress, byte[] referenceMapEncoding, long referenceMapIndex, ObjectReferenceVisitor visitor) {
assert referenceMapIndex != CodeInfoQueryResult.NO_REFERENCE_MAP;
assert referenceMapEncoding != null;
UnsignedWord uncompressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getReferenceSize());
UnsignedWord compressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getCompressedReferenceSize());
UnsignedWord slotSize = WordFactory.unsigned(SubstrateReferenceMap.getSlotSizeInBytes());
Pointer objRef = (Pointer) baseAddress;
long idx = referenceMapIndex;
while (true) {
int gap = ByteArrayReader.getU1(referenceMapEncoding, idx);
if (gap == GAP_END_OF_TABLE) {
break;
}
int count = ByteArrayReader.getS1(referenceMapEncoding, idx + 1);
// Skip a gap.
objRef = objRef.add(slotSize.multiply(gap));
// Visit the offsets.
boolean compressed = (count < 0);
UnsignedWord refSize = compressed ? compressedSize : uncompressedSize;
count = (count < 0) ? -count : count;
for (int c = 0; c < count; c += 1) {
final boolean visitResult = visitor.visitObjectReferenceInline(objRef, compressed);
if (!visitResult) {
return false;
}
objRef = objRef.add(refSize);
}
idx += 2;
}
return true;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class StubUtil method verifyObject.
/**
* Verifies that a given object value is well formed if {@code -XX:+VerifyOops} is enabled.
*/
public static Object verifyObject(Object object) {
if (verifyOops(INJECTED_VMCONFIG)) {
Word verifyOopCounter = WordFactory.unsigned(verifyOopCounterAddress(INJECTED_VMCONFIG));
verifyOopCounter.writeInt(0, verifyOopCounter.readInt(0) + 1);
Pointer oop = Word.objectToTrackedPointer(object);
if (object != null) {
GuardingNode anchorNode = SnippetAnchorNode.anchor();
// make sure object is 'reasonable'
if (!oop.and(WordFactory.unsigned(verifyOopMask(INJECTED_VMCONFIG))).equal(WordFactory.unsigned(verifyOopBits(INJECTED_VMCONFIG)))) {
fatal("oop not in heap: %p", oop.rawValue());
}
KlassPointer klass = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
if (klass.isNull()) {
fatal("klass for oop %p is null", oop.rawValue());
}
}
}
return object;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class Space method allocateMemory.
/**
* Allocate memory from an AlignedHeapChunk in this Space.
*
* This is "slow-path" memory allocation.
*/
private Pointer allocateMemory(UnsignedWord objectSize) {
final Log trace = Log.noopLog().string("[SpaceImpl.allocateMemory:").string(" space: ").string(getName()).string(" size: ").unsigned(objectSize).newline();
Pointer result = WordFactory.nullPointer();
/* First try allocating in the last chunk. */
final AlignedHeapChunk.AlignedHeader oldChunk = getLastAlignedHeapChunk();
trace.string(" oldChunk: ").hex(oldChunk);
if (oldChunk.isNonNull()) {
result = AlignedHeapChunk.allocateMemory(oldChunk, objectSize);
trace.string(" oldChunk provides: ").hex(result);
}
/* If oldChunk did not provide, try allocating a new chunk for the requested memory. */
if (result.isNull()) {
final AlignedHeapChunk.AlignedHeader newChunk = requestAlignedHeapChunk();
trace.string(" newChunk: ").hex(newChunk);
if (newChunk.isNonNull()) {
/* Allocate the Object within the new chunk. */
result = AlignedHeapChunk.allocateMemory(newChunk, objectSize);
trace.string(" newChunk provides: ").hex(result);
}
}
trace.string(" returns: ").hex(result).string("]").newline();
return result;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class ThreadLocalAllocation method allocateLargeArray.
@Uninterruptible(reason = "Holds uninitialized memory, modifies TLAB")
private static Object allocateLargeArray(DynamicHub hub, int length, UnsignedWord size, UnalignedHeapChunk.UnalignedHeader uChunk, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet) {
/* Register the new chunk in the TLAB linked list of unaligned chunks. */
uChunk.setNext(tlab.getUnalignedChunk());
tlab.setUnalignedChunk(uChunk);
/* Allocate the memory. We must have a chunk, otherwise we already threw an exception. */
Pointer memory = UnalignedHeapChunk.allocateMemory(uChunk, size);
assert memory.isNonNull();
/* Install the DynamicHub and length, and zero the elements. */
return KnownIntrinsics.formatArray(memory, hub.asClass(), length, rememberedSet, true);
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class ThreadLocalAllocation method allocateSmallArray.
@Uninterruptible(reason = "Holds uninitialized memory, modifies TLAB")
private static Object allocateSmallArray(DynamicHub hub, int length, UnsignedWord size, ThreadLocalAllocation.Descriptor tlab, boolean rememberedSet, AlignedHeader newChunk) {
registerNewAllocationChunk(tlab, newChunk);
/*
* Allocate the memory. We must have a chunk, because we just registered one and we are
* still in the same block of uninterruptible code.
*/
Pointer memory = allocateMemory(tlab, size);
assert memory.isNonNull();
/* Install the DynamicHub and length, and zero the elements. */
return KnownIntrinsics.formatArray(memory, hub.asClass(), length, rememberedSet, false);
}
Aggregations