jdk/src/share/classes/sun/tools/jconsole/MemoryTab.java
author egahlin
Fri, 16 Aug 2013 17:02:12 +0200
changeset 19429 7de30a1db3b3
parent 14342 8435a30053c1
permissions -rw-r--r--
6417702: Graph in Memory tab is not redrawn immediately if changed via 'Chart' combo box Reviewed-by: alanb, jbachorik, sjiang
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19429
7de30a1db3b3 6417702: Graph in Memory tab is not redrawn immediately if changed via 'Chart' combo box
egahlin
parents: 14342
diff changeset
     2
 * Copyright (c) 2004, 2013, 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);
19429
7de30a1db3b3 6417702: Graph in Memory tab is not redrawn immediately if changed via 'Chart' combo box
egahlin
parents: 14342
diff changeset
   231
            plotterPanel.repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void gc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        new Thread("MemoryPanel.gc") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    proxyClient.getMemoryMXBean().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    // Ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public SwingWorker<?, ?> newSwingWorker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return new SwingWorker<Boolean, Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            private long[] used, committed, max, threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            private long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            private String detailsStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            private boolean initialRun = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            public Boolean doInBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (plotterList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        createPlotters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    } catch (final IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    initialRun = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                used      = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                committed = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                max       = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                threshold = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                timeStamp = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    MemoryUsage mu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    used[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    threshold[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                            PoolPlotter poolPlotter = (PoolPlotter)plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            ObjectName objectName = poolPlotter.objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                            AttributeList al =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                proxyClient.getAttributes(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                          new String[] { "Usage", "UsageThreshold" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                            if (al.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                CompositeData cd = (CompositeData)((Attribute)al.get(0)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                mu = MemoryUsage.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                if (al.size() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                    threshold[i] = (Long)((Attribute)al.get(1)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        } else if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            mu = proxyClient.getMemoryMXBean().getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                            mu = proxyClient.getMemoryMXBean().getNonHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        // Skip this plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    if (mu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        used[i]      = mu.getUsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        committed[i] = mu.getCommitted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        max[i]       = mu.getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                detailsStr = formatDetails();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            protected void done() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    if (!get()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                } catch (InterruptedException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                } catch (ExecutionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                if (initialRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    // Add Memory Pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    for (Plotter p : plotterList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        plotterChoice.addItem(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        timeComboBox.addPlotter(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    add(bottomPanel,  BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                int poolCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    if (used[i] >= 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                            plotter.addValues(timeStamp, used[i], committed[i], max[i], threshold[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                            if (threshold[i] > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                plotter.setIsPlotted(thresholdKey, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                            poolChart.setValue(poolCount++, (PoolPlotter)plotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                               used[i], threshold[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            plotter.addValues(timeStamp, used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                        if (plotter == heapPlotter && overviewPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                            overviewPanel.getPlotter().addValues(timeStamp, used[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                            overviewPanel.updateMemoryInfo(used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                details.setText(detailsStr);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private String formatDetails() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (proxyClient.isDead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        String text = "<table cellspacing=0 cellpadding=0>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (plotter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        //long time = plotter.getLastTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        String timeStamp = formatDateTime(time);
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   391
        text += newRow(Messages.TIME, timeStamp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        long used = plotter.getLastValue(usedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        long committed = plotter.getLastValue(committedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        long max = plotter.getLastValue(maxKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        long threshold = plotter.getLastValue(thresholdKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   398
        text += newRow(Messages.USED, formatKBytes(used));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (committed > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   400
            text += newRow(Messages.COMMITTED, formatKBytes(committed));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (max > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   403
            text += newRow(Messages.MAX, formatKBytes(max));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (threshold > 0L) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   406
            text += newRow(Messages.USAGE_THRESHOLD, formatKBytes(threshold));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            Collection<GarbageCollectorMXBean> garbageCollectors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                proxyClient.getGarbageCollectorMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            boolean descPrinted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                String gcName = garbageCollectorMBean.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                long gcCount = garbageCollectorMBean.getCollectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                long gcTime = garbageCollectorMBean.getCollectionTime();
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   418
                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
   419
                                              gcName,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   420
                                              String.format("%,d",gcCount));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                if (!descPrinted) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   422
                    text += newRow(Messages.GC_TIME, str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    descPrinted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    text += newRow(null, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        Object src = ev.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (src == gcButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    private class PoolPlotter extends Plotter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        ObjectName objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        boolean isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        long value, threshold, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        int barX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        public PoolPlotter(ObjectName objectName, String name, boolean isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            super(Plotter.Unit.BYTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            this.objectName = objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            this.name       = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            this.isHeap     = isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            setAccessibleName(this,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   456
                              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
   457
                                               name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    private class PoolChart extends BorderedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                            implements Accessible, MouseListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        final int height       = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        final int leftMargin   =  50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        final int rightMargin  =  23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        final int bottomMargin =  35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        final int barWidth     =  22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        final int barGap       =   3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        final int groupGap     =   8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        final int barHeight    = height * 2 / 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        final Color greenBar           = new Color(100, 255, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        final Color greenBarBackground = new Color(210, 255, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        final Color redBarBackground   = new Color(255, 210, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        Font smallFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        ArrayList<PoolPlotter> poolPlotters = new ArrayList<PoolPlotter>(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        int nHeapPools    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        int nNonHeapPools = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Rectangle heapRect    = new Rectangle(leftMargin,            height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        Rectangle nonHeapRect = new Rectangle(leftMargin + groupGap, height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        public PoolChart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            super(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            setFocusable(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        public void setValue(int poolIndex, PoolPlotter poolPlotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                             long value, long threshold, long max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            poolPlotter.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            poolPlotter.threshold = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            poolPlotter.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            if (poolIndex == poolPlotters.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                poolPlotters.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    poolPlotter.barX = nHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    nHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    heapRect.width = nHeapPools * barWidth + (nHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    nonHeapRect.x  = leftMargin + heapRect.width + groupGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    poolPlotter.barX = nonHeapRect.x - leftMargin + nNonHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    nNonHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    nonHeapRect.width = nNonHeapPools * barWidth + (nNonHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                poolPlotters.set(poolIndex, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        private void paintPoolBar(Graphics g, PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            Rectangle barRect = getBarRect(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            g.drawRect(barRect.x, barRect.y, barRect.width, barRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            long value = poolPlotter.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            long max   = poolPlotter.max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (max > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                g.translate(barRect.x, barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                // Paint green background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                g.setColor(greenBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                g.fillRect(1, 1, barRect.width - 1, barRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                int greenHeight = (int)(value * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                long threshold = poolPlotter.threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                if (threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    int redHeight = (int)(threshold * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    // Paint red background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    g.setColor(redBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    g.fillRect(1, 1, barRect.width - 1, barRect.height - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    if (value > threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        // Over threshold, paint red bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        g.setColor(thresholdColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                   barRect.width - 1, greenHeight - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        greenHeight = redHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                // Paint green bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                g.setColor(greenBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                           barRect.width - 1, greenHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                g.translate(-barRect.x, -barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            if (poolPlotters.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            if (smallFont == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                smallFont = g.getFont().deriveFont(9.0F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // Paint background for chart area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            Rectangle r = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            g.fillRect(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            g.setFont(smallFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            int fontDescent = fm.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            // Paint percentage axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            for (int pc : new int[] { 0, 25, 50, 75, 100 }) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                String str = pc + "% --";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                g.drawString(str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                             leftMargin - fm.stringWidth(str) - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                             height - bottomMargin - (pc * barHeight / 100) + fontDescent + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                paintPoolBar(g, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            g.drawRect(heapRect.x,    heapRect.y,    heapRect.width,    heapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            g.drawRect(nonHeapRect.x, nonHeapRect.y, nonHeapRect.width, nonHeapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            Color heapColor    = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            Color nonHeapColor = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                if (poolPlotter.threshold > 0L && poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        heapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        nonHeapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            g.setColor(heapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            g.fillRect(heapRect.x + 1,    heapRect.y + 1,    heapRect.width - 1,    heapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            g.setColor(nonHeapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            g.fillRect(nonHeapRect.x + 1, nonHeapRect.y + 1, nonHeapRect.width - 1, nonHeapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   618
            String str = Messages.HEAP;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            int stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            int x = heapRect.x + (heapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            int y = heapRect.y + heapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            g.setColor(Color.white);
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.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   630
            str = Messages.NON_HEAP;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            x = nonHeapRect.x + (nonHeapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            y = nonHeapRect.y + nonHeapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            g.setColor(Color.white);
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.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            // Highlight current plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            g.setColor(Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                r = heapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                r = nonHeapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            } else if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                r = getBarRect((PoolPlotter)plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                g.drawRect(r.x - 1, r.y - 1, r.width + 2, r.height + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        private Rectangle getBarRect(PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return new Rectangle(leftMargin + poolPlotter.barX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                 height - bottomMargin - barHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                 barWidth, barHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return new Dimension(nonHeapRect.x + nonHeapRect.width + rightMargin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                                 height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            if (plotter != null && plotter != plotterChoice.getSelectedItem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                plotterChoice.setSelectedItem(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public String getToolTipText(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            return (plotter != null) ? plotter.toString() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        private Plotter getPlotter(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            Plotter plotter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (heapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                plotter = heapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            } else if (nonHeapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                plotter = nonHeapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    if (getBarRect(poolPlotter).contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        plotter = poolPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            return plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        public void mousePressed(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        public void mouseReleased(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        public void mouseEntered(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        public void mouseExited(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                accessibleContext = new AccessiblePoolChart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        protected class AccessiblePoolChart extends AccessibleJPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            public String getAccessibleName() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   719
                String name = Messages.MEMORY_TAB_POOL_CHART_ACCESSIBLE_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                String keyValueList = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    String value = (poolPlotter.value * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    // Assume format string ends with newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   726
                        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
   727
                                         poolPlotter.toString(), value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    if (poolPlotter.threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                        String threshold =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                            (poolPlotter.threshold * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                        if (poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                            keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   733
                               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
   734
                                                threshold);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                            keyValueList +=
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   737
                                    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
   738
                                                     threshold);
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                return name + "\n" + keyValueList + ".";
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    OverviewPanel[] getOverviewPanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        if (overviewPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            overviewPanel = new MemoryOverviewPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        return new OverviewPanel[] { overviewPanel };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    private static class MemoryOverviewPanel extends OverviewPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        MemoryOverviewPanel() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   758
            super(Messages.HEAP_MEMORY_USAGE, usedKey, Messages.USED, Plotter.Unit.BYTES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        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
   762
            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
   763
                                                    formatBytes(used, true),
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   764
                                                    formatBytes(committed, true),
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   765
                                                    formatBytes(max, true)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
}