Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java @ 8031:927a311d00f9
8007320: NPG: move method annotations
Summary: allocate method annotations and attach to ConstMethod if present
Reviewed-by: dcubed, jiangli, sspitsyn, iklam
author | coleenp |
---|---|
date | Mon, 11 Feb 2013 14:06:22 -0500 |
parents | da91efe96a93 |
children | 9a094d29af19 |
rev | line source |
---|---|
0 | 1 /* |
4830
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
2 * Copyright (c) 2003, 2012, 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:
337
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
337
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:
337
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
27 import java.util.*; | |
28 import sun.jvm.hotspot.gc_interface.*; | |
3972 | 29 import sun.jvm.hotspot.gc_implementation.g1.*; |
0 | 30 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*; |
31 import sun.jvm.hotspot.gc_implementation.shared.*; | |
32 import sun.jvm.hotspot.memory.*; | |
4061
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
33 import sun.jvm.hotspot.oops.*; |
0 | 34 import sun.jvm.hotspot.runtime.*; |
35 | |
36 public class HeapSummary extends Tool { | |
37 | |
38 public static void main(String[] args) { | |
39 HeapSummary hs = new HeapSummary(); | |
40 hs.start(args); | |
41 hs.stop(); | |
42 } | |
43 | |
44 public void run() { | |
45 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
46 VM.Flag[] flags = VM.getVM().getCommandLineFlags(); | |
47 Map flagMap = new HashMap(); | |
48 if (flags == null) { | |
49 System.out.println("WARNING: command line flags are not available"); | |
50 } else { | |
51 for (int f = 0; f < flags.length; f++) { | |
52 flagMap.put(flags[f].getName(), flags[f]); | |
53 } | |
54 } | |
55 | |
56 System.out.println(); | |
57 printGCAlgorithm(flagMap); | |
58 System.out.println(); | |
59 System.out.println("Heap Configuration:"); | |
60 printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap)); | |
61 printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap)); | |
62 printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap)); | |
63 printValMB("NewSize = ", getFlagValue("NewSize", flagMap)); | |
64 printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap)); | |
65 printValMB("OldSize = ", getFlagValue("OldSize", flagMap)); | |
66 printValue("NewRatio = ", getFlagValue("NewRatio", flagMap)); | |
67 printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap)); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4830
diff
changeset
|
68 printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4830
diff
changeset
|
69 printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap)); |
4830
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
70 printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); |
0 | 71 |
72 System.out.println(); | |
73 System.out.println("Heap Usage:"); | |
74 | |
3972 | 75 if (heap instanceof SharedHeap) { |
76 SharedHeap sharedHeap = (SharedHeap) heap; | |
77 if (sharedHeap instanceof GenCollectedHeap) { | |
78 GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap; | |
79 for (int n = 0; n < genHeap.nGens(); n++) { | |
80 Generation gen = genHeap.getGen(n); | |
81 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) { | |
82 System.out.println("New Generation (Eden + 1 Survivor Space):"); | |
83 printGen(gen); | |
0 | 84 |
3972 | 85 ContiguousSpace eden = ((DefNewGeneration)gen).eden(); |
86 System.out.println("Eden Space:"); | |
87 printSpace(eden); | |
88 | |
89 ContiguousSpace from = ((DefNewGeneration)gen).from(); | |
90 System.out.println("From Space:"); | |
91 printSpace(from); | |
0 | 92 |
3972 | 93 ContiguousSpace to = ((DefNewGeneration)gen).to(); |
94 System.out.println("To Space:"); | |
95 printSpace(to); | |
96 } else { | |
97 System.out.println(gen.name() + ":"); | |
98 printGen(gen); | |
99 } | |
100 } | |
101 } else if (sharedHeap instanceof G1CollectedHeap) { | |
102 G1CollectedHeap g1h = (G1CollectedHeap) sharedHeap; | |
3984
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
103 G1MonitoringSupport g1mm = g1h.g1mm(); |
4830
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
104 long edenRegionNum = g1mm.edenRegionNum(); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
105 long survivorRegionNum = g1mm.survivorRegionNum(); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
106 HeapRegionSetBase oldSet = g1h.oldSet(); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
107 HeapRegionSetBase humongousSet = g1h.humongousSet(); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
108 long oldRegionNum = oldSet.regionNum() + humongousSet.regionNum(); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
109 printG1Space("G1 Heap:", g1h.n_regions(), |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
110 g1h.used(), g1h.capacity()); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
111 System.out.println("G1 Young Generation:"); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
112 printG1Space("Eden Space:", edenRegionNum, |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
113 g1mm.edenUsed(), g1mm.edenCommitted()); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
114 printG1Space("Survivor Space:", survivorRegionNum, |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
115 g1mm.survivorUsed(), g1mm.survivorCommitted()); |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
116 printG1Space("G1 Old Generation:", oldRegionNum, |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
117 g1mm.oldUsed(), g1mm.oldCommitted()); |
3972 | 118 } else { |
119 throw new RuntimeException("unknown SharedHeap type : " + heap.getClass()); | |
0 | 120 } |
121 } else if (heap instanceof ParallelScavengeHeap) { | |
122 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
123 PSYoungGen youngGen = psh.youngGen(); | |
124 printPSYoungGen(youngGen); | |
125 | |
126 PSOldGen oldGen = psh.oldGen(); | |
127 long oldFree = oldGen.capacity() - oldGen.used(); | |
128 System.out.println("PS Old Generation"); | |
129 printValMB("capacity = ", oldGen.capacity()); | |
130 printValMB("used = ", oldGen.used()); | |
131 printValMB("free = ", oldFree); | |
132 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used"); | |
133 } else { | |
3972 | 134 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass()); |
0 | 135 } |
4061
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
136 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
137 System.out.println(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
138 printInternStringStatistics(); |
0 | 139 } |
140 | |
141 // Helper methods | |
142 | |
143 private void printGCAlgorithm(Map flagMap) { | |
144 // print about new generation | |
145 long l = getFlagValue("UseParNewGC", flagMap); | |
146 if (l == 1L) { | |
147 System.out.println("using parallel threads in the new generation."); | |
148 } | |
149 | |
150 l = getFlagValue("UseTLAB", flagMap); | |
151 if (l == 1L) { | |
152 System.out.println("using thread-local object allocation."); | |
153 } | |
154 | |
155 l = getFlagValue("UseConcMarkSweepGC", flagMap); | |
156 if (l == 1L) { | |
157 System.out.println("Concurrent Mark-Sweep GC"); | |
158 return; | |
159 } | |
160 | |
161 l = getFlagValue("UseParallelGC", flagMap); | |
162 if (l == 1L) { | |
163 System.out.print("Parallel GC "); | |
164 l = getFlagValue("ParallelGCThreads", flagMap); | |
165 System.out.println("with " + l + " thread(s)"); | |
166 return; | |
167 } | |
168 | |
3972 | 169 l = getFlagValue("UseG1GC", flagMap); |
170 if (l == 1L) { | |
171 System.out.print("Garbage-First (G1) GC "); | |
172 l = getFlagValue("ParallelGCThreads", flagMap); | |
173 System.out.println("with " + l + " thread(s)"); | |
174 return; | |
175 } | |
176 | |
0 | 177 System.out.println("Mark Sweep Compact GC"); |
178 } | |
179 | |
180 private void printPSYoungGen(PSYoungGen youngGen) { | |
181 System.out.println("PS Young Generation"); | |
182 MutableSpace eden = youngGen.edenSpace(); | |
183 System.out.println("Eden Space:"); | |
184 printMutableSpace(eden); | |
185 MutableSpace from = youngGen.fromSpace(); | |
186 System.out.println("From Space:"); | |
187 printMutableSpace(from); | |
188 MutableSpace to = youngGen.toSpace(); | |
189 System.out.println("To Space:"); | |
190 printMutableSpace(to); | |
191 } | |
192 | |
193 private void printMutableSpace(MutableSpace space) { | |
194 printValMB("capacity = ", space.capacity()); | |
195 printValMB("used = ", space.used()); | |
196 long free = space.capacity() - space.used(); | |
197 printValMB("free = ", free); | |
198 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
199 } | |
200 | |
201 private static String alignment = " "; | |
202 | |
203 private void printGen(Generation gen) { | |
204 printValMB("capacity = ", gen.capacity()); | |
205 printValMB("used = ", gen.used()); | |
206 printValMB("free = ", gen.free()); | |
207 System.out.println(alignment + (double)gen.used() * 100.0 / gen.capacity() + "% used"); | |
208 } | |
209 | |
210 private void printSpace(ContiguousSpace space) { | |
211 printValMB("capacity = ", space.capacity()); | |
212 printValMB("used = ", space.used()); | |
213 printValMB("free = ", space.free()); | |
214 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
215 } | |
216 | |
4830
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
217 private void printG1Space(String spaceName, long regionNum, |
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
218 long used, long capacity) { |
3984
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
219 long free = capacity - used; |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
220 System.out.println(spaceName); |
4830
0b3d1ec6eaee
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
4061
diff
changeset
|
221 printValue("regions = ", regionNum); |
3984
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
222 printValMB("capacity = ", capacity); |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
223 printValMB("used = ", used); |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
224 printValMB("free = ", free); |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
225 double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0; |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
226 System.out.println(alignment + occPerc + "% used"); |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
227 } |
81aa07130d30
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
3972
diff
changeset
|
228 |
0 | 229 private static final double FACTOR = 1024*1024; |
230 private void printValMB(String title, long value) { | |
281
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
231 if (value < 0) { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
232 System.out.println(alignment + title + (value >>> 20) + " MB"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
233 } else { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
234 double mb = value/FACTOR; |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
235 System.out.println(alignment + title + value + " (" + mb + "MB)"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
236 } |
0 | 237 } |
238 | |
239 private void printValue(String title, long value) { | |
240 System.out.println(alignment + title + value); | |
241 } | |
242 | |
243 private long getFlagValue(String name, Map flagMap) { | |
244 VM.Flag f = (VM.Flag) flagMap.get(name); | |
245 if (f != null) { | |
246 if (f.isBool()) { | |
247 return f.getBool()? 1L : 0L; | |
248 } else { | |
249 return Long.parseLong(f.getValue()); | |
250 } | |
251 } else { | |
252 return -1; | |
253 } | |
254 } | |
4061
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
255 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
256 private void printInternStringStatistics() { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
257 class StringStat implements StringTable.StringVisitor { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
258 private int count; |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
259 private long size; |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
260 private OopField stringValueField; |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
261 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
262 StringStat() { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
263 VM vm = VM.getVM(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
264 SystemDictionary sysDict = vm.getSystemDictionary(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
265 InstanceKlass strKlass = sysDict.getStringKlass(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
266 // String has a field named 'value' of type 'char[]'. |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
267 stringValueField = (OopField) strKlass.findField("value", "[C"); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
268 } |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
269 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
270 private long stringSize(Instance instance) { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
271 // We include String content in size calculation. |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
272 return instance.getObjectSize() + |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
273 stringValueField.getValue(instance).getObjectSize(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
274 } |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
275 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
276 public void visit(Instance str) { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
277 count++; |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
278 size += stringSize(str); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
279 } |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
280 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
281 public void print() { |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
282 System.out.println(count + |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
283 " interned Strings occupying " + size + " bytes."); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
284 } |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
285 } |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
286 |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
287 StringStat stat = new StringStat(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
288 StringTable strTable = VM.getVM().getStringTable(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
289 strTable.stringsDo(stat); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
290 stat.print(); |
e3e363b2bf19
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
3984
diff
changeset
|
291 } |
0 | 292 } |