Mercurial > hg > truffle
annotate src/share/vm/classfile/verificationType.hpp @ 1972:f95d63e2154a
6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg
author | stefank |
---|---|
date | Tue, 23 Nov 2010 13:22:55 -0800 |
parents | c18cbe5936b8 |
children | 3582bf76420e |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP |
26 #define SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP | |
27 | |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "memory/allocation.hpp" | |
30 #include "oops/instanceKlass.hpp" | |
31 #include "oops/oop.inline.hpp" | |
32 #include "oops/symbolOop.hpp" | |
33 #include "runtime/handles.hpp" | |
34 #include "runtime/signature.hpp" | |
35 | |
0 | 36 enum { |
37 // As specifed in the JVM spec | |
38 ITEM_Top = 0, | |
39 ITEM_Integer = 1, | |
40 ITEM_Float = 2, | |
41 ITEM_Double = 3, | |
42 ITEM_Long = 4, | |
43 ITEM_Null = 5, | |
44 ITEM_UninitializedThis = 6, | |
45 ITEM_Object = 7, | |
46 ITEM_Uninitialized = 8, | |
47 ITEM_Bogus = (uint)-1 | |
48 }; | |
49 | |
50 class VerificationType VALUE_OBJ_CLASS_SPEC { | |
51 private: | |
52 // Least significant bits of _handle are always 0, so we use these as | |
53 // the indicator that the _handle is valid. Otherwise, the _data field | |
54 // contains encoded data (as specified below). Should the VM change | |
55 // and the lower bits on oops aren't 0, the assert in the constructor | |
56 // will catch this and we'll have to add a descriminator tag to this | |
57 // structure. | |
58 union { | |
59 symbolOop* _handle; | |
60 uintptr_t _data; | |
61 } _u; | |
62 | |
63 enum { | |
64 // These rest are not found in classfiles, but used by the verifier | |
65 ITEM_Boolean = 9, ITEM_Byte, ITEM_Short, ITEM_Char, | |
66 ITEM_Long_2nd, ITEM_Double_2nd | |
67 }; | |
68 | |
69 // Enum for the _data field | |
70 enum { | |
71 // Bottom two bits determine if the type is a reference, primitive, | |
72 // uninitialized or a query-type. | |
73 TypeMask = 0x00000003, | |
74 | |
75 // Topmost types encoding | |
76 Reference = 0x0, // _handle contains the name | |
77 Primitive = 0x1, // see below for primitive list | |
78 Uninitialized = 0x2, // 0x00ffff00 contains bci | |
79 TypeQuery = 0x3, // Meta-types used for category testing | |
80 | |
81 // Utility flags | |
82 ReferenceFlag = 0x00, // For reference query types | |
83 Category1Flag = 0x01, // One-word values | |
84 Category2Flag = 0x02, // First word of a two-word value | |
85 Category2_2ndFlag = 0x04, // Second word of a two-word value | |
86 | |
87 // special reference values | |
88 Null = 0x00000000, // A reference with a 0 handle is null | |
89 | |
90 // Primitives categories (the second byte determines the category) | |
91 Category1 = (Category1Flag << 1 * BitsPerByte) | Primitive, | |
92 Category2 = (Category2Flag << 1 * BitsPerByte) | Primitive, | |
93 Category2_2nd = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive, | |
94 | |
95 // Primitive values (type descriminator stored in most-signifcant bytes) | |
96 Bogus = (ITEM_Bogus << 2 * BitsPerByte) | Category1, | |
97 Boolean = (ITEM_Boolean << 2 * BitsPerByte) | Category1, | |
98 Byte = (ITEM_Byte << 2 * BitsPerByte) | Category1, | |
99 Short = (ITEM_Short << 2 * BitsPerByte) | Category1, | |
100 Char = (ITEM_Char << 2 * BitsPerByte) | Category1, | |
101 Integer = (ITEM_Integer << 2 * BitsPerByte) | Category1, | |
102 Float = (ITEM_Float << 2 * BitsPerByte) | Category1, | |
103 Long = (ITEM_Long << 2 * BitsPerByte) | Category2, | |
104 Double = (ITEM_Double << 2 * BitsPerByte) | Category2, | |
105 Long_2nd = (ITEM_Long_2nd << 2 * BitsPerByte) | Category2_2nd, | |
106 Double_2nd = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd, | |
107 | |
108 // Used by Uninitialized (second and third bytes hold the bci) | |
109 BciMask = 0xffff << 1 * BitsPerByte, | |
110 BciForThis = ((u2)-1), // A bci of -1 is an Unintialized-This | |
111 | |
112 // Query values | |
113 ReferenceQuery = (ReferenceFlag << 1 * BitsPerByte) | TypeQuery, | |
114 Category1Query = (Category1Flag << 1 * BitsPerByte) | TypeQuery, | |
115 Category2Query = (Category2Flag << 1 * BitsPerByte) | TypeQuery, | |
116 Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery | |
117 }; | |
118 | |
119 VerificationType(uintptr_t raw_data) { | |
120 _u._data = raw_data; | |
121 } | |
122 | |
123 public: | |
124 | |
125 VerificationType() { *this = bogus_type(); } | |
126 | |
127 // Create verification types | |
128 static VerificationType bogus_type() { return VerificationType(Bogus); } | |
129 static VerificationType null_type() { return VerificationType(Null); } | |
130 static VerificationType integer_type() { return VerificationType(Integer); } | |
131 static VerificationType float_type() { return VerificationType(Float); } | |
132 static VerificationType long_type() { return VerificationType(Long); } | |
133 static VerificationType long2_type() { return VerificationType(Long_2nd); } | |
134 static VerificationType double_type() { return VerificationType(Double); } | |
135 static VerificationType boolean_type() { return VerificationType(Boolean); } | |
136 static VerificationType byte_type() { return VerificationType(Byte); } | |
137 static VerificationType char_type() { return VerificationType(Char); } | |
138 static VerificationType short_type() { return VerificationType(Short); } | |
139 static VerificationType double2_type() | |
140 { return VerificationType(Double_2nd); } | |
141 | |
142 // "check" types are used for queries. A "check" type is not assignable | |
143 // to anything, but the specified types are assignable to a "check". For | |
144 // example, any category1 primitive is assignable to category1_check and | |
145 // any reference is assignable to reference_check. | |
146 static VerificationType reference_check() | |
147 { return VerificationType(ReferenceQuery); } | |
148 static VerificationType category1_check() | |
149 { return VerificationType(Category1Query); } | |
150 static VerificationType category2_check() | |
151 { return VerificationType(Category2Query); } | |
152 static VerificationType category2_2nd_check() | |
153 { return VerificationType(Category2_2ndQuery); } | |
154 | |
155 // For reference types, store the actual oop* handle | |
156 static VerificationType reference_type(symbolHandle sh) { | |
157 assert(((uintptr_t)sh.raw_value() & 0x3) == 0, "Oops must be aligned"); | |
158 // If the above assert fails in the future because oop* isn't aligned, | |
159 // then this type encoding system will have to change to have a tag value | |
160 // to descriminate between oops and primitives. | |
161 return VerificationType((uintptr_t)((symbolOop*)sh.raw_value())); | |
162 } | |
163 static VerificationType reference_type(symbolOop s, TRAPS) | |
164 { return reference_type(symbolHandle(THREAD, s)); } | |
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); } | |
181 bool is_long() const { return (_u._data == Long); } | |
182 bool is_float() const { return (_u._data == Float); } | |
183 bool is_double() const { return (_u._data == Double); } | |
184 bool is_long2() const { return (_u._data == Long_2nd); } | |
185 bool is_double2() const { return (_u._data == Double_2nd); } | |
186 bool is_reference() const { return ((_u._data & TypeMask) == Reference); } | |
187 bool is_category1() const { | |
188 // This should return true for all one-word types, which are category1 | |
189 // primitives, and references (including uninitialized refs). Though | |
190 // the 'query' types should technically return 'false' here, if we | |
191 // allow this to return true, we can perform the test using only | |
192 // 2 operations rather than 8 (3 masks, 3 compares and 2 logical 'ands'). | |
193 // Since noone should call this on a query type anyway, this is ok. | |
194 assert(!is_check(), "Must not be a check type (wrong value returned)"); | |
195 return ((_u._data & Category1) != Primitive); | |
196 // should only return false if it's a primitive, and the category1 flag | |
197 // is not set. | |
198 } | |
199 bool is_category2() const { return ((_u._data & Category2) == Category2); } | |
200 bool is_category2_2nd() const { | |
201 return ((_u._data & Category2_2nd) == Category2_2nd); | |
202 } | |
203 bool is_reference_check() const { return _u._data == ReferenceQuery; } | |
204 bool is_category1_check() const { return _u._data == Category1Query; } | |
205 bool is_category2_check() const { return _u._data == Category2Query; } | |
206 bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; } | |
207 bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; } | |
208 | |
209 bool is_x_array(char sig) const { | |
210 return is_null() || (is_array() && (name()->byte_at(1) == sig)); | |
211 } | |
212 bool is_int_array() const { return is_x_array('I'); } | |
213 bool is_byte_array() const { return is_x_array('B'); } | |
214 bool is_bool_array() const { return is_x_array('Z'); } | |
215 bool is_char_array() const { return is_x_array('C'); } | |
216 bool is_short_array() const { return is_x_array('S'); } | |
217 bool is_long_array() const { return is_x_array('J'); } | |
218 bool is_float_array() const { return is_x_array('F'); } | |
219 bool is_double_array() const { return is_x_array('D'); } | |
220 bool is_object_array() const { return is_x_array('L'); } | |
221 bool is_array_array() const { return is_x_array('['); } | |
222 bool is_reference_array() const | |
223 { return is_object_array() || is_array_array(); } | |
224 bool is_object() const | |
225 { return (is_reference() && !is_null() && name()->utf8_length() >= 1 && | |
226 name()->byte_at(0) != '['); } | |
227 bool is_array() const | |
228 { return (is_reference() && !is_null() && name()->utf8_length() >= 2 && | |
229 name()->byte_at(0) == '['); } | |
230 bool is_uninitialized() const | |
231 { return ((_u._data & Uninitialized) == Uninitialized); } | |
232 bool is_uninitialized_this() const | |
233 { return is_uninitialized() && bci() == BciForThis; } | |
234 | |
235 VerificationType to_category2_2nd() const { | |
236 assert(is_category2(), "Must be a double word"); | |
237 return VerificationType(is_long() ? Long_2nd : Double_2nd); | |
238 } | |
239 | |
240 u2 bci() const { | |
241 assert(is_uninitialized(), "Must be uninitialized type"); | |
242 return ((_u._data & BciMask) >> 1 * BitsPerByte); | |
243 } | |
244 | |
245 symbolHandle name_handle() const { | |
246 assert(is_reference() && !is_null(), "Must be a non-null reference"); | |
247 return symbolHandle(_u._handle, true); | |
248 } | |
249 symbolOop name() const { | |
250 assert(is_reference() && !is_null(), "Must be a non-null reference"); | |
251 return *(_u._handle); | |
252 } | |
253 | |
254 bool equals(const VerificationType& t) const { | |
255 return (_u._data == t._u._data || | |
256 (is_reference() && t.is_reference() && !is_null() && !t.is_null() && | |
257 name() == t.name())); | |
258 } | |
259 | |
260 bool operator ==(const VerificationType& t) const { | |
261 return equals(t); | |
262 } | |
263 | |
264 bool operator !=(const VerificationType& t) const { | |
265 return !equals(t); | |
266 } | |
267 | |
268 // The whole point of this type system - check to see if one type | |
269 // is assignable to another. Returns true if one can assign 'from' to | |
270 // this. | |
271 bool is_assignable_from( | |
272 const VerificationType& from, instanceKlassHandle context, TRAPS) const { | |
273 if (equals(from) || is_bogus()) { | |
274 return true; | |
275 } else { | |
276 switch(_u._data) { | |
277 case Category1Query: | |
278 return from.is_category1(); | |
279 case Category2Query: | |
280 return from.is_category2(); | |
281 case Category2_2ndQuery: | |
282 return from.is_category2_2nd(); | |
283 case ReferenceQuery: | |
284 return from.is_reference() || from.is_uninitialized(); | |
285 case Boolean: | |
286 case Byte: | |
287 case Char: | |
288 case Short: | |
289 // An int can be assigned to boolean, byte, char or short values. | |
290 return from.is_integer(); | |
291 default: | |
292 if (is_reference() && from.is_reference()) { | |
293 return is_reference_assignable_from(from, context, CHECK_false); | |
294 } else { | |
295 return false; | |
296 } | |
297 } | |
298 } | |
299 } | |
300 | |
301 VerificationType get_component(TRAPS) const; | |
302 | |
303 int dimensions() const { | |
304 assert(is_array(), "Must be an array"); | |
305 int index = 0; | |
306 while (name()->byte_at(index++) == '['); | |
307 return index; | |
308 } | |
309 | |
310 void print_on(outputStream* st) const PRODUCT_RETURN; | |
311 | |
312 private: | |
313 | |
314 bool is_reference_assignable_from( | |
315 const VerificationType&, instanceKlassHandle, TRAPS) const; | |
316 }; | |
1972 | 317 |
318 #endif // SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP |