Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java @ 3972:4f93f0d00802
7059019: G1: add G1 support to the SA
Summary: Extend the SA to recognize the G1CollectedHeap and implement any code that's needed by our serviceability tools (jmap, jinfo, jstack, etc.) that depend on the SA.
Reviewed-by: never, poonam, johnc
author | tonyp |
---|---|
date | Tue, 20 Sep 2011 09:59:59 -0400 |
parents | c18cbe5936b8 |
children | 81aa07130d30 |
rev | line source |
---|---|
0 | 1 /* |
3972 | 2 * Copyright (c) 2003, 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:
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.*; | |
33 import sun.jvm.hotspot.runtime.*; | |
34 | |
35 public class HeapSummary extends Tool { | |
36 | |
37 public static void main(String[] args) { | |
38 HeapSummary hs = new HeapSummary(); | |
39 hs.start(args); | |
40 hs.stop(); | |
41 } | |
42 | |
43 public void run() { | |
44 CollectedHeap heap = VM.getVM().getUniverse().heap(); | |
45 VM.Flag[] flags = VM.getVM().getCommandLineFlags(); | |
46 Map flagMap = new HashMap(); | |
47 if (flags == null) { | |
48 System.out.println("WARNING: command line flags are not available"); | |
49 } else { | |
50 for (int f = 0; f < flags.length; f++) { | |
51 flagMap.put(flags[f].getName(), flags[f]); | |
52 } | |
53 } | |
54 | |
55 System.out.println(); | |
56 printGCAlgorithm(flagMap); | |
57 System.out.println(); | |
58 System.out.println("Heap Configuration:"); | |
59 printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap)); | |
60 printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap)); | |
61 printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap)); | |
62 printValMB("NewSize = ", getFlagValue("NewSize", flagMap)); | |
63 printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap)); | |
64 printValMB("OldSize = ", getFlagValue("OldSize", flagMap)); | |
65 printValue("NewRatio = ", getFlagValue("NewRatio", flagMap)); | |
66 printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap)); | |
67 printValMB("PermSize = ", getFlagValue("PermSize", flagMap)); | |
68 printValMB("MaxPermSize = ", getFlagValue("MaxPermSize", flagMap)); | |
69 | |
70 System.out.println(); | |
71 System.out.println("Heap Usage:"); | |
72 | |
3972 | 73 if (heap instanceof SharedHeap) { |
74 SharedHeap sharedHeap = (SharedHeap) heap; | |
75 if (sharedHeap instanceof GenCollectedHeap) { | |
76 GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap; | |
77 for (int n = 0; n < genHeap.nGens(); n++) { | |
78 Generation gen = genHeap.getGen(n); | |
79 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) { | |
80 System.out.println("New Generation (Eden + 1 Survivor Space):"); | |
81 printGen(gen); | |
0 | 82 |
3972 | 83 ContiguousSpace eden = ((DefNewGeneration)gen).eden(); |
84 System.out.println("Eden Space:"); | |
85 printSpace(eden); | |
86 | |
87 ContiguousSpace from = ((DefNewGeneration)gen).from(); | |
88 System.out.println("From Space:"); | |
89 printSpace(from); | |
0 | 90 |
3972 | 91 ContiguousSpace to = ((DefNewGeneration)gen).to(); |
92 System.out.println("To Space:"); | |
93 printSpace(to); | |
94 } else { | |
95 System.out.println(gen.name() + ":"); | |
96 printGen(gen); | |
97 } | |
98 } | |
99 } else if (sharedHeap instanceof G1CollectedHeap) { | |
100 G1CollectedHeap g1h = (G1CollectedHeap) sharedHeap; | |
0 | 101 |
3972 | 102 System.out.println("Garbage-First (G1) Heap"); |
103 long capacityBytes = g1h.capacity(); | |
104 long usedBytes = g1h.used(); | |
105 long freeBytes = capacityBytes - usedBytes; | |
106 printValMB("region size = ", HeapRegion.grainBytes()); | |
107 printValue("regions = ", g1h.n_regions()); | |
108 printValMB("capacity = ", capacityBytes); | |
109 printValMB("used = ", usedBytes); | |
110 printValMB("free = ", freeBytes); | |
111 System.out.println(alignment + (double) usedBytes * 100.0 / capacityBytes + "% used"); | |
112 } else { | |
113 throw new RuntimeException("unknown SharedHeap type : " + heap.getClass()); | |
0 | 114 } |
3972 | 115 // Perm generation shared by the above |
116 Generation permGen = sharedHeap.permGen(); | |
0 | 117 System.out.println("Perm Generation:"); |
118 printGen(permGen); | |
119 } else if (heap instanceof ParallelScavengeHeap) { | |
120 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
121 PSYoungGen youngGen = psh.youngGen(); | |
122 printPSYoungGen(youngGen); | |
123 | |
124 PSOldGen oldGen = psh.oldGen(); | |
125 long oldFree = oldGen.capacity() - oldGen.used(); | |
126 System.out.println("PS Old Generation"); | |
127 printValMB("capacity = ", oldGen.capacity()); | |
128 printValMB("used = ", oldGen.used()); | |
129 printValMB("free = ", oldFree); | |
130 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used"); | |
131 | |
132 PSPermGen permGen = psh.permGen(); | |
133 long permFree = permGen.capacity() - permGen.used(); | |
134 System.out.println("PS Perm Generation"); | |
135 printValMB("capacity = ", permGen.capacity()); | |
136 printValMB("used = ", permGen.used()); | |
137 printValMB("free = ", permFree); | |
138 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used"); | |
139 } else { | |
3972 | 140 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass()); |
0 | 141 } |
142 } | |
143 | |
144 // Helper methods | |
145 | |
146 private void printGCAlgorithm(Map flagMap) { | |
147 // print about new generation | |
148 long l = getFlagValue("UseParNewGC", flagMap); | |
149 if (l == 1L) { | |
150 System.out.println("using parallel threads in the new generation."); | |
151 } | |
152 | |
153 l = getFlagValue("UseTLAB", flagMap); | |
154 if (l == 1L) { | |
155 System.out.println("using thread-local object allocation."); | |
156 } | |
157 | |
158 l = getFlagValue("UseConcMarkSweepGC", flagMap); | |
159 if (l == 1L) { | |
160 System.out.println("Concurrent Mark-Sweep GC"); | |
161 return; | |
162 } | |
163 | |
164 l = getFlagValue("UseParallelGC", flagMap); | |
165 if (l == 1L) { | |
166 System.out.print("Parallel GC "); | |
167 l = getFlagValue("ParallelGCThreads", flagMap); | |
168 System.out.println("with " + l + " thread(s)"); | |
169 return; | |
170 } | |
171 | |
3972 | 172 l = getFlagValue("UseG1GC", flagMap); |
173 if (l == 1L) { | |
174 System.out.print("Garbage-First (G1) GC "); | |
175 l = getFlagValue("ParallelGCThreads", flagMap); | |
176 System.out.println("with " + l + " thread(s)"); | |
177 return; | |
178 } | |
179 | |
0 | 180 System.out.println("Mark Sweep Compact GC"); |
181 } | |
182 | |
183 private void printPSYoungGen(PSYoungGen youngGen) { | |
184 System.out.println("PS Young Generation"); | |
185 MutableSpace eden = youngGen.edenSpace(); | |
186 System.out.println("Eden Space:"); | |
187 printMutableSpace(eden); | |
188 MutableSpace from = youngGen.fromSpace(); | |
189 System.out.println("From Space:"); | |
190 printMutableSpace(from); | |
191 MutableSpace to = youngGen.toSpace(); | |
192 System.out.println("To Space:"); | |
193 printMutableSpace(to); | |
194 } | |
195 | |
196 private void printMutableSpace(MutableSpace space) { | |
197 printValMB("capacity = ", space.capacity()); | |
198 printValMB("used = ", space.used()); | |
199 long free = space.capacity() - space.used(); | |
200 printValMB("free = ", free); | |
201 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
202 } | |
203 | |
204 private static String alignment = " "; | |
205 | |
206 private void printGen(Generation gen) { | |
207 printValMB("capacity = ", gen.capacity()); | |
208 printValMB("used = ", gen.used()); | |
209 printValMB("free = ", gen.free()); | |
210 System.out.println(alignment + (double)gen.used() * 100.0 / gen.capacity() + "% used"); | |
211 } | |
212 | |
213 private void printSpace(ContiguousSpace space) { | |
214 printValMB("capacity = ", space.capacity()); | |
215 printValMB("used = ", space.used()); | |
216 printValMB("free = ", space.free()); | |
217 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
218 } | |
219 | |
220 private static final double FACTOR = 1024*1024; | |
221 private void printValMB(String title, long value) { | |
281
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
222 if (value < 0) { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
223 System.out.println(alignment + title + (value >>> 20) + " MB"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
224 } else { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
225 double mb = value/FACTOR; |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
226 System.out.println(alignment + title + value + " (" + mb + "MB)"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
227 } |
0 | 228 } |
229 | |
230 private void printValue(String title, long value) { | |
231 System.out.println(alignment + title + value); | |
232 } | |
233 | |
234 private long getFlagValue(String name, Map flagMap) { | |
235 VM.Flag f = (VM.Flag) flagMap.get(name); | |
236 if (f != null) { | |
237 if (f.isBool()) { | |
238 return f.getBool()? 1L : 0L; | |
239 } else { | |
240 return Long.parseLong(f.getValue()); | |
241 } | |
242 } else { | |
243 return -1; | |
244 } | |
245 } | |
246 } |