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