--- old/src/hotspot/share/prims/jni.cpp 2020-07-23 02:52:55.824936574 -0400 +++ new/src/hotspot/share/prims/jni.cpp 2020-07-23 02:52:54.725923559 -0400 @@ -328,8 +328,7 @@ if (UsePerfData && !class_loader.is_null()) { // check whether the current caller thread holds the lock or not. // If not, increment the corresponding counter - if (ObjectSynchronizer:: - query_lock_ownership((JavaThread*)THREAD, class_loader) != + if (ObjectSynchronizer::query_lock_ownership(thread, class_loader) != ObjectSynchronizer::owner_self) { ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); } @@ -753,7 +752,7 @@ HOTSPOT_JNI_NEWGLOBALREF_ENTRY(env, ref); Handle ref_handle(thread, JNIHandles::resolve(ref)); - jobject ret = JNIHandles::make_global(ref_handle); + jobject ret = JNIHandles::make_global(ref_handle, AllocFailStrategy::RETURN_NULL); HOTSPOT_JNI_NEWGLOBALREF_RETURN(ret); return ret; @@ -797,7 +796,8 @@ HOTSPOT_JNI_NEWLOCALREF_ENTRY(env, ref); - jobject ret = JNIHandles::make_local(THREAD, JNIHandles::resolve(ref)); + jobject ret = JNIHandles::make_local(THREAD, JNIHandles::resolve(ref), + AllocFailStrategy::RETURN_NULL); HOTSPOT_JNI_NEWLOCALREF_RETURN(ret); return ret; @@ -3048,10 +3048,13 @@ JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) JNIWrapper("jni_NewWeakGlobalRef"); - HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(env, ref); + HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(env, ref); Handle ref_handle(thread, JNIHandles::resolve(ref)); - jweak ret = JNIHandles::make_weak_global(ref_handle); - HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(ret); + jweak ret = JNIHandles::make_weak_global(ref_handle, AllocFailStrategy::RETURN_NULL); + if (ret == NULL) { + THROW_OOP_(Universe::out_of_memory_error_c_heap(), NULL); + } + HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(ret); return ret; JNI_END @@ -3127,6 +3130,12 @@ directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); + // Global refs will be NULL if out-of-memory (no exception is pending) + if (bufferClass == NULL || directBufferClass == NULL || directByteBufferClass == NULL) { + directBufferSupportInitializeFailed = 1; + return false; + } + // Get needed field and method IDs directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "", "(JI)V"); if (env->ExceptionCheck()) {