use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class NewInstanceStub method newInstance.
/**
* Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to
* -XX:-UseTLAB).
*
* @param hub the hub of the object to be allocated
* @param intArrayHub the hub for {@code int[].class}
*/
@Snippet
private static Object newInstance(KlassPointer hub, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister, @ConstantParameter OptionValues options) {
/*
* The type is known to be an instance so Klass::_layout_helper is the instance size as a
* raw number
*/
Word thread = registerAsWord(threadRegister);
boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported();
if (!forceSlowPath(options) && inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG)) {
if (isInstanceKlassFullyInitialized(hub)) {
int sizeInBytes = readLayoutHelper(hub);
Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
if (memory.notEqual(0)) {
Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(INJECTED_VMCONFIG), PROTOTYPE_MARK_WORD_LOCATION);
NewObjectSnippets.formatObjectForStub(hub, sizeInBytes, memory, prototypeMarkWord);
return verifyObject(memory.toObject());
}
}
}
if (logging(options)) {
printf("newInstance: calling new_instance_c\n");
}
newInstanceC(NEW_INSTANCE_C, thread, hub);
handlePendingException(thread, true);
return verifyObject(getAndClearObjectResult(thread));
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class OutOfBoundsExceptionStub method createOutOfBoundsException.
@Snippet
private static Object createOutOfBoundsException(int idx, @ConstantParameter Register threadRegister, @ConstantParameter int bufferSizeInWords) {
Word buffer = AllocaNode.alloca(bufferSizeInWords);
long number = idx;
if (number < 0) {
number = -number;
}
Word ptr = buffer.add(MAX_INT_STRING_SIZE);
ptr.writeByte(0, (byte) 0);
do {
long digit = number % 10;
number /= 10;
ptr = ptr.subtract(1);
ptr.writeByte(0, (byte) ('0' + digit));
} while (number > 0);
if (idx < 0) {
ptr = ptr.subtract(1);
ptr.writeByte(0, (byte) '-');
}
return createException(threadRegister, ArrayIndexOutOfBoundsException.class, ptr);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class UnwindExceptionToCallerStub method unwindExceptionToCaller.
@Snippet
private static void unwindExceptionToCaller(Object exception, Word returnAddress, @ConstantParameter Register threadRegister, @ConstantParameter OptionValues options) {
Pointer exceptionOop = Word.objectToTrackedPointer(exception);
if (logging(options)) {
printf("unwinding exception %p (", exceptionOop.rawValue());
decipher(exceptionOop.rawValue());
printf(") at %p (", returnAddress.rawValue());
decipher(returnAddress.rawValue());
printf(")\n");
}
Word thread = registerAsWord(threadRegister);
checkNoExceptionInThread(thread, assertionsEnabled(INJECTED_VMCONFIG));
checkExceptionNotNull(assertionsEnabled(INJECTED_VMCONFIG), exception);
Word handlerInCallerPc = exceptionHandlerForReturnAddress(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, thread, returnAddress);
if (logging(options)) {
printf("handler for exception %p at return address %p is at %p (", exceptionOop.rawValue(), returnAddress.rawValue(), handlerInCallerPc.rawValue());
decipher(handlerInCallerPc.rawValue());
printf(")\n");
}
jumpToExceptionHandlerInCaller(handlerInCallerPc, exception, returnAddress);
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class StringToBytesSnippets method transform.
@Snippet
public static byte[] transform(@ConstantParameter String compilationTimeString) {
int i = compilationTimeString.length();
byte[] array = (byte[]) NewArrayNode.newUninitializedArray(byte.class, i);
Word cArray = CStringConstant.cstring(compilationTimeString);
while (i-- > 0) {
// array[i] = cArray.readByte(i);
UNSAFE.putByte(array, arrayBaseOffset() + i, cArray.readByte(i, CSTRING_LOCATION));
}
return array;
}
use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.
the class WriteBarrierSnippets method g1ArrayRangePreWriteBarrier.
@Snippet
public static void g1ArrayRangePreWriteBarrier(Address address, int length, @ConstantParameter int elementStride, @ConstantParameter Register threadRegister) {
Word thread = registerAsWord(threadRegister);
byte markingValue = thread.readByte(g1SATBQueueMarkingOffset(INJECTED_VMCONFIG));
// If the concurrent marker is not enabled or the vector length is zero, return.
if (markingValue == (byte) 0 || length == 0) {
return;
}
Word bufferAddress = thread.readWord(g1SATBQueueBufferOffset(INJECTED_VMCONFIG));
Word indexAddress = thread.add(g1SATBQueueIndexOffset(INJECTED_VMCONFIG));
long indexValue = indexAddress.readWord(0).rawValue();
final int scale = arrayIndexScale(JavaKind.Object);
long start = getPointerToFirstArrayElement(address, length, elementStride);
for (int i = 0; i < length; i++) {
Word arrElemPtr = WordFactory.pointer(start + i * scale);
Pointer oop = Word.objectToTrackedPointer(arrElemPtr.readObject(0, BarrierType.NONE));
verifyOop(oop.toObject());
if (oop.notEqual(0)) {
if (indexValue != 0) {
indexValue = indexValue - wordSize();
Word logAddress = bufferAddress.add(WordFactory.unsigned(indexValue));
// Log the object to be marked as well as update the SATB's buffer next index.
logAddress.writeWord(0, oop, GC_LOG_LOCATION);
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), GC_INDEX_LOCATION);
} else {
g1PreBarrierStub(G1WBPRECALL, oop.toObject());
}
}
}
}
Aggregations