src/share/vm/oops/markOop.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File cms-comp Sdiff src/share/vm/oops

src/share/vm/oops/markOop.hpp

Print this page




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 // The markOop describes the header of an object.
  26 //
  27 // Note that the mark is not a real oop but just a word.
  28 // It is placed in the oop hierarchy for historical reasons.
  29 //
  30 // Bit-format of an object header (most significant first):
  31 //
  32 //
  33 //  unused:0/25 hash:25/31 age:4 biased_lock:1 lock:2 = 32/64 bits

  34 //
  35 //  - hash contains the identity hash value: largest value is
  36 //    31 bits, see os::random().  Also, 64-bit vm's require
  37 //    a hash value no bigger than 32 bits because they will not
  38 //    properly generate a mask larger than that: see library_call.cpp
  39 //    and c1_CodePatterns_sparc.cpp.
  40 //
  41 //  - the biased lock pattern is used to bias a lock toward a given
  42 //    thread. When this pattern is set in the low three bits, the lock
  43 //    is either biased toward a given thread or "anonymously" biased,
  44 //    indicating that it is possible for it to be biased. When the
  45 //    lock is biased toward a given thread, locking and unlocking can
  46 //    be performed by that thread without using atomic operations.
  47 //    When a lock's bias is revoked, it reverts back to the normal
  48 //    locking scheme described below.
  49 //
  50 //    Note that we are overloading the meaning of the "unlocked" state
  51 //    of the header. Because we steal a bit from the age we can
  52 //    guarantee that the bias pattern will never be seen for a truly
  53 //    unlocked object.


  74 //                                               not valid at any other time
  75 //
  76 //    We assume that stack/thread pointers have the lowest two bits cleared.
  77 
  78 class BasicLock;
  79 class ObjectMonitor;
  80 class JavaThread;
  81 
  82 class markOopDesc: public oopDesc {
  83  private:
  84   // Conversion
  85   uintptr_t value() const { return (uintptr_t) this; }
  86 
  87  public:
  88   // Constants
  89   enum { age_bits                 = 4,
  90          lock_bits                = 2,
  91          biased_lock_bits         = 1,
  92          max_hash_bits            = BitsPerWord - age_bits - lock_bits - biased_lock_bits,
  93          hash_bits                = max_hash_bits > 31 ? 31 : max_hash_bits,

  94          epoch_bits               = 2
  95   };
  96 
  97   // The biased locking code currently requires that the age bits be
  98   // contiguous to the lock bits. Class data sharing would prefer the
  99   // hash bits to be lower down to provide more random hash codes for
 100   // shared read-only symbolOop objects, because these objects' mark
 101   // words are set to their own address with marked_value in the lock
 102   // bit, and using lower bits would make their identity hash values
 103   // more random. However, the performance decision was made in favor
 104   // of the biased locking code.
 105 
 106   enum { lock_shift               = 0,
 107          biased_lock_shift        = lock_bits,
 108          age_shift                = lock_bits + biased_lock_bits,
 109          hash_shift               = lock_bits + biased_lock_bits + age_bits,

 110          epoch_shift              = hash_shift
 111   };
 112 
 113   enum { lock_mask                = right_n_bits(lock_bits),
 114          lock_mask_in_place       = lock_mask << lock_shift,
 115          biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits),
 116          biased_lock_mask_in_place= biased_lock_mask << lock_shift,
 117          biased_lock_bit_in_place = 1 << biased_lock_shift,
 118          age_mask                 = right_n_bits(age_bits),
 119          age_mask_in_place        = age_mask << age_shift,
 120          epoch_mask               = right_n_bits(epoch_bits),
 121          epoch_mask_in_place      = epoch_mask << epoch_shift


 122 #ifndef _WIN64
 123          ,hash_mask               = right_n_bits(hash_bits),
 124          hash_mask_in_place       = (address_word)hash_mask << hash_shift
 125 #endif
 126   };
 127 
 128   // Alignment of JavaThread pointers encoded in object header required by biased locking
 129   enum { biased_lock_alignment    = 2 << (epoch_shift + epoch_bits)
 130   };
 131 
 132 #ifdef _WIN64
 133     // These values are too big for Win64
 134     const static uintptr_t hash_mask = right_n_bits(hash_bits);
 135     const static uintptr_t hash_mask_in_place  =
 136                             (address_word)hash_mask << hash_shift;
 137 #endif
 138 
 139   enum { locked_value             = 0,
 140          unlocked_value           = 1,
 141          monitor_value            = 2,


 343 
 344   // Prototype mark for initialization
 345   static markOop prototype() {
 346     return markOop( no_hash_in_place | no_lock_in_place );
 347   }
 348 
 349   // Helper function for restoration of unmarked mark oops during GC
 350   static inline markOop prototype_for_object(oop obj);
 351 
 352   // Debugging
 353   void print_on(outputStream* st) const;
 354 
 355   // Prepare address of oop for placement into mark
 356   inline static markOop encode_pointer_as_mark(void* p) { return markOop(p)->set_marked(); }
 357 
 358   // Recover address of oop from encoded form used in mark
 359   inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return clear_lock_bits(); }
 360 
 361   // see the definition in markOop.cpp for the gory details
 362   bool should_not_be_cached() const;














































 363 };


  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 // The markOop describes the header of an object.
  26 //
  27 // Note that the mark is not a real oop but just a word.
  28 // It is placed in the oop hierarchy for historical reasons.
  29 //
  30 // Bit-format of an object header (most significant first):
  31 //
  32 //
  33 //  32 bits: hash:25/31 age:4 biased_lock:1 lock:2
  34 //  64 bits: unused:0/23 hash:27/33 cms:2 age:4 biased_lock:1 lock:2
  35 //
  36 //  - hash contains the identity hash value: largest value is
  37 //    31 bits, see os::random().  Also, 64-bit vm's require
  38 //    a hash value no bigger than 32 bits because they will not
  39 //    properly generate a mask larger than that: see library_call.cpp
  40 //    and c1_CodePatterns_sparc.cpp.
  41 //
  42 //  - the biased lock pattern is used to bias a lock toward a given
  43 //    thread. When this pattern is set in the low three bits, the lock
  44 //    is either biased toward a given thread or "anonymously" biased,
  45 //    indicating that it is possible for it to be biased. When the
  46 //    lock is biased toward a given thread, locking and unlocking can
  47 //    be performed by that thread without using atomic operations.
  48 //    When a lock's bias is revoked, it reverts back to the normal
  49 //    locking scheme described below.
  50 //
  51 //    Note that we are overloading the meaning of the "unlocked" state
  52 //    of the header. Because we steal a bit from the age we can
  53 //    guarantee that the bias pattern will never be seen for a truly
  54 //    unlocked object.


  75 //                                               not valid at any other time
  76 //
  77 //    We assume that stack/thread pointers have the lowest two bits cleared.
  78 
  79 class BasicLock;
  80 class ObjectMonitor;
  81 class JavaThread;
  82 
  83 class markOopDesc: public oopDesc {
  84  private:
  85   // Conversion
  86   uintptr_t value() const { return (uintptr_t) this; }
  87 
  88  public:
  89   // Constants
  90   enum { age_bits                 = 4,
  91          lock_bits                = 2,
  92          biased_lock_bits         = 1,
  93          max_hash_bits            = BitsPerWord - age_bits - lock_bits - biased_lock_bits,
  94          hash_bits                = max_hash_bits > 31 ? 31 : max_hash_bits,
  95          cms_bits                 = LP64_ONLY(2) NOT_LP64(0),
  96          epoch_bits               = 2
  97   };
  98 
  99   // The biased locking code currently requires that the age bits be
 100   // contiguous to the lock bits. Class data sharing would prefer the
 101   // hash bits to be lower down to provide more random hash codes for
 102   // shared read-only symbolOop objects, because these objects' mark
 103   // words are set to their own address with marked_value in the lock
 104   // bit, and using lower bits would make their identity hash values
 105   // more random. However, the performance decision was made in favor
 106   // of the biased locking code.
 107 
 108   enum { lock_shift               = 0,
 109          biased_lock_shift        = lock_bits,
 110          age_shift                = lock_bits + biased_lock_bits,
 111          cms_shift                = age_shift + age_bits,
 112          hash_shift               = cms_shift + cms_bits,
 113          epoch_shift              = hash_shift
 114   };
 115 
 116   enum { lock_mask                = right_n_bits(lock_bits),
 117          lock_mask_in_place       = lock_mask << lock_shift,
 118          biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits),
 119          biased_lock_mask_in_place= biased_lock_mask << lock_shift,
 120          biased_lock_bit_in_place = 1 << biased_lock_shift,
 121          age_mask                 = right_n_bits(age_bits),
 122          age_mask_in_place        = age_mask << age_shift,
 123          epoch_mask               = right_n_bits(epoch_bits),
 124          epoch_mask_in_place      = epoch_mask << epoch_shift,
 125          cms_mask                 = right_n_bits(cms_bits),
 126          cms_mask_in_place        = cms_mask << cms_shift
 127 #ifndef _WIN64
 128          ,hash_mask               = right_n_bits(hash_bits),
 129          hash_mask_in_place       = (address_word)hash_mask << hash_shift
 130 #endif
 131   };
 132 
 133   // Alignment of JavaThread pointers encoded in object header required by biased locking
 134   enum { biased_lock_alignment    = 2 << (epoch_shift + epoch_bits)
 135   };
 136 
 137 #ifdef _WIN64
 138     // These values are too big for Win64
 139     const static uintptr_t hash_mask = right_n_bits(hash_bits);
 140     const static uintptr_t hash_mask_in_place  =
 141                             (address_word)hash_mask << hash_shift;
 142 #endif
 143 
 144   enum { locked_value             = 0,
 145          unlocked_value           = 1,
 146          monitor_value            = 2,


 348 
 349   // Prototype mark for initialization
 350   static markOop prototype() {
 351     return markOop( no_hash_in_place | no_lock_in_place );
 352   }
 353 
 354   // Helper function for restoration of unmarked mark oops during GC
 355   static inline markOop prototype_for_object(oop obj);
 356 
 357   // Debugging
 358   void print_on(outputStream* st) const;
 359 
 360   // Prepare address of oop for placement into mark
 361   inline static markOop encode_pointer_as_mark(void* p) { return markOop(p)->set_marked(); }
 362 
 363   // Recover address of oop from encoded form used in mark
 364   inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return clear_lock_bits(); }
 365 
 366   // see the definition in markOop.cpp for the gory details
 367   bool should_not_be_cached() const;
 368 
 369   // These markOops indicate cms free chunk blocks and not objects.
 370   // In 64 bit, the markOop is set to distinguish them from oops.
 371   // 0x1 is free chunk and 0x3 is can't coalesce, no other bits should be
 372   // set other than unlocked.
 373   // These are defined in 32 bit mode for vmStructs.
 374   const static uintptr_t cms_free_chunk_pattern  = 0x1;
 375   const static uintptr_t cms_no_coalesce_pattern = 0x3;
 376 
 377   // Constants for the size field.
 378   enum { size_shift                = cms_shift + cms_bits,
 379          size_bits                 = 35    // need for compressed oops 32G
 380        };
 381   // These values are too big for Win64
 382   const static uintptr_t size_mask = LP64_ONLY(right_n_bits(size_bits))
 383                                      NOT_LP64(0);
 384   const static uintptr_t size_mask_in_place =
 385                                      (address_word)size_mask << size_shift;
 386 
 387 #ifdef _LP64
 388   static markOop cms_free_prototype() {
 389     return markOop(((intptr_t)prototype() & ~cms_mask_in_place) |
 390                    ((cms_free_chunk_pattern & cms_mask) << cms_shift));
 391   }
 392   markOop set_cms_no_coalesce() {
 393     return markOop(((intptr_t)value() & ~cms_mask_in_place) |
 394                    ((cms_no_coalesce_pattern & cms_mask) << cms_shift));
 395   }
 396   uintptr_t cms_encoding() const {
 397     return mask_bits(value() >> cms_shift, cms_mask);
 398   }
 399   bool is_cms_free_chunk() const {
 400     return is_neutral() && 
 401            (cms_encoding() & cms_free_chunk_pattern) == cms_free_chunk_pattern;
 402   }
 403   bool is_cms_no_coalesce() const {
 404     return is_neutral() && (cms_encoding() == cms_no_coalesce_pattern);
 405   }
 406 
 407   size_t get_size() const       { return (size_t)(value() >> size_shift); }
 408   static markOop set_size_and_free(size_t size) {
 409     assert((size & ~size_mask) == 0, "shouldn't overflow size field");
 410     return markOop(((intptr_t)cms_free_prototype() & ~size_mask_in_place) |
 411                    (((intptr_t)size & size_mask) << size_shift));
 412   }
 413 #endif // _LP64
 414 };
src/share/vm/oops/markOop.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File