124 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass"; |
124 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass"; |
125 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call"; |
125 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call"; |
126 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call"; |
126 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call"; |
127 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations"; |
127 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations"; |
128 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation"; |
128 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation"; |
|
129 static const char * fatal_prim_type_array_expected = "Primitive type array expected but not received for JNI array operation"; |
129 static const char * fatal_non_array = "Non-array passed to JNI array operations"; |
130 static const char * fatal_non_array = "Non-array passed to JNI array operations"; |
130 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI"; |
131 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI"; |
131 static const char * fatal_should_be_static = "Non-static field ID passed to JNI"; |
132 static const char * fatal_should_be_static = "Non-static field ID passed to JNI"; |
132 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI"; |
133 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI"; |
133 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations"; |
134 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations"; |
276 oop s = jniCheck::validate_object(thr, js); |
277 oop s = jniCheck::validate_object(thr, js); |
277 if (!s || !java_lang_String::is_instance(s)) |
278 if (!s || !java_lang_String::is_instance(s)) |
278 ReportJNIFatalError(thr, fatal_non_string); |
279 ReportJNIFatalError(thr, fatal_non_string); |
279 } |
280 } |
280 |
281 |
281 static inline void |
282 static inline arrayOop |
282 checkArray(JavaThread* thr, jarray jArray, int elementType) |
283 check_is_array(JavaThread* thr, jarray jArray) |
283 { |
284 { |
284 ASSERT_OOPS_ALLOWED; |
285 ASSERT_OOPS_ALLOWED; |
285 arrayOop aOop; |
286 arrayOop aOop; |
286 |
287 |
287 aOop = (arrayOop)jniCheck::validate_object(thr, jArray); |
288 aOop = (arrayOop)jniCheck::validate_object(thr, jArray); |
288 if (aOop == NULL || !aOop->is_array()) |
289 if (aOop == NULL || !aOop->is_array()) { |
289 ReportJNIFatalError(thr, fatal_non_array); |
290 ReportJNIFatalError(thr, fatal_non_array); |
290 |
|
291 if (elementType != -1) { |
|
292 if (aOop->is_typeArray()) { |
|
293 BasicType array_type = TypeArrayKlass::cast(aOop->klass())->element_type(); |
|
294 if (array_type != elementType) |
|
295 ReportJNIFatalError(thr, fatal_element_type_mismatch); |
|
296 } else if (aOop->is_objArray()) { |
|
297 if ( T_OBJECT != elementType) |
|
298 ReportJNIFatalError(thr, fatal_object_array_expected); |
|
299 } else { |
|
300 ReportJNIFatalError(thr, fatal_unknown_array_object); |
|
301 } |
|
302 } |
291 } |
303 } |
292 return aOop; |
304 |
293 } |
|
294 |
|
295 static inline arrayOop |
|
296 check_is_primitive_array(JavaThread* thr, jarray jArray) { |
|
297 arrayOop aOop = check_is_array(thr, jArray); |
|
298 |
|
299 if (!aOop->is_typeArray()) { |
|
300 ReportJNIFatalError(thr, fatal_prim_type_array_expected); |
|
301 } |
|
302 return aOop; |
|
303 } |
|
304 |
|
305 static inline void |
|
306 check_primitive_array_type(JavaThread* thr, jarray jArray, BasicType elementType) |
|
307 { |
|
308 BasicType array_type; |
|
309 arrayOop aOop; |
|
310 |
|
311 aOop = check_is_primitive_array(thr, jArray); |
|
312 array_type = TypeArrayKlass::cast(aOop->klass())->element_type(); |
|
313 if (array_type != elementType) { |
|
314 ReportJNIFatalError(thr, fatal_element_type_mismatch); |
|
315 } |
|
316 } |
|
317 |
|
318 static inline void |
|
319 check_is_obj_array(JavaThread* thr, jarray jArray) { |
|
320 BasicType array_type; |
|
321 arrayOop aOop; |
|
322 |
|
323 aOop = check_is_array(thr, jArray); |
|
324 array_type = TypeArrayKlass::cast(aOop->klass())->element_type(); |
|
325 if (array_type != T_OBJECT) { |
|
326 ReportJNIFatalError(thr, fatal_object_array_expected); |
|
327 } |
|
328 } |
305 |
329 |
306 oop jniCheck::validate_handle(JavaThread* thr, jobject obj) { |
330 oop jniCheck::validate_handle(JavaThread* thr, jobject obj) { |
307 if (JNIHandles::is_frame_handle(thr, obj) || |
331 if (JNIHandles::is_frame_handle(thr, obj) || |
308 JNIHandles::is_local_handle(thr, obj) || |
332 JNIHandles::is_local_handle(thr, obj) || |
309 JNIHandles::is_global_handle(obj) || |
333 JNIHandles::is_global_handle(obj) || |
1485 checked_jni_Get##Result##ArrayElements(JNIEnv *env, \ |
1509 checked_jni_Get##Result##ArrayElements(JNIEnv *env, \ |
1486 ElementType##Array array, \ |
1510 ElementType##Array array, \ |
1487 jboolean *isCopy)) \ |
1511 jboolean *isCopy)) \ |
1488 functionEnter(thr); \ |
1512 functionEnter(thr); \ |
1489 IN_VM( \ |
1513 IN_VM( \ |
1490 checkArray(thr, array, ElementTag); \ |
1514 check_primitive_array_type(thr, array, ElementTag); \ |
1491 ) \ |
1515 ) \ |
1492 ElementType *result = UNCHECKED()->Get##Result##ArrayElements(env, \ |
1516 ElementType *result = UNCHECKED()->Get##Result##ArrayElements(env, \ |
1493 array, \ |
1517 array, \ |
1494 isCopy); \ |
1518 isCopy); \ |
1495 functionExit(env); \ |
1519 functionExit(env); \ |
1511 ElementType##Array array, \ |
1535 ElementType##Array array, \ |
1512 ElementType *elems, \ |
1536 ElementType *elems, \ |
1513 jint mode)) \ |
1537 jint mode)) \ |
1514 functionEnterExceptionAllowed(thr); \ |
1538 functionEnterExceptionAllowed(thr); \ |
1515 IN_VM( \ |
1539 IN_VM( \ |
1516 checkArray(thr, array, ElementTag); \ |
1540 check_primitive_array_type(thr, array, ElementTag); \ |
1517 ASSERT_OOPS_ALLOWED; \ |
1541 ASSERT_OOPS_ALLOWED; \ |
1518 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
1542 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
1519 /* cannot check validity of copy, unless every request is logged by |
1543 /* cannot check validity of copy, unless every request is logged by |
1520 * checking code. Implementation of this check is deferred until a |
1544 * checking code. Implementation of this check is deferred until a |
1521 * subsequent release. |
1545 * subsequent release. |
1541 jsize start, \ |
1565 jsize start, \ |
1542 jsize len, \ |
1566 jsize len, \ |
1543 ElementType *buf)) \ |
1567 ElementType *buf)) \ |
1544 functionEnter(thr); \ |
1568 functionEnter(thr); \ |
1545 IN_VM( \ |
1569 IN_VM( \ |
1546 checkArray(thr, array, ElementTag); \ |
1570 check_primitive_array_type(thr, array, ElementTag); \ |
1547 ) \ |
1571 ) \ |
1548 UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \ |
1572 UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \ |
1549 functionExit(env); \ |
1573 functionExit(env); \ |
1550 JNI_END |
1574 JNI_END |
1551 |
1575 |
1565 jsize start, \ |
1589 jsize start, \ |
1566 jsize len, \ |
1590 jsize len, \ |
1567 const ElementType *buf)) \ |
1591 const ElementType *buf)) \ |
1568 functionEnter(thr); \ |
1592 functionEnter(thr); \ |
1569 IN_VM( \ |
1593 IN_VM( \ |
1570 checkArray(thr, array, ElementTag); \ |
1594 check_primitive_array_type(thr, array, ElementTag); \ |
1571 ) \ |
1595 ) \ |
1572 UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \ |
1596 UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \ |
1573 functionExit(env); \ |
1597 functionExit(env); \ |
1574 JNI_END |
1598 JNI_END |
1575 |
1599 |
1681 jarray array, |
1705 jarray array, |
1682 void *carray, |
1706 void *carray, |
1683 jint mode)) |
1707 jint mode)) |
1684 functionEnterCriticalExceptionAllowed(thr); |
1708 functionEnterCriticalExceptionAllowed(thr); |
1685 IN_VM( |
1709 IN_VM( |
1686 checkArray(thr, array, -1); |
1710 check_is_primitive_array(thr, array); |
1687 ) |
1711 ) |
1688 /* The Hotspot JNI code does not use the parameters, so just check the |
1712 /* The Hotspot JNI code does not use the parameters, so just check the |
1689 * array parameter as a minor sanity check |
1713 * array parameter as a minor sanity check |
1690 */ |
1714 */ |
1691 UNCHECKED()->ReleasePrimitiveArrayCritical(env, array, carray, mode); |
1715 UNCHECKED()->ReleasePrimitiveArrayCritical(env, array, carray, mode); |