Skip to content

Commit 166c728

Browse files
committed
8255858: Add debug agent support for storing thread names
Reviewed-by: sspitsyn, amenkov
1 parent a0ade22 commit 166c728

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ typedef struct ThreadNode {
8484
struct ThreadNode *prev;
8585
jlong frameGeneration;
8686
struct ThreadList *list; /* Tells us what list this thread is in */
87+
#ifdef DEBUG_THREADNAME
88+
char name[256];
89+
#endif
8790
} ThreadNode;
8891

8992
static jint suspendAllCount;
@@ -349,6 +352,22 @@ insertThread(JNIEnv *env, ThreadList *list, jthread thread)
349352
node->eventBag = eventBag;
350353
addNode(list, node);
351354

355+
#ifdef DEBUG_THREADNAME
356+
{
357+
/* Set the thread name */
358+
jvmtiThreadInfo info;
359+
jvmtiError error;
360+
361+
memset(&info, 0, sizeof(info));
362+
error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
363+
(gdata->jvmti, node->thread, &info);
364+
if (info.name != NULL) {
365+
strncpy(node->name, info.name, sizeof(node->name) - 1);
366+
jvmtiDeallocate(info.name);
367+
}
368+
}
369+
#endif
370+
352371
/* Set thread local storage for quick thread -> node access.
353372
* Some threads may not be in a state that allows setting of TLS,
354373
* which is ok, see findThread, it deals with threads without TLS set.

0 commit comments

Comments
 (0)