This commit is contained in:
David Holmes 2014-07-14 21:48:47 +00:00
commit a36ef5533f
3 changed files with 25 additions and 20 deletions

View File

@ -247,15 +247,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
@ -741,7 +732,8 @@ JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(env, capacity);
//%note jni_11
if (capacity < 0 || capacity > MAX_REASONABLE_LOCAL_CAPACITY) {
if (capacity < 0 ||
((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) {
HOTSPOT_JNI_PUSHLOCALFRAME_RETURN((uint32_t)JNI_ERR);
return JNI_ERR;
}
@ -844,7 +836,8 @@ JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity))
HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(env, capacity);
jint ret;
if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) {
if (capacity >= 0 &&
((MaxJNILocalCapacity <= 0) || (capacity <= MaxJNILocalCapacity))) {
ret = JNI_OK;
} else {
ret = JNI_ERR;

View File

@ -185,6 +185,9 @@ static void NativeReportJNIWarning(JavaThread* thr, const char *msg) {
* throw an ArrayIndexOutOfBoundsException or ArrayStoreException.
*
* In all other cases, a non-error return value guarantees that no exceptions have been thrown.
*
* Programmers often defend against ArrayIndexOutOfBoundsException, so warning
* for these functions would be pedantic.
*/
static inline void
check_pending_exception(JavaThread* thr) {
@ -201,6 +204,16 @@ check_pending_exception(JavaThread* thr) {
}
}
/**
* Add to the planned number of handles. I.e. plus current live & warning threshold
*/
static inline void
add_planned_handle_capacity(JNIHandleBlock* handles, size_t capacity) {
handles->set_planned_capacity(capacity +
handles->get_number_of_live_handles() +
CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
}
static inline void
functionEnterCritical(JavaThread* thr)
@ -243,7 +256,7 @@ functionExit(JavaThread* thr)
thr->print_stack();
)
// Complain just the once, reset to current + warn threshold
handles->set_planned_capacity(live_handles + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
add_planned_handle_capacity(handles, 0);
}
}
@ -720,7 +733,7 @@ JNI_ENTRY_CHECKED(jint,
NativeReportJNIFatalError(thr, "negative capacity");
jint result = UNCHECKED()->PushLocalFrame(env, capacity);
if (result == JNI_OK) {
thr->active_handles()->set_planned_capacity(capacity + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
add_planned_handle_capacity(thr->active_handles(), capacity);
}
functionExit(thr);
return result;
@ -824,7 +837,7 @@ JNI_ENTRY_CHECKED(jint,
}
jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
if (result == JNI_OK) {
thr->active_handles()->set_planned_capacity(capacity + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
add_planned_handle_capacity(thr->active_handles(), capacity);
}
functionExit(thr);
return result;
@ -1628,7 +1641,6 @@ JNI_ENTRY_CHECKED(jobject,
check_is_obj_array(thr, array);
)
jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index);
thr->set_pending_jni_exception_check("GetObjectArrayElement");
functionExit(thr);
return result;
JNI_END
@ -1643,7 +1655,6 @@ JNI_ENTRY_CHECKED(void,
check_is_obj_array(thr, array);
)
UNCHECKED()->SetObjectArrayElement(env,array,index,val);
thr->set_pending_jni_exception_check("SetObjectArrayElement");
functionExit(thr);
JNI_END
@ -1733,7 +1744,6 @@ JNI_ENTRY_CHECKED(void, \
check_primitive_array_type(thr, array, ElementTag); \
) \
UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \
thr->set_pending_jni_exception_check("Get"#Result"ArrayRegion"); \
functionExit(thr); \
JNI_END
@ -1758,7 +1768,6 @@ JNI_ENTRY_CHECKED(void, \
check_primitive_array_type(thr, array, ElementTag); \
) \
UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \
thr->set_pending_jni_exception_check("Set"#Result"ArrayRegion"); \
functionExit(thr); \
JNI_END
@ -1835,7 +1844,6 @@ JNI_ENTRY_CHECKED(void,
checkString(thr, str);
)
UNCHECKED()->GetStringRegion(env, str, start, len, buf);
thr->set_pending_jni_exception_check("GetStringRegion");
functionExit(thr);
JNI_END
@ -1850,7 +1858,6 @@ JNI_ENTRY_CHECKED(void,
checkString(thr, str);
)
UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
thr->set_pending_jni_exception_check("GetStringUTFRegion");
functionExit(thr);
JNI_END

View File

@ -1216,6 +1216,11 @@ class CommandLineFlags {
product(bool, UseFastJNIAccessors, true, \
"Use optimized versions of Get<Primitive>Field") \
\
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 " \