1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
207 static inline void
208 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
209 {
210 fieldDescriptor fd;
211
212 /* make sure it is a static field */
213 if (!jfieldIDWorkaround::is_static_jfieldID(fid))
214 ReportJNIFatalError(thr, fatal_should_be_static);
215
216 /* validate the class being passed */
217 ASSERT_OOPS_ALLOWED;
218 klassOop k_oop = jniCheck::validate_class(thr, cls, false);
219
220 /* check for proper subclass hierarchy */
221 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
222 klassOop f_oop = id->holder();
223 if (!instanceKlass::cast(k_oop)->is_subtype_of(f_oop))
224 ReportJNIFatalError(thr, fatal_wrong_static_field);
225
226 /* check for proper field type */
227 if (!instanceKlass::cast(f_oop)->find_local_field_from_offset(
228 id->offset(), true, &fd))
229 ReportJNIFatalError(thr, fatal_static_field_not_found);
230 if ((fd.field_type() != ftype) &&
231 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
232 ReportJNIFatalError(thr, fatal_static_field_mismatch);
233 }
234 }
235
236 static inline void
237 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
238 {
239 fieldDescriptor fd;
240
241 /* make sure it is an instance field */
242 if (jfieldIDWorkaround::is_static_jfieldID(fid))
243 ReportJNIFatalError(thr, fatal_should_be_nonstatic);
244
245 /* validate the object being passed and then get its class */
246 ASSERT_OOPS_ALLOWED;
247 oop oopObj = jniCheck::validate_object(thr, obj);
248 if (!oopObj) {
|
1 /*
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
207 static inline void
208 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
209 {
210 fieldDescriptor fd;
211
212 /* make sure it is a static field */
213 if (!jfieldIDWorkaround::is_static_jfieldID(fid))
214 ReportJNIFatalError(thr, fatal_should_be_static);
215
216 /* validate the class being passed */
217 ASSERT_OOPS_ALLOWED;
218 klassOop k_oop = jniCheck::validate_class(thr, cls, false);
219
220 /* check for proper subclass hierarchy */
221 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
222 klassOop f_oop = id->holder();
223 if (!instanceKlass::cast(k_oop)->is_subtype_of(f_oop))
224 ReportJNIFatalError(thr, fatal_wrong_static_field);
225
226 /* check for proper field type */
227 if (!id->find_local_field(&fd))
228 ReportJNIFatalError(thr, fatal_static_field_not_found);
229 if ((fd.field_type() != ftype) &&
230 !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
231 ReportJNIFatalError(thr, fatal_static_field_mismatch);
232 }
233 }
234
235 static inline void
236 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
237 {
238 fieldDescriptor fd;
239
240 /* make sure it is an instance field */
241 if (jfieldIDWorkaround::is_static_jfieldID(fid))
242 ReportJNIFatalError(thr, fatal_should_be_nonstatic);
243
244 /* validate the object being passed and then get its class */
245 ASSERT_OOPS_ALLOWED;
246 oop oopObj = jniCheck::validate_object(thr, obj);
247 if (!oopObj) {
|