Fix object identity hash.
The object identity hash is now stored in the monitor word after
being computed. Hashes are computed by a pseudo random number
generator.
When we write the image, we eagerly compute object hashes to
prevent pages getting dirtied.
Bug: 8981901
Change-Id: Ic8edacbacb0afc7055fd740a52444929f88ed564
diff --git a/runtime/lock_word-inl.h b/runtime/lock_word-inl.h
index 30bf9bb..59947f5 100644
--- a/runtime/lock_word-inl.h
+++ b/runtime/lock_word-inl.h
@@ -33,7 +33,7 @@
inline Monitor* LockWord::FatLockMonitor() const {
DCHECK_EQ(GetState(), kFatLocked);
- return reinterpret_cast<Monitor*>(value_ << 1);
+ return reinterpret_cast<Monitor*>(value_ << kStateSize);
}
inline LockWord::LockWord() : value_(0) {
@@ -41,10 +41,15 @@
}
inline LockWord::LockWord(Monitor* mon)
- : value_((reinterpret_cast<uint32_t>(mon) >> 1) | (kStateFat << kStateShift)) {
+ : value_((reinterpret_cast<uint32_t>(mon) >> kStateSize) | (kStateFat << kStateShift)) {
DCHECK_EQ(FatLockMonitor(), mon);
}
+inline uint32_t LockWord::GetHashCode() const {
+ DCHECK_EQ(GetState(), kHashCode);
+ return (value_ >> kHashShift) & kHashMask;
+}
+
} // namespace art
#endif // ART_RUNTIME_LOCK_WORD_INL_H_