1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/jvmtiEventController.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,1045 @@ 1.4 +/* 1.5 + * Copyright 2003-2007 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 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_jvmtiEventController.cpp.incl" 1.30 + 1.31 +#ifdef JVMTI_TRACE 1.32 +#define EC_TRACE(out) if (JvmtiTrace::trace_event_controller()) { SafeResourceMark rm; tty->print_cr out; } while (0) 1.33 +#else 1.34 +#define EC_TRACE(out) 1.35 +#endif /*JVMTI_TRACE */ 1.36 + 1.37 +// bits for standard events 1.38 + 1.39 +static const jlong SINGLE_STEP_BIT = (((jlong)1) << (JVMTI_EVENT_SINGLE_STEP - TOTAL_MIN_EVENT_TYPE_VAL)); 1.40 +static const jlong FRAME_POP_BIT = (((jlong)1) << (JVMTI_EVENT_FRAME_POP - TOTAL_MIN_EVENT_TYPE_VAL)); 1.41 +static const jlong BREAKPOINT_BIT = (((jlong)1) << (JVMTI_EVENT_BREAKPOINT - TOTAL_MIN_EVENT_TYPE_VAL)); 1.42 +static const jlong FIELD_ACCESS_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_ACCESS - TOTAL_MIN_EVENT_TYPE_VAL)); 1.43 +static const jlong FIELD_MODIFICATION_BIT = (((jlong)1) << (JVMTI_EVENT_FIELD_MODIFICATION - TOTAL_MIN_EVENT_TYPE_VAL)); 1.44 +static const jlong METHOD_ENTRY_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_ENTRY - TOTAL_MIN_EVENT_TYPE_VAL)); 1.45 +static const jlong METHOD_EXIT_BIT = (((jlong)1) << (JVMTI_EVENT_METHOD_EXIT - TOTAL_MIN_EVENT_TYPE_VAL)); 1.46 +static const jlong CLASS_FILE_LOAD_HOOK_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - TOTAL_MIN_EVENT_TYPE_VAL)); 1.47 +static const jlong NATIVE_METHOD_BIND_BIT = (((jlong)1) << (JVMTI_EVENT_NATIVE_METHOD_BIND - TOTAL_MIN_EVENT_TYPE_VAL)); 1.48 +static const jlong VM_START_BIT = (((jlong)1) << (JVMTI_EVENT_VM_START - TOTAL_MIN_EVENT_TYPE_VAL)); 1.49 +static const jlong VM_INIT_BIT = (((jlong)1) << (JVMTI_EVENT_VM_INIT - TOTAL_MIN_EVENT_TYPE_VAL)); 1.50 +static const jlong VM_DEATH_BIT = (((jlong)1) << (JVMTI_EVENT_VM_DEATH - TOTAL_MIN_EVENT_TYPE_VAL)); 1.51 +static const jlong CLASS_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_LOAD - TOTAL_MIN_EVENT_TYPE_VAL)); 1.52 +static const jlong CLASS_PREPARE_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_PREPARE - TOTAL_MIN_EVENT_TYPE_VAL)); 1.53 +static const jlong THREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL)); 1.54 +static const jlong THREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL)); 1.55 +static const jlong EXCEPTION_THROW_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION - TOTAL_MIN_EVENT_TYPE_VAL)); 1.56 +static const jlong EXCEPTION_CATCH_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION_CATCH - TOTAL_MIN_EVENT_TYPE_VAL)); 1.57 +static const jlong MONITOR_CONTENDED_ENTER_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTER - TOTAL_MIN_EVENT_TYPE_VAL)); 1.58 +static const jlong MONITOR_CONTENDED_ENTERED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED - TOTAL_MIN_EVENT_TYPE_VAL)); 1.59 +static const jlong MONITOR_WAIT_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAIT - TOTAL_MIN_EVENT_TYPE_VAL)); 1.60 +static const jlong MONITOR_WAITED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAITED - TOTAL_MIN_EVENT_TYPE_VAL)); 1.61 +static const jlong DYNAMIC_CODE_GENERATED_BIT = (((jlong)1) << (JVMTI_EVENT_DYNAMIC_CODE_GENERATED - TOTAL_MIN_EVENT_TYPE_VAL)); 1.62 +static const jlong DATA_DUMP_BIT = (((jlong)1) << (JVMTI_EVENT_DATA_DUMP_REQUEST - TOTAL_MIN_EVENT_TYPE_VAL)); 1.63 +static const jlong COMPILED_METHOD_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_LOAD - TOTAL_MIN_EVENT_TYPE_VAL)); 1.64 +static const jlong COMPILED_METHOD_UNLOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL)); 1.65 +static const jlong GARBAGE_COLLECTION_START_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_START - TOTAL_MIN_EVENT_TYPE_VAL)); 1.66 +static const jlong GARBAGE_COLLECTION_FINISH_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - TOTAL_MIN_EVENT_TYPE_VAL)); 1.67 +static const jlong OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE - TOTAL_MIN_EVENT_TYPE_VAL)); 1.68 +static const jlong RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL)); 1.69 +static const jlong VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL)); 1.70 + 1.71 +// bits for extension events 1.72 +static const jlong CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL)); 1.73 + 1.74 + 1.75 +static const jlong MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT | 1.76 + MONITOR_WAIT_BIT | MONITOR_WAITED_BIT; 1.77 +static const jlong EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT; 1.78 +static const jlong INTERP_EVENT_BITS = SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT | 1.79 + FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT; 1.80 +static const jlong THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS | 1.81 + BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT; 1.82 +static const jlong NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT; 1.83 +static const jlong EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | 1.84 + VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT | 1.85 + THREAD_START_BIT | THREAD_END_BIT | 1.86 + DYNAMIC_CODE_GENERATED_BIT; 1.87 +static const jlong GLOBAL_EVENT_BITS = ~THREAD_FILTERED_EVENT_BITS; 1.88 + 1.89 + 1.90 +/////////////////////////////////////////////////////////////// 1.91 +// 1.92 +// JvmtiEventEnabled 1.93 +// 1.94 + 1.95 +JvmtiEventEnabled::JvmtiEventEnabled() { 1.96 + clear(); 1.97 +} 1.98 + 1.99 + 1.100 +void JvmtiEventEnabled::clear() { 1.101 + _enabled_bits = 0; 1.102 +#ifndef PRODUCT 1.103 + _init_guard = JEE_INIT_GUARD; 1.104 +#endif 1.105 +} 1.106 + 1.107 +void JvmtiEventEnabled::set_enabled(jvmtiEvent event_type, bool enabled) { 1.108 + jlong bits = get_bits(); 1.109 + jlong mask = bit_for(event_type); 1.110 + if (enabled) { 1.111 + bits |= mask; 1.112 + } else { 1.113 + bits &= ~mask; 1.114 + } 1.115 + set_bits(bits); 1.116 +} 1.117 + 1.118 + 1.119 +/////////////////////////////////////////////////////////////// 1.120 +// 1.121 +// JvmtiEnvThreadEventEnable 1.122 +// 1.123 + 1.124 +JvmtiEnvThreadEventEnable::JvmtiEnvThreadEventEnable() { 1.125 + _event_user_enabled.clear(); 1.126 + _event_enabled.clear(); 1.127 +} 1.128 + 1.129 + 1.130 +JvmtiEnvThreadEventEnable::~JvmtiEnvThreadEventEnable() { 1.131 + _event_user_enabled.clear(); 1.132 + _event_enabled.clear(); 1.133 +} 1.134 + 1.135 + 1.136 +/////////////////////////////////////////////////////////////// 1.137 +// 1.138 +// JvmtiThreadEventEnable 1.139 +// 1.140 + 1.141 +JvmtiThreadEventEnable::JvmtiThreadEventEnable() { 1.142 + _event_enabled.clear(); 1.143 +} 1.144 + 1.145 + 1.146 +JvmtiThreadEventEnable::~JvmtiThreadEventEnable() { 1.147 + _event_enabled.clear(); 1.148 +} 1.149 + 1.150 + 1.151 +/////////////////////////////////////////////////////////////// 1.152 +// 1.153 +// JvmtiEnvEventEnable 1.154 +// 1.155 + 1.156 +JvmtiEnvEventEnable::JvmtiEnvEventEnable() { 1.157 + _event_user_enabled.clear(); 1.158 + _event_callback_enabled.clear(); 1.159 + _event_enabled.clear(); 1.160 +} 1.161 + 1.162 + 1.163 +JvmtiEnvEventEnable::~JvmtiEnvEventEnable() { 1.164 + _event_user_enabled.clear(); 1.165 + _event_callback_enabled.clear(); 1.166 + _event_enabled.clear(); 1.167 +} 1.168 + 1.169 + 1.170 +/////////////////////////////////////////////////////////////// 1.171 +// 1.172 +// VM_EnterInterpOnlyMode 1.173 +// 1.174 + 1.175 +class VM_EnterInterpOnlyMode : public VM_Operation { 1.176 +private: 1.177 + JvmtiThreadState *_state; 1.178 + 1.179 +public: 1.180 + VM_EnterInterpOnlyMode(JvmtiThreadState *state); 1.181 + 1.182 + bool allow_nested_vm_operations() const { return true; } 1.183 + VMOp_Type type() const { return VMOp_EnterInterpOnlyMode; } 1.184 + void doit(); 1.185 + 1.186 + // to do: this same function is in jvmtiImpl - should be in one place 1.187 + bool can_be_deoptimized(vframe* vf) { 1.188 + return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized()); 1.189 + } 1.190 +}; 1.191 + 1.192 +VM_EnterInterpOnlyMode::VM_EnterInterpOnlyMode(JvmtiThreadState *state) 1.193 + : _state(state) 1.194 +{ 1.195 +} 1.196 + 1.197 + 1.198 +void VM_EnterInterpOnlyMode::doit() { 1.199 + // Set up the current stack depth for later tracking 1.200 + _state->invalidate_cur_stack_depth(); 1.201 + 1.202 + _state->enter_interp_only_mode(); 1.203 + 1.204 + JavaThread *thread = _state->get_thread(); 1.205 + if (thread->has_last_Java_frame()) { 1.206 + // If running in fullspeed mode, single stepping is implemented 1.207 + // as follows: first, the interpreter does not dispatch to 1.208 + // compiled code for threads that have single stepping enabled; 1.209 + // second, we deoptimize all methods on the thread's stack when 1.210 + // interpreted-only mode is enabled the first time for a given 1.211 + // thread (nothing to do if no Java frames yet). 1.212 + int num_marked = 0; 1.213 + ResourceMark resMark; 1.214 + RegisterMap rm(thread, false); 1.215 + for (vframe* vf = thread->last_java_vframe(&rm); vf; vf = vf->sender()) { 1.216 + if (can_be_deoptimized(vf)) { 1.217 + ((compiledVFrame*) vf)->code()->mark_for_deoptimization(); 1.218 + ++num_marked; 1.219 + } 1.220 + } 1.221 + if (num_marked > 0) { 1.222 + VM_Deoptimize op; 1.223 + VMThread::execute(&op); 1.224 + } 1.225 + } 1.226 +} 1.227 + 1.228 + 1.229 +/////////////////////////////////////////////////////////////// 1.230 +// 1.231 +// VM_ChangeSingleStep 1.232 +// 1.233 + 1.234 +class VM_ChangeSingleStep : public VM_Operation { 1.235 +private: 1.236 + bool _on; 1.237 + 1.238 +public: 1.239 + VM_ChangeSingleStep(bool on); 1.240 + VMOp_Type type() const { return VMOp_ChangeSingleStep; } 1.241 + bool allow_nested_vm_operations() const { return true; } 1.242 + void doit(); // method definition is after definition of JvmtiEventControllerPrivate because of scoping 1.243 +}; 1.244 + 1.245 + 1.246 +VM_ChangeSingleStep::VM_ChangeSingleStep(bool on) 1.247 + : _on(on != 0) 1.248 +{ 1.249 +} 1.250 + 1.251 + 1.252 + 1.253 + 1.254 +/////////////////////////////////////////////////////////////// 1.255 +// 1.256 +// JvmtiEventControllerPrivate 1.257 +// 1.258 +// Private internal implementation methods for JvmtiEventController. 1.259 +// 1.260 +// These methods are thread safe either because they are called 1.261 +// in early VM initialization which is single threaded, or they 1.262 +// hold the JvmtiThreadState_lock. 1.263 +// 1.264 + 1.265 +class JvmtiEventControllerPrivate : public AllStatic { 1.266 + static bool _initialized; 1.267 +public: 1.268 + static void set_should_post_single_step(bool on); 1.269 + static void enter_interp_only_mode(JvmtiThreadState *state); 1.270 + static void leave_interp_only_mode(JvmtiThreadState *state); 1.271 + static void recompute_enabled(); 1.272 + static jlong recompute_env_enabled(JvmtiEnvBase* env); 1.273 + static jlong recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state); 1.274 + static jlong recompute_thread_enabled(JvmtiThreadState *state); 1.275 + static void event_init(); 1.276 + 1.277 + static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, 1.278 + jvmtiEvent event_type, bool enabled); 1.279 + static void set_event_callbacks(JvmtiEnvBase *env, 1.280 + const jvmtiEventCallbacks* callbacks, 1.281 + jint size_of_callbacks); 1.282 + 1.283 + static void set_extension_event_callback(JvmtiEnvBase *env, 1.284 + jint extension_event_index, 1.285 + jvmtiExtensionEvent callback); 1.286 + 1.287 + static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.288 + static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.289 + static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); 1.290 + static void change_field_watch(jvmtiEvent event_type, bool added); 1.291 + 1.292 + static void thread_started(JavaThread *thread); 1.293 + static void thread_ended(JavaThread *thread); 1.294 + 1.295 + static void env_initialize(JvmtiEnvBase *env); 1.296 + static void env_dispose(JvmtiEnvBase *env); 1.297 + 1.298 + static void vm_start(); 1.299 + static void vm_init(); 1.300 + static void vm_death(); 1.301 + 1.302 + static void trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed); 1.303 + static void trace_changed(jlong now_enabled, jlong changed); 1.304 +}; 1.305 + 1.306 +bool JvmtiEventControllerPrivate::_initialized = false; 1.307 + 1.308 +void JvmtiEventControllerPrivate::set_should_post_single_step(bool on) { 1.309 + // we have permission to do this, VM op doesn't 1.310 + JvmtiExport::set_should_post_single_step(on); 1.311 +} 1.312 + 1.313 + 1.314 +// This change must always be occur when at a safepoint. 1.315 +// Being at a safepoint causes the interpreter to use the 1.316 +// safepoint dispatch table which we overload to find single 1.317 +// step points. Just to be sure that it has been set, we 1.318 +// call notice_safepoints when turning on single stepping. 1.319 +// When we leave our current safepoint, should_post_single_step 1.320 +// will be checked by the interpreter, and the table kept 1.321 +// or changed accordingly. 1.322 +void VM_ChangeSingleStep::doit() { 1.323 + JvmtiEventControllerPrivate::set_should_post_single_step(_on); 1.324 + if (_on) { 1.325 + Interpreter::notice_safepoints(); 1.326 + } 1.327 +} 1.328 + 1.329 + 1.330 +void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) { 1.331 + EC_TRACE(("JVMTI [%s] # Entering interpreter only mode", 1.332 + JvmtiTrace::safe_get_thread_name(state->get_thread()))); 1.333 + 1.334 + VM_EnterInterpOnlyMode op(state); 1.335 + VMThread::execute(&op); 1.336 +} 1.337 + 1.338 + 1.339 +void 1.340 +JvmtiEventControllerPrivate::leave_interp_only_mode(JvmtiThreadState *state) { 1.341 + EC_TRACE(("JVMTI [%s] # Leaving interpreter only mode", 1.342 + JvmtiTrace::safe_get_thread_name(state->get_thread()))); 1.343 + state->leave_interp_only_mode(); 1.344 +} 1.345 + 1.346 + 1.347 +void 1.348 +JvmtiEventControllerPrivate::trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed) { 1.349 +#ifdef JVMTI_TRACE 1.350 + if (JvmtiTrace::trace_event_controller()) { 1.351 + SafeResourceMark rm; 1.352 + // traces standard events only 1.353 + for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { 1.354 + jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); 1.355 + if (changed & bit) { 1.356 + // it changed, print it 1.357 + tty->print_cr("JVMTI [%s] # %s event %s", 1.358 + JvmtiTrace::safe_get_thread_name(state->get_thread()), 1.359 + (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei)); 1.360 + } 1.361 + } 1.362 + } 1.363 +#endif /*JVMTI_TRACE */ 1.364 +} 1.365 + 1.366 + 1.367 +void 1.368 +JvmtiEventControllerPrivate::trace_changed(jlong now_enabled, jlong changed) { 1.369 +#ifdef JVMTI_TRACE 1.370 + if (JvmtiTrace::trace_event_controller()) { 1.371 + SafeResourceMark rm; 1.372 + // traces standard events only 1.373 + for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { 1.374 + jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); 1.375 + if (changed & bit) { 1.376 + // it changed, print it 1.377 + tty->print_cr("JVMTI [-] # %s event %s", 1.378 + (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei)); 1.379 + } 1.380 + } 1.381 + } 1.382 +#endif /*JVMTI_TRACE */ 1.383 +} 1.384 + 1.385 + 1.386 +// For the specified env: compute the currently truly enabled events 1.387 +// set external state accordingly. 1.388 +// Return value and set value must include all events. 1.389 +// But outside this class, only non-thread-filtered events can be queried.. 1.390 +jlong 1.391 +JvmtiEventControllerPrivate::recompute_env_enabled(JvmtiEnvBase* env) { 1.392 + jlong was_enabled = env->env_event_enable()->_event_enabled.get_bits(); 1.393 + jlong now_enabled = 1.394 + env->env_event_enable()->_event_callback_enabled.get_bits() & 1.395 + env->env_event_enable()->_event_user_enabled.get_bits(); 1.396 + 1.397 + switch (JvmtiEnv::get_phase()) { 1.398 + case JVMTI_PHASE_PRIMORDIAL: 1.399 + case JVMTI_PHASE_ONLOAD: 1.400 + // only these events allowed in primordial or onload phase 1.401 + now_enabled &= (EARLY_EVENT_BITS & ~THREAD_FILTERED_EVENT_BITS); 1.402 + break; 1.403 + case JVMTI_PHASE_START: 1.404 + // only these events allowed in start phase 1.405 + now_enabled &= EARLY_EVENT_BITS; 1.406 + break; 1.407 + case JVMTI_PHASE_LIVE: 1.408 + // all events allowed during live phase 1.409 + break; 1.410 + case JVMTI_PHASE_DEAD: 1.411 + // no events allowed when dead 1.412 + now_enabled = 0; 1.413 + break; 1.414 + default: 1.415 + assert(false, "no other phases - sanity check"); 1.416 + break; 1.417 + } 1.418 + 1.419 + // will we really send these events to this env 1.420 + env->env_event_enable()->_event_enabled.set_bits(now_enabled); 1.421 + 1.422 + trace_changed(now_enabled, (now_enabled ^ was_enabled) & ~THREAD_FILTERED_EVENT_BITS); 1.423 + 1.424 + return now_enabled; 1.425 +} 1.426 + 1.427 + 1.428 +// For the specified env and thread: compute the currently truly enabled events 1.429 +// set external state accordingly. Only thread-filtered events are included. 1.430 +jlong 1.431 +JvmtiEventControllerPrivate::recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state) { 1.432 + JvmtiEnv *env = ets->get_env(); 1.433 + 1.434 + jlong was_enabled = ets->event_enable()->_event_enabled.get_bits(); 1.435 + jlong now_enabled = THREAD_FILTERED_EVENT_BITS & 1.436 + env->env_event_enable()->_event_callback_enabled.get_bits() & 1.437 + (env->env_event_enable()->_event_user_enabled.get_bits() | 1.438 + ets->event_enable()->_event_user_enabled.get_bits()); 1.439 + 1.440 + // for frame pops and field watchs, computed enabled state 1.441 + // is only true if an event has been requested 1.442 + if (!ets->has_frame_pops()) { 1.443 + now_enabled &= ~FRAME_POP_BIT; 1.444 + } 1.445 + if (*((int *)JvmtiExport::get_field_access_count_addr()) == 0) { 1.446 + now_enabled &= ~FIELD_ACCESS_BIT; 1.447 + } 1.448 + if (*((int *)JvmtiExport::get_field_modification_count_addr()) == 0) { 1.449 + now_enabled &= ~FIELD_MODIFICATION_BIT; 1.450 + } 1.451 + 1.452 + switch (JvmtiEnv::get_phase()) { 1.453 + case JVMTI_PHASE_DEAD: 1.454 + // no events allowed when dead 1.455 + now_enabled = 0; 1.456 + break; 1.457 + } 1.458 + 1.459 + // if anything changed do update 1.460 + if (now_enabled != was_enabled) { 1.461 + 1.462 + // will we really send these events to this thread x env 1.463 + ets->event_enable()->_event_enabled.set_bits(now_enabled); 1.464 + 1.465 + // If the enabled status of the single step or breakpoint events changed, 1.466 + // the location status may need to change as well. 1.467 + jlong changed = now_enabled ^ was_enabled; 1.468 + if (changed & SINGLE_STEP_BIT) { 1.469 + ets->reset_current_location(JVMTI_EVENT_SINGLE_STEP, (now_enabled & SINGLE_STEP_BIT) != 0); 1.470 + } 1.471 + if (changed & BREAKPOINT_BIT) { 1.472 + ets->reset_current_location(JVMTI_EVENT_BREAKPOINT, (now_enabled & BREAKPOINT_BIT) != 0); 1.473 + } 1.474 + trace_changed(state, now_enabled, changed); 1.475 + } 1.476 + return now_enabled; 1.477 +} 1.478 + 1.479 + 1.480 +// For the specified thread: compute the currently truly enabled events 1.481 +// set external state accordingly. Only thread-filtered events are included. 1.482 +jlong 1.483 +JvmtiEventControllerPrivate::recompute_thread_enabled(JvmtiThreadState *state) { 1.484 + jlong was_any_env_enabled = state->thread_event_enable()->_event_enabled.get_bits(); 1.485 + jlong any_env_enabled = 0; 1.486 + 1.487 + { 1.488 + // This iteration will include JvmtiEnvThreadStates whoses environments 1.489 + // have been disposed. These JvmtiEnvThreadStates must not be filtered 1.490 + // as recompute must be called on them to disable their events, 1.491 + JvmtiEnvThreadStateIterator it(state); 1.492 + for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { 1.493 + any_env_enabled |= recompute_env_thread_enabled(ets, state); 1.494 + } 1.495 + } 1.496 + 1.497 + if (any_env_enabled != was_any_env_enabled) { 1.498 + // mark if event is truly enabled on this thread in any environment 1.499 + state->thread_event_enable()->_event_enabled.set_bits(any_env_enabled); 1.500 + 1.501 + // compute interp_only mode 1.502 + bool should_be_interp = (any_env_enabled & INTERP_EVENT_BITS) != 0; 1.503 + bool is_now_interp = state->is_interp_only_mode(); 1.504 + 1.505 + if (should_be_interp != is_now_interp) { 1.506 + if (should_be_interp) { 1.507 + enter_interp_only_mode(state); 1.508 + } else { 1.509 + leave_interp_only_mode(state); 1.510 + } 1.511 + } 1.512 + } 1.513 + return any_env_enabled; 1.514 +} 1.515 + 1.516 + 1.517 +// Compute truly enabled events - meaning if the event can and could be 1.518 +// sent. An event is truly enabled if it is user enabled on the thread 1.519 +// or globally user enabled, but only if there is a callback or event hook 1.520 +// for it and, for field watch and frame pop, one has been set. 1.521 +// Compute if truly enabled, per thread, per environment, per combination 1.522 +// (thread x environment), and overall. These merges are true if any is true. 1.523 +// True per thread if some environment has callback set and the event is globally 1.524 +// enabled or enabled for this thread. 1.525 +// True per environment if the callback is set and the event is globally 1.526 +// enabled in this environment or enabled for any thread in this environment. 1.527 +// True per combination if the environment has the callback set and the 1.528 +// event is globally enabled in this environment or the event is enabled 1.529 +// for this thread and environment. 1.530 +// 1.531 +// All states transitions dependent on these transitions are also handled here. 1.532 +void 1.533 +JvmtiEventControllerPrivate::recompute_enabled() { 1.534 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.535 + 1.536 + // event enabled for any thread in any environment 1.537 + jlong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits(); 1.538 + jlong any_env_thread_enabled = 0; 1.539 + 1.540 + EC_TRACE(("JVMTI [-] # recompute enabled - before %llx", was_any_env_thread_enabled)); 1.541 + 1.542 + // compute non-thread-filters events. 1.543 + // This must be done separately from thread-filtered events, since some 1.544 + // events can occur before any threads exist. 1.545 + JvmtiEnvIterator it; 1.546 + for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) { 1.547 + any_env_thread_enabled |= recompute_env_enabled(env); 1.548 + } 1.549 + 1.550 + // We need to create any missing jvmti_thread_state if there are globally set thread 1.551 + // filtered events and there weren't last time 1.552 + if ( (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 && 1.553 + (was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) { 1.554 + assert(JvmtiEnv::is_vm_live() || (JvmtiEnv::get_phase()==JVMTI_PHASE_START), 1.555 + "thread filtered events should not be enabled when VM not in start or live phase"); 1.556 + { 1.557 + MutexLocker mu(Threads_lock); //hold the Threads_lock for the iteration 1.558 + for (JavaThread *tp = Threads::first(); tp != NULL; tp = tp->next()) { 1.559 + JvmtiThreadState::state_for_while_locked(tp); // create the thread state if missing 1.560 + } 1.561 + }// release Threads_lock 1.562 + } 1.563 + 1.564 + // compute and set thread-filtered events 1.565 + for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { 1.566 + any_env_thread_enabled |= recompute_thread_enabled(state); 1.567 + } 1.568 + 1.569 + // set universal state (across all envs and threads) 1.570 + jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled; 1.571 + if (delta != 0) { 1.572 + JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0); 1.573 + JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0); 1.574 + JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0); 1.575 + JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0); 1.576 + JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0); 1.577 + JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0); 1.578 + JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0); 1.579 + JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0); 1.580 + JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0); 1.581 + JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0); 1.582 + JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0); 1.583 + JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0); 1.584 + JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0); 1.585 + JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0); 1.586 + JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0); 1.587 + JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0); 1.588 + JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0); 1.589 + JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0); 1.590 + JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0); 1.591 + JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0); 1.592 + 1.593 + // need this if we want thread events or we need them to init data 1.594 + JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0); 1.595 + 1.596 + // If single stepping is turned on or off, execute the VM op to change it. 1.597 + if (delta & SINGLE_STEP_BIT) { 1.598 + switch (JvmtiEnv::get_phase()) { 1.599 + case JVMTI_PHASE_DEAD: 1.600 + // If the VM is dying we can't execute VM ops 1.601 + break; 1.602 + case JVMTI_PHASE_LIVE: { 1.603 + VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0); 1.604 + VMThread::execute(&op); 1.605 + break; 1.606 + } 1.607 + default: 1.608 + assert(false, "should never come here before live phase"); 1.609 + break; 1.610 + } 1.611 + } 1.612 + 1.613 + // set global truly enabled, that is, any thread in any environment 1.614 + JvmtiEventController::_universal_global_event_enabled.set_bits(any_env_thread_enabled); 1.615 + } 1.616 + 1.617 + EC_TRACE(("JVMTI [-] # recompute enabled - after %llx", any_env_thread_enabled)); 1.618 +} 1.619 + 1.620 + 1.621 +void 1.622 +JvmtiEventControllerPrivate::thread_started(JavaThread *thread) { 1.623 + assert(thread->is_Java_thread(), "Must be JavaThread"); 1.624 + assert(thread == Thread::current(), "must be current thread"); 1.625 + assert(JvmtiEnvBase::environments_might_exist(), "to enter event controller, JVM TI environments must exist"); 1.626 + 1.627 + EC_TRACE(("JVMTI [%s] # thread started", JvmtiTrace::safe_get_thread_name(thread))); 1.628 + 1.629 + // if we have any thread filtered events globally enabled, create/update the thread state 1.630 + if ((JvmtiEventController::_universal_global_event_enabled.get_bits() & THREAD_FILTERED_EVENT_BITS) != 0) { 1.631 + MutexLocker mu(JvmtiThreadState_lock); 1.632 + // create the thread state if missing 1.633 + JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); 1.634 + if (state != NULL) { // skip threads with no JVMTI thread state 1.635 + recompute_thread_enabled(state); 1.636 + } 1.637 + } 1.638 +} 1.639 + 1.640 + 1.641 +void 1.642 +JvmtiEventControllerPrivate::thread_ended(JavaThread *thread) { 1.643 + // Removes the JvmtiThreadState associated with the specified thread. 1.644 + // May be called after all environments have been disposed. 1.645 + 1.646 + EC_TRACE(("JVMTI [%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread))); 1.647 + 1.648 + JvmtiThreadState *state = thread->jvmti_thread_state(); 1.649 + if (state != NULL) { 1.650 + MutexLocker mu(JvmtiThreadState_lock); 1.651 + delete state; 1.652 + } 1.653 +} 1.654 + 1.655 +void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env, 1.656 + const jvmtiEventCallbacks* callbacks, 1.657 + jint size_of_callbacks) { 1.658 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.659 + EC_TRACE(("JVMTI [*] # set event callbacks")); 1.660 + 1.661 + env->set_event_callbacks(callbacks, size_of_callbacks); 1.662 + jlong enabled_bits = 0; 1.663 + for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { 1.664 + jvmtiEvent evt_t = (jvmtiEvent)ei; 1.665 + if (env->has_callback(evt_t)) { 1.666 + enabled_bits |= JvmtiEventEnabled::bit_for(evt_t); 1.667 + } 1.668 + } 1.669 + env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); 1.670 + recompute_enabled(); 1.671 +} 1.672 + 1.673 +void 1.674 +JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env, 1.675 + jint extension_event_index, 1.676 + jvmtiExtensionEvent callback) 1.677 +{ 1.678 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.679 + EC_TRACE(("JVMTI [*] # set extension event callback")); 1.680 + 1.681 + // extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL 1.682 + assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL && 1.683 + extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check"); 1.684 + 1.685 + 1.686 + // As the bits for both standard (jvmtiEvent) and extension 1.687 + // (jvmtiExtEvents) are stored in the same word we cast here to 1.688 + // jvmtiEvent to set/clear the bit for this extension event. 1.689 + jvmtiEvent event_type = (jvmtiEvent)extension_event_index; 1.690 + 1.691 + // Prevent a possible race condition where events are re-enabled by a call to 1.692 + // set event callbacks, where the DisposeEnvironment occurs after the boiler-plate 1.693 + // environment check and before the lock is acquired. 1.694 + // We can safely do the is_valid check now, as JvmtiThreadState_lock is held. 1.695 + bool enabling = (callback != NULL) && (env->is_valid()); 1.696 + env->env_event_enable()->set_user_enabled(event_type, enabling); 1.697 + 1.698 + // update the callback 1.699 + jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks(); 1.700 + switch (extension_event_index) { 1.701 + case EXT_EVENT_CLASS_UNLOAD : 1.702 + ext_callbacks->ClassUnload = callback; 1.703 + break; 1.704 + default: 1.705 + ShouldNotReachHere(); 1.706 + } 1.707 + 1.708 + // update the callback enable/disable bit 1.709 + jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits(); 1.710 + jlong bit_for = JvmtiEventEnabled::bit_for(event_type); 1.711 + if (enabling) { 1.712 + enabled_bits |= bit_for; 1.713 + } else { 1.714 + enabled_bits &= ~bit_for; 1.715 + } 1.716 + env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits); 1.717 + 1.718 + recompute_enabled(); 1.719 +} 1.720 + 1.721 + 1.722 +void 1.723 +JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) { 1.724 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.725 + EC_TRACE(("JVMTI [*] # env initialize")); 1.726 + 1.727 + if (JvmtiEnvBase::is_vm_live()) { 1.728 + // if we didn't initialize event info already (this is a late 1.729 + // launched environment), do it now. 1.730 + event_init(); 1.731 + } 1.732 + 1.733 + env->initialize(); 1.734 + 1.735 + // add the JvmtiEnvThreadState to each JvmtiThreadState 1.736 + for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) { 1.737 + state->add_env(env); 1.738 + assert((JvmtiEnv*)(state->env_thread_state(env)->get_env()) == env, "sanity check"); 1.739 + } 1.740 + JvmtiEventControllerPrivate::recompute_enabled(); 1.741 +} 1.742 + 1.743 + 1.744 +void 1.745 +JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) { 1.746 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.747 + EC_TRACE(("JVMTI [*] # env dispose")); 1.748 + 1.749 + // Before the environment is marked disposed, disable all events on this 1.750 + // environment (by zapping the callbacks). As a result, the disposed 1.751 + // environment will not call event handlers. 1.752 + set_event_callbacks(env, NULL, 0); 1.753 + for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL; 1.754 + extension_event_index <= EXT_MAX_EVENT_TYPE_VAL; 1.755 + ++extension_event_index) { 1.756 + set_extension_event_callback(env, extension_event_index, NULL); 1.757 + } 1.758 + 1.759 + // Let the environment finish disposing itself. 1.760 + env->env_dispose(); 1.761 +} 1.762 + 1.763 + 1.764 +void 1.765 +JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, 1.766 + jvmtiEvent event_type, bool enabled) { 1.767 + assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check"); 1.768 + 1.769 + EC_TRACE(("JVMTI [%s] # user %s event %s", 1.770 + thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread), 1.771 + enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type))); 1.772 + 1.773 + if (thread == NULL) { 1.774 + env->env_event_enable()->set_user_enabled(event_type, enabled); 1.775 + } else { 1.776 + // create the thread state (if it didn't exist before) 1.777 + JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread); 1.778 + if (state != NULL) { 1.779 + state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled); 1.780 + } 1.781 + } 1.782 + recompute_enabled(); 1.783 +} 1.784 + 1.785 + 1.786 +void 1.787 +JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.788 + EC_TRACE(("JVMTI [%s] # set frame pop - frame=%d", 1.789 + JvmtiTrace::safe_get_thread_name(ets->get_thread()), 1.790 + fpop.frame_number() )); 1.791 + 1.792 + ets->get_frame_pops()->set(fpop); 1.793 + recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); 1.794 +} 1.795 + 1.796 + 1.797 +void 1.798 +JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.799 + EC_TRACE(("JVMTI [%s] # clear frame pop - frame=%d", 1.800 + JvmtiTrace::safe_get_thread_name(ets->get_thread()), 1.801 + fpop.frame_number() )); 1.802 + 1.803 + ets->get_frame_pops()->clear(fpop); 1.804 + recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); 1.805 +} 1.806 + 1.807 + 1.808 +void 1.809 +JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.810 + int cleared_cnt = ets->get_frame_pops()->clear_to(fpop); 1.811 + 1.812 + EC_TRACE(("JVMTI [%s] # clear to frame pop - frame=%d, count=%d", 1.813 + JvmtiTrace::safe_get_thread_name(ets->get_thread()), 1.814 + fpop.frame_number(), 1.815 + cleared_cnt )); 1.816 + 1.817 + if (cleared_cnt > 0) { 1.818 + recompute_thread_enabled(ets->get_thread()->jvmti_thread_state()); 1.819 + } 1.820 +} 1.821 + 1.822 +void 1.823 +JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) { 1.824 + int *count_addr; 1.825 + 1.826 + switch (event_type) { 1.827 + case JVMTI_EVENT_FIELD_MODIFICATION: 1.828 + count_addr = (int *)JvmtiExport::get_field_modification_count_addr(); 1.829 + break; 1.830 + case JVMTI_EVENT_FIELD_ACCESS: 1.831 + count_addr = (int *)JvmtiExport::get_field_access_count_addr(); 1.832 + break; 1.833 + default: 1.834 + assert(false, "incorrect event"); 1.835 + return; 1.836 + } 1.837 + 1.838 + EC_TRACE(("JVMTI [-] # change field watch - %s %s count=%d", 1.839 + event_type==JVMTI_EVENT_FIELD_MODIFICATION? "modification" : "access", 1.840 + added? "add" : "remove", 1.841 + *count_addr)); 1.842 + 1.843 + if (added) { 1.844 + (*count_addr)++; 1.845 + if (*count_addr == 1) { 1.846 + recompute_enabled(); 1.847 + } 1.848 + } else { 1.849 + if (*count_addr > 0) { 1.850 + (*count_addr)--; 1.851 + if (*count_addr == 0) { 1.852 + recompute_enabled(); 1.853 + } 1.854 + } else { 1.855 + assert(false, "field watch out of phase"); 1.856 + } 1.857 + } 1.858 +} 1.859 + 1.860 +void 1.861 +JvmtiEventControllerPrivate::event_init() { 1.862 + assert(JvmtiThreadState_lock->is_locked(), "sanity check"); 1.863 + 1.864 + if (_initialized) { 1.865 + return; 1.866 + } 1.867 + 1.868 + EC_TRACE(("JVMTI [-] # VM live")); 1.869 + 1.870 +#ifdef ASSERT 1.871 + // check that our idea and the spec's idea of threaded events match 1.872 + for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) { 1.873 + jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei); 1.874 + assert(((THREAD_FILTERED_EVENT_BITS & bit) != 0) == JvmtiUtil::event_threaded(ei), 1.875 + "thread filtered event list does not match"); 1.876 + } 1.877 +#endif 1.878 + 1.879 + _initialized = true; 1.880 +} 1.881 + 1.882 +void 1.883 +JvmtiEventControllerPrivate::vm_start() { 1.884 + // some events are now able to be enabled (phase has changed) 1.885 + JvmtiEventControllerPrivate::recompute_enabled(); 1.886 +} 1.887 + 1.888 + 1.889 +void 1.890 +JvmtiEventControllerPrivate::vm_init() { 1.891 + event_init(); 1.892 + 1.893 + // all the events are now able to be enabled (phase has changed) 1.894 + JvmtiEventControllerPrivate::recompute_enabled(); 1.895 +} 1.896 + 1.897 + 1.898 +void 1.899 +JvmtiEventControllerPrivate::vm_death() { 1.900 + // events are disabled (phase has changed) 1.901 + JvmtiEventControllerPrivate::recompute_enabled(); 1.902 +} 1.903 + 1.904 + 1.905 +/////////////////////////////////////////////////////////////// 1.906 +// 1.907 +// JvmtiEventController 1.908 +// 1.909 + 1.910 +JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled; 1.911 + 1.912 +bool 1.913 +JvmtiEventController::is_global_event(jvmtiEvent event_type) { 1.914 + assert(is_valid_event_type(event_type), "invalid event type"); 1.915 + jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL); 1.916 + return((bit_for & GLOBAL_EVENT_BITS)!=0); 1.917 +} 1.918 + 1.919 +void 1.920 +JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, jvmtiEvent event_type, bool enabled) { 1.921 + if (Threads::number_of_threads() == 0) { 1.922 + // during early VM start-up locks don't exist, but we are safely single threaded, 1.923 + // call the functionality without holding the JvmtiThreadState_lock. 1.924 + JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); 1.925 + } else { 1.926 + MutexLocker mu(JvmtiThreadState_lock); 1.927 + JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled); 1.928 + } 1.929 +} 1.930 + 1.931 + 1.932 +void 1.933 +JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env, 1.934 + const jvmtiEventCallbacks* callbacks, 1.935 + jint size_of_callbacks) { 1.936 + if (Threads::number_of_threads() == 0) { 1.937 + // during early VM start-up locks don't exist, but we are safely single threaded, 1.938 + // call the functionality without holding the JvmtiThreadState_lock. 1.939 + JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); 1.940 + } else { 1.941 + MutexLocker mu(JvmtiThreadState_lock); 1.942 + JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks); 1.943 + } 1.944 +} 1.945 + 1.946 +void 1.947 +JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env, 1.948 + jint extension_event_index, 1.949 + jvmtiExtensionEvent callback) { 1.950 + if (Threads::number_of_threads() == 0) { 1.951 + JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); 1.952 + } else { 1.953 + MutexLocker mu(JvmtiThreadState_lock); 1.954 + JvmtiEventControllerPrivate::set_extension_event_callback(env, extension_event_index, callback); 1.955 + } 1.956 +} 1.957 + 1.958 + 1.959 + 1.960 + 1.961 +void 1.962 +JvmtiEventController::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.963 + MutexLocker mu(JvmtiThreadState_lock); 1.964 + JvmtiEventControllerPrivate::set_frame_pop(ets, fpop); 1.965 +} 1.966 + 1.967 + 1.968 +void 1.969 +JvmtiEventController::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.970 + MutexLocker mu(JvmtiThreadState_lock); 1.971 + JvmtiEventControllerPrivate::clear_frame_pop(ets, fpop); 1.972 +} 1.973 + 1.974 + 1.975 +void 1.976 +JvmtiEventController::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) { 1.977 + MutexLocker mu(JvmtiThreadState_lock); 1.978 + JvmtiEventControllerPrivate::clear_to_frame_pop(ets, fpop); 1.979 +} 1.980 + 1.981 +void 1.982 +JvmtiEventController::change_field_watch(jvmtiEvent event_type, bool added) { 1.983 + MutexLocker mu(JvmtiThreadState_lock); 1.984 + JvmtiEventControllerPrivate::change_field_watch(event_type, added); 1.985 +} 1.986 + 1.987 +void 1.988 +JvmtiEventController::thread_started(JavaThread *thread) { 1.989 + // operates only on the current thread 1.990 + // JvmtiThreadState_lock grabbed only if needed. 1.991 + JvmtiEventControllerPrivate::thread_started(thread); 1.992 +} 1.993 + 1.994 +void 1.995 +JvmtiEventController::thread_ended(JavaThread *thread) { 1.996 + // operates only on the current thread 1.997 + // JvmtiThreadState_lock grabbed only if needed. 1.998 + JvmtiEventControllerPrivate::thread_ended(thread); 1.999 +} 1.1000 + 1.1001 +void 1.1002 +JvmtiEventController::env_initialize(JvmtiEnvBase *env) { 1.1003 + if (Threads::number_of_threads() == 0) { 1.1004 + // during early VM start-up locks don't exist, but we are safely single threaded, 1.1005 + // call the functionality without holding the JvmtiThreadState_lock. 1.1006 + JvmtiEventControllerPrivate::env_initialize(env); 1.1007 + } else { 1.1008 + MutexLocker mu(JvmtiThreadState_lock); 1.1009 + JvmtiEventControllerPrivate::env_initialize(env); 1.1010 + } 1.1011 +} 1.1012 + 1.1013 +void 1.1014 +JvmtiEventController::env_dispose(JvmtiEnvBase *env) { 1.1015 + if (Threads::number_of_threads() == 0) { 1.1016 + // during early VM start-up locks don't exist, but we are safely single threaded, 1.1017 + // call the functionality without holding the JvmtiThreadState_lock. 1.1018 + JvmtiEventControllerPrivate::env_dispose(env); 1.1019 + } else { 1.1020 + MutexLocker mu(JvmtiThreadState_lock); 1.1021 + JvmtiEventControllerPrivate::env_dispose(env); 1.1022 + } 1.1023 +} 1.1024 + 1.1025 + 1.1026 +void 1.1027 +JvmtiEventController::vm_start() { 1.1028 + if (JvmtiEnvBase::environments_might_exist()) { 1.1029 + MutexLocker mu(JvmtiThreadState_lock); 1.1030 + JvmtiEventControllerPrivate::vm_start(); 1.1031 + } 1.1032 +} 1.1033 + 1.1034 +void 1.1035 +JvmtiEventController::vm_init() { 1.1036 + if (JvmtiEnvBase::environments_might_exist()) { 1.1037 + MutexLocker mu(JvmtiThreadState_lock); 1.1038 + JvmtiEventControllerPrivate::vm_init(); 1.1039 + } 1.1040 +} 1.1041 + 1.1042 +void 1.1043 +JvmtiEventController::vm_death() { 1.1044 + if (JvmtiEnvBase::environments_might_exist()) { 1.1045 + MutexLocker mu(JvmtiThreadState_lock); 1.1046 + JvmtiEventControllerPrivate::vm_death(); 1.1047 + } 1.1048 +}