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 *
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.debugger.JVMDebugger;
33 import sun.jvm.hotspot.memory.*;
34 import sun.jvm.hotspot.oops.*;
35 import sun.jvm.hotspot.runtime.*;
36
37 public class HeapSummary extends Tool {
38
39 public HeapSummary() {
40 super();
41 }
42
43 public HeapSummary(JVMDebugger d) {
44 super(d);
45 }
46
47 public static void main(String[] args) {
48 HeapSummary hs = new HeapSummary();
49 hs.execute(args);
59 for (int f = 0; f < flags.length; f++) {
60 flagMap.put(flags[f].getName(), flags[f]);
61 }
62 }
63
64 System.out.println();
65 printGCAlgorithm(flagMap);
66 System.out.println();
67 System.out.println("Heap Configuration:");
68 printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap));
69 printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap));
70 printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap));
71 printValMB("NewSize = ", getFlagValue("NewSize", flagMap));
72 printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap));
73 printValMB("OldSize = ", getFlagValue("OldSize", flagMap));
74 printValue("NewRatio = ", getFlagValue("NewRatio", flagMap));
75 printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap));
76 printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap));
77 printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
78 printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap));
79 printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes());
80
81 System.out.println();
82 System.out.println("Heap Usage:");
83
84 if (heap instanceof SharedHeap) {
85 SharedHeap sharedHeap = (SharedHeap) heap;
86 if (sharedHeap instanceof GenCollectedHeap) {
87 GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap;
88 for (int n = 0; n < genHeap.nGens(); n++) {
89 Generation gen = genHeap.getGen(n);
90 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
91 System.out.println("New Generation (Eden + 1 Survivor Space):");
92 printGen(gen);
93
94 ContiguousSpace eden = ((DefNewGeneration)gen).eden();
95 System.out.println("Eden Space:");
96 printSpace(eden);
97
98 ContiguousSpace from = ((DefNewGeneration)gen).from();
99 System.out.println("From Space:");
123 g1mm.edenUsed(), g1mm.edenCommitted());
124 printG1Space("Survivor Space:", survivorRegionNum,
125 g1mm.survivorUsed(), g1mm.survivorCommitted());
126 printG1Space("G1 Old Generation:", oldRegionNum,
127 g1mm.oldUsed(), g1mm.oldCommitted());
128 } else {
129 throw new RuntimeException("unknown SharedHeap type : " + heap.getClass());
130 }
131 } else if (heap instanceof ParallelScavengeHeap) {
132 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
133 PSYoungGen youngGen = psh.youngGen();
134 printPSYoungGen(youngGen);
135
136 PSOldGen oldGen = psh.oldGen();
137 long oldFree = oldGen.capacity() - oldGen.used();
138 System.out.println("PS Old Generation");
139 printValMB("capacity = ", oldGen.capacity());
140 printValMB("used = ", oldGen.used());
141 printValMB("free = ", oldFree);
142 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
143 } else {
144 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
145 }
146
147 System.out.println();
148 printInternStringStatistics();
149 }
150
151 // Helper methods
152
153 private void printGCAlgorithm(Map flagMap) {
154 // print about new generation
155 long l = getFlagValue("UseParNewGC", flagMap);
156 if (l == 1L) {
157 System.out.println("using parallel threads in the new generation.");
158 }
159
160 l = getFlagValue("UseTLAB", flagMap);
161 if (l == 1L) {
162 System.out.println("using thread-local object allocation.");
163 }
164
165 l = getFlagValue("UseConcMarkSweepGC", flagMap);
166 if (l == 1L) {
167 System.out.println("Concurrent Mark-Sweep GC");
168 return;
169 }
170
171 l = getFlagValue("UseParallelGC", flagMap);
172 if (l == 1L) {
173 System.out.print("Parallel GC ");
174 l = getFlagValue("ParallelGCThreads", flagMap);
175 System.out.println("with " + l + " thread(s)");
176 return;
177 }
178
179 l = getFlagValue("UseG1GC", flagMap);
180 if (l == 1L) {
181 System.out.print("Garbage-First (G1) GC ");
182 l = getFlagValue("ParallelGCThreads", flagMap);
183 System.out.println("with " + l + " thread(s)");
184 return;
185 }
186
187 System.out.println("Mark Sweep Compact GC");
188 }
189
190 private void printPSYoungGen(PSYoungGen youngGen) {
191 System.out.println("PS Young Generation");
192 MutableSpace eden = youngGen.edenSpace();
193 System.out.println("Eden Space:");
194 printMutableSpace(eden);
195 MutableSpace from = youngGen.fromSpace();
196 System.out.println("From Space:");
197 printMutableSpace(from);
198 MutableSpace to = youngGen.toSpace();
199 System.out.println("To Space:");
200 printMutableSpace(to);
201 }
|
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 *
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.shenandoah.*;
31 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
32 import sun.jvm.hotspot.gc_implementation.shared.*;
33 import sun.jvm.hotspot.debugger.JVMDebugger;
34 import sun.jvm.hotspot.memory.*;
35 import sun.jvm.hotspot.oops.*;
36 import sun.jvm.hotspot.runtime.*;
37
38 public class HeapSummary extends Tool {
39
40 public HeapSummary() {
41 super();
42 }
43
44 public HeapSummary(JVMDebugger d) {
45 super(d);
46 }
47
48 public static void main(String[] args) {
49 HeapSummary hs = new HeapSummary();
50 hs.execute(args);
60 for (int f = 0; f < flags.length; f++) {
61 flagMap.put(flags[f].getName(), flags[f]);
62 }
63 }
64
65 System.out.println();
66 printGCAlgorithm(flagMap);
67 System.out.println();
68 System.out.println("Heap Configuration:");
69 printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap));
70 printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap));
71 printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap));
72 printValMB("NewSize = ", getFlagValue("NewSize", flagMap));
73 printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap));
74 printValMB("OldSize = ", getFlagValue("OldSize", flagMap));
75 printValue("NewRatio = ", getFlagValue("NewRatio", flagMap));
76 printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap));
77 printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap));
78 printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
79 printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap));
80 if (heap instanceof ShenandoahHeap) {
81 printValMB("ShenandoahRegionSize = ", ShenandoahHeapRegion.regionSizeBytes());
82 } else {
83 printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes());
84 }
85
86 System.out.println();
87 System.out.println("Heap Usage:");
88
89 if (heap instanceof SharedHeap) {
90 SharedHeap sharedHeap = (SharedHeap) heap;
91 if (sharedHeap instanceof GenCollectedHeap) {
92 GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap;
93 for (int n = 0; n < genHeap.nGens(); n++) {
94 Generation gen = genHeap.getGen(n);
95 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
96 System.out.println("New Generation (Eden + 1 Survivor Space):");
97 printGen(gen);
98
99 ContiguousSpace eden = ((DefNewGeneration)gen).eden();
100 System.out.println("Eden Space:");
101 printSpace(eden);
102
103 ContiguousSpace from = ((DefNewGeneration)gen).from();
104 System.out.println("From Space:");
128 g1mm.edenUsed(), g1mm.edenCommitted());
129 printG1Space("Survivor Space:", survivorRegionNum,
130 g1mm.survivorUsed(), g1mm.survivorCommitted());
131 printG1Space("G1 Old Generation:", oldRegionNum,
132 g1mm.oldUsed(), g1mm.oldCommitted());
133 } else {
134 throw new RuntimeException("unknown SharedHeap type : " + heap.getClass());
135 }
136 } else if (heap instanceof ParallelScavengeHeap) {
137 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
138 PSYoungGen youngGen = psh.youngGen();
139 printPSYoungGen(youngGen);
140
141 PSOldGen oldGen = psh.oldGen();
142 long oldFree = oldGen.capacity() - oldGen.used();
143 System.out.println("PS Old Generation");
144 printValMB("capacity = ", oldGen.capacity());
145 printValMB("used = ", oldGen.used());
146 printValMB("free = ", oldFree);
147 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
148 } else if (heap instanceof ShenandoahHeap) {
149 ShenandoahHeap sh = (ShenandoahHeap) heap;
150 long num_regions = sh.numOfRegions();
151 System.out.println("Shenandoah Heap:");
152 System.out.println(" regions = " + num_regions);
153 printValMB("capacity = ", num_regions * ShenandoahHeapRegion.regionSizeBytes());
154 printValMB("used = ", sh.used());
155 printValMB("committed = ", sh.committed());
156 } else {
157 throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
158 }
159
160 System.out.println();
161 printInternStringStatistics();
162 }
163
164 // Helper methods
165
166 private void printGCAlgorithm(Map flagMap) {
167 // print about new generation
168 long l = getFlagValue("UseParNewGC", flagMap);
169 if (l == 1L) {
170 System.out.println("using parallel threads in the new generation.");
171 }
172
173 l = getFlagValue("UseTLAB", flagMap);
174 if (l == 1L) {
175 System.out.println("using thread-local object allocation.");
176 }
177
178 l = getFlagValue("UseConcMarkSweepGC", flagMap);
179 if (l == 1L) {
180 System.out.println("Concurrent Mark-Sweep GC");
181 return;
182 }
183
184 l = getFlagValue("UseParallelGC", flagMap);
185 if (l == 1L) {
186 System.out.print("Parallel GC ");
187 l = getFlagValue("ParallelGCThreads", flagMap);
188 System.out.println("with " + l + " thread(s)");
189 return;
190 }
191
192 l = getFlagValue("UseG1GC", flagMap);
193 if (l == 1L) {
194 System.out.print("Garbage-First (G1) GC ");
195 l = getFlagValue("ParallelGCThreads", flagMap);
196 System.out.println("with " + l + " thread(s)");
197 return;
198 }
199
200 l = getFlagValue("UseShenandoahGC", flagMap);
201 if (l == 1L) {
202 System.out.print("Shenandoah GC ");
203 l = getFlagValue("ParallelGCThreads", flagMap);
204 System.out.println("with " + l + " thread(s)");
205 return;
206 }
207
208 System.out.println("Mark Sweep Compact GC");
209 }
210
211 private void printPSYoungGen(PSYoungGen youngGen) {
212 System.out.println("PS Young Generation");
213 MutableSpace eden = youngGen.edenSpace();
214 System.out.println("Eden Space:");
215 printMutableSpace(eden);
216 MutableSpace from = youngGen.fromSpace();
217 System.out.println("From Space:");
218 printMutableSpace(from);
219 MutableSpace to = youngGen.toSpace();
220 System.out.println("To Space:");
221 printMutableSpace(to);
222 }
|