< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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_KLASS_HPP
  26 #define SHARE_OOPS_KLASS_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "memory/iterator.hpp"
  30 #include "memory/memRegion.hpp"


  31 #include "oops/metadata.hpp"
  32 #include "oops/oop.hpp"
  33 #include "oops/oopHandle.hpp"
  34 #include "utilities/accessFlags.hpp"
  35 #include "utilities/macros.hpp"
  36 #if INCLUDE_JFR
  37 #include "jfr/support/jfrTraceIdExtension.hpp"
  38 #endif
  39 
  40 // Klass IDs for all subclasses of Klass
  41 enum KlassID {
  42   InstanceKlassID,
  43   InstanceRefKlassID,
  44   InstanceMirrorKlassID,
  45   InstanceClassLoaderKlassID,
  46   TypeArrayKlassID,

  47   ObjArrayKlassID
  48 };
  49 
  50 const uint KLASS_ID_COUNT = 6;
  51 
  52 //
  53 // A Klass provides:
  54 //  1: language level class object (method dictionary etc.)
  55 //  2: provide vm dispatch behavior for the object
  56 // Both functions are combined into one C++ class.
  57 
  58 // One reason for the oop/klass dichotomy in the implementation is
  59 // that we don't want a C++ vtbl pointer in every object.  Thus,
  60 // normal oops don't have any virtual functions.  Instead, they
  61 // forward all "virtual" functions to their klass, which does have
  62 // a vtbl and does the C++ dispatch depending on the object's
  63 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  64 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
  65 
  66 // Forward declarations.
  67 template <class T> class Array;
  68 template <class T> class GrowableArray;
  69 class fieldDescriptor;
  70 class KlassSizeStats;


  81  protected:
  82   // If you add a new field that points to any metaspace object, you
  83   // must add this field to Klass::metaspace_pointers_do().
  84 
  85   // note: put frequently-used fields together at start of klass structure
  86   // for better cache behavior (may not make much of a difference but sure won't hurt)
  87   enum { _primary_super_limit = 8 };
  88 
  89   // The "layout helper" is a combined descriptor of object layout.
  90   // For klasses which are neither instance nor array, the value is zero.
  91   //
  92   // For instances, layout helper is a positive number, the instance size.
  93   // This size is already passed through align_object_size and scaled to bytes.
  94   // The low order bit is set if instances of this class cannot be
  95   // allocated using the fastpath.
  96   //
  97   // For arrays, layout helper is a negative number, containing four
  98   // distinct bytes, as follows:
  99   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
 100   // where:
 101   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
 102   //    hsz is array header size in bytes (i.e., offset of first element)
 103   //    ebt is the BasicType of the elements
 104   //    esz is the element size in bytes
 105   // This packed word is arranged so as to be quickly unpacked by the
 106   // various fast paths that use the various subfields.
 107   //
 108   // The esz bits can be used directly by a SLL instruction, without masking.
 109   //
 110   // Note that the array-kind tag looks like 0x00 for instance klasses,
 111   // since their length in bytes is always less than 24Mb.
 112   //
 113   // Final note:  This comes first, immediately after C++ vtable,
 114   // because it is frequently queried.
 115   jint        _layout_helper;
 116 
 117   // Klass identifier used to implement devirtualized oop closure dispatching.
 118   const KlassID _id;
 119 
 120   // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
 121   // and _primary_supers all help make fast subtype checks.  See big discussion


 331   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
 332   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
 333   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
 334   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
 335   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
 336   static ByteSize class_loader_data_offset()     { return in_ByteSize(offset_of(Klass, _class_loader_data)); }
 337   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
 338   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
 339   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
 340 
 341   // Unpacking layout_helper:
 342   enum {
 343     _lh_neutral_value           = 0,  // neutral non-array non-instance value
 344     _lh_instance_slow_path_bit  = 0x01,
 345     _lh_log2_element_size_shift = BitsPerByte*0,
 346     _lh_log2_element_size_mask  = BitsPerLong-1,
 347     _lh_element_type_shift      = BitsPerByte*1,
 348     _lh_element_type_mask       = right_n_bits(BitsPerByte),  // shifted mask
 349     _lh_header_size_shift       = BitsPerByte*2,
 350     _lh_header_size_mask        = right_n_bits(BitsPerByte),  // shifted mask
 351     _lh_array_tag_bits          = 2,
 352     _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits,
 353     _lh_array_tag_obj_value     = ~0x01   // 0x80000000 >> 30
 354   };
 355 
 356   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30


 357 
 358   static int layout_helper_size_in_bytes(jint lh) {
 359     assert(lh > (jint)_lh_neutral_value, "must be instance");
 360     return (int) lh & ~_lh_instance_slow_path_bit;
 361   }
 362   static bool layout_helper_needs_slow_path(jint lh) {
 363     assert(lh > (jint)_lh_neutral_value, "must be instance");
 364     return (lh & _lh_instance_slow_path_bit) != 0;
 365   }
 366   static bool layout_helper_is_instance(jint lh) {
 367     return (jint)lh > (jint)_lh_neutral_value;
 368   }
 369   static bool layout_helper_is_array(jint lh) {
 370     return (jint)lh < (jint)_lh_neutral_value;
 371   }
 372   static bool layout_helper_is_typeArray(jint lh) {
 373     // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
 374     return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
 375   }
 376   static bool layout_helper_is_objArray(jint lh) {
 377     // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
 378     return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);


 379   }
 380   static int layout_helper_header_size(jint lh) {
 381     assert(lh < (jint)_lh_neutral_value, "must be array");
 382     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
 383     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
 384     return hsize;
 385   }
 386   static BasicType layout_helper_element_type(jint lh) {
 387     assert(lh < (jint)_lh_neutral_value, "must be array");
 388     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
 389     assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
 390     return (BasicType) btvalue;
 391   }
 392 
 393   // Want a pattern to quickly diff against layout header in register
 394   // find something less clever!
 395   static int layout_helper_boolean_diffbit() {
 396     jint zlh = array_layout_helper(T_BOOLEAN);
 397     jint blh = array_layout_helper(T_BYTE);
 398     assert(zlh != blh, "array layout helpers must differ");
 399     int diffbit = 1;
 400     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
 401       diffbit <<= 1;
 402       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
 403     }
 404     return diffbit;
 405   }
 406 
 407   static int layout_helper_log2_element_size(jint lh) {
 408     assert(lh < (jint)_lh_neutral_value, "must be array");
 409     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
 410     assert(l2esz <= LogBytesPerLong,
 411            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
 412     return l2esz;
 413   }
 414   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
 415     return (tag        << _lh_array_tag_shift)
 416       |    (hsize      << _lh_header_size_shift)
 417       |    ((int)etype << _lh_element_type_shift)
 418       |    (log2_esize << _lh_log2_element_size_shift);
 419   }
 420   static jint instance_layout_helper(jint size, bool slow_path_flag) {
 421     return (size << LogBytesPerWord)
 422       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
 423   }
 424   static int layout_helper_to_size_helper(jint lh) {
 425     assert(lh > (jint)_lh_neutral_value, "must be instance");
 426     // Note that the following expression discards _lh_instance_slow_path_bit.
 427     return lh >> LogBytesPerWord;
 428   }
 429   // Out-of-line version computes everything based on the etype:
 430   static jint array_layout_helper(BasicType etype);


 463 
 464   // array copying
 465   virtual void  copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
 466 
 467   // tells if the class should be initialized
 468   virtual bool should_be_initialized() const    { return false; }
 469   // initializes the klass
 470   virtual void initialize(TRAPS);
 471   // lookup operation for MethodLookupCache
 472   friend class MethodLookupCache;
 473   virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
 474   virtual Method* uncached_lookup_method(const Symbol* name, const Symbol* signature,
 475                                          OverpassLookupMode overpass_mode,
 476                                          PrivateLookupMode = find_private) const;
 477  public:
 478   Method* lookup_method(const Symbol* name, const Symbol* signature) const {
 479     return uncached_lookup_method(name, signature, find_overpass);
 480   }
 481 
 482   // array class with specific rank
 483   Klass* array_klass(int rank, TRAPS)         {  return array_klass_impl(false, rank, THREAD); }






 484 
 485   // array class with this klass as element type
 486   Klass* array_klass(TRAPS)                   {  return array_klass_impl(false, THREAD); }






 487 
 488   // These will return NULL instead of allocating on the heap:
 489   // NB: these can block for a mutex, like other functions with TRAPS arg.
 490   Klass* array_klass_or_null(int rank);
 491   Klass* array_klass_or_null();
 492 
 493   virtual oop protection_domain() const = 0;
 494 
 495   oop class_loader() const;
 496 
 497   // This loads the klass's holder as a phantom. This is useful when a weak Klass
 498   // pointer has been "peeked" and then must be kept alive before it may
 499   // be used safely.  All uses of klass_holder need to apply the appropriate barriers,
 500   // except during GC.
 501   oop klass_holder() const { return class_loader_data()->holder_phantom(); }
 502 
 503  protected:
 504   virtual Klass* array_klass_impl(bool or_null, int rank, TRAPS);
 505   virtual Klass* array_klass_impl(bool or_null, TRAPS);
 506 
 507   // Error handling when length > max_length or length < 0
 508   static void check_array_allocation_length(int length, int max_length, TRAPS);
 509 
 510   void set_vtable_length(int len) { _vtable_len= len; }
 511 
 512   vtableEntry* start_of_vtable() const;
 513  public:
 514   Method* method_at_vtable(int index);
 515 
 516   static ByteSize vtable_start_offset();
 517   static ByteSize vtable_length_offset() {
 518     return byte_offset_of(Klass, _vtable_len);
 519   }
 520 
 521   // CDS support - remove and restore oops from metadata. Oops are not shared.
 522   virtual void remove_unshareable_info();
 523   virtual void remove_java_mirror();
 524   virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
 525 


 532 
 533   // actual oop size of obj in memory
 534   virtual int oop_size(oop obj) const = 0;
 535 
 536   // Size of klass in word size.
 537   virtual int size() const = 0;
 538 #if INCLUDE_SERVICES
 539   virtual void collect_statistics(KlassSizeStats *sz) const;
 540 #endif
 541 
 542   // Returns the Java name for a class (Resource allocated)
 543   // For arrays, this returns the name of the element with a leading '['.
 544   // For classes, this returns the name with the package separators
 545   //     turned into '.'s.
 546   const char* external_name() const;
 547   // Returns the name for a class (Resource allocated) as the class
 548   // would appear in a signature.
 549   // For arrays, this returns the name of the element with a leading '['.
 550   // For classes, this returns the name with a leading 'L' and a trailing ';'
 551   //     and the package separators as '/'.


 552   virtual const char* signature_name() const;
 553 
 554   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
 555   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
 556 
 557   // Returns "interface", "abstract class" or "class".
 558   const char* external_kind() const;
 559 
 560   // type testing operations
 561 #ifdef ASSERT
 562  protected:
 563   virtual bool is_instance_klass_slow()     const { return false; }
 564   virtual bool is_array_klass_slow()        const { return false; }
 565   virtual bool is_objArray_klass_slow()     const { return false; }
 566   virtual bool is_typeArray_klass_slow()    const { return false; }

 567 #endif // ASSERT


 568  public:
 569 
 570   // Fast non-virtual versions
 571   #ifndef ASSERT
 572   #define assert_same_query(xval, xcheck) xval
 573   #else
 574  private:
 575   static bool assert_same_query(bool xval, bool xslow) {
 576     assert(xval == xslow, "slow and fast queries agree");
 577     return xval;
 578   }
 579  public:
 580   #endif
 581   inline  bool is_instance_klass()            const { return assert_same_query(
 582                                                       layout_helper_is_instance(layout_helper()),
 583                                                       is_instance_klass_slow()); }
 584   inline  bool is_array_klass()               const { return assert_same_query(
 585                                                     layout_helper_is_array(layout_helper()),
 586                                                     is_array_klass_slow()); }
 587   inline  bool is_objArray_klass()            const { return assert_same_query(
 588                                                     layout_helper_is_objArray(layout_helper()),
 589                                                     is_objArray_klass_slow()); }
 590   inline  bool is_typeArray_klass()           const { return assert_same_query(
 591                                                     layout_helper_is_typeArray(layout_helper()),
 592                                                     is_typeArray_klass_slow()); }





 593   #undef assert_same_query
 594 
 595   // Access flags
 596   AccessFlags access_flags() const         { return _access_flags;  }
 597   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
 598 
 599   bool is_public() const                { return _access_flags.is_public(); }
 600   bool is_final() const                 { return _access_flags.is_final(); }
 601   bool is_interface() const             { return _access_flags.is_interface(); }
 602   bool is_abstract() const              { return _access_flags.is_abstract(); }
 603   bool is_super() const                 { return _access_flags.is_super(); }
 604   bool is_synthetic() const             { return _access_flags.is_synthetic(); }
 605   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
 606   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
 607   bool has_final_method() const         { return _access_flags.has_final_method(); }
 608   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
 609   void set_has_final_method()           { _access_flags.set_has_final_method(); }
 610   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
 611   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
 612   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
 613   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
 614   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
 615   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
 616 
 617   bool is_cloneable() const;
 618   void set_is_cloneable();
 619 
 620   // Biased locking support
 621   // Note: the prototype header is always set up to be at least the
 622   // prototype markOop. If biased locking is enabled it may further be
 623   // biasable and have an epoch.
 624   markOop prototype_header() const      { return _prototype_header; }




 625   // NOTE: once instances of this klass are floating around in the
 626   // system, this header must only be updated at a safepoint.
 627   // NOTE 2: currently we only ever set the prototype header to the
 628   // biasable prototype for instanceKlasses. There is no technical
 629   // reason why it could not be done for arrayKlasses aside from
 630   // wanting to reduce the initial scope of this optimization. There
 631   // are potential problems in setting the bias pattern for
 632   // JVM-internal oops.
 633   inline void set_prototype_header(markOop header);
 634   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
 635 
 636   int  biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
 637   // Atomically increments biased_lock_revocation_count and returns updated value
 638   int atomic_incr_biased_lock_revocation_count();
 639   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 640   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 641   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 642 
 643   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 644 




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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_KLASS_HPP
  26 #define SHARE_OOPS_KLASS_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "memory/iterator.hpp"
  30 #include "memory/memRegion.hpp"
  31 #include "oops/arrayStorageProperties.hpp"
  32 #include "oops/markOop.hpp"
  33 #include "oops/metadata.hpp"
  34 #include "oops/oop.hpp"
  35 #include "oops/oopHandle.hpp"
  36 #include "utilities/accessFlags.hpp"
  37 #include "utilities/macros.hpp"
  38 #if INCLUDE_JFR
  39 #include "jfr/support/jfrTraceIdExtension.hpp"
  40 #endif
  41 
  42 // Klass IDs for all subclasses of Klass
  43 enum KlassID {
  44   InstanceKlassID,
  45   InstanceRefKlassID,
  46   InstanceMirrorKlassID,
  47   InstanceClassLoaderKlassID,
  48   TypeArrayKlassID,
  49   ValueArrayKlassID,
  50   ObjArrayKlassID
  51 };
  52 
  53 const uint KLASS_ID_COUNT = 7;
  54 
  55 //
  56 // A Klass provides:
  57 //  1: language level class object (method dictionary etc.)
  58 //  2: provide vm dispatch behavior for the object
  59 // Both functions are combined into one C++ class.
  60 
  61 // One reason for the oop/klass dichotomy in the implementation is
  62 // that we don't want a C++ vtbl pointer in every object.  Thus,
  63 // normal oops don't have any virtual functions.  Instead, they
  64 // forward all "virtual" functions to their klass, which does have
  65 // a vtbl and does the C++ dispatch depending on the object's
  66 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  67 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
  68 
  69 // Forward declarations.
  70 template <class T> class Array;
  71 template <class T> class GrowableArray;
  72 class fieldDescriptor;
  73 class KlassSizeStats;


  84  protected:
  85   // If you add a new field that points to any metaspace object, you
  86   // must add this field to Klass::metaspace_pointers_do().
  87 
  88   // note: put frequently-used fields together at start of klass structure
  89   // for better cache behavior (may not make much of a difference but sure won't hurt)
  90   enum { _primary_super_limit = 8 };
  91 
  92   // The "layout helper" is a combined descriptor of object layout.
  93   // For klasses which are neither instance nor array, the value is zero.
  94   //
  95   // For instances, layout helper is a positive number, the instance size.
  96   // This size is already passed through align_object_size and scaled to bytes.
  97   // The low order bit is set if instances of this class cannot be
  98   // allocated using the fastpath.
  99   //
 100   // For arrays, layout helper is a negative number, containing four
 101   // distinct bytes, as follows:
 102   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
 103   // where:
 104   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops, 0xA0 if value types
 105   //    hsz is array header size in bytes (i.e., offset of first element)
 106   //    ebt is the BasicType of the elements
 107   //    esz is the element size in bytes
 108   // This packed word is arranged so as to be quickly unpacked by the
 109   // various fast paths that use the various subfields.
 110   //
 111   // The esz bits can be used directly by a SLL instruction, without masking.
 112   //
 113   // Note that the array-kind tag looks like 0x00 for instance klasses,
 114   // since their length in bytes is always less than 24Mb.
 115   //
 116   // Final note:  This comes first, immediately after C++ vtable,
 117   // because it is frequently queried.
 118   jint        _layout_helper;
 119 
 120   // Klass identifier used to implement devirtualized oop closure dispatching.
 121   const KlassID _id;
 122 
 123   // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
 124   // and _primary_supers all help make fast subtype checks.  See big discussion


 334   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
 335   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
 336   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
 337   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
 338   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
 339   static ByteSize class_loader_data_offset()     { return in_ByteSize(offset_of(Klass, _class_loader_data)); }
 340   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
 341   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
 342   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
 343 
 344   // Unpacking layout_helper:
 345   enum {
 346     _lh_neutral_value           = 0,  // neutral non-array non-instance value
 347     _lh_instance_slow_path_bit  = 0x01,
 348     _lh_log2_element_size_shift = BitsPerByte*0,
 349     _lh_log2_element_size_mask  = BitsPerLong-1,
 350     _lh_element_type_shift      = BitsPerByte*1,
 351     _lh_element_type_mask       = right_n_bits(BitsPerByte),  // shifted mask
 352     _lh_header_size_shift       = BitsPerByte*2,
 353     _lh_header_size_mask        = right_n_bits(BitsPerByte),  // shifted mask
 354     _lh_array_tag_bits          = 3,
 355     _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits

 356   };
 357 
 358   static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
 359   static const unsigned int _lh_array_tag_vt_value   = 0Xfffffffd;
 360   static const unsigned int _lh_array_tag_obj_value  = 0Xfffffffe;
 361 
 362   static int layout_helper_size_in_bytes(jint lh) {
 363     assert(lh > (jint)_lh_neutral_value, "must be instance");
 364     return (int) lh & ~_lh_instance_slow_path_bit;
 365   }
 366   static bool layout_helper_needs_slow_path(jint lh) {
 367     assert(lh > (jint)_lh_neutral_value, "must be instance");
 368     return (lh & _lh_instance_slow_path_bit) != 0;
 369   }
 370   static bool layout_helper_is_instance(jint lh) {
 371     return (jint)lh > (jint)_lh_neutral_value;
 372   }
 373   static bool layout_helper_is_array(jint lh) {
 374     return (jint)lh < (jint)_lh_neutral_value;
 375   }
 376   static bool layout_helper_is_typeArray(jint lh) {
 377     return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);

 378   }
 379   static bool layout_helper_is_objArray(jint lh) {
 380     return (juint)_lh_array_tag_obj_value == (juint)(lh >> _lh_array_tag_shift);
 381   }
 382   static bool layout_helper_is_valueArray(jint lh) {
 383     return (juint)_lh_array_tag_vt_value == (juint)(lh >> _lh_array_tag_shift);
 384   }
 385   static int layout_helper_header_size(jint lh) {
 386     assert(lh < (jint)_lh_neutral_value, "must be array");
 387     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
 388     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
 389     return hsize;
 390   }
 391   static BasicType layout_helper_element_type(jint lh) {
 392     assert(lh < (jint)_lh_neutral_value, "must be array");
 393     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
 394     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_VALUETYPE, "sanity");
 395     return (BasicType) btvalue;
 396   }
 397 
 398   // Want a pattern to quickly diff against layout header in register
 399   // find something less clever!
 400   static int layout_helper_boolean_diffbit() {
 401     jint zlh = array_layout_helper(T_BOOLEAN);
 402     jint blh = array_layout_helper(T_BYTE);
 403     assert(zlh != blh, "array layout helpers must differ");
 404     int diffbit = 1;
 405     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
 406       diffbit <<= 1;
 407       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
 408     }
 409     return diffbit;
 410   }
 411 
 412   static int layout_helper_log2_element_size(jint lh) {
 413     assert(lh < (jint)_lh_neutral_value, "must be array");
 414     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
 415     assert(layout_helper_element_type(lh) == T_VALUETYPE || l2esz <= LogBytesPerLong,
 416            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
 417     return l2esz;
 418   }
 419   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
 420     return (tag        << _lh_array_tag_shift)
 421       |    (hsize      << _lh_header_size_shift)
 422       |    ((int)etype << _lh_element_type_shift)
 423       |    (log2_esize << _lh_log2_element_size_shift);
 424   }
 425   static jint instance_layout_helper(jint size, bool slow_path_flag) {
 426     return (size << LogBytesPerWord)
 427       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
 428   }
 429   static int layout_helper_to_size_helper(jint lh) {
 430     assert(lh > (jint)_lh_neutral_value, "must be instance");
 431     // Note that the following expression discards _lh_instance_slow_path_bit.
 432     return lh >> LogBytesPerWord;
 433   }
 434   // Out-of-line version computes everything based on the etype:
 435   static jint array_layout_helper(BasicType etype);


 468 
 469   // array copying
 470   virtual void  copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
 471 
 472   // tells if the class should be initialized
 473   virtual bool should_be_initialized() const    { return false; }
 474   // initializes the klass
 475   virtual void initialize(TRAPS);
 476   // lookup operation for MethodLookupCache
 477   friend class MethodLookupCache;
 478   virtual Klass* find_field(Symbol* name, Symbol* signature, fieldDescriptor* fd) const;
 479   virtual Method* uncached_lookup_method(const Symbol* name, const Symbol* signature,
 480                                          OverpassLookupMode overpass_mode,
 481                                          PrivateLookupMode = find_private) const;
 482  public:
 483   Method* lookup_method(const Symbol* name, const Symbol* signature) const {
 484     return uncached_lookup_method(name, signature, find_overpass);
 485   }
 486 
 487   // array class with specific rank
 488   Klass* array_klass(int rank, TRAPS) {
 489     return array_klass_impl(ArrayStorageProperties::empty, false, rank, THREAD);
 490   }
 491 
 492   Klass* array_klass(ArrayStorageProperties storage_props, int rank, TRAPS) {
 493     return array_klass_impl(storage_props, false, rank, THREAD);
 494   }
 495 
 496   // array class with this klass as element type
 497   Klass* array_klass(TRAPS) {
 498     return array_klass_impl(ArrayStorageProperties::empty, false, THREAD);
 499   }
 500 
 501   Klass* array_klass(ArrayStorageProperties storage_props, TRAPS) {
 502     return array_klass_impl(storage_props, false, THREAD);
 503   }
 504 
 505   // These will return NULL instead of allocating on the heap:
 506   // NB: these can block for a mutex, like other functions with TRAPS arg.
 507   Klass* array_klass_or_null(ArrayStorageProperties storage_props, int rank);
 508   Klass* array_klass_or_null(ArrayStorageProperties storage_props);
 509 
 510   virtual oop protection_domain() const = 0;
 511 
 512   oop class_loader() const;
 513 
 514   // This loads the klass's holder as a phantom. This is useful when a weak Klass
 515   // pointer has been "peeked" and then must be kept alive before it may
 516   // be used safely.  All uses of klass_holder need to apply the appropriate barriers,
 517   // except during GC.
 518   oop klass_holder() const { return class_loader_data()->holder_phantom(); }
 519 
 520  protected:
 521   virtual Klass* array_klass_impl(ArrayStorageProperties storage_props, bool or_null, int rank, TRAPS);
 522   virtual Klass* array_klass_impl(ArrayStorageProperties storage_props, bool or_null, TRAPS);
 523 
 524   // Error handling when length > max_length or length < 0
 525   static void check_array_allocation_length(int length, int max_length, TRAPS);
 526 
 527   void set_vtable_length(int len) { _vtable_len= len; }
 528 
 529   vtableEntry* start_of_vtable() const;
 530  public:
 531   Method* method_at_vtable(int index);
 532 
 533   static ByteSize vtable_start_offset();
 534   static ByteSize vtable_length_offset() {
 535     return byte_offset_of(Klass, _vtable_len);
 536   }
 537 
 538   // CDS support - remove and restore oops from metadata. Oops are not shared.
 539   virtual void remove_unshareable_info();
 540   virtual void remove_java_mirror();
 541   virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
 542 


 549 
 550   // actual oop size of obj in memory
 551   virtual int oop_size(oop obj) const = 0;
 552 
 553   // Size of klass in word size.
 554   virtual int size() const = 0;
 555 #if INCLUDE_SERVICES
 556   virtual void collect_statistics(KlassSizeStats *sz) const;
 557 #endif
 558 
 559   // Returns the Java name for a class (Resource allocated)
 560   // For arrays, this returns the name of the element with a leading '['.
 561   // For classes, this returns the name with the package separators
 562   //     turned into '.'s.
 563   const char* external_name() const;
 564   // Returns the name for a class (Resource allocated) as the class
 565   // would appear in a signature.
 566   // For arrays, this returns the name of the element with a leading '['.
 567   // For classes, this returns the name with a leading 'L' and a trailing ';'
 568   //     and the package separators as '/'.
 569   // For value classes, this returns the name with a leading 'Q' and a trailing ';'
 570   //     and the package separators as '/'.
 571   virtual const char* signature_name() const;
 572 
 573   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
 574   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
 575 
 576   // Returns "interface", "abstract class" or "class".
 577   const char* external_kind() const;
 578 
 579   // type testing operations
 580 #ifdef ASSERT
 581  protected:
 582   virtual bool is_instance_klass_slow()     const { return false; }
 583   virtual bool is_array_klass_slow()        const { return false; }
 584   virtual bool is_objArray_klass_slow()     const { return false; }
 585   virtual bool is_typeArray_klass_slow()    const { return false; }
 586   virtual bool is_valueArray_klass_slow()   const { return false; }
 587 #endif // ASSERT
 588   // current implementation uses this method even in non debug builds
 589   virtual bool is_value_slow()          const { return false; }
 590  public:
 591 
 592   // Fast non-virtual versions
 593   #ifndef ASSERT
 594   #define assert_same_query(xval, xcheck) xval
 595   #else
 596  private:
 597   static bool assert_same_query(bool xval, bool xslow) {
 598     assert(xval == xslow, "slow and fast queries agree");
 599     return xval;
 600   }
 601  public:
 602   #endif
 603   inline  bool is_instance_klass()            const { return assert_same_query(
 604                                                       layout_helper_is_instance(layout_helper()),
 605                                                       is_instance_klass_slow()); }
 606   inline  bool is_array_klass()               const { return assert_same_query(
 607                                                     layout_helper_is_array(layout_helper()),
 608                                                     is_array_klass_slow()); }
 609   inline  bool is_objArray_klass()            const { return assert_same_query(
 610                                                     layout_helper_is_objArray(layout_helper()),
 611                                                     is_objArray_klass_slow()); }
 612   inline  bool is_typeArray_klass()           const { return assert_same_query(
 613                                                     layout_helper_is_typeArray(layout_helper()),
 614                                                     is_typeArray_klass_slow()); }
 615   inline  bool is_value()                     const { return is_value_slow(); } //temporary hack
 616   inline  bool is_valueArray_klass()          const { return assert_same_query(
 617                                                     layout_helper_is_valueArray(layout_helper()),
 618                                                     is_valueArray_klass_slow()); }
 619 
 620   #undef assert_same_query
 621 
 622   // Access flags
 623   AccessFlags access_flags() const         { return _access_flags;  }
 624   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
 625 
 626   bool is_public() const                { return _access_flags.is_public(); }
 627   bool is_final() const                 { return _access_flags.is_final(); }
 628   bool is_interface() const             { return _access_flags.is_interface(); }
 629   bool is_abstract() const              { return _access_flags.is_abstract(); }
 630   bool is_super() const                 { return _access_flags.is_super(); }
 631   bool is_synthetic() const             { return _access_flags.is_synthetic(); }
 632   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
 633   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
 634   bool has_final_method() const         { return _access_flags.has_final_method(); }
 635   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
 636   void set_has_final_method()           { _access_flags.set_has_final_method(); }
 637   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
 638   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
 639   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
 640   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
 641   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
 642   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
 643 
 644   bool is_cloneable() const;
 645   void set_is_cloneable();
 646 
 647   // Biased locking support
 648   // Note: the prototype header is always set up to be at least the
 649   // prototype markOop. If biased locking is enabled it may further be
 650   // biasable and have an epoch.
 651   markOop prototype_header() const      { return _prototype_header; }
 652   static inline markOop default_prototype_header(Klass* k) {
 653     return (k == NULL) ? markOopDesc::prototype() : k->prototype_header();
 654   }
 655 
 656   // NOTE: once instances of this klass are floating around in the
 657   // system, this header must only be updated at a safepoint.
 658   // NOTE 2: currently we only ever set the prototype header to the
 659   // biasable prototype for instanceKlasses. There is no technical
 660   // reason why it could not be done for arrayKlasses aside from
 661   // wanting to reduce the initial scope of this optimization. There
 662   // are potential problems in setting the bias pattern for
 663   // JVM-internal oops.
 664   inline void set_prototype_header(markOop header);
 665   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
 666 
 667   int  biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
 668   // Atomically increments biased_lock_revocation_count and returns updated value
 669   int atomic_incr_biased_lock_revocation_count();
 670   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 671   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 672   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 673 
 674   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 675 


< prev index next >