Search in sources :

Example 96 with Pointer

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

the class HeapChunkProvider method zap.

/**
 * Write the given value over all the Object memory in the chunk.
 */
private static void zap(Header<?> chunk, WordBase value) {
    Pointer start = chunk.getTop();
    Pointer limit = chunk.getEnd();
    log().string("  zap chunk: ").hex(chunk).string("  start: ").hex(start).string("  limit: ").hex(limit).string("  value: ").hex(value).newline();
    for (Pointer p = start; p.belowThan(limit); p = p.add(FrameAccess.wordSize())) {
        p.writeWord(0, value);
    }
}
Also used : Pointer(org.graalvm.word.Pointer)

Example 97 with Pointer

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

the class Deoptimizer method deoptimizeInRangeOperation.

/**
 * Deoptimize a specific method on all thread stacks.
 */
private static void deoptimizeInRangeOperation(CodePointer fromIp, CodePointer toIp, boolean deoptAll) {
    VMOperation.guaranteeInProgress("Deoptimizer.deoptimizeInRangeOperation, but not in VMOperation.");
    /* Handle my own thread specially, because I do not have a JavaFrameAnchor. */
    StackFrameVisitor currentThreadDeoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, CEntryPointContext.getCurrentIsolateThread());
    Pointer sp = KnownIntrinsics.readCallerStackPointer();
    CodePointer ip = KnownIntrinsics.readReturnAddress();
    JavaStackWalker.walkCurrentThread(sp, ip, currentThreadDeoptVisitor);
    /* If I am multi-threaded, deoptimize this method on all the other stacks. */
    if (SubstrateOptions.MultiThreaded.getValue()) {
        for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
            if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
                continue;
            }
            StackFrameVisitor deoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, vmThread);
            JavaStackWalker.walkThread(vmThread, deoptVisitor);
        }
    }
    if (testGCinDeoptimizer) {
        Heap.getHeap().getGC().collect("from Deoptimizer.deoptimizeInRange because of testGCinDeoptimizer");
    }
}
Also used : StackFrameVisitor(com.oracle.svm.core.stack.StackFrameVisitor) IsolateThread(org.graalvm.nativeimage.IsolateThread) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer)

Example 98 with Pointer

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

the class Deoptimizer method rewriteStackAndJumpToTarget.

/**
 * Performs the actual stack rewriting. When this method is called the sp is already at the
 * bottom of the deopt target method.
 *
 * @param newSp Points to the bottom of the deopt target method (but above the return address
 *            slot).
 * @param frame The deopt frame handle.
 * @return The epilog of this method restores the return value registers from the returned frame
 *         handle. The instructions for restoring the return value registers must be generated
 *         in this method's epilog by a backend-specific FrameContext class.
 */
@DeoptStub(stubType = StubType.ExitStub)
@NeverInline("don't provoke the writeStackPointer devil with a non-trivial method")
@Uninterruptible(reason = "Frame holds Objects in unmanaged storage.")
private static DeoptimizedFrame rewriteStackAndJumpToTarget(Pointer newSp, DeoptimizedFrame frame) {
    /*
         * The first word of the new stack content is already the return address into the caller of
         * deoptimizeInRange(). So when this method returns we are inside the caller of
         * deoptimizeInRange().
         */
    Pointer bottomSp = newSp.subtract(FrameAccess.returnAddressSize());
    frame.getTargetContent().copyToPointer(bottomSp);
    if (DeoptimizationCounters.Options.ProfileDeoptimization.getValue()) {
        DeoptimizationCounters.counters().timeSpentInDeopt.add(System.nanoTime() - DeoptimizationCounters.startTime.get());
    }
    return frame;
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) NeverInline(com.oracle.svm.core.annotate.NeverInline)

Example 99 with Pointer

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

the class Deoptimizer method deoptStub.

/**
 * Performs the second step of deoptimization: the actual rewriting of a deoptimized method's
 * frame.
 * <p>
 * The pointer to the deopt stub code was installed in the return address slot by
 * {@link #deoptimizeInRange}. Therefore the stub is "called" when a method wants to return to a
 * deoptimized method.
 * <p>
 * When {@link #deoptStub} is "called", the stack looks like this:
 *
 * <pre>
 *    :                                :
 *    |                                |
 *    |                                |   frame of the
 *    +--------------------------------+   deoptimized method
 *    | pointer to DeoptimizedFrame    |
 *    +--------------------------------+--------- no return address between the frames!
 *    |                                |
 *    |                                |   frame of
 *    |                                |   {@link #deoptStub}
 *    :     ...                        :
 * </pre>
 *
 * @param frame This is the handle which was created in {@link #deoptimizeInRange}. It is
 *            fetched from the stack (the slot above the original return address) and passed as
 *            parameter. The instructions for fetching the frame handle must be generated in
 *            this method's prolog by a backend-specific FrameContext class. The prolog also
 *            stores the original return value registers in the {@code frame}.
 */
@DeoptStub(stubType = StubType.EntryStub)
@Uninterruptible(reason = "Frame holds Objects in unmanaged storage.")
public static void deoptStub(DeoptimizedFrame frame) {
    DeoptimizationCounters.counters().deoptCount.inc();
    if (DeoptimizationCounters.Options.ProfileDeoptimization.getValue()) {
        DeoptimizationCounters.startTime.set(System.nanoTime());
    }
    /* Build the content of the deopt target stack frames. */
    frame.buildContent();
    /*
         * The frame was pinned to keep it from moving during construction. I can unpin it now that
         * I am uninterruptible. (And I have to unpin it.)
         */
    frame.getPin().close();
    recentDeoptimizationEvents.append(frame.getCompletedMessage());
    Pointer sp = KnownIntrinsics.readStackPointer();
    /* Do the stack rewriting. Return directly to the deopt target. */
    final Pointer newSp = sp.add(WordFactory.unsigned(deoptStubFrameSize)).add(WordFactory.unsigned(frame.getSourceTotalFrameSize()).subtract(frame.getTargetContent().getSize()).subtract(FrameAccess.returnAddressSize()));
    rewriteStackStub(newSp, frame);
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 100 with Pointer

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

the class InteriorObjRefWalker method walkObjectInline.

@AlwaysInline("Performance critical version")
public static boolean walkObjectInline(final Object obj, final ObjectReferenceVisitor visitor) {
    final DynamicHub objHub = ObjectHeader.readDynamicHubFromObject(obj);
    final int layoutEncoding = objHub.getLayoutEncoding();
    final Pointer objPointer = Word.objectToUntrackedPointer(obj);
    // Visit each Object reference in the array part of the Object.
    if (LayoutEncoding.isObjectArray(layoutEncoding)) {
        int length = KnownIntrinsics.readArrayLength(obj);
        for (int index = 0; index < length; index++) {
            final UnsignedWord elementOffset = LayoutEncoding.getArrayElementOffset(layoutEncoding, index);
            final Pointer elementPointer = objPointer.add(elementOffset);
            boolean isCompressed = ReferenceAccess.singleton().haveCompressedReferences();
            final boolean visitResult = visitor.visitObjectReferenceInline(elementPointer, isCompressed);
            if (!visitResult) {
                return false;
            }
        }
    }
    // Visit Object reference in the fields of the Object.
    byte[] referenceMapEncoding = DynamicHubSupport.getReferenceMapEncoding();
    long referenceMapIndex = objHub.getReferenceMapIndex();
    return ReferenceMapDecoder.walkOffsetsFromPointer(objPointer, referenceMapEncoding, referenceMapIndex, visitor);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

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