Search in sources :

Example 41 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class JNIFunctions method NewWeakGlobalRef.

/*
     * jweak NewWeakGlobalRef(JNIEnv *env, jobject obj);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle NewWeakGlobalRef(JNIEnvironment env, JNIObjectHandle handle) {
    JNIObjectHandle result = JNIObjectHandles.nullHandle();
    Object obj = JNIObjectHandles.getObject(handle);
    if (obj != null) {
        result = (JNIObjectHandle) JNIGlobalHandles.singleton().createWeak(obj);
    }
    return result;
}
Also used : JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 42 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class JNIFunctions method ThrowNew.

/*
     * jint ThrowNew(JNIEnv *env, jclass clazz, const char *message);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void ThrowNew(JNIEnvironment env, JNIObjectHandle clazzHandle, CCharPointer message) throws Throwable {
    Class<?> clazz = JNIObjectHandles.getObject(clazzHandle);
    JNIMethodId ctor = JNIReflectionDictionary.singleton().getMethodID(clazz, "<init>", "(Ljava/lang/String;)V", false);
    JNIObjectHandle messageHandle = NewStringUTF(env, message);
    NewObjectWithObjectArgFunctionPointer newObject = (NewObjectWithObjectArgFunctionPointer) env.getFunctions().getNewObject();
    JNIObjectHandle exception = newObject.invoke(env, clazzHandle, ctor, messageHandle);
    throw (Throwable) JNIObjectHandles.getObject(exception);
}
Also used : JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId) JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 43 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class JNIFunctions method FatalError.

/*
     * void FatalError(JNIEnv *env, const char *msg);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void FatalError(JNIEnvironment env, CCharPointer message) {
    Log log = Log.log().autoflush(true);
    log.string("Fatal error reported via JNI: ").string(message).newline();
    VMThreads.StatusSupport.setStatusIgnoreSafepoints();
    SubstrateUtil.printDiagnostics(log, KnownIntrinsics.readCallerStackPointer(), KnownIntrinsics.readReturnAddress());
    LogHandler.get().fatalError();
}
Also used : Log(com.oracle.svm.core.log.Log) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 44 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint 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 45 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class JavaMainWrapper method run.

@CEntryPoint
@CEntryPointOptions(prologue = EnterCreateIsolatePrologue.class, include = CEntryPointOptions.NotIncludedAutomatically.class)
public static int run(int paramArgc, CCharPointerPointer paramArgv) throws Exception {
    JavaThreads.singleton().assignJavaThread(preallocatedThread, true);
    JavaMainWrapper.argc = paramArgc;
    JavaMainWrapper.argv = paramArgv;
    Architecture imageArchitecture = ImageSingletons.lookup(TargetDescription.class).arch;
    AMD64CPUFeatureAccess.verifyHostSupportsArchitecture(imageArchitecture);
    String[] args = SubstrateUtil.getArgs(paramArgc, paramArgv);
    if (SubstrateOptions.ParseRuntimeOptions.getValue()) {
        args = RuntimeOptionParser.singleton().parse(args, DEFAULT_OPTION_PREFIX, PLUS_MINUS, true);
        args = RuntimeOptionParser.singleton().parse(args, GRAAL_OPTION_PREFIX, NAME_VALUE, true);
        args = XOptions.singleton().parse(args);
        args = RuntimePropertyParser.parse(args);
    }
    mainArgs = args;
    try {
        final RuntimeSupport rs = RuntimeSupport.getRuntimeSupport();
        if (AllocationSite.Options.AllocationProfiling.getValue()) {
            rs.addShutdownHook(new AllocationSite.AllocationProfilingShutdownHook());
        }
        if (SubstrateOptions.PrintGCSummary.getValue()) {
            rs.addShutdownHook(new PrintGCSummaryShutdownHook());
        }
        try {
            JavaMainSupport.executeStartupHooks();
            ImageSingletons.lookup(JavaMainSupport.class).getJavaMainMethod().invoke(null, (Object) mainArgs);
        } finally {
            // always execute the shutdown hooks
            JavaMainSupport.executeShutdownHooks();
        }
    } catch (Throwable ex) {
        SnippetRuntime.reportUnhandledExceptionJava(ex);
    }
    JavaThreads.singleton().joinAllNonDaemons();
    Counter.logValues();
    return 0;
}
Also used : RuntimeSupport(com.oracle.svm.core.jdk.RuntimeSupport) Architecture(jdk.vm.ci.code.Architecture) TargetDescription(jdk.vm.ci.code.TargetDescription) AllocationSite(com.oracle.svm.core.allocationprofile.AllocationSite) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)81 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)26 Value (org.graalvm.polyglot.Value)23 CEntryPointContext (org.graalvm.nativeimage.c.function.CEntryPointContext)19 Context (org.graalvm.polyglot.Context)19 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)7 ObjectHandle (org.graalvm.nativeimage.ObjectHandle)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)4 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)3 PinnedObject (org.graalvm.nativeimage.PinnedObject)3 Log (com.oracle.svm.core.log.Log)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)2 JNINativeLinkage (com.oracle.svm.jni.access.JNINativeLinkage)2 JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)2 JNINativeMethod (com.oracle.svm.jni.nativeapi.JNINativeMethod)2 Executable (java.lang.reflect.Executable)2 Method (java.lang.reflect.Method)2 ByteBuffer (java.nio.ByteBuffer)2