author | jgeorge |
Tue, 20 Mar 2018 11:24:32 +0530 | |
changeset 49463 | ccb003941743 |
parent 47216 | 71c04702a3d5 |
child 50445 | bd6b78feb6a3 |
child 56669 | b20a56352d78 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49463
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.tools; |
|
26 |
||
27 |
import java.util.*; |
|
30764 | 28 |
import sun.jvm.hotspot.gc.g1.*; |
29 |
import sun.jvm.hotspot.gc.parallel.*; |
|
30769 | 30 |
import sun.jvm.hotspot.gc.serial.*; |
30764 | 31 |
import sun.jvm.hotspot.gc.shared.*; |
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
32 |
import sun.jvm.hotspot.debugger.JVMDebugger; |
1 | 33 |
import sun.jvm.hotspot.memory.*; |
10985
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
34 |
import sun.jvm.hotspot.oops.*; |
1 | 35 |
import sun.jvm.hotspot.runtime.*; |
36 |
||
38261
ddf6760621fc
8155091: Remove SA related functions from tmtools
dsamersoff
parents:
36508
diff
changeset
|
37 |
public class HeapSummary extends Tool { |
1 | 38 |
|
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
39 |
public HeapSummary() { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
40 |
super(); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
41 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
42 |
|
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
43 |
public HeapSummary(JVMDebugger d) { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
44 |
super(d); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
45 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
15811
diff
changeset
|
46 |
|
1 | 47 |
public static void main(String[] args) { |
48 |
HeapSummary hs = new HeapSummary(); |
|
21065
b8281f54308b
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
19979
diff
changeset
|
49 |
hs.execute(args); |
1 | 50 |
} |
51 |
||
36508 | 52 |
@Override |
53 |
public String getName() { |
|
54 |
return "heapSummary"; |
|
55 |
} |
|
56 |
||
1 | 57 |
public void run() { |
58 |
CollectedHeap heap = VM.getVM().getUniverse().heap(); |
|
59 |
VM.Flag[] flags = VM.getVM().getCommandLineFlags(); |
|
60 |
Map flagMap = new HashMap(); |
|
61 |
if (flags == null) { |
|
62 |
System.out.println("WARNING: command line flags are not available"); |
|
63 |
} else { |
|
64 |
for (int f = 0; f < flags.length; f++) { |
|
65 |
flagMap.put(flags[f].getName(), flags[f]); |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
System.out.println(); |
|
70 |
printGCAlgorithm(flagMap); |
|
71 |
System.out.println(); |
|
72 |
System.out.println("Heap Configuration:"); |
|
19979
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
73 |
printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
74 |
printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
75 |
printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
76 |
printValMB("NewSize = ", getFlagValue("NewSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
77 |
printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
78 |
printValMB("OldSize = ", getFlagValue("OldSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
79 |
printValue("NewRatio = ", getFlagValue("NewRatio", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
80 |
printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
81 |
printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
82 |
printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
83 |
printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap)); |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
18481
diff
changeset
|
84 |
printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); |
1 | 85 |
|
86 |
System.out.println(); |
|
87 |
System.out.println("Heap Usage:"); |
|
88 |
||
30154 | 89 |
if (heap instanceof GenCollectedHeap) { |
90 |
GenCollectedHeap genHeap = (GenCollectedHeap) heap; |
|
91 |
for (int n = 0; n < genHeap.nGens(); n++) { |
|
92 |
Generation gen = genHeap.getGen(n); |
|
30769 | 93 |
if (gen instanceof DefNewGeneration) { |
30154 | 94 |
System.out.println("New Generation (Eden + 1 Survivor Space):"); |
95 |
printGen(gen); |
|
1 | 96 |
|
30154 | 97 |
ContiguousSpace eden = ((DefNewGeneration)gen).eden(); |
98 |
System.out.println("Eden Space:"); |
|
99 |
printSpace(eden); |
|
10663 | 100 |
|
30154 | 101 |
ContiguousSpace from = ((DefNewGeneration)gen).from(); |
102 |
System.out.println("From Space:"); |
|
103 |
printSpace(from); |
|
1 | 104 |
|
30154 | 105 |
ContiguousSpace to = ((DefNewGeneration)gen).to(); |
106 |
System.out.println("To Space:"); |
|
107 |
printSpace(to); |
|
108 |
} else { |
|
109 |
System.out.println(gen.name() + ":"); |
|
110 |
printGen(gen); |
|
10663 | 111 |
} |
1 | 112 |
} |
30154 | 113 |
} else if (heap instanceof G1CollectedHeap) { |
49463
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
114 |
printG1HeapSummary((G1CollectedHeap)heap); |
1 | 115 |
} else if (heap instanceof ParallelScavengeHeap) { |
116 |
ParallelScavengeHeap psh = (ParallelScavengeHeap) heap; |
|
117 |
PSYoungGen youngGen = psh.youngGen(); |
|
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 |
} else { |
|
10663 | 128 |
throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass()); |
1 | 129 |
} |
10985
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
130 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
131 |
System.out.println(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
132 |
printInternStringStatistics(); |
1 | 133 |
} |
134 |
||
135 |
// Helper methods |
|
136 |
||
137 |
private void printGCAlgorithm(Map flagMap) { |
|
43605
07baf498d588
8173421: Obsolete and expired flags for JDK 10 need to be removed and related tests updated
dholmes
parents:
38261
diff
changeset
|
138 |
long l = getFlagValue("UseTLAB", flagMap); |
1 | 139 |
if (l == 1L) { |
140 |
System.out.println("using thread-local object allocation."); |
|
141 |
} |
|
142 |
||
143 |
l = getFlagValue("UseConcMarkSweepGC", flagMap); |
|
144 |
if (l == 1L) { |
|
145 |
System.out.println("Concurrent Mark-Sweep GC"); |
|
146 |
return; |
|
147 |
} |
|
148 |
||
149 |
l = getFlagValue("UseParallelGC", flagMap); |
|
150 |
if (l == 1L) { |
|
151 |
System.out.print("Parallel GC "); |
|
152 |
l = getFlagValue("ParallelGCThreads", flagMap); |
|
153 |
System.out.println("with " + l + " thread(s)"); |
|
154 |
return; |
|
155 |
} |
|
156 |
||
10663 | 157 |
l = getFlagValue("UseG1GC", flagMap); |
158 |
if (l == 1L) { |
|
159 |
System.out.print("Garbage-First (G1) GC "); |
|
160 |
l = getFlagValue("ParallelGCThreads", flagMap); |
|
161 |
System.out.println("with " + l + " thread(s)"); |
|
162 |
return; |
|
163 |
} |
|
164 |
||
1 | 165 |
System.out.println("Mark Sweep Compact GC"); |
166 |
} |
|
167 |
||
168 |
private void printPSYoungGen(PSYoungGen youngGen) { |
|
169 |
System.out.println("PS Young Generation"); |
|
170 |
MutableSpace eden = youngGen.edenSpace(); |
|
171 |
System.out.println("Eden Space:"); |
|
172 |
printMutableSpace(eden); |
|
173 |
MutableSpace from = youngGen.fromSpace(); |
|
174 |
System.out.println("From Space:"); |
|
175 |
printMutableSpace(from); |
|
176 |
MutableSpace to = youngGen.toSpace(); |
|
177 |
System.out.println("To Space:"); |
|
178 |
printMutableSpace(to); |
|
179 |
} |
|
180 |
||
181 |
private void printMutableSpace(MutableSpace space) { |
|
182 |
printValMB("capacity = ", space.capacity()); |
|
183 |
printValMB("used = ", space.used()); |
|
184 |
long free = space.capacity() - space.used(); |
|
185 |
printValMB("free = ", free); |
|
186 |
System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); |
|
187 |
} |
|
188 |
||
189 |
private static String alignment = " "; |
|
190 |
||
191 |
private void printGen(Generation gen) { |
|
192 |
printValMB("capacity = ", gen.capacity()); |
|
193 |
printValMB("used = ", gen.used()); |
|
194 |
printValMB("free = ", gen.free()); |
|
195 |
System.out.println(alignment + (double)gen.used() * 100.0 / gen.capacity() + "% used"); |
|
196 |
} |
|
197 |
||
198 |
private void printSpace(ContiguousSpace space) { |
|
199 |
printValMB("capacity = ", space.capacity()); |
|
200 |
printValMB("used = ", space.used()); |
|
201 |
printValMB("free = ", space.free()); |
|
202 |
System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used"); |
|
203 |
} |
|
204 |
||
49463
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
205 |
public void printG1HeapSummary(G1CollectedHeap g1h) { |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
206 |
G1MonitoringSupport g1mm = g1h.g1mm(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
207 |
long edenRegionNum = g1mm.edenRegionNum(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
208 |
long survivorRegionNum = g1mm.survivorRegionNum(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
209 |
HeapRegionSetBase oldSet = g1h.oldSet(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
210 |
HeapRegionSetBase humongousSet = g1h.humongousSet(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
211 |
long oldRegionNum = oldSet.length() + humongousSet.length(); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
212 |
printG1Space("G1 Heap:", g1h.n_regions(), |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
213 |
g1h.used(), g1h.capacity()); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
214 |
System.out.println("G1 Young Generation:"); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
215 |
printG1Space("Eden Space:", edenRegionNum, |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
216 |
g1mm.edenUsed(), g1mm.edenCommitted()); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
217 |
printG1Space("Survivor Space:", survivorRegionNum, |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
218 |
g1mm.survivorUsed(), g1mm.survivorCommitted()); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
219 |
printG1Space("G1 Old Generation:", oldRegionNum, |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
220 |
g1mm.oldUsed(), g1mm.oldCommitted()); |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
221 |
} |
ccb003941743
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents:
47216
diff
changeset
|
222 |
|
11577
0af7e6e062a7
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
10985
diff
changeset
|
223 |
private void printG1Space(String spaceName, long regionNum, |
0af7e6e062a7
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
10985
diff
changeset
|
224 |
long used, long capacity) { |
10675
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
225 |
long free = capacity - used; |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
226 |
System.out.println(spaceName); |
11577
0af7e6e062a7
7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents:
10985
diff
changeset
|
227 |
printValue("regions = ", regionNum); |
10675
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
228 |
printValMB("capacity = ", capacity); |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
229 |
printValMB("used = ", used); |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
230 |
printValMB("free = ", free); |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
231 |
double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0; |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
232 |
System.out.println(alignment + occPerc + "% used"); |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
233 |
} |
8b887b2cb116
7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents:
10663
diff
changeset
|
234 |
|
1 | 235 |
private static final double FACTOR = 1024*1024; |
236 |
private void printValMB(String title, long value) { |
|
989
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
237 |
if (value < 0) { |
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
238 |
System.out.println(alignment + title + (value >>> 20) + " MB"); |
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
239 |
} else { |
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
240 |
double mb = value/FACTOR; |
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
241 |
System.out.println(alignment + title + value + " (" + mb + "MB)"); |
04e4dadeec8a
6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents:
1
diff
changeset
|
242 |
} |
1 | 243 |
} |
244 |
||
245 |
private void printValue(String title, long value) { |
|
246 |
System.out.println(alignment + title + value); |
|
247 |
} |
|
248 |
||
249 |
private long getFlagValue(String name, Map flagMap) { |
|
250 |
VM.Flag f = (VM.Flag) flagMap.get(name); |
|
251 |
if (f != null) { |
|
252 |
if (f.isBool()) { |
|
253 |
return f.getBool()? 1L : 0L; |
|
254 |
} else { |
|
255 |
return Long.parseLong(f.getValue()); |
|
256 |
} |
|
257 |
} else { |
|
258 |
return -1; |
|
259 |
} |
|
260 |
} |
|
10985
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
261 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
262 |
private void printInternStringStatistics() { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
263 |
class StringStat implements StringTable.StringVisitor { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
264 |
private int count; |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
265 |
private long size; |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
266 |
private OopField stringValueField; |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
267 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
268 |
StringStat() { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
269 |
VM vm = VM.getVM(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
270 |
SystemDictionary sysDict = vm.getSystemDictionary(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
271 |
InstanceKlass strKlass = sysDict.getStringKlass(); |
33628 | 272 |
// String has a field named 'value' of type 'byte[]'. |
273 |
stringValueField = (OopField) strKlass.findField("value", "[B"); |
|
10985
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
274 |
} |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
275 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
276 |
private long stringSize(Instance instance) { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
277 |
// We include String content in size calculation. |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
278 |
return instance.getObjectSize() + |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
279 |
stringValueField.getValue(instance).getObjectSize(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
280 |
} |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
281 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
282 |
public void visit(Instance str) { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
283 |
count++; |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
284 |
size += stringSize(str); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
285 |
} |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
286 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
287 |
public void print() { |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
288 |
System.out.println(count + |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
289 |
" interned Strings occupying " + size + " bytes."); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
290 |
} |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
291 |
} |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
292 |
|
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
293 |
StringStat stat = new StringStat(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
294 |
StringTable strTable = VM.getVM().getStringTable(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
295 |
strTable.stringsDo(stat); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
296 |
stat.print(); |
f529e2356036
7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents:
10675
diff
changeset
|
297 |
} |
1 | 298 |
} |