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