1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/jvmtiEventController.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,240 @@ 1.4 +/* 1.5 + * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef _JAVA_JVMTI_EVENT_CONTROLLER_H_ 1.29 +#define _JAVA_JVMTI_EVENT_CONTROLLER_H_ 1.30 + 1.31 +// forward declaration 1.32 +class JvmtiEventControllerPrivate; 1.33 +class JvmtiEventController; 1.34 +class JvmtiEnvThreadState; 1.35 +class JvmtiFramePop; 1.36 +class JvmtiEnvBase; 1.37 + 1.38 + 1.39 +// Extension event support 1.40 +// 1.41 +// jvmtiExtEvent is the extensions equivalent of jvmtiEvent 1.42 +// jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks 1.43 + 1.44 +// Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0. 1.45 +typedef enum { 1.46 + EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1, 1.47 + EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD, 1.48 + EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD 1.49 +} jvmtiExtEvent; 1.50 + 1.51 +typedef struct { 1.52 + jvmtiExtensionEvent ClassUnload; 1.53 +} jvmtiExtEventCallbacks; 1.54 + 1.55 + 1.56 +// The complete range of events is EXT_MIN_EVENT_TYPE_VAL to 1.57 +// JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous). 1.58 +const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL; 1.59 +const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL; 1.60 + 1.61 + 1.62 +/////////////////////////////////////////////////////////////// 1.63 +// 1.64 +// JvmtiEventEnabled 1.65 +// 1.66 +// Utility class 1.67 +// 1.68 +// A boolean array indexed by event_type, used as an internal 1.69 +// data structure to track what JVMTI event types are enabled. 1.70 +// Used for user set enabling and disabling (globally and on a 1.71 +// per thread basis), and for computed merges across environments, 1.72 +// threads and the VM as a whole. 1.73 +// 1.74 +// for inlines see jvmtiEventController_inline.hpp 1.75 +// 1.76 + 1.77 +class JvmtiEventEnabled VALUE_OBJ_CLASS_SPEC { 1.78 +private: 1.79 + friend class JvmtiEventControllerPrivate; 1.80 + jlong _enabled_bits; 1.81 +#ifndef PRODUCT 1.82 + enum { 1.83 + JEE_INIT_GUARD = 0xEAD0 1.84 + } _init_guard; 1.85 +#endif 1.86 + static jlong bit_for(jvmtiEvent event_type); 1.87 + jlong get_bits(); 1.88 + void set_bits(jlong bits); 1.89 +public: 1.90 + JvmtiEventEnabled(); 1.91 + void clear(); 1.92 + bool is_enabled(jvmtiEvent event_type); 1.93 + void set_enabled(jvmtiEvent event_type, bool enabled); 1.94 +}; 1.95 + 1.96 + 1.97 +/////////////////////////////////////////////////////////////// 1.98 +// 1.99 +// JvmtiEnvThreadEventEnable 1.100 +// 1.101 +// JvmtiEventController data specific to a particular environment and thread. 1.102 +// 1.103 +// for inlines see jvmtiEventController_inline.hpp 1.104 +// 1.105 + 1.106 +class JvmtiEnvThreadEventEnable VALUE_OBJ_CLASS_SPEC { 1.107 +private: 1.108 + friend class JvmtiEventControllerPrivate; 1.109 + JvmtiEventEnabled _event_user_enabled; 1.110 + JvmtiEventEnabled _event_enabled; 1.111 + 1.112 +public: 1.113 + JvmtiEnvThreadEventEnable(); 1.114 + ~JvmtiEnvThreadEventEnable(); 1.115 + bool is_enabled(jvmtiEvent event_type); 1.116 + void set_user_enabled(jvmtiEvent event_type, bool enabled); 1.117 +}; 1.118 + 1.119 + 1.120 +/////////////////////////////////////////////////////////////// 1.121 +// 1.122 +// JvmtiThreadEventEnable 1.123 +// 1.124 +// JvmtiEventController data specific to a particular thread. 1.125 +// 1.126 +// for inlines see jvmtiEventController_inline.hpp 1.127 +// 1.128 + 1.129 +class JvmtiThreadEventEnable VALUE_OBJ_CLASS_SPEC { 1.130 +private: 1.131 + friend class JvmtiEventControllerPrivate; 1.132 + JvmtiEventEnabled _event_enabled; 1.133 + 1.134 +public: 1.135 + JvmtiThreadEventEnable(); 1.136 + ~JvmtiThreadEventEnable(); 1.137 + bool is_enabled(jvmtiEvent event_type); 1.138 +}; 1.139 + 1.140 + 1.141 +/////////////////////////////////////////////////////////////// 1.142 +// 1.143 +// JvmtiEnvEventEnable 1.144 +// 1.145 +// JvmtiEventController data specific to a particular environment. 1.146 +// 1.147 +// for inlines see jvmtiEventController_inline.hpp 1.148 +// 1.149 + 1.150 +class JvmtiEnvEventEnable VALUE_OBJ_CLASS_SPEC { 1.151 +private: 1.152 + friend class JvmtiEventControllerPrivate; 1.153 + 1.154 + // user set global event enablement indexed by jvmtiEvent 1.155 + JvmtiEventEnabled _event_user_enabled; 1.156 + 1.157 + // this flag indicates the presence (true) or absence (false) of event callbacks 1.158 + // it is indexed by jvmtiEvent 1.159 + JvmtiEventEnabled _event_callback_enabled; 1.160 + 1.161 + // indexed by jvmtiEvent true if enabled globally or on any thread. 1.162 + // True only if there is a callback for it. 1.163 + JvmtiEventEnabled _event_enabled; 1.164 + 1.165 +public: 1.166 + JvmtiEnvEventEnable(); 1.167 + ~JvmtiEnvEventEnable(); 1.168 + bool is_enabled(jvmtiEvent event_type); 1.169 + void set_user_enabled(jvmtiEvent event_type, bool enabled); 1.170 +}; 1.171 + 1.172 + 1.173 +/////////////////////////////////////////////////////////////// 1.174 +// 1.175 +// JvmtiEventController 1.176 +// 1.177 +// The class is the access point for all actions that change 1.178 +// which events are active, this include: 1.179 +// enabling and disabling events 1.180 +// changing the callbacks/eventhook (they may be null) 1.181 +// setting and clearing field watchpoints 1.182 +// setting frame pops 1.183 +// encountering frame pops 1.184 +// 1.185 +// for inlines see jvmtiEventController_inline.hpp 1.186 +// 1.187 + 1.188 +class JvmtiEventController : AllStatic { 1.189 +private: 1.190 + friend class JvmtiEventControllerPrivate; 1.191 + 1.192 + // for all environments, global array indexed by jvmtiEvent 1.193 + static JvmtiEventEnabled _universal_global_event_enabled; 1.194 + 1.195 +public: 1.196 + static bool is_enabled(jvmtiEvent event_type); 1.197 + 1.198 + // events that can ONLY be enabled/disabled globally (can't toggle on individual threads). 1.199 + static bool is_global_event(jvmtiEvent event_type); 1.200 + 1.201 + // is the event_type valid? 1.202 + // to do: check against valid event array 1.203 + static bool is_valid_event_type(jvmtiEvent event_type) { 1.204 + return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL) 1.205 + && ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL); 1.206 + } 1.207 + 1.208 + // Use (thread == NULL) to enable/disable an event globally. 1.209 + // Use (thread != NULL) to enable/disable an event for a particular thread. 1.210 + // thread is ignored for events that can only be specified globally 1.211 + static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, 1.212 + jvmtiEvent event_type, bool enabled); 1.213 + 1.214 + // Setting callbacks changes computed enablement and must be done 1.215 + // at a safepoint otherwise a NULL callback could be attempted 1.216 + static void set_event_callbacks(JvmtiEnvBase *env, 1.217 + const jvmtiEventCallbacks* callbacks, 1.218 + jint size_of_callbacks); 1.219 + 1.220 + // Sets the callback function for a single extension event and enables 1.221 + // (or disables it). 1.222 + static void set_extension_event_callback(JvmtiEnvBase* env, 1.223 + jint extension_event_index, 1.224 + jvmtiExtensionEvent callback); 1.225 + 1.226 + static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.227 + static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.228 + static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.229 + 1.230 + static void change_field_watch(jvmtiEvent event_type, bool added); 1.231 + 1.232 + static void thread_started(JavaThread *thread); 1.233 + static void thread_ended(JavaThread *thread); 1.234 + 1.235 + static void env_initialize(JvmtiEnvBase *env); 1.236 + static void env_dispose(JvmtiEnvBase *env); 1.237 + 1.238 + static void vm_start(); 1.239 + static void vm_init(); 1.240 + static void vm_death(); 1.241 +}; 1.242 + 1.243 +#endif /* _JAVA_JVMTI_EVENT_CONTROLLER_H_ */