256 fieldDescriptor fd; 257 258 /* make sure it is a static field */ 259 if (!jfieldIDWorkaround::is_static_jfieldID(fid)) 260 ReportJNIFatalError(thr, fatal_should_be_static); 261 262 /* validate the class being passed */ 263 ASSERT_OOPS_ALLOWED; 264 Klass* k_oop = jniCheck::validate_class(thr, cls, false); 265 266 /* check for proper subclass hierarchy */ 267 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid); 268 Klass* f_oop = id->holder(); 269 if (!InstanceKlass::cast(k_oop)->is_subtype_of(f_oop)) 270 ReportJNIFatalError(thr, fatal_wrong_static_field); 271 272 /* check for proper field type */ 273 if (!id->find_local_field(&fd)) 274 ReportJNIFatalError(thr, fatal_static_field_not_found); 275 if ((fd.field_type() != ftype) && 276 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) { 277 ReportJNIFatalError(thr, fatal_static_field_mismatch); 278 } 279 } 280 281 static inline void 282 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype) 283 { 284 fieldDescriptor fd; 285 286 /* make sure it is an instance field */ 287 if (jfieldIDWorkaround::is_static_jfieldID(fid)) 288 ReportJNIFatalError(thr, fatal_should_be_nonstatic); 289 290 /* validate the object being passed and then get its class */ 291 ASSERT_OOPS_ALLOWED; 292 oop oopObj = jniCheck::validate_object(thr, obj); 293 if (oopObj == NULL) { 294 ReportJNIFatalError(thr, fatal_null_object); 295 } 296 Klass* k_oop = oopObj->klass(); 297 298 if (!jfieldIDWorkaround::is_valid_jfieldID(k_oop, fid)) { 299 ReportJNIFatalError(thr, fatal_wrong_field); 300 } 301 302 /* make sure the field exists */ 303 int offset = jfieldIDWorkaround::from_instance_jfieldID(k_oop, fid); 304 if (!InstanceKlass::cast(k_oop)->contains_field_offset(offset)) 305 ReportJNIFatalError(thr, fatal_wrong_field); 306 307 /* check for proper field type */ 308 if (!InstanceKlass::cast(k_oop)->find_field_from_offset(offset, 309 false, &fd)) 310 ReportJNIFatalError(thr, fatal_instance_field_not_found); 311 312 if ((fd.field_type() != ftype) && 313 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) { 314 ReportJNIFatalError(thr, fatal_instance_field_mismatch); 315 } 316 } 317 318 static inline void 319 checkString(JavaThread* thr, jstring js) 320 { 321 ASSERT_OOPS_ALLOWED; 322 oop s = jniCheck::validate_object(thr, js); 323 if ((s == NULL) || !java_lang_String::is_instance(s)) 324 ReportJNIFatalError(thr, fatal_non_string); 325 } 326 327 static inline arrayOop 328 check_is_array(JavaThread* thr, jarray jArray) 329 { 330 ASSERT_OOPS_ALLOWED; 331 arrayOop aOop; 332 333 aOop = (arrayOop)jniCheck::validate_object(thr, jArray); | 256 fieldDescriptor fd; 257 258 /* make sure it is a static field */ 259 if (!jfieldIDWorkaround::is_static_jfieldID(fid)) 260 ReportJNIFatalError(thr, fatal_should_be_static); 261 262 /* validate the class being passed */ 263 ASSERT_OOPS_ALLOWED; 264 Klass* k_oop = jniCheck::validate_class(thr, cls, false); 265 266 /* check for proper subclass hierarchy */ 267 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid); 268 Klass* f_oop = id->holder(); 269 if (!InstanceKlass::cast(k_oop)->is_subtype_of(f_oop)) 270 ReportJNIFatalError(thr, fatal_wrong_static_field); 271 272 /* check for proper field type */ 273 if (!id->find_local_field(&fd)) 274 ReportJNIFatalError(thr, fatal_static_field_not_found); 275 if ((fd.field_type() != ftype) && 276 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT) && 277 !(fd.field_type() == T_VALUETYPE && ftype == T_OBJECT)) { 278 ReportJNIFatalError(thr, fatal_static_field_mismatch); 279 } 280 } 281 282 static inline void 283 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype) 284 { 285 fieldDescriptor fd; 286 287 /* make sure it is an instance field */ 288 if (jfieldIDWorkaround::is_static_jfieldID(fid)) 289 ReportJNIFatalError(thr, fatal_should_be_nonstatic); 290 291 /* validate the object being passed and then get its class */ 292 ASSERT_OOPS_ALLOWED; 293 oop oopObj = jniCheck::validate_object(thr, obj); 294 if (oopObj == NULL) { 295 ReportJNIFatalError(thr, fatal_null_object); 296 } 297 Klass* k_oop = oopObj->klass(); 298 299 if (!jfieldIDWorkaround::is_valid_jfieldID(k_oop, fid)) { 300 ReportJNIFatalError(thr, fatal_wrong_field); 301 } 302 303 /* make sure the field exists */ 304 int offset = jfieldIDWorkaround::from_instance_jfieldID(k_oop, fid); 305 if (!InstanceKlass::cast(k_oop)->contains_field_offset(offset)) 306 ReportJNIFatalError(thr, fatal_wrong_field); 307 308 /* check for proper field type */ 309 if (!InstanceKlass::cast(k_oop)->find_field_from_offset(offset, 310 false, &fd)) 311 ReportJNIFatalError(thr, fatal_instance_field_not_found); 312 313 if ((fd.field_type() != ftype) && 314 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT) && 315 !(fd.field_type() == T_VALUETYPE && ftype == T_OBJECT)) { 316 ReportJNIFatalError(thr, fatal_instance_field_mismatch); 317 } 318 } 319 320 static inline void 321 checkString(JavaThread* thr, jstring js) 322 { 323 ASSERT_OOPS_ALLOWED; 324 oop s = jniCheck::validate_object(thr, js); 325 if ((s == NULL) || !java_lang_String::is_instance(s)) 326 ReportJNIFatalError(thr, fatal_non_string); 327 } 328 329 static inline arrayOop 330 check_is_array(JavaThread* thr, jarray jArray) 331 { 332 ASSERT_OOPS_ALLOWED; 333 arrayOop aOop; 334 335 aOop = (arrayOop)jniCheck::validate_object(thr, jArray); |