Search in sources :

Example 1 with RestrictHeapAccess

use of com.oracle.svm.core.annotate.RestrictHeapAccess in project graal by oracle.

the class PosixCEntryPointSnippets method detachThreadMT.

@SubstrateForeignCallTarget
@Uninterruptible(reason = "Thread state going away.")
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not (thread-local) allocate while detaching a thread.")
private static int detachThreadMT(IsolateThread thread) {
    int result = Errors.NO_ERROR;
    /*
         * Set thread status to exited. This makes me immune to safepoints (the safepoint mechanism
         * ignores me). Also clear any pending safepoint requests, since I will not honor them.
         */
    VMThreads.StatusSupport.setStatusExited();
    Safepoint.setSafepointRequested(Safepoint.SafepointRequestValues.RESET);
    // try-finally because try-with-resources can call interruptible code
    VMThreads.THREAD_MUTEX.lockNoTransition();
    try {
        detachJavaLangThreadMT(thread);
        // clear references to thread to avoid unintended use
        writeCurrentVMThread(VMThreads.nullThread());
        PosixVMThreads.VMThreadTL.set(VMThreads.nullThread());
        VMThreads.detachThread(thread);
    } catch (Throwable t) {
        result = Errors.UNSPECIFIED;
    } finally {
        VMThreads.THREAD_MUTEX.unlock();
        LibC.free(thread);
    }
    return result;
}
Also used : Safepoint(com.oracle.svm.core.thread.Safepoint) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess)

Example 2 with RestrictHeapAccess

use of com.oracle.svm.core.annotate.RestrictHeapAccess in project graal by oracle.

the class RestrictHeapAccessCalleesFeature method aggregateMethods.

/**
 * Aggregate a set of methods that are annotated with {@link RestrictHeapAccess} or with
 * {@link Uninterruptible}, or methods that are called from those methods.
 */
public void aggregateMethods(Collection<AnalysisMethod> methods) {
    assert !initialized : "RestrictHeapAccessCallees.aggregateMethods: Should only initialize once.";
    final Map<AnalysisMethod, RestrictionInfo> aggregation = new HashMap<>();
    final MethodAggregator visitor = new MethodAggregator(aggregation, assertionErrorConstructorList);
    final AnalysisMethodCalleeWalker walker = new AnalysisMethodCalleeWalker();
    for (AnalysisMethod method : methods) {
        final RestrictHeapAccess annotation = method.getAnnotation(RestrictHeapAccess.class);
        if ((annotation != null && annotation.access() != Access.UNRESTRICTED) || method.isAnnotationPresent(Uninterruptible.class)) {
            for (AnalysisMethod calleeImpl : method.getImplementations()) {
                walker.walkMethod(calleeImpl, visitor);
            }
        }
    }
    calleeToCallerMap = Collections.unmodifiableMap(aggregation);
    initialized = true;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) HashMap(java.util.HashMap) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess)

Example 3 with RestrictHeapAccess

use of com.oracle.svm.core.annotate.RestrictHeapAccess in project graal by oracle.

the class SubstrateSegfaultHandler method dispatch.

@CEntryPoint
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate in segfault signal handler.")
@Uninterruptible(reason = "Must be uninterruptible until it gets immune to safepoints", calleeMustBe = false)
private static void dispatch(int signalNumber, @SuppressWarnings("unused") siginfo_t sigInfo, ucontext_t uContext) {
    if (dispatchInProgress) {
        Log.log().newline().string("[ [ SubstrateSegfaultHandler already handling signal ").signed(signalNumber).string(" ] ]").newline();
        return;
    }
    dispatchInProgress = true;
    VMThreads.StatusSupport.setStatusIgnoreSafepoints();
    Log log = Log.log();
    log.autoflush(true);
    log.string("[ [ SubstrateSegfaultHandler caught signal ").signed(signalNumber).string(" ] ]").newline();
    GregsPointer gregs = uContext.uc_mcontext_gregs();
    long spValue = gregs.read(Signal.GregEnum.REG_RSP.getCValue());
    long ipValue = gregs.read(Signal.GregEnum.REG_RIP.getCValue());
    log.newline().string("General Purpose Register Set Values: ").newline();
    log.indent(true);
    log.string("RAX ").zhex(gregs.read(Signal.GregEnum.REG_RAX.getCValue())).newline();
    log.string("RBX ").zhex(gregs.read(Signal.GregEnum.REG_RBX.getCValue())).newline();
    log.string("RCX ").zhex(gregs.read(Signal.GregEnum.REG_RCX.getCValue())).newline();
    log.string("RDX ").zhex(gregs.read(Signal.GregEnum.REG_RDX.getCValue())).newline();
    log.string("RBP ").zhex(gregs.read(Signal.GregEnum.REG_RBP.getCValue())).newline();
    log.string("RSI ").zhex(gregs.read(Signal.GregEnum.REG_RSI.getCValue())).newline();
    log.string("RDI ").zhex(gregs.read(Signal.GregEnum.REG_RDI.getCValue())).newline();
    log.string("RSP ").zhex(spValue).newline();
    log.string("R8  ").zhex(gregs.read(Signal.GregEnum.REG_R8.getCValue())).newline();
    log.string("R9  ").zhex(gregs.read(Signal.GregEnum.REG_R9.getCValue())).newline();
    log.string("R10 ").zhex(gregs.read(Signal.GregEnum.REG_R10.getCValue())).newline();
    log.string("R11 ").zhex(gregs.read(Signal.GregEnum.REG_R11.getCValue())).newline();
    log.string("R12 ").zhex(gregs.read(Signal.GregEnum.REG_R12.getCValue())).newline();
    log.string("R13 ").zhex(gregs.read(Signal.GregEnum.REG_R13.getCValue())).newline();
    log.string("R14 ").zhex(gregs.read(Signal.GregEnum.REG_R14.getCValue())).newline();
    log.string("R15 ").zhex(gregs.read(Signal.GregEnum.REG_R15.getCValue())).newline();
    log.string("EFL ").zhex(gregs.read(Signal.GregEnum.REG_EFL.getCValue())).newline();
    log.string("RIP ").zhex(ipValue).newline();
    log.indent(false);
    SubstrateUtil.printDiagnostics(log, WordFactory.pointer(spValue), WordFactory.pointer(ipValue));
    log.string("Use runtime option -R:-InstallSegfaultHandler if you don't want to use SubstrateSegfaultHandler.").newline();
    log.newline().string("Bye bye ...").newline().newline();
    LogHandler.get().fatalError();
}
Also used : Log(com.oracle.svm.core.log.Log) GregsPointer(com.oracle.svm.core.posix.headers.Signal.GregsPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess)

Example 4 with RestrictHeapAccess

use of com.oracle.svm.core.annotate.RestrictHeapAccess in project graal by oracle.

the class SubstrateUtil method printDiagnostics.

/**
 * Prints extensive diagnostic information to the given Log.
 */
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate during printing diagnostics.")
public static void printDiagnostics(Log log, Pointer sp, CodePointer ip) {
    if (diagnosticsInProgress) {
        log.string("Error: printDiagnostics already in progress.").newline();
        BreakpointNode.breakpoint();
        return;
    }
    diagnosticsInProgress = true;
    log.newline();
    try {
        dumpJavaFrameAnchors(log);
    } catch (Exception e) {
        dumpException(log, "dumpJavaFrameAnchors", e);
    }
    try {
        dumpDeoptStubPointer(log);
    } catch (Exception e) {
        dumpException(log, "dumpDeoptStubPointer", e);
    }
    try {
        dumpTopFrame(log, sp, ip);
    } catch (Exception e) {
        dumpException(log, "dumpTopFrame", e);
    }
    try {
        dumpVMThreads(log);
    } catch (Exception e) {
        dumpException(log, "dumpVMThreads", e);
    }
    IsolateThread currentThread = CEntryPointContext.getCurrentIsolateThread();
    try {
        dumpVMThreadState(log, currentThread);
    } catch (Exception e) {
        dumpException(log, "dumpVMThreadState", e);
    }
    try {
        dumpRecentVMOperations(log);
    } catch (Exception e) {
        dumpException(log, "dumpRecentVMOperations", e);
    }
    dumpRuntimeCompilation(log);
    try {
        dumpCounters(log);
    } catch (Exception e) {
        dumpException(log, "dumpCounters", e);
    }
    try {
        dumpStacktraceRaw(log, sp);
    } catch (Exception e) {
        dumpException(log, "dumpStacktraceRaw", e);
    }
    try {
        dumpStacktraceStage0(log, sp, ip);
    } catch (Exception e) {
        dumpException(log, "dumpStacktraceStage0", e);
    }
    try {
        dumpStacktraceStage1(log, sp, ip);
    } catch (Exception e) {
        dumpException(log, "dumpStacktraceStage1", e);
    }
    try {
        dumpStacktrace(log, sp, ip);
    } catch (Exception e) {
        dumpException(log, "dumpStacktrace", e);
    }
    if (VMOperationControl.isFrozen()) {
        for (IsolateThread vmThread = VMThreads.firstThread(); vmThread != VMThreads.nullThread(); vmThread = VMThreads.nextThread(vmThread)) {
            if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
                continue;
            }
            try {
                dumpStacktrace(log, vmThread);
            } catch (Exception e) {
                dumpException(log, "dumpStacktrace", e);
            }
        }
    }
    diagnosticsInProgress = false;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess)

Aggregations

RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)3 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 Log (com.oracle.svm.core.log.Log)1 GregsPointer (com.oracle.svm.core.posix.headers.Signal.GregsPointer)1 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)1 Safepoint (com.oracle.svm.core.thread.Safepoint)1 HashMap (java.util.HashMap)1 IsolateThread (org.graalvm.nativeimage.IsolateThread)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1