Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java @ 2426:1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
Summary: Update the copyright to be 2010 on all changed files in OpenJDK
Reviewed-by: ohair
author | trims |
---|---|
date | Tue, 05 Apr 2011 14:12:31 -0700 |
parents | c18cbe5936b8 |
children | 4f93f0d00802 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
337
diff
changeset
|
2 * Copyright (c) 2003, 2008, 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.*; | |
29 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*; | |
30 import sun.jvm.hotspot.gc_implementation.shared.*; | |
31 import sun.jvm.hotspot.memory.*; | |
32 import sun.jvm.hotspot.runtime.*; | |
33 import sun.jvm.hotspot.tools.*; | |
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 | |
73 if (heap instanceof GenCollectedHeap) { | |
74 GenCollectedHeap genHeap = (GenCollectedHeap) heap; | |
75 for (int n = 0; n < genHeap.nGens(); n++) { | |
76 Generation gen = genHeap.getGen(n); | |
77 if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) { | |
78 System.out.println("New Generation (Eden + 1 Survivor Space):"); | |
79 printGen(gen); | |
80 | |
81 ContiguousSpace eden = ((DefNewGeneration)gen).eden(); | |
82 System.out.println("Eden Space:"); | |
83 printSpace(eden); | |
84 | |
85 ContiguousSpace from = ((DefNewGeneration)gen).from(); | |
86 System.out.println("From Space:"); | |
87 printSpace(from); | |
88 | |
89 ContiguousSpace to = ((DefNewGeneration)gen).to(); | |
90 System.out.println("To Space:"); | |
91 printSpace(to); | |
92 } else { | |
93 System.out.println(gen.name() + ":"); | |
94 printGen(gen); | |
95 } | |
96 } | |
97 // Perm generation | |
98 Generation permGen = genHeap.permGen(); | |
99 System.out.println("Perm Generation:"); | |
100 printGen(permGen); | |
101 } else if (heap instanceof ParallelScavengeHeap) { | |
102 ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; | |
103 PSYoungGen youngGen = psh.youngGen(); | |
104 printPSYoungGen(youngGen); | |
105 | |
106 PSOldGen oldGen = psh.oldGen(); | |
107 long oldFree = oldGen.capacity() - oldGen.used(); | |
108 System.out.println("PS Old Generation"); | |
109 printValMB("capacity = ", oldGen.capacity()); | |
110 printValMB("used = ", oldGen.used()); | |
111 printValMB("free = ", oldFree); | |
112 System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used"); | |
113 | |
114 PSPermGen permGen = psh.permGen(); | |
115 long permFree = permGen.capacity() - permGen.used(); | |
116 System.out.println("PS Perm Generation"); | |
117 printValMB("capacity = ", permGen.capacity()); | |
118 printValMB("used = ", permGen.used()); | |
119 printValMB("free = ", permFree); | |
120 System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used"); | |
121 } else { | |
122 throw new RuntimeException("unknown heap type : " + heap.getClass()); | |
123 } | |
124 } | |
125 | |
126 // Helper methods | |
127 | |
128 private void printGCAlgorithm(Map flagMap) { | |
129 // print about new generation | |
130 long l = getFlagValue("UseParNewGC", flagMap); | |
131 if (l == 1L) { | |
132 System.out.println("using parallel threads in the new generation."); | |
133 } | |
134 | |
135 l = getFlagValue("UseTLAB", flagMap); | |
136 if (l == 1L) { | |
137 System.out.println("using thread-local object allocation."); | |
138 } | |
139 | |
140 l = getFlagValue("UseConcMarkSweepGC", flagMap); | |
141 if (l == 1L) { | |
142 System.out.println("Concurrent Mark-Sweep GC"); | |
143 return; | |
144 } | |
145 | |
146 l = getFlagValue("UseParallelGC", flagMap); | |
147 if (l == 1L) { | |
148 System.out.print("Parallel GC "); | |
149 l = getFlagValue("ParallelGCThreads", flagMap); | |
150 System.out.println("with " + l + " thread(s)"); | |
151 return; | |
152 } | |
153 | |
154 System.out.println("Mark Sweep Compact GC"); | |
155 } | |
156 | |
157 private void printPSYoungGen(PSYoungGen youngGen) { | |
158 System.out.println("PS Young Generation"); | |
159 MutableSpace eden = youngGen.edenSpace(); | |
160 System.out.println("Eden Space:"); | |
161 printMutableSpace(eden); | |
162 MutableSpace from = youngGen.fromSpace(); | |
163 System.out.println("From Space:"); | |
164 printMutableSpace(from); | |
165 MutableSpace to = youngGen.toSpace(); | |
166 System.out.println("To Space:"); | |
167 printMutableSpace(to); | |
168 } | |
169 | |
170 private void printMutableSpace(MutableSpace space) { | |
171 printValMB("capacity = ", space.capacity()); | |
172 printValMB("used = ", space.used()); | |
173 long free = space.capacity() - space.used(); | |
174 printValMB("free = ", free); | |
175 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
176 } | |
177 | |
178 private static String alignment = " "; | |
179 | |
180 private void printGen(Generation gen) { | |
181 printValMB("capacity = ", gen.capacity()); | |
182 printValMB("used = ", gen.used()); | |
183 printValMB("free = ", gen.free()); | |
184 System.out.println(alignment + (double)gen.used() * 100.0 / gen.capacity() + "% used"); | |
185 } | |
186 | |
187 private void printSpace(ContiguousSpace space) { | |
188 printValMB("capacity = ", space.capacity()); | |
189 printValMB("used = ", space.used()); | |
190 printValMB("free = ", space.free()); | |
191 System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); | |
192 } | |
193 | |
194 private static final double FACTOR = 1024*1024; | |
195 private void printValMB(String title, long value) { | |
281
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
196 if (value < 0) { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
197 System.out.println(alignment + title + (value >>> 20) + " MB"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
198 } else { |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
199 double mb = value/FACTOR; |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
200 System.out.println(alignment + title + value + " (" + mb + "MB)"); |
a2de7dfbfcf0
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
0
diff
changeset
|
201 } |
0 | 202 } |
203 | |
204 private void printValue(String title, long value) { | |
205 System.out.println(alignment + title + value); | |
206 } | |
207 | |
208 private long getFlagValue(String name, Map flagMap) { | |
209 VM.Flag f = (VM.Flag) flagMap.get(name); | |
210 if (f != null) { | |
211 if (f.isBool()) { | |
212 return f.getBool()? 1L : 0L; | |
213 } else { | |
214 return Long.parseLong(f.getValue()); | |
215 } | |
216 } else { | |
217 return -1; | |
218 } | |
219 } | |
220 } |