Search in sources :

Example 41 with Word

use of org.graalvm.compiler.word.Word 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 42 with Word

use of org.graalvm.compiler.word.Word 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 43 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class ThreadSubstitutions method isInterrupted.

/**
 * hidden in 9.
 */
@MethodSubstitution(isStatic = false, optional = true)
public static boolean isInterrupted(final Thread thisObject, boolean clearInterrupted) {
    Word javaThread = CurrentJavaThreadNode.get();
    Object thread = javaThread.readObject(threadObjectOffset(INJECTED_VMCONFIG), JAVA_THREAD_THREAD_OBJECT_LOCATION);
    if (thisObject == thread) {
        Word osThread = javaThread.readWord(osThreadOffset(INJECTED_VMCONFIG), JAVA_THREAD_OSTHREAD_LOCATION);
        boolean interrupted = osThread.readInt(osThreadInterruptedOffset(INJECTED_VMCONFIG), any()) != 0;
        if (!interrupted || !clearInterrupted) {
            return interrupted;
        }
    }
    return threadIsInterruptedStub(THREAD_IS_INTERRUPTED, thisObject, clearInterrupted);
}
Also used : Word(org.graalvm.compiler.word.Word) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 44 with Word

use of org.graalvm.compiler.word.Word 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)

Example 45 with Word

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

Aggregations

Word (org.graalvm.compiler.word.Word)53 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)32 Snippet (org.graalvm.compiler.api.replacements.Snippet)22 Pointer (org.graalvm.word.Pointer)12 UnsignedWord (org.graalvm.word.UnsignedWord)7 MethodSubstitution (org.graalvm.compiler.api.replacements.MethodSubstitution)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)5 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 HotSpotReplacementsUtil.loadKlassFromObject (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)2 SignedWord (org.graalvm.word.SignedWord)2 Substitute (com.oracle.svm.core.annotate.Substitute)1 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)1 Pwd.passwd (com.oracle.svm.core.posix.headers.Pwd.passwd)1 Pwd.passwdPointer (com.oracle.svm.core.posix.headers.Pwd.passwdPointer)1 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)1 Isolate (org.graalvm.nativeimage.Isolate)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1