8046668: Excessive checked JNI warnings from Java startup
authordsimms
Mon, 14 Jul 2014 10:50:20 +0200
changeset 25629 812ae9c40c85
parent 25628 ca4c7cff1573
child 25630 ff281ea14d41
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
hotspot/src/share/vm/prims/jniCheck.cpp
--- a/hotspot/src/share/vm/prims/jniCheck.cpp	Fri Jul 11 13:49:15 2014 -0700
+++ b/hotspot/src/share/vm/prims/jniCheck.cpp	Mon Jul 14 10:50:20 2014 +0200
@@ -185,6 +185,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) {
@@ -201,6 +204,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)
@@ -243,7 +256,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);
   }
 }
 
@@ -720,7 +733,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;
@@ -824,7 +837,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;
@@ -1628,7 +1641,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
@@ -1643,7 +1655,6 @@
       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 @@
       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 @@
       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 @@
       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 @@
       checkString(thr, str);
     )
     UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
-    thr->set_pending_jni_exception_check("GetStringUTFRegion");
     functionExit(thr);
 JNI_END