Skip to content

Commit 1fdf5cb

Browse files
committed
Optimized populating the JFR | Threads view, code cleanup
1 parent 162c35f commit 1fdf5cb

File tree

1 file changed

+59
-36
lines changed

1 file changed

+59
-36
lines changed

visualvm/jfr/src/org/graalvm/visualvm/jfr/views/threads/ThreadsViewSupport.java

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import java.util.Collections;
3535
import java.util.Comparator;
3636
import java.util.HashMap;
37+
import java.util.HashSet;
3738
import java.util.Iterator;
3839
import java.util.List;
3940
import java.util.Map;
41+
import java.util.Set;
4042
import java.util.TreeMap;
4143
import javax.swing.AbstractAction;
4244
import javax.swing.AbstractButton;
@@ -270,51 +272,74 @@ private static final class State {
270272
private long lastTimestamp = Long.MIN_VALUE;
271273
private Map<Long, List<State>> states;
272274
private Map<Long, Definition> definitions;
275+
private Set<String> ignoredEvents;
273276

274277
private boolean[] activeTypes = new boolean[6];
275278

276279
@Override
277280
public void init() {
278281
states = new HashMap();
279282
definitions = new TreeMap();
283+
ignoredEvents = new HashSet();
280284
}
281285

282286
@Override
283287
public boolean visit(String typeName, JFREvent event) {
284-
if ("jdk.ThreadStart".equals(typeName)) { // NOI18N
285-
processEvent(event, "thread", CommonConstants.THREAD_STATUS_RUNNING, Byte.MIN_VALUE); // NOI18N
286-
activeTypes[0] = true;
287-
} else if ("jdk.ThreadEnd".equals(typeName)) { // NOI18N
288-
processEvent(event, "thread", CommonConstants.THREAD_STATUS_ZOMBIE, Byte.MIN_VALUE); // NOI18N
289-
activeTypes[1] = true;
290-
} else if ("jdk.JavaMonitorWait".equals(typeName)) { // NOI18N
291-
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_WAIT, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
292-
activeTypes[2] = true;
293-
} else if ("jdk.JavaMonitorEnter".equals(typeName)) { // NOI18N
294-
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_MONITOR, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
295-
activeTypes[3] = true;
296-
} else if ("jdk.ThreadPark".equals(typeName)) { // NOI18N
297-
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_PARK, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
298-
activeTypes[4] = true;
299-
} else if ("jdk.ThreadSleep".equals(typeName)) { // NOI18N
300-
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_SLEEPING, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
301-
activeTypes[5] = true;
302-
} else if ("jdk.Compilation".equals(typeName)) { // ?? // NOI18N
303-
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_RUNNING, CommonConstants.THREAD_STATUS_PARK); // ?? // NOI18N
304-
} else if ("jdk.ThreadAllocationStatistics".equals(typeName)) { // NOI18N
305-
try {
306-
JFRThread thread = event.getThread("eventThread"); // NOI18N
307-
if (thread != null) {
308-
long allocated = event.getLong("allocated"); // NOI18N
309-
byte tstate = allocated > 0 ? CommonConstants.THREAD_STATUS_RUNNING : CommonConstants.THREAD_STATUS_WAIT; // ??
310-
processDefinition(thread.getId(), thread.getName(), ValuesConverter.instantToRelativeNanos(event.getInstant("eventTime"), jfrModel), tstate); // NOI18N
288+
switch (typeName) {
289+
case "jdk.ThreadStart": // NOI18N
290+
processEvent(event, "thread", CommonConstants.THREAD_STATUS_RUNNING, Byte.MIN_VALUE); // NOI18N
291+
activeTypes[0] = true;
292+
break;
293+
294+
case "jdk.ThreadEnd": // NOI18N
295+
processEvent(event, "thread", CommonConstants.THREAD_STATUS_ZOMBIE, Byte.MIN_VALUE); // NOI18N
296+
activeTypes[1] = true;
297+
break;
298+
299+
case "jdk.JavaMonitorWait": // NOI18N
300+
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_WAIT, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
301+
activeTypes[2] = true;
302+
break;
303+
304+
case "jdk.JavaMonitorEnter": // NOI18N
305+
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_MONITOR, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
306+
activeTypes[3] = true;
307+
break;
308+
309+
case "jdk.ThreadPark": // NOI18N
310+
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_PARK, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
311+
activeTypes[4] = true;
312+
break;
313+
314+
case "jdk.ThreadSleep": // NOI18N
315+
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_SLEEPING, CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
316+
activeTypes[5] = true;
317+
break;
318+
319+
case "jdk.Compilation": // NOI18N
320+
processEvent(event, "eventThread", CommonConstants.THREAD_STATUS_RUNNING, CommonConstants.THREAD_STATUS_PARK); // ?? // NOI18N
321+
break;
322+
323+
case "jdk.ThreadAllocationStatistics": // NOI18N
324+
try {
325+
JFRThread thread = event.getThread("eventThread"); // NOI18N
326+
if (thread != null) {
327+
long allocated = event.getLong("allocated"); // NOI18N
328+
byte tstate = allocated > 0 ? CommonConstants.THREAD_STATUS_RUNNING : CommonConstants.THREAD_STATUS_WAIT; // ??
329+
processDefinition(thread.getId(), thread.getName(), ValuesConverter.instantToRelativeNanos(event.getInstant("eventTime"), jfrModel), tstate); // NOI18N
330+
}
331+
} catch (JFRPropertyNotAvailableException e) { System.err.println(">>> --- " + e); }
332+
break;
333+
334+
default:
335+
try {
336+
if (!ignoredEvents.contains(typeName)) {
337+
JFRThread thread = event.getThread("eventThread"); // NOI18N
338+
if (thread != null) processDefinition(thread.getId(), thread.getName(), ValuesConverter.instantToRelativeNanos(event.getInstant("eventTime"), jfrModel), CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
339+
}
340+
} catch (JFRPropertyNotAvailableException e) {
341+
ignoredEvents.add(typeName);
311342
}
312-
} catch (JFRPropertyNotAvailableException e) { System.err.println(">>> --- " + e); }
313-
} else {
314-
try {
315-
JFRThread thread = event.getThread("eventThread"); // NOI18N
316-
if (thread != null) processDefinition(thread.getId(), thread.getName(), ValuesConverter.instantToRelativeNanos(event.getInstant("eventTime"), jfrModel), CommonConstants.THREAD_STATUS_RUNNING); // NOI18N
317-
} catch (JFRPropertyNotAvailableException e) {} // valid state, no eventThread defined for the event
318343
}
319344

320345
return false;
@@ -369,11 +394,9 @@ public void run() {
369394
}
370395
});
371396

372-
states.clear();
373397
states = null;
374-
375-
definitions.clear();
376398
definitions = null;
399+
ignoredEvents = null;
377400
}
378401

379402

0 commit comments

Comments
 (0)