hotspot/agent/src/share/classes/sun/jvm/hotspot/ui/FindInHeapPanel.java
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
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 2002-2004 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.ui;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import javax.swing.text.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
/** Finds a given (Address) value in the heap. Only intended for use
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    in a debugging system. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
public class FindInHeapPanel extends JPanel {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  private RawHeapVisitor   iterator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private long             addressSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private long             usedSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private long             iterated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private Address          value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private ProgressBarPanel progressBar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private HistoryComboBox  addressField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private JButton          findButton;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private JTextArea        textArea;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private ArrayList        updates;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private double           lastFrac;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static final double minUpdateFraction = 0.05;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  public FindInHeapPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    JPanel topPanel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    JPanel panel = new JPanel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    panel.add(new JLabel("Address to search for:"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    addressField = new HistoryComboBox();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    panel.add(addressField);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    addressSize = VM.getVM().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    iterator = new RawHeapVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        boolean error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        public void prologue(long used) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
          usedSize = used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
          iterated = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
          lastFrac = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
          error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
          updates = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        public void visitAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
          if (error) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
          Address val = addr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
          if (AddressOps.equal(val, value)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
            error = reportResult(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
          iterated += addressSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
          updateProgressBar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    95
        public void visitCompOopAddress(Address addr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    96
          if (error) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    98
          Address val = addr.getCompOopAddressAt(0);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    99
          if (AddressOps.equal(val, value)) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   100
            error = reportResult(addr);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   101
          }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   102
          iterated += addressSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   103
          updateProgressBar();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   104
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   105
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        public void epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
          iterated = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
          updateProgressBar();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
          findButton.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    findButton = new JButton("Find");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    ActionListener listener = new ActionListener() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        public void actionPerformed(ActionEvent e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
          clearResultWindow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
          // Parse text
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
            Address val = VM.getVM().getDebugger().parseAddress(addressField.getText());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
            value = val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
            findButton.setEnabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
            java.lang.Thread t = new java.lang.Thread(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                  try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                    VM.getVM().getObjectHeap().iterateRaw(iterator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                  } finally {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
                    SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                          findButton.setEnabled(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
              });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
            t.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
          } catch (Exception ex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
            textArea.setText("Error parsing address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    panel.add(findButton);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    findButton.addActionListener(listener);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    addressField.addActionListener(listener);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    topPanel.add(panel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    progressBar = new ProgressBarPanel(ProgressBarPanel.HORIZONTAL, "Search progress:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    topPanel.add(progressBar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    add(topPanel, BorderLayout.NORTH);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    textArea = new JTextArea();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    JScrollPane scroller = new JScrollPane(textArea);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    add(scroller, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  private boolean pendingUpdate = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  private boolean reportResult(final Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    synchronized (this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        updates.add("found at " + addr + "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        if (!pendingUpdate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
          pendingUpdate = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
              public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                updateResultWindow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
            });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      } catch (Throwable t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        t.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  private void clearResultWindow() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          Document d = textArea.getDocument();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
            d.remove(0, d.getLength());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
          } catch (BadLocationException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  private synchronized void updateResultWindow() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (updates.size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      Iterator i = updates.iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      while (i.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        textArea.append((String)i.next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      updates = new ArrayList();;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    pendingUpdate = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  private void invokeInDispatchThread(Runnable runnable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    if (EventQueue.isDispatchThread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      runnable.run();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      SwingUtilities.invokeLater(runnable);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  private void updateProgressBar() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    final double frac = (double) iterated / (double) usedSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    if (frac == 0.0 || (frac - lastFrac > minUpdateFraction)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      lastFrac = frac;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      if (iterated > usedSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        System.out.println("iterated " + iterated + " usedSize " + usedSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      SwingUtilities.invokeLater(new Runnable() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
            progressBar.setValue(frac);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
}