< prev index next >

src/hotspot/share/oops/constantPool.hpp

Print this page

227 
228   // Klass holding pool
229   InstanceKlass* pool_holder() const      { return _pool_holder; }
230   void set_pool_holder(InstanceKlass* k)  { _pool_holder = k; }
231   InstanceKlass** pool_holder_addr()      { return &_pool_holder; }
232 
233   // Interpreter runtime support
234   ConstantPoolCache* cache() const        { return _cache; }
235   void set_cache(ConstantPoolCache* cache){ _cache = cache; }
236 
237   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
238   virtual MetaspaceObj::Type type() const { return ConstantPoolType; }
239 
240   // Create object cache in the constant pool
241   void initialize_resolved_references(ClassLoaderData* loader_data,
242                                       const intStack& reference_map,
243                                       int constant_pool_map_length,
244                                       TRAPS);
245 
246   // resolved strings, methodHandles and callsite objects from the constant pool
247   objArrayOop resolved_references()  const;
248   objArrayOop resolved_references_or_null()  const;
249   oop resolved_reference_at(int obj_index) const;
250   oop set_resolved_reference_at(int index, oop new_value);
251 
252   // mapping resolved object array indexes to cp indexes and back.
253   int object_to_cp_index(int index)         { return reference_map()->at(index); }
254   int cp_to_object_index(int index);
255 
256   void set_resolved_klasses(Array<Klass*>* rk)  { _resolved_klasses = rk; }
257   Array<Klass*>* resolved_klasses() const       { return _resolved_klasses; }
258   void allocate_resolved_klasses(ClassLoaderData* loader_data, int num_klasses, TRAPS);
259   void initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS);
260 
261   // Given the per-instruction index of an indy instruction, report the
262   // main constant pool entry for its bootstrap specifier.
263   // From there, uncached_name/signature_ref_at will get the name/type.
264   inline u2 invokedynamic_bootstrap_ref_index_at(int indy_index) const;
265 
266   // Assembly code support
267   static ByteSize tags_offset()         { return byte_offset_of(ConstantPool, _tags); }
268   static ByteSize cache_offset()        { return byte_offset_of(ConstantPool, _cache); }
269   static ByteSize pool_holder_offset()  { return byte_offset_of(ConstantPool, _pool_holder); }
270   static ByteSize resolved_klasses_offset()    { return byte_offset_of(ConstantPool, _resolved_klasses); }
271 
272   // Storing constants
273 
274   // For temporary use while constructing constant pool
275   void klass_index_at_put(int cp_index, int name_index) {
276     tag_at_put(cp_index, JVM_CONSTANT_ClassIndex);
277     *int_at_addr(cp_index) = name_index;
278   }
279 
280   // Hidden class support:
281   void klass_at_put(int class_index, Klass* k);
282 
283   void unresolved_klass_at_put(int cp_index, int name_index, int resolved_klass_index) {
284     release_tag_at_put(cp_index, JVM_CONSTANT_UnresolvedClass);
285 
286     assert((name_index & 0xffff0000) == 0, "must be");
287     assert((resolved_klass_index & 0xffff0000) == 0, "must be");
288     *int_at_addr(cp_index) =
289       build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index);
290   }
291 
292   void method_handle_index_at_put(int cp_index, int ref_kind, int ref_index) {
293     tag_at_put(cp_index, JVM_CONSTANT_MethodHandle);
294     *int_at_addr(cp_index) = ((jint) ref_index<<16) | ref_kind;

586   constantTag tag_ref_at(int cp_cache_index, Bytecodes::Code code);
587 
588   int to_cp_index(int which, Bytecodes::Code code);
589 
590   bool is_resolved(int which, Bytecodes::Code code);
591 
592   // Lookup for entries consisting of (name_index, signature_index)
593   u2 name_ref_index_at(int cp_index);            // ==  low-order jshort of name_and_type_at(cp_index)
594   u2 signature_ref_index_at(int cp_index);       // == high-order jshort of name_and_type_at(cp_index)
595 
596   BasicType basic_type_for_signature_at(int cp_index) const;
597 
598   // Resolve string constants (to prevent allocation during compilation)
599   void resolve_string_constants(TRAPS) {
600     constantPoolHandle h_this(THREAD, this);
601     resolve_string_constants_impl(h_this, CHECK);
602   }
603 
604 #if INCLUDE_CDS
605   // CDS support
606   objArrayOop prepare_resolved_references_for_archiving() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
607   void remove_unshareable_info();
608   void restore_unshareable_info(TRAPS);
609 private:
610   void remove_unshareable_entries();
611   void remove_resolved_klass_if_non_deterministic(int cp_index);
612   template <typename Function> void iterate_archivable_resolved_references(Function function);
613 #endif
614 
615  private:
616   enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
617  public:
618 
619   // Get the tag for a constant, which may involve a constant dynamic
620   constantTag constant_tag_at(int cp_index);
621   // Get the basic type for a constant, which may involve a constant dynamic
622   BasicType basic_type_for_constant_at(int cp_index);
623 
624   // Resolve late bound constants.
625   oop resolve_constant_at(int cp_index, TRAPS) {
626     constantPoolHandle h_this(THREAD, this);
627     return resolve_constant_at_impl(h_this, cp_index, _no_index_sentinel, nullptr, THREAD);
628   }
629 
630   oop resolve_cached_constant_at(int cache_index, TRAPS) {
631     constantPoolHandle h_this(THREAD, this);
632     return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, nullptr, THREAD);
633   }
634 
635   oop resolve_possibly_cached_constant_at(int cp_index, TRAPS) {
636     constantPoolHandle h_this(THREAD, this);
637     return resolve_constant_at_impl(h_this, cp_index, _possible_index_sentinel, nullptr, THREAD);
638   }
639 
640   oop find_cached_constant_at(int cp_index, bool& found_it, TRAPS) {
641     constantPoolHandle h_this(THREAD, this);
642     return resolve_constant_at_impl(h_this, cp_index, _possible_index_sentinel, &found_it, THREAD);
643   }
644 
645   void copy_bootstrap_arguments_at(int cp_index,
646                                    int start_arg, int end_arg,
647                                    objArrayHandle info, int pos,
648                                    bool must_resolve, Handle if_not_available, TRAPS) {
649     constantPoolHandle h_this(THREAD, this);
650     copy_bootstrap_arguments_at_impl(h_this, cp_index, start_arg, end_arg,
651                                      info, pos, must_resolve, if_not_available, THREAD);
652   }
653 
654   // Klass name matches name at offset
655   bool klass_name_at_matches(const InstanceKlass* k, int cp_index);
656 
657   // Sizing
658   int length() const                   { return _length; }
659   void set_length(int length)          { _length = length; }
660 
661   // Tells whether index is within bounds.
662   bool is_within_bounds(int index) const {
663     return 0 <= index && index < length();
664   }
665 
666   // Sizing (in words)
667   static int header_size()             {

726     return *int_at_addr(cp_index);
727   }
728 
729   // Performs the LinkResolver checks
730   static void verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* klass, TRAPS);
731 
732   // Implementation of methods that needs an exposed 'this' pointer, in order to
733   // handle GC while executing the method
734   static Klass* klass_at_impl(const constantPoolHandle& this_cp, int cp_index, TRAPS);
735   static oop string_at_impl(const constantPoolHandle& this_cp, int cp_index, int obj_index, TRAPS);
736 
737   static void trace_class_resolution(const constantPoolHandle& this_cp, Klass* k);
738 
739   // Resolve string constants (to prevent allocation during compilation)
740   static void resolve_string_constants_impl(const constantPoolHandle& this_cp, TRAPS);
741 
742   static oop resolve_constant_at_impl(const constantPoolHandle& this_cp, int cp_index, int cache_index,
743                                       bool* status_return, TRAPS);
744   static void copy_bootstrap_arguments_at_impl(const constantPoolHandle& this_cp, int cp_index,
745                                                int start_arg, int end_arg,
746                                                objArrayHandle info, int pos,
747                                                bool must_resolve, Handle if_not_available, TRAPS);
748 
749   // Exception handling
750   static void save_and_throw_exception(const constantPoolHandle& this_cp, int cp_index, constantTag tag, TRAPS);
751 
752  public:
753   // Exception handling
754   static void throw_resolution_error(const constantPoolHandle& this_cp, int which, TRAPS);
755 
756   // Merging ConstantPool* support:
757   bool compare_entry_to(int index1, const constantPoolHandle& cp2, int index2);
758   void copy_cp_to(int start_cpi, int end_cpi, const constantPoolHandle& to_cp, int to_cpi, TRAPS) {
759     constantPoolHandle h_this(THREAD, this);
760     copy_cp_to_impl(h_this, start_cpi, end_cpi, to_cp, to_cpi, THREAD);
761   }
762   static void copy_cp_to_impl(const constantPoolHandle& from_cp, int start_cpi, int end_cpi, const constantPoolHandle& to_cp, int to_cpi, TRAPS);
763   static void copy_entry_to(const constantPoolHandle& from_cp, int from_cpi, const constantPoolHandle& to_cp, int to_cpi);
764   static void copy_bsm_entries(const constantPoolHandle& from_cp, const constantPoolHandle& to_cp, TRAPS);
765   int  find_matching_entry(int pattern_i, const constantPoolHandle& search_cp);
766   int  version() const                    { return _saved._version; }

227 
228   // Klass holding pool
229   InstanceKlass* pool_holder() const      { return _pool_holder; }
230   void set_pool_holder(InstanceKlass* k)  { _pool_holder = k; }
231   InstanceKlass** pool_holder_addr()      { return &_pool_holder; }
232 
233   // Interpreter runtime support
234   ConstantPoolCache* cache() const        { return _cache; }
235   void set_cache(ConstantPoolCache* cache){ _cache = cache; }
236 
237   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
238   virtual MetaspaceObj::Type type() const { return ConstantPoolType; }
239 
240   // Create object cache in the constant pool
241   void initialize_resolved_references(ClassLoaderData* loader_data,
242                                       const intStack& reference_map,
243                                       int constant_pool_map_length,
244                                       TRAPS);
245 
246   // resolved strings, methodHandles and callsite objects from the constant pool
247   refArrayOop resolved_references()  const;
248   refArrayOop resolved_references_or_null()  const;
249   oop resolved_reference_at(int obj_index) const;
250   oop set_resolved_reference_at(int index, oop new_value);
251 
252   // mapping resolved object array indexes to cp indexes and back.
253   int object_to_cp_index(int index)         { return reference_map()->at(index); }
254   int cp_to_object_index(int index);
255 
256   void set_resolved_klasses(Array<Klass*>* rk)  { _resolved_klasses = rk; }
257   Array<Klass*>* resolved_klasses() const       { return _resolved_klasses; }
258   void allocate_resolved_klasses(ClassLoaderData* loader_data, int num_klasses, TRAPS);
259   void initialize_unresolved_klasses(ClassLoaderData* loader_data, TRAPS);
260 
261   // Given the per-instruction index of an indy instruction, report the
262   // main constant pool entry for its bootstrap specifier.
263   // From there, uncached_name/signature_ref_at will get the name/type.
264   inline u2 invokedynamic_bootstrap_ref_index_at(int indy_index) const;
265 
266   // Assembly code support
267   static ByteSize tags_offset()         { return byte_offset_of(ConstantPool, _tags); }
268   static ByteSize cache_offset()        { return byte_offset_of(ConstantPool, _cache); }
269   static ByteSize pool_holder_offset()  { return byte_offset_of(ConstantPool, _pool_holder); }
270   static ByteSize resolved_klasses_offset()    { return byte_offset_of(ConstantPool, _resolved_klasses); }
271 
272   // Storing constants
273 
274   // For temporary use while constructing constant pool. Used during a retransform/class redefinition as well.
275   void klass_index_at_put(int cp_index, int name_index) {
276     tag_at_put(cp_index, JVM_CONSTANT_ClassIndex);
277     *int_at_addr(cp_index) = name_index;
278   }
279 
280   // Hidden class support:
281   void klass_at_put(int class_index, Klass* k);
282 
283   void unresolved_klass_at_put(int cp_index, int name_index, int resolved_klass_index) {
284     release_tag_at_put(cp_index, JVM_CONSTANT_UnresolvedClass);
285 
286     assert((name_index & 0xffff0000) == 0, "must be");
287     assert((resolved_klass_index & 0xffff0000) == 0, "must be");
288     *int_at_addr(cp_index) =
289       build_int_from_shorts((jushort)resolved_klass_index, (jushort)name_index);
290   }
291 
292   void method_handle_index_at_put(int cp_index, int ref_kind, int ref_index) {
293     tag_at_put(cp_index, JVM_CONSTANT_MethodHandle);
294     *int_at_addr(cp_index) = ((jint) ref_index<<16) | ref_kind;

586   constantTag tag_ref_at(int cp_cache_index, Bytecodes::Code code);
587 
588   int to_cp_index(int which, Bytecodes::Code code);
589 
590   bool is_resolved(int which, Bytecodes::Code code);
591 
592   // Lookup for entries consisting of (name_index, signature_index)
593   u2 name_ref_index_at(int cp_index);            // ==  low-order jshort of name_and_type_at(cp_index)
594   u2 signature_ref_index_at(int cp_index);       // == high-order jshort of name_and_type_at(cp_index)
595 
596   BasicType basic_type_for_signature_at(int cp_index) const;
597 
598   // Resolve string constants (to prevent allocation during compilation)
599   void resolve_string_constants(TRAPS) {
600     constantPoolHandle h_this(THREAD, this);
601     resolve_string_constants_impl(h_this, CHECK);
602   }
603 
604 #if INCLUDE_CDS
605   // CDS support
606   refArrayOop prepare_resolved_references_for_archiving() NOT_CDS_JAVA_HEAP_RETURN_(nullptr);
607   void remove_unshareable_info();
608   void restore_unshareable_info(TRAPS);
609 private:
610   void remove_unshareable_entries();
611   void remove_resolved_klass_if_non_deterministic(int cp_index);
612   template <typename Function> void iterate_archivable_resolved_references(Function function);
613 #endif
614 
615  private:
616   enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
617  public:
618 
619   // Get the tag for a constant, which may involve a constant dynamic
620   constantTag constant_tag_at(int cp_index);
621   // Get the basic type for a constant, which may involve a constant dynamic
622   BasicType basic_type_for_constant_at(int cp_index);
623 
624   // Resolve late bound constants.
625   oop resolve_constant_at(int cp_index, TRAPS) {
626     constantPoolHandle h_this(THREAD, this);
627     return resolve_constant_at_impl(h_this, cp_index, _no_index_sentinel, nullptr, THREAD);
628   }
629 
630   oop resolve_cached_constant_at(int cache_index, TRAPS) {
631     constantPoolHandle h_this(THREAD, this);
632     return resolve_constant_at_impl(h_this, _no_index_sentinel, cache_index, nullptr, THREAD);
633   }
634 
635   oop resolve_possibly_cached_constant_at(int cp_index, TRAPS) {
636     constantPoolHandle h_this(THREAD, this);
637     return resolve_constant_at_impl(h_this, cp_index, _possible_index_sentinel, nullptr, THREAD);
638   }
639 
640   oop find_cached_constant_at(int cp_index, bool& found_it, TRAPS) {
641     constantPoolHandle h_this(THREAD, this);
642     return resolve_constant_at_impl(h_this, cp_index, _possible_index_sentinel, &found_it, THREAD);
643   }
644 
645   void copy_bootstrap_arguments_at(int cp_index,
646                                    int start_arg, int end_arg,
647                                    refArrayHandle info, int pos,
648                                    bool must_resolve, Handle if_not_available, TRAPS) {
649     constantPoolHandle h_this(THREAD, this);
650     copy_bootstrap_arguments_at_impl(h_this, cp_index, start_arg, end_arg,
651                                      info, pos, must_resolve, if_not_available, THREAD);
652   }
653 
654   // Klass name matches name at offset
655   bool klass_name_at_matches(const InstanceKlass* k, int cp_index);
656 
657   // Sizing
658   int length() const                   { return _length; }
659   void set_length(int length)          { _length = length; }
660 
661   // Tells whether index is within bounds.
662   bool is_within_bounds(int index) const {
663     return 0 <= index && index < length();
664   }
665 
666   // Sizing (in words)
667   static int header_size()             {

726     return *int_at_addr(cp_index);
727   }
728 
729   // Performs the LinkResolver checks
730   static void verify_constant_pool_resolve(const constantPoolHandle& this_cp, Klass* klass, TRAPS);
731 
732   // Implementation of methods that needs an exposed 'this' pointer, in order to
733   // handle GC while executing the method
734   static Klass* klass_at_impl(const constantPoolHandle& this_cp, int cp_index, TRAPS);
735   static oop string_at_impl(const constantPoolHandle& this_cp, int cp_index, int obj_index, TRAPS);
736 
737   static void trace_class_resolution(const constantPoolHandle& this_cp, Klass* k);
738 
739   // Resolve string constants (to prevent allocation during compilation)
740   static void resolve_string_constants_impl(const constantPoolHandle& this_cp, TRAPS);
741 
742   static oop resolve_constant_at_impl(const constantPoolHandle& this_cp, int cp_index, int cache_index,
743                                       bool* status_return, TRAPS);
744   static void copy_bootstrap_arguments_at_impl(const constantPoolHandle& this_cp, int cp_index,
745                                                int start_arg, int end_arg,
746                                                refArrayHandle info, int pos,
747                                                bool must_resolve, Handle if_not_available, TRAPS);
748 
749   // Exception handling
750   static void save_and_throw_exception(const constantPoolHandle& this_cp, int cp_index, constantTag tag, TRAPS);
751 
752  public:
753   // Exception handling
754   static void throw_resolution_error(const constantPoolHandle& this_cp, int which, TRAPS);
755 
756   // Merging ConstantPool* support:
757   bool compare_entry_to(int index1, const constantPoolHandle& cp2, int index2);
758   void copy_cp_to(int start_cpi, int end_cpi, const constantPoolHandle& to_cp, int to_cpi, TRAPS) {
759     constantPoolHandle h_this(THREAD, this);
760     copy_cp_to_impl(h_this, start_cpi, end_cpi, to_cp, to_cpi, THREAD);
761   }
762   static void copy_cp_to_impl(const constantPoolHandle& from_cp, int start_cpi, int end_cpi, const constantPoolHandle& to_cp, int to_cpi, TRAPS);
763   static void copy_entry_to(const constantPoolHandle& from_cp, int from_cpi, const constantPoolHandle& to_cp, int to_cpi);
764   static void copy_bsm_entries(const constantPoolHandle& from_cp, const constantPoolHandle& to_cp, TRAPS);
765   int  find_matching_entry(int pattern_i, const constantPoolHandle& search_cp);
766   int  version() const                    { return _saved._version; }
< prev index next >