< prev index next > test/jdk/java/foreign/enablenativeaccess/panama_module/org/openjdk/foreigntest/libLinkerInvokerModule.cpp
Print this page
typedef struct {
JavaVM* jvm;
jobject linker;
jobject desc;
jobject opts;
+ jthrowable exception;
} Context;
void call(void* arg) {
Context* context = (Context*)arg;
JNIEnv* env;
context->jvm->AttachCurrentThread((void**)&env, NULL);
jclass linkerClass = env->FindClass("java/lang/foreign/Linker");
jmethodID nativeLinkerMethod = env->GetMethodID(linkerClass, "downcallHandle",
"(Ljava/lang/foreign/FunctionDescriptor;[Ljava/lang/foreign/Linker$Option;)Ljava/lang/invoke/MethodHandle;");
env->CallVoidMethod(context->linker, nativeLinkerMethod, context->desc, context->opts);
+ context->exception = (jthrowable) env->NewGlobalRef(env->ExceptionOccurred());
+ env->ExceptionClear();
context->jvm->DetachCurrentThread();
}
extern "C" {
JNIEXPORT void JNICALL
env->GetJavaVM(&context.jvm);
context.linker = env->NewGlobalRef(linker);
context.desc = env->NewGlobalRef(desc);
context.opts = env->NewGlobalRef(opts);
run_in_new_thread_and_join(call, &context);
+ if (context.exception != nullptr) {
+ env->Throw(context.exception); // transfer exception to this thread
+ }
env->DeleteGlobalRef(context.linker);
env->DeleteGlobalRef(context.desc);
env->DeleteGlobalRef(context.opts);
+ env->DeleteGlobalRef(context.exception);
}
}
< prev index next >