Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java @ 12023:d1034bd8cefc
8022284: Hide internal data structure in PhaseCFG
Summary: Hide private node to block mapping using public interface
Reviewed-by: kvn, roland
author | adlertz |
---|---|
date | Wed, 07 Aug 2013 17:56:19 +0200 |
parents | 38ea2efa32a7 |
children | 7fe6ef09d242 |
rev | line source |
---|---|
0 | 1 /* |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
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 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
27 import sun.jvm.hotspot.debugger.JVMDebugger; |
0 | 28 import sun.jvm.hotspot.tools.*; |
29 | |
30 import sun.jvm.hotspot.oops.*; | |
31 import sun.jvm.hotspot.runtime.VM; | |
32 import sun.jvm.hotspot.utilities.SystemDictionaryHelper; | |
33 import sun.jvm.hotspot.utilities.ObjectReader; | |
34 import sun.jvm.hotspot.utilities.MarkBits; | |
35 | |
36 import java.util.HashMap; | |
37 import java.util.ArrayList; | |
38 import java.util.Collections; | |
39 import java.util.Comparator; | |
40 | |
41 /* | |
42 * Iterates over the queue of object pending finalization and prints a | |
43 * summary of these objects in the form of a histogram. | |
44 */ | |
45 public class FinalizerInfo extends Tool { | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
46 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
47 public FinalizerInfo() { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
48 super(); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
49 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
50 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
51 public FinalizerInfo(JVMDebugger d) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
52 super(d); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
53 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
2411
diff
changeset
|
54 |
0 | 55 public static void main(String[] args) { |
56 FinalizerInfo finfo = new FinalizerInfo(); | |
57 finfo.start(args); | |
58 finfo.stop(); | |
59 } | |
60 | |
61 public void run() { | |
62 /* | |
63 * The implementation here has a dependency on the implementation of | |
64 * java.lang.ref.Finalizer. If the Finalizer implementation changes it's | |
65 * possible this method will require changes too. We looked into using | |
66 * ObjectReader to deserialize the objects from the target VM but as | |
67 * there aren't any public methods to traverse the queue it means using | |
68 * reflection which will also tie us to the implementation. | |
69 * | |
70 * The assumption here is that Finalizer.queue is the ReferenceQueue | |
71 * with the objects awaiting finalization. The ReferenceQueue queueLength | |
72 * is the number of objects in the queue, and 'head' is the head of the | |
73 * queue. | |
74 */ | |
75 InstanceKlass ik = | |
76 SystemDictionaryHelper.findInstanceKlass("java.lang.ref.Finalizer"); | |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
77 final Oop[] queueref = new Oop[1]; |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
78 ik.iterateStaticFields(new DefaultOopVisitor() { |
0 | 79 public void doOop(OopField field, boolean isVMField) { |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
80 String name = field.getID().getName(); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
81 if (name.equals("queue")) { |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
82 queueref[0] = field.getValue(getObj()); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
83 } |
0 | 84 } |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
85 }); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
86 Oop queue = queueref[0]; |
0 | 87 |
88 InstanceKlass k = (InstanceKlass) queue.getKlass(); | |
89 | |
90 LongField queueLengthField = (LongField) k.findField("queueLength", "J"); | |
91 long queueLength = queueLengthField.getValue(queue); | |
92 | |
93 OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); | |
94 Oop head = headField.getValue(queue); | |
95 | |
96 System.out.println("Number of objects pending for finalization: " + queueLength); | |
97 | |
98 /* | |
99 * If 'head' is non-NULL then it is the head of a list of References. | |
100 * We iterate over the list (end of list is when head.next == head) | |
101 */ | |
102 if (head != null) { | |
103 k = (InstanceKlass) head.getKlass(); | |
104 OopField referentField = | |
105 (OopField) k.findField("referent", "Ljava/lang/Object;"); | |
106 OopField nextField = | |
107 (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); | |
108 | |
109 HashMap map = new HashMap(); | |
110 for (;;) { | |
111 Oop referent = referentField.getValue(head); | |
112 | |
113 Klass klass = referent.getKlass(); | |
114 if (!map.containsKey(klass)) { | |
115 map.put(klass, new ObjectHistogramElement(klass)); | |
116 } | |
117 ((ObjectHistogramElement)map.get(klass)).updateWith(referent); | |
118 | |
119 Oop next = nextField.getValue(head); | |
120 if (next == null || next.equals(head)) break; | |
121 head = next; | |
122 } | |
123 | |
124 /* | |
125 * Sort results - decending order by total size | |
126 */ | |
127 ArrayList list = new ArrayList(); | |
128 list.addAll(map.values()); | |
129 Collections.sort(list, new Comparator() { | |
130 public int compare(Object o1, Object o2) { | |
131 return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); | |
132 } | |
133 }); | |
134 | |
135 /* | |
136 * Print summary of objects in queue | |
137 */ | |
138 System.out.println(""); | |
139 System.out.println("Count" + "\t" + "Class description"); | |
140 System.out.println("-------------------------------------------------------"); | |
141 for (int i=0; i<list.size(); i++) { | |
142 ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); | |
143 System.out.println(e.getCount() + "\t" + e.getDescription()); | |
144 } | |
145 } | |
146 | |
147 } | |
148 } |