diff options
author | 2018-01-22 17:45:02 -0800 | |
---|---|---|
committer | 2018-01-22 17:45:02 -0800 | |
commit | 2a96fe8541b7179e923b6edd27dfe1b8ceb6988e (patch) | |
tree | 30ebaef5f4540ca7d1b21382b87c7bf9b358cbdb | |
parent | d78ca5213b780ca3165acb68e44f88f639e8ca45 (diff) |
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
-rw-r--r-- | openjdkjvmti/events-inl.h | 4 | ||||
-rw-r--r-- | openjdkjvmti/events.cc | 6 | ||||
-rw-r--r-- | openjdkjvmti/events.h | 5 |
3 files changed, 8 insertions, 7 deletions
diff --git a/openjdkjvmti/events-inl.h b/openjdkjvmti/events-inl.h index 007669b50f..74ffb84579 100644 --- a/openjdkjvmti/events-inl.h +++ b/openjdkjvmti/events-inl.h @@ -187,7 +187,7 @@ FORALL_EVENT_TYPES(MAKE_EVENT_HANDLER_FUNC) template <ArtJvmtiEvent kEvent, typename ...Args> inline std::vector<impl::EventHandlerFunc<kEvent>> EventHandler::CollectEvents(art::Thread* thread, Args... args) const { - art::MutexLock mu(thread, envs_lock_); + art::ReaderMutexLock mu(thread, envs_lock_); std::vector<impl::EventHandlerFunc<kEvent>> handlers; for (ArtJvmTiEnv* env : envs) { if (ShouldDispatch<kEvent>(env, thread, args...)) { @@ -527,7 +527,7 @@ inline bool EventHandler::ShouldDispatch(ArtJvmTiEnv* env, } inline void EventHandler::RecalculateGlobalEventMask(ArtJvmtiEvent event) { - art::MutexLock mu(art::Thread::Current(), envs_lock_); + art::WriterMutexLock mu(art::Thread::Current(), envs_lock_); RecalculateGlobalEventMaskLocked(event); } diff --git a/openjdkjvmti/events.cc b/openjdkjvmti/events.cc index d98fda5f9c..62b73c08c0 100644 --- a/openjdkjvmti/events.cc +++ b/openjdkjvmti/events.cc @@ -196,12 +196,12 @@ void EventMasks::HandleChangedCapabilities(const jvmtiCapabilities& caps, bool c } 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 @@ jvmtiError EventHandler::SetEvent(ArtJvmTiEnv* env, { // 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) { diff --git a/openjdkjvmti/events.h b/openjdkjvmti/events.h index 81edb931cd..8141eff88c 100644 --- a/openjdkjvmti/events.h +++ b/openjdkjvmti/events.h @@ -283,7 +283,7 @@ class EventHandler { 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 @@ class EventHandler { 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; |