1 /*
2 * Copyright (c) 2003, 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 *
140 static VerificationType char_type() { return VerificationType(Char); }
141 static VerificationType short_type() { return VerificationType(Short); }
142 static VerificationType double2_type()
143 { return VerificationType(Double_2nd); }
144
145 // "check" types are used for queries. A "check" type is not assignable
146 // to anything, but the specified types are assignable to a "check". For
147 // example, any category1 primitive is assignable to category1_check and
148 // any reference is assignable to reference_check.
149 static VerificationType reference_check()
150 { return VerificationType(ReferenceQuery); }
151 static VerificationType category1_check()
152 { return VerificationType(Category1Query); }
153 static VerificationType category2_check()
154 { return VerificationType(Category2Query); }
155 static VerificationType category2_2nd_check()
156 { return VerificationType(Category2_2ndQuery); }
157
158 // For reference types, store the actual Symbol
159 static VerificationType reference_type(Symbol* sh) {
160 assert(((uintptr_t)sh & 0x3) == 0, "Oops must be aligned");
161 // If the above assert fails in the future because oop* isn't aligned,
162 // then this type encoding system will have to change to have a tag value
163 // to descriminate between oops and primitives.
164 return VerificationType((uintptr_t)sh);
165 }
166 static VerificationType uninitialized_type(u2 bci)
167 { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
168 static VerificationType uninitialized_this_type()
169 { return uninitialized_type(BciForThis); }
170
171 // Create based on u1 read from classfile
172 static VerificationType from_tag(u1 tag);
173
174 bool is_bogus() const { return (_u._data == Bogus); }
175 bool is_null() const { return (_u._data == Null); }
176 bool is_boolean() const { return (_u._data == Boolean); }
177 bool is_byte() const { return (_u._data == Byte); }
178 bool is_char() const { return (_u._data == Char); }
179 bool is_short() const { return (_u._data == Short); }
180 bool is_integer() const { return (_u._data == Integer); }
286 return from.is_integer();
287 default:
288 if (is_reference() && from.is_reference()) {
289 return is_reference_assignable_from(from, context, CHECK_false);
290 } else {
291 return false;
292 }
293 }
294 }
295 }
296
297 VerificationType get_component(ClassVerifier* context, TRAPS) const;
298
299 int dimensions() const {
300 assert(is_array(), "Must be an array");
301 int index = 0;
302 while (name()->byte_at(index++) == '[');
303 return index;
304 }
305
306 void print_on(outputStream* st) const PRODUCT_RETURN;
307
308 private:
309
310 bool is_reference_assignable_from(
311 const VerificationType&, ClassVerifier*, TRAPS) const;
312 };
313
314 #endif // SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
|
1 /*
2 * Copyright (c) 2003, 2012, 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 *
140 static VerificationType char_type() { return VerificationType(Char); }
141 static VerificationType short_type() { return VerificationType(Short); }
142 static VerificationType double2_type()
143 { return VerificationType(Double_2nd); }
144
145 // "check" types are used for queries. A "check" type is not assignable
146 // to anything, but the specified types are assignable to a "check". For
147 // example, any category1 primitive is assignable to category1_check and
148 // any reference is assignable to reference_check.
149 static VerificationType reference_check()
150 { return VerificationType(ReferenceQuery); }
151 static VerificationType category1_check()
152 { return VerificationType(Category1Query); }
153 static VerificationType category2_check()
154 { return VerificationType(Category2Query); }
155 static VerificationType category2_2nd_check()
156 { return VerificationType(Category2_2ndQuery); }
157
158 // For reference types, store the actual Symbol
159 static VerificationType reference_type(Symbol* sh) {
160 assert(((uintptr_t)sh & 0x3) == 0, "Symbols must be aligned");
161 // If the above assert fails in the future because oop* isn't aligned,
162 // then this type encoding system will have to change to have a tag value
163 // to descriminate between oops and primitives.
164 return VerificationType((uintptr_t)sh);
165 }
166 static VerificationType uninitialized_type(u2 bci)
167 { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
168 static VerificationType uninitialized_this_type()
169 { return uninitialized_type(BciForThis); }
170
171 // Create based on u1 read from classfile
172 static VerificationType from_tag(u1 tag);
173
174 bool is_bogus() const { return (_u._data == Bogus); }
175 bool is_null() const { return (_u._data == Null); }
176 bool is_boolean() const { return (_u._data == Boolean); }
177 bool is_byte() const { return (_u._data == Byte); }
178 bool is_char() const { return (_u._data == Char); }
179 bool is_short() const { return (_u._data == Short); }
180 bool is_integer() const { return (_u._data == Integer); }
286 return from.is_integer();
287 default:
288 if (is_reference() && from.is_reference()) {
289 return is_reference_assignable_from(from, context, CHECK_false);
290 } else {
291 return false;
292 }
293 }
294 }
295 }
296
297 VerificationType get_component(ClassVerifier* context, TRAPS) const;
298
299 int dimensions() const {
300 assert(is_array(), "Must be an array");
301 int index = 0;
302 while (name()->byte_at(index++) == '[');
303 return index;
304 }
305
306 void print_on(outputStream* st) const;
307
308 private:
309
310 bool is_reference_assignable_from(
311 const VerificationType&, ClassVerifier*, TRAPS) const;
312 };
313
314 #endif // SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
|