diff options
| author | 2018-06-19 01:09:01 +0000 | |
|---|---|---|
| committer | 2018-06-19 01:09:01 +0000 | |
| commit | 2c12bb624e91d8f1282d868fd2f2e33ba3746d6c (patch) | |
| tree | b378c9a7051ce84c3c22847be179845a04d76376 /runtime/monitor.cc | |
| parent | e3435cb810a5c48626a1564dbed0ae4dda89d57b (diff) | |
| parent | 8bb3c68422ce06f444d7c4e49c7af7b1c5cbeb7c (diff) | |
Merge "Use strong CAS for identity hash code"
Diffstat (limited to 'runtime/monitor.cc')
| -rw-r--r-- | runtime/monitor.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/runtime/monitor.cc b/runtime/monitor.cc index 2c38de5dae..e723169ac2 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -134,13 +134,15 @@ Monitor::Monitor(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_ } int32_t Monitor::GetHashCode() { - while (!HasHashCode()) { - if (hash_code_.CompareAndSetWeakRelaxed(0, mirror::Object::GenerateIdentityHashCode())) { - break; - } + int32_t hc = hash_code_.load(std::memory_order_relaxed); + if (!HasHashCode()) { + // Use a strong CAS to prevent spurious failures since these can make the boot image + // non-deterministic. + hash_code_.CompareAndSetStrongRelaxed(0, mirror::Object::GenerateIdentityHashCode()); + hc = hash_code_.load(std::memory_order_relaxed); } DCHECK(HasHashCode()); - return hash_code_.load(std::memory_order_relaxed); + return hc; } bool Monitor::Install(Thread* self) { |