< prev index next >
hotspot/src/share/vm/prims/jniCheck.cpp
Print this page
rev 7377 : 8046668: Excessive checked JNI warnings from Java startup
Summary: Removed pedantic checked exception warnings for AIOOBException, add to current handle capacity
Reviewed-by: hseigel, lfoltan
*** 183,192 ****
--- 183,195 ----
*
* - Some of the JNI array access functions do not return an error code, but may
* 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) {
if (thr->has_pending_exception()) {
NativeReportJNIWarning(thr, "JNI call made with exception pending");
*** 199,208 ****
--- 202,221 ----
)
thr->clear_pending_jni_exception_check(); // Just complain once
}
}
+ /**
+ * 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)
{
check_pending_exception(thr);
*** 241,251 ****
tty->print_cr("WARNING: JNI local refs: %zu, exceeds capacity: %zu",
live_handles, planned_capacity);
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);
}
}
static inline void
checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
--- 254,264 ----
tty->print_cr("WARNING: JNI local refs: %zu, exceeds capacity: %zu",
live_handles, planned_capacity);
thr->print_stack();
)
// Complain just the once, reset to current + warn threshold
! add_planned_handle_capacity(handles, 0);
}
}
static inline void
checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
*** 718,728 ****
functionEnterExceptionAllowed(thr);
if (capacity < 0)
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);
}
functionExit(thr);
return result;
JNI_END
--- 731,741 ----
functionEnterExceptionAllowed(thr);
if (capacity < 0)
NativeReportJNIFatalError(thr, "negative capacity");
jint result = UNCHECKED()->PushLocalFrame(env, capacity);
if (result == JNI_OK) {
! add_planned_handle_capacity(thr->active_handles(), capacity);
}
functionExit(thr);
return result;
JNI_END
*** 822,832 ****
if (capacity < 0) {
NativeReportJNIFatalError(thr, "negative capacity");
}
jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
if (result == JNI_OK) {
! thr->active_handles()->set_planned_capacity(capacity + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
}
functionExit(thr);
return result;
JNI_END
--- 835,845 ----
if (capacity < 0) {
NativeReportJNIFatalError(thr, "negative capacity");
}
jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
if (result == JNI_OK) {
! add_planned_handle_capacity(thr->active_handles(), capacity);
}
functionExit(thr);
return result;
JNI_END
*** 1626,1636 ****
functionEnter(thr);
IN_VM(
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
JNI_ENTRY_CHECKED(void,
--- 1639,1648 ----
*** 1641,1651 ****
functionEnter(thr);
IN_VM(
check_is_obj_array(thr, array);
)
UNCHECKED()->SetObjectArrayElement(env,array,index,val);
- thr->set_pending_jni_exception_check("SetObjectArrayElement");
functionExit(thr);
JNI_END
#define WRAPPER_NewScalarArray(Return, Result) \
JNI_ENTRY_CHECKED(Return, \
--- 1653,1662 ----
*** 1731,1741 ****
functionEnter(thr); \
IN_VM( \
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
WRAPPER_GetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
WRAPPER_GetScalarArrayRegion(T_BYTE, jbyte, Byte)
--- 1742,1751 ----
*** 1756,1766 ****
functionEnter(thr); \
IN_VM( \
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
WRAPPER_SetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
WRAPPER_SetScalarArrayRegion(T_BYTE, jbyte, Byte)
--- 1766,1775 ----
*** 1833,1843 ****
functionEnter(thr);
IN_VM(
checkString(thr, str);
)
UNCHECKED()->GetStringRegion(env, str, start, len, buf);
- thr->set_pending_jni_exception_check("GetStringRegion");
functionExit(thr);
JNI_END
JNI_ENTRY_CHECKED(void,
checked_jni_GetStringUTFRegion(JNIEnv *env,
--- 1842,1851 ----
*** 1848,1858 ****
functionEnter(thr);
IN_VM(
checkString(thr, str);
)
UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
- thr->set_pending_jni_exception_check("GetStringUTFRegion");
functionExit(thr);
JNI_END
JNI_ENTRY_CHECKED(void *,
checked_jni_GetPrimitiveArrayCritical(JNIEnv *env,
--- 1856,1865 ----
< prev index next >