Skip to content

Commit

Permalink
Call VMRuntime.shutdown() after closing the context.
Browse files Browse the repository at this point in the history
Should run Java exit hooks.
  • Loading branch information
ansalond committed Aug 26, 2022
1 parent 5627ec6 commit ac8017b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ static int closeContext(@SuppressWarnings("unused") IsolateThread thread, JNIJav
return JNIErrors.JNI_OK();
}

@CEntryPoint(name = "Espresso_Shutdown")
static int shutdown(@SuppressWarnings("unused") IsolateThread thread) {
VMRuntime.shutdown();
return JNIErrors.JNI_OK();
}

@CEntryPoint(name = "Espresso_Exit")
static void exit(@SuppressWarnings("unused") IsolateThread thread, JNIJavaVM javaVM) {
ObjectHandle contextHandle = javaVM.getFunctions().getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ typedef int (*Espresso_ReleaseContext_fn_t)(graal_isolatethread_t* thread, struc

typedef int (*Espresso_CloseContext_fn_t)(graal_isolatethread_t* thread, struct JavaVM_* javaVM);

typedef int (*Espresso_Shutdown_fn_t)(graal_isolatethread_t* thread);

typedef void (*Espresso_Exit_fn_t)(graal_isolatethread_t* thread, struct JavaVM_* javaVM);

#if defined(__cplusplus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ typedef struct LibJavaVM {
Espresso_LeaveContext_fn_t Espresso_LeaveContext; // leave
Espresso_ReleaseContext_fn_t Espresso_ReleaseContext; // release
Espresso_CloseContext_fn_t Espresso_CloseContext; // release + leave + close
Espresso_Shutdown_fn_t Espresso_Shutdown; // shutdown
Espresso_Exit_fn_t Espresso_Exit; // leave + close + exit
} LibJavaVM;

Expand Down
17 changes: 8 additions & 9 deletions espresso/src/com.oracle.truffle.espresso.mokapot/src/mokapot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ LibJavaVM *load_libjavavm(const char* lib_path) {
BIND_LIBJAVAVM(Espresso_LeaveContext)
BIND_LIBJAVAVM(Espresso_ReleaseContext)
BIND_LIBJAVAVM(Espresso_CloseContext)
BIND_LIBJAVAVM(Espresso_Shutdown)
BIND_LIBJAVAVM(Espresso_Exit)

#undef BIND_LIBJAVAVM_SVM_API
Expand All @@ -1699,6 +1700,7 @@ LibJavaVM *load_libjavavm(const char* lib_path) {
result->Espresso_LeaveContext = Espresso_LeaveContext;
result->Espresso_ReleaseContext = Espresso_ReleaseContext;
result->Espresso_CloseContext = Espresso_CloseContext;
result->Espresso_Shutdown = Espresso_Shutdown;
result->Espresso_Exit = Espresso_Exit;
return result;
}
Expand Down Expand Up @@ -1778,24 +1780,21 @@ jint DestroyJavaVM(JavaVM *vm) {
}
jint result = (*espressoJavaVM)->DestroyJavaVM(espressoJavaVM);
remove_java_vm(vm);
jint result2;
if (espressoIsolate->is_sun_standard_launcher == JNI_TRUE) {
libjavavm->Espresso_Exit(thread, (struct JavaVM_ *) espressoJavaVM);
fprintf(stderr, "Error: Espresso_Exit didn't exit");
result2 = JNI_ERR;
} else {
result2 = libjavavm->Espresso_CloseContext(thread, (struct JavaVM_ *) espressoJavaVM);
}
jint result2 = libjavavm->Espresso_CloseContext(thread, (struct JavaVM_ *) espressoJavaVM);
if (result == JNI_OK && result2 != JNI_OK) {
result = result2;
}
result2 = libjavavm->detach_thread(thread);
result2 = libjavavm->Espresso_Shutdown(thread);
if (result == JNI_OK && result2 != JNI_OK) {
result = result2;
}
if (libjavavm->tear_down_isolate(thread) != 0 && result == JNI_OK) {
result = JNI_ERR;
}
result2 = libjavavm->detach_thread(thread);
if (result == JNI_OK && result2 != JNI_OK) {
result = result2;
}
free(espressoIsolate);
return result;
}
Expand Down

0 comments on commit ac8017b

Please sign in to comment.