1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/jvmtiEventController.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,245 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP 1.29 +#define SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP 1.30 + 1.31 +#include "jvmtifiles/jvmti.h" 1.32 +#include "memory/allocation.hpp" 1.33 +#include "memory/allocation.inline.hpp" 1.34 +#include "utilities/globalDefinitions.hpp" 1.35 + 1.36 +// forward declaration 1.37 +class JvmtiEventControllerPrivate; 1.38 +class JvmtiEventController; 1.39 +class JvmtiEnvThreadState; 1.40 +class JvmtiFramePop; 1.41 +class JvmtiEnvBase; 1.42 + 1.43 + 1.44 +// Extension event support 1.45 +// 1.46 +// jvmtiExtEvent is the extensions equivalent of jvmtiEvent 1.47 +// jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks 1.48 + 1.49 +// Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0. 1.50 +typedef enum { 1.51 + EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1, 1.52 + EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD, 1.53 + EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD 1.54 +} jvmtiExtEvent; 1.55 + 1.56 +typedef struct { 1.57 + jvmtiExtensionEvent ClassUnload; 1.58 +} jvmtiExtEventCallbacks; 1.59 + 1.60 + 1.61 +// The complete range of events is EXT_MIN_EVENT_TYPE_VAL to 1.62 +// JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous). 1.63 +const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL; 1.64 +const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL; 1.65 + 1.66 + 1.67 +/////////////////////////////////////////////////////////////// 1.68 +// 1.69 +// JvmtiEventEnabled 1.70 +// 1.71 +// Utility class 1.72 +// 1.73 +// A boolean array indexed by event_type, used as an internal 1.74 +// data structure to track what JVMTI event types are enabled. 1.75 +// Used for user set enabling and disabling (globally and on a 1.76 +// per thread basis), and for computed merges across environments, 1.77 +// threads and the VM as a whole. 1.78 +// 1.79 +// for inlines see jvmtiEventController_inline.hpp 1.80 +// 1.81 + 1.82 +class JvmtiEventEnabled VALUE_OBJ_CLASS_SPEC { 1.83 +private: 1.84 + friend class JvmtiEventControllerPrivate; 1.85 + jlong _enabled_bits; 1.86 +#ifndef PRODUCT 1.87 + enum { 1.88 + JEE_INIT_GUARD = 0xEAD0 1.89 + } _init_guard; 1.90 +#endif 1.91 + static jlong bit_for(jvmtiEvent event_type); 1.92 + jlong get_bits(); 1.93 + void set_bits(jlong bits); 1.94 +public: 1.95 + JvmtiEventEnabled(); 1.96 + void clear(); 1.97 + bool is_enabled(jvmtiEvent event_type); 1.98 + void set_enabled(jvmtiEvent event_type, bool enabled); 1.99 +}; 1.100 + 1.101 + 1.102 +/////////////////////////////////////////////////////////////// 1.103 +// 1.104 +// JvmtiEnvThreadEventEnable 1.105 +// 1.106 +// JvmtiEventController data specific to a particular environment and thread. 1.107 +// 1.108 +// for inlines see jvmtiEventController_inline.hpp 1.109 +// 1.110 + 1.111 +class JvmtiEnvThreadEventEnable VALUE_OBJ_CLASS_SPEC { 1.112 +private: 1.113 + friend class JvmtiEventControllerPrivate; 1.114 + JvmtiEventEnabled _event_user_enabled; 1.115 + JvmtiEventEnabled _event_enabled; 1.116 + 1.117 +public: 1.118 + JvmtiEnvThreadEventEnable(); 1.119 + ~JvmtiEnvThreadEventEnable(); 1.120 + bool is_enabled(jvmtiEvent event_type); 1.121 + void set_user_enabled(jvmtiEvent event_type, bool enabled); 1.122 +}; 1.123 + 1.124 + 1.125 +/////////////////////////////////////////////////////////////// 1.126 +// 1.127 +// JvmtiThreadEventEnable 1.128 +// 1.129 +// JvmtiEventController data specific to a particular thread. 1.130 +// 1.131 +// for inlines see jvmtiEventController_inline.hpp 1.132 +// 1.133 + 1.134 +class JvmtiThreadEventEnable VALUE_OBJ_CLASS_SPEC { 1.135 +private: 1.136 + friend class JvmtiEventControllerPrivate; 1.137 + JvmtiEventEnabled _event_enabled; 1.138 + 1.139 +public: 1.140 + JvmtiThreadEventEnable(); 1.141 + ~JvmtiThreadEventEnable(); 1.142 + bool is_enabled(jvmtiEvent event_type); 1.143 +}; 1.144 + 1.145 + 1.146 +/////////////////////////////////////////////////////////////// 1.147 +// 1.148 +// JvmtiEnvEventEnable 1.149 +// 1.150 +// JvmtiEventController data specific to a particular environment. 1.151 +// 1.152 +// for inlines see jvmtiEventController_inline.hpp 1.153 +// 1.154 + 1.155 +class JvmtiEnvEventEnable VALUE_OBJ_CLASS_SPEC { 1.156 +private: 1.157 + friend class JvmtiEventControllerPrivate; 1.158 + 1.159 + // user set global event enablement indexed by jvmtiEvent 1.160 + JvmtiEventEnabled _event_user_enabled; 1.161 + 1.162 + // this flag indicates the presence (true) or absence (false) of event callbacks 1.163 + // it is indexed by jvmtiEvent 1.164 + JvmtiEventEnabled _event_callback_enabled; 1.165 + 1.166 + // indexed by jvmtiEvent true if enabled globally or on any thread. 1.167 + // True only if there is a callback for it. 1.168 + JvmtiEventEnabled _event_enabled; 1.169 + 1.170 +public: 1.171 + JvmtiEnvEventEnable(); 1.172 + ~JvmtiEnvEventEnable(); 1.173 + bool is_enabled(jvmtiEvent event_type); 1.174 + void set_user_enabled(jvmtiEvent event_type, bool enabled); 1.175 +}; 1.176 + 1.177 + 1.178 +/////////////////////////////////////////////////////////////// 1.179 +// 1.180 +// JvmtiEventController 1.181 +// 1.182 +// The class is the access point for all actions that change 1.183 +// which events are active, this include: 1.184 +// enabling and disabling events 1.185 +// changing the callbacks/eventhook (they may be null) 1.186 +// setting and clearing field watchpoints 1.187 +// setting frame pops 1.188 +// encountering frame pops 1.189 +// 1.190 +// for inlines see jvmtiEventController_inline.hpp 1.191 +// 1.192 + 1.193 +class JvmtiEventController : AllStatic { 1.194 +private: 1.195 + friend class JvmtiEventControllerPrivate; 1.196 + 1.197 + // for all environments, global array indexed by jvmtiEvent 1.198 + static JvmtiEventEnabled _universal_global_event_enabled; 1.199 + 1.200 +public: 1.201 + static bool is_enabled(jvmtiEvent event_type); 1.202 + 1.203 + // events that can ONLY be enabled/disabled globally (can't toggle on individual threads). 1.204 + static bool is_global_event(jvmtiEvent event_type); 1.205 + 1.206 + // is the event_type valid? 1.207 + // to do: check against valid event array 1.208 + static bool is_valid_event_type(jvmtiEvent event_type) { 1.209 + return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL) 1.210 + && ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL); 1.211 + } 1.212 + 1.213 + // Use (thread == NULL) to enable/disable an event globally. 1.214 + // Use (thread != NULL) to enable/disable an event for a particular thread. 1.215 + // thread is ignored for events that can only be specified globally 1.216 + static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, 1.217 + jvmtiEvent event_type, bool enabled); 1.218 + 1.219 + // Setting callbacks changes computed enablement and must be done 1.220 + // at a safepoint otherwise a NULL callback could be attempted 1.221 + static void set_event_callbacks(JvmtiEnvBase *env, 1.222 + const jvmtiEventCallbacks* callbacks, 1.223 + jint size_of_callbacks); 1.224 + 1.225 + // Sets the callback function for a single extension event and enables 1.226 + // (or disables it). 1.227 + static void set_extension_event_callback(JvmtiEnvBase* env, 1.228 + jint extension_event_index, 1.229 + jvmtiExtensionEvent callback); 1.230 + 1.231 + static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.232 + static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.233 + static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.234 + 1.235 + static void change_field_watch(jvmtiEvent event_type, bool added); 1.236 + 1.237 + static void thread_started(JavaThread *thread); 1.238 + static void thread_ended(JavaThread *thread); 1.239 + 1.240 + static void env_initialize(JvmtiEnvBase *env); 1.241 + static void env_dispose(JvmtiEnvBase *env); 1.242 + 1.243 + static void vm_start(); 1.244 + static void vm_init(); 1.245 + static void vm_death(); 1.246 +}; 1.247 + 1.248 +#endif // SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP