< prev index next >

src/share/vm/oops/constantPool.hpp

Print this page


  29 #include "oops/cpCache.hpp"
  30 #include "oops/objArrayOop.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "oops/typeArrayOop.hpp"
  33 #include "runtime/handles.hpp"
  34 #include "utilities/bytes.hpp"
  35 #include "utilities/constantTag.hpp"
  36 
  37 // A ConstantPool is an array containing class constants as described in the
  38 // class file.
  39 //
  40 // Most of the constant pool entries are written during class parsing, which
  41 // is safe.  For klass types, the constant pool entry is
  42 // modified when the entry is resolved.  If a klass constant pool
  43 // entry is read without a lock, only the resolved state guarantees that
  44 // the entry in the constant pool is a klass object and not a Symbol*.
  45 
  46 class SymbolHashMap;
  47 
  48 class CPSlot VALUE_OBJ_CLASS_SPEC {

  49   intptr_t _ptr;

  50  public:
  51   enum TagBits  { _resolved_value = 0, _symbol_bit = 1, _pseudo_bit = 2, _symbol_mask = 3 };
  52 
  53   CPSlot(intptr_t ptr): _ptr(ptr) {}
  54   CPSlot(Klass* ptr): _ptr((intptr_t)ptr) {}
  55   CPSlot(Symbol* ptr): _ptr((intptr_t)ptr | _symbol_bit) {}
  56   CPSlot(Symbol* ptr, int tag_bits): _ptr((intptr_t)ptr | tag_bits) {}
  57 
  58   intptr_t value()   { return _ptr; }
  59   bool is_resolved()      { return (_ptr & _symbol_bit ) == _resolved_value; }
  60   bool is_unresolved()    { return (_ptr & _symbol_bit ) != _resolved_value; }
  61   bool is_pseudo_string() { return (_ptr & _symbol_mask) == _symbol_bit + _pseudo_bit; }
  62 
  63   Symbol* get_symbol() {
  64     assert(is_unresolved(), "bad call");
  65     return (Symbol*)(_ptr & ~_symbol_mask);
  66   }
  67   Klass* get_klass() {
  68     assert(is_resolved(), "bad call");
  69     return (Klass*)_ptr;
























  70   }
  71 };
  72 
  73 class KlassSizeStats;
  74 
  75 class ConstantPool : public Metadata {
  76   friend class VMStructs;
  77   friend class JVMCIVMStructs;
  78   friend class BytecodeInterpreter;  // Directly extracts a klass in the pool for fast instanceof/checkcast
  79   friend class Universe;             // For null constructor
  80  private:
  81   Array<u1>*           _tags;        // the tag array describing the constant pool's contents
  82   ConstantPoolCache*   _cache;       // the cache holding interpreter runtime information
  83   InstanceKlass*       _pool_holder; // the corresponding class
  84   Array<u2>*           _operands;    // for variable-sized (InvokeDynamic) nodes, usually empty
  85 
  86   // Array of resolved objects from the constant pool and map from resolved
  87   // object index to original constant pool index
  88   jobject              _resolved_references;
  89   Array<u2>*           _reference_map;
  90 
  91   enum {
  92     _has_preresolution = 1,           // Flags
  93     _on_stack          = 2

  94   };
  95 
  96   int                  _flags;  // old fashioned bit twiddling
  97   int                  _length; // number of elements in the array
  98 
  99   union {
 100     // set for CDS to restore resolved references
 101     int                _resolved_reference_length;
 102     // keeps version number for redefined classes (used in backtrace)
 103     int                _version;
 104   } _saved;
 105 
 106   void set_tags(Array<u1>* tags)               { _tags = tags; }
 107   void tag_at_put(int which, jbyte t)          { tags()->at_put(which, t); }
 108   void release_tag_at_put(int which, jbyte t)  { tags()->release_at_put(which, t); }
 109 
 110   u1* tag_addr_at(int which) const             { return tags()->adr_at(which); }
 111 
 112   void set_operands(Array<u2>* operands)       { _operands = operands; }
 113 
 114   int flags() const                            { return _flags; }
 115   void set_flags(int f)                        { _flags = f; }
 116 
 117  private:
 118   intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); }
 119 
 120   CPSlot slot_at(int which) const {
 121     assert(is_within_bounds(which), "index out of bounds");

 122     // Uses volatile because the klass slot changes without a lock.
 123     volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which));
 124     assert(adr != 0 || which == 0, "cp entry for klass should not be zero");
 125     return CPSlot(adr);
 126   }
 127 
 128   void slot_at_put(int which, CPSlot s) const {
 129     assert(is_within_bounds(which), "index out of bounds");
 130     assert(s.value() != 0, "Caught something");
 131     *(intptr_t*)&base()[which] = s.value();
 132   }
 133   intptr_t* obj_at_addr_raw(int which) const {
 134     assert(is_within_bounds(which), "index out of bounds");
 135     return (intptr_t*) &base()[which];
 136   }
 137 
 138   jint* int_at_addr(int which) const {
 139     assert(is_within_bounds(which), "index out of bounds");
 140     return (jint*) &base()[which];
 141   }


 149     assert(is_within_bounds(which), "index out of bounds");
 150     return (jfloat*) &base()[which];
 151   }
 152 
 153   jdouble* double_at_addr(int which) const {
 154     assert(is_within_bounds(which), "index out of bounds");
 155     return (jdouble*) &base()[which];
 156   }
 157 
 158   ConstantPool(Array<u1>* tags);
 159   ConstantPool() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
 160  public:
 161   static ConstantPool* allocate(ClassLoaderData* loader_data, int length, TRAPS);
 162 
 163   bool is_constantPool() const volatile     { return true; }
 164 
 165   Array<u1>* tags() const                   { return _tags; }
 166   Array<u2>* operands() const               { return _operands; }
 167 
 168   bool has_preresolution() const            { return (_flags & _has_preresolution) != 0; }
 169   void set_has_preresolution()              { _flags |= _has_preresolution; }



 170 
 171   // Redefine classes support.  If a method refering to this constant pool
 172   // is on the executing stack, or as a handle in vm code, this constant pool
 173   // can't be removed from the set of previous versions saved in the instance
 174   // class.
 175   bool on_stack() const                      { return (_flags &_on_stack) != 0; }
 176   void set_on_stack(const bool value);
 177 



 178   // Klass holding pool
 179   InstanceKlass* pool_holder() const      { return _pool_holder; }
 180   void set_pool_holder(InstanceKlass* k)  { _pool_holder = k; }
 181   InstanceKlass** pool_holder_addr()      { return &_pool_holder; }
 182 
 183   // Interpreter runtime support
 184   ConstantPoolCache* cache() const        { return _cache; }
 185   void set_cache(ConstantPoolCache* cache){ _cache = cache; }
 186 
 187   // Create object cache in the constant pool
 188   void initialize_resolved_references(ClassLoaderData* loader_data,
 189                                       const intStack& reference_map,
 190                                       int constant_pool_map_length,
 191                                       TRAPS);
 192 
 193   // resolved strings, methodHandles and callsite objects from the constant pool
 194   objArrayOop resolved_references()  const;
 195   // mapping resolved object array indexes to cp indexes and back.
 196   int object_to_cp_index(int index)         { return _reference_map->at(index); }
 197   int cp_to_object_index(int index);
 198 





 199   // Invokedynamic indexes.
 200   // They must look completely different from normal indexes.
 201   // The main reason is that byte swapping is sometimes done on normal indexes.
 202   // Finally, it is helpful for debugging to tell the two apart.
 203   static bool is_invokedynamic_index(int i) { return (i < 0); }
 204   static int  decode_invokedynamic_index(int i) { assert(is_invokedynamic_index(i),  ""); return ~i; }
 205   static int  encode_invokedynamic_index(int i) { assert(!is_invokedynamic_index(i), ""); return ~i; }
 206 
 207 
 208   // The invokedynamic points at a CP cache entry.  This entry points back
 209   // at the original CP entry (CONSTANT_InvokeDynamic) and also (via f2) at an entry
 210   // in the resolved_references array (which provides the appendix argument).
 211   int invokedynamic_cp_cache_index(int index) const {
 212     assert (is_invokedynamic_index(index), "should be a invokedynamic index");
 213     int cache_index = decode_invokedynamic_index(index);
 214     return cache_index;
 215   }
 216   ConstantPoolCacheEntry* invokedynamic_cp_cache_entry_at(int index) const {
 217     // decode index that invokedynamic points to.
 218     int cp_cache_index = invokedynamic_cp_cache_index(index);
 219     return cache()->entry_at(cp_cache_index);
 220   }
 221 
 222   // Assembly code support
 223   static int tags_offset_in_bytes()         { return offset_of(ConstantPool, _tags); }
 224   static int cache_offset_in_bytes()        { return offset_of(ConstantPool, _cache); }
 225   static int pool_holder_offset_in_bytes()  { return offset_of(ConstantPool, _pool_holder); }
 226   static int resolved_references_offset_in_bytes() { return offset_of(ConstantPool, _resolved_references); }
 227 
 228   // Storing constants
 229 
 230   void klass_at_put(int which, Klass* k) {
 231     assert(k != NULL, "resolved class shouldn't be null");
 232     assert(is_within_bounds(which), "index out of bounds");
 233     OrderAccess::release_store_ptr((Klass* volatile *)obj_at_addr_raw(which), k);
 234     // The interpreter assumes when the tag is stored, the klass is resolved
 235     // and the Klass* is a klass rather than a Symbol*, so we need
 236     // hardware store ordering here.
 237     release_tag_at_put(which, JVM_CONSTANT_Class);
 238   }
 239 
 240   // For temporary use while constructing constant pool
 241   void klass_index_at_put(int which, int name_index) {
 242     tag_at_put(which, JVM_CONSTANT_ClassIndex);
 243     *int_at_addr(which) = name_index;
 244   }
 245 
 246   // Temporary until actual use
 247   void unresolved_klass_at_put(int which, Symbol* s) {



 248     release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass);
 249     slot_at_put(which, s);




 250   }
 251 
 252   void method_handle_index_at_put(int which, int ref_kind, int ref_index) {
 253     tag_at_put(which, JVM_CONSTANT_MethodHandle);
 254     *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind;
 255   }
 256 
 257   void method_type_index_at_put(int which, int ref_index) {
 258     tag_at_put(which, JVM_CONSTANT_MethodType);
 259     *int_at_addr(which) = ref_index;
 260   }
 261 
 262   void invoke_dynamic_at_put(int which, int bootstrap_specifier_index, int name_and_type_index) {
 263     tag_at_put(which, JVM_CONSTANT_InvokeDynamic);
 264     *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index;
 265   }
 266 
 267   void unresolved_string_at_put(int which, Symbol* s) {
 268     release_tag_at_put(which, JVM_CONSTANT_String);
 269     slot_at_put(which, CPSlot(s, CPSlot::_symbol_bit));
 270   }
 271 
 272   void int_at_put(int which, jint i) {
 273     tag_at_put(which, JVM_CONSTANT_Integer);
 274     *int_at_addr(which) = i;
 275   }
 276 
 277   void long_at_put(int which, jlong l) {
 278     tag_at_put(which, JVM_CONSTANT_Long);
 279     // *long_at_addr(which) = l;
 280     Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l));
 281   }
 282 
 283   void float_at_put(int which, jfloat f) {
 284     tag_at_put(which, JVM_CONSTANT_Float);
 285     *float_at_addr(which) = f;
 286   }
 287 
 288   void double_at_put(int which, jdouble d) {
 289     tag_at_put(which, JVM_CONSTANT_Double);


 331     *int_at_addr(which) = ((jint) signature_index<<16) | name_index;  // Not so nice
 332   }
 333 
 334   // Tag query
 335 
 336   constantTag tag_at(int which) const { return (constantTag)tags()->at_acquire(which); }
 337 
 338   // Fetching constants
 339 
 340   Klass* klass_at(int which, TRAPS) {
 341     constantPoolHandle h_this(THREAD, this);
 342     return klass_at_impl(h_this, which, true, THREAD);
 343   }
 344 
 345   // Version of klass_at that doesn't save the resolution error, called during deopt
 346   Klass* klass_at_ignore_error(int which, TRAPS) {
 347     constantPoolHandle h_this(THREAD, this);
 348     return klass_at_impl(h_this, which, false, THREAD);
 349   }
 350 









 351   Symbol* klass_name_at(int which) const;  // Returns the name, w/o resolving.



 352 
 353   Klass* resolved_klass_at(int which) const {  // Used by Compiler
 354     guarantee(tag_at(which).is_klass(), "Corrupted constant pool");
 355     // Must do an acquire here in case another thread resolved the klass
 356     // behind our back, lest we later load stale values thru the oop.
 357     return CPSlot((Klass*)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which))).get_klass();




 358   }
 359 
 360   // RedefineClasses() API support:
 361   Symbol* klass_at_noresolve(int which) { return klass_name_at(which); }





 362 
 363   jint int_at(int which) {
 364     assert(tag_at(which).is_int(), "Corrupted constant pool");
 365     return *int_at_addr(which);
 366   }
 367 
 368   jlong long_at(int which) {
 369     assert(tag_at(which).is_long(), "Corrupted constant pool");
 370     // return *long_at_addr(which);
 371     u8 tmp = Bytes::get_native_u8((address)&base()[which]);
 372     return *((jlong*)&tmp);
 373   }
 374 
 375   jfloat float_at(int which) {
 376     assert(tag_at(which).is_float(), "Corrupted constant pool");
 377     return *float_at_addr(which);
 378   }
 379 
 380   jdouble double_at(int which) {
 381     assert(tag_at(which).is_double(), "Corrupted constant pool");


 411     assert(tag_at(which).is_string(), "Corrupted constant pool");
 412     return slot_at(which).is_pseudo_string();
 413   }
 414 
 415   oop pseudo_string_at(int which, int obj_index) {
 416     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 417     oop s = resolved_references()->obj_at(obj_index);
 418     return s;
 419   }
 420 
 421   oop pseudo_string_at(int which) {
 422     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 423     int obj_index = cp_to_object_index(which);
 424     oop s = resolved_references()->obj_at(obj_index);
 425     return s;
 426   }
 427 
 428   void pseudo_string_at_put(int which, int obj_index, oop x) {
 429     assert(tag_at(which).is_string(), "Corrupted constant pool");
 430     Symbol* sym = unresolved_string_at(which);
 431     slot_at_put(which, CPSlot(sym, (CPSlot::_symbol_bit | CPSlot::_pseudo_bit)));
 432     string_at_put(which, obj_index, x);    // this works just fine
 433   }
 434 
 435   // only called when we are sure a string entry is already resolved (via an
 436   // earlier string_at call.
 437   oop resolved_string_at(int which) {
 438     assert(tag_at(which).is_string(), "Corrupted constant pool");
 439     // Must do an acquire here in case another thread resolved the klass
 440     // behind our back, lest we later load stale values thru the oop.
 441     // we might want a volatile_obj_at in ObjArrayKlass.
 442     int obj_index = cp_to_object_index(which);
 443     return resolved_references()->obj_at(obj_index);
 444   }
 445 
 446   Symbol* unresolved_string_at(int which) {
 447     assert(tag_at(which).is_string(), "Corrupted constant pool");
 448     Symbol* sym = slot_at(which).get_symbol();
 449     return sym;
 450   }
 451 


 742   int pre_resolve_shared_klasses(TRAPS);
 743 
 744   // Debugging
 745   const char* printable_name_at(int which) PRODUCT_RETURN0;
 746 
 747 #ifdef ASSERT
 748   enum { CPCACHE_INDEX_TAG = 0x10000 };  // helps keep CP cache indices distinct from CP indices
 749 #else
 750   enum { CPCACHE_INDEX_TAG = 0 };        // in product mode, this zero value is a no-op
 751 #endif //ASSERT
 752 
 753   static int decode_cpcache_index(int raw_index, bool invokedynamic_ok = false) {
 754     if (invokedynamic_ok && is_invokedynamic_index(raw_index))
 755       return decode_invokedynamic_index(raw_index);
 756     else
 757       return raw_index - CPCACHE_INDEX_TAG;
 758   }
 759 
 760  private:
 761 
 762   void set_resolved_references(jobject s) { _resolved_references = s; }
 763   Array<u2>* reference_map() const        { return _reference_map; }
 764   void set_reference_map(Array<u2>* o)    { _reference_map = o; }
 765 
 766   // patch JSR 292 resolved references after the class is linked.
 767   void patch_resolved_references(GrowableArray<Handle>* cp_patches);
 768 
 769   Symbol* impl_name_ref_at(int which, bool uncached);
 770   Symbol* impl_signature_ref_at(int which, bool uncached);
 771   int       impl_klass_ref_index_at(int which, bool uncached);
 772   int       impl_name_and_type_ref_index_at(int which, bool uncached);
 773   constantTag impl_tag_ref_at(int which, bool uncached);
 774 
 775   // Used while constructing constant pool (only by ClassFileParser)
 776   jint klass_index_at(int which) {
 777     assert(tag_at(which).is_klass_index(), "Corrupted constant pool");
 778     return *int_at_addr(which);
 779   }
 780 
 781   jint string_index_at(int which) {
 782     assert(tag_at(which).is_string_index(), "Corrupted constant pool");
 783     return *int_at_addr(which);
 784   }




  29 #include "oops/cpCache.hpp"
  30 #include "oops/objArrayOop.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "oops/typeArrayOop.hpp"
  33 #include "runtime/handles.hpp"
  34 #include "utilities/bytes.hpp"
  35 #include "utilities/constantTag.hpp"
  36 
  37 // A ConstantPool is an array containing class constants as described in the
  38 // class file.
  39 //
  40 // Most of the constant pool entries are written during class parsing, which
  41 // is safe.  For klass types, the constant pool entry is
  42 // modified when the entry is resolved.  If a klass constant pool
  43 // entry is read without a lock, only the resolved state guarantees that
  44 // the entry in the constant pool is a klass object and not a Symbol*.
  45 
  46 class SymbolHashMap;
  47 
  48 class CPSlot VALUE_OBJ_CLASS_SPEC {
  49  friend class ConstantPool;
  50   intptr_t _ptr;
  51   enum TagBits  {_pseudo_bit = 1};
  52  public:

  53 
  54   CPSlot(intptr_t ptr): _ptr(ptr) {}
  55   CPSlot(Symbol* ptr, int tag_bits = 0): _ptr((intptr_t)ptr | tag_bits) {}


  56 
  57   intptr_t value()   { return _ptr; }
  58   bool is_pseudo_string() { return (_ptr & _pseudo_bit) != 0; }


  59 
  60   Symbol* get_symbol() {
  61     return (Symbol*)(_ptr & ~_pseudo_bit);

  62   }
  63 };
  64 
  65 // This represents a JVM_CONSTANT_Class, JVM_CONSTANT_UnresolvedClass, or
  66 // JVM_CONSTANT_UnresolvedClassInError slot in the constant pool.
  67 class CPKlassSlot VALUE_OBJ_CLASS_SPEC {
  68   // cp->symbol_at(_name_index) gives the name of the class.
  69   int _name_index;
  70 
  71   // cp->_resolved_klasses->at(_resolved_klass_index) gives the Klass* for the class.
  72   int _resolved_klass_index;
  73 public:
  74   enum {
  75     // This is used during constant pool merging where the resolved klass index is
  76     // not yet known, and will be computed at a later stage (during a call to
  77     // initialize_unresolved_klasses()).
  78     _temp_resolved_klass_index = 0xffff
  79   };
  80   CPKlassSlot(int n, int rk) {
  81     _name_index = n;
  82     _resolved_klass_index = rk;
  83   }
  84   int name_index() const {
  85     return _name_index;
  86   }
  87   int resolved_klass_index() const {
  88     assert(_resolved_klass_index != _temp_resolved_klass_index, "constant pool merging was incomplete");
  89     return _resolved_klass_index;
  90   }
  91 };
  92 
  93 class KlassSizeStats;
  94 
  95 class ConstantPool : public Metadata {
  96   friend class VMStructs;
  97   friend class JVMCIVMStructs;
  98   friend class BytecodeInterpreter;  // Directly extracts a klass in the pool for fast instanceof/checkcast
  99   friend class Universe;             // For null constructor
 100  private:
 101   Array<u1>*           _tags;        // the tag array describing the constant pool's contents
 102   ConstantPoolCache*   _cache;       // the cache holding interpreter runtime information
 103   InstanceKlass*       _pool_holder; // the corresponding class
 104   Array<u2>*           _operands;    // for variable-sized (InvokeDynamic) nodes, usually empty
 105 
 106   // ... will be changed to support compressed pointers
 107   Array<Klass*>*       _resolved_klasses;


 108 
 109   enum {
 110     _has_preresolution = 1,           // Flags
 111     _on_stack          = 2,
 112     _is_shared         = 4
 113   };
 114 
 115   int                  _flags;  // old fashioned bit twiddling
 116   int                  _length; // number of elements in the array
 117 
 118   union {
 119     // set for CDS to restore resolved references
 120     int                _resolved_reference_length;
 121     // keeps version number for redefined classes (used in backtrace)
 122     int                _version;
 123   } _saved;
 124 
 125   void set_tags(Array<u1>* tags)               { _tags = tags; }
 126   void tag_at_put(int which, jbyte t)          { tags()->at_put(which, t); }
 127   void release_tag_at_put(int which, jbyte t)  { tags()->release_at_put(which, t); }
 128 
 129   u1* tag_addr_at(int which) const             { return tags()->adr_at(which); }
 130 
 131   void set_operands(Array<u2>* operands)       { _operands = operands; }
 132 
 133   int flags() const                            { return _flags; }
 134   void set_flags(int f)                        { _flags = f; }
 135 
 136  private:
 137   intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); }
 138 
 139   CPSlot slot_at(int which) const {
 140     assert(is_within_bounds(which), "index out of bounds");
 141     assert(!tag_at(which).is_unresolved_klass() && !tag_at(which).is_unresolved_klass_in_error(), "Corrupted constant pool");
 142     // Uses volatile because the klass slot changes without a lock.
 143     volatile intptr_t adr = (intptr_t)OrderAccess::load_ptr_acquire(obj_at_addr_raw(which));
 144     assert(adr != 0 || which == 0, "cp entry for klass should not be zero");
 145     return CPSlot(adr);
 146   }
 147 
 148   void slot_at_put(int which, CPSlot s) const {
 149     assert(is_within_bounds(which), "index out of bounds");
 150     assert(s.value() != 0, "Caught something");
 151     *(intptr_t*)&base()[which] = s.value();
 152   }
 153   intptr_t* obj_at_addr_raw(int which) const {
 154     assert(is_within_bounds(which), "index out of bounds");
 155     return (intptr_t*) &base()[which];
 156   }
 157 
 158   jint* int_at_addr(int which) const {
 159     assert(is_within_bounds(which), "index out of bounds");
 160     return (jint*) &base()[which];
 161   }


 169     assert(is_within_bounds(which), "index out of bounds");
 170     return (jfloat*) &base()[which];
 171   }
 172 
 173   jdouble* double_at_addr(int which) const {
 174     assert(is_within_bounds(which), "index out of bounds");
 175     return (jdouble*) &base()[which];
 176   }
 177 
 178   ConstantPool(Array<u1>* tags);
 179   ConstantPool() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
 180  public:
 181   static ConstantPool* allocate(ClassLoaderData* loader_data, int length, TRAPS);
 182 
 183   bool is_constantPool() const volatile     { return true; }
 184 
 185   Array<u1>* tags() const                   { return _tags; }
 186   Array<u2>* operands() const               { return _operands; }
 187 
 188   bool has_preresolution() const            { return (_flags & _has_preresolution) != 0; }
 189   void set_has_preresolution() {
 190     assert(!is_shared(), "should never be called on shared ConstantPools");
 191     _flags |= _has_preresolution;
 192   }
 193 
 194   // Redefine classes support.  If a method refering to this constant pool
 195   // is on the executing stack, or as a handle in vm code, this constant pool
 196   // can't be removed from the set of previous versions saved in the instance
 197   // class.
 198   bool on_stack() const                      { return (_flags &_on_stack) != 0; }
 199   void set_on_stack(const bool value);
 200 
 201   // Faster than MetaspaceObj::is_shared() - used by set_on_stack()
 202   bool is_shared() const                     { return (_flags & _is_shared) != 0; }
 203 
 204   // Klass holding pool
 205   InstanceKlass* pool_holder() const      { return _pool_holder; }
 206   void set_pool_holder(InstanceKlass* k)  { _pool_holder = k; }
 207   InstanceKlass** pool_holder_addr()      { return &_pool_holder; }
 208 
 209   // Interpreter runtime support
 210   ConstantPoolCache* cache() const        { return _cache; }
 211   void set_cache(ConstantPoolCache* cache){ _cache = cache; }
 212 
 213   // Create object cache in the constant pool
 214   void initialize_resolved_references(ClassLoaderData* loader_data,
 215                                       const intStack& reference_map,
 216                                       int constant_pool_map_length,
 217                                       TRAPS);
 218 
 219   // resolved strings, methodHandles and callsite objects from the constant pool
 220   objArrayOop resolved_references()  const;
 221   // mapping resolved object array indexes to cp indexes and back.
 222   int object_to_cp_index(int index)         { return reference_map()->at(index); }
 223   int cp_to_object_index(int index);
 224 
 225   void set_resolved_klasses(Array<Klass*>* rk)  { _resolved_klasses = rk; }
 226   Array<Klass*>* resolved_klasses() const       { return _resolved_klasses; }
 227   void allocate_resolved_klasses(ClassLoaderData* loader_data, int num_klasses, TRAPS);
 228   void initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS);
 229 
 230   // Invokedynamic indexes.
 231   // They must look completely different from normal indexes.
 232   // The main reason is that byte swapping is sometimes done on normal indexes.
 233   // Finally, it is helpful for debugging to tell the two apart.
 234   static bool is_invokedynamic_index(int i) { return (i < 0); }
 235   static int  decode_invokedynamic_index(int i) { assert(is_invokedynamic_index(i),  ""); return ~i; }
 236   static int  encode_invokedynamic_index(int i) { assert(!is_invokedynamic_index(i), ""); return ~i; }
 237 
 238 
 239   // The invokedynamic points at a CP cache entry.  This entry points back
 240   // at the original CP entry (CONSTANT_InvokeDynamic) and also (via f2) at an entry
 241   // in the resolved_references array (which provides the appendix argument).
 242   int invokedynamic_cp_cache_index(int index) const {
 243     assert (is_invokedynamic_index(index), "should be a invokedynamic index");
 244     int cache_index = decode_invokedynamic_index(index);
 245     return cache_index;
 246   }
 247   ConstantPoolCacheEntry* invokedynamic_cp_cache_entry_at(int index) const {
 248     // decode index that invokedynamic points to.
 249     int cp_cache_index = invokedynamic_cp_cache_index(index);
 250     return cache()->entry_at(cp_cache_index);
 251   }
 252 
 253   // Assembly code support
 254   static int tags_offset_in_bytes()         { return offset_of(ConstantPool, _tags); }
 255   static int cache_offset_in_bytes()        { return offset_of(ConstantPool, _cache); }
 256   static int pool_holder_offset_in_bytes()  { return offset_of(ConstantPool, _pool_holder); }
 257   static int resolved_klasses_offset_in_bytes()    { return offset_of(ConstantPool, _resolved_klasses); }
 258 
 259   // Storing constants
 260 










 261   // For temporary use while constructing constant pool
 262   void klass_index_at_put(int which, int name_index) {
 263     tag_at_put(which, JVM_CONSTANT_ClassIndex);
 264     *int_at_addr(which) = name_index;
 265   }
 266 
 267   // Anonymous class support:
 268   void klass_at_put(int class_index, int name_index, int resolved_klass_index, Klass* k, Symbol* name);
 269   void klass_at_put(int class_index, Klass* k);
 270 
 271   void unresolved_klass_at_put(int which, int name_index, int resolved_klass_index) {
 272     release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass);
 273 
 274     assert((name_index & 0xffff0000) == 0, "must be");
 275     assert((resolved_klass_index & 0xffff0000) == 0, "must be");
 276     *int_at_addr(which) =
 277       build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index);
 278   }
 279 
 280   void method_handle_index_at_put(int which, int ref_kind, int ref_index) {
 281     tag_at_put(which, JVM_CONSTANT_MethodHandle);
 282     *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind;
 283   }
 284 
 285   void method_type_index_at_put(int which, int ref_index) {
 286     tag_at_put(which, JVM_CONSTANT_MethodType);
 287     *int_at_addr(which) = ref_index;
 288   }
 289 
 290   void invoke_dynamic_at_put(int which, int bootstrap_specifier_index, int name_and_type_index) {
 291     tag_at_put(which, JVM_CONSTANT_InvokeDynamic);
 292     *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index;
 293   }
 294 
 295   void unresolved_string_at_put(int which, Symbol* s) {
 296     release_tag_at_put(which, JVM_CONSTANT_String);
 297     slot_at_put(which, CPSlot(s));
 298   }
 299 
 300   void int_at_put(int which, jint i) {
 301     tag_at_put(which, JVM_CONSTANT_Integer);
 302     *int_at_addr(which) = i;
 303   }
 304 
 305   void long_at_put(int which, jlong l) {
 306     tag_at_put(which, JVM_CONSTANT_Long);
 307     // *long_at_addr(which) = l;
 308     Bytes::put_native_u8((address)long_at_addr(which), *((u8*) &l));
 309   }
 310 
 311   void float_at_put(int which, jfloat f) {
 312     tag_at_put(which, JVM_CONSTANT_Float);
 313     *float_at_addr(which) = f;
 314   }
 315 
 316   void double_at_put(int which, jdouble d) {
 317     tag_at_put(which, JVM_CONSTANT_Double);


 359     *int_at_addr(which) = ((jint) signature_index<<16) | name_index;  // Not so nice
 360   }
 361 
 362   // Tag query
 363 
 364   constantTag tag_at(int which) const { return (constantTag)tags()->at_acquire(which); }
 365 
 366   // Fetching constants
 367 
 368   Klass* klass_at(int which, TRAPS) {
 369     constantPoolHandle h_this(THREAD, this);
 370     return klass_at_impl(h_this, which, true, THREAD);
 371   }
 372 
 373   // Version of klass_at that doesn't save the resolution error, called during deopt
 374   Klass* klass_at_ignore_error(int which, TRAPS) {
 375     constantPoolHandle h_this(THREAD, this);
 376     return klass_at_impl(h_this, which, false, THREAD);
 377   }
 378 
 379   CPKlassSlot klass_slot_at(int which) const {
 380     assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
 381            "Corrupted constant pool");
 382     int value = *int_at_addr(which);
 383     int name_index = extract_high_short_from_int(value);
 384     int resolved_klass_index = extract_low_short_from_int(value);
 385     return CPKlassSlot(name_index, resolved_klass_index);
 386   }
 387 
 388   Symbol* klass_name_at(int which) const;  // Returns the name, w/o resolving.
 389   int klass_name_index_at(int which) const {
 390     return klass_slot_at(which).name_index();
 391   }
 392 
 393   Klass* resolved_klass_at(int which) const {  // Used by Compiler
 394     guarantee(tag_at(which).is_klass(), "Corrupted constant pool");
 395     // Must do an acquire here in case another thread resolved the klass
 396     // behind our back, lest we later load stale values thru the oop.
 397     CPKlassSlot kslot = klass_slot_at(which);
 398     assert(tag_at(kslot.name_index()).is_symbol(), "sanity");
 399 
 400     Klass** adr = resolved_klasses()->adr_at(kslot.resolved_klass_index());
 401     return (Klass*)OrderAccess::load_ptr_acquire(adr);
 402   }
 403 
 404   // RedefineClasses() API support:
 405   Symbol* klass_at_noresolve(int which) { return klass_name_at(which); }
 406   void temp_unresolved_klass_at_put(int which, int name_index) {
 407     // Used only during constant pool merging for class redefinition. The resolved klass index
 408     // will be initialized later by a call to initialize_unresolved_klasses().
 409     unresolved_klass_at_put(which, name_index, CPKlassSlot::_temp_resolved_klass_index);
 410   }
 411 
 412   jint int_at(int which) {
 413     assert(tag_at(which).is_int(), "Corrupted constant pool");
 414     return *int_at_addr(which);
 415   }
 416 
 417   jlong long_at(int which) {
 418     assert(tag_at(which).is_long(), "Corrupted constant pool");
 419     // return *long_at_addr(which);
 420     u8 tmp = Bytes::get_native_u8((address)&base()[which]);
 421     return *((jlong*)&tmp);
 422   }
 423 
 424   jfloat float_at(int which) {
 425     assert(tag_at(which).is_float(), "Corrupted constant pool");
 426     return *float_at_addr(which);
 427   }
 428 
 429   jdouble double_at(int which) {
 430     assert(tag_at(which).is_double(), "Corrupted constant pool");


 460     assert(tag_at(which).is_string(), "Corrupted constant pool");
 461     return slot_at(which).is_pseudo_string();
 462   }
 463 
 464   oop pseudo_string_at(int which, int obj_index) {
 465     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 466     oop s = resolved_references()->obj_at(obj_index);
 467     return s;
 468   }
 469 
 470   oop pseudo_string_at(int which) {
 471     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 472     int obj_index = cp_to_object_index(which);
 473     oop s = resolved_references()->obj_at(obj_index);
 474     return s;
 475   }
 476 
 477   void pseudo_string_at_put(int which, int obj_index, oop x) {
 478     assert(tag_at(which).is_string(), "Corrupted constant pool");
 479     Symbol* sym = unresolved_string_at(which);
 480     slot_at_put(which, CPSlot(sym, CPSlot::_pseudo_bit));
 481     string_at_put(which, obj_index, x);    // this works just fine
 482   }
 483 
 484   // only called when we are sure a string entry is already resolved (via an
 485   // earlier string_at call.
 486   oop resolved_string_at(int which) {
 487     assert(tag_at(which).is_string(), "Corrupted constant pool");
 488     // Must do an acquire here in case another thread resolved the klass
 489     // behind our back, lest we later load stale values thru the oop.
 490     // we might want a volatile_obj_at in ObjArrayKlass.
 491     int obj_index = cp_to_object_index(which);
 492     return resolved_references()->obj_at(obj_index);
 493   }
 494 
 495   Symbol* unresolved_string_at(int which) {
 496     assert(tag_at(which).is_string(), "Corrupted constant pool");
 497     Symbol* sym = slot_at(which).get_symbol();
 498     return sym;
 499   }
 500 


 791   int pre_resolve_shared_klasses(TRAPS);
 792 
 793   // Debugging
 794   const char* printable_name_at(int which) PRODUCT_RETURN0;
 795 
 796 #ifdef ASSERT
 797   enum { CPCACHE_INDEX_TAG = 0x10000 };  // helps keep CP cache indices distinct from CP indices
 798 #else
 799   enum { CPCACHE_INDEX_TAG = 0 };        // in product mode, this zero value is a no-op
 800 #endif //ASSERT
 801 
 802   static int decode_cpcache_index(int raw_index, bool invokedynamic_ok = false) {
 803     if (invokedynamic_ok && is_invokedynamic_index(raw_index))
 804       return decode_invokedynamic_index(raw_index);
 805     else
 806       return raw_index - CPCACHE_INDEX_TAG;
 807   }
 808 
 809  private:
 810 
 811   void set_resolved_references(jobject s) { _cache->set_resolved_references(s); }
 812   Array<u2>* reference_map() const        {  return (_cache == NULL) ? NULL :  _cache->reference_map(); }
 813   void set_reference_map(Array<u2>* o)    { _cache->set_reference_map(o); }
 814 
 815   // patch JSR 292 resolved references after the class is linked.
 816   void patch_resolved_references(GrowableArray<Handle>* cp_patches);
 817 
 818   Symbol* impl_name_ref_at(int which, bool uncached);
 819   Symbol* impl_signature_ref_at(int which, bool uncached);
 820   int       impl_klass_ref_index_at(int which, bool uncached);
 821   int       impl_name_and_type_ref_index_at(int which, bool uncached);
 822   constantTag impl_tag_ref_at(int which, bool uncached);
 823 
 824   // Used while constructing constant pool (only by ClassFileParser)
 825   jint klass_index_at(int which) {
 826     assert(tag_at(which).is_klass_index(), "Corrupted constant pool");
 827     return *int_at_addr(which);
 828   }
 829 
 830   jint string_index_at(int which) {
 831     assert(tag_at(which).is_string_index(), "Corrupted constant pool");
 832     return *int_at_addr(which);
 833   }


< prev index next >