< prev index next >

src/share/vm/classfile/verificationType.hpp

Print this page




  53   private:
  54     // Least significant bits of _handle are always 0, so we use these as
  55     // the indicator that the _handle is valid.  Otherwise, the _data field
  56     // contains encoded data (as specified below).  Should the VM change
  57     // and the lower bits on oops aren't 0, the assert in the constructor
  58     // will catch this and we'll have to add a descriminator tag to this
  59     // structure.
  60     union {
  61       Symbol*   _sym;
  62       uintptr_t _data;
  63     } _u;
  64 
  65     enum {
  66       // These rest are not found in classfiles, but used by the verifier
  67       ITEM_Boolean = 9, ITEM_Byte, ITEM_Short, ITEM_Char,
  68       ITEM_Long_2nd, ITEM_Double_2nd
  69     };
  70 
  71     // Enum for the _data field
  72     enum {
  73       // Bottom two bits determine if the type is a reference, primitive,
  74       // uninitialized or a query-type.
  75       TypeMask           = 0x00000003,
  76 
  77       // Topmost types encoding
  78       Reference          = 0x0,        // _sym contains the name
  79       Primitive          = 0x1,        // see below for primitive list
  80       Uninitialized      = 0x2,        // 0x00ffff00 contains bci
  81       TypeQuery          = 0x3,        // Meta-types used for category testing

  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 
  89       // special reference values
  90       Null               = 0x00000000, // A reference with a 0 sym is null
  91 
  92       // Primitives categories (the second byte determines the category)
  93       Category1          = (Category1Flag     << 1 * BitsPerByte) | Primitive,
  94       Category2          = (Category2Flag     << 1 * BitsPerByte) | Primitive,
  95       Category2_2nd      = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive,
  96 
  97       // Primitive values (type descriminator stored in most-signifcant bytes)
  98       // Bogus needs the " | Primitive".  Else, is_reference(Bogus) returns TRUE.
  99       Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Primitive,
 100       Boolean            = (ITEM_Boolean    << 2 * BitsPerByte) | Category1,
 101       Byte               = (ITEM_Byte       << 2 * BitsPerByte) | Category1,
 102       Short              = (ITEM_Short      << 2 * BitsPerByte) | Category1,
 103       Char               = (ITEM_Char       << 2 * BitsPerByte) | Category1,
 104       Integer            = (ITEM_Integer    << 2 * BitsPerByte) | Category1,
 105       Float              = (ITEM_Float      << 2 * BitsPerByte) | Category1,
 106       Long               = (ITEM_Long       << 2 * BitsPerByte) | Category2,
 107       Double             = (ITEM_Double     << 2 * BitsPerByte) | Category2,
 108       Long_2nd           = (ITEM_Long_2nd   << 2 * BitsPerByte) | Category2_2nd,
 109       Double_2nd         = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd,
 110 
 111       // Used by Uninitialized (second and third bytes hold the bci)
 112       BciMask            = 0xffff << 1 * BitsPerByte,
 113       BciForThis         = ((u2)-1),   // A bci of -1 is an Unintialized-This
 114 
 115       // Query values
 116       ReferenceQuery     = (ReferenceFlag     << 1 * BitsPerByte) | TypeQuery,
 117       Category1Query     = (Category1Flag     << 1 * BitsPerByte) | TypeQuery,
 118       Category2Query     = (Category2Flag     << 1 * BitsPerByte) | TypeQuery,
 119       Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery

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


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











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

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

 205   bool is_category1_check() const { return _u._data == Category1Query; }
 206   bool is_category2_check() const { return _u._data == Category2Query; }
 207   bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
 208   bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
 209 
 210   bool is_x_array(char sig) const {
 211     return is_null() || (is_array() && (name()->byte_at(1) == sig));
 212   }
 213   bool is_int_array() const { return is_x_array('I'); }
 214   bool is_byte_array() const { return is_x_array('B'); }
 215   bool is_bool_array() const { return is_x_array('Z'); }
 216   bool is_char_array() const { return is_x_array('C'); }
 217   bool is_short_array() const { return is_x_array('S'); }
 218   bool is_long_array() const { return is_x_array('J'); }
 219   bool is_float_array() const { return is_x_array('F'); }
 220   bool is_double_array() const { return is_x_array('D'); }
 221   bool is_object_array() const { return is_x_array('L'); }

 222   bool is_array_array() const { return is_x_array('['); }
 223   bool is_reference_array() const
 224     { return is_object_array() || is_array_array(); }
 225   bool is_object() const
 226     { return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
 227               name()->byte_at(0) != '['); }
 228   bool is_array() const
 229     { return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
 230               name()->byte_at(0) == '['); }
 231   bool is_uninitialized() const
 232     { return ((_u._data & Uninitialized) == Uninitialized); }
 233   bool is_uninitialized_this() const
 234     { return is_uninitialized() && bci() == BciForThis; }
 235 
 236   VerificationType to_category2_2nd() const {
 237     assert(is_category2(), "Must be a double word");
 238     return VerificationType(is_long() ? Long_2nd : Double_2nd);
 239   }
 240 
 241   u2 bci() const {
 242     assert(is_uninitialized(), "Must be uninitialized type");
 243     return ((_u._data & BciMask) >> 1 * BitsPerByte);
 244   }
 245 
 246   Symbol* name() const {
 247     assert(is_reference() && !is_null(), "Must be a non-null reference");
 248     return _u._sym;
 249   }
 250 
 251   bool equals(const VerificationType& t) const {
 252     return (_u._data == t._u._data ||
 253       (is_reference() && t.is_reference() && !is_null() && !t.is_null() &&
 254        name() == t.name()));
 255   }
 256 
 257   bool operator ==(const VerificationType& t) const {
 258     return equals(t);
 259   }
 260 
 261   bool operator !=(const VerificationType& t) const {
 262     return !equals(t);
 263   }
 264 
 265   // The whole point of this type system - check to see if one type
 266   // is assignable to another.  Returns true if one can assign 'from' to
 267   // this.
 268   bool is_assignable_from(
 269       const VerificationType& from, ClassVerifier* context,
 270       bool from_field_is_protected, TRAPS) const {
 271     if (equals(from) || is_bogus()) {
 272       return true;
 273     } else {
 274       switch(_u._data) {
 275         case Category1Query:
 276           return from.is_category1();
 277         case Category2Query:
 278           return from.is_category2();
 279         case Category2_2ndQuery:
 280           return from.is_category2_2nd();
 281         case ReferenceQuery:
 282           return from.is_reference() || from.is_uninitialized();


 283         case Boolean:
 284         case Byte:
 285         case Char:
 286         case Short:
 287           // An int can be assigned to boolean, byte, char or short values.
 288           return from.is_integer();
 289         default:
 290           if (is_reference() && from.is_reference()) {
 291             return is_reference_assignable_from(from, context,
 292                                                 from_field_is_protected,
 293                                                 THREAD);


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


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








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


  53   private:
  54     // Least significant bits of _handle are always 0, so we use these as
  55     // the indicator that the _handle is valid.  Otherwise, the _data field
  56     // contains encoded data (as specified below).  Should the VM change
  57     // and the lower bits on oops aren't 0, the assert in the constructor
  58     // will catch this and we'll have to add a descriminator tag to this
  59     // structure.
  60     union {
  61       Symbol*   _sym;
  62       uintptr_t _data;
  63     } _u;
  64 
  65     enum {
  66       // These rest are not found in classfiles, but used by the verifier
  67       ITEM_Boolean = 9, ITEM_Byte, ITEM_Short, ITEM_Char,
  68       ITEM_Long_2nd, ITEM_Double_2nd
  69     };
  70 
  71     // Enum for the _data field
  72     enum {
  73       // Bottom three bits determine if the type is a reference, value type,
  74       // primitive, uninitialized or a query-type.
  75       TypeMask           = 0x00000007,
  76 
  77       // Topmost types encoding
  78       Reference          = 0x0,        // _sym contains the name of an object 
  79       Primitive          = 0x1,        // see below for primitive list
  80       Uninitialized      = 0x2,        // 0x00ffff00 contains bci
  81       TypeQuery          = 0x3,        // Meta-types used for category testing
  82       ValueType          = 0x4,        // _sym contains the name of a value type
  83 
  84       // Utility flags
  85       ReferenceFlag      = 0x00,       // For reference query types
  86       Category1Flag      = 0x01,       // One-word values
  87       Category2Flag      = 0x02,       // First word of a two-word value
  88       Category2_2ndFlag  = 0x04,       // Second word of a two-word value
  89       ValueTypeFlag      = 0x08,       // For value type query types
  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     };
 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 valuetype_check()
 156     { return VerificationType(ValueTypeQuery); }
 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 
 164   // For reference types, store the actual Symbol
 165   static VerificationType reference_type(Symbol* sh) {
 166       assert(((uintptr_t)sh & TypeMask) == 0, "Symbols must be aligned");
 167       // If the above assert fails in the future because oop* isn't aligned,
 168       // then this type encoding system will have to change to have a tag value
 169       // to descriminate between oops and primitives.
 170       return VerificationType((uintptr_t)sh);
 171   }  
 172   static VerificationType uninitialized_type(u2 bci)
 173     { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
 174   static VerificationType uninitialized_this_type()
 175     { return uninitialized_type(BciForThis); }
 176 
 177   // For value types, store the actual Symbol* and set the 3rd bit.
 178   // Provides a way for a value type to be distinguished from a reference type.
 179   static VerificationType valuetype_type(Symbol* sh) {
 180       assert(((uintptr_t)sh & TypeMask) == 0, "Symbols must be aligned");
 181       assert((uintptr_t)sh != 0, "Null is not a valid value type");
 182       // If the above assert fails in the future because oop* isn't aligned,
 183       // then this type encoding system will have to change to have a tag value
 184       // to descriminate between oops and primitives.
 185       return VerificationType((uintptr_t)sh | ValueType);
 186   }
 187 
 188   // Create based on u1 read from classfile
 189   static VerificationType from_tag(u1 tag);
 190 
 191   bool is_bogus() const     { return (_u._data == Bogus); }
 192   bool is_null() const      { return (_u._data == Null); }
 193   bool is_boolean() const   { return (_u._data == Boolean); }
 194   bool is_byte() const      { return (_u._data == Byte); }
 195   bool is_char() const      { return (_u._data == Char); }
 196   bool is_short() const     { return (_u._data == Short); }
 197   bool is_integer() const   { return (_u._data == Integer); }
 198   bool is_long() const      { return (_u._data == Long); }
 199   bool is_float() const     { return (_u._data == Float); }
 200   bool is_double() const    { return (_u._data == Double); }
 201   bool is_long2() const     { return (_u._data == Long_2nd); }
 202   bool is_double2() const   { return (_u._data == Double_2nd); }
 203   bool is_reference() const { return (((_u._data & TypeMask) == Reference) && !is_valuetype_check()); }
 204   bool is_valuetype() const { return ((_u._data & TypeMask) == ValueType); }
 205   bool is_category1() const {
 206     // This should return true for all one-word types, which are category1
 207     // primitives, references (including uninitialized refs) and value types.
 208     // Though the 'query' types should technically return 'false' here, if we
 209     // allow this to return true, we can perform the test using only
 210     // 2 operations rather than 8 (3 masks, 3 compares and 2 logical 'ands').
 211     // Since noone should call this on a query type anyway, this is ok.
 212     assert(!is_check(), "Must not be a check type (wrong value returned)");
 213     return ((_u._data & Category1) != Primitive);
 214     // should only return false if it's a primitive, and the category1 flag
 215     // is not set.
 216   }
 217   bool is_category2() const { return ((_u._data & Category2) == Category2); }
 218   bool is_category2_2nd() const {
 219     return ((_u._data & Category2_2nd) == Category2_2nd);
 220   }
 221   bool is_reference_check() const { return _u._data == ReferenceQuery; }
 222   bool is_valuetype_check() const { return _u._data == ValueTypeQuery; }
 223   bool is_category1_check() const { return _u._data == Category1Query; }
 224   bool is_category2_check() const { return _u._data == Category2Query; }
 225   bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
 226   bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
 227 
 228   bool is_x_array(char sig) const {
 229     return is_null() || (is_array() && (name()->byte_at(1) == sig));
 230   }
 231   bool is_int_array() const { return is_x_array('I'); }
 232   bool is_byte_array() const { return is_x_array('B'); }
 233   bool is_bool_array() const { return is_x_array('Z'); }
 234   bool is_char_array() const { return is_x_array('C'); }
 235   bool is_short_array() const { return is_x_array('S'); }
 236   bool is_long_array() const { return is_x_array('J'); }
 237   bool is_float_array() const { return is_x_array('F'); }
 238   bool is_double_array() const { return is_x_array('D'); }
 239   bool is_object_array() const { return is_x_array('L'); }
 240   bool is_value_array() const { return is_x_array('Q'); }
 241   bool is_array_array() const { return is_x_array('['); }
 242   bool is_reference_array() const
 243     { return is_object_array() || is_array_array(); }
 244   bool is_object() const
 245     { return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
 246               name()->byte_at(0) != '['); }
 247   bool is_array() const
 248     { return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
 249               name()->byte_at(0) == '['); }
 250   bool is_uninitialized() const
 251     { return ((_u._data & Uninitialized) == Uninitialized); }
 252   bool is_uninitialized_this() const
 253     { return is_uninitialized() && bci() == BciForThis; }
 254 
 255   VerificationType to_category2_2nd() const {
 256     assert(is_category2(), "Must be a double word");
 257     return VerificationType(is_long() ? Long_2nd : Double_2nd);
 258   }
 259 
 260   u2 bci() const {
 261     assert(is_uninitialized(), "Must be uninitialized type");
 262     return ((_u._data & BciMask) >> 1 * BitsPerByte);
 263   }
 264 
 265   Symbol* name() const {
 266     assert(!is_null() && (is_reference() || is_valuetype()), "Must be a non-null reference or a value type");
 267     return (is_reference() ? _u._sym : ((Symbol*)(_u._data & ~(uintptr_t)ValueType)));
 268   }
 269 
 270   bool equals(const VerificationType& t) const {
 271     return (_u._data == t._u._data ||
 272             (((is_reference() && t.is_reference()) || (is_valuetype() && t.is_valuetype())) &&
 273              !is_null() && !t.is_null() && name() == t.name()));
 274   }
 275 
 276   bool operator ==(const VerificationType& t) const {
 277     return equals(t);
 278   }
 279 
 280   bool operator !=(const VerificationType& t) const {
 281     return !equals(t);
 282   }
 283 
 284   // The whole point of this type system - check to see if one type
 285   // is assignable to another.  Returns true if one can assign 'from' to
 286   // this.
 287   bool is_assignable_from(
 288       const VerificationType& from, ClassVerifier* context,
 289       bool from_field_is_protected, TRAPS) const {
 290     if (equals(from) || is_bogus()) {
 291       return true;
 292     } else {
 293       switch(_u._data) {
 294         case Category1Query:
 295           return from.is_category1();
 296         case Category2Query:
 297           return from.is_category2();
 298         case Category2_2ndQuery:
 299           return from.is_category2_2nd();
 300         case ReferenceQuery:
 301           return from.is_reference() || from.is_uninitialized();
 302         case ValueTypeQuery:
 303           return from.is_valuetype();
 304         case Boolean:
 305         case Byte:
 306         case Char:
 307         case Short:
 308           // An int can be assigned to boolean, byte, char or short values.
 309           return from.is_integer();
 310         default:
 311           if (is_reference() && from.is_reference()) {
 312             return is_reference_assignable_from(from, context,
 313                                                 from_field_is_protected,
 314                                                 THREAD);
 315           } else if (is_valuetype() && from.is_valuetype()) {
 316             return is_valuetype_assignable_from(from, context, THREAD);
 317           } else {
 318             return false;
 319           }
 320       }
 321     }
 322   }
 323 
 324   // Check to see if one array component type is assignable to another.
 325   // Same as is_assignable_from() except int primitives must be identical.
 326   bool is_component_assignable_from(
 327       const VerificationType& from, ClassVerifier* context,
 328       bool from_field_is_protected, TRAPS) const {
 329     if (equals(from) || is_bogus()) {
 330       return true;
 331     } else {
 332       switch(_u._data) {
 333         case Boolean:
 334         case Byte:
 335         case Char:
 336         case Short:


 340       }
 341     }
 342   }
 343 
 344   VerificationType get_component(ClassVerifier* context, TRAPS) const;
 345 
 346   int dimensions() const {
 347     assert(is_array(), "Must be an array");
 348     int index = 0;
 349     while (name()->byte_at(index) == '[') index++;
 350     return index;
 351   }
 352 
 353   void print_on(outputStream* st) const;
 354 
 355  private:
 356 
 357   bool is_reference_assignable_from(
 358     const VerificationType&, ClassVerifier*, bool from_field_is_protected,
 359     TRAPS) const;
 360 
 361   bool is_valuetype_assignable_from(const VerificationType& from, ClassVerifier* context, TRAPS) const {
 362     // 1. Check names - two value types are assignable if they have the same name
 363     // 2. Check java/lang/__Value - from may be trying to be assigned to a __Value parameter
 364     assert(is_valuetype() && from.is_valuetype(), "Is value type assignable called with a non-value type");
 365     return (name() == from.name() ||
 366             name() == vmSymbols::java_lang____Value());
 367   }
 368 
 369  public:
 370   static bool resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
 371                                               Symbol* from_name, bool from_field_is_protected,
 372                                               bool from_is_array, bool from_is_object,
 373                                               TRAPS);
 374 };
 375 
 376 #endif // SHARE_VM_CLASSFILE_VERIFICATIONTYPE_HPP
< prev index next >