Search in sources :

Example 1 with CEntryPointOptions

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

the class NativeImageGenerator method registerEntryPoints.

private void registerEntryPoints(Map<Method, CEntryPointData> entryPoints) {
    for (Method m : loader.findAnnotatedMethods(CEntryPoint.class)) {
        if (!Modifier.isStatic(m.getModifiers())) {
            throw UserError.abort("entry point method " + m.getDeclaringClass().getName() + "." + m.getName() + " is not static. Add a static modifier to the method.");
        }
        boolean include = true;
        CEntryPointOptions options = m.getAnnotation(CEntryPointOptions.class);
        if (options != null) {
            BooleanSupplier instance;
            try {
                Constructor<? extends BooleanSupplier> constructor = options.include().getDeclaredConstructor();
                constructor.setAccessible(true);
                instance = constructor.newInstance();
            } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                throw VMError.shouldNotReachHere(ex);
            }
            include = instance.getAsBoolean();
        }
        if (include) {
            entryPoints.put(m, CEntryPointData.create(m));
        }
    }
}
Also used : CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Method(java.lang.reflect.Method) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) BooleanSupplier(java.util.function.BooleanSupplier) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with CEntryPointOptions

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

the class JNIFunctions method UnregisterNatives.

/*
     * jint UnregisterNatives(JNIEnv *env, jclass clazz);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int UnregisterNatives(JNIEnvironment env, JNIObjectHandle hclazz) {
    Class<?> clazz = JNIObjectHandles.getObject(hclazz);
    String internalName = MetaUtil.toInternalName(clazz.getName());
    for (JNINativeLinkage linkage : JNIReflectionDictionary.singleton().getLinkages(internalName)) {
        linkage.unsetEntryPoint();
    }
    return JNIErrors.JNI_OK();
}
Also used : JNINativeLinkage(com.oracle.svm.jni.access.JNINativeLinkage) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 3 with CEntryPointOptions

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

the class JNIFunctions method GetStringUTFRegion.

/*
     * void GetStringUTFRegion(JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void GetStringUTFRegion(JNIEnvironment env, JNIObjectHandle hstr, int start, int len, CCharPointer 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);
    }
    // estimate: caller must pre-allocate
    int capacity = Utf8.maxUtf8ByteLength(len, true);
    // enough
    ByteBuffer buffer = SubstrateUtil.wrapAsByteBuffer(buf, capacity);
    Utf8.substringToUtf8(buffer, str, start, start + len, true);
}
Also used : 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 4 with CEntryPointOptions

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

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

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