blob: b29830112e9790fa5c33b4f5e176eaef3b0d9308 [file] [log] [blame]
Andreas Gampe77708d92016-10-07 11:48:21 -07001/*
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
24namespace openjdkjvmti {
25
26template <typename FnType>
27ALWAYS_INLINE static inline FnType* GetCallback(ArtJvmTiEnv* env, jvmtiEvent event) {
28 if (env->event_callbacks == nullptr) {
29 return nullptr;
30 }
31
32 switch (event) {
33 case JVMTI_EVENT_VM_INIT:
34 return reinterpret_cast<FnType*>(env->event_callbacks->VMInit);
35 case JVMTI_EVENT_VM_DEATH:
36 return reinterpret_cast<FnType*>(env->event_callbacks->VMDeath);
37 case JVMTI_EVENT_THREAD_START:
38 return reinterpret_cast<FnType*>(env->event_callbacks->ThreadStart);
39 case JVMTI_EVENT_THREAD_END:
40 return reinterpret_cast<FnType*>(env->event_callbacks->ThreadEnd);
41 case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK:
42 return reinterpret_cast<FnType*>(env->event_callbacks->ClassFileLoadHook);
43 case JVMTI_EVENT_CLASS_LOAD:
44 return reinterpret_cast<FnType*>(env->event_callbacks->ClassLoad);
45 case JVMTI_EVENT_CLASS_PREPARE:
46 return reinterpret_cast<FnType*>(env->event_callbacks->ClassPrepare);
47 case JVMTI_EVENT_VM_START:
48 return reinterpret_cast<FnType*>(env->event_callbacks->VMStart);
49 case JVMTI_EVENT_EXCEPTION:
50 return reinterpret_cast<FnType*>(env->event_callbacks->Exception);
51 case JVMTI_EVENT_EXCEPTION_CATCH:
52 return reinterpret_cast<FnType*>(env->event_callbacks->ExceptionCatch);
53 case JVMTI_EVENT_SINGLE_STEP:
54 return reinterpret_cast<FnType*>(env->event_callbacks->SingleStep);
55 case JVMTI_EVENT_FRAME_POP:
56 return reinterpret_cast<FnType*>(env->event_callbacks->FramePop);
57 case JVMTI_EVENT_BREAKPOINT:
58 return reinterpret_cast<FnType*>(env->event_callbacks->Breakpoint);
59 case JVMTI_EVENT_FIELD_ACCESS:
60 return reinterpret_cast<FnType*>(env->event_callbacks->FieldAccess);
61 case JVMTI_EVENT_FIELD_MODIFICATION:
62 return reinterpret_cast<FnType*>(env->event_callbacks->FieldModification);
63 case JVMTI_EVENT_METHOD_ENTRY:
64 return reinterpret_cast<FnType*>(env->event_callbacks->MethodEntry);
65 case JVMTI_EVENT_METHOD_EXIT:
66 return reinterpret_cast<FnType*>(env->event_callbacks->MethodExit);
67 case JVMTI_EVENT_NATIVE_METHOD_BIND:
68 return reinterpret_cast<FnType*>(env->event_callbacks->NativeMethodBind);
69 case JVMTI_EVENT_COMPILED_METHOD_LOAD:
70 return reinterpret_cast<FnType*>(env->event_callbacks->CompiledMethodLoad);
71 case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
72 return reinterpret_cast<FnType*>(env->event_callbacks->CompiledMethodUnload);
73 case JVMTI_EVENT_DYNAMIC_CODE_GENERATED:
74 return reinterpret_cast<FnType*>(env->event_callbacks->DynamicCodeGenerated);
75 case JVMTI_EVENT_DATA_DUMP_REQUEST:
76 return reinterpret_cast<FnType*>(env->event_callbacks->DataDumpRequest);
77 case JVMTI_EVENT_MONITOR_WAIT:
78 return reinterpret_cast<FnType*>(env->event_callbacks->MonitorWait);
79 case JVMTI_EVENT_MONITOR_WAITED:
80 return reinterpret_cast<FnType*>(env->event_callbacks->MonitorWaited);
81 case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
82 return reinterpret_cast<FnType*>(env->event_callbacks->MonitorContendedEnter);
83 case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
84 return reinterpret_cast<FnType*>(env->event_callbacks->MonitorContendedEntered);
85 case JVMTI_EVENT_RESOURCE_EXHAUSTED:
86 return reinterpret_cast<FnType*>(env->event_callbacks->ResourceExhausted);
87 case JVMTI_EVENT_GARBAGE_COLLECTION_START:
88 return reinterpret_cast<FnType*>(env->event_callbacks->GarbageCollectionStart);
89 case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
90 return reinterpret_cast<FnType*>(env->event_callbacks->GarbageCollectionFinish);
91 case JVMTI_EVENT_OBJECT_FREE:
92 return reinterpret_cast<FnType*>(env->event_callbacks->ObjectFree);
93 case JVMTI_EVENT_VM_OBJECT_ALLOC:
94 return reinterpret_cast<FnType*>(env->event_callbacks->VMObjectAlloc);
95 }
96 return nullptr;
97}
98
99template <typename ...Args>
100inline void EventHandler::DispatchEvent(art::Thread* thread, jvmtiEvent event, Args... args) {
101 using FnType = void(jvmtiEnv*, Args...);
102 for (ArtJvmTiEnv* env : envs) {
103 bool dispatch = env->event_masks.global_event_mask.Test(event);
104
105 if (!dispatch && thread != nullptr && env->event_masks.unioned_thread_event_mask.Test(event)) {
106 EventMask* mask = env->event_masks.GetEventMaskOrNull(thread);
107 dispatch = mask != nullptr && mask->Test(event);
108 }
109
110 if (dispatch) {
111 FnType* callback = GetCallback<FnType>(env, event);
112 if (callback != nullptr) {
113 (*callback)(env, args...);
114 }
115 }
116 }
117}
118
119} // namespace openjdkjvmti
120
121#endif // ART_RUNTIME_OPENJDKJVMTI_EVENTS_INL_H_