Search in sources :

Example 26 with CEntryPoint

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

the class JNIFunctions method GetStringRegion.

/*
     * void GetStringRegion(JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void GetStringRegion(JNIEnvironment env, JNIObjectHandle hstr, int start, int len, CShortPointer buf) {
    String str = JNIObjectHandles.getObject(hstr);
    if (start < 0) {
        throw new StringIndexOutOfBoundsException(start);
    }
    if (start + len > str.length()) {
        throw new StringIndexOutOfBoundsException(start + len);
    }
    if (len < 0) {
        throw new StringIndexOutOfBoundsException(len);
    }
    for (int i = 0; i < len; i++) {
        char c = str.charAt(start + i);
        buf.write(i, (short) c);
    }
}
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 27 with CEntryPoint

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

the class JNIFunctions method FromReflectedField.

/*
     * jfieldID FromReflectedField(JNIEnv *env, jobject field);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIFieldId FromReflectedField(JNIEnvironment env, JNIObjectHandle fieldHandle) {
    JNIFieldId fieldId = Word.zero();
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        Field obj = JNIObjectHandles.getObject(fieldHandle);
        if (obj != null) {
            boolean isStatic = Modifier.isStatic(obj.getModifiers());
            fieldId = JNIReflectionDictionary.singleton().getFieldID(obj.getDeclaringClass(), obj.getName());
        }
    }
    return fieldId;
}
Also used : Field(java.lang.reflect.Field) JNIFieldId(com.oracle.svm.jni.nativeapi.JNIFieldId) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 28 with CEntryPoint

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

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

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

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