HDFS-15270. Account for *env == NULL in hdfsThreadDestructor (#1951)

OpenJ9 JVM properly terminates the thread before hdfsThreadDestructor is
invoked. JNIEnv is a mirror of J9VMThread in OpenJ9. After proper thread
termination, accessing JNIEnv in hdfsThreadDestructor (*env)->GetJavaVM,
yields a SIGSEGV since *env is NULL after thread cleanup is performed.

The main purpose of hdfsThreadDestructor is to invoke
DetachCurrentThread, which performs thread cleanup in OpenJ9. Since
OpenJ9 performs thread cleanup before hdfsThreadDestructor is invoked,
hdfsThreadDestructor should account for *env == NULL and skip
DetachCurrentThread.

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
This commit is contained in:
Babneet Singh 2020-05-04 16:08:53 -04:00 committed by GitHub
parent ebb878bab9
commit 1996351b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -53,7 +53,7 @@ void hdfsThreadDestructor(void *v)
char thr_name[MAXTHRID]; char thr_name[MAXTHRID];
/* Detach the current thread from the JVM */ /* Detach the current thread from the JVM */
if (env) { if ((env != NULL) && (*env != NULL)) {
ret = (*env)->GetJavaVM(env, &vm); ret = (*env)->GetJavaVM(env, &vm);
if (ret != 0) { if (ret != 0) {

View File

@ -46,10 +46,10 @@ static void detachCurrentThreadFromJvm()
if (threadLocalStorageGet(&state) || !state) { if (threadLocalStorageGet(&state) || !state) {
return; return;
} }
if (!state->env) { env = state->env;
if ((env == NULL) || (*env == NULL)) {
return; return;
} }
env = state->env;
ret = (*env)->GetJavaVM(env, &vm); ret = (*env)->GetJavaVM(env, &vm);
if (ret) { if (ret) {
fprintf(stderr, fprintf(stderr,