--- a/hotspot/src/share/vm/prims/jniCheck.cpp Fri Jul 04 11:46:01 2014 +0200
+++ b/hotspot/src/share/vm/prims/jniCheck.cpp Mon Jul 14 10:15:21 2014 -0400
@@ -170,6 +170,9 @@
* 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) {
@@ -186,6 +189,16 @@
}
}
+/**
+ * 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)
@@ -228,7 +241,7 @@
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);
}
}
@@ -705,7 +718,7 @@
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;
@@ -809,7 +822,7 @@
}
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;
@@ -1613,7 +1626,6 @@
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
@@ -1628,7 +1640,6 @@
check_is_obj_array(thr, array);
)
UNCHECKED()->SetObjectArrayElement(env,array,index,val);
- thr->set_pending_jni_exception_check("SetObjectArrayElement");
functionExit(thr);
JNI_END
@@ -1718,7 +1729,6 @@
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
@@ -1743,7 +1753,6 @@
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
@@ -1820,7 +1829,6 @@
checkString(thr, str);
)
UNCHECKED()->GetStringRegion(env, str, start, len, buf);
- thr->set_pending_jni_exception_check("GetStringRegion");
functionExit(thr);
JNI_END
@@ -1835,7 +1843,6 @@
checkString(thr, str);
)
UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
- thr->set_pending_jni_exception_check("GetStringUTFRegion");
functionExit(thr);
JNI_END