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 class CPKlassSlot VALUE_OBJ_CLASS_SPEC { 66 int _name_index; 67 int _resolved_klass_index; 68 public: 69 CPKlassSlot(int n, int rk) { 70 _name_index = n; 71 _resolved_klass_index = rk; 72 } 73 int name_index() const { 74 return _name_index; 75 } 76 int resolved_klass_index() const { 77 return _resolved_klass_index; 78 } 79 }; 80 81 class KlassSizeStats; 82 83 class ConstantPool : public Metadata { 84 friend class VMStructs; 85 friend class JVMCIVMStructs; 86 friend class BytecodeInterpreter; // Directly extracts a klass in the pool for fast instanceof/checkcast 87 friend class Universe; // For null constructor 88 private: 89 Array<u1>* _tags; // the tag array describing the constant pool's contents 90 ConstantPoolCache* _cache; // the cache holding interpreter runtime information 91 InstanceKlass* _pool_holder; // the corresponding class 92 Array<u2>* _operands; // for variable-sized (InvokeDynamic) nodes, usually empty 93 94 // ... will be changed to support compressed pointers 95 Array<Klass*>* _resolved_klasses; 96 97 enum { 98 _has_preresolution = 1, // Flags 99 _on_stack = 2, 100 _is_shared = 4 101 }; 102 enum { 103 _invalid_resolved_klass_index = 0xffff 104 }; 105 106 int _flags; // old fashioned bit twiddling 107 int _length; // number of elements in the array 108 109 union { 110 // set for CDS to restore resolved references 111 int _resolved_reference_length; 112 // keeps version number for redefined classes (used in backtrace) 113 int _version; 114 } _saved; 115 116 void set_tags(Array<u1>* tags) { _tags = tags; } 117 void tag_at_put(int which, jbyte t) { tags()->at_put(which, t); } 118 void release_tag_at_put(int which, jbyte t) { tags()->release_at_put(which, t); } 119 120 u1* tag_addr_at(int which) const { return tags()->adr_at(which); } 121 122 void set_operands(Array<u2>* operands) { _operands = operands; } 123 124 int flags() const { return _flags; } 238 ConstantPoolCacheEntry* invokedynamic_cp_cache_entry_at(int index) const { 239 // decode index that invokedynamic points to. 240 int cp_cache_index = invokedynamic_cp_cache_index(index); 241 return cache()->entry_at(cp_cache_index); 242 } 243 244 // Assembly code support 245 static int tags_offset_in_bytes() { return offset_of(ConstantPool, _tags); } 246 static int cache_offset_in_bytes() { return offset_of(ConstantPool, _cache); } 247 static int pool_holder_offset_in_bytes() { return offset_of(ConstantPool, _pool_holder); } 248 static int resolved_klasses_offset_in_bytes() { return offset_of(ConstantPool, _resolved_klasses); } 249 250 // Storing constants 251 252 // For temporary use while constructing constant pool 253 void klass_index_at_put(int which, int name_index) { 254 tag_at_put(which, JVM_CONSTANT_ClassIndex); 255 *int_at_addr(which) = name_index; 256 } 257 258 void klass_at_put(int class_index, int name_index, int resolved_klass_index, Klass* k, Symbol* name); 259 260 void unresolved_klass_at_put(int which, int name_index, int resolved_klass_index) { 261 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); 262 263 assert((name_index & 0xffff0000) == 0, "must be"); 264 assert((resolved_klass_index & 0xffff0000) == 0, "must be"); 265 *int_at_addr(which) = 266 build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index); 267 } 268 269 void temp_unresolved_klass_at_put(int which, int name_index) { 270 unresolved_klass_at_put(which, name_index, _invalid_resolved_klass_index); 271 } 272 273 void method_handle_index_at_put(int which, int ref_kind, int ref_index) { 274 tag_at_put(which, JVM_CONSTANT_MethodHandle); 275 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind; 276 } 277 278 void method_type_index_at_put(int which, int ref_index) { 279 tag_at_put(which, JVM_CONSTANT_MethodType); 280 *int_at_addr(which) = ref_index; 281 } 282 283 void invoke_dynamic_at_put(int which, int bootstrap_specifier_index, int name_and_type_index) { 284 tag_at_put(which, JVM_CONSTANT_InvokeDynamic); 285 *int_at_addr(which) = ((jint) name_and_type_index<<16) | bootstrap_specifier_index; 286 } 287 288 void unresolved_string_at_put(int which, Symbol* s) { 289 release_tag_at_put(which, JVM_CONSTANT_String); 290 slot_at_put(which, CPSlot(s)); 291 } 292 379 } 380 381 Symbol* klass_name_at(int which) const; // Returns the name, w/o resolving. 382 int klass_name_index_at(int which) const { 383 return klass_slot_at(which).name_index(); 384 } 385 386 Klass* resolved_klass_at(int which) const { // Used by Compiler 387 guarantee(tag_at(which).is_klass(), "Corrupted constant pool"); 388 // Must do an acquire here in case another thread resolved the klass 389 // behind our back, lest we later load stale values thru the oop. 390 CPKlassSlot kslot = klass_slot_at(which); 391 assert(tag_at(kslot.name_index()).is_symbol(), "sanity"); 392 393 Klass** adr = resolved_klasses()->adr_at(kslot.resolved_klass_index()); 394 return (Klass*)OrderAccess::load_ptr_acquire(adr); 395 } 396 397 // RedefineClasses() API support: 398 Symbol* klass_at_noresolve(int which) { return klass_name_at(which); } 399 400 jint int_at(int which) { 401 assert(tag_at(which).is_int(), "Corrupted constant pool"); 402 return *int_at_addr(which); 403 } 404 405 jlong long_at(int which) { 406 assert(tag_at(which).is_long(), "Corrupted constant pool"); 407 // return *long_at_addr(which); 408 u8 tmp = Bytes::get_native_u8((address)&base()[which]); 409 return *((jlong*)&tmp); 410 } 411 412 jfloat float_at(int which) { 413 assert(tag_at(which).is_float(), "Corrupted constant pool"); 414 return *float_at_addr(which); 415 } 416 417 jdouble double_at(int which) { 418 assert(tag_at(which).is_double(), "Corrupted constant pool"); | 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; } 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 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"); |