blob: 60c48f1bce4ac8daad25b46a6319b6068f39d5ec [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26
27/*
28 * The contents of this file are subject to the Sun Public License
29 * Version 1.0 (the "License"); you may not use this file except in
30 * compliance with the License. A copy of the License is available at
31 * http://www.sun.com/, and in the file LICENSE.html in the
32 * doc directory.
33 *
34 * The Original Code is HAT. The Initial Developer of the
35 * Original Code is Bill Foote, with contributions from others
36 * at JavaSoft/Sun. Portions created by Bill Foote and others
37 * at Javasoft/Sun are Copyright (C) 1997-2004. All Rights Reserved.
38 *
39 * In addition to the formal license, I ask that you don't
40 * change the history or donations files without permission.
41 *
42 */
43
44package com.sun.tools.hat.internal.server;
45
46import com.sun.tools.hat.internal.model.*;
47import com.sun.tools.hat.internal.util.ArraySorter;
48import com.sun.tools.hat.internal.util.Comparer;
49
50import java.util.Enumeration;
51
52/**
53 *
54 * @author Bill Foote
55 */
56
57
58class ClassQuery extends QueryHandler {
59
60
61 public ClassQuery() {
62 }
63
64 public void run() {
65 startHtml("Class " + query);
66 JavaClass clazz = snapshot.findClass(query);
67 if (clazz == null) {
68 error("class not found: " + query);
69 } else {
70 printFullClass(clazz);
71 }
72 endHtml();
73 }
74
75 protected void printFullClass(JavaClass clazz) {
76 out.print("<h1>");
77 print(clazz.toString());
78 out.println("</h1>");
79
80 out.println("<h2>Superclass:</h2>");
81 printClass(clazz.getSuperclass());
82
83 out.println("<h2>Loader Details</h2>");
84 out.println("<h3>ClassLoader:</h3>");
85 printThing(clazz.getLoader());
86
87 out.println("<h3>Signers:</h3>");
88 printThing(clazz.getSigners());
89
90 out.println("<h3>Protection Domain:</h3>");
91 printThing(clazz.getProtectionDomain());
92
93 out.println("<h2>Subclasses:</h2>");
94 JavaClass[] sc = clazz.getSubclasses();
95 for (int i = 0; i < sc.length; i++) {
96 out.print(" ");
97 printClass(sc[i]);
98 out.println("<br>");
99 }
100
101 out.println("<h2>Instance Data Members:</h2>");
102 JavaField[] ff = clazz.getFields();
103 ff = (JavaField[]) ff.clone();
104 ArraySorter.sort(ff, new Comparer() {
105 public int compare(Object lhs, Object rhs) {
106 JavaField left = (JavaField) lhs;
107 JavaField right = (JavaField) rhs;
108 return left.getName().compareTo(right.getName());
109 }
110 });
111 for (int i = 0; i < ff.length; i++) {
112 out.print(" ");
113 printField(ff[i]);
114 out.println("<br>");
115 }
116
117 out.println("<h2>Static Data Members:</h2>");
118 JavaStatic[] ss = clazz.getStatics();
119 for (int i = 0; i < ss.length; i++) {
120 printStatic(ss[i]);
121 out.println("<br>");
122 }
123
124 out.println("<h2>Instances</h2>");
125
126 printAnchorStart();
127 out.print("instances/" + encodeForURL(clazz));
128 out.print("\">");
129 out.println("Exclude subclasses</a><br>");
130
131 printAnchorStart();
132 out.print("allInstances/" + encodeForURL(clazz));
133 out.print("\">");
134 out.println("Include subclasses</a><br>");
135
136
137 if (snapshot.getHasNewSet()) {
138 out.println("<h2>New Instances</h2>");
139
140 printAnchorStart();
141 out.print("newInstances/" + encodeForURL(clazz));
142 out.print("\">");
143 out.println("Exclude subclasses</a><br>");
144
145 printAnchorStart();
146 out.print("allNewInstances/" + encodeForURL(clazz));
147 out.print("\">");
148 out.println("Include subclasses</a><br>");
149 }
150
151 out.println("<h2>References summary by Type</h2>");
152 printAnchorStart();
153 out.print("refsByType/" + encodeForURL(clazz));
154 out.print("\">");
155 out.println("References summary by type</a>");
156
157 printReferencesTo(clazz);
158 }
159
160 protected void printReferencesTo(JavaHeapObject obj) {
161 if (obj.getId() == -1) {
162 return;
163 }
164 out.println("<h2>References to this object:</h2>");
165 out.flush();
166 Enumeration referers = obj.getReferers();
167 while (referers.hasMoreElements()) {
168 JavaHeapObject ref = (JavaHeapObject) referers.nextElement();
169 printThing(ref);
170 print (" : " + ref.describeReferenceTo(obj, snapshot));
171 // If there are more than one references, this only gets the
172 // first one.
173 out.println("<br>");
174 }
175
176 out.println("<h2>Other Queries</h2>");
177 out.println("Reference Chains from Rootset");
178 long id = obj.getId();
179
180 out.print("<ul><li>");
181 printAnchorStart();
182 out.print("roots/");
183 printHex(id);
184 out.print("\">");
185 out.println("Exclude weak refs</a>");
186
187 out.print("<li>");
188 printAnchorStart();
189 out.print("allRoots/");
190 printHex(id);
191 out.print("\">");
192 out.println("Include weak refs</a></ul>");
193
194 printAnchorStart();
195 out.print("reachableFrom/");
196 printHex(id);
197 out.print("\">");
198 out.println("Objects reachable from here</a><br>");
199 }
200
201
202}