use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerSizeOfPlugins.
private static void registerSizeOfPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins) {
Registration r = new Registration(plugins, SizeOf.class);
r.register1("get", Class.class, new InvocationPlugin() {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
int result = SizeOf.get(clazz);
b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Int, ConstantNode.forInt(result)));
return true;
}
});
r.register1("unsigned", Class.class, new InvocationPlugin() {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
UnsignedWord result = SizeOf.unsigned(clazz);
b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Object, ConstantNode.forConstant(snippetReflection.forObject(result), b.getMetaAccess())));
return true;
}
});
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class WriteBarrierSnippets method g1PostWriteBarrier.
@Snippet
public static void g1PostWriteBarrier(Address address, Object object, Object value, @ConstantParameter boolean usePrecise, @ConstantParameter Register threadRegister, @ConstantParameter boolean trace, @ConstantParameter Counters counters) {
Word thread = registerAsWord(threadRegister);
Object fixedValue = FixedValueAnchorNode.getObject(value);
verifyOop(object);
verifyOop(fixedValue);
validateObject(object, fixedValue);
Pointer oop;
if (usePrecise) {
oop = Word.fromAddress(address);
} else {
oop = Word.objectToTrackedPointer(object);
}
int gcCycle = 0;
if (trace) {
Pointer gcTotalCollectionsAddress = WordFactory.pointer(HotSpotReplacementsUtil.gcTotalCollectionsAddress(INJECTED_VMCONFIG));
gcCycle = (int) gcTotalCollectionsAddress.readLong(0);
log(trace, "[%d] G1-Post Thread: %p Object: %p\n", gcCycle, thread.rawValue(), Word.objectToTrackedPointer(object).rawValue());
log(trace, "[%d] G1-Post Thread: %p Field: %p\n", gcCycle, thread.rawValue(), oop.rawValue());
}
Pointer writtenValue = Word.objectToTrackedPointer(fixedValue);
// The result of the xor reveals whether the installed pointer crosses heap regions.
// In case it does the write barrier has to be issued.
final int logOfHeapRegionGrainBytes = GraalHotSpotVMConfigNode.logOfHeapRegionGrainBytes();
UnsignedWord xorResult = (oop.xor(writtenValue)).unsignedShiftRight(logOfHeapRegionGrainBytes);
// Calculate the address of the card to be enqueued to the
// thread local card queue.
UnsignedWord cardBase = oop.unsignedShiftRight(cardTableShift(INJECTED_VMCONFIG));
final long startAddress = GraalHotSpotVMConfigNode.cardTableAddress();
int displacement = 0;
if (((int) startAddress) == startAddress && GraalHotSpotVMConfigNode.isCardTableAddressConstant()) {
displacement = (int) startAddress;
} else {
cardBase = cardBase.add(WordFactory.unsigned(startAddress));
}
Word cardAddress = (Word) cardBase.add(displacement);
counters.g1AttemptedPostWriteBarrierCounter.inc();
if (probability(FREQUENT_PROBABILITY, xorResult.notEqual(0))) {
counters.g1EffectiveAfterXORPostWriteBarrierCounter.inc();
// If the written value is not null continue with the barrier addition.
if (probability(FREQUENT_PROBABILITY, writtenValue.notEqual(0))) {
byte cardByte = cardAddress.readByte(0, GC_CARD_LOCATION);
counters.g1EffectiveAfterNullPostWriteBarrierCounter.inc();
// If the card is already dirty, (hence already enqueued) skip the insertion.
if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue(INJECTED_VMCONFIG))) {
MembarNode.memoryBarrier(STORE_LOAD, GC_CARD_LOCATION);
byte cardByteReload = cardAddress.readByte(0, GC_CARD_LOCATION);
if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue(INJECTED_VMCONFIG))) {
log(trace, "[%d] G1-Post Thread: %p Card: %p \n", gcCycle, thread.rawValue(), WordFactory.unsigned((int) cardByte).rawValue());
cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION);
counters.g1ExecutedPostWriteBarrierCounter.inc();
// If the thread local card queue is full, issue a native call which will
// initialize a new one and add the card entry.
Word indexAddress = thread.add(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
Word indexValue = thread.readWord(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) {
Word bufferAddress = thread.readWord(g1CardQueueBufferOffset(INJECTED_VMCONFIG));
Word nextIndex = indexValue.subtract(wordSize());
Word logAddress = bufferAddress.add(nextIndex);
// Log the object to be scanned as well as update
// the card queue's next index.
logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION);
indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION);
} else {
g1PostBarrierStub(G1WBPOSTCALL, cardAddress);
}
}
}
}
}
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method objectCopyBackward.
private static void objectCopyBackward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
UnsignedWord size = elementSize.multiply(length);
objectCopyBackwardsUninterruptibly(fromArray, fromOffset, toArray, toOffset, elementSize, size);
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method primitiveCopyBackward.
private static void primitiveCopyBackward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
UnsignedWord size = elementSize.multiply(length);
if (size.and(1).notEqual(0)) {
size = size.subtract(1);
ObjectAccess.writeByte(toArray, toOffset.add(size), ObjectAccess.readByte(fromArray, fromOffset.add(size)));
}
if (size.and(3).notEqual(0)) {
size = size.subtract(2);
ObjectAccess.writeShort(toArray, toOffset.add(size), ObjectAccess.readShort(fromArray, fromOffset.add(size)));
}
if (size.and(7).notEqual(0)) {
size = size.subtract(4);
ObjectAccess.writeInt(toArray, toOffset.add(size), ObjectAccess.readInt(fromArray, fromOffset.add(size)));
}
while (size.aboveThan(0)) {
size = size.subtract(8);
ObjectAccess.writeLong(toArray, toOffset.add(size), ObjectAccess.readLong(fromArray, fromOffset.add(size)));
}
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method objectCopyBackwardsUninterruptibly.
@Uninterruptible(reason = "Only the first writeObject has a write-barrier.")
private static void objectCopyBackwardsUninterruptibly(Object fromArray, UnsignedWord fromOffset, Object toArray, UnsignedWord toOffset, UnsignedWord elementSize, UnsignedWord size) {
// Loop-peel the first iteration so I can use BarrieredAccess
// to put a write barrier on the destination.
// TODO: I am explicitly not making the first read have a read barrier.
UnsignedWord remaining = size;
if (remaining.aboveThan(0)) {
remaining = remaining.subtract(elementSize);
BarrieredAccess.writeObject(toArray, toOffset.add(remaining), ObjectAccess.readObject(fromArray, fromOffset.add(remaining)));
while (remaining.aboveThan(0)) {
remaining = remaining.subtract(elementSize);
ObjectAccess.writeObject(toArray, toOffset.add(remaining), ObjectAccess.readObject(fromArray, fromOffset.add(remaining)));
}
}
}
Aggregations