@@ -235,12 +235,8 @@ nonTlsSearch(JNIEnv *env, ThreadList *list, jthread thread)
235235 * All assume that the threadLock is held before calling.
236236 */
237237
238-
239238/*
240239 * Search for a thread on the list. If list==NULL, search all lists.
241- * TODO: TLS cache is temporary diabled for all threads, not added for virtual threads yet
242- * It cause intermittent failures because ThreadNode data is broken.
243- * Need to enable setThreadLocalStorage in 2 places.
244240 */
245241static ThreadNode *
246242findThread (ThreadList * list , jthread thread )
@@ -1285,10 +1281,14 @@ commonResumeList(JNIEnv *env)
12851281 /* count number of threads to hard resume */
12861282 (void ) enumerateOverThreadList (env , & runningThreads , resumeCountHelper ,
12871283 & reqCnt );
1284+ (void ) enumerateOverThreadList (env , & runningVThreads , resumeCountHelper ,
1285+ & reqCnt );
12881286 if (reqCnt == 0 ) {
12891287 /* nothing to hard resume so do just the accounting part */
12901288 (void ) enumerateOverThreadList (env , & runningThreads , resumeCopyHelper ,
12911289 NULL );
1290+ (void ) enumerateOverThreadList (env , & runningVThreads , resumeCopyHelper ,
1291+ NULL );
12921292 return JVMTI_ERROR_NONE ;
12931293 }
12941294
@@ -1307,13 +1307,15 @@ commonResumeList(JNIEnv *env)
13071307 reqPtr = reqList ;
13081308 (void ) enumerateOverThreadList (env , & runningThreads , resumeCopyHelper ,
13091309 & reqPtr );
1310+ (void ) enumerateOverThreadList (env , & runningVThreads , resumeCopyHelper ,
1311+ & reqPtr );
13101312
13111313 error = JVMTI_FUNC_PTR (gdata -> jvmti ,ResumeThreadList )
13121314 (gdata -> jvmti , reqCnt , reqList , results );
13131315 for (i = 0 ; i < reqCnt ; i ++ ) {
13141316 ThreadNode * node ;
13151317
1316- node = findThread ( & runningThreads , reqList [i ]);
1318+ node = findRunningThread ( reqList [i ]);
13171319 if (node == NULL ) {
13181320 EXIT_ERROR (AGENT_ERROR_INVALID_THREAD ,"missing entry in running thread table" );
13191321 }
@@ -1623,7 +1625,12 @@ threadControl_suspendAll(void)
16231625 }
16241626 }
16251627
1626- /* Increment suspend count of each virtual thread that we are tracking. */
1628+ /*
1629+ * Increment suspendCount of each virtual thread that we are tracking. Note the
1630+ * compliment to this that happens during the resumeAll() is handled by
1631+ * commonResumeList(), so it's a bit orthogonal to how we handle incrementing
1632+ * the suspendCount.
1633+ */
16271634 error = enumerateOverThreadList (env , & runningVThreads , incrementSupendCountHelper , NULL );
16281635 JDI_ASSERT (error == JVMTI_ERROR_NONE );
16291636 }
@@ -1681,16 +1688,6 @@ threadControl_suspendAll(void)
16811688 return error ;
16821689}
16831690
1684- static jvmtiError
1685- decrementSupendCountHelper (JNIEnv * env , ThreadNode * node , void * arg )
1686- {
1687- // Some vthreads might already have a suspendCount of 0. Just ignore them.
1688- if (node -> suspendCount > 0 ) {
1689- node -> suspendCount -- ;
1690- }
1691- return JVMTI_ERROR_NONE ;
1692- }
1693-
16941691static jvmtiError
16951692resumeHelper (JNIEnv * env , ThreadNode * node , void * ignored )
16961693{
@@ -1727,10 +1724,6 @@ threadControl_resumeAll(void)
17271724 EXIT_ERROR (error , "cannot resume all virtual threads" );
17281725 }
17291726 }
1730-
1731- /* Decrement suspend count of each virtual thread that we are tracking. */
1732- error = enumerateOverThreadList (env , & runningVThreads , decrementSupendCountHelper , NULL );
1733- JDI_ASSERT (error == JVMTI_ERROR_NONE );
17341727 }
17351728
17361729 /*
@@ -2567,6 +2560,18 @@ threadControl_reset(void)
25672560 env = getEnv ();
25682561 eventHandler_lock (); /* for proper lock order */
25692562 debugMonitorEnter (threadLock );
2563+
2564+ if (gdata -> vthreadsSupported ) {
2565+ if (suspendAllCount > 0 ) {
2566+ /* Tell JVMTI to resume all virtual threads. */
2567+ jvmtiError error = JVMTI_FUNC_PTR (gdata -> jvmti ,ResumeAllVirtualThreads )
2568+ (gdata -> jvmti );
2569+ if (error != JVMTI_ERROR_NONE ) {
2570+ EXIT_ERROR (error , "cannot resume all virtual threads" );
2571+ }
2572+ }
2573+ }
2574+
25702575 (void )enumerateOverThreadList (env , & runningThreads , resetHelper , NULL );
25712576 (void )enumerateOverThreadList (env , & otherThreads , resetHelper , NULL );
25722577 (void )enumerateOverThreadList (env , & runningVThreads , resetHelper , NULL );
0 commit comments