OSDN Git Service

Add release fence after copying object
authorMathieu Chartier <mathieuc@google.com>
Wed, 30 Nov 2016 01:55:19 +0000 (17:55 -0800)
committerMathieu Chartier <mathieuc@google.com>
Wed, 30 Nov 2016 17:57:13 +0000 (09:57 -0800)
Try to ensure that the field CAS in ConcurrentCopying::Process will
never reorder before the object copy.

May fix a bug where null classes are seen.

Test: test-art-host CC

Bug: 33210571
Change-Id: I71ab937b7ca60c88c5f69698731edac6a8f2e91a

runtime/gc/collector/concurrent_copying.cc

index 8353b26..19ee0fb 100644 (file)
@@ -2145,14 +2145,18 @@ mirror::Object* ConcurrentCopying::Copy(mirror::Object* from_ref) {
       to_ref->SetReadBarrierState(ReadBarrier::GrayState());
     }
 
+    // Do a fence to prevent the field CAS in ConcurrentCopying::Process from possibly reordering
+    // before the object copy.
+    QuasiAtomic::ThreadFenceRelease();
+
     LockWord new_lock_word = LockWord::FromForwardingAddress(reinterpret_cast<size_t>(to_ref));
 
     // Try to atomically write the fwd ptr.
-    bool success = from_ref->CasLockWordWeakSequentiallyConsistent(old_lock_word, new_lock_word);
+    bool success = from_ref->CasLockWordWeakRelaxed(old_lock_word, new_lock_word);
     if (LIKELY(success)) {
       // The CAS succeeded.
-      objects_moved_.FetchAndAddSequentiallyConsistent(1);
-      bytes_moved_.FetchAndAddSequentiallyConsistent(region_space_alloc_size);
+      objects_moved_.FetchAndAddRelaxed(1);
+      bytes_moved_.FetchAndAddRelaxed(region_space_alloc_size);
       if (LIKELY(!fall_back_to_non_moving)) {
         DCHECK(region_space_->IsInToSpace(to_ref));
       } else {