< prev index next >

src/share/vm/oops/klass.hpp

Print this page




  62 class Klass : public Metadata {
  63   friend class VMStructs;
  64   friend class JVMCIVMStructs;
  65  protected:
  66   // note: put frequently-used fields together at start of klass structure
  67   // for better cache behavior (may not make much of a difference but sure won't hurt)
  68   enum { _primary_super_limit = 8 };
  69 
  70   // The "layout helper" is a combined descriptor of object layout.
  71   // For klasses which are neither instance nor array, the value is zero.
  72   //
  73   // For instances, layout helper is a positive number, the instance size.
  74   // This size is already passed through align_object_size and scaled to bytes.
  75   // The low order bit is set if instances of this class cannot be
  76   // allocated using the fastpath.
  77   //
  78   // For arrays, layout helper is a negative number, containing four
  79   // distinct bytes, as follows:
  80   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
  81   // where:
  82   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
  83   //    hsz is array header size in bytes (i.e., offset of first element)
  84   //    ebt is the BasicType of the elements
  85   //    esz is the element size in bytes
  86   // This packed word is arranged so as to be quickly unpacked by the
  87   // various fast paths that use the various subfields.
  88   //
  89   // The esz bits can be used directly by a SLL instruction, without masking.
  90   //
  91   // Note that the array-kind tag looks like 0x00 for instance klasses,
  92   // since their length in bytes is always less than 24Mb.
  93   //
  94   // Final note:  This comes first, immediately after C++ vtable,
  95   // because it is frequently queried.
  96   jint        _layout_helper;
  97 
  98   // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
  99   // and _primary_supers all help make fast subtype checks.  See big discussion
 100   // in doc/server_compiler/checktype.txt
 101   //
 102   // Where to look to observe a supertype (it is &_secondary_super_cache for


 299   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
 300   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
 301   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
 302   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
 303   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
 304   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
 305   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
 306   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
 307 
 308   // Unpacking layout_helper:
 309   enum {
 310     _lh_neutral_value           = 0,  // neutral non-array non-instance value
 311     _lh_instance_slow_path_bit  = 0x01,
 312     _lh_log2_element_size_shift = BitsPerByte*0,
 313     _lh_log2_element_size_mask  = BitsPerLong-1,
 314     _lh_element_type_shift      = BitsPerByte*1,
 315     _lh_element_type_mask       = right_n_bits(BitsPerByte),  // shifted mask
 316     _lh_header_size_shift       = BitsPerByte*2,
 317     _lh_header_size_mask        = right_n_bits(BitsPerByte),  // shifted mask
 318 
 319     // Additional array type bits
 320     _lh_valuetype_bit         = 29, // maybe objArray or valueArrayOop
 321 
 322     _lh_array_tag_bits            = 2,
 323     _lh_array_tag_shift           = BitsPerInt - _lh_array_tag_bits,
 324     _lh_array_tag_type_value      = ~0x00,  // 0xC0000000 >> 30
 325     _lh_array_tag_obj_value       = ~0x01   // 0x80000000 >> 30

 326   };
 327 
 328   static int layout_helper_size_in_bytes(jint lh) {
 329     assert(lh > (jint)_lh_neutral_value, "must be instance");
 330     return (int) lh & ~_lh_instance_slow_path_bit;
 331   }
 332   static bool layout_helper_needs_slow_path(jint lh) {
 333     assert(lh > (jint)_lh_neutral_value, "must be instance");
 334     return (lh & _lh_instance_slow_path_bit) != 0;
 335   }
 336   static bool layout_helper_is_instance(jint lh) {
 337     return (jint)lh > (jint)_lh_neutral_value;
 338   }
 339   static bool layout_helper_is_array(jint lh) {
 340     return (jint)lh < (jint)_lh_neutral_value;
 341   }
 342   static bool layout_helper_is_typeArray(jint lh) {
 343     return _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
 344   }
 345   static bool layout_helper_is_objArray(jint lh) {
 346     return _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
 347   }
 348   static bool layout_helper_is_valueArray(jint lh) {
 349     return (lh >> _lh_valuetype_bit) & 1;
 350   }
 351   static int layout_helper_header_size(jint lh) {
 352     assert(lh < (jint)_lh_neutral_value, "must be array");
 353     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
 354     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
 355     return hsize;
 356   }
 357   static BasicType layout_helper_element_type(jint lh) {
 358     assert(lh < (jint)_lh_neutral_value, "must be array");
 359     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
 360     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_VALUETYPE, "sanity");
 361     return (BasicType) btvalue;
 362   }
 363   static int layout_helper_log2_element_size(jint lh) {
 364     assert(lh < (jint)_lh_neutral_value, "must be array");
 365     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
 366     assert(l2esz <= LogBitsPerLong,
 367            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
 368     return l2esz;
 369   }




  62 class Klass : public Metadata {
  63   friend class VMStructs;
  64   friend class JVMCIVMStructs;
  65  protected:
  66   // note: put frequently-used fields together at start of klass structure
  67   // for better cache behavior (may not make much of a difference but sure won't hurt)
  68   enum { _primary_super_limit = 8 };
  69 
  70   // The "layout helper" is a combined descriptor of object layout.
  71   // For klasses which are neither instance nor array, the value is zero.
  72   //
  73   // For instances, layout helper is a positive number, the instance size.
  74   // This size is already passed through align_object_size and scaled to bytes.
  75   // The low order bit is set if instances of this class cannot be
  76   // allocated using the fastpath.
  77   //
  78   // For arrays, layout helper is a negative number, containing four
  79   // distinct bytes, as follows:
  80   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
  81   // where:
  82   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops, 0xA0 if value types
  83   //    hsz is array header size in bytes (i.e., offset of first element)
  84   //    ebt is the BasicType of the elements
  85   //    esz is the element size in bytes
  86   // This packed word is arranged so as to be quickly unpacked by the
  87   // various fast paths that use the various subfields.
  88   //
  89   // The esz bits can be used directly by a SLL instruction, without masking.
  90   //
  91   // Note that the array-kind tag looks like 0x00 for instance klasses,
  92   // since their length in bytes is always less than 24Mb.
  93   //
  94   // Final note:  This comes first, immediately after C++ vtable,
  95   // because it is frequently queried.
  96   jint        _layout_helper;
  97 
  98   // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
  99   // and _primary_supers all help make fast subtype checks.  See big discussion
 100   // in doc/server_compiler/checktype.txt
 101   //
 102   // Where to look to observe a supertype (it is &_secondary_super_cache for


 299   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
 300   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
 301   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
 302   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
 303   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
 304   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
 305   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
 306   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
 307 
 308   // Unpacking layout_helper:
 309   enum {
 310     _lh_neutral_value           = 0,  // neutral non-array non-instance value
 311     _lh_instance_slow_path_bit  = 0x01,
 312     _lh_log2_element_size_shift = BitsPerByte*0,
 313     _lh_log2_element_size_mask  = BitsPerLong-1,
 314     _lh_element_type_shift      = BitsPerByte*1,
 315     _lh_element_type_mask       = right_n_bits(BitsPerByte),  // shifted mask
 316     _lh_header_size_shift       = BitsPerByte*2,
 317     _lh_header_size_mask        = right_n_bits(BitsPerByte),  // shifted mask
 318 
 319     _lh_array_tag_bits            = 3,



 320     _lh_array_tag_shift           = BitsPerInt - _lh_array_tag_bits,
 321     _lh_array_tag_type_value      = ~0x3,  // bits ~100 compare as int, ie. sign extended
 322     _lh_array_tag_vt_value        = ~0x2,  // bits ~101
 323     _lh_array_tag_obj_value       = ~0x1,  // bits ~110
 324   };
 325 
 326   static int layout_helper_size_in_bytes(jint lh) {
 327     assert(lh > (jint)_lh_neutral_value, "must be instance");
 328     return (int) lh & ~_lh_instance_slow_path_bit;
 329   }
 330   static bool layout_helper_needs_slow_path(jint lh) {
 331     assert(lh > (jint)_lh_neutral_value, "must be instance");
 332     return (lh & _lh_instance_slow_path_bit) != 0;
 333   }
 334   static bool layout_helper_is_instance(jint lh) {
 335     return (jint)lh > (jint)_lh_neutral_value;
 336   }
 337   static bool layout_helper_is_array(jint lh) {
 338     return (jint)lh < (jint)_lh_neutral_value;
 339   }
 340   static bool layout_helper_is_typeArray(jint lh) {
 341     return _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
 342   }
 343   static bool layout_helper_is_objArray(jint lh) {
 344     return _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
 345   }
 346   static bool layout_helper_is_valueArray(jint lh) {
 347     return _lh_array_tag_vt_value == (lh >> _lh_array_tag_shift);
 348   }
 349   static int layout_helper_header_size(jint lh) {
 350     assert(lh < (jint)_lh_neutral_value, "must be array");
 351     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
 352     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
 353     return hsize;
 354   }
 355   static BasicType layout_helper_element_type(jint lh) {
 356     assert(lh < (jint)_lh_neutral_value, "must be array");
 357     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
 358     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_VALUETYPE, "sanity");
 359     return (BasicType) btvalue;
 360   }
 361   static int layout_helper_log2_element_size(jint lh) {
 362     assert(lh < (jint)_lh_neutral_value, "must be array");
 363     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
 364     assert(l2esz <= LogBitsPerLong,
 365            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
 366     return l2esz;
 367   }


< prev index next >