< prev index next >

src/hotspot/share/oops/instanceKlass.hpp

Print this page




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_OOPS_INSTANCEKLASS_HPP
  26 #define SHARE_OOPS_INSTANCEKLASS_HPP
  27 
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.hpp"
  30 #include "classfile/moduleEntry.hpp"
  31 #include "classfile/packageEntry.hpp"
  32 #include "memory/referenceType.hpp"
  33 #include "oops/annotations.hpp"
  34 #include "oops/constMethod.hpp"
  35 #include "oops/fieldInfo.hpp"
  36 #include "oops/instanceOop.hpp"
  37 #include "oops/klassVtable.hpp"

  38 #include "runtime/handles.hpp"
  39 #include "runtime/os.hpp"
  40 #include "utilities/accessFlags.hpp"
  41 #include "utilities/align.hpp"
  42 #include "utilities/macros.hpp"
  43 #if INCLUDE_JFR
  44 #include "jfr/support/jfrKlassExtension.hpp"
  45 #endif
  46 
  47 
  48 // An InstanceKlass is the VM level representation of a Java class.
  49 // It contains all information needed for at class at execution runtime.
  50 
  51 //  InstanceKlass embedded field layout (after declared fields):
  52 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  53 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  54 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  55 //      indicating where oops are located in instances of this klass.
  56 //    [EMBEDDED implementor of the interface] only exist for interface
  57 //    [EMBEDDED unsafe_anonymous_host klass] only exist for an unsafe anonymous class (JSR 292 enabled)


 174   // class info index for the class that is a nest member. This data
 175   // has not been validated.
 176   Array<jushort>* _nest_members;
 177 
 178   // The NestHost attribute. The class info index for the class
 179   // that is the nest-host of this class. This data has not been validated.
 180   jushort _nest_host_index;
 181 
 182   // Resolved nest-host klass: either true nest-host or self if we are not nested.
 183   // By always being set it makes nest-member access checks simpler.
 184   InstanceKlass* _nest_host;
 185 
 186   // the source debug extension for this klass, NULL if not specified.
 187   // Specified as UTF-8 string without terminating zero byte in the classfile,
 188   // it is stored in the instanceklass as a NULL-terminated UTF-8 string
 189   const char*     _source_debug_extension;
 190   // Array name derived from this class which needs unreferencing
 191   // if this class is unloaded.
 192   Symbol*         _array_name;
 193 


 194   // Number of heapOopSize words used by non-static fields in this klass
 195   // (including inherited fields but after header_size()).
 196   int             _nonstatic_field_size;
 197   int             _static_field_size;    // number words used by static fields (oop and non-oop) in this klass
 198   // Constant pool index to the utf8 entry of the Generic signature,
 199   // or 0 if none.
 200   u2              _generic_signature_index;
 201   // Constant pool index to the utf8 entry for the name of source file
 202   // containing this klass, 0 if not specified.
 203   u2              _source_file_name_index;
 204   u2              _static_oop_field_count;// number of static oop fields in this klass
 205   u2              _java_fields_count;    // The number of declared Java fields

 206   int             _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
 207 
 208   int             _itable_len;           // length of Java itable (in words)
 209   // _is_marked_dependent can be set concurrently, thus cannot be part of the
 210   // _misc_flags.
 211   bool            _is_marked_dependent;  // used for marking during flushing and deoptimization
 212   bool            _is_being_redefined;   // used for locking redefinition
 213 
 214   // The low two bits of _misc_flags contains the kind field.
 215   // This can be used to quickly discriminate among the four kinds of
 216   // InstanceKlass.
 217 
 218   static const unsigned _misc_kind_field_size = 2;
 219   static const unsigned _misc_kind_field_pos  = 0;
 220   static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u;
 221 
 222   static const unsigned _misc_kind_other        = 0; // concrete InstanceKlass
 223   static const unsigned _misc_kind_reference    = 1; // InstanceRefKlass
 224   static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass
 225   static const unsigned _misc_kind_mirror       = 3; // InstanceMirrorKlass


 417   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 418   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
 419   Array<int>* create_new_default_vtable_indices(int len, TRAPS);
 420 
 421   // interfaces
 422   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 423   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 424     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 425     _local_interfaces = a; }
 426 
 427   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 428   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 429     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 430     _transitive_interfaces = a;
 431   }
 432 
 433  private:
 434   friend class fieldDescriptor;
 435   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 436 


 437  public:
 438   int     field_offset      (int index) const { return field(index)->offset(); }
 439   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 440   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 441   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }
 442 
 443   // Number of Java declared fields
 444   int java_fields_count() const           { return (int)_java_fields_count; }
 445 
 446   Array<u2>* fields() const            { return _fields; }
 447   void set_fields(Array<u2>* f, u2 java_fields_count) {
 448     guarantee(_fields == NULL || f == NULL, "Just checking");
 449     _fields = f;
 450     _java_fields_count = java_fields_count;
 451   }
 452 
 453   // inner classes
 454   Array<u2>* inner_classes() const       { return _inner_classes; }
 455   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 456 
 457   // nest members
 458   Array<u2>* nest_members() const     { return _nest_members; }
 459   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 460 
 461   // nest-host index
 462   jushort nest_host_index() const { return _nest_host_index; }
 463   void set_nest_host_index(u2 i)  { _nest_host_index = i; }















 464 
 465 private:
 466   // Called to verify that k is a member of this nest - does not look at k's nest-host
 467   bool has_nest_member(InstanceKlass* k, TRAPS) const;
 468 public:
 469   // Returns nest-host class, resolving and validating it if needed
 470   // Returns NULL if an exception occurs during loading, or validation fails
 471   InstanceKlass* nest_host(Symbol* validationException, TRAPS);
 472   // Check if this klass is a nestmate of k - resolves this nest-host and k's
 473   bool has_nestmate_access_to(InstanceKlass* k, TRAPS);
 474 
 475   enum InnerClassAttributeOffset {
 476     // From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814
 477     inner_class_inner_class_info_offset = 0,
 478     inner_class_outer_class_info_offset = 1,
 479     inner_class_inner_name_offset = 2,
 480     inner_class_access_flags_offset = 3,
 481     inner_class_next_offset = 4
 482   };
 483 




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_OOPS_INSTANCEKLASS_HPP
  26 #define SHARE_OOPS_INSTANCEKLASS_HPP
  27 
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.hpp"
  30 #include "classfile/moduleEntry.hpp"
  31 #include "classfile/packageEntry.hpp"
  32 #include "memory/referenceType.hpp"
  33 #include "oops/annotations.hpp"
  34 #include "oops/constMethod.hpp"
  35 #include "oops/fieldInfo.hpp"
  36 #include "oops/instanceOop.hpp"
  37 #include "oops/klassVtable.hpp"
  38 #include "oops/recordParamInfo.hpp"
  39 #include "runtime/handles.hpp"
  40 #include "runtime/os.hpp"
  41 #include "utilities/accessFlags.hpp"
  42 #include "utilities/align.hpp"
  43 #include "utilities/macros.hpp"
  44 #if INCLUDE_JFR
  45 #include "jfr/support/jfrKlassExtension.hpp"
  46 #endif
  47 
  48 
  49 // An InstanceKlass is the VM level representation of a Java class.
  50 // It contains all information needed for at class at execution runtime.
  51 
  52 //  InstanceKlass embedded field layout (after declared fields):
  53 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  54 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  55 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  56 //      indicating where oops are located in instances of this klass.
  57 //    [EMBEDDED implementor of the interface] only exist for interface
  58 //    [EMBEDDED unsafe_anonymous_host klass] only exist for an unsafe anonymous class (JSR 292 enabled)


 175   // class info index for the class that is a nest member. This data
 176   // has not been validated.
 177   Array<jushort>* _nest_members;
 178 
 179   // The NestHost attribute. The class info index for the class
 180   // that is the nest-host of this class. This data has not been validated.
 181   jushort _nest_host_index;
 182 
 183   // Resolved nest-host klass: either true nest-host or self if we are not nested.
 184   // By always being set it makes nest-member access checks simpler.
 185   InstanceKlass* _nest_host;
 186 
 187   // the source debug extension for this klass, NULL if not specified.
 188   // Specified as UTF-8 string without terminating zero byte in the classfile,
 189   // it is stored in the instanceklass as a NULL-terminated UTF-8 string
 190   const char*     _source_debug_extension;
 191   // Array name derived from this class which needs unreferencing
 192   // if this class is unloaded.
 193   Symbol*         _array_name;
 194 
 195   Array<u2>*      _record_params;
 196 
 197   // Number of heapOopSize words used by non-static fields in this klass
 198   // (including inherited fields but after header_size()).
 199   int             _nonstatic_field_size;
 200   int             _static_field_size;    // number words used by static fields (oop and non-oop) in this klass
 201   // Constant pool index to the utf8 entry of the Generic signature,
 202   // or 0 if none.
 203   u2              _generic_signature_index;
 204   // Constant pool index to the utf8 entry for the name of source file
 205   // containing this klass, 0 if not specified.
 206   u2              _source_file_name_index;
 207   u2              _static_oop_field_count;// number of static oop fields in this klass
 208   u2              _java_fields_count;    // The number of declared Java fields
 209   u2              _record_params_count;  // The number of record parameters
 210   int             _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
 211 
 212   int             _itable_len;           // length of Java itable (in words)
 213   // _is_marked_dependent can be set concurrently, thus cannot be part of the
 214   // _misc_flags.
 215   bool            _is_marked_dependent;  // used for marking during flushing and deoptimization
 216   bool            _is_being_redefined;   // used for locking redefinition
 217 
 218   // The low two bits of _misc_flags contains the kind field.
 219   // This can be used to quickly discriminate among the four kinds of
 220   // InstanceKlass.
 221 
 222   static const unsigned _misc_kind_field_size = 2;
 223   static const unsigned _misc_kind_field_pos  = 0;
 224   static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u;
 225 
 226   static const unsigned _misc_kind_other        = 0; // concrete InstanceKlass
 227   static const unsigned _misc_kind_reference    = 1; // InstanceRefKlass
 228   static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass
 229   static const unsigned _misc_kind_mirror       = 3; // InstanceMirrorKlass


 421   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 422   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
 423   Array<int>* create_new_default_vtable_indices(int len, TRAPS);
 424 
 425   // interfaces
 426   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 427   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 428     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 429     _local_interfaces = a; }
 430 
 431   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 432   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 433     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 434     _transitive_interfaces = a;
 435   }
 436 
 437  private:
 438   friend class fieldDescriptor;
 439   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 440 
 441   RecordParamInfo* record_param(int index) const { return RecordParamInfo::from_record_params_array(_record_params, index); }
 442 
 443  public:
 444   int     field_offset      (int index) const { return field(index)->offset(); }
 445   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 446   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 447   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }
 448 
 449   // Number of Java declared fields
 450   int java_fields_count() const           { return (int)_java_fields_count; }
 451 
 452   Array<u2>* fields() const            { return _fields; }
 453   void set_fields(Array<u2>* f, u2 java_fields_count) {
 454     guarantee(_fields == NULL || f == NULL, "Just checking");
 455     _fields = f;
 456     _java_fields_count = java_fields_count;
 457   }
 458 
 459   // inner classes
 460   Array<u2>* inner_classes() const       { return _inner_classes; }
 461   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 462 
 463   // nest members
 464   Array<u2>* nest_members() const     { return _nest_members; }
 465   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 466 
 467   // nest-host index
 468   jushort nest_host_index() const { return _nest_host_index; }
 469   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 470 
 471   // record parameters
 472   int     record_param_access_flags(int index) const { return record_param(index)->access_flags(); }
 473   Symbol* record_param_name(int index) const { return record_param(index)->name(constants()); }
 474   Symbol* record_param_signature(int index) const { return record_param(index)->signature(constants()); }
 475   Symbol* record_param_descriptor(int index) const { return record_param(index)->signature(constants()); }
 476 
 477   int record_params_count() const       { return (int)_record_params_count; }
 478 
 479   Array<u2>* record_params() const       { return _record_params; }
 480   void set_record_params(Array<u2>* record_params, u2 record_params_count) {
 481     guarantee(_record_params == NULL || record_params == NULL, "Just checking");
 482     _record_params = record_params;
 483     _record_params_count = record_params_count;
 484   }
 485 
 486 private:
 487   // Called to verify that k is a member of this nest - does not look at k's nest-host
 488   bool has_nest_member(InstanceKlass* k, TRAPS) const;
 489 public:
 490   // Returns nest-host class, resolving and validating it if needed
 491   // Returns NULL if an exception occurs during loading, or validation fails
 492   InstanceKlass* nest_host(Symbol* validationException, TRAPS);
 493   // Check if this klass is a nestmate of k - resolves this nest-host and k's
 494   bool has_nestmate_access_to(InstanceKlass* k, TRAPS);
 495 
 496   enum InnerClassAttributeOffset {
 497     // From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814
 498     inner_class_inner_class_info_offset = 0,
 499     inner_class_outer_class_info_offset = 1,
 500     inner_class_inner_name_offset = 2,
 501     inner_class_access_flags_offset = 3,
 502     inner_class_next_offset = 4
 503   };
 504 


< prev index next >