< prev index next >

src/hotspot/share/prims/jvmtiEventController.cpp

Print this page

   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 #include "precompiled.hpp"

  26 #include "interpreter/interpreter.hpp"
  27 #include "jvmtifiles/jvmtiEnv.hpp"
  28 #include "logging/log.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "prims/jvmtiEventController.hpp"
  31 #include "prims/jvmtiEventController.inline.hpp"
  32 #include "prims/jvmtiExport.hpp"
  33 #include "prims/jvmtiImpl.hpp"
  34 #include "prims/jvmtiTagMap.hpp"
  35 #include "prims/jvmtiThreadState.inline.hpp"
  36 #include "runtime/deoptimization.hpp"
  37 #include "runtime/frame.inline.hpp"
  38 #include "runtime/stackFrameStream.inline.hpp"
  39 #include "runtime/thread.inline.hpp"
  40 #include "runtime/threadSMR.hpp"
  41 #include "runtime/vframe.hpp"
  42 #include "runtime/vframe_hp.hpp"
  43 #include "runtime/vmThread.hpp"
  44 #include "runtime/vmOperations.hpp"
  45 

  71 static const jlong  CLASS_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  72 static const jlong  CLASS_PREPARE_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_PREPARE - TOTAL_MIN_EVENT_TYPE_VAL));
  73 static const jlong  THREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL));
  74 static const jlong  THREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL));
  75 static const jlong  EXCEPTION_THROW_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION - TOTAL_MIN_EVENT_TYPE_VAL));
  76 static const jlong  EXCEPTION_CATCH_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION_CATCH - TOTAL_MIN_EVENT_TYPE_VAL));
  77 static const jlong  MONITOR_CONTENDED_ENTER_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTER - TOTAL_MIN_EVENT_TYPE_VAL));
  78 static const jlong  MONITOR_CONTENDED_ENTERED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED - TOTAL_MIN_EVENT_TYPE_VAL));
  79 static const jlong  MONITOR_WAIT_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAIT - TOTAL_MIN_EVENT_TYPE_VAL));
  80 static const jlong  MONITOR_WAITED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAITED - TOTAL_MIN_EVENT_TYPE_VAL));
  81 static const jlong  DYNAMIC_CODE_GENERATED_BIT = (((jlong)1) << (JVMTI_EVENT_DYNAMIC_CODE_GENERATED - TOTAL_MIN_EVENT_TYPE_VAL));
  82 static const jlong  DATA_DUMP_BIT = (((jlong)1) << (JVMTI_EVENT_DATA_DUMP_REQUEST - TOTAL_MIN_EVENT_TYPE_VAL));
  83 static const jlong  COMPILED_METHOD_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  84 static const jlong  COMPILED_METHOD_UNLOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  85 static const jlong  GARBAGE_COLLECTION_START_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_START - TOTAL_MIN_EVENT_TYPE_VAL));
  86 static const jlong  GARBAGE_COLLECTION_FINISH_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - TOTAL_MIN_EVENT_TYPE_VAL));
  87 static const jlong  OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE - TOTAL_MIN_EVENT_TYPE_VAL));
  88 static const jlong  RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL));
  89 static const jlong  VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
  90 static const jlong  SAMPLED_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_SAMPLED_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));


  91 
  92 // bits for extension events
  93 static const jlong  CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));


  94 
  95 

  96 static const jlong  MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT |
  97                           MONITOR_WAIT_BIT | MONITOR_WAITED_BIT;
  98 static const jlong  EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT;
  99 static const jlong  INTERP_EVENT_BITS =  SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT |
 100                                 FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT;
 101 static const jlong  THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS |
 102                                         BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT |
 103                                         SAMPLED_OBJECT_ALLOC_BIT;
 104 static const jlong  NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT;
 105 static const jlong  EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT |
 106                                VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT |
 107                                THREAD_START_BIT | THREAD_END_BIT |
 108                                COMPILED_METHOD_LOAD_BIT | COMPILED_METHOD_UNLOAD_BIT |
 109                                DYNAMIC_CODE_GENERATED_BIT;
 110 static const jlong  GLOBAL_EVENT_BITS = ~THREAD_FILTERED_EVENT_BITS;
 111 static const jlong  SHOULD_POST_ON_EXCEPTIONS_BITS = EXCEPTION_BITS | METHOD_EXIT_BIT | FRAME_POP_BIT;
 112 
 113 ///////////////////////////////////////////////////////////////
 114 //
 115 // JvmtiEventEnabled
 116 //
 117 
 118 JvmtiEventEnabled::JvmtiEventEnabled() {
 119   clear();
 120 }
 121 

 187   _event_user_enabled.clear();
 188   _event_callback_enabled.clear();
 189   _event_enabled.clear();
 190 }
 191 
 192 
 193 ///////////////////////////////////////////////////////////////
 194 //
 195 // EnterInterpOnlyModeClosure
 196 //
 197 
 198 class EnterInterpOnlyModeClosure : public HandshakeClosure {
 199  private:
 200   bool _completed;
 201  public:
 202   EnterInterpOnlyModeClosure() : HandshakeClosure("EnterInterpOnlyMode"), _completed(false) { }
 203   void do_thread(Thread* th) {
 204     JavaThread* jt = JavaThread::cast(th);
 205     JvmtiThreadState* state = jt->jvmti_thread_state();
 206 
 207     // Set up the current stack depth for later tracking
 208     state->invalidate_cur_stack_depth();
 209 
 210     state->enter_interp_only_mode();
 211 





 212     if (jt->has_last_Java_frame()) {
 213       // If running in fullspeed mode, single stepping is implemented
 214       // as follows: first, the interpreter does not dispatch to
 215       // compiled code for threads that have single stepping enabled;
 216       // second, we deoptimize all compiled java frames on the thread's stack when
 217       // interpreted-only mode is enabled the first time for a given
 218       // thread (nothing to do if no Java frames yet).
 219       ResourceMark resMark;
 220       for (StackFrameStream fst(jt, false /* update */, false /* process_frames */); !fst.is_done(); fst.next()) {
 221         if (fst.current()->can_be_deoptimized()) {
 222           Deoptimization::deoptimize(jt, *fst.current());
 223         }
 224       }
 225     }
 226     _completed = true;
 227   }
 228   bool completed() {
 229     return _completed;
 230   }
 231 };

 262 //
 263 // Private internal implementation methods for JvmtiEventController.
 264 //
 265 // These methods are thread safe either because they are called
 266 // in early VM initialization which is single threaded, or they
 267 // hold the JvmtiThreadState_lock.
 268 //
 269 
 270 class JvmtiEventControllerPrivate : public AllStatic {
 271   static bool _initialized;
 272 public:
 273   static void set_should_post_single_step(bool on);
 274   static void enter_interp_only_mode(JvmtiThreadState *state);
 275   static void leave_interp_only_mode(JvmtiThreadState *state);
 276   static void recompute_enabled();
 277   static jlong recompute_env_enabled(JvmtiEnvBase* env);
 278   static jlong recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state);
 279   static jlong recompute_thread_enabled(JvmtiThreadState *state);
 280   static void event_init();
 281 
 282   static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,
 283                         jvmtiEvent event_type, bool enabled);
 284   static void set_event_callbacks(JvmtiEnvBase *env,
 285                                   const jvmtiEventCallbacks* callbacks,
 286                                   jint size_of_callbacks);
 287 
 288   static void set_extension_event_callback(JvmtiEnvBase *env,
 289                                            jint extension_event_index,
 290                                            jvmtiExtensionEvent callback);
 291 
 292   static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 293   static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 294   static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 295   static void change_field_watch(jvmtiEvent event_type, bool added);
 296 
 297   static void thread_started(JavaThread *thread);
 298   static void thread_ended(JavaThread *thread);
 299 
 300   static void env_initialize(JvmtiEnvBase *env);
 301   static void env_dispose(JvmtiEnvBase *env);
 302 

 322 // When _on == true, we use the safepoint interpreter dispatch table
 323 // to allow us to find the single step points. Otherwise, we switch
 324 // back to the regular interpreter dispatch table.
 325 // Note: We call Interpreter::notice_safepoints() and ignore_safepoints()
 326 // in a VM_Operation to safely make the dispatch table switch. We
 327 // no longer rely on the safepoint mechanism to do any of this work
 328 // for us.
 329 void VM_ChangeSingleStep::doit() {
 330   log_debug(interpreter, safepoint)("changing single step to '%s'", _on ? "on" : "off");
 331   JvmtiEventControllerPrivate::set_should_post_single_step(_on);
 332   if (_on) {
 333     Interpreter::notice_safepoints();
 334   } else {
 335     Interpreter::ignore_safepoints();
 336   }
 337 }
 338 
 339 
 340 void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) {
 341   EC_TRACE(("[%s] # Entering interpreter only mode",
 342             JvmtiTrace::safe_get_thread_name(state->get_thread())));
 343   EnterInterpOnlyModeClosure hs;
 344   JavaThread *target = state->get_thread();
 345   Thread *current = Thread::current();
 346   if (target->is_handshake_safe_for(current)) {







 347     hs.do_thread(target);
 348   } else {
 349     Handshake::execute(&hs, target);
 350     guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
 351   }
 352 }
 353 
 354 
 355 void
 356 JvmtiEventControllerPrivate::leave_interp_only_mode(JvmtiThreadState *state) {
 357   EC_TRACE(("[%s] # Leaving interpreter only mode",
 358             JvmtiTrace::safe_get_thread_name(state->get_thread())));
 359   state->leave_interp_only_mode();
 360 }
 361 
 362 
 363 void
 364 JvmtiEventControllerPrivate::trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed) {
 365 #ifdef JVMTI_TRACE
 366   if (JvmtiTrace::trace_event_controller()) {
 367     SafeResourceMark rm;
 368     // traces standard events only
 369     for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 370       jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
 371       if (changed & bit) {
 372         // it changed, print it
 373          log_trace(jvmti)("[%s] # %s event %s",
 374                       JvmtiTrace::safe_get_thread_name(state->get_thread()),
 375                       (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));
 376       }
 377     }
 378   }
 379 #endif /*JVMTI_TRACE */
 380 }
 381 
 382 
 383 void
 384 JvmtiEventControllerPrivate::trace_changed(jlong now_enabled, jlong changed) {
 385 #ifdef JVMTI_TRACE
 386   if (JvmtiTrace::trace_event_controller()) {
 387     SafeResourceMark rm;
 388     // traces standard events only
 389     for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 390       jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
 391       if (changed & bit) {
 392         // it changed, print it
 393          log_trace(jvmti)("[-] # %s event %s",
 394                       (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));

 511     if (changed & SINGLE_STEP_BIT) {
 512       ets->reset_current_location(JVMTI_EVENT_SINGLE_STEP, (now_enabled & SINGLE_STEP_BIT) != 0);
 513     }
 514     if (changed & BREAKPOINT_BIT) {
 515       ets->reset_current_location(JVMTI_EVENT_BREAKPOINT,  (now_enabled & BREAKPOINT_BIT) != 0);
 516     }
 517     trace_changed(state, now_enabled, changed);
 518   }
 519   return now_enabled;
 520 }
 521 
 522 
 523 // For the specified thread: compute the currently truly enabled events
 524 // set external state accordingly.  Only thread-filtered events are included.
 525 jlong
 526 JvmtiEventControllerPrivate::recompute_thread_enabled(JvmtiThreadState *state) {
 527   if (state == NULL) {
 528     // associated JavaThread is exiting
 529     return (jlong)0;
 530   }
 531 
 532   julong was_any_env_enabled = state->thread_event_enable()->_event_enabled.get_bits();
 533   julong any_env_enabled = 0;
 534   // JVMTI_EVENT_FRAME_POP can be disabled (in the case FRAME_POP_BIT is not set),
 535   // but we need to set interp_only if some JvmtiEnvThreadState has frame pop set
 536   // to clear the request
 537   bool has_frame_pops = false;
 538 
 539   {
 540     // This iteration will include JvmtiEnvThreadStates whose environments
 541     // have been disposed.  These JvmtiEnvThreadStates must not be filtered
 542     // as recompute must be called on them to disable their events,
 543     JvmtiEnvThreadStateIterator it(state);
 544     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
 545       any_env_enabled |= recompute_env_thread_enabled(ets, state);
 546       has_frame_pops |= ets->has_frame_pops();
 547     }
 548   }
 549 
 550   if (any_env_enabled != was_any_env_enabled) {
 551     // mark if event is truly enabled on this thread in any environment
 552     state->thread_event_enable()->_event_enabled.set_bits(any_env_enabled);
 553 
 554     // update the JavaThread cached value for thread-specific should_post_on_exceptions value
 555     bool should_post_on_exceptions = (any_env_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0;
 556     state->set_should_post_on_exceptions(should_post_on_exceptions);






 557   }
 558 
 559   // compute interp_only mode
 560   bool should_be_interp = (any_env_enabled & INTERP_EVENT_BITS) != 0 || has_frame_pops;
 561   bool is_now_interp = state->is_interp_only_mode();
 562 
 563   if (should_be_interp != is_now_interp) {
 564     if (should_be_interp) {
 565       enter_interp_only_mode(state);
 566     } else {
 567       leave_interp_only_mode(state);
 568     }
 569   }
 570 





 571   return any_env_enabled;
 572 }
 573 
 574 
 575 // Compute truly enabled events - meaning if the event can and could be
 576 // sent.  An event is truly enabled if it is user enabled on the thread
 577 // or globally user enabled, but only if there is a callback or event hook
 578 // for it and, for field watch and frame pop, one has been set.
 579 // Compute if truly enabled, per thread, per environment, per combination
 580 // (thread x environment), and overall.  These merges are true if any is true.
 581 // True per thread if some environment has callback set and the event is globally
 582 // enabled or enabled for this thread.
 583 // True per environment if the callback is set and the event is globally
 584 // enabled in this environment or enabled for any thread in this environment.
 585 // True per combination if the environment has the callback set and the
 586 // event is globally enabled in this environment or the event is enabled
 587 // for this thread and environment.
 588 //
 589 // All states transitions dependent on these transitions are also handled here.
 590 void
 591 JvmtiEventControllerPrivate::recompute_enabled() {
 592   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 593 
 594   // event enabled for any thread in any environment
 595   julong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits();
 596   julong any_env_thread_enabled = 0;
 597 
 598   EC_TRACE(("[-] # recompute enabled - before " JULONG_FORMAT_X, was_any_env_thread_enabled));
 599 
 600   // compute non-thread-filters events.
 601   // This must be done separately from thread-filtered events, since some
 602   // events can occur before any threads exist.
 603   JvmtiEnvIterator it;
 604   for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
 605     any_env_thread_enabled |= recompute_env_enabled(env);
 606   }
 607 
 608   // We need to create any missing jvmti_thread_state if there are globally set thread
 609   // filtered events and there weren't last time
 610   if (    (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 &&
 611       (was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) {
 612     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *tp = jtiwh.next(); ) {
 613       // state_for_while_locked() makes tp->is_exiting() check
 614       JvmtiThreadState::state_for_while_locked(tp);  // create the thread state if missing








 615     }
 616   }
 617 
 618   // compute and set thread-filtered events
 619   for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) {
 620     any_env_thread_enabled |= recompute_thread_enabled(state);
 621   }
 622 
 623   // set universal state (across all envs and threads)
 624   jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled;
 625   if (delta != 0) {
 626     JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0);
 627     JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0);
 628     JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0);
 629     JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0);
 630     JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0);
 631     JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0);
 632     JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0);
 633     JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0);
 634     JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0);
 635     JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0);
 636     JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0);
 637     JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0);
 638     JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0);
 639     JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0);
 640     JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0);
 641     JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0);
 642     JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0);
 643     JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0);
 644     JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0);
 645     JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0);
 646     JvmtiExport::set_should_post_sampled_object_alloc((any_env_thread_enabled & SAMPLED_OBJECT_ALLOC_BIT) != 0);




 647 
 648     // need this if we want thread events or we need them to init data
 649     JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0);
 650 
 651     // If single stepping is turned on or off, execute the VM op to change it.
 652     if (delta & SINGLE_STEP_BIT) {
 653       switch (JvmtiEnv::get_phase()) {
 654       case JVMTI_PHASE_DEAD:
 655         // If the VM is dying we can't execute VM ops
 656         break;
 657       case JVMTI_PHASE_LIVE: {
 658         VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0);
 659         VMThread::execute(&op);
 660         break;
 661       }
 662       default:
 663         assert(false, "should never come here before live phase");
 664         break;
 665       }
 666     }

 702   // May be called after all environments have been disposed.
 703   assert(JvmtiThreadState_lock->is_locked(), "sanity check");
 704 
 705   EC_TRACE(("[%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread)));
 706 
 707   JvmtiThreadState *state = thread->jvmti_thread_state();
 708   assert(state != NULL, "else why are we here?");
 709   delete state;
 710 }
 711 
 712 void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env,
 713                                                       const jvmtiEventCallbacks* callbacks,
 714                                                       jint size_of_callbacks) {
 715   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 716   EC_TRACE(("[*] # set event callbacks"));
 717 
 718   // May be changing the event handler for ObjectFree.
 719   flush_object_free_events(env);
 720 
 721   env->set_event_callbacks(callbacks, size_of_callbacks);
 722   jlong enabled_bits = 0;

 723   for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 724     jvmtiEvent evt_t = (jvmtiEvent)ei;
 725     if (env->has_callback(evt_t)) {
 726       enabled_bits |= JvmtiEventEnabled::bit_for(evt_t);
 727     }
 728   }
 729   env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
 730   recompute_enabled();
 731 }
 732 
 733 void
 734 JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env,
 735                                                           jint extension_event_index,
 736                                                           jvmtiExtensionEvent callback)
 737 {
 738   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 739   EC_TRACE(("[*] # set extension event callback"));
 740 
 741   // extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL
 742   assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL &&
 743          extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check");
 744 
 745 
 746   // As the bits for both standard (jvmtiEvent) and extension
 747   // (jvmtiExtEvents) are stored in the same word we cast here to
 748   // jvmtiEvent to set/clear the bit for this extension event.
 749   jvmtiEvent event_type = (jvmtiEvent)extension_event_index;
 750 
 751   // Prevent a possible race condition where events are re-enabled by a call to
 752   // set event callbacks, where the DisposeEnvironment occurs after the boiler-plate
 753   // environment check and before the lock is acquired.
 754   // We can safely do the is_valid check now, as JvmtiThreadState_lock is held.
 755   bool enabling = (callback != NULL) && (env->is_valid());
 756   env->env_event_enable()->set_user_enabled(event_type, enabling);
 757 
 758   // update the callback
 759   jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks();
 760   switch (extension_event_index) {
 761     case EXT_EVENT_CLASS_UNLOAD :
 762       ext_callbacks->ClassUnload = callback;
 763       break;






 764     default:
 765       ShouldNotReachHere();
 766   }
 767 
 768   // update the callback enable/disable bit
 769   jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits();
 770   jlong bit_for = JvmtiEventEnabled::bit_for(event_type);
 771   if (enabling) {
 772     enabled_bits |= bit_for;
 773   } else {
 774     enabled_bits &= ~bit_for;
 775   }
 776   env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
 777 
 778   recompute_enabled();
 779 }
 780 
 781 
 782 void
 783 JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) {

 805 JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) {
 806   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 807   EC_TRACE(("[*] # env dispose"));
 808 
 809   // Before the environment is marked disposed, disable all events on this
 810   // environment (by zapping the callbacks).  As a result, the disposed
 811   // environment will not call event handlers.
 812   set_event_callbacks(env, NULL, 0);
 813   for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL;
 814        extension_event_index <= EXT_MAX_EVENT_TYPE_VAL;
 815        ++extension_event_index) {
 816     set_extension_event_callback(env, extension_event_index, NULL);
 817   }
 818 
 819   // Let the environment finish disposing itself.
 820   env->env_dispose();
 821 }
 822 
 823 
 824 void
 825 JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,
 826                                           jvmtiEvent event_type, bool enabled) {
 827   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 828 
 829   EC_TRACE(("[%s] # user %s event %s",
 830             thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread),
 831             enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type)));
 832 
 833   if (event_type == JVMTI_EVENT_OBJECT_FREE) {
 834     flush_object_free_events(env);
 835   }
 836 
 837   if (thread == NULL) {
 838     env->env_event_enable()->set_user_enabled(event_type, enabled);
 839   } else {
 840     // create the thread state (if it didn't exist before)
 841     JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread);
 842     if (state != NULL) {
 843       state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled);
 844     }
 845   }
 846   recompute_enabled();
 847 }
 848 
 849 
 850 void
 851 JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 852   EC_TRACE(("[%s] # set frame pop - frame=%d",
 853             JvmtiTrace::safe_get_thread_name(ets->get_thread()),
 854             fpop.frame_number() ));
 855 
 856   ets->get_frame_pops()->set(fpop);
 857   recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
 858 }
 859 
 860 
 861 void
 862 JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 863   EC_TRACE(("[%s] # clear frame pop - frame=%d",
 864             JvmtiTrace::safe_get_thread_name(ets->get_thread()),
 865             fpop.frame_number() ));
 866 
 867   ets->get_frame_pops()->clear(fpop);
 868   recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
 869 }
 870 
 871 
 872 void
 873 JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 874   int cleared_cnt = ets->get_frame_pops()->clear_to(fpop);
 875 
 876   EC_TRACE(("[%s] # clear to frame pop - frame=%d, count=%d",
 877             JvmtiTrace::safe_get_thread_name(ets->get_thread()),
 878             fpop.frame_number(),
 879             cleared_cnt ));
 880 
 881   if (cleared_cnt > 0) {
 882     recompute_thread_enabled(ets->get_thread()->jvmti_thread_state());
 883   }
 884 }
 885 
 886 void
 887 JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) {
 888   int *count_addr;
 889 
 890   switch (event_type) {
 891   case JVMTI_EVENT_FIELD_MODIFICATION:
 892     count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
 893     break;
 894   case JVMTI_EVENT_FIELD_ACCESS:
 895     count_addr = (int *)JvmtiExport::get_field_access_count_addr();
 896     break;
 897   default:
 898     assert(false, "incorrect event");
 899     return;
 900   }
 901 
 902   EC_TRACE(("[-] # change field watch - %s %s count=%d",

 964   // events are disabled (phase has changed)
 965   JvmtiEventControllerPrivate::recompute_enabled();
 966 }
 967 
 968 
 969 ///////////////////////////////////////////////////////////////
 970 //
 971 // JvmtiEventController
 972 //
 973 
 974 JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled;
 975 
 976 bool
 977 JvmtiEventController::is_global_event(jvmtiEvent event_type) {
 978   assert(is_valid_event_type(event_type), "invalid event type");
 979   jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL);
 980   return((bit_for & GLOBAL_EVENT_BITS)!=0);
 981 }
 982 
 983 void
 984 JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, jvmtiEvent event_type, bool enabled) {

 985   if (Threads::number_of_threads() == 0) {
 986     // during early VM start-up locks don't exist, but we are safely single threaded,
 987     // call the functionality without holding the JvmtiThreadState_lock.
 988     JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled);
 989   } else {



 990     MutexLocker mu(JvmtiThreadState_lock);
 991     JvmtiEventControllerPrivate::set_user_enabled(env, thread, event_type, enabled);
 992   }
 993 }
 994 
 995 
 996 void
 997 JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env,
 998                                           const jvmtiEventCallbacks* callbacks,
 999                                           jint size_of_callbacks) {
1000   if (Threads::number_of_threads() == 0) {
1001     // during early VM start-up locks don't exist, but we are safely single threaded,
1002     // call the functionality without holding the JvmtiThreadState_lock.
1003     JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
1004   } else {
1005     MutexLocker mu(JvmtiThreadState_lock);
1006     JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
1007   }
1008 }
1009 
1010 void
1011 JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env,

   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 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "interpreter/interpreter.hpp"
  28 #include "jvmtifiles/jvmtiEnv.hpp"
  29 #include "logging/log.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "prims/jvmtiEventController.hpp"
  32 #include "prims/jvmtiEventController.inline.hpp"
  33 #include "prims/jvmtiExport.hpp"
  34 #include "prims/jvmtiImpl.hpp"
  35 #include "prims/jvmtiTagMap.hpp"
  36 #include "prims/jvmtiThreadState.inline.hpp"
  37 #include "runtime/deoptimization.hpp"
  38 #include "runtime/frame.inline.hpp"
  39 #include "runtime/stackFrameStream.inline.hpp"
  40 #include "runtime/thread.inline.hpp"
  41 #include "runtime/threadSMR.hpp"
  42 #include "runtime/vframe.hpp"
  43 #include "runtime/vframe_hp.hpp"
  44 #include "runtime/vmThread.hpp"
  45 #include "runtime/vmOperations.hpp"
  46 

  72 static const jlong  CLASS_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  73 static const jlong  CLASS_PREPARE_BIT = (((jlong)1) << (JVMTI_EVENT_CLASS_PREPARE - TOTAL_MIN_EVENT_TYPE_VAL));
  74 static const jlong  THREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL));
  75 static const jlong  THREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL));
  76 static const jlong  EXCEPTION_THROW_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION - TOTAL_MIN_EVENT_TYPE_VAL));
  77 static const jlong  EXCEPTION_CATCH_BIT = (((jlong)1) << (JVMTI_EVENT_EXCEPTION_CATCH - TOTAL_MIN_EVENT_TYPE_VAL));
  78 static const jlong  MONITOR_CONTENDED_ENTER_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTER - TOTAL_MIN_EVENT_TYPE_VAL));
  79 static const jlong  MONITOR_CONTENDED_ENTERED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED - TOTAL_MIN_EVENT_TYPE_VAL));
  80 static const jlong  MONITOR_WAIT_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAIT - TOTAL_MIN_EVENT_TYPE_VAL));
  81 static const jlong  MONITOR_WAITED_BIT = (((jlong)1) << (JVMTI_EVENT_MONITOR_WAITED - TOTAL_MIN_EVENT_TYPE_VAL));
  82 static const jlong  DYNAMIC_CODE_GENERATED_BIT = (((jlong)1) << (JVMTI_EVENT_DYNAMIC_CODE_GENERATED - TOTAL_MIN_EVENT_TYPE_VAL));
  83 static const jlong  DATA_DUMP_BIT = (((jlong)1) << (JVMTI_EVENT_DATA_DUMP_REQUEST - TOTAL_MIN_EVENT_TYPE_VAL));
  84 static const jlong  COMPILED_METHOD_LOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_LOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  85 static const jlong  COMPILED_METHOD_UNLOAD_BIT = (((jlong)1) << (JVMTI_EVENT_COMPILED_METHOD_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  86 static const jlong  GARBAGE_COLLECTION_START_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_START - TOTAL_MIN_EVENT_TYPE_VAL));
  87 static const jlong  GARBAGE_COLLECTION_FINISH_BIT = (((jlong)1) << (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH - TOTAL_MIN_EVENT_TYPE_VAL));
  88 static const jlong  OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE - TOTAL_MIN_EVENT_TYPE_VAL));
  89 static const jlong  RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL));
  90 static const jlong  VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
  91 static const jlong  SAMPLED_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_SAMPLED_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
  92 static const jlong  VTHREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL));
  93 static const jlong  VTHREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL));
  94 
  95 // bits for extension events
  96 static const jlong  CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));
  97 static const jlong  VTHREAD_MOUNT_BIT = (((jlong)1) << (EXT_EVENT_VIRTUAL_THREAD_MOUNT - TOTAL_MIN_EVENT_TYPE_VAL));
  98 static const jlong  VTHREAD_UNMOUNT_BIT = (((jlong)1) << (EXT_EVENT_VIRTUAL_THREAD_UNMOUNT - TOTAL_MIN_EVENT_TYPE_VAL));
  99 
 100 
 101 static const jlong  VTHREAD_BITS = VTHREAD_START_BIT | VTHREAD_END_BIT | VTHREAD_MOUNT_BIT | VTHREAD_UNMOUNT_BIT;
 102 static const jlong  MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT |
 103                           MONITOR_WAIT_BIT | MONITOR_WAITED_BIT;
 104 static const jlong  EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT;
 105 static const jlong  INTERP_EVENT_BITS =  SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT |
 106                                 FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT;
 107 static const jlong  THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS | VTHREAD_BITS |
 108                                         BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT |
 109                                         SAMPLED_OBJECT_ALLOC_BIT;
 110 static const jlong  NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT;
 111 static const jlong  EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT |
 112                                VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT |
 113                                THREAD_START_BIT | THREAD_END_BIT |
 114                                COMPILED_METHOD_LOAD_BIT | COMPILED_METHOD_UNLOAD_BIT |
 115                                DYNAMIC_CODE_GENERATED_BIT;
 116 static const jlong  GLOBAL_EVENT_BITS = ~THREAD_FILTERED_EVENT_BITS;
 117 static const jlong  SHOULD_POST_ON_EXCEPTIONS_BITS = EXCEPTION_BITS | METHOD_EXIT_BIT | FRAME_POP_BIT;
 118 
 119 ///////////////////////////////////////////////////////////////
 120 //
 121 // JvmtiEventEnabled
 122 //
 123 
 124 JvmtiEventEnabled::JvmtiEventEnabled() {
 125   clear();
 126 }
 127 

 193   _event_user_enabled.clear();
 194   _event_callback_enabled.clear();
 195   _event_enabled.clear();
 196 }
 197 
 198 
 199 ///////////////////////////////////////////////////////////////
 200 //
 201 // EnterInterpOnlyModeClosure
 202 //
 203 
 204 class EnterInterpOnlyModeClosure : public HandshakeClosure {
 205  private:
 206   bool _completed;
 207  public:
 208   EnterInterpOnlyModeClosure() : HandshakeClosure("EnterInterpOnlyMode"), _completed(false) { }
 209   void do_thread(Thread* th) {
 210     JavaThread* jt = JavaThread::cast(th);
 211     JvmtiThreadState* state = jt->jvmti_thread_state();
 212 
 213     // invalidate_cur_stack_depth is called in enter_interp_only_mode


 214     state->enter_interp_only_mode();
 215 
 216     if (state->get_thread() != NULL) {
 217       // TODO LOOM: find out why the other place where this is called is insufficient 
 218       Continuation::set_cont_fastpath_thread_state(state->get_thread());
 219     }
 220 
 221     if (jt->has_last_Java_frame()) {
 222       // If running in fullspeed mode, single stepping is implemented
 223       // as follows: first, the interpreter does not dispatch to
 224       // compiled code for threads that have single stepping enabled;
 225       // second, we deoptimize all compiled java frames on the thread's stack when
 226       // interpreted-only mode is enabled the first time for a given
 227       // thread (nothing to do if no Java frames yet).
 228       ResourceMark resMark;
 229       for (StackFrameStream fst(jt, false /* update */, false /* process_frames */); !fst.is_done(); fst.next()) {
 230         if (fst.current()->can_be_deoptimized()) {
 231           Deoptimization::deoptimize(jt, *fst.current());
 232         }
 233       }
 234     }
 235     _completed = true;
 236   }
 237   bool completed() {
 238     return _completed;
 239   }
 240 };

 271 //
 272 // Private internal implementation methods for JvmtiEventController.
 273 //
 274 // These methods are thread safe either because they are called
 275 // in early VM initialization which is single threaded, or they
 276 // hold the JvmtiThreadState_lock.
 277 //
 278 
 279 class JvmtiEventControllerPrivate : public AllStatic {
 280   static bool _initialized;
 281 public:
 282   static void set_should_post_single_step(bool on);
 283   static void enter_interp_only_mode(JvmtiThreadState *state);
 284   static void leave_interp_only_mode(JvmtiThreadState *state);
 285   static void recompute_enabled();
 286   static jlong recompute_env_enabled(JvmtiEnvBase* env);
 287   static jlong recompute_env_thread_enabled(JvmtiEnvThreadState* ets, JvmtiThreadState* state);
 288   static jlong recompute_thread_enabled(JvmtiThreadState *state);
 289   static void event_init();
 290 
 291   static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, oop thread_oop,
 292                         jvmtiEvent event_type, bool enabled);
 293   static void set_event_callbacks(JvmtiEnvBase *env,
 294                                   const jvmtiEventCallbacks* callbacks,
 295                                   jint size_of_callbacks);
 296 
 297   static void set_extension_event_callback(JvmtiEnvBase *env,
 298                                            jint extension_event_index,
 299                                            jvmtiExtensionEvent callback);
 300 
 301   static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 302   static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 303   static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
 304   static void change_field_watch(jvmtiEvent event_type, bool added);
 305 
 306   static void thread_started(JavaThread *thread);
 307   static void thread_ended(JavaThread *thread);
 308 
 309   static void env_initialize(JvmtiEnvBase *env);
 310   static void env_dispose(JvmtiEnvBase *env);
 311 

 331 // When _on == true, we use the safepoint interpreter dispatch table
 332 // to allow us to find the single step points. Otherwise, we switch
 333 // back to the regular interpreter dispatch table.
 334 // Note: We call Interpreter::notice_safepoints() and ignore_safepoints()
 335 // in a VM_Operation to safely make the dispatch table switch. We
 336 // no longer rely on the safepoint mechanism to do any of this work
 337 // for us.
 338 void VM_ChangeSingleStep::doit() {
 339   log_debug(interpreter, safepoint)("changing single step to '%s'", _on ? "on" : "off");
 340   JvmtiEventControllerPrivate::set_should_post_single_step(_on);
 341   if (_on) {
 342     Interpreter::notice_safepoints();
 343   } else {
 344     Interpreter::ignore_safepoints();
 345   }
 346 }
 347 
 348 
 349 void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) {
 350   EC_TRACE(("[%s] # Entering interpreter only mode",
 351             JvmtiTrace::safe_get_thread_name(state->get_thread_or_saved())));
 352   EnterInterpOnlyModeClosure hs;
 353   JavaThread *target = state->get_thread();
 354   Thread *current = Thread::current();
 355 
 356   // TBD: This is TMP workaround. We need a proper synchronization here.
 357   if (target == NULL) {
 358     state->enter_interp_only_mode(); // increment _saved_interp_only_mode
 359     return;
 360   }
 361 
 362 if (target->is_handshake_safe_for(current)) {
 363     hs.do_thread(target);
 364   } else {
 365     Handshake::execute(&hs, target);
 366     guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
 367   }
 368 }
 369 
 370 
 371 void
 372 JvmtiEventControllerPrivate::leave_interp_only_mode(JvmtiThreadState *state) {
 373   EC_TRACE(("[%s] # Leaving interpreter only mode",
 374             JvmtiTrace::safe_get_thread_name(state->get_thread_or_saved())));
 375   state->leave_interp_only_mode();
 376 }
 377 
 378 
 379 void
 380 JvmtiEventControllerPrivate::trace_changed(JvmtiThreadState *state, jlong now_enabled, jlong changed) {
 381 #ifdef JVMTI_TRACE
 382   if (JvmtiTrace::trace_event_controller()) {
 383     SafeResourceMark rm;
 384     // traces standard events only
 385     for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 386       jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
 387       if (changed & bit) {
 388         // it changed, print it
 389          log_trace(jvmti)("[%s] # %s event %s",
 390                       JvmtiTrace::safe_get_thread_name(state->get_thread_or_saved()),
 391                       (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));
 392       }
 393     }
 394   }
 395 #endif /*JVMTI_TRACE */
 396 }
 397 
 398 
 399 void
 400 JvmtiEventControllerPrivate::trace_changed(jlong now_enabled, jlong changed) {
 401 #ifdef JVMTI_TRACE
 402   if (JvmtiTrace::trace_event_controller()) {
 403     SafeResourceMark rm;
 404     // traces standard events only
 405     for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 406       jlong bit = JvmtiEventEnabled::bit_for((jvmtiEvent)ei);
 407       if (changed & bit) {
 408         // it changed, print it
 409          log_trace(jvmti)("[-] # %s event %s",
 410                       (now_enabled & bit)? "Enabling" : "Disabling", JvmtiTrace::event_name((jvmtiEvent)ei));

 527     if (changed & SINGLE_STEP_BIT) {
 528       ets->reset_current_location(JVMTI_EVENT_SINGLE_STEP, (now_enabled & SINGLE_STEP_BIT) != 0);
 529     }
 530     if (changed & BREAKPOINT_BIT) {
 531       ets->reset_current_location(JVMTI_EVENT_BREAKPOINT,  (now_enabled & BREAKPOINT_BIT) != 0);
 532     }
 533     trace_changed(state, now_enabled, changed);
 534   }
 535   return now_enabled;
 536 }
 537 
 538 
 539 // For the specified thread: compute the currently truly enabled events
 540 // set external state accordingly.  Only thread-filtered events are included.
 541 jlong
 542 JvmtiEventControllerPrivate::recompute_thread_enabled(JvmtiThreadState *state) {
 543   if (state == NULL) {
 544     // associated JavaThread is exiting
 545     return (jlong)0;
 546   }

 547   julong was_any_env_enabled = state->thread_event_enable()->_event_enabled.get_bits();
 548   julong any_env_enabled = 0;
 549   // JVMTI_EVENT_FRAME_POP can be disabled (in the case FRAME_POP_BIT is not set),
 550   // but we need to set interp_only if some JvmtiEnvThreadState has frame pop set
 551   // to clear the request
 552   bool has_frame_pops = false;
 553 
 554   {
 555     // This iteration will include JvmtiEnvThreadStates whose environments
 556     // have been disposed.  These JvmtiEnvThreadStates must not be filtered
 557     // as recompute must be called on them to disable their events,
 558     JvmtiEnvThreadStateIterator it(state);
 559     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
 560       any_env_enabled |= recompute_env_thread_enabled(ets, state);
 561       has_frame_pops |= ets->has_frame_pops();
 562     }
 563   }
 564 
 565   if (any_env_enabled != was_any_env_enabled) {
 566     // mark if event is truly enabled on this thread in any environment
 567     state->thread_event_enable()->_event_enabled.set_bits(any_env_enabled);
 568 
 569     // pointer to JavaThread can be NULL for unmouted virtual thread
 570     if (state->get_thread() != NULL) {
 571       // update the JavaThread cached value for thread-specific should_post_on_exceptions value
 572       bool should_post_on_exceptions = (any_env_enabled & SHOULD_POST_ON_EXCEPTIONS_BITS) != 0;
 573       state->set_should_post_on_exceptions(should_post_on_exceptions);
 574     }
 575   }
 576   if (state->get_thread() == NULL) {
 577     return any_env_enabled;
 578   }
 579 
 580   // compute interp_only mode
 581   bool should_be_interp = (any_env_enabled & INTERP_EVENT_BITS) != 0 || has_frame_pops;
 582   bool is_now_interp = state->is_interp_only_mode();
 583 
 584   if (should_be_interp != is_now_interp) {
 585     if (should_be_interp) {
 586       enter_interp_only_mode(state);
 587     } else {
 588       leave_interp_only_mode(state);
 589     }
 590   }
 591 
 592   // TBD: there is a race here, so get_thread() can return NULL below.
 593   if (state->get_thread() != NULL) {
 594     Continuation::set_cont_fastpath_thread_state(state->get_thread());
 595   }
 596 
 597   return any_env_enabled;
 598 }
 599 
 600 
 601 // Compute truly enabled events - meaning if the event can and could be
 602 // sent.  An event is truly enabled if it is user enabled on the thread
 603 // or globally user enabled, but only if there is a callback or event hook
 604 // for it and, for field watch and frame pop, one has been set.
 605 // Compute if truly enabled, per thread, per environment, per combination
 606 // (thread x environment), and overall.  These merges are true if any is true.
 607 // True per thread if some environment has callback set and the event is globally
 608 // enabled or enabled for this thread.
 609 // True per environment if the callback is set and the event is globally
 610 // enabled in this environment or enabled for any thread in this environment.
 611 // True per combination if the environment has the callback set and the
 612 // event is globally enabled in this environment or the event is enabled
 613 // for this thread and environment.
 614 //
 615 // All states transitions dependent on these transitions are also handled here.
 616 void
 617 JvmtiEventControllerPrivate::recompute_enabled() {
 618   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 619 
 620   // event enabled for any thread in any environment
 621   julong was_any_env_thread_enabled = JvmtiEventController::_universal_global_event_enabled.get_bits();
 622   julong any_env_thread_enabled = 0;
 623 
 624   EC_TRACE(("[-] # recompute enabled - before " JULONG_FORMAT_X, was_any_env_thread_enabled));
 625 
 626   // Compute non-thread-filtered events.
 627   // This must be done separately from thread-filtered events, since some
 628   // events can occur before any threads exist.
 629   JvmtiEnvIterator it;
 630   for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
 631     any_env_thread_enabled |= recompute_env_enabled(env);
 632   }
 633 
 634   // We need to create any missing jvmti_thread_state if there are globally set thread
 635   // filtered events and there weren't last time
 636   if (    (any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) != 0 &&
 637       (was_any_env_thread_enabled & THREAD_FILTERED_EVENT_BITS) == 0) {
 638     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *tp = jtiwh.next(); ) {
 639       oop jt_oop = tp->threadObj();
 640 
 641       // create the thread state if missing, state_for_while_locked() makes tp->is_exiting() check
 642       JvmtiThreadState* state = JvmtiThreadState::state_for_while_locked(tp, jt_oop);
 643 
 644       // create the thread state for mounted virtual thread if missing
 645       oop vt_oop = tp->mounted_vthread();
 646       if (vt_oop != NULL && java_lang_VirtualThread::is_instance(vt_oop)) {
 647         state = JvmtiThreadState::state_for_while_locked(tp, vt_oop);
 648       } 
 649     }
 650   }
 651 
 652   // compute and set thread-filtered events
 653   for (JvmtiThreadState *state = JvmtiThreadState::first(); state != NULL; state = state->next()) {
 654     any_env_thread_enabled |= recompute_thread_enabled(state);
 655   }
 656 
 657   // set universal state (across all envs and threads)
 658   jlong delta = any_env_thread_enabled ^ was_any_env_thread_enabled;
 659   if (delta != 0) {
 660     JvmtiExport::set_should_post_field_access((any_env_thread_enabled & FIELD_ACCESS_BIT) != 0);
 661     JvmtiExport::set_should_post_field_modification((any_env_thread_enabled & FIELD_MODIFICATION_BIT) != 0);
 662     JvmtiExport::set_should_post_class_load((any_env_thread_enabled & CLASS_LOAD_BIT) != 0);
 663     JvmtiExport::set_should_post_class_file_load_hook((any_env_thread_enabled & CLASS_FILE_LOAD_HOOK_BIT) != 0);
 664     JvmtiExport::set_should_post_native_method_bind((any_env_thread_enabled & NATIVE_METHOD_BIND_BIT) != 0);
 665     JvmtiExport::set_should_post_dynamic_code_generated((any_env_thread_enabled & DYNAMIC_CODE_GENERATED_BIT) != 0);
 666     JvmtiExport::set_should_post_data_dump((any_env_thread_enabled & DATA_DUMP_BIT) != 0);
 667     JvmtiExport::set_should_post_class_prepare((any_env_thread_enabled & CLASS_PREPARE_BIT) != 0);
 668     JvmtiExport::set_should_post_class_unload((any_env_thread_enabled & CLASS_UNLOAD_BIT) != 0);
 669     JvmtiExport::set_should_post_monitor_contended_enter((any_env_thread_enabled & MONITOR_CONTENDED_ENTER_BIT) != 0);
 670     JvmtiExport::set_should_post_monitor_contended_entered((any_env_thread_enabled & MONITOR_CONTENDED_ENTERED_BIT) != 0);
 671     JvmtiExport::set_should_post_monitor_wait((any_env_thread_enabled & MONITOR_WAIT_BIT) != 0);
 672     JvmtiExport::set_should_post_monitor_waited((any_env_thread_enabled & MONITOR_WAITED_BIT) != 0);
 673     JvmtiExport::set_should_post_garbage_collection_start((any_env_thread_enabled & GARBAGE_COLLECTION_START_BIT) != 0);
 674     JvmtiExport::set_should_post_garbage_collection_finish((any_env_thread_enabled & GARBAGE_COLLECTION_FINISH_BIT) != 0);
 675     JvmtiExport::set_should_post_object_free((any_env_thread_enabled & OBJECT_FREE_BIT) != 0);
 676     JvmtiExport::set_should_post_resource_exhausted((any_env_thread_enabled & RESOURCE_EXHAUSTED_BIT) != 0);
 677     JvmtiExport::set_should_post_compiled_method_load((any_env_thread_enabled & COMPILED_METHOD_LOAD_BIT) != 0);
 678     JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0);
 679     JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0);
 680     JvmtiExport::set_should_post_sampled_object_alloc((any_env_thread_enabled & SAMPLED_OBJECT_ALLOC_BIT) != 0);
 681     JvmtiExport::set_should_post_vthread_start((any_env_thread_enabled & VTHREAD_START_BIT) != 0);
 682     JvmtiExport::set_should_post_vthread_end((any_env_thread_enabled & VTHREAD_END_BIT) != 0);
 683     JvmtiExport::set_should_post_vthread_mount((any_env_thread_enabled & VTHREAD_MOUNT_BIT) != 0);
 684     JvmtiExport::set_should_post_vthread_unmount((any_env_thread_enabled & VTHREAD_UNMOUNT_BIT) != 0);
 685 
 686     // need this if we want thread events or we need them to init data
 687     JvmtiExport::set_should_post_thread_life((any_env_thread_enabled & NEED_THREAD_LIFE_EVENTS) != 0);
 688 
 689     // If single stepping is turned on or off, execute the VM op to change it.
 690     if (delta & SINGLE_STEP_BIT) {
 691       switch (JvmtiEnv::get_phase()) {
 692       case JVMTI_PHASE_DEAD:
 693         // If the VM is dying we can't execute VM ops
 694         break;
 695       case JVMTI_PHASE_LIVE: {
 696         VM_ChangeSingleStep op((any_env_thread_enabled & SINGLE_STEP_BIT) != 0);
 697         VMThread::execute(&op);
 698         break;
 699       }
 700       default:
 701         assert(false, "should never come here before live phase");
 702         break;
 703       }
 704     }

 740   // May be called after all environments have been disposed.
 741   assert(JvmtiThreadState_lock->is_locked(), "sanity check");
 742 
 743   EC_TRACE(("[%s] # thread ended", JvmtiTrace::safe_get_thread_name(thread)));
 744 
 745   JvmtiThreadState *state = thread->jvmti_thread_state();
 746   assert(state != NULL, "else why are we here?");
 747   delete state;
 748 }
 749 
 750 void JvmtiEventControllerPrivate::set_event_callbacks(JvmtiEnvBase *env,
 751                                                       const jvmtiEventCallbacks* callbacks,
 752                                                       jint size_of_callbacks) {
 753   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 754   EC_TRACE(("[*] # set event callbacks"));
 755 
 756   // May be changing the event handler for ObjectFree.
 757   flush_object_free_events(env);
 758 
 759   env->set_event_callbacks(callbacks, size_of_callbacks);
 760   jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits();
 761 
 762   for (int ei = JVMTI_MIN_EVENT_TYPE_VAL; ei <= JVMTI_MAX_EVENT_TYPE_VAL; ++ei) {
 763     jvmtiEvent evt_t = (jvmtiEvent)ei;
 764     if (env->has_callback(evt_t)) {
 765       enabled_bits |= JvmtiEventEnabled::bit_for(evt_t);
 766     }
 767   }
 768   env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
 769   recompute_enabled();
 770 }
 771 
 772 void
 773 JvmtiEventControllerPrivate::set_extension_event_callback(JvmtiEnvBase *env,
 774                                                           jint extension_event_index,
 775                                                           jvmtiExtensionEvent callback)
 776 {
 777   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 778   EC_TRACE(("[*] # set extension event callback"));
 779 
 780   // extension events are allocated below JVMTI_MIN_EVENT_TYPE_VAL
 781   assert(extension_event_index >= (jint)EXT_MIN_EVENT_TYPE_VAL &&
 782          extension_event_index <= (jint)EXT_MAX_EVENT_TYPE_VAL, "sanity check");
 783 
 784 
 785   // As the bits for both standard (jvmtiEvent) and extension
 786   // (jvmtiExtEvents) are stored in the same word we cast here to
 787   // jvmtiEvent to set/clear the bit for this extension event.
 788   jvmtiEvent event_type = (jvmtiEvent)extension_event_index;
 789 
 790   // Prevent a possible race condition where events are re-enabled by a call to
 791   // set event callbacks, where the DisposeEnvironment occurs after the boiler-plate
 792   // environment check and before the lock is acquired.
 793   // We can safely do the is_valid check now, as JvmtiThreadState_lock is held.
 794   bool enabling = (callback != NULL) && (env->is_valid());

 795 
 796   // update the callback
 797   jvmtiExtEventCallbacks* ext_callbacks = env->ext_callbacks();
 798   switch (extension_event_index) {
 799     case EXT_EVENT_CLASS_UNLOAD :
 800       ext_callbacks->ClassUnload = callback;
 801       break;
 802     case EXT_EVENT_VIRTUAL_THREAD_MOUNT :
 803       ext_callbacks->VirtualThreadMount = callback;
 804       break;
 805     case EXT_EVENT_VIRTUAL_THREAD_UNMOUNT :
 806       ext_callbacks->VirtualThreadUnmount = callback;
 807       break;
 808     default:
 809       ShouldNotReachHere();
 810   }
 811 
 812   // update the callback enable/disable bit
 813   jlong enabled_bits = env->env_event_enable()->_event_callback_enabled.get_bits();
 814   jlong bit_for = JvmtiEventEnabled::bit_for(event_type);
 815   if (enabling) {
 816     enabled_bits |= bit_for;
 817   } else {
 818     enabled_bits &= ~bit_for;
 819   }
 820   env->env_event_enable()->_event_callback_enabled.set_bits(enabled_bits);
 821 
 822   recompute_enabled();
 823 }
 824 
 825 
 826 void
 827 JvmtiEventControllerPrivate::env_initialize(JvmtiEnvBase *env) {

 849 JvmtiEventControllerPrivate::env_dispose(JvmtiEnvBase *env) {
 850   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 851   EC_TRACE(("[*] # env dispose"));
 852 
 853   // Before the environment is marked disposed, disable all events on this
 854   // environment (by zapping the callbacks).  As a result, the disposed
 855   // environment will not call event handlers.
 856   set_event_callbacks(env, NULL, 0);
 857   for (jint extension_event_index = EXT_MIN_EVENT_TYPE_VAL;
 858        extension_event_index <= EXT_MAX_EVENT_TYPE_VAL;
 859        ++extension_event_index) {
 860     set_extension_event_callback(env, extension_event_index, NULL);
 861   }
 862 
 863   // Let the environment finish disposing itself.
 864   env->env_dispose();
 865 }
 866 
 867 
 868 void
 869 JvmtiEventControllerPrivate::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, oop thread_oop,
 870                                           jvmtiEvent event_type, bool enabled) {
 871   assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
 872 
 873   EC_TRACE(("[%s] # user %s event %s",
 874             thread==NULL? "ALL": JvmtiTrace::safe_get_thread_name(thread),
 875             enabled? "enabled" : "disabled", JvmtiTrace::event_name(event_type)));
 876 
 877   if (event_type == JVMTI_EVENT_OBJECT_FREE) {
 878     flush_object_free_events(env);
 879   }
 880 
 881   if (thread == NULL && thread_oop == NULL) { // thread can be NULL for unmounted virtual trheads
 882     env->env_event_enable()->set_user_enabled(event_type, enabled);
 883   } else {
 884     // create the thread state (if it didn't exist before)
 885     JvmtiThreadState *state = JvmtiThreadState::state_for_while_locked(thread, thread_oop);
 886     if (state != NULL) {
 887       state->env_thread_state(env)->event_enable()->set_user_enabled(event_type, enabled);
 888     }
 889   }
 890   recompute_enabled();
 891 }
 892 
 893 
 894 void
 895 JvmtiEventControllerPrivate::set_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 896   EC_TRACE(("[%s] # set frame pop - frame=%d",
 897             JvmtiTrace::safe_get_thread_name(ets->get_thread_or_saved()),
 898             fpop.frame_number() ));
 899 
 900   ets->get_frame_pops()->set(fpop);
 901   recompute_thread_enabled(ets->jvmti_thread_state());
 902 }
 903 
 904 
 905 void
 906 JvmtiEventControllerPrivate::clear_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 907   EC_TRACE(("[%s] # clear frame pop - frame=%d",
 908             JvmtiTrace::safe_get_thread_name(ets->get_thread_or_saved()),
 909             fpop.frame_number() ));
 910 
 911   ets->get_frame_pops()->clear(fpop);
 912   recompute_thread_enabled(ets->jvmti_thread_state());
 913 }
 914 
 915 
 916 void
 917 JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiFramePop fpop) {
 918   int cleared_cnt = ets->get_frame_pops()->clear_to(fpop);
 919 
 920   EC_TRACE(("[%s] # clear to frame pop - frame=%d, count=%d",
 921             JvmtiTrace::safe_get_thread_name(ets->get_thread_or_saved()),
 922             fpop.frame_number(),
 923             cleared_cnt ));
 924 
 925   if (cleared_cnt > 0) {
 926     recompute_thread_enabled(ets->jvmti_thread_state());
 927   }
 928 }
 929 
 930 void
 931 JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) {
 932   int *count_addr;
 933 
 934   switch (event_type) {
 935   case JVMTI_EVENT_FIELD_MODIFICATION:
 936     count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
 937     break;
 938   case JVMTI_EVENT_FIELD_ACCESS:
 939     count_addr = (int *)JvmtiExport::get_field_access_count_addr();
 940     break;
 941   default:
 942     assert(false, "incorrect event");
 943     return;
 944   }
 945 
 946   EC_TRACE(("[-] # change field watch - %s %s count=%d",

1008   // events are disabled (phase has changed)
1009   JvmtiEventControllerPrivate::recompute_enabled();
1010 }
1011 
1012 
1013 ///////////////////////////////////////////////////////////////
1014 //
1015 // JvmtiEventController
1016 //
1017 
1018 JvmtiEventEnabled JvmtiEventController::_universal_global_event_enabled;
1019 
1020 bool
1021 JvmtiEventController::is_global_event(jvmtiEvent event_type) {
1022   assert(is_valid_event_type(event_type), "invalid event type");
1023   jlong bit_for = ((jlong)1) << (event_type - TOTAL_MIN_EVENT_TYPE_VAL);
1024   return((bit_for & GLOBAL_EVENT_BITS)!=0);
1025 }
1026 
1027 void
1028 JvmtiEventController::set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, oop thread_oop,
1029                                        jvmtiEvent event_type, bool enabled) {
1030   if (Threads::number_of_threads() == 0) {
1031     // during early VM start-up locks don't exist, but we are safely single threaded,
1032     // call the functionality without holding the JvmtiThreadState_lock.
1033     JvmtiEventControllerPrivate::set_user_enabled(env, thread, NULL, event_type, enabled);
1034   } else {
1035     Thread* current_thread = Thread::current();
1036     HandleMark hm(current_thread);
1037     Handle thread_oop_h = Handle(current_thread, thread_oop);
1038     MutexLocker mu(JvmtiThreadState_lock);
1039     JvmtiEventControllerPrivate::set_user_enabled(env, thread, thread_oop_h(), event_type, enabled);
1040   }
1041 }
1042 
1043 
1044 void
1045 JvmtiEventController::set_event_callbacks(JvmtiEnvBase *env,
1046                                           const jvmtiEventCallbacks* callbacks,
1047                                           jint size_of_callbacks) {
1048   if (Threads::number_of_threads() == 0) {
1049     // during early VM start-up locks don't exist, but we are safely single threaded,
1050     // call the functionality without holding the JvmtiThreadState_lock.
1051     JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
1052   } else {
1053     MutexLocker mu(JvmtiThreadState_lock);
1054     JvmtiEventControllerPrivate::set_event_callbacks(env, callbacks, size_of_callbacks);
1055   }
1056 }
1057 
1058 void
1059 JvmtiEventController::set_extension_event_callback(JvmtiEnvBase *env,
< prev index next >