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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.tools;
26
27 import java.util.*;
28 import sun.jvm.hotspot.gc_interface.*;
29 import sun.jvm.hotspot.gc_implementation.g1.*;
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 }
117 printPSYoungGen(youngGen);
118
119 PSOldGen oldGen = psh.oldGen();
120 long oldFree = oldGen.capacity() - oldGen.used();
121 System.out.println("PS Old Generation");
122 printValMB("capacity = ", oldGen.capacity());
123 printValMB("used = ", oldGen.used());
124 printValMB("free = ", oldFree);
125 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
126
127 PSPermGen permGen = psh.permGen();
128 long permFree = permGen.capacity() - permGen.used();
129 System.out.println("PS Perm Generation");
130 printValMB("capacity = ", permGen.capacity());
131 printValMB("used = ", permGen.used());
132 printValMB("free = ", permFree);
133 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used");
134 } else {
135 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
136 }
137 }
138
139 // Helper methods
140
141 private void printGCAlgorithm(Map flagMap) {
142 // print about new generation
143 long l = getFlagValue("UseParNewGC", flagMap);
144 if (l == 1L) {
145 System.out.println("using parallel threads in the new generation.");
146 }
147
148 l = getFlagValue("UseTLAB", flagMap);
149 if (l == 1L) {
150 System.out.println("using thread-local object allocation.");
151 }
152
153 l = getFlagValue("UseConcMarkSweepGC", flagMap);
154 if (l == 1L) {
155 System.out.println("Concurrent Mark-Sweep GC");
156 return;
231 System.out.println(alignment + title + value + " (" + mb + "MB)");
232 }
233 }
234
235 private void printValue(String title, long value) {
236 System.out.println(alignment + title + value);
237 }
238
239 private long getFlagValue(String name, Map flagMap) {
240 VM.Flag f = (VM.Flag) flagMap.get(name);
241 if (f != null) {
242 if (f.isBool()) {
243 return f.getBool()? 1L : 0L;
244 } else {
245 return Long.parseLong(f.getValue());
246 }
247 } else {
248 return -1;
249 }
250 }
251 }
|
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.tools;
26
27 import java.util.*;
28 import sun.jvm.hotspot.gc_interface.*;
29 import sun.jvm.hotspot.gc_implementation.g1.*;
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.oops.*;
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 }
118 printPSYoungGen(youngGen);
119
120 PSOldGen oldGen = psh.oldGen();
121 long oldFree = oldGen.capacity() - oldGen.used();
122 System.out.println("PS Old Generation");
123 printValMB("capacity = ", oldGen.capacity());
124 printValMB("used = ", oldGen.used());
125 printValMB("free = ", oldFree);
126 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
127
128 PSPermGen permGen = psh.permGen();
129 long permFree = permGen.capacity() - permGen.used();
130 System.out.println("PS Perm Generation");
131 printValMB("capacity = ", permGen.capacity());
132 printValMB("used = ", permGen.used());
133 printValMB("free = ", permFree);
134 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used");
135 } else {
136 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
137 }
138
139 System.out.println();
140 printInternStringStatistics();
141 }
142
143 // Helper methods
144
145 private void printGCAlgorithm(Map flagMap) {
146 // print about new generation
147 long l = getFlagValue("UseParNewGC", flagMap);
148 if (l == 1L) {
149 System.out.println("using parallel threads in the new generation.");
150 }
151
152 l = getFlagValue("UseTLAB", flagMap);
153 if (l == 1L) {
154 System.out.println("using thread-local object allocation.");
155 }
156
157 l = getFlagValue("UseConcMarkSweepGC", flagMap);
158 if (l == 1L) {
159 System.out.println("Concurrent Mark-Sweep GC");
160 return;
235 System.out.println(alignment + title + value + " (" + mb + "MB)");
236 }
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 }
255
256 private void printInternStringStatistics() {
257 class StringStat implements StringTable.StringVisitor {
258 private int count;
259 private long size;
260 private OopField stringValueField;
261
262 StringStat() {
263 VM vm = VM.getVM();
264 SystemDictionary sysDict = vm.getSystemDictionary();
265 InstanceKlass strKlass = sysDict.getStringKlass();
266 // String has a field named 'value' of type 'char[]'.
267 stringValueField = (OopField) strKlass.findField("value", "[C");
268 }
269
270 private long stringSize(Instance instance) {
271 // We include String content in size calculation.
272 return instance.getObjectSize() +
273 stringValueField.getValue(instance).getObjectSize();
274 }
275
276 public void visit(Instance str) {
277 count++;
278 size += stringSize(str);
279 }
280
281 public void print() {
282 System.out.println(count +
283 " interned Strings occupying " + size + " bytes.");
284 }
285 }
286
287 StringStat stat = new StringStat();
288 StringTable strTable = VM.getVM().getStringTable();
289 strTable.stringsDo(stat);
290 stat.print();
291 }
292 }
|