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