Fix infinite loop in GenerateIdentityHashCode
Root Cause:
If no one changes the seed, it will become infinite loop due to below condition
(expected_value & LockWord::kHashMask) == 0
Solution:
Changes the seed before entering the next loop
Added test.
Bug: 19046417
Change-Id: I7d1c377dd1bda780681514b24d61ebc776bc80ab
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h
index 221feca..07d15b5 100644
--- a/runtime/mirror/object.h
+++ b/runtime/mirror/object.h
@@ -419,6 +419,11 @@
void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
NO_THREAD_SAFETY_ANALYSIS;
+ // Used by object_test.
+ static void SetHashCodeSeed(uint32_t new_seed);
+ // Generate an identity hash code. Public for object test.
+ static uint32_t GenerateIdentityHashCode();
+
protected:
// Accessors for non-Java type fields
template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
@@ -471,9 +476,6 @@
}
}
- // Generate an identity hash code.
- static uint32_t GenerateIdentityHashCode();
-
// A utility function that copies an object in a read barrier and
// write barrier-aware way. This is internally used by Clone() and
// Class::CopyOf().
@@ -481,6 +483,8 @@
size_t num_bytes)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ static Atomic<uint32_t> hash_code_seed;
+
// The Class representing the type of the object.
HeapReference<Class> klass_;
// Monitor and hash code information.