1 /* 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP 26 #define SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP 27 28 #include "jvmtifiles/jvmti.h" 29 #include "memory/allocation.hpp" 30 #include "memory/allocation.inline.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 // forward declaration 34 class JvmtiEventControllerPrivate; 35 class JvmtiEventController; 36 class JvmtiEnvThreadState; 37 class JvmtiFramePop; 38 class JvmtiEnvBase; 39 40 41 // Extension event support 42 // 43 // jvmtiExtEvent is the extensions equivalent of jvmtiEvent 44 // jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks 45 46 // Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0. 47 typedef enum { 48 EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1, 49 EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD, 50 EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD 51 } jvmtiExtEvent; 52 53 typedef struct { 54 jvmtiExtensionEvent ClassUnload; 55 } jvmtiExtEventCallbacks; 56 57 58 // The complete range of events is EXT_MIN_EVENT_TYPE_VAL to 59 // JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous). 60 const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL; 61 const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL; 62 63 64 /////////////////////////////////////////////////////////////// 65 // 66 // JvmtiEventEnabled 67 // 68 // Utility class 69 // 70 // A boolean array indexed by event_type, used as an internal 71 // data structure to track what JVMTI event types are enabled. 72 // Used for user set enabling and disabling (globally and on a 73 // per thread basis), and for computed merges across environments, 74 // threads and the VM as a whole. 75 // 76 // for inlines see jvmtiEventController_inline.hpp 77 // 78 79 class JvmtiEventEnabled VALUE_OBJ_CLASS_SPEC { 80 private: 81 friend class JvmtiEventControllerPrivate; 82 jlong _enabled_bits; 83 #ifndef PRODUCT 84 enum { 85 JEE_INIT_GUARD = 0xEAD0 86 } _init_guard; 87 #endif 88 static jlong bit_for(jvmtiEvent event_type); 89 jlong get_bits(); 90 void set_bits(jlong bits); 91 public: 92 JvmtiEventEnabled(); 93 void clear(); 94 bool is_enabled(jvmtiEvent event_type); 95 void set_enabled(jvmtiEvent event_type, bool enabled); 96 }; 97 98 99 /////////////////////////////////////////////////////////////// 100 // 101 // JvmtiEnvThreadEventEnable 102 // 103 // JvmtiEventController data specific to a particular environment and thread. 104 // 105 // for inlines see jvmtiEventController_inline.hpp 106 // 107 108 class JvmtiEnvThreadEventEnable VALUE_OBJ_CLASS_SPEC { 109 private: 110 friend class JvmtiEventControllerPrivate; 111 JvmtiEventEnabled _event_user_enabled; 112 JvmtiEventEnabled _event_enabled; 113 114 public: 115 JvmtiEnvThreadEventEnable(); 116 ~JvmtiEnvThreadEventEnable(); 117 bool is_enabled(jvmtiEvent event_type); 118 void set_user_enabled(jvmtiEvent event_type, bool enabled); 119 }; 120 121 122 /////////////////////////////////////////////////////////////// 123 // 124 // JvmtiThreadEventEnable 125 // 126 // JvmtiEventController data specific to a particular thread. 127 // 128 // for inlines see jvmtiEventController_inline.hpp 129 // 130 131 class JvmtiThreadEventEnable VALUE_OBJ_CLASS_SPEC { 132 private: 133 friend class JvmtiEventControllerPrivate; 134 JvmtiEventEnabled _event_enabled; 135 136 public: 137 JvmtiThreadEventEnable(); 138 ~JvmtiThreadEventEnable(); 139 bool is_enabled(jvmtiEvent event_type); 140 }; 141 142 143 /////////////////////////////////////////////////////////////// 144 // 145 // JvmtiEnvEventEnable 146 // 147 // JvmtiEventController data specific to a particular environment. 148 // 149 // for inlines see jvmtiEventController_inline.hpp 150 // 151 152 class JvmtiEnvEventEnable VALUE_OBJ_CLASS_SPEC { 153 private: 154 friend class JvmtiEventControllerPrivate; 155 156 // user set global event enablement indexed by jvmtiEvent 157 JvmtiEventEnabled _event_user_enabled; 158 159 // this flag indicates the presence (true) or absence (false) of event callbacks 160 // it is indexed by jvmtiEvent 161 JvmtiEventEnabled _event_callback_enabled; 162 163 // indexed by jvmtiEvent true if enabled globally or on any thread. 164 // True only if there is a callback for it. 165 JvmtiEventEnabled _event_enabled; 166 167 public: 168 JvmtiEnvEventEnable(); 169 ~JvmtiEnvEventEnable(); 170 bool is_enabled(jvmtiEvent event_type); 171 void set_user_enabled(jvmtiEvent event_type, bool enabled); 172 }; 173 174 175 /////////////////////////////////////////////////////////////// 176 // 177 // JvmtiEventController 178 // 179 // The class is the access point for all actions that change 180 // which events are active, this include: 181 // enabling and disabling events 182 // changing the callbacks/eventhook (they may be null) 183 // setting and clearing field watchpoints 184 // setting frame pops 185 // encountering frame pops 186 // 187 // for inlines see jvmtiEventController_inline.hpp 188 // 189 190 class JvmtiEventController : AllStatic { 191 private: 192 friend class JvmtiEventControllerPrivate; 193 194 // for all environments, global array indexed by jvmtiEvent 195 static JvmtiEventEnabled _universal_global_event_enabled; 196 197 public: 198 static bool is_enabled(jvmtiEvent event_type); 199 200 // events that can ONLY be enabled/disabled globally (can't toggle on individual threads). 201 static bool is_global_event(jvmtiEvent event_type); 202 203 // is the event_type valid? 204 // to do: check against valid event array 205 static bool is_valid_event_type(jvmtiEvent event_type) { 206 return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL) 207 && ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL); 208 } 209 210 // Use (thread == NULL) to enable/disable an event globally. 211 // Use (thread != NULL) to enable/disable an event for a particular thread. 212 // thread is ignored for events that can only be specified globally 213 static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, 214 jvmtiEvent event_type, bool enabled); 215 216 // Setting callbacks changes computed enablement and must be done 217 // at a safepoint otherwise a NULL callback could be attempted 218 static void set_event_callbacks(JvmtiEnvBase *env, 219 const jvmtiEventCallbacks* callbacks, 220 jint size_of_callbacks); 221 222 // Sets the callback function for a single extension event and enables 223 // (or disables it). 224 static void set_extension_event_callback(JvmtiEnvBase* env, 225 jint extension_event_index, 226 jvmtiExtensionEvent callback); 227 228 static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 229 static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 230 static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 231 232 static void change_field_watch(jvmtiEvent event_type, bool added); 233 234 static void thread_started(JavaThread *thread); 235 static void thread_ended(JavaThread *thread); 236 237 static void env_initialize(JvmtiEnvBase *env); 238 static void env_dispose(JvmtiEnvBase *env); 239 240 static void vm_start(); 241 static void vm_init(); 242 static void vm_death(); 243 }; 244 245 #endif // SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP