Search in sources :

Example 51 with Pointer

use of org.graalvm.word.Pointer 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 52 with Pointer

use of org.graalvm.word.Pointer 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 53 with Pointer

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

Example 54 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class JavaStackWalker method doWalk.

@AlwaysInline("avoid virtual call to visitor")
private static boolean doWalk(JavaFrameAnchor lastAnchor, Pointer startSP, CodePointer startIP, StackFrameVisitor visitor) {
    if (!visitor.prologue()) {
        return false;
    }
    if (startSP.isNonNull() && startIP.isNonNull()) {
        JavaFrameAnchor anchor = lastAnchor;
        Pointer sp = startSP;
        CodePointer ip = startIP;
        while (true) {
            while (anchor.isNonNull() && anchor.getLastJavaSP().belowOrEqual(sp)) {
                /* Skip anchors that are in parts of the stack we are not traversing. */
                anchor = anchor.getPreviousAnchor();
            }
            long totalFrameSize;
            DeoptimizedFrame deoptFrame = Deoptimizer.checkDeoptimized(sp);
            if (deoptFrame != null) {
                totalFrameSize = deoptFrame.getSourceTotalFrameSize();
            } else {
                totalFrameSize = CodeInfoTable.lookupTotalFrameSize(ip);
            }
            if (totalFrameSize != -1) {
                /* This is a Java frame, visit it. */
                if (!visitor.visitFrame(sp, ip, deoptFrame)) {
                    return false;
                }
                /* Bump sp *up* over my frame. */
                sp = sp.add(WordFactory.unsigned(totalFrameSize));
                /* Read the return address to my caller. */
                ip = FrameAccess.readReturnAddress(sp);
            } else if (anchor.isNonNull()) {
                /*
                     * At the end of a block of Java frames, but we have more Java frames after a
                     * block of C frames.
                     */
                assert anchor.getLastJavaSP().aboveThan(sp);
                sp = anchor.getLastJavaSP();
                ip = FrameAccess.readReturnAddress(sp);
                anchor = anchor.getPreviousAnchor();
            } else {
                /* Really at the end of the stack, we are done with walking. */
                break;
            }
        }
    } else {
    /*
             * It is fine for a thread to have no Java frames, for example in the case of a native
             * thread that was attached via JNI, but is currently not executing any Java code.
             */
    }
    return visitor.epilogue();
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizedFrame(com.oracle.svm.core.deopt.DeoptimizedFrame) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 55 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class SubstrateInspectedFrame method iterateFrames.

@NeverInline("Stack walking starts at the physical caller frame of this method")
@Override
public <T> T iterateFrames(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip, InspectedFrameVisitor<T> visitor) {
    if (SubstrateUtil.HOSTED) {
        /*
             * During native-image generation we use HotSpotStackIntrospection to iterate frames.
             * `initialMethods` and `matchingMethods` are hosted versions of `ResolvedJavaMethod`
             * that we provide them in `SubstrateTruffleRuntime`.
             */
        StackIntrospection hostedStackIntrospection = JVMCI.getRuntime().getHostJVMCIBackend().getStackIntrospection();
        return hostedStackIntrospection.iterateFrames(initialMethods, matchingMethods, initialSkip, visitor);
    }
    /* Stack walking starts at the physical caller frame of this method. */
    Pointer startSP = KnownIntrinsics.readCallerStackPointer();
    CodePointer startIP = KnownIntrinsics.readReturnAddress();
    PhysicalStackFrameVisitor<T> physicalFrameVisitor = new PhysicalStackFrameVisitor<>(initialMethods, matchingMethods, initialSkip, visitor);
    JavaStackWalker.walkCurrentThread(startSP, startIP, physicalFrameVisitor);
    return physicalFrameVisitor.result;
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) StackIntrospection(jdk.vm.ci.code.stack.StackIntrospection) NeverInline(com.oracle.svm.core.annotate.NeverInline)

Aggregations

Pointer (org.graalvm.word.Pointer)103 UnsignedWord (org.graalvm.word.UnsignedWord)45 Log (com.oracle.svm.core.log.Log)30 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)17 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)15 Snippet (org.graalvm.compiler.api.replacements.Snippet)14 Word (org.graalvm.compiler.word.Word)12 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)9 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)7 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)5 NeverInline (com.oracle.svm.core.annotate.NeverInline)5 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3 SignedWord (org.graalvm.word.SignedWord)3 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2