Thread-local mark stacks for the CC collector.

Thread-local mark stacks are assigned to mutators where they push
references in read barriers to reduce the (CAS) synchronization cost
in a global mark stack/queue.

We step through three mark stack modes (thread-local, shared,
GC-exclusive) and use per-thread flags to disable/enable system weak
accesses (only for the CC collector) instead of the existing global
one to safely perform the marking phase. The reasons are 1)
thread-local mark stacks for mutators need to be revoked using a
checkpoint to avoid races (incorrectly leaving a reference on mark
stacks) when terminating marking, and 2) we can’t use a checkpoint
while system weak accesses are disabled (or a deadlock would
happen). More details are described in the code comments.

Performance improvements in Ritzperf EAAC: a ~2.8% improvement
(13290->12918) in run time and a ~23% improvement (51.6s->39.8s) in
the total GC time on N5.

Bug: 12687968
Change-Id: I5d234d7e48bf115cd773d38bdb62ad24ce9116c7
diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc
index 2a96278..2a06ab3 100644
--- a/runtime/intern_table.cc
+++ b/runtime/intern_table.cc
@@ -231,13 +231,21 @@
   CHECK(!allow_new_interns_);
 }
 
+void InternTable::BroadcastForNewInterns() {
+  CHECK(kUseReadBarrier);
+  Thread* self = Thread::Current();
+  MutexLock mu(self, *Locks::intern_table_lock_);
+  new_intern_condition_.Broadcast(self);
+}
+
 mirror::String* InternTable::Insert(mirror::String* s, bool is_strong) {
   if (s == nullptr) {
     return nullptr;
   }
   Thread* self = Thread::Current();
   MutexLock mu(self, *Locks::intern_table_lock_);
-  while (UNLIKELY(!allow_new_interns_)) {
+  while (UNLIKELY((!kUseReadBarrier && !allow_new_interns_) ||
+                  (kUseReadBarrier && !self->GetWeakRefAccessEnabled()))) {
     new_intern_condition_.WaitHoldingLocks(self);
   }
   // Check the strong table for a match.