Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8262486: Merge trivial JDWP agent changes from the loom repo to the jdk repo #2815

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.c
Expand Up @@ -518,8 +518,7 @@ eventFilterRestricted_passesFilter(JNIEnv *env,

case JDWP_REQUEST_MODIFIER(SourceNameMatch): {
char* desiredNamePattern = filter->u.SourceNameOnly.sourceNamePattern;
if (searchAllSourceNames(env, clazz,
desiredNamePattern) != 1) {
if (searchAllSourceNames(env, clazz, desiredNamePattern) != 1) {
/* The name isn't in the SDE; try the sourceName in the ref
* type
*/
Expand Down Expand Up @@ -943,7 +942,6 @@ eventFilter_setStepFilter(HandlerNode *node, jint index,
return JVMTI_ERROR_NONE;
}


jvmtiError
eventFilter_setSourceNameMatchFilter(HandlerNode *node,
jint index,
Expand Down
11 changes: 6 additions & 5 deletions src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
Expand Up @@ -269,7 +269,7 @@ eventHandlerRestricted_iterator(EventIndex ei,

/* BREAKPOINT, METHOD_ENTRY and SINGLE_STEP events are covered by
* the co-location of events policy. Of these three co-located
* events, METHOD_ENTRY is always reported first and BREAKPOINT
* events, METHOD_ENTRY is always reported first and BREAKPOINT
* is always reported last. Here are the possible combinations and
* their order:
*
Expand Down Expand Up @@ -534,7 +534,8 @@ synthesizeUnloadEvent(void *signatureVoid, void *envVoid)
/* Garbage Collection Happened */
static unsigned int garbageCollected = 0;

/* The JVMTI generic event callback. Each event is passed to a sequence of
/*
* The JVMTI generic event callback. Each event is passed to a sequence of
* handlers in a chain until the chain ends or one handler
* consumes the event.
*/
Expand All @@ -545,8 +546,9 @@ event_callback(JNIEnv *env, EventInfo *evinfo)
jbyte eventSessionID = currentSessionID; /* session could change */
jthrowable currentException;
jthread thread;
EventIndex ei = evinfo->ei;

LOG_MISC(("event_callback(): ei=%s", eventText(evinfo->ei)));
LOG_MISC(("event_callback(): ei=%s", eventText(ei)));
log_debugee_location("event_callback()", evinfo->thread, evinfo->method, evinfo->location);

/* We want to preserve any current exception that might get
Expand Down Expand Up @@ -602,8 +604,7 @@ event_callback(JNIEnv *env, EventInfo *evinfo)
* resources can be allocated. This must be done before
* grabbing any locks.
*/
eventBag = threadControl_onEventHandlerEntry(eventSessionID,
evinfo->ei, thread, currentException);
eventBag = threadControl_onEventHandlerEntry(eventSessionID, evinfo, currentException);
if ( eventBag == NULL ) {
jboolean invoking;
do {
Expand Down
6 changes: 3 additions & 3 deletions src/jdk.jdwp.agent/share/native/libjdwp/eventHelper.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1045,12 +1045,12 @@ eventHelper_reportEvents(jbyte sessionID, struct bag *eventBag)

void
eventHelper_recordEvent(EventInfo *evinfo, jint id, jbyte suspendPolicy,
struct bag *eventBag)
struct bag *eventBag)
{
JNIEnv *env = getEnv();
CommandSingle *command = bagAdd(eventBag);
if (command == NULL) {
EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"badAdd(eventBag)");
EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"bagAdd(eventBag)");
}

command->singleKind = COMMAND_SINGLE_EVENT;
Expand Down
6 changes: 5 additions & 1 deletion src/jdk.jdwp.agent/share/native/libjdwp/standardHandlers.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -36,6 +36,7 @@

#include "standardHandlers.h"

/* HandlerFunction - Invoked from event_callback() */
static void
handleClassPrepare(JNIEnv *env, EventInfo *evinfo,
HandlerNode *node,
Expand Down Expand Up @@ -75,6 +76,7 @@ handleClassPrepare(JNIEnv *env, EventInfo *evinfo,
node->suspendPolicy, eventBag);
}

/* HandlerFunction - Invoked from event_callback() */
static void
handleGarbageCollectionFinish(JNIEnv *env, EventInfo *evinfo,
HandlerNode *node,
Expand All @@ -83,6 +85,7 @@ handleGarbageCollectionFinish(JNIEnv *env, EventInfo *evinfo,
JDI_ASSERT_MSG(JNI_FALSE, "Should never call handleGarbageCollectionFinish");
}

/* HandlerFunction - Invoked from event_callback() for METHOD_ENTRY and METHOD_EXIT. */
static void
handleFrameEvent(JNIEnv *env, EventInfo *evinfo,
HandlerNode *node,
Expand Down Expand Up @@ -122,6 +125,7 @@ handleFrameEvent(JNIEnv *env, EventInfo *evinfo,
eventBag);
}

/* HandlerFunction - Invoked from event_callback() */
static void
genericHandler(JNIEnv *env, EventInfo *evinfo,
HandlerNode *node,
Expand Down
34 changes: 20 additions & 14 deletions src/jdk.jdwp.agent/share/native/libjdwp/stepControl.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -341,18 +341,21 @@ handleFramePopEvent(JNIEnv *env, EventInfo *evinfo,
*/
LOG_STEP(("handleFramePopEvent: starting singlestep, depth==OUT && fromDepth > afterPopDepth (%d>%d)",fromDepth, afterPopDepth));
enableStepping(thread);
} else if (step->methodEnterHandlerNode != NULL &&
fromDepth >= afterPopDepth) {
/*
* We installed a method entry event handler as part of a
* step into operation. We've popped back to the original
* stepping frame without finding a place to stop.
* Resume stepping in the original frame.
*/
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==OUT && fromDepth >= afterPopDepth (%d>%d)",fromDepth, afterPopDepth));
enableStepping(thread);
(void)eventHandler_free(step->methodEnterHandlerNode);
step->methodEnterHandlerNode = NULL;
} else if (step->methodEnterHandlerNode != NULL) {
/* We installed a method entry event handler as part of a step into operation. */
JDI_ASSERT(step->depth == JDWP_STEP_DEPTH(INTO));
if (fromDepth >= afterPopDepth) {
/*
* We've popped back to the original stepping frame without finding a place to stop.
* Resume stepping in the original frame.
*/
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth >= afterPopDepth (%d>=%d)", fromDepth, afterPopDepth));
enableStepping(thread);
(void)eventHandler_free(step->methodEnterHandlerNode);
step->methodEnterHandlerNode = NULL;
} else {
LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==INTO && fromDepth < afterPopDepth (%d<%d)", fromDepth, afterPopDepth));
}
}
LOG_STEP(("handleFramePopEvent: finished"));
}
Expand Down Expand Up @@ -603,6 +606,8 @@ stepControl_handleStep(JNIEnv *env, jthread thread,
"installing event method enter handler");
}
}
LOG_STEP(("stepControl_handleStep: NotifyFramePop (fromDepth=%d currentDepth=%d)",
fromDepth, currentDepth));

error = JVMTI_FUNC_PTR(gdata->jvmti,NotifyFramePop)
(gdata->jvmti, thread, 0);
Expand Down Expand Up @@ -739,6 +744,7 @@ initEvents(jthread thread, StepRequest *step)
EI_EXCEPTION_CATCH,
handleExceptionCatchEvent,
thread);
JDI_ASSERT(step->framePopHandlerNode == NULL);
step->framePopHandlerNode = eventHandler_createInternalThreadOnly(
EI_FRAME_POP,
handleFramePopEvent,
Expand Down Expand Up @@ -793,7 +799,7 @@ stepControl_beginStep(JNIEnv *env, jthread thread, jint size, jint depth,
jvmtiError error2;

LOG_STEP(("stepControl_beginStep: thread=%p,size=%d,depth=%d",
thread, size, depth));
thread, size, depth));

eventHandler_lock(); /* for proper lock order */
stepControl_lock();
Expand Down
57 changes: 41 additions & 16 deletions src/jdk.jdwp.agent/share/native/libjdwp/threadControl.c
Expand Up @@ -39,6 +39,8 @@
* If the ei field is non-zero, then one of the possible
* co-located events has been posted and the other fields describe
* the event's location.
*
* See comment above deferEventReport() for an explanation of co-located events.
*/
typedef struct CoLocatedEventInfo_ {
EventIndex ei;
Expand All @@ -63,27 +65,28 @@ typedef struct CoLocatedEventInfo_ {
*/
typedef struct ThreadNode {
jthread thread;
unsigned int toBeResumed : 1;
unsigned int pendingInterrupt : 1;
unsigned int isDebugThread : 1;
unsigned int suspendOnStart : 1;
unsigned int isStarted : 1;
unsigned int toBeResumed : 1; /* true if this thread was successfully suspended. */
unsigned int pendingInterrupt : 1; /* true if thread is interrupted while handling an event. */
unsigned int isDebugThread : 1; /* true if this is one of our debug agent threads. */
unsigned int suspendOnStart : 1; /* true for new threads if we are currently in a VM.suspend(). */
unsigned int isStarted : 1; /* THREAD_START or VIRTUAL_THREAD_SCHEDULED event received. */
unsigned int popFrameEvent : 1;
unsigned int popFrameProceed : 1;
unsigned int popFrameThread : 1;
EventIndex current_ei;
jobject pendingStop;
EventIndex current_ei; /* Used to determine if we are currently handling an event on this thread. */
jobject pendingStop; /* Object we are throwing to stop the thread (ThreadReferenceImpl.stop). */
jint suspendCount;
jint resumeFrameDepth; /* !=0 => This thread is in a call to Thread.resume() */
jvmtiEventMode instructionStepMode;
StepRequest currentStep;
InvokeRequest currentInvoke;
struct bag *eventBag;
CoLocatedEventInfo cleInfo;
struct bag *eventBag; /* Accumulation of JDWP events to be sent as a reply. */
CoLocatedEventInfo cleInfo; /* See comment above deferEventReport() for an explanation. */
struct ThreadNode *next;
struct ThreadNode *prev;
jlong frameGeneration;
struct ThreadList *list; /* Tells us what list this thread is in */
jlong frameGeneration; /* used to generate a unique frameID. Incremented whenever existing frameID
needs to be invalidated, such as when the thread is resumed. */
struct ThreadList *list; /* Tells us what list this thread is in. */
#ifdef DEBUG_THREADNAME
char name[256];
#endif
Expand Down Expand Up @@ -228,7 +231,10 @@ nonTlsSearch(JNIEnv *env, ThreadList *list, jthread thread)
/*
* These functions maintain the linked list of currently running threads.
* All assume that the threadLock is held before calling.
* If list==NULL, search both lists.
*/

/*
* Search for a thread on the list. If list==NULL, search all lists.
*/
static ThreadNode *
findThread(ThreadList *list, jthread thread)
Expand Down Expand Up @@ -672,6 +678,10 @@ notifyAppResumeComplete(void)
}
}

/*
* Event handler for FRAME_POP and EXCEPTION_CATCH when in Thread.resume()
* so we can detect its completion.
*/
static void
handleAppResumeCompletion(JNIEnv *env, EventInfo *evinfo,
HandlerNode *handlerNode,
Expand Down Expand Up @@ -756,6 +766,7 @@ trackAppResume(jthread thread)
}
}

/* Global breakpoint handler for Thread.resume() */
static void
handleAppResumeBreakpoint(JNIEnv *env, EventInfo *evinfo,
HandlerNode *handlerNode,
Expand Down Expand Up @@ -927,7 +938,7 @@ deferredSuspendThreadByNode(ThreadNode *node)
* happens when suspendOnStart is set to true.
*/
if (error != JVMTI_ERROR_NONE) {
node->suspendCount--;
node->suspendCount--;
}
}

Expand Down Expand Up @@ -1080,6 +1091,9 @@ commonSuspend(JNIEnv *env, jthread thread, jboolean deferred)
* to a separate list of threads so that we'll resume it later.
*/
node = findThread(&runningThreads, thread);
#if 0
tty_message("commonSuspend: node(%p) suspendCount(%d) %s", node, node->suspendCount, node->name);
#endif
if (node == NULL) {
node = insertThread(env, &otherThreads, thread);
}
Expand Down Expand Up @@ -1387,7 +1401,6 @@ commonSuspendList(JNIEnv *env, jint initCount, jthread *initList)
return error;
}


static jvmtiError
commonResume(jthread thread)
{
Expand All @@ -1399,6 +1412,9 @@ commonResume(jthread thread)
* not, check the auxiliary list used by threadControl_suspendThread.
*/
node = findThread(NULL, thread);
#if 0
tty_message("commonResume: node(%p) suspendCount(%d) %s", node, node->suspendCount, node->name);
#endif

/*
* If the node is in neither list, the debugger never suspended
Expand Down Expand Up @@ -1520,6 +1536,9 @@ threadControl_suspendAll(void)
{
jvmtiError error;
JNIEnv *env;
#if 0
tty_message("threadControl_suspendAll: suspendAllCount(%d)", suspendAllCount);
#endif

env = getEnv();

Expand Down Expand Up @@ -1593,6 +1612,9 @@ threadControl_resumeAll(void)
{
jvmtiError error;
JNIEnv *env;
#if 0
tty_message("threadControl_resumeAll: suspendAllCount(%d)", suspendAllCount);
#endif

env = getEnv();

Expand Down Expand Up @@ -2050,13 +2072,15 @@ checkForPopFrameEvents(JNIEnv *env, EventIndex ei, jthread thread)
}

struct bag *
threadControl_onEventHandlerEntry(jbyte sessionID, EventIndex ei, jthread thread, jobject currentException)
threadControl_onEventHandlerEntry(jbyte sessionID, EventInfo *evinfo, jobject currentException)
{
ThreadNode *node;
JNIEnv *env;
struct bag *eventBag;
jthread threadToSuspend;
jboolean consumed;
EventIndex ei = evinfo->ei;
jthread thread = evinfo->thread;

env = getEnv();
threadToSuspend = NULL;
Expand Down Expand Up @@ -2483,7 +2507,8 @@ threadControl_setEventMode(jvmtiEventMode mode, EventIndex ei, jthread thread)
* Returns the current thread, if the thread has generated at least
* one event, and has not generated a thread end event.
*/
jthread threadControl_currentThread(void)
jthread
threadControl_currentThread(void)
{
jthread thread;

Expand Down
3 changes: 1 addition & 2 deletions src/jdk.jdwp.agent/share/native/libjdwp/threadControl.h
Expand Up @@ -40,8 +40,7 @@ void threadControl_onDisconnect(void);

jvmtiError threadControl_popFrames(jthread thread, FrameNumber fnum);

struct bag *threadControl_onEventHandlerEntry(jbyte sessionID,
EventIndex ei, jthread thread, jobject currentException);
struct bag *threadControl_onEventHandlerEntry(jbyte sessionID, EventInfo *evinfo, jobject currentException);
void threadControl_onEventHandlerExit(EventIndex ei, jthread thread, struct bag *);


Expand Down