< prev index next >

src/hotspot/share/oops/instanceKlass.hpp

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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/classLoaderData.hpp"
  29 #include "memory/referenceType.hpp"
  30 #include "oops/annotations.hpp"
  31 #include "oops/constMethod.hpp"
  32 #include "oops/fieldInfo.hpp"
  33 #include "oops/instanceOop.hpp"
  34 #include "oops/klassVtable.hpp"

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


 165   // last two shorts [class_index, method_index] of the array. If only
 166   // the InnerClasses attribute exists, the _inner_classes array length is
 167   // number_of_inner_classes * 4. If the class has both InnerClasses
 168   // and EnclosingMethod attributes the _inner_classes array length is
 169   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 170   Array<jushort>* _inner_classes;
 171 
 172   // The NestMembers attribute. An array of shorts, where each is a
 173   // class info index for the class that is a nest member. This data
 174   // has not been validated.
 175   Array<jushort>* _nest_members;
 176 
 177   // The NestHost attribute. The class info index for the class
 178   // that is the nest-host of this class. This data has not been validated.
 179   jushort _nest_host_index;
 180 
 181   // Resolved nest-host klass: either true nest-host or self if we are not nested.
 182   // By always being set it makes nest-member access checks simpler.
 183   InstanceKlass* _nest_host;
 184 




 185   // the source debug extension for this klass, NULL if not specified.
 186   // Specified as UTF-8 string without terminating zero byte in the classfile,
 187   // it is stored in the instanceklass as a NULL-terminated UTF-8 string
 188   const char*     _source_debug_extension;
 189   // Array name derived from this class which needs unreferencing
 190   // if this class is unloaded.
 191   Symbol*         _array_name;
 192 


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

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


 401   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 402   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
 403   Array<int>* create_new_default_vtable_indices(int len, TRAPS);
 404 
 405   // interfaces
 406   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 407   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 408     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 409     _local_interfaces = a; }
 410 
 411   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 412   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 413     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 414     _transitive_interfaces = a;
 415   }
 416 
 417  private:
 418   friend class fieldDescriptor;
 419   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 420 


 421  public:
 422   int     field_offset      (int index) const { return field(index)->offset(); }
 423   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 424   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 425   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }
 426 
 427   // Number of Java declared fields
 428   int java_fields_count() const           { return (int)_java_fields_count; }
 429 
 430   Array<u2>* fields() const            { return _fields; }
 431   void set_fields(Array<u2>* f, u2 java_fields_count) {
 432     guarantee(_fields == NULL || f == NULL, "Just checking");
 433     _fields = f;
 434     _java_fields_count = java_fields_count;
 435   }
 436 
 437   // inner classes
 438   Array<u2>* inner_classes() const       { return _inner_classes; }
 439   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 440 
 441   // nest members
 442   Array<u2>* nest_members() const     { return _nest_members; }
 443   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 444 
 445   // nest-host index
 446   jushort nest_host_index() const { return _nest_host_index; }
 447   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 448 
















 449 private:
 450   // Called to verify that k is a member of this nest - does not look at k's nest-host
 451   bool has_nest_member(InstanceKlass* k, TRAPS) const;



 452 public:
 453   // Returns nest-host class, resolving and validating it if needed
 454   // Returns NULL if an exception occurs during loading, or validation fails
 455   InstanceKlass* nest_host(Symbol* validationException, TRAPS);
 456   // Check if this klass is a nestmate of k - resolves this nest-host and k's
 457   bool has_nestmate_access_to(InstanceKlass* k, TRAPS);
 458 
 459   enum InnerClassAttributeOffset {
 460     // From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814
 461     inner_class_inner_class_info_offset = 0,
 462     inner_class_outer_class_info_offset = 1,
 463     inner_class_inner_name_offset = 2,
 464     inner_class_access_flags_offset = 3,
 465     inner_class_next_offset = 4
 466   };
 467 
 468   enum EnclosingMethodAttributeOffset {
 469     enclosing_method_class_index_offset = 0,
 470     enclosing_method_method_index_offset = 1,
 471     enclosing_method_attribute_size = 2


 488 
 489   // Find InnerClasses attribute and return outer_class_info_index & inner_name_index.
 490   bool find_inner_classes_attr(int* ooff, int* noff, TRAPS) const;
 491 
 492  private:
 493   // Check prohibited package ("java/" only loadable by boot or platform loaders)
 494   static void check_prohibited_package(Symbol* class_name,
 495                                        ClassLoaderData* loader_data,
 496                                        TRAPS);
 497  public:
 498   // initialization state
 499   bool is_loaded() const                   { return _init_state >= loaded; }
 500   bool is_linked() const                   { return _init_state >= linked; }
 501   bool is_initialized() const              { return _init_state == fully_initialized; }
 502   bool is_not_initialized() const          { return _init_state <  being_initialized; }
 503   bool is_being_initialized() const        { return _init_state == being_initialized; }
 504   bool is_in_error_state() const           { return _init_state == initialization_error; }
 505   bool is_reentrant_initialization(Thread *thread)  { return thread == _init_thread; }
 506   ClassState  init_state()                 { return (ClassState)_init_state; }
 507   bool is_rewritten() const                { return (_misc_flags & _misc_rewritten) != 0; }



 508 
 509   // defineClass specified verification
 510   bool should_verify_class() const         {
 511     return (_misc_flags & _misc_should_verify_class) != 0;
 512   }
 513   void set_should_verify_class(bool value) {
 514     if (value) {
 515       _misc_flags |= _misc_should_verify_class;
 516     } else {
 517       _misc_flags &= ~_misc_should_verify_class;
 518     }
 519   }
 520 
 521   // marking
 522   bool is_marked_dependent() const         { return _is_marked_dependent; }
 523   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 524 
 525   // initialization (virtuals from Klass)
 526   bool should_be_initialized() const;  // means that initialize should be called
 527   void initialize(TRAPS);




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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/classLoaderData.hpp"
  29 #include "memory/referenceType.hpp"
  30 #include "oops/annotations.hpp"
  31 #include "oops/constMethod.hpp"
  32 #include "oops/fieldInfo.hpp"
  33 #include "oops/instanceOop.hpp"
  34 #include "oops/klassVtable.hpp"
  35 #include "oops/recordParamInfo.hpp"
  36 #include "runtime/handles.hpp"
  37 #include "runtime/os.hpp"
  38 #include "utilities/accessFlags.hpp"
  39 #include "utilities/align.hpp"
  40 #include "utilities/macros.hpp"
  41 #if INCLUDE_JFR
  42 #include "jfr/support/jfrKlassExtension.hpp"
  43 #endif
  44 
  45 
  46 // An InstanceKlass is the VM level representation of a Java class.
  47 // It contains all information needed for at class at execution runtime.
  48 
  49 //  InstanceKlass embedded field layout (after declared fields):
  50 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  51 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  52 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  53 //      indicating where oops are located in instances of this klass.
  54 //    [EMBEDDED implementor of the interface] only exist for interface
  55 //    [EMBEDDED unsafe_anonymous_host klass] only exist for an unsafe anonymous class (JSR 292 enabled)


 166   // last two shorts [class_index, method_index] of the array. If only
 167   // the InnerClasses attribute exists, the _inner_classes array length is
 168   // number_of_inner_classes * 4. If the class has both InnerClasses
 169   // and EnclosingMethod attributes the _inner_classes array length is
 170   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 171   Array<jushort>* _inner_classes;
 172 
 173   // The NestMembers attribute. An array of shorts, where each is a
 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 PermittedSubtypes attribute. An array of shorts, where each is a
 187   // class info index for the class that is a permitted subtype.
 188   Array<jushort>* _permitted_subtypes;
 189 
 190   // the source debug extension for this klass, NULL if not specified.
 191   // Specified as UTF-8 string without terminating zero byte in the classfile,
 192   // it is stored in the instanceklass as a NULL-terminated UTF-8 string
 193   const char*     _source_debug_extension;
 194   // Array name derived from this class which needs unreferencing
 195   // if this class is unloaded.
 196   Symbol*         _array_name;
 197 
 198   Array<u2>*      _record_params;
 199 
 200   // Number of heapOopSize words used by non-static fields in this klass
 201   // (including inherited fields but after header_size()).
 202   int             _nonstatic_field_size;
 203   int             _static_field_size;    // number words used by static fields (oop and non-oop) in this klass
 204   // Constant pool index to the utf8 entry of the Generic signature,
 205   // or 0 if none.
 206   u2              _generic_signature_index;
 207   // Constant pool index to the utf8 entry for the name of source file
 208   // containing this klass, 0 if not specified.
 209   u2              _source_file_name_index;
 210   u2              _static_oop_field_count;// number of static oop fields in this klass
 211   u2              _java_fields_count;    // The number of declared Java fields
 212   int              _record_params_count;  // The number of record parameters
 213   int             _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
 214 
 215   int             _itable_len;           // length of Java itable (in words)
 216   // _is_marked_dependent can be set concurrently, thus cannot be part of the
 217   // _misc_flags.
 218   bool            _is_marked_dependent;  // used for marking during flushing and deoptimization
 219   bool            _is_being_redefined;   // used for locking redefinition
 220 
 221   // The low two bits of _misc_flags contains the kind field.
 222   // This can be used to quickly discriminate among the four kinds of
 223   // InstanceKlass.
 224 
 225   static const unsigned _misc_kind_field_size = 2;
 226   static const unsigned _misc_kind_field_pos  = 0;
 227   static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u;
 228 
 229   static const unsigned _misc_kind_other        = 0; // concrete InstanceKlass
 230   static const unsigned _misc_kind_reference    = 1; // InstanceRefKlass
 231   static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass
 232   static const unsigned _misc_kind_mirror       = 3; // InstanceMirrorKlass


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


 517 
 518   // Find InnerClasses attribute and return outer_class_info_index & inner_name_index.
 519   bool find_inner_classes_attr(int* ooff, int* noff, TRAPS) const;
 520 
 521  private:
 522   // Check prohibited package ("java/" only loadable by boot or platform loaders)
 523   static void check_prohibited_package(Symbol* class_name,
 524                                        ClassLoaderData* loader_data,
 525                                        TRAPS);
 526  public:
 527   // initialization state
 528   bool is_loaded() const                   { return _init_state >= loaded; }
 529   bool is_linked() const                   { return _init_state >= linked; }
 530   bool is_initialized() const              { return _init_state == fully_initialized; }
 531   bool is_not_initialized() const          { return _init_state <  being_initialized; }
 532   bool is_being_initialized() const        { return _init_state == being_initialized; }
 533   bool is_in_error_state() const           { return _init_state == initialization_error; }
 534   bool is_reentrant_initialization(Thread *thread)  { return thread == _init_thread; }
 535   ClassState  init_state()                 { return (ClassState)_init_state; }
 536   bool is_rewritten() const                { return (_misc_flags & _misc_rewritten) != 0; }
 537 
 538   // is this a sealed class
 539   bool is_sealed() const;
 540 
 541   // defineClass specified verification
 542   bool should_verify_class() const         {
 543     return (_misc_flags & _misc_should_verify_class) != 0;
 544   }
 545   void set_should_verify_class(bool value) {
 546     if (value) {
 547       _misc_flags |= _misc_should_verify_class;
 548     } else {
 549       _misc_flags &= ~_misc_should_verify_class;
 550     }
 551   }
 552 
 553   // marking
 554   bool is_marked_dependent() const         { return _is_marked_dependent; }
 555   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 556 
 557   // initialization (virtuals from Klass)
 558   bool should_be_initialized() const;  // means that initialize should be called
 559   void initialize(TRAPS);


< prev index next >