RFR (XS) 8189766: whitebox failure with -Xcheck:jni

David Holmes david.holmes at oracle.com
Tue May 29 07:06:15 UTC 2018


bug: https://bugs.openjdk.java.net/browse/JDK-8189766
webrev: http://cr.openjdk.java.net/~dholmes/8189766/webrev/

A WB_ENTRY already handles the pending JNI exception check by explicitly 
clearing it via a helper:

#define WB_ENTRY(result_type, header) JNI_ENTRY(result_type, header) \
   ClearPendingJniExcCheck _clearCheck(env);

#define WB_END JNI_END

But the whitebox function then does e.g:

WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
   bool result;
   if (GetVMFlag <bool> (thread, env, name, &result, &JVMFlag::boolAt)) {
     ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
     return booleanBox(thread, env, result);
   }
   return NULL;
WB_END

where booleanBox is defined eventually as:

template <typename T>
static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, 
Symbol* sig, T value) {
   ResourceMark rm(thread);
   jclass clazz = env->FindClass(name->as_C_string());
   CHECK_JNI_EXCEPTION_(env, NULL);
   jmethodID methodID = env->GetStaticMethodID(clazz,
         vmSymbols::valueOf_name()->as_C_string(),
         sig->as_C_string());
   CHECK_JNI_EXCEPTION_(env, NULL);
   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
   CHECK_JNI_EXCEPTION_(env, NULL);
   return result;
}

so we call JNI methods that will set the pending_jni_exception_check 
flag, but CHECK_JNI_EXCEPTION is defined as:

#define CHECK_JNI_EXCEPTION_(env, value) \
   do { \
     JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \
     if (HAS_PENDING_EXCEPTION) { \
       return(value); \
     } \
   } while (0)

which means it is not clearing the pending_jni_exception_check flag even 
though it is checking for exceptions!

So we explicitly clear the flag. Trying to use the JNI ExceptionOccurred 
function fails as not all the methods that call CHECK_JNI_EXCEPTION are 
_thread_in_native.

Testing (in progress):
          hotspot tier1 and tier2 with -Xcheck:jni
          regular CI testing

Thanks,
David


More information about the hotspot-dev mailing list