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 | |
| 17 | #ifndef ART_RUNTIME_OPENJDKJVMTI_EVENTS_INL_H_ |
| 18 | #define ART_RUNTIME_OPENJDKJVMTI_EVENTS_INL_H_ |
| 19 | |
| 20 | #include "events.h" |
| 21 | |
| 22 | #include "art_jvmti.h" |
| 23 | |
| 24 | namespace openjdkjvmti { |
| 25 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 26 | static inline ArtJvmtiEvent GetArtJvmtiEvent(ArtJvmTiEnv* env ATTRIBUTE_UNUSED, |
| 27 | jvmtiEvent e) { |
| 28 | return static_cast<ArtJvmtiEvent>(e); |
| 29 | } |
| 30 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 31 | template <typename FnType> |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 32 | ALWAYS_INLINE static inline FnType* GetCallback(ArtJvmTiEnv* env, ArtJvmtiEvent event) { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 33 | if (env->event_callbacks == nullptr) { |
| 34 | return nullptr; |
| 35 | } |
| 36 | |
Andreas Gampe | 27fa96c | 2016-10-07 15:05:24 -0700 | [diff] [blame] | 37 | // TODO: Add a type check. Can be done, for example, by an explicitly instantiated template |
| 38 | // function. |
| 39 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 40 | switch (event) { |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 41 | case ArtJvmtiEvent::kVmInit: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 42 | return reinterpret_cast<FnType*>(env->event_callbacks->VMInit); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 43 | case ArtJvmtiEvent::kVmDeath: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 44 | return reinterpret_cast<FnType*>(env->event_callbacks->VMDeath); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 45 | case ArtJvmtiEvent::kThreadStart: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 46 | return reinterpret_cast<FnType*>(env->event_callbacks->ThreadStart); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 47 | case ArtJvmtiEvent::kThreadEnd: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 48 | return reinterpret_cast<FnType*>(env->event_callbacks->ThreadEnd); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 49 | case ArtJvmtiEvent::kClassFileLoadHook: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 50 | return reinterpret_cast<FnType*>(env->event_callbacks->ClassFileLoadHook); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 51 | case ArtJvmtiEvent::kClassLoad: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 52 | return reinterpret_cast<FnType*>(env->event_callbacks->ClassLoad); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 53 | case ArtJvmtiEvent::kClassPrepare: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 54 | return reinterpret_cast<FnType*>(env->event_callbacks->ClassPrepare); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 55 | case ArtJvmtiEvent::kVmStart: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 56 | return reinterpret_cast<FnType*>(env->event_callbacks->VMStart); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 57 | case ArtJvmtiEvent::kException: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 58 | return reinterpret_cast<FnType*>(env->event_callbacks->Exception); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 59 | case ArtJvmtiEvent::kExceptionCatch: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 60 | return reinterpret_cast<FnType*>(env->event_callbacks->ExceptionCatch); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 61 | case ArtJvmtiEvent::kSingleStep: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 62 | return reinterpret_cast<FnType*>(env->event_callbacks->SingleStep); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 63 | case ArtJvmtiEvent::kFramePop: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 64 | return reinterpret_cast<FnType*>(env->event_callbacks->FramePop); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 65 | case ArtJvmtiEvent::kBreakpoint: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 66 | return reinterpret_cast<FnType*>(env->event_callbacks->Breakpoint); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 67 | case ArtJvmtiEvent::kFieldAccess: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 68 | return reinterpret_cast<FnType*>(env->event_callbacks->FieldAccess); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 69 | case ArtJvmtiEvent::kFieldModification: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 70 | return reinterpret_cast<FnType*>(env->event_callbacks->FieldModification); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 71 | case ArtJvmtiEvent::kMethodEntry: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 72 | return reinterpret_cast<FnType*>(env->event_callbacks->MethodEntry); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 73 | case ArtJvmtiEvent::kMethodExit: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 74 | return reinterpret_cast<FnType*>(env->event_callbacks->MethodExit); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 75 | case ArtJvmtiEvent::kNativeMethodBind: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 76 | return reinterpret_cast<FnType*>(env->event_callbacks->NativeMethodBind); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 77 | case ArtJvmtiEvent::kCompiledMethodLoad: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 78 | return reinterpret_cast<FnType*>(env->event_callbacks->CompiledMethodLoad); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 79 | case ArtJvmtiEvent::kCompiledMethodUnload: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 80 | return reinterpret_cast<FnType*>(env->event_callbacks->CompiledMethodUnload); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 81 | case ArtJvmtiEvent::kDynamicCodeGenerated: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 82 | return reinterpret_cast<FnType*>(env->event_callbacks->DynamicCodeGenerated); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 83 | case ArtJvmtiEvent::kDataDumpRequest: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 84 | return reinterpret_cast<FnType*>(env->event_callbacks->DataDumpRequest); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 85 | case ArtJvmtiEvent::kMonitorWait: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 86 | return reinterpret_cast<FnType*>(env->event_callbacks->MonitorWait); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 87 | case ArtJvmtiEvent::kMonitorWaited: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 88 | return reinterpret_cast<FnType*>(env->event_callbacks->MonitorWaited); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 89 | case ArtJvmtiEvent::kMonitorContendedEnter: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 90 | return reinterpret_cast<FnType*>(env->event_callbacks->MonitorContendedEnter); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 91 | case ArtJvmtiEvent::kMonitorContendedEntered: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 92 | return reinterpret_cast<FnType*>(env->event_callbacks->MonitorContendedEntered); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 93 | case ArtJvmtiEvent::kResourceExhausted: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 94 | return reinterpret_cast<FnType*>(env->event_callbacks->ResourceExhausted); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 95 | case ArtJvmtiEvent::kGarbageCollectionStart: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 96 | return reinterpret_cast<FnType*>(env->event_callbacks->GarbageCollectionStart); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 97 | case ArtJvmtiEvent::kGarbageCollectionFinish: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 98 | return reinterpret_cast<FnType*>(env->event_callbacks->GarbageCollectionFinish); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 99 | case ArtJvmtiEvent::kObjectFree: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 100 | return reinterpret_cast<FnType*>(env->event_callbacks->ObjectFree); |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 101 | case ArtJvmtiEvent::kVmObjectAlloc: |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 102 | return reinterpret_cast<FnType*>(env->event_callbacks->VMObjectAlloc); |
| 103 | } |
| 104 | return nullptr; |
| 105 | } |
| 106 | |
| 107 | template <typename ...Args> |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 108 | inline void EventHandler::DispatchEvent(art::Thread* thread, |
| 109 | ArtJvmtiEvent event, |
| 110 | Args... args) const { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 111 | using FnType = void(jvmtiEnv*, Args...); |
| 112 | for (ArtJvmTiEnv* env : envs) { |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 113 | if (ShouldDispatch(event, env, thread)) { |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 114 | FnType* callback = GetCallback<FnType>(env, event); |
| 115 | if (callback != nullptr) { |
| 116 | (*callback)(env, args...); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame^] | 122 | inline bool EventHandler::ShouldDispatch(ArtJvmtiEvent event, |
| 123 | ArtJvmTiEnv* env, |
| 124 | art::Thread* thread) { |
| 125 | bool dispatch = env->event_masks.global_event_mask.Test(event); |
| 126 | |
| 127 | if (!dispatch && thread != nullptr && env->event_masks.unioned_thread_event_mask.Test(event)) { |
| 128 | EventMask* mask = env->event_masks.GetEventMaskOrNull(thread); |
| 129 | dispatch = mask != nullptr && mask->Test(event); |
| 130 | } |
| 131 | return dispatch; |
| 132 | } |
| 133 | |
Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 134 | } // namespace openjdkjvmti |
| 135 | |
| 136 | #endif // ART_RUNTIME_OPENJDKJVMTI_EVENTS_INL_H_ |