Skip to content

Commit 253cf78

Browse files
committedFeb 23, 2022
8282076: Merge some debug agent changes from the loom repo
Reviewed-by: amenkov, lmesnik
1 parent f86f38a commit 253cf78

File tree

3 files changed

+72
-56
lines changed

3 files changed

+72
-56
lines changed
 

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

+58-46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -534,6 +534,62 @@ synthesizeUnloadEvent(void *signatureVoid, void *envVoid)
534534
/* Garbage Collection Happened */
535535
static unsigned int garbageCollected = 0;
536536

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+
}
592+
537593
/*
538594
* The JVMTI generic event callback. Each event is passed to a sequence of
539595
* handlers in a chain until the chain ends or one handler
@@ -634,51 +690,7 @@ event_callback(JNIEnv *env, EventInfo *evinfo)
634690
}
635691
}
636692

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-
}
693+
filterAndHandleEvent(env, evinfo, ei, eventBag, eventSessionID);
682694

683695
/* we are continuing after VMDeathEvent - now we are dead */
684696
if (evinfo->ei == EI_VM_DEATH) {

‎src/jdk.jdwp.agent/share/native/libjdwp/stepControl.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -463,14 +463,18 @@ handleMethodEnterEvent(JNIEnv *env, EventInfo *evinfo,
463463
*/
464464
JDI_ASSERT(step->depth == JDWP_STEP_DEPTH(INTO));
465465

466-
if ( (!eventFilter_predictFiltering(step->stepHandlerNode,
467-
clazz, classname))
468-
&& ( step->granularity != JDWP_STEP_SIZE(LINE)
469-
|| hasLineNumbers(method) ) ) {
466+
/*
467+
* We need to figure out if we are entering a method that we want to resume
468+
* single stepping in. If the class of this method is being filtered out, then
469+
* we don't resume. Otherwise, if we are not line stepping then we resume, and
470+
* if we are line stepping we don't resume unless the method has LineNumbers.
471+
*/
472+
jboolean filteredOut = eventFilter_predictFiltering(step->stepHandlerNode, clazz, classname);
473+
jboolean isStepLine = step->granularity == JDWP_STEP_SIZE(LINE);
474+
if (!filteredOut && (!isStepLine || hasLineNumbers(method))) {
470475
/*
471-
* We've found a suitable method in which to stop. Step
472-
* until we reach the next safe location to complete the step->,
473-
* and we can get rid of the method entry handler.
476+
* We've found a suitable method in which to resume stepping.
477+
* We can also get rid of the method entry handler now.
474478
*/
475479
enableStepping(thread);
476480
if ( step->methodEnterHandlerNode != NULL ) {

‎src/jdk.jdwp.agent/share/native/libjdwp/threadControl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -69,7 +69,7 @@ typedef struct ThreadNode {
6969
unsigned int pendingInterrupt : 1; /* true if thread is interrupted while handling an event. */
7070
unsigned int isDebugThread : 1; /* true if this is one of our debug agent threads. */
7171
unsigned int suspendOnStart : 1; /* true for new threads if we are currently in a VM.suspend(). */
72-
unsigned int isStarted : 1; /* THREAD_START or VIRTUAL_THREAD_SCHEDULED event received. */
72+
unsigned int isStarted : 1; /* THREAD_START event received. */
7373
unsigned int popFrameEvent : 1;
7474
unsigned int popFrameProceed : 1;
7575
unsigned int popFrameThread : 1;

0 commit comments

Comments
 (0)
Please sign in to comment.