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