src/share/vm/prims/jvmtiEventController.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial