Search in sources :

Example 6 with CEntryPointOptions

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

the class JNIFunctions method ToReflectedMethod.

/*
     * jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle ToReflectedMethod(JNIEnvironment env, JNIObjectHandle classHandle, JNIMethodId methodId, boolean isStatic) {
    Executable result = null;
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        JNIAccessibleMethod jniMethod = JNIReflectionDictionary.getMethodByID(methodId);
        JNIAccessibleMethodDescriptor descriptor = JNIReflectionDictionary.getMethodDescriptor(jniMethod);
        if (descriptor != null) {
            Class<?> clazz = jniMethod.getDeclaringClass().getClassObject();
            if (descriptor.isConstructor()) {
                for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
                    if (descriptor.equals(JNIAccessibleMethodDescriptor.of(ctor))) {
                        result = ctor;
                        break;
                    }
                }
            } else {
                for (Method method : clazz.getDeclaredMethods()) {
                    if (descriptor.getName().equals(method.getName())) {
                        if (descriptor.equals(JNIAccessibleMethodDescriptor.of(method))) {
                            result = method;
                            break;
                        }
                    }
                }
            }
        }
    }
    return JNIThreadLocalHandles.get().create(result);
}
Also used : JNIAccessibleMethodDescriptor(com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) Method(java.lang.reflect.Method) JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) Executable(java.lang.reflect.Executable) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 7 with CEntryPointOptions

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

the class JNIFunctions method GetDirectBufferAddress.

@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static WordPointer GetDirectBufferAddress(JNIEnvironment env, JNIObjectHandle handle) {
    WordPointer address = WordFactory.nullPointer();
    Object obj = JNIObjectHandles.getObject(handle);
    if (obj instanceof Target_java_nio_Buffer) {
        Target_java_nio_Buffer buf = (Target_java_nio_Buffer) obj;
        address = Word.pointer(buf.address);
    }
    return address;
}
Also used : WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 8 with CEntryPointOptions

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

the class JNIFunctions method RegisterNatives.

/*
     * jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint
     * nMethods);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINativeMethod methods, int nmethods) {
    Class<?> clazz = JNIObjectHandles.getObject(hclazz);
    Pointer p = (Pointer) methods;
    for (int i = 0; i < nmethods; i++) {
        JNINativeMethod entry = (JNINativeMethod) p;
        String name = CTypeConversion.toJavaString(entry.name());
        String signature = CTypeConversion.toJavaString(entry.signature());
        CFunctionPointer fnPtr = entry.fnPtr();
        String declaringClass = MetaUtil.toInternalName(clazz.getName());
        JNINativeLinkage linkage = JNIReflectionDictionary.singleton().getLinkage(declaringClass, name, signature);
        if (linkage != null) {
            linkage.setEntryPoint(fnPtr);
        } else {
            return JNIErrors.JNI_ERR();
        }
        p = p.add(SizeOf.get(JNINativeMethod.class));
    }
    return JNIErrors.JNI_OK();
}
Also used : JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) CShortPointer(org.graalvm.nativeimage.c.type.CShortPointer) JNIJavaVMPointer(com.oracle.svm.jni.nativeapi.JNIJavaVMPointer) Pointer(org.graalvm.word.Pointer) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JNINativeLinkage(com.oracle.svm.jni.access.JNINativeLinkage) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 9 with CEntryPointOptions

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

the class JNIInvocationInterface method DetachCurrentThread.

/*
     * jint DetachCurrentThread(JavaVM *vm);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIJavaVMEnterAttachThreadPrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int DetachCurrentThread(JNIJavaVM vm) {
    int result = JNIErrors.JNI_OK();
    if (!vm.equal(JNIFunctionTables.singleton().getGlobalJavaVM())) {
        result = JNIErrors.JNI_ERR();
    }
    // JNI specification requires releasing all owned monitors
    Support.releaseCurrentThreadOwnedMonitors();
    return result;
}
Also used : CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 10 with CEntryPointOptions

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

the class NativeAPIImpl method isSameObject.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int isSameObject(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle1, TruffleObjectHandle handle2) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Object object1 = support.resolveHandle(handle1);
    Object object2 = support.resolveHandle(handle2);
    return object1 == object2 ? 1 : 0;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) 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