src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/HSDB.java
author pliden
Tue, 12 Jun 2018 17:40:28 +0200
changeset 50525 767cdb97f103
parent 50523 7b7c75d87f9b
child 52925 9c18c9d839d3
permissions -rw-r--r--
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental) Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke Contributed-by: per.liden@oracle.com, stefan.karlsson@oracle.com, erik.osterlund@oracle.com, mikael.gerdin@oracle.com, kim.barrett@oracle.com, nils.eliasson@oracle.com, rickard.backman@oracle.com, rwestrel@redhat.com, coleen.phillimore@oracle.com, robbin.ehn@oracle.com, gerard.ziemski@oracle.com, hugh.wilkinson@intel.com, sandhya.viswanathan@intel.com, bill.npo.wheeler@intel.com, vinay.k.awasthi@intel.com, yasuenag@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.compiler.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.debugger.*;
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47602
diff changeset
    36
import sun.jvm.hotspot.gc.epsilon.*;
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30590
diff changeset
    37
import sun.jvm.hotspot.gc.parallel.*;
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30590
diff changeset
    38
import sun.jvm.hotspot.gc.shared.*;
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    39
import sun.jvm.hotspot.gc.g1.*;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    40
import sun.jvm.hotspot.gc.z.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
import sun.jvm.hotspot.ui.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
import sun.jvm.hotspot.ui.tree.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
import sun.jvm.hotspot.ui.classbrowser.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
/** The top-level HotSpot Debugger. FIXME: make this an embeddable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    component! (Among other things, figure out what to do with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    menu bar...) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
public class HSDB implements ObjectHistogramPanel.Listener, SAListener {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  public static void main(String[] args) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    new HSDB(args).run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private HotSpotAgent agent;
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    63
  private JVMDebugger jvmDebugger;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private JDesktopPane desktop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private boolean      attached;
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    66
  private boolean      argError;
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    67
  private JFrame frame;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  /** List <JMenuItem> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  private java.util.List attachMenuItems;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  /** List <JMenuItem> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  private java.util.List detachMenuItems;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  private JMenu toolsMenu;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  private JMenuItem showDbgConsoleMenuItem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  private JMenuItem computeRevPtrsMenuItem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  private JInternalFrame attachWaitDialog;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  private JInternalFrame threadsFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  private JInternalFrame consoleFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  private WorkerThread workerThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // These had to be made data members because they are referenced in inner classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  private String pidText;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  private int pid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  private String execPath;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  private String coreFilename;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  private void doUsage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    System.out.println("Usage:  java HSDB [[pid] | [path-to-java-executable [path-to-corefile]] | help ]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    System.out.println("           pid:                     attach to the process whose id is 'pid'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    System.out.println("           path-to-java-executable: Debug a core file produced by this program");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    System.out.println("           path-to-corefile:        Debug this corefile.  The default is 'core'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    System.out.println("        If no arguments are specified, you can select what to do from the GUI.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    HotSpotAgent.showUsage();
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    92
    argError = true;
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    93
  }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    94
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    95
  public HSDB(JVMDebugger d) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
    96
    jvmDebugger = d;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  private HSDB(String[] args) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    switch (args.length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    case (0):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    case (1):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      if (args[0].equals("help") || args[0].equals("-help")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        doUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      // If all numbers, it is a PID to attach to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      // Else, it is a pathname to a .../bin/java for a core file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        int unused = Integer.parseInt(args[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        // If we get here, we have a PID and not a core file name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        pidText = args[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      } catch (NumberFormatException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        execPath = args[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        coreFilename = "core";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    case (2):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      execPath = args[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      coreFilename = args[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      System.out.println("HSDB Error: Too many options specified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      doUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
35045
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   131
  private class CloseUI extends WindowAdapter {
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   132
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   133
      @Override
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   134
      public void windowClosing(WindowEvent e) {
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   135
          workerThread.shutdown();
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   136
          frame.dispose();
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   137
      }
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   138
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   139
  }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   140
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   141
  public void run() {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   142
    // Don't start the UI if there were bad arguments.
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   143
    if (argError) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   144
        return;
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   145
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
35889
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   147
    // Create frame first, to catch any GUI creation issues
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   148
    // before we initialize agent
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   149
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   150
    frame = new JFrame("HSDB - HotSpot Debugger");
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   151
    frame.setSize(800, 600);
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   152
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   153
    frame.addWindowListener(new CloseUI());
d0d5d6cb28b6 8148104: HSDB could not terminate when launched on CLI
dsamersoff
parents: 35217
diff changeset
   154
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    agent = new HotSpotAgent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    workerThread = new WorkerThread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    attachMenuItems = new java.util.ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    detachMenuItems = new java.util.ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    JMenuBar menuBar = new JMenuBar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    // File menu
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    JMenu menu = new JMenu("File");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    menu.setMnemonic(KeyEvent.VK_F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    JMenuItem item;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    item = createMenuItem("Attach to HotSpot process...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                                showAttachDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    item.setMnemonic(KeyEvent.VK_A);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    menu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    attachMenuItems.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    item = createMenuItem("Open HotSpot core file...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                                showOpenCoreFileDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    item.setMnemonic(KeyEvent.VK_O);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    menu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    attachMenuItems.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    item = createMenuItem("Connect to debug server...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                                showConnectDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    item.setMnemonic(KeyEvent.VK_S);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    menu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    attachMenuItems.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    item = createMenuItem("Detach",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                                detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    item.setMnemonic(KeyEvent.VK_S);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    menu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    detachMenuItems.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // Disable detach menu items at first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    setMenuItemsEnabled(detachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    menu.addSeparator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    item = createMenuItem("Exit",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                            new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
                                public void actionPerformed(ActionEvent e) {
35045
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   222
                                  workerThread.shutdown();
d7725e7f76b1 8144332: HSDB could not terminate when close button is pushed.
ysuenaga
parents: 31399
diff changeset
   223
                                  frame.dispose();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                              });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    item.setMnemonic(KeyEvent.VK_X);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    menu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    menuBar.add(menu);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    // Tools menu
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    toolsMenu = new JMenu("Tools");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    toolsMenu.setMnemonic(KeyEvent.VK_T);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    item = createMenuItem("Class Browser",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
                                showClassBrowser();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    item.setMnemonic(KeyEvent.VK_B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    item = createMenuItem("Code Viewer",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                                showCodeViewer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    item.setMnemonic(KeyEvent.VK_C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    item = createMenuItem("Compute Reverse Ptrs",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
                                fireComputeReversePtrs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    computeRevPtrsMenuItem = item;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    item.setMnemonic(KeyEvent.VK_M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    item = createMenuItem("Deadlock Detection",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
                                showDeadlockDetectionPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    item.setMnemonic(KeyEvent.VK_D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    item = createMenuItem("Find Object by Query",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
                                showFindByQueryPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    item.setMnemonic(KeyEvent.VK_Q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    item = createMenuItem("Find Pointer",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
                                showFindPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    item.setMnemonic(KeyEvent.VK_P);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    item = createMenuItem("Find Value In Heap",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
                                showFindInHeapPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    item.setMnemonic(KeyEvent.VK_V);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    item = createMenuItem("Find Value In Code Cache",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
                                showFindInCodeCachePanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    item.setMnemonic(KeyEvent.VK_A);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    item = createMenuItem("Heap Parameters",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
                                showHeapParametersPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    item.setMnemonic(KeyEvent.VK_H);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    item = createMenuItem("Inspector",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
                                showInspector(null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    item.setMnemonic(KeyEvent.VK_R);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    item = createMenuItem("Memory Viewer",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
                                showMemoryViewer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    item.setMnemonic(KeyEvent.VK_M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    item = createMenuItem("Monitor Cache Dump",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
                                showMonitorCacheDumpPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    item.setMnemonic(KeyEvent.VK_D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    item = createMenuItem("Object Histogram",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
                              public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
                                showObjectHistogram();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    item.setMnemonic(KeyEvent.VK_O);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    item = createMenuItem("Show System Properties",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
                                showSystemProperties();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    item.setMnemonic(KeyEvent.VK_S);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    item = createMenuItem("Show VM Version",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                                showVMVersion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    item.setMnemonic(KeyEvent.VK_M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    item = createMenuItem("Show -XX flags",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
                                showCommandLineFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    item.setMnemonic(KeyEvent.VK_X);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    toolsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    toolsMenu.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    menuBar.add(toolsMenu);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    // Windows menu
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    JMenu windowsMenu = new JMenu("Windows");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    windowsMenu.setMnemonic(KeyEvent.VK_W);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    item = createMenuItem("Console",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
                          new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
                                 showConsole();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
                          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    item.setMnemonic(KeyEvent.VK_C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    windowsMenu.add(item);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    showDbgConsoleMenuItem = createMenuItem("Debugger Console",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                                         new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
                                             public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
                                               showDebuggerConsole();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
                                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
                                           });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    showDbgConsoleMenuItem.setMnemonic(KeyEvent.VK_D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    windowsMenu.add(showDbgConsoleMenuItem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    showDbgConsoleMenuItem.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    menuBar.add(windowsMenu);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    frame.setJMenuBar(menuBar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    desktop = new JDesktopPane();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    frame.getContentPane().add(desktop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    GraphicsUtilities.reshapeToAspectRatio(frame, 4.0f/3.0f, 0.75f, Toolkit.getDefaultToolkit().getScreenSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    GraphicsUtilities.centerInContainer(frame, Toolkit.getDefaultToolkit().getScreenSize());
578
862a85ed20db 6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents: 1
diff changeset
   424
    frame.setVisible(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    Runtime.getRuntime().addShutdownHook(new java.lang.Thread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
          detachDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   432
    // If jvmDebugger is already set, we have been given a JVMDebugger.
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   433
    // Otherwise, if pidText != null we are supposed to attach to it.
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   434
    // Finally, if execPath != null, it is the path of a jdk/bin/java
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   435
    // and coreFilename is the pathname of a core file we are
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   436
    // supposed to attach to.
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   437
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   438
    if (jvmDebugger != null) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   439
      attach(jvmDebugger);
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
   440
    } else if (pidText != null) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      attach(pidText);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    } else if (execPath != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      attach(execPath, coreFilename);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  private void showAttachDialog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    // FIXME: create filtered text field which only accepts numbers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    setMenuItemsEnabled(attachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    final JInternalFrame attachDialog = new JInternalFrame("Attach to HotSpot process");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    attachDialog.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    JPanel panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    attachDialog.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    panel.add(new JLabel("Enter process ID:"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    final JTextField pidTextField = new JTextField(10);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    ActionListener attacher = new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
          attachDialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
          desktop.remove(attachDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
          workerThread.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
              public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
                attach(pidTextField.getText());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    pidTextField.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    panel.add(pidTextField);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    attachDialog.getContentPane().add(panel, BorderLayout.NORTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    Box vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    JTextArea ta = new JTextArea(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
                                 "Enter the process ID of a currently-running HotSpot process. On " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
                                 "Solaris and most Unix operating systems, this can be determined by " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                                 "typing \"ps -u <your username> | grep java\"; the process ID is the " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
                                 "first number which appears on the resulting line. On Windows, the " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
                                 "process ID is present in the Task Manager, which can be brought up " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                                 "while logged on to the desktop by pressing Ctrl-Alt-Delete.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    ta.setLineWrap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    ta.setWrapStyleWord(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    ta.setEditable(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    ta.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    panel.add(ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    Box hbox = Box.createHorizontalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    JButton button = new JButton("OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    button.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    hbox.add(Box.createHorizontalStrut(20));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    button = new JButton("Cancel");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    button.addActionListener(new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
          attachDialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          desktop.remove(attachDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
          setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    panel.add(hbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    attachDialog.getContentPane().add(vbox, BorderLayout.SOUTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    desktop.add(attachDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    attachDialog.setSize(400, 300);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    GraphicsUtilities.centerInContainer(attachDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    attachDialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    pidTextField.requestFocus();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  private void showOpenCoreFileDialog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    setMenuItemsEnabled(attachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    final JInternalFrame dialog = new JInternalFrame("Open Core File");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    dialog.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    JPanel panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    dialog.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    Box hbox = Box.createHorizontalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    Box vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    vbox.add(new JLabel("Path to core file:"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    vbox.add(new JLabel("Path to Java executable:"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    hbox.add(vbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    final JTextField corePathField = new JTextField(40);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    final JTextField execPathField = new JTextField(40);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    vbox.add(corePathField);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    vbox.add(execPathField);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    hbox.add(vbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    final JButton browseCorePath = new JButton("Browse ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    final JButton browseExecPath = new JButton("Browse ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    browseCorePath.addActionListener(new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
                                        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
                                           JFileChooser fileChooser = new JFileChooser(new File("."));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
                                           int retVal = fileChooser.showOpenDialog(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
                                           if (retVal == JFileChooser.APPROVE_OPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
                                              corePathField.setText(fileChooser.getSelectedFile().getPath());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
                                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
                                     });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    browseExecPath.addActionListener(new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
                                        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
                                           JFileChooser fileChooser = new JFileChooser(new File("."));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
                                           int retVal = fileChooser.showOpenDialog(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
                                           if (retVal == JFileChooser.APPROVE_OPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
                                              execPathField.setText(fileChooser.getSelectedFile().getPath());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
                                           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
                                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
                                     });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    vbox.add(browseCorePath);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    vbox.add(browseExecPath);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    hbox.add(vbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    panel.add(hbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    dialog.getContentPane().add(panel, BorderLayout.NORTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    ActionListener attacher = new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
          dialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
          desktop.remove(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
          workerThread.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
              public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
                attach(execPathField.getText(), corePathField.getText());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    corePathField.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    execPathField.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    JTextArea ta = new JTextArea(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
                                 "Enter the full path names to the core file from a HotSpot process " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
                                 "and the Java executable from which it came. The latter is typically " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
                                 "located in the JDK/JRE directory under the directory " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                                 "jre/bin/<arch>/native_threads.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    ta.setLineWrap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    ta.setWrapStyleWord(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    ta.setEditable(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    ta.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    panel.add(ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    hbox = Box.createHorizontalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    JButton button = new JButton("OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    button.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    hbox.add(Box.createHorizontalStrut(20));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    button = new JButton("Cancel");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    button.addActionListener(new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
          dialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
          desktop.remove(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
          setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    panel.add(hbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    dialog.getContentPane().add(vbox, BorderLayout.SOUTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    desktop.add(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    dialog.setSize(500, 300);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    GraphicsUtilities.centerInContainer(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    dialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    corePathField.requestFocus();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  private void showConnectDialog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    // FIXME: create filtered text field which only accepts numbers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    setMenuItemsEnabled(attachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    final JInternalFrame dialog = new JInternalFrame("Connect to HotSpot Debug Server");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    dialog.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    JPanel panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    dialog.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    panel.add(new JLabel("Enter machine name:"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    final JTextField pidTextField = new JTextField(40);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    ActionListener attacher = new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
          dialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
          desktop.remove(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
          workerThread.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
              public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
                connect(pidTextField.getText());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    pidTextField.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    panel.add(pidTextField);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    dialog.getContentPane().add(panel, BorderLayout.NORTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    Box vbox = Box.createVerticalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    JTextArea ta = new JTextArea(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
                                 "Enter the name of a machine on which the HotSpot \"Debug Server\" is " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
                                 "running and is attached to a process or core file.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    ta.setLineWrap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    ta.setWrapStyleWord(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    ta.setEditable(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    ta.setBackground(panel.getBackground());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    panel.add(ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    Box hbox = Box.createHorizontalBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    JButton button = new JButton("OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    button.addActionListener(attacher);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    hbox.add(Box.createHorizontalStrut(20));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    button = new JButton("Cancel");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    button.addActionListener(new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
          dialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
          desktop.remove(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
          setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    hbox.add(button);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
    hbox.add(Box.createGlue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
    panel.add(hbox);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    vbox.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    dialog.getContentPane().add(vbox, BorderLayout.SOUTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    desktop.add(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    dialog.setSize(400, 300);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    GraphicsUtilities.centerInContainer(dialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    dialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    pidTextField.requestFocus();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  public void showThreadOopInspector(JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    showInspector(new OopTreeNodeAdapter(thread.getThreadObj(), null));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  public void showInspector(SimpleTreeNode adapter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    showPanel("Inspector", new Inspector(adapter), 1.0f, 0.65f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  public void showLiveness(Oop oop, LivenessPathList liveness) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    PrintStream tty = new PrintStream(bos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    int numPaths = liveness.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    for (int i = 0; i < numPaths; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      tty.println("Path " + (i + 1) + " of " + numPaths + ":");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
      liveness.get(i).printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    JTextArea ta = new JTextArea(bos.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    ta.setLineWrap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    ta.setWrapStyleWord(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    ta.setEditable(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    JPanel panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
    panel.setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    JScrollPane scroller = new JScrollPane();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    scroller.getViewport().add(ta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    panel.add(scroller, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
    tty = new PrintStream(bos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    tty.print("Liveness result for ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    Oop.printOopValueOn(oop, tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    JInternalFrame frame = new JInternalFrame(bos.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    frame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    frame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    frame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
    frame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    frame.getContentPane().add(panel, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    frame.pack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
    desktop.add(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    GraphicsUtilities.reshapeToAspectRatio(frame, 0.5f / 0.2f, 0.5f, frame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    frame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  private void fireComputeReversePtrs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    // Possible this might have been computed elsewhere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    if (VM.getVM().getRevPtrs() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      computeRevPtrsMenuItem.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    workerThread.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
          HeapProgress progress = new HeapProgress("Reverse Pointers Analysis");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
            ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
            analysis.setHeapProgressThunk(progress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
            analysis.run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
            computeRevPtrsMenuItem.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
          } catch (OutOfMemoryError e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
            final String errMsg = formatMessage(e.toString(), 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
            SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
                public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                  JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
                                                        "Error computing reverse pointers:" + errMsg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
                                                        "Error",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
                                                        JOptionPane.WARNING_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
              });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
          } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
            // make sure the progress bar goes away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
            progress.heapIterationComplete();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  // Simple struct containing signal information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  class SignalInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    public int sigNum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    public String sigName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  // Need to have mutable vframe as well as visible memory panel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  abstract class StackWalker implements Runnable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    protected JavaVFrame vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    protected AnnotatedMemoryPanel annoPanel;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    StackWalker(JavaVFrame vf, AnnotatedMemoryPanel annoPanel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      this.vf = vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
      this.annoPanel = annoPanel;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  public void showThreadStackMemory(final JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    // dumpStack(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    JavaVFrame vframe = getLastJavaVFrame(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    if (vframe == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
                                            "Thread \"" + thread.getThreadName() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
                                            "\" has no Java frames on its stack",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
                                            "Show Stack Memory",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
                                            JOptionPane.INFORMATION_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
    JInternalFrame stackFrame = new JInternalFrame("Stack Memory for " + thread.getThreadName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    stackFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    stackFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    stackFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    stackFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    final long addressSize = agent.getTypeDataBase().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    boolean is64Bit = (addressSize == 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    // This is somewhat of a  hack to guess a thread's stack limits since the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    // JavaThread doesn't support this functionality. However it is nice in that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    // it locks us into the active region of the thread's stack and not its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    // theoretical limits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    sun.jvm.hotspot.runtime.Frame tmpFrame = thread.getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    Address sp = tmpFrame.getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    Address starting = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    Address maxSP = starting;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    Address minSP = starting;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    RegisterMap tmpMap = thread.newRegisterMap(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
        tmpFrame = tmpFrame.sender(tmpMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
        if (tmpFrame != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
          sp = tmpFrame.getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
          if (sp != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
            maxSP = AddressOps.max(maxSP, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
            minSP = AddressOps.min(minSP, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    // It is useful to be able to see say +/- 8K on the current stack range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    AnnotatedMemoryPanel annoMemPanel = new AnnotatedMemoryPanel(agent.getDebugger(), is64Bit, starting,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
                                                                 minSP.addOffsetTo(-8192),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
                                                                 maxSP.addOffsetTo( 8192));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    stackFrame.getContentPane().add(annoMemPanel, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    desktop.add(stackFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    GraphicsUtilities.reshapeToAspectRatio(stackFrame, 4.0f / 3.0f, 0.85f, stackFrame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    stackFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    // Stackmap computation for interpreted frames is expensive; do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    // all stackwalking work in another thread for better GUI
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    // responsiveness
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    workerThread.invokeLater(new StackWalker(vframe, annoMemPanel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
          Address startAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
          // As this is a debugger, we want to provide potential crash
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
          // information to the user, i.e., by marking signal handler frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
          // on the stack. Since this system is currently targeted at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
          // annotating the Java frames (interpreted or compiled) on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
          // stack and not, for example, "external" frames (note the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
          // absence of a PC-to-symbol lookup mechanism at the Debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
          // level), we want to mark any Java frames which were interrupted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
          // by a signal. We do this by making two passes over the stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
          // one which finds signal handler frames and puts the parent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
          // frames in a table and one which finds Java frames and if they
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
          // are in the table indicates that they were interrupted by a signal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
          Map interruptedFrameMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
          {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
            sun.jvm.hotspot.runtime.Frame tmpFrame = thread.getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
            RegisterMap tmpMap = thread.newRegisterMap(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
            while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
              if (tmpFrame.isSignalHandlerFrameDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
                // Add some information to the map that we can extract later
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
                sun.jvm.hotspot.runtime.Frame interruptedFrame = tmpFrame.sender(tmpMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
                SignalInfo info = new SignalInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
                info.sigNum  = tmpFrame.getSignalNumberDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
                info.sigName = tmpFrame.getSignalNameDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
                interruptedFrameMap.put(interruptedFrame, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
              tmpFrame = tmpFrame.sender(tmpMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
          while (vf != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
            String anno = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
            JavaVFrame curVFrame = vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
            sun.jvm.hotspot.runtime.Frame curFrame = curVFrame.getFrame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
            Method interpreterFrameMethod = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
            if (curVFrame.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
              anno = "Interpreted frame";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
              anno = "Compiled frame";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
              if (curVFrame.isDeoptimized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
                anno += " (deoptimized)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
            if (curVFrame.mayBeImpreciseDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
              anno += "; information may be imprecise";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
            if (curVFrame.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
              // Find the codelet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
              InterpreterCodelet codelet = VM.getVM().getInterpreter().getCodeletContaining(curFrame.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
              String description = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
              if (codelet != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
                description = codelet.getDescription();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
              if (description == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
                anno += "\n(Unknown interpreter codelet)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
                anno += "\nExecuting in codelet \"" + description + "\" at PC = " + curFrame.getPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
            } else if (curVFrame.isCompiledFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
              anno += "\nExecuting at PC = " + curFrame.getPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
            if (startAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
              startAddr = curFrame.getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
            // FIXME: some compiled frames with empty oop map sets have been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
            // found (for example, Vector's inner Enumeration class, method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
            // "hasMoreElements"). Not sure yet why these cases are showing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
            // up -- should be possible (though unlikely) for safepoint code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
            // to patch the return instruction of these methods and then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
            // later attempt to get an oop map for that instruction. For
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
            // now, we warn if we find such a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
            boolean shouldSkipOopMaps = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
            if (curVFrame.isCompiledFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
              CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 22234
diff changeset
   942
              ImmutableOopMapSet maps = cb.getOopMaps();
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   943
              if ((maps == null) || (maps.getCount() == 0)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
                shouldSkipOopMaps = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
            // Add signal information to annotation if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
            SignalInfo sigInfo = (SignalInfo) interruptedFrameMap.get(curFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
            if (sigInfo != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
              // This frame took a signal and we need to report it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
              anno = (anno + "\n*** INTERRUPTED BY SIGNAL " + Integer.toString(sigInfo.sigNum) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
                      " (" + sigInfo.sigName + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
            JavaVFrame nextVFrame = curVFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
            sun.jvm.hotspot.runtime.Frame nextFrame = curFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
            do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
              curVFrame = nextVFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
              curFrame = nextFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
              try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
                Method method = curVFrame.getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
                if (interpreterFrameMethod == null && curVFrame.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
                  interpreterFrameMethod = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
                int bci = curVFrame.getBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
                String lineNumberAnno = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
                if (method.hasLineNumberTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
                  if ((bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
                      (bci >= 0 && bci < method.getCodeSize())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
                    lineNumberAnno = ", line " + method.getLineNumberFromBCI(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
                  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
                    lineNumberAnno = " (INVALID BCI)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
                anno += "\n" + method.getMethodHolder().getName().asString() + "." +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
                               method.getName().asString() + method.getSignature().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
                               "\n@bci " + bci + lineNumberAnno;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
              } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
                anno += "\n(ERROR while iterating vframes for frame " + curFrame + ")";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
              nextVFrame = curVFrame.javaSender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
              if (nextVFrame != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
                nextFrame = nextVFrame.getFrame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
            } while (nextVFrame != null && nextFrame.equals(curFrame));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
            if (shouldSkipOopMaps) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 22234
diff changeset
   991
              anno = anno + "\nNOTE: null or empty ImmutableOopMapSet found for this CodeBlob";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
            if (curFrame.getFP() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
              annoPanel.addAnnotation(new Annotation(curFrame.getSP(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
                                                     curFrame.getFP(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
                                                     anno));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
            } else {
31399
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
   999
              // For C2, which has null frame pointers on x86/amd64/aarch64
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1000
              CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1001
              Address sp = curFrame.getSP();
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1002
              if (Assert.ASSERTS_ENABLED) {
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1003
                Assert.that(cb.getFrameSize() > 0, "CodeBlob must have non-zero frame size");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
              }
31399
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1005
              annoPanel.addAnnotation(new Annotation(sp,
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1006
                                                     sp.addOffsetTo(cb.getFrameSize()),
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 30776
diff changeset
  1007
                                                     anno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
            // Add interpreter frame annotations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
            if (curFrame.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
              annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameExpressionStack(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
                                                     curFrame.addressOfInterpreterFrameTOS(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
                                                     "Interpreter expression stack"));
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1015
              Address monBegin = curFrame.interpreterFrameMonitorBegin().address();
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1016
              Address monEnd = curFrame.interpreterFrameMonitorEnd().address();
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1017
              if (!monBegin.equals(monEnd)) {
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1018
                  annoPanel.addAnnotation(new Annotation(monBegin, monEnd,
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1019
                                                         "BasicObjectLocks"));
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
  1020
              }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
              if (interpreterFrameMethod != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
                // The offset is just to get the right stack slots highlighted in the output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
                int offset = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
                annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameLocal(offset),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
                                                       curFrame.addressOfInterpreterFrameLocal((int) interpreterFrameMethod.getMaxLocals() + offset),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
                                                       "Interpreter locals area for frame with SP = " + curFrame.getSP()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
              }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10517
diff changeset
  1028
              String methodAnno = "Interpreter frame Method*";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
              if (interpreterFrameMethod == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
                methodAnno += " (BAD OOP)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
              Address a = curFrame.addressOfInterpreterFrameMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
              annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), methodAnno));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
              a = curFrame.addressOfInterpreterFrameCPCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
              annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), "Interpreter constant pool cache"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
            RegisterMap rm = (RegisterMap) vf.getRegisterMap().clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
            if (!shouldSkipOopMaps) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
              try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
                curFrame.oopsDo(new AddressVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
                    public void visitAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
                      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
                        Assert.that(addr.andWithMask(VM.getVM().getAddressSize() - 1) == null,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
                                    "Address " + addr + "should have been aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
                      }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1047
                      OopHandle handle = addr.getOopHandleAt(0);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1048
                      addAnnotation(addr, handle);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1049
                    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1050
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1051
                    public void visitCompOopAddress(Address addr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1052
                      if (Assert.ASSERTS_ENABLED) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1053
                        Assert.that(addr.andWithMask(VM.getVM().getAddressSize() - 1) == null,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1054
                                    "Address " + addr + "should have been aligned");
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1055
                      }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1056
                      OopHandle handle = addr.getCompOopHandleAt(0);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1057
                      addAnnotation(addr, handle);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1058
                    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1059
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1060
                    public void addAnnotation(Address addr, OopHandle handle) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
                      // Check contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
                      String anno = "null oop";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
                      if (handle != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
                        // Find location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
                        CollectedHeap collHeap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
                        boolean bad = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
                        anno = "BAD OOP";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
                        if (collHeap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
                          GenCollectedHeap heap = (GenCollectedHeap) collHeap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
                          for (int i = 0; i < heap.nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
                            if (heap.getGen(i).isIn(handle)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
                              if (i == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
                                anno = "NewGen ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
                              } else if (i == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
                                anno = "OldGen ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
                              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
                                anno = "Gen " + i + " ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
                              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
                              bad = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
                              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1084
                        } else if (collHeap instanceof G1CollectedHeap) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1085
                          G1CollectedHeap heap = (G1CollectedHeap)collHeap;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1086
                          HeapRegion region = heap.hrm().getByAddress(handle);
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1087
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1088
                          if (region.isFree()) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1089
                            anno = "Free ";
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1090
                            bad = false;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1091
                          } else if (region.isYoung()) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1092
                            anno = "Young ";
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1093
                            bad = false;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1094
                          } else if (region.isHumongous()) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1095
                            anno = "Humongous ";
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1096
                            bad = false;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1097
                          } else if (region.isPinned()) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1098
                            anno = "Pinned ";
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1099
                            bad = false;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1100
                          } else if (region.isOld()) {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1101
                            anno = "Old ";
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1102
                            bad = false;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
  1103
                          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
                        } else if (collHeap instanceof ParallelScavengeHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
                          ParallelScavengeHeap heap = (ParallelScavengeHeap) collHeap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
                          if (heap.youngGen().isIn(handle)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
                            anno = "PSYoungGen ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
                            bad = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
                          } else if (heap.oldGen().isIn(handle)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
                            anno = "PSOldGen ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
                            bad = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
                          }
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47602
diff changeset
  1113
                        } else if (collHeap instanceof EpsilonHeap) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47602
diff changeset
  1114
                          anno = "Epsilon ";
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47602
diff changeset
  1115
                          bad = false;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
  1116
                        } else if (collHeap instanceof ZCollectedHeap) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
  1117
                          ZCollectedHeap heap = (ZCollectedHeap) collHeap;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
  1118
                          anno = "ZHeap ";
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
  1119
                          bad = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
                        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
                          // Optimistically assume the oop isn't bad
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
                          anno = "[Unknown generation] ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
                          bad = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
                        if (!bad) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
                          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
                            Oop oop = VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
                            if (oop instanceof Instance) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
                                // Java-level objects always have workable names
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
                              anno = anno + oop.getKlass().getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
                            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
                              ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
                              Oop.printOopValueOn(oop, new PrintStream(bos));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
                              anno = anno + bos.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
                            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
                          catch (AddressException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
                            anno += "CORRUPT OOP";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
                          catch (NullPointerException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
                            anno += "CORRUPT OOP (null pointer)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
                          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
                      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
                      annoPanel.addAnnotation(new Annotation(addr, addr.addOffsetTo(addressSize), anno));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
                  }, rm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
              } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
                System.err.println("Error while performing oopsDo for frame " + curFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
                e.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
            vf = nextVFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
          // This used to paint as we walked the frames. This caused the display to be refreshed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
          // enough to be annoying on remote displays. It also would cause the annotations to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
          // be displayed in varying order which caused some annotations to overwrite others
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
          // depending on the races between painting and adding annotations. This latter problem
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
          // still exists to some degree but moving this code here definitely seems to reduce it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
          annoPanel.makeVisible(startAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
          annoPanel.repaint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1170
  // Attach to existing JVMDebugger, which should be already attached to a core/process.
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1171
  private void attach(JVMDebugger d) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1172
    attached = true;
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1173
    showThreadsDialog();
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1174
  }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 13728
diff changeset
  1175
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  /** NOTE we are in a different thread here than either the main
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
      thread or the Swing/AWT event handler thread, so we must be very
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
      careful when creating or removing widgets */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  private void attach(String pidText) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
      this.pidText = pidText;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
      pid = Integer.parseInt(pidText);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    catch (NumberFormatException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
            setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
            JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
                                                  "Unable to parse process ID \"" + HSDB.this.pidText + "\".\nPlease enter a number.",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
                                                  "Parse error",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
                                                  JOptionPane.WARNING_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    // Try to attach to this process
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    Runnable remover = new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
            attachWaitDialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
            desktop.remove(attachWaitDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
            attachWaitDialog = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
            JOptionPane pane = new JOptionPane("Attaching to process " + pid + ", please wait...", JOptionPane.INFORMATION_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
            pane.setOptions(new Object[] {});
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
            attachWaitDialog = pane.createInternalFrame(desktop, "Attaching to Process");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
            attachWaitDialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
      // FIXME: display exec'd debugger's output messages during this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
      // lengthy call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
      agent.attach(pid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
      if (agent.getDebugger().hasConsole()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
        showDbgConsoleMenuItem.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
      attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    catch (DebuggerException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
      final String errMsg = formatMessage(e.getMessage(), 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
            setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
            JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
                                                  "Unable to connect to process ID " + pid + ":\n\n" + errMsg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
                                                  "Unable to Connect",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
                                                  JOptionPane.WARNING_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
      agent.detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    // OK, the VM should be available. Create the Threads dialog.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    showThreadsDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  /** NOTE we are in a different thread here than either the main
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
      thread or the Swing/AWT event handler thread, so we must be very
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
      careful when creating or removing widgets */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
  private void attach(final String executablePath, final String corePath) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    // Try to open this core file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
    Runnable remover = new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
            attachWaitDialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
            desktop.remove(attachWaitDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
            attachWaitDialog = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
            JOptionPane pane = new JOptionPane("Opening core file, please wait...", JOptionPane.INFORMATION_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
            pane.setOptions(new Object[] {});
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
            attachWaitDialog = pane.createInternalFrame(desktop, "Opening Core File");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
            attachWaitDialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
      // FIXME: display exec'd debugger's output messages during this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
      // lengthy call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
      agent.attach(executablePath, corePath);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
      if (agent.getDebugger().hasConsole()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
        showDbgConsoleMenuItem.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
      attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    catch (DebuggerException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
      final String errMsg = formatMessage(e.getMessage(), 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
            setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
            JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
                                                  "Unable to open core file\n" + corePath + ":\n\n" + errMsg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
                                                  "Unable to Open Core File",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
                                                  JOptionPane.WARNING_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
      agent.detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    // OK, the VM should be available. Create the Threads dialog.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    showThreadsDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  /** NOTE we are in a different thread here than either the main
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
      thread or the Swing/AWT event handler thread, so we must be very
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
      careful when creating or removing widgets */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
  private void connect(final String remoteMachineName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    // Try to open this core file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
    Runnable remover = new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
            attachWaitDialog.setVisible(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
            desktop.remove(attachWaitDialog);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
            attachWaitDialog = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
            JOptionPane pane = new JOptionPane("Connecting to debug server, please wait...", JOptionPane.INFORMATION_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
            pane.setOptions(new Object[] {});
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
            attachWaitDialog = pane.createInternalFrame(desktop, "Connecting to Debug Server");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
            attachWaitDialog.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
      agent.attach(remoteMachineName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
      if (agent.getDebugger().hasConsole()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
        showDbgConsoleMenuItem.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
      attached = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    catch (DebuggerException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
      SwingUtilities.invokeLater(remover);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
      final String errMsg = formatMessage(e.getMessage(), 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
            setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
            JOptionPane.showInternalMessageDialog(desktop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
                                                  "Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
                                                  "Unable to Connect",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
                                                  JOptionPane.WARNING_MESSAGE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
      agent.detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
    // OK, the VM should be available. Create the Threads dialog.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
    showThreadsDialog();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
  private void detachDebugger() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    if (!attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
    agent.detach();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
    attached = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
  private void detach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
    detachDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
    attachWaitDialog = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
    threadsFrame = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
    consoleFrame = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
    setMenuItemsEnabled(attachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
    setMenuItemsEnabled(detachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
    toolsMenu.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
    showDbgConsoleMenuItem.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
    // FIXME: is this sufficient, or will I have to do anything else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
    // to the components to kill them off? What about WorkerThreads?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    desktop.removeAll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
    desktop.invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    desktop.validate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
    desktop.repaint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  /** NOTE that this is called from another thread than the main or
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
      Swing thread and we have to be careful about synchronization */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
  private void showThreadsDialog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
    SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
          threadsFrame = new JInternalFrame("Java Threads");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
          threadsFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
          threadsFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
          JavaThreadsPanel threadsPanel = new JavaThreadsPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
          threadsPanel.addPanelListener(HSDB.this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
          threadsFrame.getContentPane().add(threadsPanel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
          threadsFrame.setSize(500, 300);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
          threadsFrame.pack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
          desktop.add(threadsFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
          GraphicsUtilities.moveToInContainer(threadsFrame, 0.75f, 0.25f, 0, 20);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
          threadsFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
          setMenuItemsEnabled(attachMenuItems, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
          setMenuItemsEnabled(detachMenuItems, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
          toolsMenu.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
          VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
              public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
                computeRevPtrsMenuItem.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  private void showObjectHistogram() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
    sun.jvm.hotspot.oops.ObjectHistogram histo = new sun.jvm.hotspot.oops.ObjectHistogram();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
    ObjectHistogramCleanupThunk cleanup =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
      new ObjectHistogramCleanupThunk(histo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    doHeapIteration("Object Histogram",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
                    "Generating histogram...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
                    histo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
                    cleanup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  class ObjectHistogramCleanupThunk implements CleanupThunk {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    sun.jvm.hotspot.oops.ObjectHistogram histo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
    ObjectHistogramCleanupThunk(sun.jvm.hotspot.oops.ObjectHistogram histo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
      this.histo = histo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
    public void heapIterationComplete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
            JInternalFrame histoFrame = new JInternalFrame("Object Histogram");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
            histoFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
            histoFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
            histoFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
            histoFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
            ObjectHistogramPanel panel = new ObjectHistogramPanel(histo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
            panel.addPanelListener(HSDB.this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
            histoFrame.getContentPane().add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
            desktop.add(histoFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
            GraphicsUtilities.reshapeToAspectRatio(histoFrame, 4.0f / 3.0f, 0.6f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
                                       histoFrame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
            GraphicsUtilities.centerInContainer(histoFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
            histoFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  public void showObjectsOfType(Klass type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    FindObjectByType finder = new FindObjectByType(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
    FindObjectByTypeCleanupThunk cleanup =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
      new FindObjectByTypeCleanupThunk(finder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    type.printValueOn(new PrintStream(bos));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    String typeName = bos.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    doHeapIteration("Show Objects Of Type",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
                    "Finding instances of \"" + typeName + "\"",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
                    finder,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
                    cleanup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  class FindObjectByTypeCleanupThunk implements CleanupThunk {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
    FindObjectByType finder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    FindObjectByTypeCleanupThunk(FindObjectByType finder) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
      this.finder = finder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
    public void heapIterationComplete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
            JInternalFrame finderFrame = new JInternalFrame("Show Objects of Type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
            finderFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
            finderFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
            finderFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
            finderFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
            ObjectListPanel panel = new ObjectListPanel(finder.getResults(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
                                                        new HeapProgress("Reverse Pointers Analysis"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
            panel.addPanelListener(HSDB.this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
            finderFrame.getContentPane().add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
            desktop.add(finderFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
            GraphicsUtilities.reshapeToAspectRatio(finderFrame, 4.0f / 3.0f, 0.6f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
                                       finderFrame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
            GraphicsUtilities.centerInContainer(finderFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
            finderFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
  private void showDebuggerConsole() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    if (consoleFrame == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
      consoleFrame = new JInternalFrame("Debugger Console");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
      consoleFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
      consoleFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
      consoleFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
      consoleFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
      consoleFrame.getContentPane().add(new DebuggerConsolePanel(agent.getDebugger()), BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
      GraphicsUtilities.reshapeToAspectRatio(consoleFrame, 5.0f, 0.9f, desktop.getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
    if (consoleFrame.getParent() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
      desktop.add(consoleFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
    consoleFrame.setVisible(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
    consoleFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
    consoleFrame.getContentPane().getComponent(0).requestFocus();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
  private void showConsole() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
      CommandProcessor.DebuggerInterface di = new CommandProcessor.DebuggerInterface() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
              public HotSpotAgent getAgent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
                  return agent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
              public boolean isAttached() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
                  return attached;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
              public void attach(String pid) {
42548
5ba95648287f 7107014: sun.jvm.hotspot.HSDB.FindObjectByTypeCleanupThunk.showConsole.attach infinite loop
vtewari
parents: 35889
diff changeset
  1507
                  HSDB.this.attach(pid);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
              public void attach(String java, String core) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
              public void detach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
                  detachDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
              public void reattach() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
                  if (attached) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
                      detachDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
                  if (pidText != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
                      attach(pidText);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
                  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
                      attach(execPath, coreFilename);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
          };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
      showPanel("Command Line", new CommandProcessorPanel(new CommandProcessor(di, null, null, null)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
  private void showFindByQueryPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    showPanel("Find Object by Query", new FindByQueryPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
  private void showFindPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
    showPanel("Find Pointer", new FindPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
  private void showFindInHeapPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
    showPanel("Find Address In Heap", new FindInHeapPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  private void showFindInCodeCachePanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
    showPanel("Find Address In Code Cache", new FindInCodeCachePanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
  private void showHeapParametersPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    showPanel("Heap Parameters", new HeapParametersPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
  public void showThreadInfo(final JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
    showPanel("Info for " + thread.getThreadName(), new ThreadInfoPanel(thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
  public void showJavaStackTrace(final JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
    JavaStackTracePanel jstp = new JavaStackTracePanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
    showPanel("Java stack trace for " + thread.getThreadName(), jstp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
    jstp.setJavaThread(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  private void showDeadlockDetectionPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
    showPanel("Deadlock Detection", new DeadlockDetectionPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
  private void showMonitorCacheDumpPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
    showPanel("Monitor Cache Dump", new MonitorCacheDumpPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  public void showClassBrowser() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
    final JInternalFrame progressFrame = new JInternalFrame("Class Browser");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
    progressFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
    progressFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
    progressFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
    progressFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
    final ProgressBarPanel bar = new ProgressBarPanel("Generating class list ..");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
    bar.setIndeterminate(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
    progressFrame.getContentPane().add(bar, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
    desktop.add(progressFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
    progressFrame.pack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
    GraphicsUtilities.centerInContainer(progressFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
    progressFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    workerThread.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
                                public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
                                   HTMLGenerator htmlGen = new HTMLGenerator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
                                   InstanceKlass[] klasses = SystemDictionaryHelper.getAllInstanceKlasses();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
                                   final String htmlText = htmlGen.genHTMLForKlassNames(klasses);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
                                   SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
                                      public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
                                         JInternalFrame cbFrame = new JInternalFrame("Class Browser");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
                                         cbFrame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
                                         cbFrame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
                                         cbFrame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
                                         cbFrame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
                                         ClassBrowserPanel cbPanel = new ClassBrowserPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
                                         cbFrame.getContentPane().add(cbPanel, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
                                         desktop.remove(progressFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
                                         desktop.repaint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
                                         desktop.add(cbFrame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
                                         GraphicsUtilities.reshapeToAspectRatio(cbFrame, 1.25f, 0.85f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
                                                                      cbFrame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
                                         cbFrame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
                                         cbPanel.setClassesText(htmlText);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
                                      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
                                   });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
                                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
                             });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  public void showCodeViewer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
    showPanel("Code Viewer", new CodeViewerPanel(), 1.25f, 0.85f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  public void showCodeViewer(final Address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    final CodeViewerPanel panel = new CodeViewerPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    showPanel("Code Viewer", panel, 1.25f, 0.85f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
          panel.viewAddress(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  public void showMemoryViewer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
    showPanel("Memory Viewer", new MemoryViewer(agent.getDebugger(), agent.getTypeDataBase().getAddressSize() == 8));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
  public void showCommandLineFlags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
    showPanel("Command Line Flags", new VMFlagsPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
  public void showVMVersion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    showPanel("VM Version Info", new VMVersionInfoPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
  public void showSystemProperties() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
    showPanel("System Properties", new SysPropsPanel());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  private void showPanel(String name, JPanel panel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
    showPanel(name, panel, 5.0f / 3.0f, 0.4f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  private void showPanel(String name, JPanel panel, float aspectRatio, float fillRatio) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
    JInternalFrame frame = new JInternalFrame(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
    frame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
    frame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    frame.setClosable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
    frame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
    frame.setMaximizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
    frame.getContentPane().add(panel, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
    desktop.add(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
    GraphicsUtilities.reshapeToAspectRatio(frame, aspectRatio, fillRatio, frame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
    GraphicsUtilities.randomLocation(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
    frame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
    if (panel instanceof SAPanel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
      ((SAPanel)panel).addPanelListener(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  // Framework for heap iteration with progress bar
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  interface CleanupThunk {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
    public void heapIterationComplete();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  class HeapProgress implements HeapProgressThunk {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    private JInternalFrame frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    private ProgressBarPanel bar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
    private String windowTitle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
    private String progressBarTitle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
    private CleanupThunk cleanup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    HeapProgress(String windowTitle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
      this(windowTitle, "Percentage of heap visited", null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
    HeapProgress(String windowTitle, String progressBarTitle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
      this(windowTitle, progressBarTitle, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
    HeapProgress(String windowTitle, String progressBarTitle, CleanupThunk cleanup) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
      this.windowTitle = windowTitle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
      this.progressBarTitle = progressBarTitle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
      this.cleanup = cleanup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
    public void heapIterationFractionUpdate(final double fractionOfHeapVisited) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
      if (frame == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
        SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
            public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
              frame = new JInternalFrame(windowTitle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
              frame.setResizable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
              frame.setIconifiable(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
              frame.getContentPane().setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
              bar = new ProgressBarPanel(progressBarTitle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
              frame.getContentPane().add(bar, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
              desktop.add(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
              frame.pack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
              GraphicsUtilities.constrainToSize(frame, frame.getParent().getSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
              GraphicsUtilities.centerInContainer(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
              frame.show();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
          });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
            bar.setValue(fractionOfHeapVisited);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
    public void heapIterationComplete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
            desktop.remove(frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
            desktop.repaint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
            if (VM.getVM().getRevPtrs() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
              // Ended up computing reverse pointers as a side-effect
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
              computeRevPtrsMenuItem.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
      if (cleanup != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
        cleanup.heapIterationComplete();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  class VisitHeap implements Runnable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
    HeapVisitor visitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
    VisitHeap(HeapVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
      this.visitor = visitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
    public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
      VM.getVM().getObjectHeap().iterate(visitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  private void doHeapIteration(String frameTitle,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
                               String progressBarText,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
                               HeapVisitor visitor,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
                               CleanupThunk cleanup) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
    sun.jvm.hotspot.oops.ObjectHistogram histo = new sun.jvm.hotspot.oops.ObjectHistogram();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    HeapProgress progress = new HeapProgress(frameTitle,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
                                             progressBarText,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
                                             cleanup);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    HeapVisitor progVisitor = new ProgressiveHeapVisitor(visitor, progress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
    workerThread.invokeLater(new VisitHeap(progVisitor));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
  // Stack trace helper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
  private static JavaVFrame getLastJavaVFrame(JavaThread cur) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
    RegisterMap regMap = cur.newRegisterMap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
    sun.jvm.hotspot.runtime.Frame f = cur.getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
    if (f == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
    boolean imprecise = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
    if (f.isInterpretedFrame() && !f.isInterpretedFrameValid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
      System.err.println("Correcting for invalid interpreter frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
      f = f.sender(regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
      imprecise = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
    VFrame vf = VFrame.newVFrame(f, regMap, cur, true, imprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
    if (vf == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
      System.err.println(" (Unable to create vframe for topmost frame guess)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
    if (vf.isJavaFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
      return (JavaVFrame) vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
    return (JavaVFrame) vf.javaSender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  // Internal routine for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  private static void dumpStack(JavaThread cur) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
    RegisterMap regMap = cur.newRegisterMap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
    sun.jvm.hotspot.runtime.Frame f = cur.getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
    PrintStream tty = System.err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
    while (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
      tty.print("Found ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
           if (f.isInterpretedFrame()) { tty.print("interpreted"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
      else if (f.isCompiledFrame())    { tty.print("compiled"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
      else if (f.isEntryFrame())       { tty.print("entry"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
      else if (f.isNativeFrame())      { tty.print("native"); }
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
  1793
      else if (f.isRuntimeFrame())     { tty.print("runtime"); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
      else { tty.print("external"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
      tty.print(" frame with PC = " + f.getPC() + ", SP = " + f.getSP() + ", FP = " + f.getFP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
      if (f.isSignalHandlerFrameDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
        tty.print(" (SIGNAL HANDLER)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
      if (!f.isFirstFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
        f = f.sender(regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
        f = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
  // Component utilities
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  private static JMenuItem createMenuItem(String name, ActionListener l) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    JMenuItem item = new JMenuItem(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
    item.addActionListener(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
    return item;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
  /** Punctuates the given string with \n's where necessary to not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
      exceed the given number of characters per line. Strips
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      extraneous whitespace. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
  private String formatMessage(String message, int charsPerLine) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    StringBuffer buf = new StringBuffer(message.length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
    StringTokenizer tokenizer = new StringTokenizer(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
    int curLineLength = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
    while (tokenizer.hasMoreTokens()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
      String tok = tokenizer.nextToken();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
      if (curLineLength + tok.length() > charsPerLine) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
        buf.append('\n');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
        curLineLength = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
        if (curLineLength != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
          buf.append(' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
          ++curLineLength;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
      buf.append(tok);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
      curLineLength += tok.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
    return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
  private void setMenuItemsEnabled(java.util.List items, boolean enabled) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
    for (Iterator iter = items.iterator(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
      ((JMenuItem) iter.next()).setEnabled(enabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
}