use of org.graalvm.word.UnsignedWord 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.UnsignedWord in project graal by oracle.
the class UnalignedHeapChunkMemoryWalkerAccessFeature method getObjectStartOffset.
/**
* Where does the Object start?
*/
@Fold
static UnsignedWord getObjectStartOffset() {
final UnsignedWord cardTableLimitOffset = getCardTableLimitOffset();
final UnsignedWord alignment = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getAlignment());
final UnsignedWord result = UnsignedUtils.roundUp(cardTableLimitOffset, alignment);
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class AllocationSnippets method formatObjectImpl.
private static Object formatObjectImpl(Pointer memory, DynamicHub hub, UnsignedWord size, @ConstantParameter boolean constantSize, @ConstantParameter boolean fillContents, boolean rememberedSet) {
if (fillContents) {
emitPrefetchAllocate(memory, false);
}
WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, rememberedSet, false);
memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
if (fillContents) {
UnsignedWord offset = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
if (constantSize && ((size.subtract(offset).unsignedDivide(ConfigurationValues.getTarget().wordSize)).belowOrEqual(SubstrateOptions.MaxUnrolledObjectZeroingStores.getValue()))) {
ExplodeLoopNode.explodeLoop();
}
while (offset.belowThan(size)) {
memory.writeWord(offset, WordFactory.zero(), LocationIdentity.INIT_LOCATION);
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
}
return memory.toObjectNonNull();
}
use of org.graalvm.word.UnsignedWord 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);
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class AllocationSnippets method arraysCopyOfSnippet.
@Snippet
public static Object arraysCopyOfSnippet(DynamicHub hub, Object original, int originalLength, int newLength, AllocationCounter counter) {
int layoutEncoding = hub.getLayoutEncoding();
// allocate new array without initializing the new array
Object copy = newArraySnippet(hub, newLength, layoutEncoding, false, counter);
// copy elements from original
// The length of the copied section
int length = originalLength < newLength ? originalLength : newLength;
// The size of the copied section(obtained from the length of the copied section)
UnsignedWord size = LayoutEncoding.getArraySize(layoutEncoding, length);
// The size of the new array (obtained from the length of the new array)
UnsignedWord newSize = LayoutEncoding.getArraySize(layoutEncoding, newLength);
// We know that the offset is always word aligned
UnsignedWord offset = LayoutEncoding.getArrayBaseOffset(layoutEncoding);
while (offset.belowThan(size)) {
Object val = ObjectAccess.readObject(original, offset);
ObjectAccess.writeObject(copy, offset, val, LocationIdentity.INIT_LOCATION);
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
while (offset.belowThan(newSize)) {
ObjectAccess.writeObject(copy, offset, null, LocationIdentity.INIT_LOCATION);
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
return FixedValueAnchorNode.getObject(copy);
}
Aggregations