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.h b/openjdkjvmti/events.h
index 81edb93..8141eff 100644
--- a/openjdkjvmti/events.h
+++ b/openjdkjvmti/events.h
@@ -283,7 +283,7 @@
   ALWAYS_INLINE
   inline void RecalculateGlobalEventMask(ArtJvmtiEvent event) REQUIRES(!envs_lock_);
   ALWAYS_INLINE
-  inline void RecalculateGlobalEventMaskLocked(ArtJvmtiEvent event) REQUIRES(envs_lock_);
+  inline void RecalculateGlobalEventMaskLocked(ArtJvmtiEvent event) REQUIRES_SHARED(envs_lock_);
 
   template <ArtJvmtiEvent kEvent>
   ALWAYS_INLINE inline void DispatchClassFileLoadHookEvent(art::Thread* thread,
@@ -310,7 +310,8 @@
   std::list<ArtJvmTiEnv*> envs GUARDED_BY(envs_lock_);
 
   // Top level lock. Nothing at all should be held when we lock this.
-  mutable art::Mutex envs_lock_ ACQUIRED_BEFORE(art::Locks::instrument_entrypoints_lock_);
+  mutable art::ReaderWriterMutex envs_lock_
+      ACQUIRED_BEFORE(art::Locks::instrument_entrypoints_lock_);
 
   // A union of all enabled events, anywhere.
   EventMask global_mask;