< prev index next >

src/hotspot/share/classfile/verificationType.hpp

Print this page

 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       Symbol*   _sym;
 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 : uint {
 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,        // _sym 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 sym 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 needs the " | Primitive".  Else, is_reference(Bogus) returns TRUE.
 97       Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Primitive,
 98       Boolean            = (ITEM_Boolean    << 2 * BitsPerByte) | Category1,
 99       Byte               = (ITEM_Byte       << 2 * BitsPerByte) | Category1,
100       Short              = (ITEM_Short      << 2 * BitsPerByte) | Category1,
101       Char               = (ITEM_Char       << 2 * BitsPerByte) | Category1,
102       Integer            = (ITEM_Integer    << 2 * BitsPerByte) | Category1,
103       Float              = (ITEM_Float      << 2 * BitsPerByte) | Category1,
104       Long               = (ITEM_Long       << 2 * BitsPerByte) | Category2,
105       Double             = (ITEM_Double     << 2 * BitsPerByte) | Category2,
106       Long_2nd           = (ITEM_Long_2nd   << 2 * BitsPerByte) | Category2_2nd,
107       Double_2nd         = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd,
108 
109       // Used by Uninitialized (second and third bytes hold the bci)
110       BciMask            = 0xffff << 1 * BitsPerByte,
111       BciForThis         = ((u2)-1),   // A bci of -1 is an Unintialized-This
112 
113       // Query values
114       ReferenceQuery     = (ReferenceFlag     << 1 * BitsPerByte) | TypeQuery,
115       Category1Query     = (Category1Flag     << 1 * BitsPerByte) | TypeQuery,
116       Category2Query     = (Category2Flag     << 1 * BitsPerByte) | TypeQuery,
117       Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery


118     };
119 
120   VerificationType(uintptr_t raw_data) {
121     _u._data = raw_data;
122   }
123 
124  public:
125 
126   VerificationType() { *this = bogus_type(); }
127 
128   // Create verification types
129   static VerificationType bogus_type() { return VerificationType(Bogus); }
130   static VerificationType top_type() { return bogus_type(); } // alias
131   static VerificationType null_type() { return VerificationType(Null); }
132   static VerificationType integer_type() { return VerificationType(Integer); }
133   static VerificationType float_type() { return VerificationType(Float); }
134   static VerificationType long_type() { return VerificationType(Long); }
135   static VerificationType long2_type() { return VerificationType(Long_2nd); }
136   static VerificationType double_type() { return VerificationType(Double); }
137   static VerificationType boolean_type() { return VerificationType(Boolean); }
138   static VerificationType byte_type() { return VerificationType(Byte); }
139   static VerificationType char_type() { return VerificationType(Char); }
140   static VerificationType short_type() { return VerificationType(Short); }
141   static VerificationType double2_type()
142     { return VerificationType(Double_2nd); }
143 
144   // "check" types are used for queries.  A "check" type is not assignable
145   // to anything, but the specified types are assignable to a "check".  For
146   // example, any category1 primitive is assignable to category1_check and
147   // any reference is assignable to reference_check.
148   static VerificationType reference_check()
149     { return VerificationType(ReferenceQuery); }


150   static VerificationType category1_check()
151     { return VerificationType(Category1Query); }
152   static VerificationType category2_check()
153     { return VerificationType(Category2Query); }
154   static VerificationType category2_2nd_check()
155     { return VerificationType(Category2_2ndQuery); }


156 
157   // For reference types, store the actual Symbol
158   static VerificationType reference_type(Symbol* sh) {
159       assert(((uintptr_t)sh & 0x3) == 0, "Symbols must be aligned");
160       // If the above assert fails in the future because oop* isn't aligned,
161       // then this type encoding system will have to change to have a tag value
162       // to discriminate between oops and primitives.
163       return VerificationType((uintptr_t)sh);
164   }
165   static VerificationType uninitialized_type(u2 bci)
166     { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
167   static VerificationType uninitialized_this_type()
168     { return uninitialized_type(BciForThis); }
169 











170   // Create based on u1 read from classfile
171   static VerificationType from_tag(u1 tag);
172 
173   bool is_bogus() const     { return (_u._data == Bogus); }
174   bool is_null() const      { return (_u._data == Null); }
175   bool is_boolean() const   { return (_u._data == Boolean); }
176   bool is_byte() const      { return (_u._data == Byte); }
177   bool is_char() const      { return (_u._data == Char); }
178   bool is_short() const     { return (_u._data == Short); }
179   bool is_integer() const   { return (_u._data == Integer); }
180   bool is_long() const      { return (_u._data == Long); }
181   bool is_float() const     { return (_u._data == Float); }
182   bool is_double() const    { return (_u._data == Double); }
183   bool is_long2() const     { return (_u._data == Long_2nd); }
184   bool is_double2() const   { return (_u._data == Double_2nd); }
185   bool is_reference() const { return ((_u._data & TypeMask) == Reference); }

186   bool is_category1() const {
187     // This should return true for all one-word types, which are category1
188     // primitives, and references (including uninitialized refs).  Though
189     // the 'query' types should technically return 'false' here, if we
190     // allow this to return true, we can perform the test using only
191     // 2 operations rather than 8 (3 masks, 3 compares and 2 logical 'ands').
192     // Since no one should call this on a query type anyway, this is ok.
193     assert(!is_check(), "Must not be a check type (wrong value returned)");
194     return ((_u._data & Category1) != Primitive);
195     // should only return false if it's a primitive, and the category1 flag
196     // is not set.
197   }
198   bool is_category2() const { return ((_u._data & Category2) == Category2); }
199   bool is_category2_2nd() const {
200     return ((_u._data & Category2_2nd) == Category2_2nd);
201   }
202   bool is_reference_check() const { return _u._data == ReferenceQuery; }


203   bool is_category1_check() const { return _u._data == Category1Query; }
204   bool is_category2_check() const { return _u._data == Category2Query; }
205   bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
206   bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
207 
208   bool is_x_array(char sig) const {
209     return is_null() || (is_array() && (name()->char_at(1) == sig));
210   }
211   bool is_int_array() const { return is_x_array(JVM_SIGNATURE_INT); }
212   bool is_byte_array() const { return is_x_array(JVM_SIGNATURE_BYTE); }
213   bool is_bool_array() const { return is_x_array(JVM_SIGNATURE_BOOLEAN); }
214   bool is_char_array() const { return is_x_array(JVM_SIGNATURE_CHAR); }
215   bool is_short_array() const { return is_x_array(JVM_SIGNATURE_SHORT); }
216   bool is_long_array() const { return is_x_array(JVM_SIGNATURE_LONG); }
217   bool is_float_array() const { return is_x_array(JVM_SIGNATURE_FLOAT); }
218   bool is_double_array() const { return is_x_array(JVM_SIGNATURE_DOUBLE); }
219   bool is_object_array() const { return is_x_array(JVM_SIGNATURE_CLASS); }
220   bool is_array_array() const { return is_x_array(JVM_SIGNATURE_ARRAY); }
221   bool is_reference_array() const
222     { return is_object_array() || is_array_array(); }


223   bool is_object() const
224     { return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
225               name()->char_at(0) != JVM_SIGNATURE_ARRAY); }
226   bool is_array() const
227     { return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
228               name()->char_at(0) == JVM_SIGNATURE_ARRAY); }
229   bool is_uninitialized() const
230     { return ((_u._data & Uninitialized) == Uninitialized); }
231   bool is_uninitialized_this() const
232     { return is_uninitialized() && bci() == BciForThis; }
233 
234   VerificationType to_category2_2nd() const {
235     assert(is_category2(), "Must be a double word");
236     return VerificationType(is_long() ? Long_2nd : Double_2nd);
237   }
238 






239   u2 bci() const {
240     assert(is_uninitialized(), "Must be uninitialized type");
241     return ((_u._data & BciMask) >> 1 * BitsPerByte);
242   }
243 
244   Symbol* name() const {
245     assert(is_reference() && !is_null(), "Must be a non-null reference");
246     return _u._sym;
247   }
248 
249   bool equals(const VerificationType& t) const {
250     return (_u._data == t._u._data ||
251       (is_reference() && t.is_reference() && !is_null() && !t.is_null() &&
252        name() == t.name()));


253   }
254 
255   bool operator ==(const VerificationType& t) const {
256     return equals(t);
257   }
258 
259   bool operator !=(const VerificationType& t) const {
260     return !equals(t);
261   }
262 
263   // The whole point of this type system - check to see if one type
264   // is assignable to another.  Returns true if one can assign 'from' to
265   // this.
266   bool is_assignable_from(
267       const VerificationType& from, ClassVerifier* context,
268       bool from_field_is_protected, TRAPS) const {
269     if (equals(from) || is_bogus()) {
270       return true;
271     } else {
272       switch(_u._data) {
273         case Category1Query:
274           return from.is_category1();
275         case Category2Query:
276           return from.is_category2();
277         case Category2_2ndQuery:
278           return from.is_category2_2nd();
279         case ReferenceQuery:
280           return from.is_reference() || from.is_uninitialized();





281         case Boolean:
282         case Byte:
283         case Char:
284         case Short:
285           // An int can be assigned to boolean, byte, char or short values.
286           return from.is_integer();
287         default:
288           if (is_reference() && from.is_reference()) {




289             return is_reference_assignable_from(from, context,
290                                                 from_field_is_protected,
291                                                 THREAD);
292           } else {
293             return false;
294           }
295       }
296     }
297   }
298 
299   // Check to see if one array component type is assignable to another.
300   // Same as is_assignable_from() except int primitives must be identical.
301   bool is_component_assignable_from(
302       const VerificationType& from, ClassVerifier* context,
303       bool from_field_is_protected, TRAPS) const {
304     if (equals(from) || is_bogus()) {
305       return true;
306     } else {
307       switch(_u._data) {
308         case Boolean:

316     }
317   }
318 
319   VerificationType get_component(ClassVerifier* context) const;
320 
321   int dimensions() const {
322     assert(is_array(), "Must be an array");
323     int index = 0;
324     while (name()->char_at(index) == JVM_SIGNATURE_ARRAY) index++;
325     return index;
326   }
327 
328   void print_on(outputStream* st) const;
329 
330  private:
331 
332   bool is_reference_assignable_from(
333     const VerificationType&, ClassVerifier*, bool from_field_is_protected,
334     TRAPS) const;
335 





336  public:
337   static bool resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
338                                               Symbol* from_name, bool from_field_is_protected,
339                                               bool from_is_array, bool from_is_object,
340                                               TRAPS);
341 };
342 
343 #endif // SHARE_CLASSFILE_VERIFICATIONTYPE_HPP

 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       Symbol*   _sym;
 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 : uint {
 71       // Bottom three bits determine if the type is a reference, inline type,
 72       // primitive, uninitialized or a query-type.
 73       TypeMask           = 0x00000007,
 74 
 75       // Topmost types encoding
 76       Reference          = 0x0,        // _sym contains the name of an object
 77       Primitive          = 0x1,        // see below for primitive list
 78       Uninitialized      = 0x2,        // 0x00ffff00 contains bci
 79       TypeQuery          = 0x3,        // Meta-types used for category testing
 80       InlineType         = 0x4,        // _sym contains the name of an inline type
 81 
 82       // Utility flags
 83       ReferenceFlag      = 0x00,       // For reference query types
 84       Category1Flag      = 0x01,       // One-word values
 85       Category2Flag      = 0x02,       // First word of a two-word value
 86       Category2_2ndFlag  = 0x04,       // Second word of a two-word value
 87       InlineTypeFlag     = 0x08,       // For inline type query types
 88       NonScalarFlag      = 0x10,       // For either inline type or reference queries
 89 
 90       // special reference values
 91       Null               = 0x00000000, // A reference with a 0 sym is null
 92 
 93       // Primitives categories (the second byte determines the category)
 94       Category1          = (Category1Flag     << 1 * BitsPerByte) | Primitive,
 95       Category2          = (Category2Flag     << 1 * BitsPerByte) | Primitive,
 96       Category2_2nd      = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive,
 97 
 98       // Primitive values (type descriminator stored in most-signifcant bytes)
 99       // Bogus needs the " | Primitive".  Else, is_reference(Bogus) returns TRUE.
100       Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Primitive,
101       Boolean            = (ITEM_Boolean    << 2 * BitsPerByte) | Category1,
102       Byte               = (ITEM_Byte       << 2 * BitsPerByte) | Category1,
103       Short              = (ITEM_Short      << 2 * BitsPerByte) | Category1,
104       Char               = (ITEM_Char       << 2 * BitsPerByte) | Category1,
105       Integer            = (ITEM_Integer    << 2 * BitsPerByte) | Category1,
106       Float              = (ITEM_Float      << 2 * BitsPerByte) | Category1,
107       Long               = (ITEM_Long       << 2 * BitsPerByte) | Category2,
108       Double             = (ITEM_Double     << 2 * BitsPerByte) | Category2,
109       Long_2nd           = (ITEM_Long_2nd   << 2 * BitsPerByte) | Category2_2nd,
110       Double_2nd         = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd,
111 
112       // Used by Uninitialized (second and third bytes hold the bci)
113       BciMask            = 0xffff << 1 * BitsPerByte,
114       BciForThis         = ((u2)-1),   // A bci of -1 is an Unintialized-This
115 
116       // Query values
117       ReferenceQuery     = (ReferenceFlag     << 1 * BitsPerByte) | TypeQuery,
118       Category1Query     = (Category1Flag     << 1 * BitsPerByte) | TypeQuery,
119       Category2Query     = (Category2Flag     << 1 * BitsPerByte) | TypeQuery,
120       Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery,
121       InlineTypeQuery    = (InlineTypeFlag    << 1 * BitsPerByte) | TypeQuery,
122       NonScalarQuery     = (NonScalarFlag     << 1 * BitsPerByte) | TypeQuery
123     };
124 
125   VerificationType(uintptr_t raw_data) {
126     _u._data = raw_data;
127   }
128 
129  public:
130 
131   VerificationType() { *this = bogus_type(); }
132 
133   // Create verification types
134   static VerificationType bogus_type() { return VerificationType(Bogus); }
135   static VerificationType top_type() { return bogus_type(); } // alias
136   static VerificationType null_type() { return VerificationType(Null); }
137   static VerificationType integer_type() { return VerificationType(Integer); }
138   static VerificationType float_type() { return VerificationType(Float); }
139   static VerificationType long_type() { return VerificationType(Long); }
140   static VerificationType long2_type() { return VerificationType(Long_2nd); }
141   static VerificationType double_type() { return VerificationType(Double); }
142   static VerificationType boolean_type() { return VerificationType(Boolean); }
143   static VerificationType byte_type() { return VerificationType(Byte); }
144   static VerificationType char_type() { return VerificationType(Char); }
145   static VerificationType short_type() { return VerificationType(Short); }
146   static VerificationType double2_type()
147     { return VerificationType(Double_2nd); }
148 
149   // "check" types are used for queries.  A "check" type is not assignable
150   // to anything, but the specified types are assignable to a "check".  For
151   // example, any category1 primitive is assignable to category1_check and
152   // any reference is assignable to reference_check.
153   static VerificationType reference_check()
154     { return VerificationType(ReferenceQuery); }
155   static VerificationType inline_type_check()
156     { return VerificationType(InlineTypeQuery); }
157   static VerificationType category1_check()
158     { return VerificationType(Category1Query); }
159   static VerificationType category2_check()
160     { return VerificationType(Category2Query); }
161   static VerificationType category2_2nd_check()
162     { return VerificationType(Category2_2ndQuery); }
163   static VerificationType nonscalar_check()
164     { return VerificationType(NonScalarQuery); }
165 
166   // For reference types, store the actual Symbol
167   static VerificationType reference_type(Symbol* sh) {
168       assert(((uintptr_t)sh & TypeMask) == 0, "Symbols must be aligned");
169       // If the above assert fails in the future because oop* isn't aligned,
170       // then this type encoding system will have to change to have a tag value
171       // to discriminate between oops and primitives.
172       return VerificationType((uintptr_t)sh);
173   }
174   static VerificationType uninitialized_type(u2 bci)
175     { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
176   static VerificationType uninitialized_this_type()
177     { return uninitialized_type(BciForThis); }
178 
179   // For inline types, store the actual Symbol* and set the 3rd bit.
180   // Provides a way for an inline type to be distinguished from a reference type.
181   static VerificationType inline_type(Symbol* sh) {
182       assert(((uintptr_t)sh & TypeMask) == 0, "Symbols must be aligned");
183       assert((uintptr_t)sh != 0, "Null is not a valid inline type");
184       // If the above assert fails in the future because oop* isn't aligned,
185       // then this type encoding system will have to change to have a tag value
186       // to discriminate between oops and primitives.
187       return VerificationType((uintptr_t)sh | InlineType);
188   }
189 
190   // Create based on u1 read from classfile
191   static VerificationType from_tag(u1 tag);
192 
193   bool is_bogus() const     { return (_u._data == Bogus); }
194   bool is_null() const      { return (_u._data == Null); }
195   bool is_boolean() const   { return (_u._data == Boolean); }
196   bool is_byte() const      { return (_u._data == Byte); }
197   bool is_char() const      { return (_u._data == Char); }
198   bool is_short() const     { return (_u._data == Short); }
199   bool is_integer() const   { return (_u._data == Integer); }
200   bool is_long() const      { return (_u._data == Long); }
201   bool is_float() const     { return (_u._data == Float); }
202   bool is_double() const    { return (_u._data == Double); }
203   bool is_long2() const     { return (_u._data == Long_2nd); }
204   bool is_double2() const   { return (_u._data == Double_2nd); }
205   bool is_reference() const { return (((_u._data & TypeMask) == Reference) && !is_inline_type_check()); }
206   bool is_inline_type() const { return ((_u._data & TypeMask) == InlineType); }
207   bool is_category1() const {
208     // This should return true for all one-word types, which are category1
209     // primitives, references (including uninitialized refs) and inline types.
210     // Though the 'query' types should technically return 'false' here, if we
211     // allow this to return true, we can perform the test using only
212     // 2 operations rather than 8 (3 masks, 3 compares and 2 logical 'ands').
213     // Since no one should call this on a query type anyway, this is ok.
214     assert(!is_check(), "Must not be a check type (wrong value returned)");
215     return ((_u._data & Category1) != Primitive);
216     // should only return false if it's a primitive, and the category1 flag
217     // is not set.
218   }
219   bool is_category2() const { return ((_u._data & Category2) == Category2); }
220   bool is_category2_2nd() const {
221     return ((_u._data & Category2_2nd) == Category2_2nd);
222   }
223   bool is_reference_check() const { return _u._data == ReferenceQuery; }
224   bool is_inline_type_check() const { return _u._data == InlineTypeQuery; }
225   bool is_nonscalar_check() const { return _u._data == NonScalarQuery; }
226   bool is_category1_check() const { return _u._data == Category1Query; }
227   bool is_category2_check() const { return _u._data == Category2Query; }
228   bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
229   bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
230 
231   bool is_x_array(char sig) const {
232     return is_null() || (is_array() && (name()->char_at(1) == sig));
233   }
234   bool is_int_array() const { return is_x_array(JVM_SIGNATURE_INT); }
235   bool is_byte_array() const { return is_x_array(JVM_SIGNATURE_BYTE); }
236   bool is_bool_array() const { return is_x_array(JVM_SIGNATURE_BOOLEAN); }
237   bool is_char_array() const { return is_x_array(JVM_SIGNATURE_CHAR); }
238   bool is_short_array() const { return is_x_array(JVM_SIGNATURE_SHORT); }
239   bool is_long_array() const { return is_x_array(JVM_SIGNATURE_LONG); }
240   bool is_float_array() const { return is_x_array(JVM_SIGNATURE_FLOAT); }
241   bool is_double_array() const { return is_x_array(JVM_SIGNATURE_DOUBLE); }
242   bool is_object_array() const { return is_x_array(JVM_SIGNATURE_CLASS); }
243   bool is_array_array() const { return is_x_array(JVM_SIGNATURE_ARRAY); }
244   bool is_reference_array() const
245     { return is_object_array() || is_array_array(); }
246   bool is_nonscalar_array() const
247     { return is_object_array() || is_array_array(); }
248   bool is_object() const
249     { return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
250               name()->char_at(0) != JVM_SIGNATURE_ARRAY); }
251   bool is_array() const
252     { return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
253               name()->char_at(0) == JVM_SIGNATURE_ARRAY); }
254   bool is_uninitialized() const
255     { return ((_u._data & Uninitialized) == Uninitialized); }
256   bool is_uninitialized_this() const
257     { return is_uninitialized() && bci() == BciForThis; }
258 
259   VerificationType to_category2_2nd() const {
260     assert(is_category2(), "Must be a double word");
261     return VerificationType(is_long() ? Long_2nd : Double_2nd);
262   }
263 
264   static VerificationType change_ref_to_inline_type(VerificationType ref) {
265     assert(ref.is_reference(), "Bad arg");
266     assert(!ref.is_null(), "Unexpected nullptr");
267     return inline_type(ref.name());
268   }
269 
270   u2 bci() const {
271     assert(is_uninitialized(), "Must be uninitialized type");
272     return ((_u._data & BciMask) >> 1 * BitsPerByte);
273   }
274 
275   Symbol* name() const {
276     assert(!is_null() && (is_reference() || is_inline_type()), "Must be a non-null reference or an inline type");
277     return (is_reference() ? _u._sym : ((Symbol*)(_u._data & ~(uintptr_t)InlineType)));
278   }
279 
280   bool equals(const VerificationType& t) const {
281     return (_u._data == t._u._data ||
282             (((is_reference() && t.is_reference()) ||
283              (is_inline_type() && t.is_inline_type())) &&
284               !is_null() && !t.is_null() && name() == t.name()));
285 
286   }
287 
288   bool operator ==(const VerificationType& t) const {
289     return equals(t);
290   }
291 
292   bool operator !=(const VerificationType& t) const {
293     return !equals(t);
294   }
295 
296   // The whole point of this type system - check to see if one type
297   // is assignable to another.  Returns true if one can assign 'from' to
298   // this.
299   bool is_assignable_from(
300       const VerificationType& from, ClassVerifier* context,
301       bool from_field_is_protected, TRAPS) const {
302     if (equals(from) || is_bogus()) {
303       return true;
304     } else {
305       switch(_u._data) {
306         case Category1Query:
307           return from.is_category1();
308         case Category2Query:
309           return from.is_category2();
310         case Category2_2ndQuery:
311           return from.is_category2_2nd();
312         case ReferenceQuery:
313           return from.is_reference() || from.is_uninitialized();
314         case NonScalarQuery:
315           return from.is_reference() || from.is_uninitialized() ||
316                  from.is_inline_type();
317         case InlineTypeQuery:
318           return from.is_inline_type();
319         case Boolean:
320         case Byte:
321         case Char:
322         case Short:
323           // An int can be assigned to boolean, byte, char or short values.
324           return from.is_integer();
325         default:
326           if (is_inline_type()) {
327             return is_inline_type_assignable_from(from);
328           } else if (is_reference() && from.is_inline_type()) {
329             return is_ref_assignable_from_inline_type(from, context, THREAD);
330           } else if (is_reference() && from.is_reference()) {
331             return is_reference_assignable_from(from, context,
332                                                 from_field_is_protected,
333                                                 THREAD);
334           } else {
335             return false;
336           }
337       }
338     }
339   }
340 
341   // Check to see if one array component type is assignable to another.
342   // Same as is_assignable_from() except int primitives must be identical.
343   bool is_component_assignable_from(
344       const VerificationType& from, ClassVerifier* context,
345       bool from_field_is_protected, TRAPS) const {
346     if (equals(from) || is_bogus()) {
347       return true;
348     } else {
349       switch(_u._data) {
350         case Boolean:

358     }
359   }
360 
361   VerificationType get_component(ClassVerifier* context) const;
362 
363   int dimensions() const {
364     assert(is_array(), "Must be an array");
365     int index = 0;
366     while (name()->char_at(index) == JVM_SIGNATURE_ARRAY) index++;
367     return index;
368   }
369 
370   void print_on(outputStream* st) const;
371 
372  private:
373 
374   bool is_reference_assignable_from(
375     const VerificationType&, ClassVerifier*, bool from_field_is_protected,
376     TRAPS) const;
377 
378   bool is_inline_type_assignable_from(const VerificationType& from) const;
379 
380   bool is_ref_assignable_from_inline_type(const VerificationType& from, ClassVerifier* context, TRAPS) const;
381 
382 
383  public:
384   static bool resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
385                                               Symbol* from_name, bool from_field_is_protected,
386                                               bool from_is_array, bool from_is_object,
387                                               TRAPS);
388 };
389 
390 #endif // SHARE_CLASSFILE_VERIFICATIONTYPE_HPP
< prev index next >