@@ -70,8 +70,8 @@ class JavaThreadsProvider {
70
70
private static final String JNI_LOCAL = Bundle .JavaThreadsProvider_JniLocal ();
71
71
72
72
73
- static String getThreadName (Instance instance ) {
74
- if (isVirtualThread (instance )) {
73
+ static String getThreadName (JavaClass vtClass , Instance instance ) {
74
+ if (isVirtualThread (vtClass , instance )) {
75
75
return "Virtual Thread " +DetailsSupport .getDetailsString (instance ); // NOI18N
76
76
}
77
77
String threadName = getThreadInstanceName (instance );
@@ -137,6 +137,7 @@ static HeapViewerNode[] getThreadsNodes(RootNode rootNode, Heap heap) throws Int
137
137
List <HeapViewerNode > threadNodes = new ArrayList ();
138
138
139
139
Collection <GCRoot > roots = heap .getGCRoots ();
140
+ JavaClass vtClass = heap .getJavaClassByName ("java.lang.VirtualThread" ); // NOI18N
140
141
Map <ThreadObjectGCRoot ,Map <Integer ,List <GCRoot >>> javaFrameMap = computeJavaFrameMap (roots );
141
142
ThreadObjectGCRoot oome = JavaThreadsProvider .getOOMEThread (heap );
142
143
@@ -150,7 +151,7 @@ static HeapViewerNode[] getThreadsNodes(RootNode rootNode, Heap heap) throws Int
150
151
StackTraceElement stack [] = threadRoot .getStackTrace ();
151
152
Map <Integer ,List <GCRoot >> localsMap = javaFrameMap .get (threadRoot );
152
153
153
- String tName = JavaThreadsProvider .getThreadName (threadInstance );
154
+ String tName = JavaThreadsProvider .getThreadName (vtClass , threadInstance );
154
155
155
156
final List <HeapViewerNode > stackFrameNodes = new ArrayList ();
156
157
ThreadNode threadNode = new ThreadNode (tName , threadRoot .equals (oome ), threadInstance ) {
@@ -210,6 +211,7 @@ static String getThreadsHTML(HeapContext context) {
210
211
Map <ThreadObjectGCRoot ,Map <Integer ,List <GCRoot >>> javaFrameMap = computeJavaFrameMap (roots );
211
212
ThreadObjectGCRoot oome = JavaThreadsProvider .getOOMEThread (heap );
212
213
JavaClass javaClassClass = heap .getJavaClassByName (Class .class .getName ());
214
+ JavaClass vtClass = heap .getJavaClassByName ("java.lang.VirtualThread" ); // NOI18N
213
215
// Use this to enable VisualVM color scheme for threads dumps:
214
216
// sw.append("<pre style='color: #cc3300;'>"); // NOI18N
215
217
sb .append ("<head><style>span.g {color: #666666;}</style></head>" );
@@ -219,7 +221,7 @@ static String getThreadsHTML(HeapContext context) {
219
221
ThreadObjectGCRoot threadRoot = (ThreadObjectGCRoot )root ;
220
222
Instance threadInstance = threadRoot .getInstance ();
221
223
if (threadInstance != null ) {
222
- String threadName = JavaThreadsProvider .getThreadName (threadInstance );
224
+ String threadName = JavaThreadsProvider .getThreadName (vtClass , threadInstance );
223
225
StackTraceElement stack [] = threadRoot .getStackTrace ();
224
226
Map <Integer ,List <GCRoot >> localsMap = javaFrameMap .get (threadRoot );
225
227
String style ="" ; // NOI18N
@@ -303,11 +305,9 @@ private static String getThreadInstanceName(Instance threadInstance) {
303
305
return DetailsSupport .getDetailsString ((Instance )threadName );
304
306
}
305
307
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
308
+ private static boolean isVirtualThread (JavaClass vtClass , Instance threadInstance ) {
310
309
if (vtClass != null ) {
310
+ JavaClass threadClass = threadInstance .getJavaClass ();
311
311
for (;threadClass != null ; threadClass = threadClass .getSuperClass ()) {
312
312
if (threadClass .equals (vtClass )) return true ;
313
313
}
0 commit comments