Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 17 | #ifndef ART_OPENJDKJVMTI_EVENTS_H_ |
| 18 | #define ART_OPENJDKJVMTI_EVENTS_H_ |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 19 | |
| 20 | #include <bitset> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "base/logging.h" |
| 24 | #include "jvmti.h" |
| 25 | #include "thread.h" |
| 26 | |
| 27 | namespace openjdkjvmti { |
| 28 | |
| 29 | struct ArtJvmTiEnv; |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 30 | class JvmtiAllocationListener; |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 31 | class JvmtiDdmChunkListener; |
Andreas Gampe | 9b8c588 | 2016-10-21 15:27:46 -0700 | [diff] [blame] | 32 | class JvmtiGcPauseListener; |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 33 | class JvmtiMethodTraceListener; |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 34 | class JvmtiMonitorListener; |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 35 | |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 36 | // an enum for ArtEvents. This differs from the JVMTI events only in that we distinguish between |
| 37 | // retransformation capable and incapable loading |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 38 | enum class ArtJvmtiEvent : jint { |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 39 | kMinEventTypeVal = JVMTI_MIN_EVENT_TYPE_VAL, |
| 40 | kVmInit = JVMTI_EVENT_VM_INIT, |
| 41 | kVmDeath = JVMTI_EVENT_VM_DEATH, |
| 42 | kThreadStart = JVMTI_EVENT_THREAD_START, |
| 43 | kThreadEnd = JVMTI_EVENT_THREAD_END, |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 44 | kClassFileLoadHookNonRetransformable = JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 45 | kClassLoad = JVMTI_EVENT_CLASS_LOAD, |
| 46 | kClassPrepare = JVMTI_EVENT_CLASS_PREPARE, |
| 47 | kVmStart = JVMTI_EVENT_VM_START, |
| 48 | kException = JVMTI_EVENT_EXCEPTION, |
| 49 | kExceptionCatch = JVMTI_EVENT_EXCEPTION_CATCH, |
| 50 | kSingleStep = JVMTI_EVENT_SINGLE_STEP, |
| 51 | kFramePop = JVMTI_EVENT_FRAME_POP, |
| 52 | kBreakpoint = JVMTI_EVENT_BREAKPOINT, |
| 53 | kFieldAccess = JVMTI_EVENT_FIELD_ACCESS, |
| 54 | kFieldModification = JVMTI_EVENT_FIELD_MODIFICATION, |
| 55 | kMethodEntry = JVMTI_EVENT_METHOD_ENTRY, |
| 56 | kMethodExit = JVMTI_EVENT_METHOD_EXIT, |
| 57 | kNativeMethodBind = JVMTI_EVENT_NATIVE_METHOD_BIND, |
| 58 | kCompiledMethodLoad = JVMTI_EVENT_COMPILED_METHOD_LOAD, |
| 59 | kCompiledMethodUnload = JVMTI_EVENT_COMPILED_METHOD_UNLOAD, |
| 60 | kDynamicCodeGenerated = JVMTI_EVENT_DYNAMIC_CODE_GENERATED, |
| 61 | kDataDumpRequest = JVMTI_EVENT_DATA_DUMP_REQUEST, |
| 62 | kMonitorWait = JVMTI_EVENT_MONITOR_WAIT, |
| 63 | kMonitorWaited = JVMTI_EVENT_MONITOR_WAITED, |
| 64 | kMonitorContendedEnter = JVMTI_EVENT_MONITOR_CONTENDED_ENTER, |
| 65 | kMonitorContendedEntered = JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, |
| 66 | kResourceExhausted = JVMTI_EVENT_RESOURCE_EXHAUSTED, |
| 67 | kGarbageCollectionStart = JVMTI_EVENT_GARBAGE_COLLECTION_START, |
| 68 | kGarbageCollectionFinish = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, |
| 69 | kObjectFree = JVMTI_EVENT_OBJECT_FREE, |
| 70 | kVmObjectAlloc = JVMTI_EVENT_VM_OBJECT_ALLOC, |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 71 | kClassFileLoadHookRetransformable = JVMTI_MAX_EVENT_TYPE_VAL + 1, |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 72 | kDdmPublishChunk = JVMTI_MAX_EVENT_TYPE_VAL + 2, |
| 73 | kMaxEventTypeVal = kDdmPublishChunk, |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 76 | using ArtJvmtiEventDdmPublishChunk = void (*)(jvmtiEnv *jvmti_env, |
| 77 | JNIEnv* jni_env, |
| 78 | jint data_type, |
| 79 | jint data_len, |
| 80 | const jbyte* data); |
| 81 | |
| 82 | struct ArtJvmtiEventCallbacks : jvmtiEventCallbacks { |
| 83 | ArtJvmtiEventCallbacks() : DdmPublishChunk(nullptr) { |
| 84 | memset(this, 0, sizeof(jvmtiEventCallbacks)); |
| 85 | } |
| 86 | |
| 87 | // Copies extension functions from other callback struct if it exists. There must not have been |
| 88 | // any modifications to this struct when it is called. |
| 89 | void CopyExtensionsFrom(const ArtJvmtiEventCallbacks* cb); |
| 90 | |
| 91 | jvmtiError Set(jint index, jvmtiExtensionEvent cb); |
| 92 | |
| 93 | ArtJvmtiEventDdmPublishChunk DdmPublishChunk; |
| 94 | }; |
| 95 | |
| 96 | bool IsExtensionEvent(jint e); |
| 97 | bool IsExtensionEvent(ArtJvmtiEvent e); |
| 98 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 99 | // Convert a jvmtiEvent into a ArtJvmtiEvent |
| 100 | ALWAYS_INLINE static inline ArtJvmtiEvent GetArtJvmtiEvent(ArtJvmTiEnv* env, jvmtiEvent e); |
| 101 | |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 102 | static inline jvmtiEvent GetJvmtiEvent(ArtJvmtiEvent e) { |
| 103 | if (UNLIKELY(e == ArtJvmtiEvent::kClassFileLoadHookRetransformable)) { |
| 104 | return JVMTI_EVENT_CLASS_FILE_LOAD_HOOK; |
| 105 | } else { |
| 106 | return static_cast<jvmtiEvent>(e); |
| 107 | } |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 110 | struct EventMask { |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 111 | static constexpr size_t kEventsSize = |
| 112 | static_cast<size_t>(ArtJvmtiEvent::kMaxEventTypeVal) - |
| 113 | static_cast<size_t>(ArtJvmtiEvent::kMinEventTypeVal) + 1; |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 114 | std::bitset<kEventsSize> bit_set; |
| 115 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 116 | static bool EventIsInRange(ArtJvmtiEvent event) { |
| 117 | return event >= ArtJvmtiEvent::kMinEventTypeVal && event <= ArtJvmtiEvent::kMaxEventTypeVal; |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 120 | void Set(ArtJvmtiEvent event, bool value = true) { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 121 | DCHECK(EventIsInRange(event)); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 122 | bit_set.set(static_cast<size_t>(event) - static_cast<size_t>(ArtJvmtiEvent::kMinEventTypeVal), |
| 123 | value); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 126 | bool Test(ArtJvmtiEvent event) const { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 127 | DCHECK(EventIsInRange(event)); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 128 | return bit_set.test( |
| 129 | static_cast<size_t>(event) - static_cast<size_t>(ArtJvmtiEvent::kMinEventTypeVal)); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 130 | } |
| 131 | }; |
| 132 | |
| 133 | struct EventMasks { |
| 134 | // The globally enabled events. |
| 135 | EventMask global_event_mask; |
| 136 | |
| 137 | // The per-thread enabled events. |
| 138 | |
| 139 | // It is not enough to store a Thread pointer, as these may be reused. Use the pointer and the |
| 140 | // thread id. |
| 141 | // Note: We could just use the tid like tracing does. |
| 142 | using UniqueThread = std::pair<art::Thread*, uint32_t>; |
| 143 | // TODO: Native thread objects are immovable, so we can use them as keys in an (unordered) map, |
| 144 | // if necessary. |
| 145 | std::vector<std::pair<UniqueThread, EventMask>> thread_event_masks; |
| 146 | |
| 147 | // A union of the per-thread events, for fast-pathing. |
| 148 | EventMask unioned_thread_event_mask; |
| 149 | |
| 150 | EventMask& GetEventMask(art::Thread* thread); |
| 151 | EventMask* GetEventMaskOrNull(art::Thread* thread); |
Alex Light | 74c8440 | 2017-11-29 15:26:38 -0800 | [diff] [blame] | 152 | // Circular dependencies mean we cannot see the definition of ArtJvmTiEnv so the mutex is simply |
| 153 | // asserted in the function. |
| 154 | // Note that the 'env' passed in must be the same env this EventMasks is associated with. |
| 155 | void EnableEvent(ArtJvmTiEnv* env, art::Thread* thread, ArtJvmtiEvent event); |
| 156 | // REQUIRES(env->event_info_mutex_); |
| 157 | // Circular dependencies mean we cannot see the definition of ArtJvmTiEnv so the mutex is simply |
| 158 | // asserted in the function. |
| 159 | // Note that the 'env' passed in must be the same env this EventMasks is associated with. |
| 160 | void DisableEvent(ArtJvmTiEnv* env, art::Thread* thread, ArtJvmtiEvent event); |
| 161 | // REQUIRES(env->event_info_mutex_); |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 162 | bool IsEnabledAnywhere(ArtJvmtiEvent event); |
| 163 | // Make any changes to event masks needed for the given capability changes. If caps_added is true |
| 164 | // then caps is all the newly set capabilities of the jvmtiEnv. If it is false then caps is the |
| 165 | // set of all capabilities that were removed from the jvmtiEnv. |
| 166 | void HandleChangedCapabilities(const jvmtiCapabilities& caps, bool caps_added); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 169 | namespace impl { |
| 170 | template <ArtJvmtiEvent kEvent> struct EventHandlerFunc { }; |
| 171 | } // namespace impl |
| 172 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 173 | // Helper class for event handling. |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 174 | class EventHandler { |
| 175 | public: |
| 176 | EventHandler(); |
| 177 | ~EventHandler(); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 178 | |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 179 | // do cleanup for the event handler. |
| 180 | void Shutdown(); |
| 181 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 182 | // Register an env. It is assumed that this happens on env creation, that is, no events are |
| 183 | // enabled, yet. |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 184 | void RegisterArtJvmTiEnv(ArtJvmTiEnv* env) REQUIRES(!envs_lock_); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 185 | |
Andreas Gampe | 3a7eb14 | 2017-01-19 21:59:22 -0800 | [diff] [blame] | 186 | // Remove an env. |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 187 | void RemoveArtJvmTiEnv(ArtJvmTiEnv* env) REQUIRES(!envs_lock_); |
Andreas Gampe | 3a7eb14 | 2017-01-19 21:59:22 -0800 | [diff] [blame] | 188 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 189 | bool IsEventEnabledAnywhere(ArtJvmtiEvent event) const { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 190 | if (!EventMask::EventIsInRange(event)) { |
| 191 | return false; |
| 192 | } |
| 193 | return global_mask.Test(event); |
| 194 | } |
| 195 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 196 | jvmtiError SetEvent(ArtJvmTiEnv* env, |
| 197 | art::Thread* thread, |
| 198 | ArtJvmtiEvent event, |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 199 | jvmtiEventMode mode) |
| 200 | REQUIRES(!envs_lock_); |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 201 | |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 202 | // Dispatch event to all registered environments. Since this one doesn't have a JNIEnv* it doesn't |
| 203 | // matter if it has the mutator_lock. |
Andreas Gampe | 983c175 | 2017-01-23 19:46:56 -0800 | [diff] [blame] | 204 | template <ArtJvmtiEvent kEvent, typename ...Args> |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 205 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 206 | inline void DispatchEvent(art::Thread* thread, Args... args) const |
| 207 | REQUIRES(!envs_lock_); |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 208 | |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 209 | // Dispatch event to all registered environments stashing exceptions as needed. This works since |
| 210 | // JNIEnv* is always the second argument if it is passed to an event. Needed since C++ does not |
| 211 | // allow partial template function specialization. |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 212 | // |
| 213 | // We need both of these since we want to make sure to push a stack frame when it is possible for |
| 214 | // the event to allocate local references. |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 215 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 216 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 217 | inline void DispatchEvent(art::Thread* thread, JNIEnv* jnienv, Args... args) const |
| 218 | REQUIRES(!envs_lock_); |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 219 | |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 220 | // Tell the event handler capabilities were added/lost so it can adjust the sent events.If |
| 221 | // caps_added is true then caps is all the newly set capabilities of the jvmtiEnv. If it is false |
| 222 | // then caps is the set of all capabilities that were removed from the jvmtiEnv. |
| 223 | ALWAYS_INLINE |
| 224 | inline void HandleChangedCapabilities(ArtJvmTiEnv* env, |
| 225 | const jvmtiCapabilities& caps, |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 226 | bool added) |
| 227 | REQUIRES(!envs_lock_); |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 228 | |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 229 | // Dispatch event to the given environment, only. |
| 230 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 231 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 232 | inline void DispatchEventOnEnv(ArtJvmTiEnv* env, |
| 233 | art::Thread* thread, |
| 234 | JNIEnv* jnienv, |
| 235 | Args... args) const |
| 236 | REQUIRES(!envs_lock_); |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 237 | |
| 238 | // Dispatch event to the given environment, only. |
| 239 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 240 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 241 | inline void DispatchEventOnEnv(ArtJvmTiEnv* env, art::Thread* thread, Args... args) const |
| 242 | REQUIRES(!envs_lock_); |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 243 | |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 244 | private: |
Alex Light | f6df1b5 | 2017-11-29 14:46:53 -0800 | [diff] [blame] | 245 | void SetupTraceListener(JvmtiMethodTraceListener* listener, ArtJvmtiEvent event, bool enable); |
| 246 | |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 247 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 248 | ALWAYS_INLINE |
| 249 | inline std::vector<impl::EventHandlerFunc<kEvent>> CollectEvents(art::Thread* thread, |
| 250 | Args... args) const |
| 251 | REQUIRES(!envs_lock_); |
| 252 | |
Andreas Gampe | 983c175 | 2017-01-23 19:46:56 -0800 | [diff] [blame] | 253 | template <ArtJvmtiEvent kEvent> |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 254 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 255 | inline bool ShouldDispatchOnThread(ArtJvmTiEnv* env, art::Thread* thread) const; |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 256 | |
| 257 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 258 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 259 | static inline void ExecuteCallback(impl::EventHandlerFunc<kEvent> handler, |
| 260 | JNIEnv* env, |
| 261 | Args... args) |
| 262 | REQUIRES(!envs_lock_); |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 263 | |
| 264 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 265 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 266 | static inline void ExecuteCallback(impl::EventHandlerFunc<kEvent> handler, Args... args) |
| 267 | REQUIRES(!envs_lock_); |
| 268 | |
| 269 | // Public for use to collect dispatches |
| 270 | template <ArtJvmtiEvent kEvent, typename ...Args> |
| 271 | ALWAYS_INLINE |
Alex Light | 9df79b7 | 2017-09-12 08:57:31 -0700 | [diff] [blame] | 272 | inline bool ShouldDispatch(ArtJvmTiEnv* env, art::Thread* thread, Args... args) const; |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 273 | |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 274 | ALWAYS_INLINE |
| 275 | inline bool NeedsEventUpdate(ArtJvmTiEnv* env, |
| 276 | const jvmtiCapabilities& caps, |
| 277 | bool added); |
| 278 | |
| 279 | // Recalculates the event mask for the given event. |
| 280 | ALWAYS_INLINE |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 281 | inline void RecalculateGlobalEventMask(ArtJvmtiEvent event) REQUIRES(!envs_lock_); |
| 282 | ALWAYS_INLINE |
| 283 | inline void RecalculateGlobalEventMaskLocked(ArtJvmtiEvent event) REQUIRES(envs_lock_); |
Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 284 | |
Andreas Gampe | 983c175 | 2017-01-23 19:46:56 -0800 | [diff] [blame] | 285 | template <ArtJvmtiEvent kEvent> |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 286 | ALWAYS_INLINE inline void DispatchClassFileLoadHookEvent(art::Thread* thread, |
Andreas Gampe | 983c175 | 2017-01-23 19:46:56 -0800 | [diff] [blame] | 287 | JNIEnv* jnienv, |
| 288 | jclass class_being_redefined, |
| 289 | jobject loader, |
| 290 | const char* name, |
| 291 | jobject protection_domain, |
| 292 | jint class_data_len, |
| 293 | const unsigned char* class_data, |
| 294 | jint* new_class_data_len, |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 295 | unsigned char** new_class_data) const |
| 296 | REQUIRES(!envs_lock_); |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 297 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 298 | void HandleEventType(ArtJvmtiEvent event, bool enable); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 299 | void HandleLocalAccessCapabilityAdded(); |
Alex Light | 0fa1786 | 2017-10-24 13:43:05 -0700 | [diff] [blame] | 300 | void HandleBreakpointEventsChanged(bool enable); |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 301 | |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 302 | bool OtherMonitorEventsEnabledAnywhere(ArtJvmtiEvent event); |
| 303 | |
Alex Light | b284f8d | 2017-11-21 00:00:48 +0000 | [diff] [blame] | 304 | // List of all JvmTiEnv objects that have been created, in their creation order. It is a std::list |
| 305 | // since we mostly access it by iterating over the entire thing, only ever append to the end, and |
| 306 | // need to be able to remove arbitrary elements from it. |
| 307 | std::list<ArtJvmTiEnv*> envs GUARDED_BY(envs_lock_); |
| 308 | |
| 309 | // Top level lock. Nothing at all should be held when we lock this. |
| 310 | mutable art::Mutex envs_lock_ ACQUIRED_BEFORE(art::Locks::instrument_entrypoints_lock_); |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 311 | |
| 312 | // A union of all enabled events, anywhere. |
| 313 | EventMask global_mask; |
| 314 | |
| 315 | std::unique_ptr<JvmtiAllocationListener> alloc_listener_; |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 316 | std::unique_ptr<JvmtiDdmChunkListener> ddm_listener_; |
Andreas Gampe | 9b8c588 | 2016-10-21 15:27:46 -0700 | [diff] [blame] | 317 | std::unique_ptr<JvmtiGcPauseListener> gc_pause_listener_; |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 318 | std::unique_ptr<JvmtiMethodTraceListener> method_trace_listener_; |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 319 | std::unique_ptr<JvmtiMonitorListener> monitor_listener_; |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 320 | |
| 321 | // True if frame pop has ever been enabled. Since we store pointers to stack frames we need to |
| 322 | // continue to listen to this event even if it has been disabled. |
| 323 | // TODO We could remove the listeners once all jvmtiEnvs have drained their shadow-frame vectors. |
| 324 | bool frame_pop_enabled; |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | } // namespace openjdkjvmti |
| 328 | |
Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 329 | #endif // ART_OPENJDKJVMTI_EVENTS_H_ |