equal
deleted
inserted
replaced
183 * |
183 * |
184 * - Some of the JNI array access functions do not return an error code, but may |
184 * - Some of the JNI array access functions do not return an error code, but may |
185 * throw an ArrayIndexOutOfBoundsException or ArrayStoreException. |
185 * throw an ArrayIndexOutOfBoundsException or ArrayStoreException. |
186 * |
186 * |
187 * In all other cases, a non-error return value guarantees that no exceptions have been thrown. |
187 * In all other cases, a non-error return value guarantees that no exceptions have been thrown. |
|
188 * |
|
189 * Programmers often defend against ArrayIndexOutOfBoundsException, so warning |
|
190 * for these functions would be pedantic. |
188 */ |
191 */ |
189 static inline void |
192 static inline void |
190 check_pending_exception(JavaThread* thr) { |
193 check_pending_exception(JavaThread* thr) { |
191 if (thr->has_pending_exception()) { |
194 if (thr->has_pending_exception()) { |
192 NativeReportJNIWarning(thr, "JNI call made with exception pending"); |
195 NativeReportJNIWarning(thr, "JNI call made with exception pending"); |
197 thr->get_pending_jni_exception_check()); |
200 thr->get_pending_jni_exception_check()); |
198 thr->print_stack(); |
201 thr->print_stack(); |
199 ) |
202 ) |
200 thr->clear_pending_jni_exception_check(); // Just complain once |
203 thr->clear_pending_jni_exception_check(); // Just complain once |
201 } |
204 } |
|
205 } |
|
206 |
|
207 /** |
|
208 * Add to the planned number of handles. I.e. plus current live & warning threshold |
|
209 */ |
|
210 static inline void |
|
211 add_planned_handle_capacity(JNIHandleBlock* handles, size_t capacity) { |
|
212 handles->set_planned_capacity(capacity + |
|
213 handles->get_number_of_live_handles() + |
|
214 CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD); |
202 } |
215 } |
203 |
216 |
204 |
217 |
205 static inline void |
218 static inline void |
206 functionEnterCritical(JavaThread* thr) |
219 functionEnterCritical(JavaThread* thr) |
241 tty->print_cr("WARNING: JNI local refs: %zu, exceeds capacity: %zu", |
254 tty->print_cr("WARNING: JNI local refs: %zu, exceeds capacity: %zu", |
242 live_handles, planned_capacity); |
255 live_handles, planned_capacity); |
243 thr->print_stack(); |
256 thr->print_stack(); |
244 ) |
257 ) |
245 // Complain just the once, reset to current + warn threshold |
258 // Complain just the once, reset to current + warn threshold |
246 handles->set_planned_capacity(live_handles + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD); |
259 add_planned_handle_capacity(handles, 0); |
247 } |
260 } |
248 } |
261 } |
249 |
262 |
250 static inline void |
263 static inline void |
251 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype) |
264 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype) |
718 functionEnterExceptionAllowed(thr); |
731 functionEnterExceptionAllowed(thr); |
719 if (capacity < 0) |
732 if (capacity < 0) |
720 NativeReportJNIFatalError(thr, "negative capacity"); |
733 NativeReportJNIFatalError(thr, "negative capacity"); |
721 jint result = UNCHECKED()->PushLocalFrame(env, capacity); |
734 jint result = UNCHECKED()->PushLocalFrame(env, capacity); |
722 if (result == JNI_OK) { |
735 if (result == JNI_OK) { |
723 thr->active_handles()->set_planned_capacity(capacity + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD); |
736 add_planned_handle_capacity(thr->active_handles(), capacity); |
724 } |
737 } |
725 functionExit(thr); |
738 functionExit(thr); |
726 return result; |
739 return result; |
727 JNI_END |
740 JNI_END |
728 |
741 |
822 if (capacity < 0) { |
835 if (capacity < 0) { |
823 NativeReportJNIFatalError(thr, "negative capacity"); |
836 NativeReportJNIFatalError(thr, "negative capacity"); |
824 } |
837 } |
825 jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity); |
838 jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity); |
826 if (result == JNI_OK) { |
839 if (result == JNI_OK) { |
827 thr->active_handles()->set_planned_capacity(capacity + CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD); |
840 add_planned_handle_capacity(thr->active_handles(), capacity); |
828 } |
841 } |
829 functionExit(thr); |
842 functionExit(thr); |
830 return result; |
843 return result; |
831 JNI_END |
844 JNI_END |
832 |
845 |
1626 functionEnter(thr); |
1639 functionEnter(thr); |
1627 IN_VM( |
1640 IN_VM( |
1628 check_is_obj_array(thr, array); |
1641 check_is_obj_array(thr, array); |
1629 ) |
1642 ) |
1630 jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index); |
1643 jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index); |
1631 thr->set_pending_jni_exception_check("GetObjectArrayElement"); |
|
1632 functionExit(thr); |
1644 functionExit(thr); |
1633 return result; |
1645 return result; |
1634 JNI_END |
1646 JNI_END |
1635 |
1647 |
1636 JNI_ENTRY_CHECKED(void, |
1648 JNI_ENTRY_CHECKED(void, |
1641 functionEnter(thr); |
1653 functionEnter(thr); |
1642 IN_VM( |
1654 IN_VM( |
1643 check_is_obj_array(thr, array); |
1655 check_is_obj_array(thr, array); |
1644 ) |
1656 ) |
1645 UNCHECKED()->SetObjectArrayElement(env,array,index,val); |
1657 UNCHECKED()->SetObjectArrayElement(env,array,index,val); |
1646 thr->set_pending_jni_exception_check("SetObjectArrayElement"); |
|
1647 functionExit(thr); |
1658 functionExit(thr); |
1648 JNI_END |
1659 JNI_END |
1649 |
1660 |
1650 #define WRAPPER_NewScalarArray(Return, Result) \ |
1661 #define WRAPPER_NewScalarArray(Return, Result) \ |
1651 JNI_ENTRY_CHECKED(Return, \ |
1662 JNI_ENTRY_CHECKED(Return, \ |
1731 functionEnter(thr); \ |
1742 functionEnter(thr); \ |
1732 IN_VM( \ |
1743 IN_VM( \ |
1733 check_primitive_array_type(thr, array, ElementTag); \ |
1744 check_primitive_array_type(thr, array, ElementTag); \ |
1734 ) \ |
1745 ) \ |
1735 UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \ |
1746 UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \ |
1736 thr->set_pending_jni_exception_check("Get"#Result"ArrayRegion"); \ |
|
1737 functionExit(thr); \ |
1747 functionExit(thr); \ |
1738 JNI_END |
1748 JNI_END |
1739 |
1749 |
1740 WRAPPER_GetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean) |
1750 WRAPPER_GetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean) |
1741 WRAPPER_GetScalarArrayRegion(T_BYTE, jbyte, Byte) |
1751 WRAPPER_GetScalarArrayRegion(T_BYTE, jbyte, Byte) |
1756 functionEnter(thr); \ |
1766 functionEnter(thr); \ |
1757 IN_VM( \ |
1767 IN_VM( \ |
1758 check_primitive_array_type(thr, array, ElementTag); \ |
1768 check_primitive_array_type(thr, array, ElementTag); \ |
1759 ) \ |
1769 ) \ |
1760 UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \ |
1770 UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \ |
1761 thr->set_pending_jni_exception_check("Set"#Result"ArrayRegion"); \ |
|
1762 functionExit(thr); \ |
1771 functionExit(thr); \ |
1763 JNI_END |
1772 JNI_END |
1764 |
1773 |
1765 WRAPPER_SetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean) |
1774 WRAPPER_SetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean) |
1766 WRAPPER_SetScalarArrayRegion(T_BYTE, jbyte, Byte) |
1775 WRAPPER_SetScalarArrayRegion(T_BYTE, jbyte, Byte) |
1833 functionEnter(thr); |
1842 functionEnter(thr); |
1834 IN_VM( |
1843 IN_VM( |
1835 checkString(thr, str); |
1844 checkString(thr, str); |
1836 ) |
1845 ) |
1837 UNCHECKED()->GetStringRegion(env, str, start, len, buf); |
1846 UNCHECKED()->GetStringRegion(env, str, start, len, buf); |
1838 thr->set_pending_jni_exception_check("GetStringRegion"); |
|
1839 functionExit(thr); |
1847 functionExit(thr); |
1840 JNI_END |
1848 JNI_END |
1841 |
1849 |
1842 JNI_ENTRY_CHECKED(void, |
1850 JNI_ENTRY_CHECKED(void, |
1843 checked_jni_GetStringUTFRegion(JNIEnv *env, |
1851 checked_jni_GetStringUTFRegion(JNIEnv *env, |
1848 functionEnter(thr); |
1856 functionEnter(thr); |
1849 IN_VM( |
1857 IN_VM( |
1850 checkString(thr, str); |
1858 checkString(thr, str); |
1851 ) |
1859 ) |
1852 UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf); |
1860 UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf); |
1853 thr->set_pending_jni_exception_check("GetStringUTFRegion"); |
|
1854 functionExit(thr); |
1861 functionExit(thr); |
1855 JNI_END |
1862 JNI_END |
1856 |
1863 |
1857 JNI_ENTRY_CHECKED(void *, |
1864 JNI_ENTRY_CHECKED(void *, |
1858 checked_jni_GetPrimitiveArrayCritical(JNIEnv *env, |
1865 checked_jni_GetPrimitiveArrayCritical(JNIEnv *env, |