summaryrefslogtreecommitdiff
path: root/runtime/openjdkjvmti
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2017-04-13 01:32:51 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2017-04-13 01:32:52 +0000
commit687fb792b2a819bb43d45eb720ed68a077ed1beb (patch)
treeca2a6bb4b229c363a3eb1f19e4365f1b3193ff7f /runtime/openjdkjvmti
parentdbe35eddc4324468e08afc0829787f02ee736cea (diff)
parentbb766464bced8ca7db9cdaf635ae04759151a088 (diff)
Merge changes I49c02b92,I898e5cff
* changes: Ensure one can call DisposeEnvironment during event callbacks. run-tests with jvmti-stress configuration
Diffstat (limited to 'runtime/openjdkjvmti')
-rw-r--r--runtime/openjdkjvmti/events-inl.h10
-rw-r--r--runtime/openjdkjvmti/events.cc12
-rw-r--r--runtime/openjdkjvmti/events.h2
3 files changed, 21 insertions, 3 deletions
diff --git a/runtime/openjdkjvmti/events-inl.h b/runtime/openjdkjvmti/events-inl.h
index 1ddbb869f9..233b45cda8 100644
--- a/runtime/openjdkjvmti/events-inl.h
+++ b/runtime/openjdkjvmti/events-inl.h
@@ -131,6 +131,9 @@ inline void EventHandler::DispatchClassFileLoadHookEvent(art::Thread* thread,
unsigned char* current_class_data = const_cast<unsigned char*>(class_data);
ArtJvmTiEnv* last_env = nullptr;
for (ArtJvmTiEnv* env : envs) {
+ if (env == nullptr) {
+ continue;
+ }
if (ShouldDispatch<kEvent>(env, thread)) {
jint new_len = 0;
unsigned char* new_data = nullptr;
@@ -171,7 +174,9 @@ inline void EventHandler::DispatchClassFileLoadHookEvent(art::Thread* thread,
template <ArtJvmtiEvent kEvent, typename ...Args>
inline void EventHandler::DispatchEvent(art::Thread* thread, Args... args) const {
for (ArtJvmTiEnv* env : envs) {
- DispatchEvent<kEvent, Args...>(env, thread, args...);
+ if (env != nullptr) {
+ DispatchEvent<kEvent, Args...>(env, thread, args...);
+ }
}
}
@@ -253,6 +258,9 @@ inline bool EventHandler::ShouldDispatch(ArtJvmTiEnv* env,
inline void EventHandler::RecalculateGlobalEventMask(ArtJvmtiEvent event) {
bool union_value = false;
for (const ArtJvmTiEnv* stored_env : envs) {
+ if (stored_env == nullptr) {
+ continue;
+ }
union_value |= stored_env->event_masks.global_event_mask.Test(event);
union_value |= stored_env->event_masks.unioned_thread_event_mask.Test(event);
if (union_value) {
diff --git a/runtime/openjdkjvmti/events.cc b/runtime/openjdkjvmti/events.cc
index 34492a91fd..521494a856 100644
--- a/runtime/openjdkjvmti/events.cc
+++ b/runtime/openjdkjvmti/events.cc
@@ -141,13 +141,21 @@ void EventMasks::HandleChangedCapabilities(const jvmtiCapabilities& caps, bool c
}
void EventHandler::RegisterArtJvmTiEnv(ArtJvmTiEnv* env) {
- envs.push_back(env);
+ // Since we never shrink this array we might as well try to fill gaps.
+ auto it = std::find(envs.begin(), envs.end(), nullptr);
+ if (it != envs.end()) {
+ *it = env;
+ } else {
+ envs.push_back(env);
+ }
}
void EventHandler::RemoveArtJvmTiEnv(ArtJvmTiEnv* env) {
+ // 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);
if (it != envs.end()) {
- envs.erase(it);
+ *it = nullptr;
for (size_t i = static_cast<size_t>(ArtJvmtiEvent::kMinEventTypeVal);
i <= static_cast<size_t>(ArtJvmtiEvent::kMaxEventTypeVal);
++i) {
diff --git a/runtime/openjdkjvmti/events.h b/runtime/openjdkjvmti/events.h
index ae8bf0f803..b9e3cf0b09 100644
--- a/runtime/openjdkjvmti/events.h
+++ b/runtime/openjdkjvmti/events.h
@@ -202,6 +202,8 @@ class EventHandler {
void HandleEventType(ArtJvmtiEvent event, bool enable);
// List of all JvmTiEnv objects that have been created, in their creation order.
+ // NB Some elements might be null representing envs that have been deleted. They should be skipped
+ // anytime this list is used.
std::vector<ArtJvmTiEnv*> envs;
// A union of all enabled events, anywhere.