< prev index next >

src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c

Print this page

 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  * The JVMTI generic event callback. Each event is passed to a sequence of
 539  * handlers in a chain until the chain ends or one handler
 540  * consumes the event.
 541  */
 542 static void
 543 event_callback(JNIEnv *env, EventInfo *evinfo)
 544 {
 545     struct bag *eventBag;
 546     jbyte eventSessionID = currentSessionID; /* session could change */
 547     jthrowable currentException;
 548     jthread thread;
 549     EventIndex ei = evinfo->ei;
 550 
 551     LOG_MISC(("event_callback(): ei=%s", eventText(ei)));
 552     log_debugee_location("event_callback()", evinfo->thread, evinfo->method, evinfo->location);
 553 
 554     /* We want to preserve any current exception that might get
 555      * wiped out during event handling (e.g. JNI calls). We have
 556      * to rely on space for the local reference on the current

 580         debugMonitorEnter(handlerLock);
 581 
 582         /* Clear garbage collection counter */
 583         garbageCollected = 0;
 584 
 585         /* Analyze which class unloads occurred */
 586         unloadedSignatures = classTrack_processUnloads(env);
 587 
 588         debugMonitorExit(handlerLock);
 589 
 590         /* Generate the synthetic class unload events and/or just cleanup.  */
 591         if ( unloadedSignatures != NULL ) {
 592             (void)bagEnumerateOver(unloadedSignatures, synthesizeUnloadEvent,
 593                              (void *)env);
 594             bagDestroyBag(unloadedSignatures);
 595         }
 596     }
 597 
 598     thread = evinfo->thread;
 599     if (thread != NULL) {




 600         /*
 601          * Record the fact that we're entering an event
 602          * handler so that thread operations (status, interrupt,
 603          * stop) can be done correctly and so that thread
 604          * resources can be allocated.  This must be done before
 605          * grabbing any locks.
 606          */
 607         eventBag = threadControl_onEventHandlerEntry(eventSessionID, evinfo, currentException);
 608         if ( eventBag == NULL ) {
 609             jboolean invoking;
 610             do {
 611                 /* The event has been 'handled' and this
 612                  * thread is about to continue, but it may
 613                  * have been started up just to perform a
 614                  * requested method invocation. If so, we do
 615                  * the invoke now and then stop again waiting
 616                  * for another continue. By then another
 617                  * invoke request can be in place, so there is
 618                  * a loop around this code.
 619                  */
 620                 invoking = invoker_doInvoke(thread);
 621                 if (invoking) {
 622                     eventHelper_reportInvokeDone(eventSessionID, thread);
 623                 }
 624             } while (invoking);
 625             return; /* Do nothing, event was consumed */
 626         }
 627     } else {
 628         eventBag = eventHelper_createEventBag();
 629         if (eventBag == NULL) {
 630             /*
 631              * TO DO: Report, but don't die
 632              */
 633             eventBag = NULL;  /* to shut up lint */
 634         }
 635     }
 636 
 637     debugMonitorEnter(handlerLock);
 638     {
 639         HandlerNode *node;
 640         char        *classname;
 641 
 642         /* We must keep track of all classes prepared to know what's unloaded */
 643         if (evinfo->ei == EI_CLASS_PREPARE) {
 644             classTrack_addPreparedClass(env, evinfo->clazz);
 645         }
 646 
 647         node = getHandlerChain(evinfo->ei)->first;
 648         classname = getClassname(evinfo->clazz);
 649 
 650         while (node != NULL) {
 651             /* save next so handlers can remove themselves */
 652             HandlerNode *next = NEXT(node);
 653             jboolean shouldDelete;
 654 
 655             if (eventFilterRestricted_passesFilter(env, classname,
 656                                                    evinfo, node,
 657                                                    &shouldDelete)) {
 658                 HandlerFunction func;
 659 
 660                 func = HANDLER_FUNCTION(node);
 661                 if ( func == NULL ) {
 662                     EXIT_ERROR(AGENT_ERROR_INTERNAL,"handler function NULL");
 663                 }
 664                 (*func)(env, evinfo, node, eventBag);
 665             }
 666             if (shouldDelete) {
 667                 /* We can safely free the node now that we are done
 668                  * using it.
 669                  */
 670                 (void)freeHandler(node);
 671             }
 672             node = next;
 673         }
 674         jvmtiDeallocate(classname);
 675     }
 676     debugMonitorExit(handlerLock);
 677 
 678     if (eventBag != NULL) {
 679         reportEvents(env, eventSessionID, thread, evinfo->ei,
 680                 evinfo->clazz, evinfo->method, evinfo->location, eventBag);




 681     }
 682 
 683     /* we are continuing after VMDeathEvent - now we are dead */
 684     if (evinfo->ei == EI_VM_DEATH) {
 685         gdata->vmDead = JNI_TRUE;
 686     }
 687 
 688     /*
 689      * If the bag was created locally, destroy it here.
 690      */
 691     if (thread == NULL) {
 692         bagDestroyBag(eventBag);
 693     }
 694 
 695     /* Always restore any exception that was set beforehand.  If
 696      * there is a pending async exception, StopThread will be
 697      * called from threadControl_onEventHandlerExit immediately
 698      * below.  Depending on VM implementation and state, the async
 699      * exception might immediately overwrite the currentException,
 700      * or it might be delayed until later.  */

1283         event_callback(env, &info);
1284 
1285         /* Here we unblock all the callbacks and let them return to the
1286          *   VM.  It's not clear this is necessary, but leaving threads
1287          *   blocked doesn't seem like a good idea. They don't have much
1288          *   life left anyway.
1289          */
1290     } debugMonitorExit(callbackBlock);
1291 
1292     /*
1293      * The VM will die soon after the completion of this callback -
1294      * we synchronize with both the command loop and the debug loop
1295      * for a more orderly shutdown.
1296      */
1297     commandLoop_sync();
1298     debugLoop_sync();
1299 
1300     LOG_MISC(("END cbVMDeath"));
1301 }
1302 








































































1303 /**
1304  * Delete this handler (do not delete permanent handlers):
1305  * Deinsert handler from active list,
1306  * make it inactive, and free it's memory
1307  * Assumes handlerLock held.
1308  */
1309 static jvmtiError
1310 freeHandler(HandlerNode *node) {
1311     jvmtiError error = JVMTI_ERROR_NONE;
1312 
1313     /* deinsert the handler node before disableEvents() to make
1314      * sure the event will be disabled when no other event
1315      * handlers are installed.
1316      */
1317     if (node != NULL && (!node->permanent)) {
1318         deinsert(node);
1319         error = eventFilterRestricted_deinstall(node);
1320         jvmtiDeallocate(node);
1321     }
1322 

1471     error = threadControl_setEventMode(JVMTI_ENABLE,
1472                                       EI_THREAD_START, NULL);
1473     if (error != JVMTI_ERROR_NONE) {
1474         EXIT_ERROR(error,"Can't enable thread start events");
1475     }
1476     error = threadControl_setEventMode(JVMTI_ENABLE,
1477                                        EI_THREAD_END, NULL);
1478     if (error != JVMTI_ERROR_NONE) {
1479         EXIT_ERROR(error,"Can't enable thread end events");
1480     }
1481     error = threadControl_setEventMode(JVMTI_ENABLE,
1482                                        EI_CLASS_PREPARE, NULL);
1483     if (error != JVMTI_ERROR_NONE) {
1484         EXIT_ERROR(error,"Can't enable class prepare events");
1485     }
1486     error = threadControl_setEventMode(JVMTI_ENABLE,
1487                                        EI_GC_FINISH, NULL);
1488     if (error != JVMTI_ERROR_NONE) {
1489         EXIT_ERROR(error,"Can't enable garbage collection finish events");
1490     }













1491 
1492     (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
1493     /* Event callback for JVMTI_EVENT_SINGLE_STEP */
1494     gdata->callbacks.SingleStep                 = &cbSingleStep;
1495     /* Event callback for JVMTI_EVENT_BREAKPOINT */
1496     gdata->callbacks.Breakpoint                 = &cbBreakpoint;
1497     /* Event callback for JVMTI_EVENT_FRAME_POP */
1498     gdata->callbacks.FramePop                   = &cbFramePop;
1499     /* Event callback for JVMTI_EVENT_EXCEPTION */
1500     gdata->callbacks.Exception                  = &cbException;
1501     /* Event callback for JVMTI_EVENT_THREAD_START */
1502     gdata->callbacks.ThreadStart                = &cbThreadStart;
1503     /* Event callback for JVMTI_EVENT_THREAD_END */
1504     gdata->callbacks.ThreadEnd                  = &cbThreadEnd;
1505     /* Event callback for JVMTI_EVENT_CLASS_PREPARE */
1506     gdata->callbacks.ClassPrepare               = &cbClassPrepare;
1507     /* Event callback for JVMTI_EVENT_CLASS_LOAD */
1508     gdata->callbacks.ClassLoad                  = &cbClassLoad;
1509     /* Event callback for JVMTI_EVENT_FIELD_ACCESS */
1510     gdata->callbacks.FieldAccess                = &cbFieldAccess;

1513     /* Event callback for JVMTI_EVENT_EXCEPTION_CATCH */
1514     gdata->callbacks.ExceptionCatch             = &cbExceptionCatch;
1515     /* Event callback for JVMTI_EVENT_METHOD_ENTRY */
1516     gdata->callbacks.MethodEntry                = &cbMethodEntry;
1517     /* Event callback for JVMTI_EVENT_METHOD_EXIT */
1518     gdata->callbacks.MethodExit                 = &cbMethodExit;
1519     /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTER */
1520     gdata->callbacks.MonitorContendedEnter      = &cbMonitorContendedEnter;
1521     /* Event callback for JVMTI_EVENT_MONITOR_CONTENDED_ENTERED */
1522     gdata->callbacks.MonitorContendedEntered    = &cbMonitorContendedEntered;
1523     /* Event callback for JVMTI_EVENT_MONITOR_WAIT */
1524     gdata->callbacks.MonitorWait                = &cbMonitorWait;
1525     /* Event callback for JVMTI_EVENT_MONITOR_WAITED */
1526     gdata->callbacks.MonitorWaited              = &cbMonitorWaited;
1527     /* Event callback for JVMTI_EVENT_VM_INIT */
1528     gdata->callbacks.VMInit                     = &cbVMInit;
1529     /* Event callback for JVMTI_EVENT_VM_DEATH */
1530     gdata->callbacks.VMDeath                    = &cbVMDeath;
1531     /* Event callback for JVMTI_EVENT_GARBAGE_COLLECTION_FINISH */
1532     gdata->callbacks.GarbageCollectionFinish    = &cbGarbageCollectionFinish;




1533 
1534     error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
1535                 (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
1536     if (error != JVMTI_ERROR_NONE) {
1537         EXIT_ERROR(error,"Can't set event callbacks");
1538     }
1539 
1540     /* Notify other modules that the event callbacks are in place */
1541     threadControl_onHook();
1542 
1543     /* Get the event helper thread initialized */
1544     eventHelper_initialize(sessionID);
1545 }
1546 
1547 void
1548 eventHandler_reset(jbyte sessionID)
1549 {
1550     int i;
1551 
1552     debugMonitorEnter(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

 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.  */

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 

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;

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);
< prev index next >