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