diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2015-04-23 16:12:40 -0700 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2015-04-23 21:11:40 -0700 |
commit | 60f63f53c01cb38ca18a815603282e802a6cf918 (patch) | |
tree | 4f18427401ead0c790e926672957189a0c0a39eb /runtime/lock_word.h | |
parent | 633a37ece49c5afcf3fa9a89692f07d19c56229b (diff) | |
download | art-60f63f53c01cb38ca18a815603282e802a6cf918.zip art-60f63f53c01cb38ca18a815603282e802a6cf918.tar.gz art-60f63f53c01cb38ca18a815603282e802a6cf918.tar.bz2 |
Use the lock word bits for Baker-style read barrier.
This enables the standard object header to be used with the
Baker-style read barrier.
Bug: 19355854
Bug: 12687968
Change-Id: Ie552b6e1dfe30e96cb1d0895bd0dff25f9d7d015
Diffstat (limited to 'runtime/lock_word.h')
-rw-r--r-- | runtime/lock_word.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/runtime/lock_word.h b/runtime/lock_word.h index 46c3bd4..655aa3a 100644 --- a/runtime/lock_word.h +++ b/runtime/lock_word.h @@ -94,6 +94,7 @@ class LockWord { kReadBarrierStateMaskShiftedToggled = ~kReadBarrierStateMaskShifted, // When the state is kHashCode, the non-state bits hold the hashcode. + // Note Object.hashCode() has the hash code layout hardcoded. kHashShift = 0, kHashSize = 32 - kStateSize - kReadBarrierStateSize, kHashMask = (1 << kHashSize) - 1, @@ -110,6 +111,7 @@ class LockWord { static LockWord FromThinLockId(uint32_t thread_id, uint32_t count, uint32_t rb_state) { CHECK_LE(thread_id, static_cast<uint32_t>(kThinLockMaxOwner)); CHECK_LE(count, static_cast<uint32_t>(kThinLockMaxCount)); + DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U); return LockWord((thread_id << kThinLockOwnerShift) | (count << kThinLockCountShift) | (rb_state << kReadBarrierStateShift) | (kStateThinOrUnlocked << kStateShift)); @@ -122,12 +124,14 @@ class LockWord { static LockWord FromHashCode(uint32_t hash_code, uint32_t rb_state) { CHECK_LE(hash_code, static_cast<uint32_t>(kMaxHash)); + DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U); return LockWord((hash_code << kHashShift) | (rb_state << kReadBarrierStateShift) | (kStateHash << kStateShift)); } static LockWord FromDefault(uint32_t rb_state) { + DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U); return LockWord(rb_state << kReadBarrierStateShift); } @@ -149,7 +153,8 @@ class LockWord { LockState GetState() const { CheckReadBarrierState(); - if (UNLIKELY(value_ == 0)) { + if ((!kUseReadBarrier && UNLIKELY(value_ == 0)) || + (kUseReadBarrier && UNLIKELY((value_ & kReadBarrierStateMaskShiftedToggled) == 0))) { return kUnlocked; } else { uint32_t internal_state = (value_ >> kStateShift) & kStateMask; @@ -171,6 +176,14 @@ class LockWord { return (value_ >> kReadBarrierStateShift) & kReadBarrierStateMask; } + void SetReadBarrierState(uint32_t rb_state) { + DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U); + DCHECK_NE(static_cast<uint32_t>(GetState()), static_cast<uint32_t>(kForwardingAddress)); + // Clear and or the bits. + value_ &= ~(kReadBarrierStateMask << kReadBarrierStateShift); + value_ |= (rb_state & kReadBarrierStateMask) << kReadBarrierStateShift; + } + // Return the owner thin lock thread id. uint32_t ThinLockOwner() const; |