239 fieldDescriptor fd;
240
241 /* make sure it is a static field */
242 if (!jfieldIDWorkaround::is_static_jfieldID(fid))
243 ReportJNIFatalError(thr, fatal_should_be_static);
244
245 /* validate the class being passed */
246 ASSERT_OOPS_ALLOWED;
247 Klass* k_oop = jniCheck::validate_class(thr, cls, false);
248
249 /* check for proper subclass hierarchy */
250 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
251 Klass* f_oop = id->holder();
252 if (!k_oop->is_subtype_of(f_oop))
253 ReportJNIFatalError(thr, fatal_wrong_static_field);
254
255 /* check for proper field type */
256 if (!id->find_local_field(&fd))
257 ReportJNIFatalError(thr, fatal_static_field_not_found);
258 if ((fd.field_type() != ftype) &&
259 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
260 ReportJNIFatalError(thr, fatal_static_field_mismatch);
261 }
262 }
263
264 static inline void
265 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
266 {
267 fieldDescriptor fd;
268
269 /* make sure it is an instance field */
270 if (jfieldIDWorkaround::is_static_jfieldID(fid))
271 ReportJNIFatalError(thr, fatal_should_be_nonstatic);
272
273 /* validate the object being passed and then get its class */
274 ASSERT_OOPS_ALLOWED;
275 oop oopObj = jniCheck::validate_object(thr, obj);
276 if (oopObj == nullptr) {
277 ReportJNIFatalError(thr, fatal_null_object);
278 }
279 Klass* k_oop = oopObj->klass();
327 if (!aOop->is_typeArray()) {
328 ReportJNIFatalError(thr, fatal_prim_type_array_expected);
329 }
330 return aOop;
331 }
332
333 static inline void
334 check_primitive_array_type(JavaThread* thr, jarray jArray, BasicType elementType)
335 {
336 BasicType array_type;
337 arrayOop aOop;
338
339 aOop = check_is_primitive_array(thr, jArray);
340 array_type = TypeArrayKlass::cast(aOop->klass())->element_type();
341 if (array_type != elementType) {
342 ReportJNIFatalError(thr, fatal_element_type_mismatch);
343 }
344 }
345
346 static inline void
347 check_is_obj_array(JavaThread* thr, jarray jArray) {
348 arrayOop aOop = check_is_array(thr, jArray);
349 if (!aOop->is_objArray()) {
350 ReportJNIFatalError(thr, fatal_object_array_expected);
351 }
352 }
353
354 /*
355 * Copy and wrap array elements for bounds checking.
356 * Remember the original elements (GuardedMemory::get_tag())
357 */
358 static void* check_jni_wrap_copy_array(JavaThread* thr, jarray array,
359 void* orig_elements) {
360 void* result;
361 IN_VM(
362 oop a = JNIHandles::resolve_non_null(array);
363 size_t len = arrayOop(a)->length() <<
364 TypeArrayKlass::cast(a->klass())->log2_element_size();
365 result = GuardedMemory::wrap_copy(orig_elements, len, orig_elements);
366 )
367 return result;
368 }
369
1610 return result;
1611 JNI_END
1612
1613 JNI_ENTRY_CHECKED(jobjectArray,
1614 checked_jni_NewObjectArray(JNIEnv *env,
1615 jsize len,
1616 jclass clazz,
1617 jobject init))
1618 functionEnter(thr);
1619 jobjectArray result = UNCHECKED()->NewObjectArray(env,len,clazz,init);
1620 functionExit(thr);
1621 return result;
1622 JNI_END
1623
1624 JNI_ENTRY_CHECKED(jobject,
1625 checked_jni_GetObjectArrayElement(JNIEnv *env,
1626 jobjectArray array,
1627 jsize index))
1628 functionEnter(thr);
1629 IN_VM(
1630 check_is_obj_array(thr, array);
1631 )
1632 jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index);
1633 functionExit(thr);
1634 return result;
1635 JNI_END
1636
1637 JNI_ENTRY_CHECKED(void,
1638 checked_jni_SetObjectArrayElement(JNIEnv *env,
1639 jobjectArray array,
1640 jsize index,
1641 jobject val))
1642 functionEnter(thr);
1643 IN_VM(
1644 check_is_obj_array(thr, array);
1645 )
1646 UNCHECKED()->SetObjectArrayElement(env,array,index,val);
1647 functionExit(thr);
1648 JNI_END
1649
1650 #define WRAPPER_NewScalarArray(Return, Result) \
1651 JNI_ENTRY_CHECKED(Return, \
1652 checked_jni_New##Result##Array(JNIEnv *env, \
1653 jsize len)) \
1654 functionEnter(thr); \
1655 Return result = UNCHECKED()->New##Result##Array(env,len); \
1656 functionExit(thr); \
1657 return (Return) result; \
1658 JNI_END
1659
1660 WRAPPER_NewScalarArray(jbooleanArray, Boolean)
1661 WRAPPER_NewScalarArray(jbyteArray, Byte)
1662 WRAPPER_NewScalarArray(jshortArray, Short)
1663 WRAPPER_NewScalarArray(jcharArray, Char)
1664 WRAPPER_NewScalarArray(jintArray, Int)
|
239 fieldDescriptor fd;
240
241 /* make sure it is a static field */
242 if (!jfieldIDWorkaround::is_static_jfieldID(fid))
243 ReportJNIFatalError(thr, fatal_should_be_static);
244
245 /* validate the class being passed */
246 ASSERT_OOPS_ALLOWED;
247 Klass* k_oop = jniCheck::validate_class(thr, cls, false);
248
249 /* check for proper subclass hierarchy */
250 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
251 Klass* f_oop = id->holder();
252 if (!k_oop->is_subtype_of(f_oop))
253 ReportJNIFatalError(thr, fatal_wrong_static_field);
254
255 /* check for proper field type */
256 if (!id->find_local_field(&fd))
257 ReportJNIFatalError(thr, fatal_static_field_not_found);
258 if ((fd.field_type() != ftype) &&
259 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
260 ReportJNIFatalError(thr, fatal_static_field_mismatch);
261 }
262 }
263
264 static inline void
265 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
266 {
267 fieldDescriptor fd;
268
269 /* make sure it is an instance field */
270 if (jfieldIDWorkaround::is_static_jfieldID(fid))
271 ReportJNIFatalError(thr, fatal_should_be_nonstatic);
272
273 /* validate the object being passed and then get its class */
274 ASSERT_OOPS_ALLOWED;
275 oop oopObj = jniCheck::validate_object(thr, obj);
276 if (oopObj == nullptr) {
277 ReportJNIFatalError(thr, fatal_null_object);
278 }
279 Klass* k_oop = oopObj->klass();
327 if (!aOop->is_typeArray()) {
328 ReportJNIFatalError(thr, fatal_prim_type_array_expected);
329 }
330 return aOop;
331 }
332
333 static inline void
334 check_primitive_array_type(JavaThread* thr, jarray jArray, BasicType elementType)
335 {
336 BasicType array_type;
337 arrayOop aOop;
338
339 aOop = check_is_primitive_array(thr, jArray);
340 array_type = TypeArrayKlass::cast(aOop->klass())->element_type();
341 if (array_type != elementType) {
342 ReportJNIFatalError(thr, fatal_element_type_mismatch);
343 }
344 }
345
346 static inline void
347 check_is_obj_or_inline_array(JavaThread* thr, jarray jArray) {
348 arrayOop aOop = check_is_array(thr, jArray);
349 if (!aOop->is_objArray() && !aOop->is_flatArray()) {
350 ReportJNIFatalError(thr, fatal_object_array_expected);
351 }
352 }
353
354 /*
355 * Copy and wrap array elements for bounds checking.
356 * Remember the original elements (GuardedMemory::get_tag())
357 */
358 static void* check_jni_wrap_copy_array(JavaThread* thr, jarray array,
359 void* orig_elements) {
360 void* result;
361 IN_VM(
362 oop a = JNIHandles::resolve_non_null(array);
363 size_t len = arrayOop(a)->length() <<
364 TypeArrayKlass::cast(a->klass())->log2_element_size();
365 result = GuardedMemory::wrap_copy(orig_elements, len, orig_elements);
366 )
367 return result;
368 }
369
1610 return result;
1611 JNI_END
1612
1613 JNI_ENTRY_CHECKED(jobjectArray,
1614 checked_jni_NewObjectArray(JNIEnv *env,
1615 jsize len,
1616 jclass clazz,
1617 jobject init))
1618 functionEnter(thr);
1619 jobjectArray result = UNCHECKED()->NewObjectArray(env,len,clazz,init);
1620 functionExit(thr);
1621 return result;
1622 JNI_END
1623
1624 JNI_ENTRY_CHECKED(jobject,
1625 checked_jni_GetObjectArrayElement(JNIEnv *env,
1626 jobjectArray array,
1627 jsize index))
1628 functionEnter(thr);
1629 IN_VM(
1630 check_is_obj_or_inline_array(thr, array);
1631 )
1632 jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index);
1633 functionExit(thr);
1634 return result;
1635 JNI_END
1636
1637 JNI_ENTRY_CHECKED(void,
1638 checked_jni_SetObjectArrayElement(JNIEnv *env,
1639 jobjectArray array,
1640 jsize index,
1641 jobject val))
1642 functionEnter(thr);
1643 IN_VM(
1644 check_is_obj_or_inline_array(thr, array);
1645 )
1646 UNCHECKED()->SetObjectArrayElement(env,array,index,val);
1647 functionExit(thr);
1648 JNI_END
1649
1650 #define WRAPPER_NewScalarArray(Return, Result) \
1651 JNI_ENTRY_CHECKED(Return, \
1652 checked_jni_New##Result##Array(JNIEnv *env, \
1653 jsize len)) \
1654 functionEnter(thr); \
1655 Return result = UNCHECKED()->New##Result##Array(env,len); \
1656 functionExit(thr); \
1657 return (Return) result; \
1658 JNI_END
1659
1660 WRAPPER_NewScalarArray(jbooleanArray, Boolean)
1661 WRAPPER_NewScalarArray(jbyteArray, Byte)
1662 WRAPPER_NewScalarArray(jshortArray, Short)
1663 WRAPPER_NewScalarArray(jcharArray, Char)
1664 WRAPPER_NewScalarArray(jintArray, Int)
|