annotate agent/src/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java @ 1552:c18cbe5936b8

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