65 _temp_resolved_klass_index = 0xffff
66 };
67 CPKlassSlot(int n, int rk) {
68 _name_index = n;
69 _resolved_klass_index = rk;
70 }
71 int name_index() const {
72 return _name_index;
73 }
74 int resolved_klass_index() const {
75 assert(_resolved_klass_index != _temp_resolved_klass_index, "constant pool merging was incomplete");
76 return _resolved_klass_index;
77 }
78 };
79
80 class ConstantPool : public Metadata {
81 friend class VMStructs;
82 friend class JVMCIVMStructs;
83 friend class BytecodeInterpreter; // Directly extracts a klass in the pool for fast instanceof/checkcast
84 friend class Universe; // For null constructor
85 friend class ClassPrelinker; // CDS
86 private:
87 // If you add a new field that points to any metaspace object, you
88 // must add this field to ConstantPool::metaspace_pointers_do().
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 // Consider using an array of compressed klass pointers to
95 // save space on 64-bit platforms.
96 Array<Klass*>* _resolved_klasses;
97
98 u2 _major_version; // major version number of class file
99 u2 _minor_version; // minor version number of class file
100
101 // Constant pool index to the utf8 entry of the Generic signature,
102 // or 0 if none.
103 u2 _generic_signature_index;
104 // Constant pool index to the utf8 entry for the name of source file
105 // containing this klass, 0 if not specified.
106 u2 _source_file_name_index;
107
108 enum {
109 _has_preresolution = 1, // Flags
110 _on_stack = 2,
111 _is_shared = 4,
112 _has_dynamic_constant = 8
113 };
114
115 u2 _flags; // old fashioned bit twiddling
116
117 int _length; // number of elements in the array
118
119 union {
120 // set for CDS to restore resolved references
121 int _resolved_reference_length;
122 // keeps version number for redefined classes (used in backtrace)
123 int _version;
124 } _saved;
125
126 void set_tags(Array<u1>* tags) { _tags = tags; }
127 void tag_at_put(int cp_index, jbyte t) { tags()->at_put(cp_index, t); }
128 void release_tag_at_put(int cp_index, jbyte t) { tags()->release_at_put(cp_index, t); }
129
130 u1* tag_addr_at(int cp_index) const { return tags()->adr_at(cp_index); }
131
132 void set_operands(Array<u2>* operands) { _operands = operands; }
199 }
200 u2 source_file_name_index() const { return _source_file_name_index; }
201 void set_source_file_name_index(u2 sourcefile_index) { _source_file_name_index = sourcefile_index; }
202
203 void copy_fields(const ConstantPool* orig);
204
205 // Redefine classes support. If a method referring to this constant pool
206 // is on the executing stack, or as a handle in vm code, this constant pool
207 // can't be removed from the set of previous versions saved in the instance
208 // class.
209 bool on_stack() const;
210 bool is_maybe_on_stack() const;
211 void set_on_stack(const bool value);
212
213 // Faster than MetaspaceObj::is_shared() - used by set_on_stack()
214 bool is_shared() const { return (_flags & _is_shared) != 0; }
215
216 bool has_dynamic_constant() const { return (_flags & _has_dynamic_constant) != 0; }
217 void set_has_dynamic_constant() { _flags |= _has_dynamic_constant; }
218
219 // Klass holding pool
220 InstanceKlass* pool_holder() const { return _pool_holder; }
221 void set_pool_holder(InstanceKlass* k) { _pool_holder = k; }
222 InstanceKlass** pool_holder_addr() { return &_pool_holder; }
223
224 // Interpreter runtime support
225 ConstantPoolCache* cache() const { return _cache; }
226 void set_cache(ConstantPoolCache* cache){ _cache = cache; }
227
228 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
229 virtual MetaspaceObj::Type type() const { return ConstantPoolType; }
230
231 // Create object cache in the constant pool
232 void initialize_resolved_references(ClassLoaderData* loader_data,
233 const intStack& reference_map,
234 int constant_pool_map_length,
235 TRAPS);
236
237 // resolved strings, methodHandles and callsite objects from the constant pool
238 objArrayOop resolved_references() const;
662
663 int to_cp_index(int which, Bytecodes::Code code);
664
665 bool is_resolved(int which, Bytecodes::Code code);
666
667 // Lookup for entries consisting of (name_index, signature_index)
668 u2 name_ref_index_at(int cp_index); // == low-order jshort of name_and_type_at(cp_index)
669 u2 signature_ref_index_at(int cp_index); // == high-order jshort of name_and_type_at(cp_index)
670
671 BasicType basic_type_for_signature_at(int cp_index) const;
672
673 // Resolve string constants (to prevent allocation during compilation)
674 void resolve_string_constants(TRAPS) {
675 constantPoolHandle h_this(THREAD, this);
676 resolve_string_constants_impl(h_this, CHECK);
677 }
678
679 #if INCLUDE_CDS
680 // CDS support
681 objArrayOop prepare_resolved_references_for_archiving() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
682 void add_dumped_interned_strings() NOT_CDS_JAVA_HEAP_RETURN;
683 void remove_unshareable_info();
684 void restore_unshareable_info(TRAPS);
685 private:
686 void remove_unshareable_entries();
687 void remove_resolved_klass_if_non_deterministic(int cp_index);
688 #endif
689
690 private:
691 enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
692 public:
693
694 // Get the tag for a constant, which may involve a constant dynamic
695 constantTag constant_tag_at(int cp_index);
696 // Get the basic type for a constant, which may involve a constant dynamic
697 BasicType basic_type_for_constant_at(int cp_index);
698
699 // Resolve late bound constants.
700 oop resolve_constant_at(int cp_index, TRAPS) {
701 constantPoolHandle h_this(THREAD, this);
702 return resolve_constant_at_impl(h_this, cp_index, _no_index_sentinel, nullptr, THREAD);
703 }
704
705 oop resolve_cached_constant_at(int cache_index, TRAPS) {
706 constantPoolHandle h_this(THREAD, this);
707 return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, nullptr, THREAD);
|
65 _temp_resolved_klass_index = 0xffff
66 };
67 CPKlassSlot(int n, int rk) {
68 _name_index = n;
69 _resolved_klass_index = rk;
70 }
71 int name_index() const {
72 return _name_index;
73 }
74 int resolved_klass_index() const {
75 assert(_resolved_klass_index != _temp_resolved_klass_index, "constant pool merging was incomplete");
76 return _resolved_klass_index;
77 }
78 };
79
80 class ConstantPool : public Metadata {
81 friend class VMStructs;
82 friend class JVMCIVMStructs;
83 friend class BytecodeInterpreter; // Directly extracts a klass in the pool for fast instanceof/checkcast
84 friend class Universe; // For null constructor
85 friend class AOTConstantPoolResolver;
86 private:
87 // If you add a new field that points to any metaspace object, you
88 // must add this field to ConstantPool::metaspace_pointers_do().
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 // Consider using an array of compressed klass pointers to
95 // save space on 64-bit platforms.
96 Array<Klass*>* _resolved_klasses;
97
98 u2 _major_version; // major version number of class file
99 u2 _minor_version; // minor version number of class file
100
101 // Constant pool index to the utf8 entry of the Generic signature,
102 // or 0 if none.
103 u2 _generic_signature_index;
104 // Constant pool index to the utf8 entry for the name of source file
105 // containing this klass, 0 if not specified.
106 u2 _source_file_name_index;
107
108 enum {
109 _has_preresolution = 1, // Flags
110 _on_stack = 2,
111 _is_shared = 4,
112 _has_dynamic_constant = 8,
113 _is_for_method_handle_intrinsic = 16
114 };
115
116 u2 _flags; // old fashioned bit twiddling
117
118 int _length; // number of elements in the array
119
120 union {
121 // set for CDS to restore resolved references
122 int _resolved_reference_length;
123 // keeps version number for redefined classes (used in backtrace)
124 int _version;
125 } _saved;
126
127 void set_tags(Array<u1>* tags) { _tags = tags; }
128 void tag_at_put(int cp_index, jbyte t) { tags()->at_put(cp_index, t); }
129 void release_tag_at_put(int cp_index, jbyte t) { tags()->release_at_put(cp_index, t); }
130
131 u1* tag_addr_at(int cp_index) const { return tags()->adr_at(cp_index); }
132
133 void set_operands(Array<u2>* operands) { _operands = operands; }
200 }
201 u2 source_file_name_index() const { return _source_file_name_index; }
202 void set_source_file_name_index(u2 sourcefile_index) { _source_file_name_index = sourcefile_index; }
203
204 void copy_fields(const ConstantPool* orig);
205
206 // Redefine classes support. If a method referring to this constant pool
207 // is on the executing stack, or as a handle in vm code, this constant pool
208 // can't be removed from the set of previous versions saved in the instance
209 // class.
210 bool on_stack() const;
211 bool is_maybe_on_stack() const;
212 void set_on_stack(const bool value);
213
214 // Faster than MetaspaceObj::is_shared() - used by set_on_stack()
215 bool is_shared() const { return (_flags & _is_shared) != 0; }
216
217 bool has_dynamic_constant() const { return (_flags & _has_dynamic_constant) != 0; }
218 void set_has_dynamic_constant() { _flags |= _has_dynamic_constant; }
219
220 bool is_for_method_handle_intrinsic() const { return (_flags & _is_for_method_handle_intrinsic) != 0; }
221 void set_is_for_method_handle_intrinsic() { _flags |= _is_for_method_handle_intrinsic; }
222
223 // Klass holding pool
224 InstanceKlass* pool_holder() const { return _pool_holder; }
225 void set_pool_holder(InstanceKlass* k) { _pool_holder = k; }
226 InstanceKlass** pool_holder_addr() { return &_pool_holder; }
227
228 // Interpreter runtime support
229 ConstantPoolCache* cache() const { return _cache; }
230 void set_cache(ConstantPoolCache* cache){ _cache = cache; }
231
232 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
233 virtual MetaspaceObj::Type type() const { return ConstantPoolType; }
234
235 // Create object cache in the constant pool
236 void initialize_resolved_references(ClassLoaderData* loader_data,
237 const intStack& reference_map,
238 int constant_pool_map_length,
239 TRAPS);
240
241 // resolved strings, methodHandles and callsite objects from the constant pool
242 objArrayOop resolved_references() const;
666
667 int to_cp_index(int which, Bytecodes::Code code);
668
669 bool is_resolved(int which, Bytecodes::Code code);
670
671 // Lookup for entries consisting of (name_index, signature_index)
672 u2 name_ref_index_at(int cp_index); // == low-order jshort of name_and_type_at(cp_index)
673 u2 signature_ref_index_at(int cp_index); // == high-order jshort of name_and_type_at(cp_index)
674
675 BasicType basic_type_for_signature_at(int cp_index) const;
676
677 // Resolve string constants (to prevent allocation during compilation)
678 void resolve_string_constants(TRAPS) {
679 constantPoolHandle h_this(THREAD, this);
680 resolve_string_constants_impl(h_this, CHECK);
681 }
682
683 #if INCLUDE_CDS
684 // CDS support
685 objArrayOop prepare_resolved_references_for_archiving() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
686 void find_archivable_hidden_classes() NOT_CDS_JAVA_HEAP_RETURN;
687 void add_dumped_interned_strings() NOT_CDS_JAVA_HEAP_RETURN;
688 void remove_unshareable_info();
689 void restore_unshareable_info(TRAPS);
690 private:
691 void remove_unshareable_entries();
692 void remove_resolved_klass_if_non_deterministic(int cp_index);
693 template <typename Function> void iterate_archivable_resolved_references(Function function);
694 #endif
695
696 private:
697 enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
698 public:
699
700 // Get the tag for a constant, which may involve a constant dynamic
701 constantTag constant_tag_at(int cp_index);
702 // Get the basic type for a constant, which may involve a constant dynamic
703 BasicType basic_type_for_constant_at(int cp_index);
704
705 // Resolve late bound constants.
706 oop resolve_constant_at(int cp_index, TRAPS) {
707 constantPoolHandle h_this(THREAD, this);
708 return resolve_constant_at_impl(h_this, cp_index, _no_index_sentinel, nullptr, THREAD);
709 }
710
711 oop resolve_cached_constant_at(int cache_index, TRAPS) {
712 constantPoolHandle h_this(THREAD, this);
713 return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, nullptr, THREAD);
|