Change envs_lock_ to a ReaderWriterMutex

We were getting a lot of contention on this mutex because it needs to
be held to run through the list of all active environments. Since this
list is only rarely modified we change the lock to a ReaderWriterMutex
and only lock it exclusive when we need to modify it.

Test: Examine systrace of startup with DDMS monitor running.
Bug: 72336488
Change-Id: Ie161b0f9c624384fcf36272c6edb78c4a7164149
diff --git a/openjdkjvmti/events.cc b/openjdkjvmti/events.cc
index d98fda5..62b73c0 100644
--- a/openjdkjvmti/events.cc
+++ b/openjdkjvmti/events.cc
@@ -196,12 +196,12 @@
 }
 
 void EventHandler::RegisterArtJvmTiEnv(ArtJvmTiEnv* env) {
-  art::MutexLock mu(art::Thread::Current(), envs_lock_);
+  art::WriterMutexLock mu(art::Thread::Current(), envs_lock_);
   envs.push_back(env);
 }
 
 void EventHandler::RemoveArtJvmTiEnv(ArtJvmTiEnv* env) {
-  art::MutexLock mu(art::Thread::Current(), envs_lock_);
+  art::WriterMutexLock mu(art::Thread::Current(), envs_lock_);
   // Since we might be currently iterating over the envs list we cannot actually erase elements.
   // Instead we will simply replace them with 'nullptr' and skip them manually.
   auto it = std::find(envs.begin(), envs.end(), env);
@@ -1143,7 +1143,7 @@
   {
     // Change the event masks atomically.
     art::Thread* self = art::Thread::Current();
-    art::MutexLock mu(self, envs_lock_);
+    art::WriterMutexLock mu(self, envs_lock_);
     art::WriterMutexLock mu_env_info(self, env->event_info_mutex_);
     old_state = global_mask.Test(event);
     if (mode == JVMTI_ENABLE) {