Skip to content

Commit c9d8aab

Browse files
committed
GH-539 initial support for virtual threads added
1 parent 5c8989e commit c9d8aab

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/impl/JavaThreadsProvider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class JavaThreadsProvider {
7171

7272

7373
static String getThreadName(Instance instance) {
74+
if (isVirtualThread(instance)) {
75+
return "Virtual Thread "+DetailsSupport.getDetailsString(instance); // NOI18N
76+
}
7477
String threadName = getThreadInstanceName(instance);
7578
Long threadId = (Long)instance.getValueOfField("tid"); // NOI18N
7679
Boolean daemon = (Boolean)instance.getValueOfField("daemon"); // NOI18N
@@ -300,6 +303,18 @@ private static String getThreadInstanceName(Instance threadInstance) {
300303
return DetailsSupport.getDetailsString((Instance)threadName);
301304
}
302305

306+
private static boolean isVirtualThread(Instance threadInstance) {
307+
JavaClass threadClass = threadInstance.getJavaClass();
308+
Heap h = threadClass.getHeap();
309+
JavaClass vtClass = h.getJavaClassByName("java.lang.VirtualThread"); // NOI18N
310+
if (vtClass != null) {
311+
for (;threadClass != null; threadClass = threadClass.getSuperClass()) {
312+
if (threadClass.equals(vtClass)) return true;
313+
}
314+
}
315+
return false;
316+
}
317+
303318
private static Map<ThreadObjectGCRoot,Map<Integer,List<GCRoot>>> computeJavaFrameMap(Collection<GCRoot> roots) {
304319
Map<ThreadObjectGCRoot,Map<Integer,List<GCRoot>>> javaFrameMap = new HashMap();
305320

0 commit comments

Comments
 (0)