< 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


 330   static ByteSize super_offset()                 { return in_ByteSize(offset_of(Klass, _super)); }
 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 modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
 337   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
 338   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
 339 
 340   // Unpacking layout_helper:
 341   enum {
 342     _lh_neutral_value           = 0,  // neutral non-array non-instance value
 343     _lh_instance_slow_path_bit  = 0x01,
 344     _lh_log2_element_size_shift = BitsPerByte*0,
 345     _lh_log2_element_size_mask  = BitsPerLong-1,
 346     _lh_element_type_shift      = BitsPerByte*1,
 347     _lh_element_type_mask       = right_n_bits(BitsPerByte),  // shifted mask
 348     _lh_header_size_shift       = BitsPerByte*2,
 349     _lh_header_size_mask        = right_n_bits(BitsPerByte),  // shifted mask
 350     _lh_array_tag_bits          = 2,
 351     _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits,
 352     _lh_array_tag_obj_value     = ~0x01   // 0x80000000 >> 30
 353   };
 354 
 355   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30


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


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


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


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

 566 #endif // ASSERT


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





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




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




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


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


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

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

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


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


< prev index next >