22 *
23 */
24
25 package sun.jvm.hotspot.ui;
26
27 import java.awt.BorderLayout;
28 import java.awt.Dimension;
29
30 import java.awt.event.*;
31
32 import java.io.*;
33 import java.util.*;
34
35 import javax.swing.*;
36 import javax.swing.event.ListSelectionEvent;
37 import javax.swing.event.ListSelectionListener;
38 import javax.swing.table.*;
39
40 import sun.jvm.hotspot.debugger.*;
41 import sun.jvm.hotspot.runtime.*;
42
43 import sun.jvm.hotspot.ui.action.*;
44
45 import com.sun.java.swing.ui.*;
46 import com.sun.java.swing.action.*;
47
48 /**
49 * This panel contains a JTable which displays the list of Java
50 * threads as their native thread identifiers combined with their
51 * Java names. It allows selection and examination of any of the
52 * threads.
53 */
54 public class JavaThreadsPanel extends SAPanel implements ActionListener {
55 private JavaThreadsTableModel dataModel;
56 private StatusBar statusBar;
57 private JTable threadTable;
58 private java.util.List cachedThreads = new ArrayList();
59
60
61 /** Constructor assumes the threads panel is created while the VM is
62 suspended. Subsequent resume and suspend operations of the VM
63 will cause the threads panel to clear and fill itself back in,
64 respectively. */
65 public JavaThreadsPanel() {
66 VM.getVM().registerVMResumedObserver(new Observer() {
67 public void update(Observable o, Object data) {
68 decache();
69 }
70 });
71
72 VM.getVM().registerVMSuspendedObserver(new Observer() {
73 public void update(Observable o, Object data) {
74 cache();
75 }
76 });
77
78 cache();
79
80 setLayout(new BorderLayout());
420 return;
421 }
422 showJavaStackTrace(dataModel.getJavaThread(i));
423 }
424
425 private void fireShowThreadInfo() {
426 int i = threadTable.getSelectedRow();
427 if (i < 0) {
428 return;
429 }
430 showThreadInfo(dataModel.getJavaThread(i));
431 }
432
433 /**
434 * Shows stack memory for threads which have crashed (defined as
435 * having taken a signal above a Java frame)
436 *
437 * @return a flag which indicates if crashes were encountered.
438 */
439 private boolean fireShowThreadCrashes() {
440 boolean crash = false;
441 for (Iterator iter = cachedThreads.iterator(); iter.hasNext(); ) {
442 JavaThread t = (JavaThread) ((CachedThread) iter.next()).getThread();
443 sun.jvm.hotspot.runtime.Frame tmpFrame = t.getCurrentFrameGuess();
444 RegisterMap tmpMap = t.newRegisterMap(false);
445 while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
446 if (tmpFrame.isSignalHandlerFrameDbg()) {
447 showThreadStackMemory(t);
448 crash = true;
449 break;
450 }
451 tmpFrame = tmpFrame.sender(tmpMap);
452 }
453 }
454 return crash;
455 }
456
457 private void cache() {
458 Threads threads = VM.getVM().getThreads();
459 for (JavaThread t = threads.first(); t != null; t = t.next()) {
460 if (t.isJavaThread()) {
461 cachedThreads.add(new CachedThread(t));
462 }
463 }
464 }
465
466 private void decache() {
467 cachedThreads.clear();
468 }
469
470 }
|
22 *
23 */
24
25 package sun.jvm.hotspot.ui;
26
27 import java.awt.BorderLayout;
28 import java.awt.Dimension;
29
30 import java.awt.event.*;
31
32 import java.io.*;
33 import java.util.*;
34
35 import javax.swing.*;
36 import javax.swing.event.ListSelectionEvent;
37 import javax.swing.event.ListSelectionListener;
38 import javax.swing.table.*;
39
40 import sun.jvm.hotspot.debugger.*;
41 import sun.jvm.hotspot.runtime.*;
42 import sun.jvm.hotspot.types.*;
43
44 import sun.jvm.hotspot.ui.action.*;
45
46 import com.sun.java.swing.ui.*;
47 import com.sun.java.swing.action.*;
48
49 /**
50 * This panel contains a JTable which displays the list of Java
51 * threads as their native thread identifiers combined with their
52 * Java names. It allows selection and examination of any of the
53 * threads.
54 */
55 public class JavaThreadsPanel extends SAPanel implements ActionListener {
56 private JavaThreadsTableModel dataModel;
57 private StatusBar statusBar;
58 private JTable threadTable;
59 private java.util.List<CachedThread> cachedThreads = new ArrayList();
60 private static AddressField crashThread;
61
62
63 static {
64 VM.registerVMInitializedObserver(
65 (o, a) -> initialize(VM.getVM().getTypeDataBase()));
66 }
67
68 private static void initialize(TypeDataBase db) {
69 crashThread = db.lookupType("VMError").getAddressField("_thread");
70 }
71
72 /** Constructor assumes the threads panel is created while the VM is
73 suspended. Subsequent resume and suspend operations of the VM
74 will cause the threads panel to clear and fill itself back in,
75 respectively. */
76 public JavaThreadsPanel() {
77 VM.getVM().registerVMResumedObserver(new Observer() {
78 public void update(Observable o, Object data) {
79 decache();
80 }
81 });
82
83 VM.getVM().registerVMSuspendedObserver(new Observer() {
84 public void update(Observable o, Object data) {
85 cache();
86 }
87 });
88
89 cache();
90
91 setLayout(new BorderLayout());
431 return;
432 }
433 showJavaStackTrace(dataModel.getJavaThread(i));
434 }
435
436 private void fireShowThreadInfo() {
437 int i = threadTable.getSelectedRow();
438 if (i < 0) {
439 return;
440 }
441 showThreadInfo(dataModel.getJavaThread(i));
442 }
443
444 /**
445 * Shows stack memory for threads which have crashed (defined as
446 * having taken a signal above a Java frame)
447 *
448 * @return a flag which indicates if crashes were encountered.
449 */
450 private boolean fireShowThreadCrashes() {
451 Optional<JavaThread> crashed =
452 cachedThreads.stream()
453 .map(t -> t.getThread())
454 .filter(t -> t.getAddress().equals(
455 crashThread.getValue()))
456 .findAny();
457 crashed.ifPresent(this::showThreadStackMemory);
458 return crashed.isPresent();
459 }
460
461 private void cache() {
462 Threads threads = VM.getVM().getThreads();
463 for (JavaThread t = threads.first(); t != null; t = t.next()) {
464 if (t.isJavaThread()) {
465 cachedThreads.add(new CachedThread(t));
466 }
467 }
468 }
469
470 private void decache() {
471 cachedThreads.clear();
472 }
473
474 }
|