src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java
author dcubed
Wed, 24 Apr 2019 10:20:25 -0400
changeset 54609 04857e2cd509
parent 47216 71c04702a3d5
permissions -rw-r--r--
8222295: more baseline cleanups from Async Monitor Deflation project Reviewed-by: coleenp, acorn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54609
04857e2cd509 8222295: more baseline cleanups from Async Monitor Deflation project
dcubed
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.ui;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
/** Provides information about monitor cache. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
public class MonitorCacheDumpPanel extends JPanel {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  public MonitorCacheDumpPanel() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    setLayout(new BorderLayout());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // Simple at first
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    JScrollPane scroller = new JScrollPane();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    JTextArea textArea = new JTextArea();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    textArea = new JTextArea();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    textArea.setEditable(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    textArea.setLineWrap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    textArea.setWrapStyleWord(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    scroller.getViewport().add(textArea);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    add(scroller, BorderLayout.CENTER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    PrintStream tty = new PrintStream(bos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    tty.println("Monitor Cache Dump (not including JVMTI raw monitors):");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    dumpOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    textArea.setText(bos.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private static void dumpMonitor(PrintStream tty, ObjectMonitor mon, boolean raw) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    tty.print("ObjectMonitor@" + mon.getAddress());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    if (raw) tty.print("(Raw Monitor)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    tty.println("  _header: 0x" + Long.toHexString(mon.header().value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    OopHandle obj = mon.object();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    Oop oop = heap.newOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    tty.println("  _object: " + obj + ", a " + oop.getKlass().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    Address owner = mon.owner();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    tty.println("  _owner: " + owner);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (!raw && owner != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      JavaThread thread = threads.owningThreadFromMonitor(mon);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      if (thread != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        tty.println("    owning thread: " + thread.getThreadName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        if (!thread.getAddress().equals(owner)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
          if (!thread.isLockOwned(owner)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
            tty.println("    WARNING! _owner doesn't fall in " + thread +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                        "'s stack space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    }
54609
04857e2cd509 8222295: more baseline cleanups from Async Monitor Deflation project
dcubed
parents: 47216
diff changeset
    86
    tty.println("  _contentions: " + mon.contentions());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    tty.println("  _waiters: " + mon.waiters());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    tty.println("  _recursions: " + mon.recursions());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  private void dumpOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    Iterator i = ObjectSynchronizer.objectMonitorIterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if (i == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      tty.println("This version of HotSpot VM doesn't support monitor cache dump.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      tty.println("You need 1.4.0_04, 1.4.1_01 or later versions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    ObjectMonitor mon;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    while (i.hasNext()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      mon = (ObjectMonitor)i.next();
54609
04857e2cd509 8222295: more baseline cleanups from Async Monitor Deflation project
dcubed
parents: 47216
diff changeset
   101
      if (mon.contentions() != 0 || mon.waiters() != 0 || mon.owner() != null) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        OopHandle object = mon.object();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        if (object == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
          dumpMonitor(tty, mon, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
          dumpMonitor(tty, mon, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  private static Threads threads = VM.getVM().getThreads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  private static ObjectHeap heap = VM.getVM().getObjectHeap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}