Skip to content
Permalink
Browse files
Fixed issue with resuming vthreads when debugger disconnects. Fixed i…
…ssue with resuming vthreads that were individually suspended (not with suspendAll) but were resumed withe resumeAll.
  • Loading branch information
plummercj committed Mar 1, 2021
1 parent f29945b commit a536251dbbc90206e64854b806ea1edd8215f584
Showing 1 changed file with 25 additions and 16 deletions.
@@ -1281,10 +1281,14 @@ commonResumeList(JNIEnv *env)
/* count number of threads to hard resume */
(void) enumerateOverThreadList(env, &runningThreads, resumeCountHelper,
&reqCnt);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCountHelper,
&reqCnt);
if (reqCnt == 0) {
/* nothing to hard resume so do just the accounting part */
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
NULL);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
NULL);
return JVMTI_ERROR_NONE;
}

@@ -1303,13 +1307,15 @@ commonResumeList(JNIEnv *env)
reqPtr = reqList;
(void) enumerateOverThreadList(env, &runningThreads, resumeCopyHelper,
&reqPtr);
(void) enumerateOverThreadList(env, &runningVThreads, resumeCopyHelper,
&reqPtr);

error = JVMTI_FUNC_PTR(gdata->jvmti,ResumeThreadList)
(gdata->jvmti, reqCnt, reqList, results);
for (i = 0; i < reqCnt; i++) {
ThreadNode *node;

node = findThread(&runningThreads, reqList[i]);
node = findRunningThread(reqList[i]);
if (node == NULL) {
EXIT_ERROR(AGENT_ERROR_INVALID_THREAD,"missing entry in running thread table");
}
@@ -1619,7 +1625,12 @@ threadControl_suspendAll(void)
}
}

/* Increment suspend count of each virtual thread that we are tracking. */
/*
* Increment suspendCount of each virtual thread that we are tracking. Note the
* compliment to this that happens during the resumeAll() is handled by
* commonResumeList(), so it's a bit orthogonal to how we handle incrementing
* the suspendCount.
*/
error = enumerateOverThreadList(env, &runningVThreads, incrementSupendCountHelper, NULL);
JDI_ASSERT(error == JVMTI_ERROR_NONE);
}
@@ -1677,16 +1688,6 @@ threadControl_suspendAll(void)
return error;
}

static jvmtiError
decrementSupendCountHelper(JNIEnv *env, ThreadNode *node, void *arg)
{
// Some vthreads might already have a suspendCount of 0. Just ignore them.
if (node->suspendCount > 0) {
node->suspendCount--;
}
return JVMTI_ERROR_NONE;
}

static jvmtiError
resumeHelper(JNIEnv *env, ThreadNode *node, void *ignored)
{
@@ -1723,10 +1724,6 @@ threadControl_resumeAll(void)
EXIT_ERROR(error, "cannot resume all virtual threads");
}
}

/* Decrement suspend count of each virtual thread that we are tracking. */
error = enumerateOverThreadList(env, &runningVThreads, decrementSupendCountHelper, NULL);
JDI_ASSERT(error == JVMTI_ERROR_NONE);
}

/*
@@ -2563,6 +2560,18 @@ threadControl_reset(void)
env = getEnv();
eventHandler_lock(); /* for proper lock order */
debugMonitorEnter(threadLock);

if (gdata->vthreadsSupported) {
if (suspendAllCount > 0) {
/* Tell JVMTI to resume all virtual threads. */
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,ResumeAllVirtualThreads)
(gdata->jvmti);
if (error != JVMTI_ERROR_NONE) {
EXIT_ERROR(error, "cannot resume all virtual threads");
}
}
}

(void)enumerateOverThreadList(env, &runningThreads, resetHelper, NULL);
(void)enumerateOverThreadList(env, &otherThreads, resetHelper, NULL);
(void)enumerateOverThreadList(env, &runningVThreads, resetHelper, NULL);

0 comments on commit a536251

Please sign in to comment.