Re-enable concurrent system weak sweeping.

Enabled by disallowing new system weaks during the pause and
re-allowing it after the system weaks have been swept. Reduces
GC pause by ~1ms.

Fixes pause regression caused by fix for
Bug: 10626133

Change-Id: If49d33e7ef19cb728ed3cef5187acfa53b9b05d8
diff --git a/runtime/monitor.cc b/runtime/monitor.cc
index 66c51e6..088d1f7 100644
--- a/runtime/monitor.cc
+++ b/runtime/monitor.cc
@@ -989,7 +989,9 @@
   line_number = mh.GetLineNumFromDexPC(dex_pc);
 }
 
-MonitorList::MonitorList() : monitor_list_lock_("MonitorList lock") {
+MonitorList::MonitorList()
+    : allow_new_monitors_(true), monitor_list_lock_("MonitorList lock"),
+      monitor_add_condition_("MonitorList disallow condition", monitor_list_lock_) {
 }
 
 MonitorList::~MonitorList() {
@@ -997,8 +999,24 @@
   STLDeleteElements(&list_);
 }
 
-void MonitorList::Add(Monitor* m) {
+void MonitorList::DisallowNewMonitors() {
   MutexLock mu(Thread::Current(), monitor_list_lock_);
+  allow_new_monitors_ = false;
+}
+
+void MonitorList::AllowNewMonitors() {
+  Thread* self = Thread::Current();
+  MutexLock mu(self, monitor_list_lock_);
+  allow_new_monitors_ = true;
+  monitor_add_condition_.Broadcast(self);
+}
+
+void MonitorList::Add(Monitor* m) {
+  Thread* self = Thread::Current();
+  MutexLock mu(self, monitor_list_lock_);
+  while (UNLIKELY(!allow_new_monitors_)) {
+    monitor_add_condition_.WaitHoldingLocks(self);
+  }
   list_.push_front(m);
 }