diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp index 2ddd9833b648e49ee3d8892bb9783d0539ac77fe..1fe8ab5891b0b667b396a879ae7c6d7804f09a53 100644 --- a/src/share/vm/prims/jni.cpp +++ b/src/share/vm/prims/jni.cpp @@ -292,15 +292,6 @@ void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) { "Bug in native code: jfieldID offset must address interior of object"); } -// Pick a reasonable higher bound for local capacity requested -// for EnsureLocalCapacity and PushLocalFrame. We don't want it too -// high because a test (or very unusual application) may try to allocate -// that many handles and run out of swap space. An implementation is -// permitted to allocate more handles than the ensured capacity, so this -// value is set high enough to prevent compatibility problems. -const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; - - // Wrapper to trace JNI functions #ifdef ASSERT @@ -880,7 +871,8 @@ JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) env, capacity); #endif /* USDT2 */ //%note jni_11 - if (capacity < 0 || capacity > MAX_REASONABLE_LOCAL_CAPACITY) { + if (capacity < 0 || + ((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) { #ifndef USDT2 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); #else /* USDT2 */ @@ -1039,7 +1031,8 @@ JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) env, capacity); #endif /* USDT2 */ jint ret; - if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { + if (capacity >= 0 && + ((MaxJNILocalCapacity <= 0) || (capacity <= MaxJNILocalCapacity))) { ret = JNI_OK; } else { ret = JNI_ERR; diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index 82f61f0ff8c1816cfcf278a738f1dc735a5a50e4..f3ae7528a839f04a8a9f139b1ec70b41fea56ca1 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -1216,6 +1216,11 @@ class CommandLineFlags { product(bool, UseFastJNIAccessors, true, \ "Use optimized versions of GetField") \ \ + product(intx, MaxJNILocalCapacity, 65536, \ + "Maximum allowable local JNI handle capacity to " \ + "EnsureLocalCapacity() and PushLocalFrame(), " \ + "where <= 0 is unlimited, default: 65536") \ + \ product(bool, EagerXrunInit, false, \ "Eagerly initialize -Xrun libraries; allows startup profiling, " \ "but not all -Xrun libraries may support the state of the VM " \