< 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,10 +183,13 @@
  *
  * - 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,10 +202,20 @@
     )
     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,11 +254,11 @@
       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);
+    add_planned_handle_capacity(handles, 0);
   }
 }
 
 static inline void
 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)

@@ -718,11 +731,11 @@
     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);
+      add_planned_handle_capacity(thr->active_handles(), capacity);
     }
     functionExit(thr);
     return result;
 JNI_END
 

@@ -822,11 +835,11 @@
     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);
+      add_planned_handle_capacity(thr->active_handles(), capacity);
     }
     functionExit(thr);
     return result;
 JNI_END
 

@@ -1626,11 +1639,10 @@
     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,

@@ -1641,11 +1653,10 @@
     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, \

@@ -1731,11 +1742,10 @@
     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)

@@ -1756,11 +1766,10 @@
     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)

@@ -1833,11 +1842,10 @@
     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,

@@ -1848,11 +1856,10 @@
     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,
< prev index next >