Revert "Revert^2 "Revoke CC's thread-local mark stack in ~Thread""

This reverts commit add69acb7db965bd8d817a185e962e5474f690d1.

Bug: 140119552
Reason for revert: Causes b/144408451

Change-Id: Ifaa78a3a13cbcc0524fa0fb8e25d377b6fd6ed2b
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 274f3ae..afae3ef 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -2049,12 +2049,12 @@
 }
 
 void ConcurrentCopying::RevokeThreadLocalMarkStack(Thread* thread) {
+  Thread* self = Thread::Current();
+  CHECK_EQ(self, thread);
   accounting::AtomicStack<mirror::Object>* tl_mark_stack = thread->GetThreadLocalMarkStack();
   if (tl_mark_stack != nullptr) {
-    // With 2-phase CC change, we cannot assert that is_marking_ will always be true
-    // as we perform thread stack scan even before enabling the read-barrier.
-    CHECK(is_marking_ || (use_generational_cc_ && !young_gen_));
-    MutexLock mu(Thread::Current(), mark_stack_lock_);
+    CHECK(is_marking_);
+    MutexLock mu(self, mark_stack_lock_);
     revoked_mark_stacks_.push_back(tl_mark_stack);
     RemoveThreadMarkStackMapping(thread, tl_mark_stack);
     thread->SetThreadLocalMarkStack(nullptr);
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 36c35f8..59a38e1 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2439,19 +2439,13 @@
   {
     ScopedObjectAccess soa(self);
     Runtime::Current()->GetHeap()->RevokeThreadLocalBuffers(this);
+    if (kUseReadBarrier) {
+      Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->RevokeThreadLocalMarkStack(this);
+    }
   }
 }
 
 Thread::~Thread() {
-  if (kUseReadBarrier) {
-    // It's a cheap operation so can be done in the destructor (instead of
-    // Destroy()).
-    // Doing it without mutator_lock mutual exclusion is also necessary as there
-    // is a checkpoint in ConcurrentCopying which scans the threads' stacks,
-    // thereby assigning a thread-local mark-stack to self, breaking some
-    // assumptions about how the GC works (see b/140119552).
-    Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->RevokeThreadLocalMarkStack(this);
-  }
   CHECK(tlsPtr_.class_loader_override == nullptr);
   CHECK(tlsPtr_.jpeer == nullptr);
   CHECK(tlsPtr_.opeer == nullptr);