1 /*
   2  * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /*
  26  * eventHandler
  27  *
  28  * This module handles events as they come in directly from JVMTI
  29  * and also maps them to JDI events.  JDI events are those requested
  30  * at the JDI or JDWP level and seen on those levels.  Mapping is
  31  * one-to-many, a JVMTI event may map to several JDI events, or
  32  * to none.  Part of that mapping process is filteration, which
  33  * eventFilter sub-module handles.  A JDI EventRequest corresponds
  34  * to a HandlerNode and a JDI filter to the hidden HandlerNode data
  35  * used by eventFilter.  For example, if at the JDI level the user
  36  * executed:
  37  *
  38  *   EventRequestManager erm = vm.eventRequestManager();
  39  *   BreakpointRequest bp = erm.createBreakpointRequest();
  40  *   bp.enable();
  41  *   ClassPrepareRequest req = erm.createClassPrepareRequest();
  42  *   req.enable();
  43  *   req = erm.createClassPrepareRequest();
  44  *   req.addClassFilter("Foo*");
  45  *   req.enable();
  46  *
  47  * Three handlers would be created, the first with a LocationOnly
  48  * filter and the last with a ClassMatch  filter.
  49  * When a JVMTI class prepare event for "Foobar"
  50  * comes in, the second handler will create one JDI event, the
  51  * third handler will compare the class signature, and since
  52  * it matchs create a second event.  There may also be internal
  53  * events as there are in this case, one created by the front-end
  54  * and one by the back-end.
  55  *
  56  * Each event kind has a handler chain, which is a doublely linked
  57  * list of handlers for that kind of event.
  58  */
  59 #include "util.h"
  60 #include "eventHandler.h"
  61 #include "eventHandlerRestricted.h"
  62 #include "eventFilter.h"
  63 #include "eventFilterRestricted.h"
  64 #include "standardHandlers.h"
  65 #include "threadControl.h"
  66 #include "eventHelper.h"
  67 #include "classTrack.h"
  68 #include "commonRef.h"
  69 #include "debugLoop.h"
  70 #include "signature.h"
  71 
  72 static HandlerID requestIdCounter;
  73 static jbyte currentSessionID;
  74 
  75 /* Counter of active callbacks and flag for vm_death */
  76 static int      active_callbacks   = 0;
  77 static jboolean vm_death_callback_active = JNI_FALSE;
  78 static jrawMonitorID callbackLock;
  79 static jrawMonitorID callbackBlock;
  80 
  81 /* Macros to surround callback code (non-VM_DEATH callbacks).
  82  *   Note that this just keeps a count of the non-VM_DEATH callbacks that
  83  *   are currently active, it does not prevent these callbacks from
  84  *   operating in parallel. It's the VM_DEATH callback that will wait
  85  *   for all these callbacks to finish up, so that it can report the
  86  *   VM_DEATH in a clean state.
  87  *   If the VM_DEATH callback is active in the BEGIN macro then this
  88  *   callback just blocks until released by the VM_DEATH callback.
  89  *   If the VM_DEATH callback is active in the END macro, then this
  90  *   callback will notify the VM_DEATH callback if it's the last one,
  91  *   and then block until released by the VM_DEATH callback.
  92  *   Why block? These threads are often the threads of the Java program,
  93  *   not blocking might mean that a return would continue execution of
  94  *   some java thread in the middle of VM_DEATH, this seems troubled.
  95  *
  96  *   WARNING: No not 'return' or 'goto' out of the BEGIN_CALLBACK/END_CALLBACK
  97  *            block, this will mess up the count.
  98  */
  99 
 100 #define BEGIN_CALLBACK()                                                \
 101 { /* BEGIN OF CALLBACK */                                               \
 102     jboolean bypass = JNI_TRUE;                                         \
 103     debugMonitorEnter(callbackLock); {                                  \
 104         if (vm_death_callback_active) {                                 \
 105             /* allow VM_DEATH callback to finish */                     \
 106             debugMonitorExit(callbackLock);                             \
 107             /* Now block because VM is about to die */                  \
 108             debugMonitorEnter(callbackBlock);                           \
 109             debugMonitorExit(callbackBlock);                            \
 110         } else {                                                        \
 111             active_callbacks++;                                         \
 112             bypass = JNI_FALSE;                                         \
 113             debugMonitorExit(callbackLock);                             \
 114         }                                                               \
 115     }                                                                   \
 116     if ( !bypass ) {                                                    \
 117         /* BODY OF CALLBACK CODE */
 118 
 119 #define END_CALLBACK() /* Part of bypass if body */                     \
 120         debugMonitorEnter(callbackLock); {                              \
 121             active_callbacks--;                                         \
 122             if (active_callbacks < 0) {                                 \
 123                 EXIT_ERROR(0, "Problems tracking active callbacks");    \
 124             }                                                           \
 125             if (vm_death_callback_active) {                             \
 126                 if (active_callbacks == 0) {                            \
 127                     debugMonitorNotifyAll(callbackLock);                \
 128                 }                                                       \
 129                 /* allow VM_DEATH callback to finish */                 \
 130                 debugMonitorExit(callbackLock);                         \
 131                 /* Now block because VM is about to die */              \
 132                 debugMonitorEnter(callbackBlock);                       \
 133                 debugMonitorExit(callbackBlock);                        \
 134             } else {                                                    \
 135                 debugMonitorExit(callbackLock);                         \
 136             }                                                           \
 137         }                                                               \
 138     }                                                                   \
 139 } /* END OF CALLBACK */
 140 
 141 /*
 142  * We are starting with a very simple locking scheme
 143  * for event handling.  All readers and writers of data in
 144  * the handlers[] chain must own this lock for the duration
 145  * of its use. If contention becomes a problem, we can:
 146  *
 147  * 1) create a lock per event type.
 148  * 2) move to a readers/writers approach where multiple threads
 149  * can access the chains simultaneously while reading (the
 150  * normal activity of an event callback).
 151  */
 152 static jrawMonitorID handlerLock;
 153 
 154 typedef struct HandlerChain_ {
 155     HandlerNode *first;
 156     /* add lock here */
 157 } HandlerChain;
 158 
 159 /*
 160  * This array maps event kinds to handler chains.
 161  * Protected by handlerLock.
 162  */
 163 
 164 static HandlerChain __handlers[EI_max-EI_min+1];
 165 
 166 /* Given a HandlerNode, these access our private data.
 167  */
 168 #define PRIVATE_DATA(node) \
 169        (&(((EventHandlerRestricted_HandlerNode*)(void*)(node))->private_ehpd))
 170 
 171 #define NEXT(node) (PRIVATE_DATA(node)->private_next)
 172 #define PREV(node) (PRIVATE_DATA(node)->private_prev)
 173 #define CHAIN(node) (PRIVATE_DATA(node)->private_chain)
 174 #define HANDLER_FUNCTION(node) (PRIVATE_DATA(node)->private_handlerFunction)
 175 
 176 static jclass getObjectClass(jobject object);
 177 static jvmtiError freeHandler(HandlerNode *node);
 178 
 179 static jvmtiError freeHandlerChain(HandlerChain *chain);
 180 
 181 static HandlerChain *
 182 getHandlerChain(EventIndex i)
 183 {
 184     if ( i < EI_min || i > EI_max ) {
 185         EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,"bad index for handler");
 186     }
 187     return &(__handlers[i-EI_min]);
 188 }
 189 
 190 static void
 191 insert(HandlerChain *chain, HandlerNode *node)
 192 {
 193     HandlerNode *oldHead = chain->first;
 194     NEXT(node) = oldHead;
 195     PREV(node) = NULL;
 196     CHAIN(node) = chain;
 197     if (oldHead != NULL) {
 198         PREV(oldHead) = node;
 199     }
 200     chain->first = node;
 201 }
 202 
 203 static HandlerNode *
 204 findInChain(HandlerChain *chain, HandlerID handlerID)
 205 {
 206     HandlerNode *node = chain->first;
 207     while (node != NULL) {
 208         if (node->handlerID == handlerID) {
 209             return node;
 210         }
 211         node = NEXT(node);
 212     }
 213     return NULL;
 214 }
 215 
 216 static HandlerNode *
 217 find(EventIndex ei, HandlerID handlerID)
 218 {
 219     return findInChain(getHandlerChain(ei), handlerID);
 220 }
 221 
 222 /**
 223  * Deinsert.  Safe for non-inserted nodes.
 224  */
 225 static void
 226 deinsert(HandlerNode *node)
 227 {
 228     HandlerChain *chain = CHAIN(node);
 229 
 230     if (chain == NULL) {
 231         return;
 232     }
 233     if (chain->first == node) {
 234         chain->first = NEXT(node);
 235     }
 236     if (NEXT(node) != NULL) {
 237         PREV(NEXT(node)) = PREV(node);
 238     }
 239     if (PREV(node) != NULL) {
 240         NEXT(PREV(node)) = NEXT(node);
 241     }
 242     CHAIN(node) = NULL;
 243 }
 244 
 245 jboolean
 246 eventHandlerRestricted_iterator(EventIndex ei,
 247                               IteratorFunction func, void *arg)
 248 {
 249     HandlerChain *chain;
 250     HandlerNode *node;
 251     JNIEnv *env;
 252 
 253     chain = getHandlerChain(ei);
 254     node = chain->first;
 255     env = getEnv();
 256 
 257     if ( func == NULL ) {
 258         EXIT_ERROR(AGENT_ERROR_INTERNAL,"iterator function NULL");
 259     }
 260 
 261     while (node != NULL) {
 262         if (((func)(env, node, arg))) {
 263             return JNI_TRUE;
 264         }
 265         node = NEXT(node);
 266     }
 267     return JNI_FALSE;
 268 }
 269 
 270 /* BREAKPOINT, METHOD_ENTRY and SINGLE_STEP events are covered by
 271  * the co-location of events policy. Of these three co-located
 272  * events, METHOD_ENTRY is always reported first and BREAKPOINT
 273  * is always reported last. Here are the possible combinations and
 274  * their order:
 275  *
 276  * (p1) METHOD_ENTRY, BREAKPOINT (existing)
 277  * (p2) METHOD_ENTRY, BREAKPOINT (new)
 278  * (p1) METHOD_ENTRY, SINGLE_STEP
 279  * (p1) METHOD_ENTRY, SINGLE_STEP, BREAKPOINT (existing)
 280  * (p1/p2) METHOD_ENTRY, SINGLE_STEP, BREAKPOINT (new)
 281  * (p1) SINGLE_STEP, BREAKPOINT (existing)
 282  * (p2) SINGLE_STEP, BREAKPOINT (new)
 283  *
 284  * BREAKPOINT (existing) indicates a BREAKPOINT that is set before
 285  * the other co-located event is posted. BREAKPOINT (new) indicates
 286  * a BREAKPOINT that is set after the other co-located event is
 287  * posted and before the thread has resumed execution.
 288  *
 289  * Co-location of events policy used to be implemented via
 290  * temporary BREAKPOINTs along with deferring the reporting of
 291  * non-BREAKPOINT co-located events, but the temporary BREAKPOINTs
 292  * caused performance problems on VMs where setting or clearing
 293  * BREAKPOINTs is expensive, e.g., HotSpot.
 294  *
 295  * The policy is now implemented in two phases. Phase 1: when a
 296  * METHOD_ENTRY or SINGLE_STEP event is received, if there is an
 297  * existing co-located BREAKPOINT, then the current event is
 298  * deferred. When the BREAKPOINT event is processed, the event
 299  * bag will contain the deferred METHOD_ENTRY and/or SINGLE_STEP
 300  * events along with the BREAKPOINT event. For a METHOD_ENTRY
 301  * event where there is not an existing co-located BREAKPOINT,
 302  * if SINGLE_STEP events are also enabled for the thread, then
 303  * the METHOD_ENTRY event is deferred. When the SINGLE_STEP event
 304  * is processed, the event bag will also contain the deferred
 305  * METHOD_ENTRY event. This covers each of the combinations
 306  * marked with 'p1' above.
 307  *
 308  * Phase 2: if there is no existing co-located BREAKPOINT, then the
 309  * location information for the METHOD_ENTRY or SINGLE_STEP event
 310  * is recorded in the ThreadNode. If the next event for the thread
 311  * is a co-located BREAKPOINT, then the first BREAKPOINT event will
 312  * be skipped since it cannot be delivered in the same event set.
 313  * This covers each of the combinations marked with 'p2' above.
 314  *
 315  * For the combination marked p1/p2, part of the case is handled
 316  * during phase 1 and the rest is handled during phase 2.
 317  *
 318  * The recording of information in the ThreadNode is handled in
 319  * this routine. The special handling of the next event for the
 320  * thread is handled in skipEventReport().
 321  */
 322 
 323 static jboolean
 324 deferEventReport(JNIEnv *env, jthread thread,
 325             EventIndex ei, jclass clazz, jmethodID method, jlocation location)
 326 {
 327     jboolean deferring = JNI_FALSE;
 328 
 329     switch (ei) {
 330         case EI_METHOD_ENTRY:
 331             if (!isMethodNative(method)) {
 332                 jvmtiError error;
 333                 jlocation start;
 334                 jlocation end;
 335                 error = methodLocation(method, &start, &end);
 336                 if (error == JVMTI_ERROR_NONE) {
 337                     deferring = isBreakpointSet(clazz, method, start) ||
 338                                 threadControl_getInstructionStepMode(thread)
 339                                     == JVMTI_ENABLE;
 340                     if (!deferring) {
 341                         threadControl_saveCLEInfo(env, thread, ei,
 342                                                   clazz, method, start);
 343                     }
 344                 }
 345             }
 346             break;
 347         case EI_SINGLE_STEP:
 348             deferring = isBreakpointSet(clazz, method, location);
 349             if (!deferring) {
 350                 threadControl_saveCLEInfo(env, thread, ei,
 351                                           clazz, method, location);
 352             }
 353             break;
 354         default:
 355             break;
 356     }
 357     /* TO DO: Once JVMTI supports a way to know if we're
 358      * at the end of a method, we should check here for
 359      * break and step events which precede a method exit
 360      * event.
 361      */
 362     return deferring;
 363 }
 364 
 365 /* Handle phase 2 of the co-located events policy. See detailed
 366  * comments in deferEventReport() above.
 367  */
 368 static jboolean
 369 skipEventReport(JNIEnv *env, jthread thread, EventIndex ei,
 370                         jclass clazz, jmethodID method, jlocation location)
 371 {
 372     jboolean skipping = JNI_FALSE;
 373 
 374     if (ei == EI_BREAKPOINT) {
 375         if (threadControl_cmpCLEInfo(env, thread, clazz, method, location)) {
 376             LOG_MISC(("Co-located breakpoint event found: "
 377                 "%s,thread=%p,clazz=%p,method=%p,location=%d",
 378                 eventText(ei), thread, clazz, method, location));
 379             skipping = JNI_TRUE;
 380         }
 381     }
 382 
 383     threadControl_clearCLEInfo(env, thread);
 384 
 385     return skipping;
 386 }
 387 
 388 static void
 389 reportEvents(JNIEnv *env, jbyte sessionID, jthread thread, EventIndex ei,
 390              jclass clazz, jmethodID method, jlocation location,
 391              struct bag *eventBag)
 392 {
 393     jbyte suspendPolicy;
 394     jboolean invoking;
 395 
 396     if (bagSize(eventBag) < 1) {
 397         return;
 398     }
 399 
 400     /*
 401      * Never report events before initialization completes
 402      */
 403     if (!debugInit_isInitComplete()) {
 404         return;
 405     }
 406 
 407     /*
 408      * Check to see if we should skip reporting this event due to
 409      * co-location of events policy.
 410      */
 411     if (thread != NULL &&
 412            skipEventReport(env, thread, ei, clazz, method, location)) {
 413         LOG_MISC(("event report being skipped: "
 414             "ei=%s,thread=%p,clazz=%p,method=%p,location=%d",
 415             eventText(ei), thread, clazz, method, location));
 416         bagDeleteAll(eventBag);
 417         return;
 418     }
 419 
 420     /* We delay the reporting of some events so that they can be
 421      * properly grouped into event sets with upcoming events. If
 422      * the reporting is to be deferred, the event commands remain
 423      * in the event bag until a subsequent event occurs.  Event is
 424      * NULL for synthetic events (e.g. unload).
 425      */
 426     if (thread == NULL
 427          || !deferEventReport(env, thread, ei,
 428                         clazz, method, location)) {
 429         struct bag *completedBag = bagDup(eventBag);
 430         bagDeleteAll(eventBag);
 431         if (completedBag == NULL) {
 432             /*
 433              * TO DO: Report, but don't terminate?
 434              */
 435             return;
 436         } else {
 437             suspendPolicy = eventHelper_reportEvents(sessionID, completedBag);
 438             if (thread != NULL && suspendPolicy != JDWP_SUSPEND_POLICY(NONE)) {
 439                 do {
 440                     /* The events have been reported and this
 441                      * thread is about to continue, but it may
 442                      * have been started up just to perform a
 443                      * requested method invocation. If so, we do
 444                      * the invoke now and then stop again waiting
 445                      * for another continue. By then another
 446                      * invoke request can be in place, so there is
 447                      * a loop around this code.
 448                      */
 449                     invoking = invoker_doInvoke(thread);
 450                     if (invoking) {
 451                         eventHelper_reportInvokeDone(sessionID, thread);
 452                     }
 453                 } while (invoking);
 454             }
 455             bagDestroyBag(completedBag);
 456         }
 457     }
 458 }
 459 
 460 /* A bagEnumerateFunction.  Create a synthetic class unload event
 461  * for every class no longer present.  Analogous to event_callback
 462  * combined with a handler in a unload specific (no event
 463  * structure) kind of way.
 464  */
 465 static jboolean
 466 synthesizeUnloadEvent(void *signatureVoid, void *envVoid)
 467 {
 468     JNIEnv *env = (JNIEnv *)envVoid;
 469     char *signature = *(char **)signatureVoid;
 470     char *classname;
 471     HandlerNode *node;
 472     jbyte eventSessionID = currentSessionID;
 473     struct bag *eventBag = eventHelper_createEventBag();
 474 
 475     /* TO DO: Report null error, but don't die */
 476     JDI_ASSERT(eventBag != NULL);
 477 
 478     /* Signature needs to last, so convert extra copy to
 479      * classname
 480      */
 481     classname = jvmtiAllocate((int)strlen(signature)+1);
 482     (void)strcpy(classname, signature);
 483     convertSignatureToClassname(classname);
 484 
 485     debugMonitorEnter(handlerLock);
 486 
 487     node = getHandlerChain(EI_GC_FINISH)->first;
 488     while (node != NULL) {
 489         /* save next so handlers can remove themselves */
 490         HandlerNode *next = NEXT(node);
 491         jboolean shouldDelete;
 492 
 493         if (eventFilterRestricted_passesUnloadFilter(env, classname,
 494                                                      node,
 495                                                      &shouldDelete)) {
 496             /* There may be multiple handlers, the signature will
 497              * be freed when the event helper thread has written
 498              * it.  So each event needs a separate allocation.
 499              */
 500             char *durableSignature = jvmtiAllocate((int)strlen(signature)+1);
 501             (void)strcpy(durableSignature, signature);
 502 
 503             eventHelper_recordClassUnload(node->handlerID,
 504                                           durableSignature,
 505                                           eventBag);
 506         }
 507         if (shouldDelete) {
 508             /* We can safely free the node now that we are done
 509              * using it.
 510              */
 511             (void)freeHandler(node);
 512         }
 513         node = next;
 514     }
 515 
 516     debugMonitorExit(handlerLock);
 517 
 518     if (eventBag != NULL) {
 519         reportEvents(env, eventSessionID, (jthread)NULL, 0,
 520                             (jclass)NULL, (jmethodID)NULL, 0, eventBag);
 521 
 522         /*
 523          * bag was created locally, destroy it here.
 524          */
 525         bagDestroyBag(eventBag);
 526     }
 527 
 528     jvmtiDeallocate(signature);
 529     jvmtiDeallocate(classname);
 530 
 531     return JNI_TRUE;
 532 }
 533 
 534 /* Garbage Collection Happened */
 535 static unsigned int garbageCollected = 0;
 536 
 537 /*
 538  * Run the event through each HandlerNode's filter, and if it passes, call the HandlerNode's
 539  * HandlerFunction for the event, and then report all accumulated events to the debugger.
 540  */
 541 static void
 542 filterAndHandleEvent(JNIEnv *env, EventInfo *evinfo, EventIndex ei,
 543                      struct bag *eventBag, jbyte eventSessionID)
 544 {
 545     debugMonitorEnter(handlerLock);
 546     {
 547         HandlerNode *node;
 548         char        *classname;
 549 
 550         /* We must keep track of all classes prepared to know what's unloaded */
 551         if (evinfo->ei == EI_CLASS_PREPARE) {
 552             classTrack_addPreparedClass(env, evinfo->clazz);
 553         }
 554 
 555         node = getHandlerChain(ei)->first;
 556         classname = getClassname(evinfo->clazz);
 557 
 558         /* Filter the event over each handler node. */
 559         while (node != NULL) {
 560             /* Save next so handlers can remove themselves. */
 561             HandlerNode *next = NEXT(node);
 562             jboolean shouldDelete;
 563 
 564             if (eventFilterRestricted_passesFilter(env, classname,
 565                                                    evinfo, node,
 566                                                    &shouldDelete)) {
 567                 HandlerFunction func = HANDLER_FUNCTION(node);
 568                 if (func == NULL) {
 569                     EXIT_ERROR(AGENT_ERROR_INTERNAL,"handler function NULL");
 570                 }
 571                 /* Handle the event by calling the event handler. */
 572                 (*func)(env, evinfo, node, eventBag);
 573             }
 574             if (shouldDelete) {
 575                 /* We can safely free the node now that we are done using it. */
 576                 (void)freeHandler(node);
 577             }
 578             node = next;
 579         }
 580         jvmtiDeallocate(classname);
 581     }
 582     debugMonitorExit(handlerLock);
 583 
 584     /*
 585      * The events destined for the debugger were accumulated in eventBag. Report all these events.
 586      */
 587     if (eventBag != NULL) {
 588         reportEvents(env, eventSessionID, evinfo->thread, evinfo->ei,
 589                      evinfo->clazz, evinfo->method, evinfo->location, eventBag);
 590     }
 591     // vthread fixme: if we didn't have any events to report, we should allow the vthread
 592     // ThreadNode to be released at this point.
 593 
 594 }
 595 
 596 /*
 597  * The JVMTI generic event callback. Each event is passed to a sequence of
 598  * handlers in a chain until the chain ends or one handler
 599  * consumes the event.
 600  */
 601 static void
 602 event_callback(JNIEnv *env, EventInfo *evinfo)
 603 {
 604     struct bag *eventBag;
 605     jbyte eventSessionID = currentSessionID; /* session could change */
 606     jthrowable currentException;
 607     jthread thread;
 608     EventIndex ei = evinfo->ei;
 609 
 610     LOG_MISC(("event_callback(): ei=%s", eventText(ei)));
 611     log_debugee_location("event_callback()", evinfo->thread, evinfo->method, evinfo->location);
 612 
 613     /* We want to preserve any current exception that might get
 614      * wiped out during event handling (e.g. JNI calls). We have
 615      * to rely on space for the local reference on the current
 616      * frame because doing a PushLocalFrame here might itself
 617      * generate an exception.
 618      */
 619     currentException = JNI_FUNC_PTR(env,ExceptionOccurred)(env);
 620     JNI_FUNC_PTR(env,ExceptionClear)(env);
 621 
 622     /* See if a garbage collection finish event happened earlier.
 623      *
 624      * Note: The "if" is an optimization to avoid entering the lock on every
 625      *       event; garbageCollected may be zapped before we enter
 626      *       the lock but then this just becomes one big no-op.
 627      */
 628     if ( garbageCollected > 0 ) {
 629         struct bag *unloadedSignatures = NULL;
 630 
 631         /* We want to compact the hash table of all
 632          * objects sent to the front end by removing objects that have
 633          * been collected.
 634          */
 635         commonRef_compact();
 636 
 637         /* We also need to simulate the class unload events. */
 638 
 639         debugMonitorEnter(handlerLock);
 640 
 641         /* Clear garbage collection counter */
 642         garbageCollected = 0;
 643 
 644         /* Analyze which class unloads occurred */
 645         unloadedSignatures = classTrack_processUnloads(env);
 646 
 647         debugMonitorExit(handlerLock);
 648 
 649         /* Generate the synthetic class unload events and/or just cleanup.  */
 650         if ( unloadedSignatures != NULL ) {
 651             (void)bagEnumerateOver(unloadedSignatures, synthesizeUnloadEvent,
 652                              (void *)env);
 653             bagDestroyBag(unloadedSignatures);
 654         }
 655     }
 656 
 657     thread = evinfo->thread;
 658     if (thread != NULL) {
 659         if (gdata->vthreadsSupported) {
 660             evinfo->is_vthread = isVThread(thread);
 661         }
 662 
 663         /*
 664          * Record the fact that we're entering an event
 665          * handler so that thread operations (status, interrupt,
 666          * stop) can be done correctly and so that thread
 667          * resources can be allocated.  This must be done before
 668          * grabbing any locks.
 669          */
 670         eventBag = threadControl_onEventHandlerEntry(eventSessionID, evinfo, currentException);
 671         if ( eventBag == NULL ) {
 672             jboolean invoking;
 673             do {
 674                 /* The event has been 'handled' and this
 675                  * thread is about to continue, but it may
 676                  * have been started up just to perform a
 677                  * requested method invocation. If so, we do
 678                  * the invoke now and then stop again waiting
 679                  * for another continue. By then another
 680                  * invoke request can be in place, so there is
 681                  * a loop around this code.
 682                  */
 683                 invoking = invoker_doInvoke(thread);
 684                 if (invoking) {
 685                     eventHelper_reportInvokeDone(eventSessionID, thread);
 686                 }
 687             } while (invoking);
 688             return; /* Do nothing, event was consumed */
 689         }
 690     } else {
 691         eventBag = eventHelper_createEventBag();
 692         if (eventBag == NULL) {
 693             /*
 694              * TO DO: Report, but don't die
 695              */
 696             eventBag = NULL;  /* to shut up lint */
 697         }
 698     }
 699 
 700     /* We want the vthread start/end events to mimic thread start/end events */
 701     /* vthread fixme: We can remove this now because cbVThreadStart/End set to THREAD_START/END. */
 702     if (ei == EI_VIRTUAL_THREAD_START) {
 703         ei = EI_THREAD_START;
 704         JDI_ASSERT(JNI_FALSE);
 705     }
 706     if (ei == EI_VIRTUAL_THREAD_END) {
 707         ei = EI_THREAD_END;
 708         JDI_ASSERT(JNI_FALSE);
 709     }
 710 
 711     if (gdata->vthreadsSupported && gdata->trackAllVThreads) {
 712         /* Add the vthread if we haven't added it before. */
 713         if (evinfo->is_vthread && !threadControl_isKnownVThread(thread)) {
 714             // vthread fixme: we can actually get rid of the threadControl_addVThread call now since
 715             // the call to threadControl_onEventHandlerEntry above should always end up adding
 716             // the vthread. Leave in place with an assert for now just to make sure.
 717             JDI_ASSERT(threadControl_isKnownVThread(thread));
 718             threadControl_addVThread(thread);
 719         }
 720     }
 721 
 722     if (ei == EI_THREAD_END && evinfo->is_vthread && !gdata->notifyVThreads) {
 723         /*
 724          * Skip this event since we are not notifying the debugger of vthread START/END
 725          * events. Note special handling of EI_THREAD_START is in cbVthreadStart().
 726          */
 727     } else {
 728         filterAndHandleEvent(env, evinfo, ei, eventBag, eventSessionID);
 729     }
 730 
 731     /* we are continuing after VMDeathEvent - now we are dead */
 732     if (evinfo->ei == EI_VM_DEATH) {
 733         gdata->vmDead = JNI_TRUE;
 734     }
 735 
 736     /*
 737      * If the bag was created locally, destroy it here.
 738      */
 739     if (thread == NULL) {
 740         bagDestroyBag(eventBag);
 741     }
 742 
 743     /* Always restore any exception that was set beforehand.  If
 744      * there is a pending async exception, StopThread will be
 745      * called from threadControl_onEventHandlerExit immediately
 746      * below.  Depending on VM implementation and state, the async
 747      * exception might immediately overwrite the currentException,
 748      * or it might be delayed until later.  */
 749     if (currentException != NULL) {
 750         JNI_FUNC_PTR(env,Throw)(env, currentException);
 751     } else {
 752         JNI_FUNC_PTR(env,ExceptionClear)(env);
 753     }
 754 
 755     /*
 756      * Release thread resources and perform any delayed operations.
 757      */
 758     if (thread != NULL) {
 759         threadControl_onEventHandlerExit(evinfo->ei, thread, eventBag);
 760     }
 761 }
 762 
 763 /* Returns a local ref to the declaring class for an object. */
 764 static jclass
 765 getObjectClass(jobject object)
 766 {
 767     jclass clazz;
 768     JNIEnv *env = getEnv();
 769 
 770     clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);
 771 
 772     return clazz;
 773 }
 774 
 775 /* Returns a local ref to the declaring class for a method, or NULL. */
 776 jclass
 777 getMethodClass(jvmtiEnv *jvmti_env, jmethodID method)
 778 {
 779     jclass clazz = NULL;
 780     jvmtiError error;
 781 
 782     if ( method == NULL ) {
 783         return NULL;
 784     }
 785     error = methodClass(method, &clazz);
 786     if ( error != JVMTI_ERROR_NONE ) {
 787         EXIT_ERROR(error,"Can't get jclass for a methodID, invalid?");
 788         return NULL;
 789     }
 790     return clazz;
 791 }
 792 
 793 /* Event callback for JVMTI_EVENT_SINGLE_STEP */
 794 static void JNICALL
 795 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv *env,
 796                         jthread thread, jmethodID method, jlocation location)
 797 {
 798     EventInfo info;
 799 
 800     LOG_CB(("cbSingleStep: thread=%p", thread));
 801 
 802     BEGIN_CALLBACK() {
 803         (void)memset(&info,0,sizeof(info));
 804         info.ei         = EI_SINGLE_STEP;
 805         info.thread     = thread;
 806         info.clazz      = getMethodClass(jvmti_env, method);
 807         info.method     = method;
 808         info.location   = location;
 809         event_callback(env, &info);
 810     } END_CALLBACK();
 811 
 812     LOG_MISC(("END cbSingleStep"));
 813 }
 814 
 815 /* Event callback for JVMTI_EVENT_BREAKPOINT */
 816 static void JNICALL
 817 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv *env,
 818                         jthread thread, jmethodID method, jlocation location)
 819 {
 820     EventInfo info;
 821 
 822     LOG_CB(("cbBreakpoint: thread=%p", thread));
 823 
 824     BEGIN_CALLBACK() {
 825         (void)memset(&info,0,sizeof(info));
 826         info.ei         = EI_BREAKPOINT;
 827         info.thread     = thread;
 828         info.clazz      = getMethodClass(jvmti_env, method);
 829         info.method     = method;
 830         info.location   = location;
 831         event_callback(env, &info);
 832     } END_CALLBACK();
 833 
 834     LOG_MISC(("END cbBreakpoint"));
 835 }
 836 
 837 /* Event callback for JVMTI_EVENT_FRAME_POP */
 838 static void JNICALL
 839 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv *env,
 840                         jthread thread, jmethodID method,
 841                         jboolean wasPoppedByException)
 842 {
 843     EventInfo info;
 844 
 845     /* JDWP does not return these events when popped due to an exception. */
 846     if ( wasPoppedByException ) {
 847         return;
 848     }
 849 
 850     LOG_CB(("cbFramePop: thread=%p", thread));
 851 
 852     BEGIN_CALLBACK() {
 853         (void)memset(&info,0,sizeof(info));
 854         info.ei         = EI_FRAME_POP;
 855         info.thread     = thread;
 856         info.clazz      = getMethodClass(jvmti_env, method);
 857         info.method     = method;
 858         event_callback(env, &info);
 859     } END_CALLBACK();
 860 
 861     LOG_MISC(("END cbFramePop"));
 862 }
 863 
 864 /* Event callback for JVMTI_EVENT_EXCEPTION */
 865 static void JNICALL
 866 cbException(jvmtiEnv *jvmti_env, JNIEnv *env,
 867                         jthread thread, jmethodID method,
 868                         jlocation location, jobject exception,
 869                         jmethodID catch_method, jlocation catch_location)
 870 {
 871     EventInfo info;
 872 
 873     LOG_CB(("cbException: thread=%p", thread));
 874 
 875     BEGIN_CALLBACK() {
 876         (void)memset(&info,0,sizeof(info));
 877         info.ei                         = EI_EXCEPTION;
 878         info.thread                     = thread;
 879         info.clazz                      = getMethodClass(jvmti_env, method);
 880         info.method                     = method;
 881         info.location                   = location;
 882         info.object                     = exception;
 883         info.u.exception.catch_clazz    = getMethodClass(jvmti_env, catch_method);
 884         info.u.exception.catch_method   = catch_method;
 885         info.u.exception.catch_location = catch_location;
 886         event_callback(env, &info);
 887     } END_CALLBACK();
 888 
 889     LOG_MISC(("END cbException"));
 890 }
 891 
 892 /* Event callback for JVMTI_EVENT_THREAD_START */
 893 static void JNICALL
 894 cbThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
 895 {
 896     EventInfo info;
 897 
 898     LOG_CB(("cbThreadStart: thread=%p", thread));
 899 
 900     BEGIN_CALLBACK() {
 901         (void)memset(&info,0,sizeof(info));
 902         info.ei         = EI_THREAD_START;
 903         info.thread     = thread;
 904         event_callback(env, &info);
 905     } END_CALLBACK();
 906 
 907     LOG_MISC(("END cbThreadStart"));
 908 }
 909 
 910 /* Event callback for JVMTI_EVENT_THREAD_END */
 911 static void JNICALL
 912 cbThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
 913 {
 914     EventInfo info;
 915 
 916     LOG_CB(("cbThreadEnd: thread=%p", thread));
 917 
 918     BEGIN_CALLBACK() {
 919         (void)memset(&info,0,sizeof(info));
 920         info.ei         = EI_THREAD_END;
 921         info.thread     = thread;
 922         event_callback(env, &info);
 923     } END_CALLBACK();
 924 
 925     LOG_MISC(("END cbThreadEnd"));
 926 }
 927 
 928 /* Event callback for JVMTI_EVENT_CLASS_PREPARE */
 929 static void JNICALL
 930 cbClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *env,
 931                         jthread thread, jclass klass)
 932 {
 933     EventInfo info;
 934 
 935     LOG_CB(("cbClassPrepare: thread=%p", thread));
 936 
 937     BEGIN_CALLBACK() {
 938         (void)memset(&info,0,sizeof(info));
 939         info.ei         = EI_CLASS_PREPARE;
 940         info.thread     = thread;
 941         info.clazz      = klass;
 942         event_callback(env, &info);
 943     } END_CALLBACK();
 944 
 945     LOG_MISC(("END cbClassPrepare"));
 946 }
 947 
 948 /* Event callback for JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
 949 static void JNICALL
 950 cbGarbageCollectionFinish(jvmtiEnv *jvmti_env)
 951 {
 952     LOG_CB(("cbGarbageCollectionFinish"));
 953     ++garbageCollected;
 954     LOG_MISC(("END cbGarbageCollectionFinish"));
 955 }
 956 
 957 /* Event callback for JVMTI_EVENT_CLASS_LOAD */
 958 static void JNICALL
 959 cbClassLoad(jvmtiEnv *jvmti_env, JNIEnv *env,
 960                         jthread thread, jclass klass)
 961 {
 962     EventInfo info;
 963 
 964     LOG_CB(("cbClassLoad: thread=%p", thread));
 965 
 966     BEGIN_CALLBACK() {
 967         (void)memset(&info,0,sizeof(info));
 968         info.ei         = EI_CLASS_LOAD;
 969         info.thread     = thread;
 970         info.clazz      = klass;
 971         event_callback(env, &info);
 972     } END_CALLBACK();
 973 
 974     LOG_MISC(("END cbClassLoad"));
 975 }
 976 
 977 /* Event callback for JVMTI_EVENT_FIELD_ACCESS */
 978 static void JNICALL
 979 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv *env,
 980                         jthread thread, jmethodID method,
 981                         jlocation location, jclass field_klass,
 982                         jobject object, jfieldID field)
 983 {
 984     EventInfo info;
 985 
 986     LOG_CB(("cbFieldAccess: thread=%p", thread));
 987 
 988     BEGIN_CALLBACK() {
 989         (void)memset(&info,0,sizeof(info));
 990         info.ei                         = EI_FIELD_ACCESS;
 991         info.thread                     = thread;
 992         info.clazz                      = getMethodClass(jvmti_env, method);
 993         info.method                     = method;
 994         info.location                   = location;
 995         info.u.field_access.field_clazz = field_klass;
 996         info.object                     = object;
 997         info.u.field_access.field       = field;
 998         event_callback(env, &info);
 999     } END_CALLBACK();
1000 
1001     LOG_MISC(("END cbFieldAccess"));
1002 }
1003 
1004 /* Event callback for JVMTI_EVENT_FIELD_MODIFICATION */
1005 static void JNICALL
1006 cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv *env,
1007         jthread thread, jmethodID method,
1008         jlocation location, jclass field_klass, jobject object, jfieldID field,
1009         char signature_type, jvalue new_value)
1010 {
1011     EventInfo info;
1012 
1013     LOG_CB(("cbFieldModification: thread=%p", thread));
1014 
1015     BEGIN_CALLBACK() {
1016         (void)memset(&info,0,sizeof(info));
1017         info.ei                                 = EI_FIELD_MODIFICATION;
1018         info.thread                             = thread;
1019         info.clazz                              = getMethodClass(jvmti_env, method);
1020         info.method                             = method;
1021         info.location                           = location;
1022         info.u.field_modification.field         = field;
1023         info.u.field_modification.field_clazz   = field_klass;
1024         info.object                             = object;
1025         info.u.field_modification.signature_type= signature_type;
1026         info.u.field_modification.new_value     = new_value;
1027         event_callback(env, &info);
1028     } END_CALLBACK();
1029 
1030     LOG_MISC(("END cbFieldModification"));
1031 }
1032 
1033 /* Event callback for JVMTI_EVENT_EXCEPTION_CATCH */
1034 static void JNICALL
1035 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread,
1036         jmethodID method, jlocation location, jobject exception)
1037 {
1038     EventInfo info;
1039 
1040     LOG_CB(("cbExceptionCatch: thread=%p", thread));
1041 
1042     BEGIN_CALLBACK() {
1043         (void)memset(&info,0,sizeof(info));
1044         info.ei         = EI_EXCEPTION_CATCH;
1045         info.thread     = thread;
1046         info.clazz      = getMethodClass(jvmti_env, method);
1047         info.method     = method;
1048         info.location   = location;
1049         info.object     = exception;
1050         event_callback(env, &info);
1051     } END_CALLBACK();
1052 
1053     LOG_MISC(("END cbExceptionCatch"));
1054 }
1055 
1056 /* Event callback for JVMTI_EVENT_METHOD_ENTRY */
1057 static void JNICALL
1058 cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv *env,
1059                         jthread thread, jmethodID method)
1060 {
1061     EventInfo info;
1062 
1063     LOG_CB(("cbMethodEntry: thread=%p", thread));
1064 
1065     BEGIN_CALLBACK() {
1066         (void)memset(&info,0,sizeof(info));
1067         info.ei         = EI_METHOD_ENTRY;
1068         info.thread     = thread;
1069         info.clazz      = getMethodClass(jvmti_env, method);
1070         info.method     = method;
1071         event_callback(env, &info);
1072     } END_CALLBACK();
1073 
1074     LOG_MISC(("END cbMethodEntry"));
1075 }
1076 
1077 /* Event callback for JVMTI_EVENT_METHOD_EXIT */
1078 static void JNICALL
1079 cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv *env,
1080                         jthread thread, jmethodID method,
1081                         jboolean wasPoppedByException, jvalue return_value)
1082 {
1083     EventInfo info;
1084 
1085     /* JDWP does not return these events when popped due to an exception. */
1086     if ( wasPoppedByException ) {
1087         return;
1088     }
1089 
1090     LOG_CB(("cbMethodExit: thread=%p", thread));
1091 
1092     BEGIN_CALLBACK() {
1093         (void)memset(&info,0,sizeof(info));
1094         info.ei         = EI_METHOD_EXIT;
1095         info.thread     = thread;
1096         info.clazz      = getMethodClass(jvmti_env, method);
1097         info.method     = method;
1098         info.u.method_exit.return_value = return_value;
1099         event_callback(env, &info);
1100     } END_CALLBACK();
1101 
1102     LOG_MISC(("END cbMethodExit"));
1103 }
1104 
1105 /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
1106 static void JNICALL
1107 cbMonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv *env,
1108                         jthread thread, jobject object)
1109 {
1110     EventInfo info;
1111     jvmtiError error;
1112     jmethodID  method;
1113     jlocation  location;
1114 
1115     LOG_CB(("cbMonitorContendedEnter: thread=%p", thread));
1116 
1117     BEGIN_CALLBACK() {
1118         (void)memset(&info,0,sizeof(info));
1119         info.ei         = EI_MONITOR_CONTENDED_ENTER;
1120         info.thread     = thread;
1121         info.object     = object;
1122         /* get current location of contended monitor enter */
1123         error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
1124                 (gdata->jvmti, thread, 0, &method, &location);
1125         if (error == JVMTI_ERROR_NONE) {
1126             info.location = location;
1127             info.method   = method;
1128             info.clazz    = getMethodClass(jvmti_env, method);
1129         } else {
1130             info.location = -1;
1131         }
1132         event_callback(env, &info);
1133     } END_CALLBACK();
1134 
1135     LOG_MISC(("END cbMonitorContendedEnter"));
1136 }
1137 
1138 /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
1139 static void JNICALL
1140 cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv *env,
1141                         jthread thread, jobject object)
1142 {
1143     EventInfo info;
1144     jvmtiError error;
1145     jmethodID  method;
1146     jlocation  location;
1147 
1148     LOG_CB(("cbMonitorContendedEntered: thread=%p", thread));
1149 
1150     BEGIN_CALLBACK() {
1151         (void)memset(&info,0,sizeof(info));
1152         info.ei         = EI_MONITOR_CONTENDED_ENTERED;
1153         info.thread     = thread;
1154         info.object     = object;
1155         /* get current location of contended monitor enter */
1156         error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
1157                 (gdata->jvmti, thread, 0, &method, &location);
1158         if (error == JVMTI_ERROR_NONE) {
1159             info.location = location;
1160             info.method   = method;
1161             info.clazz    = getMethodClass(jvmti_env, method);
1162         } else {
1163             info.location = -1;
1164         }
1165         event_callback(env, &info);
1166     } END_CALLBACK();
1167 
1168     LOG_MISC(("END cbMonitorContendedEntered"));
1169 }
1170 
1171 /* Event callback for JVMTI_EVENT_MONITOR_WAIT */
1172 static void JNICALL
1173 cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv *env,
1174                         jthread thread, jobject object,
1175                         jlong timeout)
1176 {
1177     EventInfo info;
1178     jvmtiError error;
1179     jmethodID  method;
1180     jlocation  location;
1181 
1182     LOG_CB(("cbMonitorWait: thread=%p", thread));
1183 
1184     BEGIN_CALLBACK() {
1185         (void)memset(&info,0,sizeof(info));
1186         info.ei         = EI_MONITOR_WAIT;
1187         info.thread     = thread;
1188         info.object     = object;
1189         /* The info.clazz is used for both class filtering and for location info.
1190          * For monitor wait event the class filtering is done for class of monitor
1191          * object. So here info.clazz is set to class of monitor object here and it
1192          * is reset to class of method before writing location info.
1193          * See writeMonitorEvent in eventHelper.c
1194          */
1195         info.clazz      = getObjectClass(object);
1196         info.u.monitor.timeout = timeout;
1197 
1198         /* get location of monitor wait() method. */
1199         error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
1200                 (gdata->jvmti, thread, 0, &method, &location);
1201         if (error == JVMTI_ERROR_NONE) {
1202             info.location = location;
1203             info.method   = method;
1204         } else {
1205             info.location = -1;
1206         }
1207         event_callback(env, &info);
1208     } END_CALLBACK();
1209 
1210     LOG_MISC(("END cbMonitorWait"));
1211 }
1212 
1213 /* Event callback for JVMTI_EVENT_MONITOR_WAIT */
1214 static void JNICALL
1215 cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv *env,
1216                         jthread thread, jobject object,
1217                         jboolean timed_out)
1218 {
1219     EventInfo info;
1220     jvmtiError error;
1221     jmethodID  method;
1222     jlocation  location;
1223 
1224     LOG_CB(("cbMonitorWaited: thread=%p", thread));
1225 
1226     BEGIN_CALLBACK() {
1227         (void)memset(&info,0,sizeof(info));
1228         info.ei         = EI_MONITOR_WAITED;
1229         info.thread     = thread;
1230         info.object     = object;
1231         /* The info.clazz is used for both class filtering and for location info.
1232          * For monitor waited event the class filtering is done for class of monitor
1233          * object. So here info.clazz is set to class of monitor object here and it
1234          * is reset to class of method before writing location info.
1235          * See writeMonitorEvent in eventHelper.c
1236          */
1237         info.clazz      = getObjectClass(object);
1238         info.u.monitor.timed_out = timed_out;
1239 
1240         /* get location of monitor wait() method */
1241         error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
1242                 (gdata->jvmti, thread, 0, &method, &location);
1243         if (error == JVMTI_ERROR_NONE) {
1244             info.location = location;
1245             info.method   = method;
1246         } else {
1247             info.location = -1;
1248         }
1249         event_callback(env, &info);
1250     } END_CALLBACK();
1251 
1252     LOG_MISC(("END cbMonitorWaited"));
1253 }
1254 
1255 /* Event callback for JVMTI_EVENT_VM_INIT */
1256 static void JNICALL
1257 cbVMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
1258 {
1259     EventInfo info;
1260 
1261     LOG_CB(("cbVMInit"));
1262 
1263     BEGIN_CALLBACK() {
1264         (void)memset(&info,0,sizeof(info));
1265         info.ei         = EI_VM_INIT;
1266         info.thread     = thread;
1267         event_callback(env, &info);
1268     } END_CALLBACK();
1269 
1270     LOG_MISC(("END cbVMInit"));
1271 }
1272 
1273 /* Event callback for JVMTI_EVENT_VM_DEATH */
1274 static void JNICALL
1275 cbVMDeath(jvmtiEnv *jvmti_env, JNIEnv *env)
1276 {
1277     jvmtiError error;
1278     EventInfo info;
1279     LOG_CB(("cbVMDeath"));
1280 
1281     /* Setting this flag is needed by findThread(). It's ok to set it before
1282        the callbacks are cleared.*/
1283     gdata->jvmtiCallBacksCleared = JNI_TRUE;
1284 
1285     /* Clear out ALL callbacks at this time, we don't want any more. */
1286     /*    This should prevent any new BEGIN_CALLBACK() calls. */
1287     (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
1288     error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
1289                 (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
1290     if (error != JVMTI_ERROR_NONE) {
1291         EXIT_ERROR(error,"Can't clear event callbacks on vm death");
1292     }
1293 
1294     /* Now that no new callbacks will be made, we need to wait for the ones
1295      *   that are still active to complete.
1296      *   The BEGIN_CALLBACK/END_CALLBACK macros implement the VM_DEATH
1297      *   callback protocol. Once the callback table is cleared (above),
1298      *   we can have callback threads in different stages:
1299      *   1) after callback function entry and before BEGIN_CALLBACK
1300      *      macro; we catch these threads with callbackBlock in the
1301      *      BEGIN_CALLBACK macro
1302      *   2) after BEGIN_CALLBACK macro and before END_CALLBACK macro; we
1303      *      catch these threads with callbackBlock in the END_CALLBACK
1304      *      macro
1305      *   3) after END_CALLBACK macro; these threads have made it past
1306      *      callbackBlock and callbackLock and don't count as active
1307      *
1308      *   Since some of the callback threads could be blocked or suspended
1309      *   we will resume all threads suspended by the debugger for a short
1310      *   time to flush out all callbacks. Note that the callback threads
1311      *   will block from returning to the VM in both macros. Some threads
1312      *   not associated with callbacks, but suspended by the debugger may
1313      *   continue on, but not for long.
1314      *   Once the last callback finishes, it will notify this thread and
1315      *   we fall out of the loop below and actually process the VM_DEATH
1316      *   event.
1317      */
1318     debugMonitorEnter(callbackBlock); {
1319         debugMonitorEnter(callbackLock); {
1320             vm_death_callback_active = JNI_TRUE;
1321             (void)threadControl_resumeAll();
1322             while (active_callbacks > 0) {
1323                 /* wait for active CALLBACKs to check in (and block) */
1324                 debugMonitorWait(callbackLock);
1325             }
1326         } debugMonitorExit(callbackLock);
1327 
1328         /* Only now should we actually process the VM death event */
1329         (void)memset(&info,0,sizeof(info));
1330         info.ei                 = EI_VM_DEATH;
1331         event_callback(env, &info);
1332 
1333         /* Here we unblock all the callbacks and let them return to the
1334          *   VM.  It's not clear this is necessary, but leaving threads
1335          *   blocked doesn't seem like a good idea. They don't have much
1336          *   life left anyway.
1337          */
1338     } debugMonitorExit(callbackBlock);
1339 
1340     /*
1341      * The VM will die soon after the completion of this callback -
1342      * we synchronize with both the command loop and the debug loop
1343      * for a more orderly shutdown.
1344      */
1345     commandLoop_sync();
1346     debugLoop_sync();
1347 
1348     LOG_MISC(("END cbVMDeath"));
1349 }
1350 
1351 /* Event callback for JVMTI_EVENT_VIRTUAL_THREAD_START */
1352 static void JNICALL
1353 cbVThreadStart(jvmtiEnv *jvmti_env, JNIEnv *env, jthread vthread)
1354 {
1355     EventInfo info;
1356 
1357     LOG_CB(("cbVThreadStart: vthread=%p", vthread));
1358     /*tty_message("cbVThreadStart: vthread=%p", vthread);*/
1359     JDI_ASSERT(gdata->vthreadsSupported);
1360 
1361     /*
1362      * Now would be a good time to cache the ThreadGroup for vthreads (carrier threads)
1363      * if we haven't already.
1364      */
1365     if (gdata->vthreadThreadGroup == NULL) {
1366         jvmtiThreadInfo info;
1367         jvmtiError error;
1368 
1369         (void)memset(&info, 0, sizeof(info));
1370         error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
1371             (gdata->jvmti, vthread, &info);
1372 
1373         if (error != JVMTI_ERROR_NONE) {
1374             EXIT_ERROR(error, "could not get vthread ThreadGroup");
1375         } else {
1376             debugMonitorEnter(callbackBlock); /* vthread fixme: any monitor will do, but there probably is a better choice. */
1377             /* Make sure there wasn't a race before setting. saveGlobalRef() will assert if the
1378              * target is not NULL. */
1379             if (gdata->vthreadThreadGroup == NULL) {
1380                 saveGlobalRef(env, info.thread_group, &gdata->vthreadThreadGroup);
1381             }
1382             debugMonitorExit(callbackBlock);
1383         }
1384     }
1385 
1386     /* Ignore VIRTUAL_THREAD_START events unless we are notifying the debugger of all vthreads or
1387      * are tracking all vthreads. Note similar code for VIRTUAL_THREAD_END is in event_callback(). */
1388     if (!gdata->notifyVThreads && !gdata->trackAllVThreads) {
1389         return;
1390     }
1391 
1392     BEGIN_CALLBACK() {
1393         (void)memset(&info,0,sizeof(info));
1394         info.ei         = EI_THREAD_START;
1395         info.thread     = vthread;
1396         event_callback(env, &info);
1397     } END_CALLBACK();
1398 
1399     LOG_MISC(("END cbVThreadStart"));
1400 }
1401 
1402 /* Event callback for JVMTI_EVENT_VIRTUAL_THREAD_END */
1403 static void JNICALL
1404 cbVThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *env, jthread vthread)
1405 {
1406 
1407     EventInfo info;
1408 
1409     LOG_CB(("cbVThreadEnd: vthread=%p", vthread));
1410     /*tty_message("cbVThreadEnd: vthread=%p", vthread);*/
1411     JDI_ASSERT(gdata->vthreadsSupported);
1412 
1413     BEGIN_CALLBACK() {
1414         (void)memset(&info,0,sizeof(info));
1415         info.ei         = EI_THREAD_END;
1416         info.thread     = vthread;
1417         event_callback(env, &info);
1418     } END_CALLBACK();
1419 
1420     LOG_MISC(("END cbVThreadEnd"));
1421 }
1422 
1423 /**
1424  * Delete this handler (do not delete permanent handlers):
1425  * Deinsert handler from active list,
1426  * make it inactive, and free it's memory
1427  * Assumes handlerLock held.
1428  */
1429 static jvmtiError
1430 freeHandler(HandlerNode *node) {
1431     jvmtiError error = JVMTI_ERROR_NONE;
1432 
1433     /* deinsert the handler node before disableEvents() to make
1434      * sure the event will be disabled when no other event
1435      * handlers are installed.
1436      */
1437     if (node != NULL && (!node->permanent)) {
1438         deinsert(node);
1439         error = eventFilterRestricted_deinstall(node);
1440         jvmtiDeallocate(node);
1441     }
1442 
1443     return error;
1444 }
1445 
1446 /**
1447  * Delete all the handlers on this chain (do not delete permanent handlers).
1448  * Assumes handlerLock held.
1449  */
1450 static jvmtiError
1451 freeHandlerChain(HandlerChain *chain)
1452 {
1453     HandlerNode *node;
1454     jvmtiError   error;
1455 
1456     error = JVMTI_ERROR_NONE;
1457     node  = chain->first;
1458     while ( node != NULL ) {
1459         HandlerNode *next;
1460         jvmtiError   singleError;
1461 
1462         next = NEXT(node);
1463         singleError = freeHandler(node);
1464         if ( singleError != JVMTI_ERROR_NONE ) {
1465             error = singleError;
1466         }
1467         node = next;
1468     }
1469     return error;
1470 }
1471 
1472 /**
1473  * Deinsert and free all memory.  Safe for non-inserted nodes.
1474  */
1475 jvmtiError
1476 eventHandler_free(HandlerNode *node)
1477 {
1478     jvmtiError error;
1479 
1480     debugMonitorEnter(handlerLock);
1481 
1482     error = freeHandler(node);
1483 
1484     debugMonitorExit(handlerLock);
1485 
1486     return error;
1487 }
1488 
1489 /**
1490  * Free all handlers of this kind created by the JDWP client,
1491  * that is, doesn't free handlers internally created by back-end.
1492  */
1493 jvmtiError
1494 eventHandler_freeAll(EventIndex ei)
1495 {
1496     jvmtiError error = JVMTI_ERROR_NONE;
1497     HandlerNode *node;
1498 
1499     debugMonitorEnter(handlerLock);
1500     node = getHandlerChain(ei)->first;
1501     while (node != NULL) {
1502         HandlerNode *next = NEXT(node);    /* allows node removal */
1503         if (node->handlerID != 0) {        /* don't free internal handlers */
1504             error = freeHandler(node);
1505             if (error != JVMTI_ERROR_NONE) {
1506                 break;
1507             }
1508         }
1509         node = next;
1510     }
1511     debugMonitorExit(handlerLock);
1512     return error;
1513 }
1514 
1515 /***
1516  * Delete all breakpoints on "clazz".
1517  */
1518 void
1519 eventHandler_freeClassBreakpoints(jclass clazz)
1520 {
1521     HandlerNode *node;
1522     JNIEnv *env = getEnv();
1523 
1524     debugMonitorEnter(handlerLock);
1525     node = getHandlerChain(EI_BREAKPOINT)->first;
1526     while (node != NULL) {
1527         HandlerNode *next = NEXT(node); /* allows node removal */
1528         if (eventFilterRestricted_isBreakpointInClass(env, clazz,
1529                                                       node)) {
1530             (void)freeHandler(node);
1531         }
1532         node = next;
1533     }
1534     debugMonitorExit(handlerLock);
1535 }
1536 
1537 jvmtiError
1538 eventHandler_freeByID(EventIndex ei, HandlerID handlerID)
1539 {
1540     jvmtiError error;
1541     HandlerNode *node;
1542 
1543     debugMonitorEnter(handlerLock);
1544     node = find(ei, handlerID);
1545     if (node != NULL) {
1546         error = freeHandler(node);
1547     } else {
1548         /* already freed */
1549         error = JVMTI_ERROR_NONE;
1550     }
1551     debugMonitorExit(handlerLock);
1552     return error;
1553 }
1554 
1555 void
1556 eventHandler_initialize(jbyte sessionID)
1557 {
1558     jvmtiError error;
1559     jint i;
1560 
1561     requestIdCounter = 1;
1562     currentSessionID = sessionID;
1563 
1564     /* This is for BEGIN_CALLBACK/END_CALLBACK handling, make sure this
1565      *   is done while none of these callbacks are active.
1566      */
1567     active_callbacks = 0;
1568     vm_death_callback_active = JNI_FALSE;
1569     callbackLock = debugMonitorCreate("JDWP Callback Lock");
1570     callbackBlock = debugMonitorCreate("JDWP Callback Block");
1571 
1572     handlerLock = debugMonitorCreate("JDWP Event Handler Lock");
1573 
1574     for (i = EI_min; i <= EI_max; ++i) {
1575         getHandlerChain(i)->first = NULL;
1576     }
1577 
1578     /*
1579      * Permanently enabled some events.
1580      */
1581     error = threadControl_setEventMode(JVMTI_ENABLE,
1582                                       EI_VM_INIT, NULL);
1583     if (error != JVMTI_ERROR_NONE) {
1584         EXIT_ERROR(error,"Can't enable vm init events");
1585     }
1586     error = threadControl_setEventMode(JVMTI_ENABLE,
1587                                       EI_VM_DEATH, NULL);
1588     if (error != JVMTI_ERROR_NONE) {
1589         EXIT_ERROR(error,"Can't enable vm death events");
1590     }
1591     error = threadControl_setEventMode(JVMTI_ENABLE,
1592                                       EI_THREAD_START, NULL);
1593     if (error != JVMTI_ERROR_NONE) {
1594         EXIT_ERROR(error,"Can't enable thread start events");
1595     }
1596     error = threadControl_setEventMode(JVMTI_ENABLE,
1597                                        EI_THREAD_END, NULL);
1598     if (error != JVMTI_ERROR_NONE) {
1599         EXIT_ERROR(error,"Can't enable thread end events");
1600     }
1601     error = threadControl_setEventMode(JVMTI_ENABLE,
1602                                        EI_CLASS_PREPARE, NULL);
1603     if (error != JVMTI_ERROR_NONE) {
1604         EXIT_ERROR(error,"Can't enable class prepare events");
1605     }
1606     error = threadControl_setEventMode(JVMTI_ENABLE,
1607                                        EI_GC_FINISH, NULL);
1608     if (error != JVMTI_ERROR_NONE) {
1609         EXIT_ERROR(error,"Can't enable garbage collection finish events");
1610     }
1611     /* Only enable vthread events if vthread support is enabled. */
1612     if (gdata->vthreadsSupported) {
1613         error = threadControl_setEventMode(JVMTI_ENABLE,
1614                                            EI_VIRTUAL_THREAD_START, NULL);
1615         if (error != JVMTI_ERROR_NONE) {
1616             EXIT_ERROR(error,"Can't enable vthread start events");
1617         }
1618         error = threadControl_setEventMode(JVMTI_ENABLE,
1619                                            EI_VIRTUAL_THREAD_END, NULL);
1620         if (error != JVMTI_ERROR_NONE) {
1621             EXIT_ERROR(error,"Can't enable vthread end events");
1622         }
1623     }
1624 
1625     (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
1626     /* Event callback for JVMTI_EVENT_SINGLE_STEP */
1627     gdata->callbacks.SingleStep                 = &cbSingleStep;
1628     /* Event callback for JVMTI_EVENT_BREAKPOINT */
1629     gdata->callbacks.Breakpoint                 = &cbBreakpoint;
1630     /* Event callback for JVMTI_EVENT_FRAME_POP */
1631     gdata->callbacks.FramePop                   = &cbFramePop;
1632     /* Event callback for JVMTI_EVENT_EXCEPTION */
1633     gdata->callbacks.Exception                  = &cbException;
1634     /* Event callback for JVMTI_EVENT_THREAD_START */
1635     gdata->callbacks.ThreadStart                = &cbThreadStart;
1636     /* Event callback for JVMTI_EVENT_THREAD_END */
1637     gdata->callbacks.ThreadEnd                  = &cbThreadEnd;
1638     /* Event callback for JVMTI_EVENT_CLASS_PREPARE */
1639     gdata->callbacks.ClassPrepare               = &cbClassPrepare;
1640     /* Event callback for JVMTI_EVENT_CLASS_LOAD */
1641     gdata->callbacks.ClassLoad                  = &cbClassLoad;
1642     /* Event callback for JVMTI_EVENT_FIELD_ACCESS */
1643     gdata->callbacks.FieldAccess                = &cbFieldAccess;
1644     /* Event callback for JVMTI_EVENT_FIELD_MODIFICATION */
1645     gdata->callbacks.FieldModification          = &cbFieldModification;
1646     /* Event callback for JVMTI_EVENT_EXCEPTION_CATCH */
1647     gdata->callbacks.ExceptionCatch             = &cbExceptionCatch;
1648     /* Event callback for JVMTI_EVENT_METHOD_ENTRY */
1649     gdata->callbacks.MethodEntry                = &cbMethodEntry;
1650     /* Event callback for JVMTI_EVENT_METHOD_EXIT */
1651     gdata->callbacks.MethodExit                 = &cbMethodExit;
1652     /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
1653     gdata->callbacks.MonitorContendedEnter      = &cbMonitorContendedEnter;
1654     /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
1655     gdata->callbacks.MonitorContendedEntered    = &cbMonitorContendedEntered;
1656     /* Event callback for JVMTI_EVENT_MONITOR_WAIT */
1657     gdata->callbacks.MonitorWait                = &cbMonitorWait;
1658     /* Event callback for JVMTI_EVENT_MONITOR_WAITED */
1659     gdata->callbacks.MonitorWaited              = &cbMonitorWaited;
1660     /* Event callback for JVMTI_EVENT_VM_INIT */
1661     gdata->callbacks.VMInit                     = &cbVMInit;
1662     /* Event callback for JVMTI_EVENT_VM_DEATH */
1663     gdata->callbacks.VMDeath                    = &cbVMDeath;
1664     /* Event callback for JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
1665     gdata->callbacks.GarbageCollectionFinish    = &cbGarbageCollectionFinish;
1666     /* Event callback for JVMTI_EVENT_VIRTUAL_THREAD_START */
1667     gdata->callbacks.VirtualThreadStart         = &cbVThreadStart;
1668     /* Event callback for JVMTI_EVENT_VIRTUAL_THREAD_END */
1669     gdata->callbacks.VirtualThreadEnd           = &cbVThreadEnd;
1670 
1671     error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
1672                 (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
1673     if (error != JVMTI_ERROR_NONE) {
1674         EXIT_ERROR(error,"Can't set event callbacks");
1675     }
1676 
1677     /* Notify other modules that the event callbacks are in place */
1678     threadControl_onHook();
1679 
1680     /* Get the event helper thread initialized */
1681     eventHelper_initialize(sessionID);
1682 }
1683 
1684 void
1685 eventHandler_reset(jbyte sessionID)
1686 {
1687     int i;
1688 
1689     debugMonitorEnter(handlerLock);
1690 
1691     /* We must do this first so that if any invokes complete,
1692      * there will be no attempt to send them to the front
1693      * end. Waiting for threadControl_reset leaves a window where
1694      * the invoke completions can sneak through.
1695      */
1696     threadControl_detachInvokes();
1697 
1698     /* Reset the event helper thread, purging all queued and
1699      * in-process commands.
1700      */
1701     eventHelper_reset(sessionID);
1702 
1703     /* delete all handlers */
1704     for (i = EI_min; i <= EI_max; i++) {
1705         (void)freeHandlerChain(getHandlerChain(i));
1706     }
1707 
1708     requestIdCounter = 1;
1709     currentSessionID = sessionID;
1710 
1711     debugMonitorExit(handlerLock);
1712 }
1713 
1714 void
1715 eventHandler_lock(void)
1716 {
1717     debugMonitorEnter(handlerLock);
1718 }
1719 
1720 void
1721 eventHandler_unlock(void)
1722 {
1723     debugMonitorExit(handlerLock);
1724 }
1725 
1726 /***** handler creation *****/
1727 
1728 HandlerNode *
1729 eventHandler_alloc(jint filterCount, EventIndex ei, jbyte suspendPolicy)
1730 {
1731     HandlerNode *node = eventFilterRestricted_alloc(filterCount);
1732 
1733     if (node != NULL) {
1734         node->ei = ei;
1735         node->suspendPolicy = suspendPolicy;
1736         node->permanent = JNI_FALSE;
1737     }
1738 
1739     return node;
1740 }
1741 
1742 
1743 HandlerID
1744 eventHandler_allocHandlerID(void)
1745 {
1746     jint handlerID;
1747     debugMonitorEnter(handlerLock);
1748     handlerID = ++requestIdCounter;
1749     debugMonitorExit(handlerLock);
1750     return handlerID;
1751 }
1752 
1753 
1754 static jvmtiError
1755 installHandler(HandlerNode *node,
1756               HandlerFunction func,
1757               jboolean external)
1758 {
1759     jvmtiError error;
1760 
1761     if ( func == NULL ) {
1762         return AGENT_ERROR_INVALID_EVENT_TYPE;
1763     }
1764 
1765     debugMonitorEnter(handlerLock);
1766 
1767     HANDLER_FUNCTION(node) = func;
1768 
1769     node->handlerID = external? ++requestIdCounter : 0;
1770     error = eventFilterRestricted_install(node);
1771     if (node->ei == EI_GC_FINISH) {
1772         classTrack_activate(getEnv());
1773     }
1774     if (error == JVMTI_ERROR_NONE) {
1775         insert(getHandlerChain(node->ei), node);
1776     }
1777 
1778     debugMonitorExit(handlerLock);
1779 
1780     return error;
1781 }
1782 
1783 static HandlerNode *
1784 createInternal(EventIndex ei, HandlerFunction func,
1785                jthread thread, jclass clazz, jmethodID method,
1786                jlocation location, jboolean permanent)
1787 {
1788     jint index = 0;
1789     jvmtiError error = JVMTI_ERROR_NONE;
1790     HandlerNode *node;
1791 
1792     /*
1793      * Start with necessary allocations
1794      */
1795     node = eventHandler_alloc(
1796         ((thread == NULL)? 0 : 1) + ((clazz == NULL)? 0 : 1),
1797         ei, JDWP_SUSPEND_POLICY(NONE));
1798     if (node == NULL) {
1799         return NULL;
1800     }
1801 
1802     node->permanent = permanent;
1803 
1804     if (thread != NULL) {
1805         error = eventFilter_setThreadOnlyFilter(node, index++, thread);
1806     }
1807 
1808     if ((error == JVMTI_ERROR_NONE) && (clazz != NULL)) {
1809         error = eventFilter_setLocationOnlyFilter(node, index++, clazz,
1810                                                   method, location);
1811     }
1812     /*
1813      * Create the new handler node
1814      */
1815     error = installHandler(node, func, JNI_FALSE);
1816 
1817     if (error != JVMTI_ERROR_NONE) {
1818         (void)eventHandler_free(node);
1819         node = NULL;
1820     }
1821     return node;
1822 }
1823 
1824 HandlerNode *
1825 eventHandler_createPermanentInternal(EventIndex ei, HandlerFunction func)
1826 {
1827     return createInternal(ei, func, NULL,
1828                           NULL, NULL, 0, JNI_TRUE);
1829 }
1830 
1831 HandlerNode *
1832 eventHandler_createInternalThreadOnly(EventIndex ei,
1833                                       HandlerFunction func,
1834                                       jthread thread)
1835 {
1836     return createInternal(ei, func, thread,
1837                           NULL, NULL, 0, JNI_FALSE);
1838 }
1839 
1840 HandlerNode *
1841 eventHandler_createInternalBreakpoint(HandlerFunction func,
1842                                       jthread thread,
1843                                       jclass clazz,
1844                                       jmethodID method,
1845                                       jlocation location)
1846 {
1847     return createInternal(EI_BREAKPOINT, func, thread,
1848                           clazz, method, location, JNI_FALSE);
1849 }
1850 
1851 jvmtiError
1852 eventHandler_installExternal(HandlerNode *node)
1853 {
1854     return installHandler(node,
1855                           standardHandlers_defaultHandler(node->ei),
1856                           JNI_TRUE);
1857 }
1858 
1859 /***** debugging *****/
1860 
1861 #ifdef DEBUG
1862 
1863 void
1864 eventHandler_dumpAllHandlers(jboolean dumpPermanent)
1865 {
1866     int ei;
1867     for (ei = EI_min; ei <= EI_max; ++ei) {
1868         eventHandler_dumpHandlers(ei, dumpPermanent);
1869     }
1870 }
1871 
1872 void
1873 eventHandler_dumpHandlers(EventIndex ei, jboolean dumpPermanent)
1874 {
1875   HandlerNode *nextNode;
1876   nextNode = getHandlerChain(ei)->first;
1877   if (nextNode != NULL) {
1878       tty_message("\nHandlers for %s(%d)", eventIndex2EventName(ei), ei);
1879       while (nextNode != NULL) {
1880           HandlerNode *node = nextNode;
1881           nextNode = NEXT(node);
1882 
1883           if (node->permanent && !dumpPermanent) {
1884               continue; // ignore permanent handlers
1885           }
1886 
1887           tty_message("node(%p) handlerID(%d) suspendPolicy(%d) permanent(%d)",
1888                       node, node->handlerID, node->suspendPolicy, node->permanent);
1889           eventFilter_dumpHandlerFilters(node);
1890       }
1891   }
1892 }
1893 
1894 void
1895 eventHandler_dumpHandler(HandlerNode *node)
1896 {
1897     tty_message("Handler for %s(%d)\n", eventIndex2EventName(node->ei), node->ei);
1898     eventFilter_dumpHandlerFilters(node);
1899 }
1900 
1901 #endif /* DEBUG */