Search in sources :

Example 26 with Snippet

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));
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.tlabIntArrayMarkWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 27 with Snippet

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);
}
Also used : Word(org.graalvm.compiler.word.Word) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 28 with Snippet

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);
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 29 with Snippet

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;
}
Also used : Word(org.graalvm.compiler.word.Word) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 30 with Snippet

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());
            }
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Aggregations

Snippet (org.graalvm.compiler.api.replacements.Snippet)47 Word (org.graalvm.compiler.word.Word)22 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)17 Pointer (org.graalvm.word.Pointer)14 UnsignedWord (org.graalvm.word.UnsignedWord)12 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)9 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)6 DynamicHub (com.oracle.svm.core.hub.DynamicHub)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 Safepoint (com.oracle.svm.core.thread.Safepoint)2 ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)2 WordBase (org.graalvm.word.WordBase)2 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)1 JavaFrameAnchor (com.oracle.svm.core.stack.JavaFrameAnchor)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)1