Use r/w Mutex to control access to jvmtiEnv event information.

We were previously relying on the mutator_lock_ to provide
synchronization when accessing control information for some jvmti
events. This was not fully thread safe. To fix this problem we
instead use a ReaderWriterMutex to control access to this data.

Refactorings to allow all methods to have appropriate lock annotations
will follow in later CL (see bug).

Performance Impact:
    Tested performance by running main piece of test 993 10 times.
    Printing redirected to /dev/null.
    Total of ~270 breakpoints are executed.

    Before: 2.62 seconds / run
    After:  2.72 seconds / run

Test: ./test.py --host -j50
Test: ./art/tools/run-prebuilt-libjdwp-tests.sh --debug

Bug: 62821960
Bug: 67958496
Bug: 67962439

Change-Id: Ib2935c2e10bc2113e8430b49a9a7b76144e4235e
diff --git a/openjdkjvmti/ti_breakpoint.cc b/openjdkjvmti/ti_breakpoint.cc
index f5116a8..75c8027 100644
--- a/openjdkjvmti/ti_breakpoint.cc
+++ b/openjdkjvmti/ti_breakpoint.cc
@@ -36,6 +36,7 @@
 #include "art_jvmti.h"
 #include "art_method-inl.h"
 #include "base/enums.h"
+#include "base/mutex-inl.h"
 #include "dex_file_annotations.h"
 #include "events-inl.h"
 #include "jni_internal.h"
@@ -62,6 +63,7 @@
 }
 
 void BreakpointUtil::RemoveBreakpointsInClass(ArtJvmTiEnv* env, art::mirror::Class* klass) {
+  art::WriterMutexLock lk(art::Thread::Current(), env->event_info_mutex_);
   std::vector<Breakpoint> to_remove;
   for (const Breakpoint& b : env->breakpoints) {
     if (b.GetMethod()->GetDeclaringClass() == klass) {
@@ -83,6 +85,7 @@
   // Need to get mutator_lock_ so we can find the interface version of any default methods.
   art::ScopedObjectAccess soa(art::Thread::Current());
   art::ArtMethod* art_method = art::jni::DecodeArtMethod(method)->GetCanonicalMethod();
+  art::WriterMutexLock lk(art::Thread::Current(), env->event_info_mutex_);
   if (location < 0 || static_cast<uint32_t>(location) >=
       art_method->GetCodeItem()->insns_size_in_code_units_) {
     return ERR(INVALID_LOCATION);
@@ -102,8 +105,9 @@
   }
   // Need to get mutator_lock_ so we can find the interface version of any default methods.
   art::ScopedObjectAccess soa(art::Thread::Current());
-  auto pos = env->breakpoints.find(
-      /* Breakpoint */ {art::jni::DecodeArtMethod(method)->GetCanonicalMethod(), location});
+  art::ArtMethod* art_method = art::jni::DecodeArtMethod(method)->GetCanonicalMethod();
+  art::WriterMutexLock lk(art::Thread::Current(), env->event_info_mutex_);
+  auto pos = env->breakpoints.find(/* Breakpoint */ {art_method, location});
   if (pos == env->breakpoints.end()) {
     return ERR(NOT_FOUND);
   }