Use SuspendAllInternal for FlipThreadRoots

Fix FlipThreadRoots to wait until all the threads are suspended by
using SuspendAllInternal. Since running threads no longer hold the
mutator lock as shared held, doing an exclusive lock will not block
if the threads are not suspended. Also implemented MarkHeapReference
which is used to preserve soft references.

Fixes CC tests.

Change-Id: I4b059238f4249cf297e21ae918becd029fe26527
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index b5d5c34..93156ac 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -73,10 +73,11 @@
   }
 }
 
-void ConcurrentCopying::MarkHeapReference(
-    mirror::HeapReference<mirror::Object>* from_ref ATTRIBUTE_UNUSED) {
-  // Unused, usually called from mod union tables.
-  UNIMPLEMENTED(FATAL);
+void ConcurrentCopying::MarkHeapReference(mirror::HeapReference<mirror::Object>* from_ref) {
+  // Used for preserving soft references, should be OK to not have a CAS here since there should be
+  // no other threads which can trigger read barriers on the same referent during reference
+  // processing.
+  from_ref->Assign(Mark(from_ref->AsMirrorPtr()));
 }
 
 ConcurrentCopying::~ConcurrentCopying() {
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 7c40eb7..60c9b5e 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -381,23 +381,7 @@
   Locks::thread_suspend_count_lock_->AssertNotHeld(self);
   CHECK_NE(self->GetState(), kRunnable);
 
-  std::vector<Thread*> runnable_threads;
-  std::vector<Thread*> other_threads;
-
-  // Suspend all threads once.
-  {
-    MutexLock mu(self, *Locks::thread_list_lock_);
-    MutexLock mu2(self, *Locks::thread_suspend_count_lock_);
-    // Update global suspend all state for attaching threads.
-    ++suspend_all_count_;
-    // Increment everybody's suspend count (except our own).
-    for (const auto& thread : list_) {
-      if (thread == self) {
-        continue;
-      }
-      thread->ModifySuspendCount(self, +1, nullptr, false);
-    }
-  }
+  SuspendAllInternal(self, self, nullptr);
 
   // Run the flip callback for the collector.
   Locks::mutator_lock_->ExclusiveLock(self);
@@ -406,6 +390,8 @@
   collector->RegisterPause(NanoTime() - start_time);
 
   // Resume runnable threads.
+  std::vector<Thread*> runnable_threads;
+  std::vector<Thread*> other_threads;
   {
     MutexLock mu(self, *Locks::thread_list_lock_);
     MutexLock mu2(self, *Locks::thread_suspend_count_lock_);