Search in sources :

Example 1 with JNIMethod

use of org.graalvm.jniutils.HotSpotCalls.JNIMethod in project graal by oracle.

the class JNIExceptionWrapper method createExceptionOfSameType.

private static <T extends JObject> T createExceptionOfSameType(JNIEnv env, Throwable original) {
    WordFactory.nullPointer();
    String className = original.getClass().getTypeName();
    JClass exceptionClass = JNIUtil.findClass(env, WordFactory.nullPointer(), getBinaryName(className), false);
    if (exceptionClass.isNonNull()) {
        JNIMethod constructor = JNIMethod.findMethod(env, exceptionClass, false, false, "<init>", encodeMethodSignature(void.class, String.class));
        if (constructor != null) {
            JNI.JValue args = StackValue.get(1, JNI.JValue.class);
            args.addressOf(0).setJObject(createHSString(env, original.getMessage()));
            T res = HotSpotCalls.getDefault().callNewObject(env, exceptionClass, constructor, args);
            return res;
        }
        constructor = JNIMethod.findMethod(env, exceptionClass, false, false, "<init>", encodeMethodSignature(void.class));
        if (constructor != null) {
            T res = HotSpotCalls.getDefault().callNewObject(env, exceptionClass, constructor, WordFactory.nullPointer());
            return res;
        }
    }
    return WordFactory.nullPointer();
}
Also used : JNIMethod(org.graalvm.jniutils.HotSpotCalls.JNIMethod) JClass(org.graalvm.jniutils.JNI.JClass) JString(org.graalvm.jniutils.JNI.JString) JNIUtil.createHSString(org.graalvm.jniutils.JNIUtil.createHSString) CTypeConversion.toCString(org.graalvm.nativeimage.c.type.CTypeConversion.toCString) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString)

Aggregations

JNIMethod (org.graalvm.jniutils.HotSpotCalls.JNIMethod)1 JClass (org.graalvm.jniutils.JNI.JClass)1 JString (org.graalvm.jniutils.JNI.JString)1 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)1 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)1 CTypeConversion.toCString (org.graalvm.nativeimage.c.type.CTypeConversion.toCString)1