comparison 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
comparison
equal deleted inserted replaced
3953:77e1a9153757 3972:4f93f0d00802
1 /* 1 /*
2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
24 24
25 package sun.jvm.hotspot.tools; 25 package sun.jvm.hotspot.tools;
26 26
27 import java.util.*; 27 import java.util.*;
28 import sun.jvm.hotspot.gc_interface.*; 28 import sun.jvm.hotspot.gc_interface.*;
29 import sun.jvm.hotspot.gc_implementation.g1.*;
29 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*; 30 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
30 import sun.jvm.hotspot.gc_implementation.shared.*; 31 import sun.jvm.hotspot.gc_implementation.shared.*;
31 import sun.jvm.hotspot.memory.*; 32 import sun.jvm.hotspot.memory.*;
32 import sun.jvm.hotspot.runtime.*; 33 import sun.jvm.hotspot.runtime.*;
33 import sun.jvm.hotspot.tools.*;
34 34
35 public class HeapSummary extends Tool { 35 public class HeapSummary extends Tool {
36 36
37 public static void main(String[] args) { 37 public static void main(String[] args) {
38 HeapSummary hs = new HeapSummary(); 38 HeapSummary hs = new HeapSummary();
68 printValMB("MaxPermSize = ", getFlagValue("MaxPermSize", flagMap)); 68 printValMB("MaxPermSize = ", getFlagValue("MaxPermSize", flagMap));
69 69
70 System.out.println(); 70 System.out.println();
71 System.out.println("Heap Usage:"); 71 System.out.println("Heap Usage:");
72 72
73 if (heap instanceof GenCollectedHeap) { 73 if (heap instanceof SharedHeap) {
74 GenCollectedHeap genHeap = (GenCollectedHeap) heap; 74 SharedHeap sharedHeap = (SharedHeap) heap;
75 for (int n = 0; n < genHeap.nGens(); n++) { 75 if (sharedHeap instanceof GenCollectedHeap) {
76 Generation gen = genHeap.getGen(n); 76 GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap;
77 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) { 77 for (int n = 0; n < genHeap.nGens(); n++) {
78 System.out.println("New Generation (Eden + 1 Survivor Space):"); 78 Generation gen = genHeap.getGen(n);
79 printGen(gen); 79 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
80 80 System.out.println("New Generation (Eden + 1 Survivor Space):");
81 ContiguousSpace eden = ((DefNewGeneration)gen).eden(); 81 printGen(gen);
82 System.out.println("Eden Space:"); 82
83 printSpace(eden); 83 ContiguousSpace eden = ((DefNewGeneration)gen).eden();
84 84 System.out.println("Eden Space:");
85 ContiguousSpace from = ((DefNewGeneration)gen).from(); 85 printSpace(eden);
86 System.out.println("From Space:"); 86
87 printSpace(from); 87 ContiguousSpace from = ((DefNewGeneration)gen).from();
88 88 System.out.println("From Space:");
89 ContiguousSpace to = ((DefNewGeneration)gen).to(); 89 printSpace(from);
90 System.out.println("To Space:"); 90
91 printSpace(to); 91 ContiguousSpace to = ((DefNewGeneration)gen).to();
92 } else { 92 System.out.println("To Space:");
93 System.out.println(gen.name() + ":"); 93 printSpace(to);
94 printGen(gen); 94 } else {
95 System.out.println(gen.name() + ":");
96 printGen(gen);
97 }
95 } 98 }
99 } else if (sharedHeap instanceof G1CollectedHeap) {
100 G1CollectedHeap g1h = (G1CollectedHeap) sharedHeap;
101
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());
96 } 114 }
97 // Perm generation 115 // Perm generation shared by the above
98 Generation permGen = genHeap.permGen(); 116 Generation permGen = sharedHeap.permGen();
99 System.out.println("Perm Generation:"); 117 System.out.println("Perm Generation:");
100 printGen(permGen); 118 printGen(permGen);
101 } else if (heap instanceof ParallelScavengeHeap) { 119 } else if (heap instanceof ParallelScavengeHeap) {
102 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; 120 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
103 PSYoungGen youngGen = psh.youngGen(); 121 PSYoungGen youngGen = psh.youngGen();
117 printValMB("capacity = ", permGen.capacity()); 135 printValMB("capacity = ", permGen.capacity());
118 printValMB("used = ", permGen.used()); 136 printValMB("used = ", permGen.used());
119 printValMB("free = ", permFree); 137 printValMB("free = ", permFree);
120 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used"); 138 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used");
121 } else { 139 } else {
122 throw new RuntimeException("unknown heap type : " + heap.getClass()); 140 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
123 } 141 }
124 } 142 }
125 143
126 // Helper methods 144 // Helper methods
127 145
147 if (l == 1L) { 165 if (l == 1L) {
148 System.out.print("Parallel GC "); 166 System.out.print("Parallel GC ");
149 l = getFlagValue("ParallelGCThreads", flagMap); 167 l = getFlagValue("ParallelGCThreads", flagMap);
150 System.out.println("with " + l + " thread(s)"); 168 System.out.println("with " + l + " thread(s)");
151 return; 169 return;
170 }
171
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;
152 } 178 }
153 179
154 System.out.println("Mark Sweep Compact GC"); 180 System.out.println("Mark Sweep Compact GC");
155 } 181 }
156 182