Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java @ 13705:ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 17 Jan 2014 17:06:08 +0100 |
parents | 7fe6ef09d242 |
children | de6a9e811145 |
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(); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
57 finfo.execute(args); |
0 | 58 } |
59 | |
60 public void run() { | |
61 /* | |
62 * The implementation here has a dependency on the implementation of | |
63 * java.lang.ref.Finalizer. If the Finalizer implementation changes it's | |
64 * possible this method will require changes too. We looked into using | |
65 * ObjectReader to deserialize the objects from the target VM but as | |
66 * there aren't any public methods to traverse the queue it means using | |
67 * reflection which will also tie us to the implementation. | |
68 * | |
69 * The assumption here is that Finalizer.queue is the ReferenceQueue | |
70 * with the objects awaiting finalization. The ReferenceQueue queueLength | |
71 * is the number of objects in the queue, and 'head' is the head of the | |
72 * queue. | |
73 */ | |
74 InstanceKlass ik = | |
75 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
|
76 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
|
77 ik.iterateStaticFields(new DefaultOopVisitor() { |
0 | 78 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
|
79 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
|
80 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
|
81 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
|
82 } |
0 | 83 } |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
84 }); |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
1552
diff
changeset
|
85 Oop queue = queueref[0]; |
0 | 86 |
87 InstanceKlass k = (InstanceKlass) queue.getKlass(); | |
88 | |
89 LongField queueLengthField = (LongField) k.findField("queueLength", "J"); | |
90 long queueLength = queueLengthField.getValue(queue); | |
91 | |
92 OopField headField = (OopField) k.findField("head", "Ljava/lang/ref/Reference;"); | |
93 Oop head = headField.getValue(queue); | |
94 | |
95 System.out.println("Number of objects pending for finalization: " + queueLength); | |
96 | |
97 /* | |
98 * If 'head' is non-NULL then it is the head of a list of References. | |
99 * We iterate over the list (end of list is when head.next == head) | |
100 */ | |
101 if (head != null) { | |
102 k = (InstanceKlass) head.getKlass(); | |
103 OopField referentField = | |
104 (OopField) k.findField("referent", "Ljava/lang/Object;"); | |
105 OopField nextField = | |
106 (OopField) k.findField("next", "Ljava/lang/ref/Reference;"); | |
107 | |
108 HashMap map = new HashMap(); | |
109 for (;;) { | |
110 Oop referent = referentField.getValue(head); | |
111 | |
112 Klass klass = referent.getKlass(); | |
113 if (!map.containsKey(klass)) { | |
114 map.put(klass, new ObjectHistogramElement(klass)); | |
115 } | |
116 ((ObjectHistogramElement)map.get(klass)).updateWith(referent); | |
117 | |
118 Oop next = nextField.getValue(head); | |
119 if (next == null || next.equals(head)) break; | |
120 head = next; | |
121 } | |
122 | |
123 /* | |
124 * Sort results - decending order by total size | |
125 */ | |
126 ArrayList list = new ArrayList(); | |
127 list.addAll(map.values()); | |
128 Collections.sort(list, new Comparator() { | |
129 public int compare(Object o1, Object o2) { | |
130 return ((ObjectHistogramElement)o1).compare((ObjectHistogramElement)o2); | |
131 } | |
132 }); | |
133 | |
134 /* | |
135 * Print summary of objects in queue | |
136 */ | |
137 System.out.println(""); | |
138 System.out.println("Count" + "\t" + "Class description"); | |
139 System.out.println("-------------------------------------------------------"); | |
140 for (int i=0; i<list.size(); i++) { | |
141 ObjectHistogramElement e = (ObjectHistogramElement)list.get(i); | |
142 System.out.println(e.getCount() + "\t" + e.getDescription()); | |
143 } | |
144 } | |
145 | |
146 } | |
147 } |