Search in sources :

Example 21 with CEntryPointOptions

use of com.oracle.svm.core.c.function.CEntryPointOptions 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)

Example 22 with CEntryPointOptions

use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.

the class NativeAPIImpl method releaseAndReturn.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static TruffleObjectHandle releaseAndReturn(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Object object = support.resolveHandle(handle);
    support.destroyGlobalHandle(handle);
    return TruffleNFISupport.createLocalHandle(object);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 23 with CEntryPointOptions

use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.

the class NativeAPIImpl method newObjectRef.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static TruffleObjectHandle newObjectRef(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Object object = support.resolveHandle(handle);
    return support.createGlobalHandle(object);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 24 with CEntryPointOptions

use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.

the class NativeClosure method invokeClosureBufferRet.

@CEntryPoint
@CEntryPointOptions(prologue = EnterClosureDataIsolatePrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void invokeClosureBufferRet(@SuppressWarnings("unused") ffi_cif cif, Pointer ret, WordPointer args, ClosureData user) {
    CIntPointer errnoMirror = ErrnoMirror.getErrnoMirrorLocation();
    errnoMirror.write(Errno.errno());
    try {
        NativeClosure closure = lookup(user);
        ByteBuffer retBuffer = closure.createRetBuffer(ret);
        Target_com_oracle_truffle_nfi_impl_LibFFIClosure_RetPatches patches = (Target_com_oracle_truffle_nfi_impl_LibFFIClosure_RetPatches) closure.call(args, retBuffer);
        if (patches != null) {
            for (int i = 0; i < patches.count; i++) {
                Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag tag = getTag(patches.patches[i]);
                int offset = getOffset(patches.patches[i]);
                Object obj = patches.objects[i];
                if (tag == Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag.OBJECT) {
                    WordBase handle = ImageSingletons.lookup(TruffleNFISupport.class).createGlobalHandle(obj);
                    ret.writeWord(offset, handle);
                } else if (tag == Target_com_oracle_truffle_nfi_impl_NativeArgumentBuffer_TypeTag.STRING) {
                    ret.writeWord(offset, serializeStringRet(obj));
                } else {
                // nothing to do
                }
            }
        }
    } finally {
        Errno.set_errno(errnoMirror.read());
    }
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordBase(org.graalvm.word.WordBase) PinnedObject(org.graalvm.nativeimage.PinnedObject) ByteBuffer(java.nio.ByteBuffer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 25 with CEntryPointOptions

use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.

the class NativeClosure method invokeClosureVoidRet.

@CEntryPoint
@CEntryPointOptions(prologue = EnterClosureDataIsolatePrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void invokeClosureVoidRet(@SuppressWarnings("unused") ffi_cif cif, @SuppressWarnings("unused") WordPointer ret, WordPointer args, ClosureData user) {
    CIntPointer errnoMirror = ErrnoMirror.getErrnoMirrorLocation();
    errnoMirror.write(Errno.errno());
    try {
        lookup(user).call(args, null);
    } finally {
        Errno.set_errno(errnoMirror.read());
    }
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)27 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)26 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)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 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)2 WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AllocationSite (com.oracle.svm.core.allocationprofile.AllocationSite)1 RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1