Fail threads attaching during runtime shutdown.

Introduce counters to indicate that threads are being born. Don't allow
thread birth to occur during runtime shutdown.

Bug: 7000936

Change-Id: Ib0d78f78c0ff126a4b5d3b5a6f1a2ff8f5061ae9
diff --git a/src/locks.h b/src/locks.h
index c5821d8..cd2f8b7 100644
--- a/src/locks.h
+++ b/src/locks.h
@@ -42,10 +42,11 @@
   kLoadLibraryLock = 7,
   kClassLinkerClassesLock = 8,
   kThreadListLock = 9,
-  kHeapBitmapLock = 10,
-  kMonitorLock = 11,
-  kMutatorLock = 12,
-  kZygoteCreationLock = 13,
+  kRuntimeShutdownLock = 10,
+  kHeapBitmapLock = 11,
+  kMonitorLock = 12,
+  kMutatorLock = 13,
+  kZygoteCreationLock = 14,
   kMaxMutexLevel = kMutatorLock,
 };
 std::ostream& operator<<(std::ostream& os, const LockLevel& rhs);
@@ -118,9 +119,12 @@
   // Allow reader-writer mutual exclusion on the mark and live bitmaps of the heap.
   static ReaderWriterMutex* heap_bitmap_lock_ ACQUIRED_AFTER(mutator_lock_);
 
+  // Guards shutdown of the runtime.
+  static Mutex* runtime_shutdown_lock_ ACQUIRED_AFTER(heap_bitmap_lock_);
+
   // The thread_list_lock_ guards ThreadList::list_. It is also commonly held to stop threads
   // attaching and detaching.
-  static Mutex* thread_list_lock_ ACQUIRED_AFTER(heap_bitmap_lock_);
+  static Mutex* thread_list_lock_ ACQUIRED_AFTER(runtime_shutdown_lock_);
 
   // Guards lists of classes within the class linker.
   static Mutex* classlinker_classes_lock_ ACQUIRED_AFTER(thread_list_lock_);