jdk/src/share/classes/sun/tools/jconsole/MemoryTab.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 12851 3334e1c781d0
child 19429 7de30a1db3b3
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12851
diff changeset
     2
 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import static sun.tools.jconsole.Formatter.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
class MemoryTab extends Tab implements ActionListener, ItemListener {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    48
    JComboBox<Plotter> plotterChoice;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    TimeComboBox timeComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    JButton gcButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    PlotterPanel plotterPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    JPanel bottomPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    HTMLPane details;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    PoolChart poolChart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    ArrayList<Plotter> plotterList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Plotter heapPlotter, nonHeapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private MemoryOverviewPanel overviewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final String usedKey        = "used";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final String committedKey   = "committed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final String maxKey         = "max";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final String thresholdKey   = "threshold";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final Color  usedColor      = Plotter.defaultColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final Color  committedColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final Color  maxColor       = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final Color  thresholdColor = Color.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      Hierarchy of panels and layouts for this tab:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        MemoryTab (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            North:  topPanel (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                        Center: controlPanel (FlowLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                    plotterChoice, timeComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                        East:   topRightPanel (FlowLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                    gcButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            Center: plotterPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                        Center: plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            South:  bottomPanel (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        Center: details
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        East:   poolChart
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static String getTabName() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    96
        return Messages.MEMORY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public MemoryTab(VMPanel vmPanel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super(vmPanel, getTabName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        setLayout(new BorderLayout(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        setBorder(new EmptyBorder(4, 4, 3, 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        JPanel topPanel     = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
               plotterPanel = new PlotterPanel(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
               bottomPanel  = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        add(topPanel,     BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        add(plotterPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 20, 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        topPanel.add(controlPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // Plotter choice
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   116
        plotterChoice = new JComboBox<Plotter>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        plotterChoice.addItemListener(this);
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   118
        controlPanel.add(new LabeledComponent(Messages.CHART_COLON,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   119
                                              Resources.getMnemonicInt(Messages.CHART_COLON),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                              plotterChoice));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // Range control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        timeComboBox = new TimeComboBox();
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   124
        controlPanel.add(new LabeledComponent(Messages.TIME_RANGE_COLON,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   125
                                              Resources.getMnemonicInt(Messages.TIME_RANGE_COLON),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                              timeComboBox));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   128
        gcButton = new JButton(Messages.PERFORM_GC);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   129
        gcButton.setMnemonic(Resources.getMnemonicInt(Messages.PERFORM_GC));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        gcButton.addActionListener(this);
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   131
        gcButton.setToolTipText(Messages.PERFORM_GC_TOOLTIP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        JPanel topRightPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        topRightPanel.setBorder(new EmptyBorder(0, 65-8, 0, 70));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        topRightPanel.add(gcButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        topPanel.add(topRightPanel, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   137
        bottomPanel.setBorder(new CompoundBorder(new TitledBorder(Messages.DETAILS),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                                  new EmptyBorder(10, 10, 10, 10)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        details = new HTMLPane();
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   141
        setAccessibleName(details, Messages.DETAILS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        bottomPanel.add(new JScrollPane(details), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        poolChart = new PoolChart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        bottomPanel.add(poolChart, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private void createPlotters() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        plotterList = new ArrayList<Plotter>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        heapPlotter = new Plotter(Plotter.Unit.BYTES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            public String toString() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   156
                return Messages.HEAP_MEMORY_USAGE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        proxyClient.addWeakPropertyChangeListener(heapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        nonHeapPlotter = new Plotter(Plotter.Unit.BYTES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            public String toString() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   163
                return Messages.NON_HEAP_MEMORY_USAGE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        setAccessibleName(heapPlotter,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   168
                          Messages.MEMORY_TAB_HEAP_PLOTTER_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        setAccessibleName(nonHeapPlotter,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   170
                          Messages.MEMORY_TAB_NON_HEAP_PLOTTER_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        proxyClient.addWeakPropertyChangeListener(nonHeapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   174
        heapPlotter.createSequence(usedKey,         Messages.USED,      usedColor,      true);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   175
        heapPlotter.createSequence(committedKey,    Messages.COMMITTED, committedColor, false);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   176
        heapPlotter.createSequence(maxKey,          Messages.MAX,       maxColor,       false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   178
        nonHeapPlotter.createSequence(usedKey,      Messages.USED,      usedColor,      true);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   179
        nonHeapPlotter.createSequence(committedKey, Messages.COMMITTED, committedColor, false);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   180
        nonHeapPlotter.createSequence(maxKey,       Messages.MAX,       maxColor,       false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        plotterList.add(heapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        plotterList.add(nonHeapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // Now add memory pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Map<ObjectName, MBeanInfo> mBeanMap = proxyClient.getMBeans("java.lang");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Set<ObjectName> keys = mBeanMap.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        ObjectName[] objectNames = keys.toArray(new ObjectName[keys.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        ArrayList<PoolPlotter> nonHeapPlotters = new ArrayList<PoolPlotter>(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        for (ObjectName objectName : objectNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            String type = objectName.getKeyProperty("type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (type.equals("MemoryPool")) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   193
                String name = Resources.format(Messages.MEMORY_POOL_LABEL,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   194
                                               objectName.getKeyProperty("name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                // Heap or non-heap?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                boolean isHeap = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                AttributeList al =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    proxyClient.getAttributes(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                              new String[] { "Type" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                if (al.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    isHeap = MemoryType.HEAP.name().equals(((Attribute)al.get(0)).getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                PoolPlotter poolPlotter = new PoolPlotter(objectName, name, isHeap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                proxyClient.addWeakPropertyChangeListener(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   206
                poolPlotter.createSequence(usedKey,      Messages.USED,      usedColor,      true);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   207
                poolPlotter.createSequence(committedKey, Messages.COMMITTED, committedColor, false);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   208
                poolPlotter.createSequence(maxKey,       Messages.MAX,       maxColor,       false);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   209
                poolPlotter.createSequence(thresholdKey, Messages.THRESHOLD, thresholdColor, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                poolPlotter.setUseDashedTransitions(thresholdKey, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    plotterList.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    // Will be added to plotterList below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    nonHeapPlotters.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // Add non-heap plotters last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        for (PoolPlotter poolPlotter : nonHeapPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            plotterList.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void itemStateChanged(ItemEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (ev.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            plotterPanel.setPlotter(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void gc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        new Thread("MemoryPanel.gc") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    proxyClient.getMemoryMXBean().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    // Ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public SwingWorker<?, ?> newSwingWorker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return new SwingWorker<Boolean, Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            private long[] used, committed, max, threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            private long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            private String detailsStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            private boolean initialRun = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            public Boolean doInBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                if (plotterList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        createPlotters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    } catch (final IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    initialRun = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                used      = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                committed = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                max       = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                threshold = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                timeStamp = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    MemoryUsage mu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    used[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    threshold[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                            PoolPlotter poolPlotter = (PoolPlotter)plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                            ObjectName objectName = poolPlotter.objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            AttributeList al =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                proxyClient.getAttributes(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                                          new String[] { "Usage", "UsageThreshold" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                            if (al.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                CompositeData cd = (CompositeData)((Attribute)al.get(0)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                mu = MemoryUsage.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                if (al.size() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                    threshold[i] = (Long)((Attribute)al.get(1)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        } else if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            mu = proxyClient.getMemoryMXBean().getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                            mu = proxyClient.getMemoryMXBean().getNonHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        // Skip this plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    if (mu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        used[i]      = mu.getUsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        committed[i] = mu.getCommitted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        max[i]       = mu.getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                detailsStr = formatDetails();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            protected void done() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    if (!get()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                } catch (InterruptedException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                } catch (ExecutionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                if (initialRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    // Add Memory Pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    for (Plotter p : plotterList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        plotterChoice.addItem(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        timeComboBox.addPlotter(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    add(bottomPanel,  BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                int poolCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    if (used[i] >= 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                            plotter.addValues(timeStamp, used[i], committed[i], max[i], threshold[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                            if (threshold[i] > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                plotter.setIsPlotted(thresholdKey, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                            poolChart.setValue(poolCount++, (PoolPlotter)plotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                               used[i], threshold[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                            plotter.addValues(timeStamp, used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        if (plotter == heapPlotter && overviewPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                            overviewPanel.getPlotter().addValues(timeStamp, used[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                            overviewPanel.updateMemoryInfo(used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                details.setText(detailsStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private String formatDetails() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (proxyClient.isDead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        String text = "<table cellspacing=0 cellpadding=0>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (plotter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        //long time = plotter.getLastTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        String timeStamp = formatDateTime(time);
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   390
        text += newRow(Messages.TIME, timeStamp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        long used = plotter.getLastValue(usedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        long committed = plotter.getLastValue(committedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        long max = plotter.getLastValue(maxKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        long threshold = plotter.getLastValue(thresholdKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   397
        text += newRow(Messages.USED, formatKBytes(used));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (committed > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   399
            text += newRow(Messages.COMMITTED, formatKBytes(committed));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (max > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   402
            text += newRow(Messages.MAX, formatKBytes(max));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (threshold > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   405
            text += newRow(Messages.USAGE_THRESHOLD, formatKBytes(threshold));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            Collection<GarbageCollectorMXBean> garbageCollectors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                proxyClient.getGarbageCollectorMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            boolean descPrinted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                String gcName = garbageCollectorMBean.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                long gcCount = garbageCollectorMBean.getCollectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                long gcTime = garbageCollectorMBean.getCollectionTime();
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   417
                String str = Resources.format(Messages.GC_TIME_DETAILS, justify(formatTime(gcTime), 14),
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   418
                                              gcName,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   419
                                              String.format("%,d",gcCount));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                if (!descPrinted) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   421
                    text += newRow(Messages.GC_TIME, str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    descPrinted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    text += newRow(null, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        Object src = ev.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (src == gcButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private class PoolPlotter extends Plotter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        ObjectName objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        boolean isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        long value, threshold, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int barX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        public PoolPlotter(ObjectName objectName, String name, boolean isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            super(Plotter.Unit.BYTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            this.objectName = objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            this.name       = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            this.isHeap     = isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            setAccessibleName(this,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   455
                              Resources.format(Messages.MEMORY_TAB_POOL_PLOTTER_ACCESSIBLE_NAME,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   456
                                               name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    private class PoolChart extends BorderedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                            implements Accessible, MouseListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        final int height       = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        final int leftMargin   =  50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        final int rightMargin  =  23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        final int bottomMargin =  35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        final int barWidth     =  22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        final int barGap       =   3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        final int groupGap     =   8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        final int barHeight    = height * 2 / 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        final Color greenBar           = new Color(100, 255, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        final Color greenBarBackground = new Color(210, 255, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        final Color redBarBackground   = new Color(255, 210, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        Font smallFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        ArrayList<PoolPlotter> poolPlotters = new ArrayList<PoolPlotter>(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int nHeapPools    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        int nNonHeapPools = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        Rectangle heapRect    = new Rectangle(leftMargin,            height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Rectangle nonHeapRect = new Rectangle(leftMargin + groupGap, height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        public PoolChart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            super(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            setFocusable(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        public void setValue(int poolIndex, PoolPlotter poolPlotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                             long value, long threshold, long max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            poolPlotter.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            poolPlotter.threshold = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            poolPlotter.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            if (poolIndex == poolPlotters.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                poolPlotters.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    poolPlotter.barX = nHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    nHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    heapRect.width = nHeapPools * barWidth + (nHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    nonHeapRect.x  = leftMargin + heapRect.width + groupGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    poolPlotter.barX = nonHeapRect.x - leftMargin + nNonHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    nNonHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    nonHeapRect.width = nNonHeapPools * barWidth + (nNonHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                poolPlotters.set(poolIndex, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        private void paintPoolBar(Graphics g, PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            Rectangle barRect = getBarRect(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            g.drawRect(barRect.x, barRect.y, barRect.width, barRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            long value = poolPlotter.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            long max   = poolPlotter.max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (max > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                g.translate(barRect.x, barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                // Paint green background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                g.setColor(greenBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                g.fillRect(1, 1, barRect.width - 1, barRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                int greenHeight = (int)(value * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                long threshold = poolPlotter.threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                if (threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    int redHeight = (int)(threshold * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    // Paint red background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    g.setColor(redBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    g.fillRect(1, 1, barRect.width - 1, barRect.height - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    if (value > threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        // Over threshold, paint red bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        g.setColor(thresholdColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                   barRect.width - 1, greenHeight - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        greenHeight = redHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                // Paint green bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                g.setColor(greenBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                           barRect.width - 1, greenHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                g.translate(-barRect.x, -barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            if (poolPlotters.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (smallFont == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                smallFont = g.getFont().deriveFont(9.0F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            // Paint background for chart area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            Rectangle r = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            g.fillRect(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            g.setFont(smallFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            int fontDescent = fm.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            // Paint percentage axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            for (int pc : new int[] { 0, 25, 50, 75, 100 }) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                String str = pc + "% --";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                g.drawString(str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                             leftMargin - fm.stringWidth(str) - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                             height - bottomMargin - (pc * barHeight / 100) + fontDescent + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                paintPoolBar(g, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            g.drawRect(heapRect.x,    heapRect.y,    heapRect.width,    heapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            g.drawRect(nonHeapRect.x, nonHeapRect.y, nonHeapRect.width, nonHeapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            Color heapColor    = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            Color nonHeapColor = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                if (poolPlotter.threshold > 0L && poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                        heapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        nonHeapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            g.setColor(heapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            g.fillRect(heapRect.x + 1,    heapRect.y + 1,    heapRect.width - 1,    heapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            g.setColor(nonHeapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            g.fillRect(nonHeapRect.x + 1, nonHeapRect.y + 1, nonHeapRect.width - 1, nonHeapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   617
            String str = Messages.HEAP;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            int stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            int x = heapRect.x + (heapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            int y = heapRect.y + heapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            g.drawString(str, x-1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            g.drawString(str, x+1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            g.drawString(str, x-1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            g.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   629
            str = Messages.NON_HEAP;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            x = nonHeapRect.x + (nonHeapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            y = nonHeapRect.y + nonHeapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            g.drawString(str, x-1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            g.drawString(str, x+1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            g.drawString(str, x-1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            g.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            // Highlight current plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            g.setColor(Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                r = heapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                r = nonHeapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            } else if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                r = getBarRect((PoolPlotter)plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                g.drawRect(r.x - 1, r.y - 1, r.width + 2, r.height + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        private Rectangle getBarRect(PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return new Rectangle(leftMargin + poolPlotter.barX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                                 height - bottomMargin - barHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                 barWidth, barHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            return new Dimension(nonHeapRect.x + nonHeapRect.width + rightMargin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                                 height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (plotter != null && plotter != plotterChoice.getSelectedItem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                plotterChoice.setSelectedItem(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        public String getToolTipText(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            return (plotter != null) ? plotter.toString() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        private Plotter getPlotter(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            Plotter plotter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            if (heapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                plotter = heapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            } else if (nonHeapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                plotter = nonHeapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    if (getBarRect(poolPlotter).contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        plotter = poolPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            return plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        public void mousePressed(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        public void mouseReleased(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        public void mouseEntered(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        public void mouseExited(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                accessibleContext = new AccessiblePoolChart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        protected class AccessiblePoolChart extends AccessibleJPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            public String getAccessibleName() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   718
                String name = Messages.MEMORY_TAB_POOL_CHART_ACCESSIBLE_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                String keyValueList = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    String value = (poolPlotter.value * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    // Assume format string ends with newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   725
                        Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   726
                                         poolPlotter.toString(), value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    if (poolPlotter.threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                        String threshold =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                            (poolPlotter.threshold * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                        if (poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                            keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   732
                               Resources.format(Messages.MEMORY_TAB_POOL_CHART_ABOVE_THRESHOLD,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   733
                                                threshold);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                            keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   736
                                    Resources.format(Messages.MEMORY_TAB_POOL_CHART_BELOW_THRESHOLD,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   737
                                                     threshold);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                return name + "\n" + keyValueList + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    OverviewPanel[] getOverviewPanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        if (overviewPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            overviewPanel = new MemoryOverviewPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return new OverviewPanel[] { overviewPanel };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    private static class MemoryOverviewPanel extends OverviewPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        MemoryOverviewPanel() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   757
            super(Messages.HEAP_MEMORY_USAGE, usedKey, Messages.USED, Plotter.Unit.BYTES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        private void updateMemoryInfo(long used, long committed, long max) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   761
            getInfoLabel().setText(Resources.format(Messages.MEMORY_TAB_INFO_LABEL_FORMAT,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   762
                                                    formatBytes(used, true),
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   763
                                                    formatBytes(committed, true),
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   764
                                                    formatBytes(max, true)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
}