author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46729 | hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java@c62d2e8b2728 |
child 50929 | ef57cfcd22ff |
permissions | -rw-r--r-- |
1 | 1 |
/* |
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
2 |
* Copyright (c) 2004, 2017, 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:
670
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
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:
670
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.utilities; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.nio.channels.*; |
|
29 |
import java.util.*; |
|
30 |
import sun.jvm.hotspot.debugger.*; |
|
31 |
import sun.jvm.hotspot.memory.*; |
|
32 |
import sun.jvm.hotspot.oops.*; |
|
33 |
import sun.jvm.hotspot.runtime.*; |
|
42889
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
34 |
import sun.jvm.hotspot.classfile.*; |
1 | 35 |
|
36 |
/* |
|
37 |
* This class writes Java heap in hprof binary format. This format is |
|
38 |
* used by Heap Analysis Tool (HAT). The class is heavily influenced |
|
39 |
* by 'hprof_io.c' of 1.5 new hprof implementation. |
|
40 |
*/ |
|
41 |
||
42 |
/* hprof binary format: (result either written to a file or sent over |
|
43 |
* the network). |
|
44 |
* |
|
45 |
* WARNING: This format is still under development, and is subject to |
|
46 |
* change without notice. |
|
47 |
* |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
48 |
* header "JAVA PROFILE 1.0.2" (0-terminated) |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
49 |
* u4 size of identifiers. Identifiers are used to represent |
1 | 50 |
* UTF8 strings, objects, stack traces, etc. They usually |
51 |
* have the same size as host pointers. For example, on |
|
52 |
* Solaris and Win32, the size is 4. |
|
53 |
* u4 high word |
|
54 |
* u4 low word number of milliseconds since 0:00 GMT, 1/1/70 |
|
55 |
* [record]* a sequence of records. |
|
56 |
* |
|
57 |
*/ |
|
58 |
||
59 |
/* |
|
60 |
* |
|
61 |
* Record format: |
|
62 |
* |
|
63 |
* u1 a TAG denoting the type of the record |
|
64 |
* u4 number of *microseconds* since the time stamp in the |
|
65 |
* header. (wraps around in a little more than an hour) |
|
66 |
* u4 number of bytes *remaining* in the record. Note that |
|
67 |
* this number excludes the tag and the length field itself. |
|
68 |
* [u1]* BODY of the record (a sequence of bytes) |
|
69 |
*/ |
|
70 |
||
71 |
/* |
|
72 |
* The following TAGs are supported: |
|
73 |
* |
|
74 |
* TAG BODY notes |
|
75 |
*---------------------------------------------------------- |
|
76 |
* HPROF_UTF8 a UTF8-encoded name |
|
77 |
* |
|
78 |
* id name ID |
|
79 |
* [u1]* UTF8 characters (no trailing zero) |
|
80 |
* |
|
81 |
* HPROF_LOAD_CLASS a newly loaded class |
|
82 |
* |
|
83 |
* u4 class serial number (> 0) |
|
84 |
* id class object ID |
|
85 |
* u4 stack trace serial number |
|
86 |
* id class name ID |
|
87 |
* |
|
88 |
* HPROF_UNLOAD_CLASS an unloading class |
|
89 |
* |
|
90 |
* u4 class serial_number |
|
91 |
* |
|
92 |
* HPROF_FRAME a Java stack frame |
|
93 |
* |
|
94 |
* id stack frame ID |
|
95 |
* id method name ID |
|
96 |
* id method signature ID |
|
97 |
* id source file name ID |
|
98 |
* u4 class serial number |
|
99 |
* i4 line number. >0: normal |
|
100 |
* -1: unknown |
|
101 |
* -2: compiled method |
|
102 |
* -3: native method |
|
103 |
* |
|
104 |
* HPROF_TRACE a Java stack trace |
|
105 |
* |
|
106 |
* u4 stack trace serial number |
|
107 |
* u4 thread serial number |
|
108 |
* u4 number of frames |
|
109 |
* [id]* stack frame IDs |
|
110 |
* |
|
111 |
* |
|
112 |
* HPROF_ALLOC_SITES a set of heap allocation sites, obtained after GC |
|
113 |
* |
|
114 |
* u2 flags 0x0001: incremental vs. complete |
|
115 |
* 0x0002: sorted by allocation vs. live |
|
116 |
* 0x0004: whether to force a GC |
|
117 |
* u4 cutoff ratio |
|
118 |
* u4 total live bytes |
|
119 |
* u4 total live instances |
|
120 |
* u8 total bytes allocated |
|
121 |
* u8 total instances allocated |
|
122 |
* u4 number of sites that follow |
|
123 |
* [u1 is_array: 0: normal object |
|
124 |
* 2: object array |
|
125 |
* 4: boolean array |
|
126 |
* 5: char array |
|
127 |
* 6: float array |
|
128 |
* 7: double array |
|
129 |
* 8: byte array |
|
130 |
* 9: short array |
|
131 |
* 10: int array |
|
132 |
* 11: long array |
|
133 |
* u4 class serial number (may be zero during startup) |
|
134 |
* u4 stack trace serial number |
|
135 |
* u4 number of bytes alive |
|
136 |
* u4 number of instances alive |
|
137 |
* u4 number of bytes allocated |
|
138 |
* u4]* number of instance allocated |
|
139 |
* |
|
140 |
* HPROF_START_THREAD a newly started thread. |
|
141 |
* |
|
142 |
* u4 thread serial number (> 0) |
|
143 |
* id thread object ID |
|
144 |
* u4 stack trace serial number |
|
145 |
* id thread name ID |
|
146 |
* id thread group name ID |
|
147 |
* id thread group parent name ID |
|
148 |
* |
|
149 |
* HPROF_END_THREAD a terminating thread. |
|
150 |
* |
|
151 |
* u4 thread serial number |
|
152 |
* |
|
153 |
* HPROF_HEAP_SUMMARY heap summary |
|
154 |
* |
|
155 |
* u4 total live bytes |
|
156 |
* u4 total live instances |
|
157 |
* u8 total bytes allocated |
|
158 |
* u8 total instances allocated |
|
159 |
* |
|
160 |
* HPROF_HEAP_DUMP denote a heap dump |
|
161 |
* |
|
162 |
* [heap dump sub-records]* |
|
163 |
* |
|
164 |
* There are four kinds of heap dump sub-records: |
|
165 |
* |
|
166 |
* u1 sub-record type |
|
167 |
* |
|
168 |
* HPROF_GC_ROOT_UNKNOWN unknown root |
|
169 |
* |
|
170 |
* id object ID |
|
171 |
* |
|
172 |
* HPROF_GC_ROOT_THREAD_OBJ thread object |
|
173 |
* |
|
174 |
* id thread object ID (may be 0 for a |
|
175 |
* thread newly attached through JNI) |
|
176 |
* u4 thread sequence number |
|
177 |
* u4 stack trace sequence number |
|
178 |
* |
|
179 |
* HPROF_GC_ROOT_JNI_GLOBAL JNI global ref root |
|
180 |
* |
|
181 |
* id object ID |
|
182 |
* id JNI global ref ID |
|
183 |
* |
|
184 |
* HPROF_GC_ROOT_JNI_LOCAL JNI local ref |
|
185 |
* |
|
186 |
* id object ID |
|
187 |
* u4 thread serial number |
|
188 |
* u4 frame # in stack trace (-1 for empty) |
|
189 |
* |
|
190 |
* HPROF_GC_ROOT_JAVA_FRAME Java stack frame |
|
191 |
* |
|
192 |
* id object ID |
|
193 |
* u4 thread serial number |
|
194 |
* u4 frame # in stack trace (-1 for empty) |
|
195 |
* |
|
196 |
* HPROF_GC_ROOT_NATIVE_STACK Native stack |
|
197 |
* |
|
198 |
* id object ID |
|
199 |
* u4 thread serial number |
|
200 |
* |
|
201 |
* HPROF_GC_ROOT_STICKY_CLASS System class |
|
202 |
* |
|
203 |
* id object ID |
|
204 |
* |
|
205 |
* HPROF_GC_ROOT_THREAD_BLOCK Reference from thread block |
|
206 |
* |
|
207 |
* id object ID |
|
208 |
* u4 thread serial number |
|
209 |
* |
|
210 |
* HPROF_GC_ROOT_MONITOR_USED Busy monitor |
|
211 |
* |
|
212 |
* id object ID |
|
213 |
* |
|
214 |
* HPROF_GC_CLASS_DUMP dump of a class object |
|
215 |
* |
|
216 |
* id class object ID |
|
217 |
* u4 stack trace serial number |
|
218 |
* id super class object ID |
|
219 |
* id class loader object ID |
|
220 |
* id signers object ID |
|
221 |
* id protection domain object ID |
|
222 |
* id reserved |
|
223 |
* id reserved |
|
224 |
* |
|
225 |
* u4 instance size (in bytes) |
|
226 |
* |
|
227 |
* u2 size of constant pool |
|
228 |
* [u2, constant pool index, |
|
229 |
* ty, type |
|
230 |
* 2: object |
|
231 |
* 4: boolean |
|
232 |
* 5: char |
|
233 |
* 6: float |
|
234 |
* 7: double |
|
235 |
* 8: byte |
|
236 |
* 9: short |
|
237 |
* 10: int |
|
238 |
* 11: long |
|
239 |
* vl]* and value |
|
240 |
* |
|
241 |
* u2 number of static fields |
|
242 |
* [id, static field name, |
|
243 |
* ty, type, |
|
244 |
* vl]* and value |
|
245 |
* |
|
246 |
* u2 number of inst. fields (not inc. super) |
|
247 |
* [id, instance field name, |
|
248 |
* ty]* type |
|
249 |
* |
|
250 |
* HPROF_GC_INSTANCE_DUMP dump of a normal object |
|
251 |
* |
|
252 |
* id object ID |
|
253 |
* u4 stack trace serial number |
|
254 |
* id class object ID |
|
255 |
* u4 number of bytes that follow |
|
256 |
* [vl]* instance field values (class, followed |
|
257 |
* by super, super's super ...) |
|
258 |
* |
|
259 |
* HPROF_GC_OBJ_ARRAY_DUMP dump of an object array |
|
260 |
* |
|
261 |
* id array object ID |
|
262 |
* u4 stack trace serial number |
|
263 |
* u4 number of elements |
|
264 |
* id array class ID |
|
265 |
* [id]* elements |
|
266 |
* |
|
267 |
* HPROF_GC_PRIM_ARRAY_DUMP dump of a primitive array |
|
268 |
* |
|
269 |
* id array object ID |
|
270 |
* u4 stack trace serial number |
|
271 |
* u4 number of elements |
|
272 |
* u1 element type |
|
273 |
* 4: boolean array |
|
274 |
* 5: char array |
|
275 |
* 6: float array |
|
276 |
* 7: double array |
|
277 |
* 8: byte array |
|
278 |
* 9: short array |
|
279 |
* 10: int array |
|
280 |
* 11: long array |
|
281 |
* [u1]* elements |
|
282 |
* |
|
283 |
* HPROF_CPU_SAMPLES a set of sample traces of running threads |
|
284 |
* |
|
285 |
* u4 total number of samples |
|
286 |
* u4 # of traces |
|
287 |
* [u4 # of samples |
|
288 |
* u4]* stack trace serial number |
|
289 |
* |
|
290 |
* HPROF_CONTROL_SETTINGS the settings of on/off switches |
|
291 |
* |
|
292 |
* u4 0x00000001: alloc traces on/off |
|
293 |
* 0x00000002: cpu sampling on/off |
|
294 |
* u2 stack trace depth |
|
295 |
* |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
296 |
* |
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
297 |
* A heap dump can optionally be generated as a sequence of heap dump |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
298 |
* segments. This sequence is terminated by an end record. The additional |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
299 |
* tags allowed by format "JAVA PROFILE 1.0.2" are: |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
300 |
* |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
301 |
* HPROF_HEAP_DUMP_SEGMENT denote a heap dump segment |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
302 |
* |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
303 |
* [heap dump sub-records]* |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
304 |
* The same sub-record types allowed by HPROF_HEAP_DUMP |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
305 |
* |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
306 |
* HPROF_HEAP_DUMP_END denotes the end of a heap dump |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
307 |
* |
1 | 308 |
*/ |
309 |
||
310 |
public class HeapHprofBinWriter extends AbstractHeapGraphWriter { |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
311 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
312 |
private static final long HPROF_SEGMENTED_HEAP_DUMP_THRESHOLD = 2L * 0x40000000; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
313 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
314 |
// The approximate size of a heap segment. Used to calculate when to create |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
315 |
// a new segment. |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
316 |
private static final long HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE = 1L * 0x40000000; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
317 |
|
1 | 318 |
// hprof binary file header |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
319 |
private static final String HPROF_HEADER_1_0_2 = "JAVA PROFILE 1.0.2"; |
1 | 320 |
|
321 |
// constants in enum HprofTag |
|
322 |
private static final int HPROF_UTF8 = 0x01; |
|
323 |
private static final int HPROF_LOAD_CLASS = 0x02; |
|
324 |
private static final int HPROF_UNLOAD_CLASS = 0x03; |
|
325 |
private static final int HPROF_FRAME = 0x04; |
|
326 |
private static final int HPROF_TRACE = 0x05; |
|
327 |
private static final int HPROF_ALLOC_SITES = 0x06; |
|
328 |
private static final int HPROF_HEAP_SUMMARY = 0x07; |
|
329 |
private static final int HPROF_START_THREAD = 0x0A; |
|
330 |
private static final int HPROF_END_THREAD = 0x0B; |
|
331 |
private static final int HPROF_HEAP_DUMP = 0x0C; |
|
332 |
private static final int HPROF_CPU_SAMPLES = 0x0D; |
|
333 |
private static final int HPROF_CONTROL_SETTINGS = 0x0E; |
|
334 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
335 |
// 1.0.2 record types |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
336 |
private static final int HPROF_HEAP_DUMP_SEGMENT = 0x1C; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
337 |
private static final int HPROF_HEAP_DUMP_END = 0x2C; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
338 |
|
1 | 339 |
// Heap dump constants |
340 |
// constants in enum HprofGcTag |
|
341 |
private static final int HPROF_GC_ROOT_UNKNOWN = 0xFF; |
|
342 |
private static final int HPROF_GC_ROOT_JNI_GLOBAL = 0x01; |
|
343 |
private static final int HPROF_GC_ROOT_JNI_LOCAL = 0x02; |
|
344 |
private static final int HPROF_GC_ROOT_JAVA_FRAME = 0x03; |
|
345 |
private static final int HPROF_GC_ROOT_NATIVE_STACK = 0x04; |
|
346 |
private static final int HPROF_GC_ROOT_STICKY_CLASS = 0x05; |
|
347 |
private static final int HPROF_GC_ROOT_THREAD_BLOCK = 0x06; |
|
348 |
private static final int HPROF_GC_ROOT_MONITOR_USED = 0x07; |
|
349 |
private static final int HPROF_GC_ROOT_THREAD_OBJ = 0x08; |
|
350 |
private static final int HPROF_GC_CLASS_DUMP = 0x20; |
|
351 |
private static final int HPROF_GC_INSTANCE_DUMP = 0x21; |
|
352 |
private static final int HPROF_GC_OBJ_ARRAY_DUMP = 0x22; |
|
353 |
private static final int HPROF_GC_PRIM_ARRAY_DUMP = 0x23; |
|
354 |
||
355 |
// constants in enum HprofType |
|
356 |
private static final int HPROF_ARRAY_OBJECT = 1; |
|
357 |
private static final int HPROF_NORMAL_OBJECT = 2; |
|
358 |
private static final int HPROF_BOOLEAN = 4; |
|
359 |
private static final int HPROF_CHAR = 5; |
|
360 |
private static final int HPROF_FLOAT = 6; |
|
361 |
private static final int HPROF_DOUBLE = 7; |
|
362 |
private static final int HPROF_BYTE = 8; |
|
363 |
private static final int HPROF_SHORT = 9; |
|
364 |
private static final int HPROF_INT = 10; |
|
365 |
private static final int HPROF_LONG = 11; |
|
366 |
||
367 |
// Java type codes |
|
368 |
private static final int JVM_SIGNATURE_BOOLEAN = 'Z'; |
|
369 |
private static final int JVM_SIGNATURE_CHAR = 'C'; |
|
370 |
private static final int JVM_SIGNATURE_BYTE = 'B'; |
|
371 |
private static final int JVM_SIGNATURE_SHORT = 'S'; |
|
372 |
private static final int JVM_SIGNATURE_INT = 'I'; |
|
373 |
private static final int JVM_SIGNATURE_LONG = 'J'; |
|
374 |
private static final int JVM_SIGNATURE_FLOAT = 'F'; |
|
375 |
private static final int JVM_SIGNATURE_DOUBLE = 'D'; |
|
376 |
private static final int JVM_SIGNATURE_ARRAY = '['; |
|
377 |
private static final int JVM_SIGNATURE_CLASS = 'L'; |
|
378 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
379 |
private static final long MAX_U4_VALUE = 0xFFFFFFFFL; |
42889
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
380 |
int serialNum = 1; |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
381 |
|
45371
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
382 |
public HeapHprofBinWriter() { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
383 |
this.KlassMap = new ArrayList<Klass>(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
384 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
385 |
|
1 | 386 |
public synchronized void write(String fileName) throws IOException { |
387 |
// open file stream and create buffered data output stream |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
388 |
fos = new FileOutputStream(fileName); |
1 | 389 |
out = new DataOutputStream(new BufferedOutputStream(fos)); |
390 |
||
391 |
VM vm = VM.getVM(); |
|
392 |
dbg = vm.getDebugger(); |
|
393 |
objectHeap = vm.getObjectHeap(); |
|
394 |
symTbl = vm.getSymbolTable(); |
|
395 |
||
396 |
OBJ_ID_SIZE = (int) vm.getOopSize(); |
|
397 |
||
398 |
BOOLEAN_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BOOLEAN); |
|
399 |
BYTE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_BYTE); |
|
400 |
CHAR_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_CHAR); |
|
401 |
SHORT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_SHORT); |
|
402 |
INT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_INT); |
|
403 |
LONG_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_LONG); |
|
404 |
FLOAT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_FLOAT); |
|
405 |
DOUBLE_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_DOUBLE); |
|
406 |
OBJECT_BASE_OFFSET = TypeArray.baseOffsetInBytes(BasicType.T_OBJECT); |
|
407 |
||
408 |
BOOLEAN_SIZE = objectHeap.getBooleanSize(); |
|
409 |
BYTE_SIZE = objectHeap.getByteSize(); |
|
410 |
CHAR_SIZE = objectHeap.getCharSize(); |
|
411 |
SHORT_SIZE = objectHeap.getShortSize(); |
|
412 |
INT_SIZE = objectHeap.getIntSize(); |
|
413 |
LONG_SIZE = objectHeap.getLongSize(); |
|
414 |
FLOAT_SIZE = objectHeap.getFloatSize(); |
|
415 |
DOUBLE_SIZE = objectHeap.getDoubleSize(); |
|
416 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
417 |
// Check weather we should dump the heap as segments |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
418 |
useSegmentedHeapDump = vm.getUniverse().heap().used() > HPROF_SEGMENTED_HEAP_DUMP_THRESHOLD; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
419 |
|
1 | 420 |
// hprof bin format header |
421 |
writeFileHeader(); |
|
422 |
||
423 |
// dummy stack trace without any frames so that |
|
424 |
// HAT can be run without -stack false option |
|
425 |
writeDummyTrace(); |
|
426 |
||
427 |
// hprof UTF-8 symbols section |
|
428 |
writeSymbols(); |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
429 |
|
1 | 430 |
// HPROF_LOAD_CLASS records for all classes |
431 |
writeClasses(); |
|
432 |
||
45371
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
433 |
// write HPROF_FRAME and HPROF_TRACE records |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
434 |
dumpStackTraces(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
435 |
|
1 | 436 |
// write CLASS_DUMP records |
437 |
writeClassDumpRecords(); |
|
438 |
||
439 |
// this will write heap data into the buffer stream |
|
440 |
super.write(); |
|
441 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
442 |
// flush buffer stream. |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
443 |
out.flush(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
444 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
445 |
// Fill in final length |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
446 |
fillInHeapRecordLength(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
447 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
448 |
if (useSegmentedHeapDump) { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
449 |
// Write heap segment-end record |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
450 |
out.writeByte((byte) HPROF_HEAP_DUMP_END); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
451 |
out.writeInt(0); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
452 |
out.writeInt(0); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
453 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
454 |
|
1 | 455 |
// flush buffer stream and throw it. |
456 |
out.flush(); |
|
457 |
out = null; |
|
458 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
459 |
// close the file stream |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
460 |
fos.close(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
461 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
462 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
463 |
@Override |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
464 |
protected void writeHeapRecordPrologue() throws IOException { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
465 |
if (currentSegmentStart == 0) { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
466 |
// write heap data header, depending on heap size use segmented heap |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
467 |
// format |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
468 |
out.writeByte((byte) (useSegmentedHeapDump ? HPROF_HEAP_DUMP_SEGMENT |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
469 |
: HPROF_HEAP_DUMP)); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
470 |
out.writeInt(0); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
471 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
472 |
// remember position of dump length, we will fixup |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
473 |
// length later - hprof format requires length. |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
474 |
out.flush(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
475 |
currentSegmentStart = fos.getChannel().position(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
476 |
// write dummy length of 0 and we'll fix it later. |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
477 |
out.writeInt(0); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
478 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
479 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
480 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
481 |
@Override |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
482 |
protected void writeHeapRecordEpilogue() throws IOException { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
483 |
if (useSegmentedHeapDump) { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
484 |
out.flush(); |
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
485 |
if ((fos.getChannel().position() - currentSegmentStart - 4L) >= HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE) { |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
486 |
fillInHeapRecordLength(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
487 |
currentSegmentStart = 0; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
488 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
489 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
490 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
491 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
492 |
private void fillInHeapRecordLength() throws IOException { |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
493 |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
494 |
// now get the current position to calculate length |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
495 |
long dumpEnd = fos.getChannel().position(); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
496 |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
497 |
// calculate the length of heap data |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
498 |
long dumpLenLong = (dumpEnd - currentSegmentStart - 4L); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
499 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
500 |
// Check length boundary, overflow could happen but is _very_ unlikely |
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
501 |
if (dumpLenLong >= (4L * 0x40000000)) { |
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
502 |
throw new RuntimeException("Heap segment size overflow."); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
503 |
} |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
504 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
505 |
// Save the current position |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
506 |
long currentPosition = fos.getChannel().position(); |
1 | 507 |
|
508 |
// seek the position to write length |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
509 |
fos.getChannel().position(currentSegmentStart); |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
510 |
|
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
511 |
int dumpLen = (int) dumpLenLong; |
1 | 512 |
|
513 |
// write length as integer |
|
514 |
fos.write((dumpLen >>> 24) & 0xFF); |
|
515 |
fos.write((dumpLen >>> 16) & 0xFF); |
|
516 |
fos.write((dumpLen >>> 8) & 0xFF); |
|
517 |
fos.write((dumpLen >>> 0) & 0xFF); |
|
518 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
519 |
//Reset to previous current position |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
520 |
fos.getChannel().position(currentPosition); |
1 | 521 |
} |
522 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
523 |
// get the size in bytes for the requested type |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
524 |
private long getSizeForType(int type) throws IOException { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
525 |
switch (type) { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
526 |
case TypeArrayKlass.T_BOOLEAN: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
527 |
return BOOLEAN_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
528 |
case TypeArrayKlass.T_INT: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
529 |
return INT_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
530 |
case TypeArrayKlass.T_CHAR: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
531 |
return CHAR_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
532 |
case TypeArrayKlass.T_SHORT: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
533 |
return SHORT_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
534 |
case TypeArrayKlass.T_BYTE: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
535 |
return BYTE_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
536 |
case TypeArrayKlass.T_LONG: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
537 |
return LONG_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
538 |
case TypeArrayKlass.T_FLOAT: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
539 |
return FLOAT_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
540 |
case TypeArrayKlass.T_DOUBLE: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
541 |
return DOUBLE_SIZE; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
542 |
default: |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
543 |
throw new RuntimeException( |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
544 |
"Should not reach here: Unknown type: " + type); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
545 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
546 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
547 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
548 |
private int getArrayHeaderSize(boolean isObjectAarray) { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
549 |
return isObjectAarray? |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
550 |
((int) BYTE_SIZE + 2 * (int) INT_SIZE + 2 * (int) OBJ_ID_SIZE): |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
551 |
(2 * (int) BYTE_SIZE + 2 * (int) INT_SIZE + (int) OBJ_ID_SIZE); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
552 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
553 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
554 |
// Check if we need to truncate an array |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
555 |
private int calculateArrayMaxLength(long originalArrayLength, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
556 |
int headerSize, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
557 |
long typeSize, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
558 |
String typeName) throws IOException { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
559 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
560 |
long length = originalArrayLength; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
561 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
562 |
// now get the current position to calculate length |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
563 |
long dumpEnd = fos.getChannel().position(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
564 |
long originalLengthInBytes = originalArrayLength * typeSize; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
565 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
566 |
// calculate the length of heap data |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
567 |
long currentRecordLength = (dumpEnd - currentSegmentStart - 4L); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
568 |
if (currentRecordLength > 0 && |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
569 |
(currentRecordLength + headerSize + originalLengthInBytes) > MAX_U4_VALUE) { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
570 |
fillInHeapRecordLength(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
571 |
currentSegmentStart = 0; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
572 |
writeHeapRecordPrologue(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
573 |
currentRecordLength = 0; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
574 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
575 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
576 |
// Calculate the max bytes we can use. |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
577 |
long maxBytes = (MAX_U4_VALUE - (headerSize + currentRecordLength)); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
578 |
|
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
579 |
if (originalLengthInBytes > maxBytes) { |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
580 |
length = maxBytes/typeSize; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
581 |
System.err.println("WARNING: Cannot dump array of type " + typeName |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
582 |
+ " with length " + originalArrayLength |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
583 |
+ "; truncating to length " + length); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
584 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
585 |
return (int) length; |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
586 |
} |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
587 |
|
1 | 588 |
private void writeClassDumpRecords() throws IOException { |
42889
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
589 |
ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph(); |
1 | 590 |
try { |
46729 | 591 |
cldGraph.classesDo(new ClassLoaderDataGraph.ClassVisitor() { |
42889
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
592 |
public void visit(Klass k) { |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
593 |
try { |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
594 |
writeHeapRecordPrologue(); |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
595 |
writeClassDumpRecord(k); |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
596 |
writeHeapRecordEpilogue(); |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
597 |
} catch (IOException e) { |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
598 |
throw new RuntimeException(e); |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
599 |
} |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
600 |
} |
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
601 |
}); |
1 | 602 |
} catch (RuntimeException re) { |
603 |
handleRuntimeException(re); |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
protected void writeClass(Instance instance) throws IOException { |
|
8878
a6283814032c
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
8729
diff
changeset
|
608 |
Klass reflectedKlass = java_lang_Class.asKlass(instance); |
1 | 609 |
// dump instance record only for primitive type Class objects. |
610 |
// all other Class objects are covered by writeClassDumpRecords. |
|
611 |
if (reflectedKlass == null) { |
|
612 |
writeInstance(instance); |
|
613 |
} |
|
614 |
} |
|
615 |
||
616 |
private void writeClassDumpRecord(Klass k) throws IOException { |
|
617 |
out.writeByte((byte)HPROF_GC_CLASS_DUMP); |
|
618 |
writeObjectID(k.getJavaMirror()); |
|
619 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
620 |
Klass superKlass = k.getJavaSuper(); |
|
621 |
if (superKlass != null) { |
|
622 |
writeObjectID(superKlass.getJavaMirror()); |
|
623 |
} else { |
|
624 |
writeObjectID(null); |
|
625 |
} |
|
626 |
||
627 |
if (k instanceof InstanceKlass) { |
|
628 |
InstanceKlass ik = (InstanceKlass) k; |
|
629 |
writeObjectID(ik.getClassLoader()); |
|
17826
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
13728
diff
changeset
|
630 |
writeObjectID(null); // ik.getJavaMirror().getSigners()); |
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
13728
diff
changeset
|
631 |
writeObjectID(null); // ik.getJavaMirror().getProtectionDomain()); |
1 | 632 |
// two reserved id fields |
633 |
writeObjectID(null); |
|
634 |
writeObjectID(null); |
|
635 |
List fields = getInstanceFields(ik); |
|
636 |
int instSize = getSizeForFields(fields); |
|
637 |
classDataCache.put(ik, new ClassData(instSize, fields)); |
|
638 |
out.writeInt(instSize); |
|
639 |
||
640 |
// For now, ignore constant pool - HAT ignores too! |
|
641 |
// output number of cp entries as zero. |
|
642 |
out.writeShort((short) 0); |
|
643 |
||
644 |
List declaredFields = ik.getImmediateFields(); |
|
645 |
List staticFields = new ArrayList(); |
|
646 |
List instanceFields = new ArrayList(); |
|
647 |
Iterator itr = null; |
|
648 |
for (itr = declaredFields.iterator(); itr.hasNext();) { |
|
649 |
Field field = (Field) itr.next(); |
|
650 |
if (field.isStatic()) { |
|
651 |
staticFields.add(field); |
|
652 |
} else { |
|
653 |
instanceFields.add(field); |
|
654 |
} |
|
655 |
} |
|
656 |
||
657 |
// dump static field descriptors |
|
658 |
writeFieldDescriptors(staticFields, ik); |
|
659 |
||
660 |
// dump instance field descriptors |
|
661 |
writeFieldDescriptors(instanceFields, null); |
|
662 |
} else { |
|
663 |
if (k instanceof ObjArrayKlass) { |
|
664 |
ObjArrayKlass oak = (ObjArrayKlass) k; |
|
665 |
Klass bottomKlass = oak.getBottomKlass(); |
|
666 |
if (bottomKlass instanceof InstanceKlass) { |
|
667 |
InstanceKlass ik = (InstanceKlass) bottomKlass; |
|
668 |
writeObjectID(ik.getClassLoader()); |
|
17826
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
13728
diff
changeset
|
669 |
writeObjectID(null); // ik.getJavaMirror().getSigners()); |
9ad5cd464a75
8003421: NPG: Move oops out of InstanceKlass into mirror
coleenp
parents:
13728
diff
changeset
|
670 |
writeObjectID(null); // ik.getJavaMirror().getProtectionDomain()); |
1 | 671 |
} else { |
672 |
writeObjectID(null); |
|
673 |
writeObjectID(null); |
|
674 |
writeObjectID(null); |
|
675 |
} |
|
676 |
} else { |
|
677 |
writeObjectID(null); |
|
678 |
writeObjectID(null); |
|
679 |
writeObjectID(null); |
|
680 |
} |
|
681 |
// two reserved id fields |
|
682 |
writeObjectID(null); |
|
683 |
writeObjectID(null); |
|
684 |
// write zero instance size -- as instance size |
|
685 |
// is variable for arrays. |
|
686 |
out.writeInt(0); |
|
687 |
// no constant pool for array klasses |
|
688 |
out.writeShort((short) 0); |
|
689 |
// no static fields for array klasses |
|
690 |
out.writeShort((short) 0); |
|
691 |
// no instance fields for array klasses |
|
692 |
out.writeShort((short) 0); |
|
693 |
} |
|
694 |
} |
|
695 |
||
45371
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
696 |
private void dumpStackTraces() throws IOException { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
697 |
// write a HPROF_TRACE record without any frames to be referenced as object alloc sites |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
698 |
writeHeader(HPROF_TRACE, 3 * (int)INT_SIZE ); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
699 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
700 |
out.writeInt(0); // thread number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
701 |
out.writeInt(0); // frame count |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
702 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
703 |
int frameSerialNum = 0; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
704 |
int numThreads = 0; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
705 |
Threads threads = VM.getVM().getThreads(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
706 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
707 |
for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
708 |
Oop threadObj = thread.getThreadObj(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
709 |
if (threadObj != null && !thread.isExiting() && !thread.isHiddenFromExternalView()) { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
710 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
711 |
// dump thread stack trace |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
712 |
ThreadStackTrace st = new ThreadStackTrace(thread); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
713 |
st.dumpStack(-1); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
714 |
numThreads++; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
715 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
716 |
// write HPROF_FRAME records for this thread's stack trace |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
717 |
int depth = st.getStackDepth(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
718 |
int threadFrameStart = frameSerialNum; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
719 |
for (int j=0; j < depth; j++) { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
720 |
StackFrameInfo frame = st.stackFrameAt(j); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
721 |
Method m = frame.getMethod(); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
722 |
int classSerialNum = KlassMap.indexOf(m.getMethodHolder()) + 1; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
723 |
// the class serial number starts from 1 |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
724 |
assert classSerialNum > 0:"class not found"; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
725 |
dumpStackFrame(++frameSerialNum, classSerialNum, m, frame.getBCI()); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
726 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
727 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
728 |
// write HPROF_TRACE record for one thread |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
729 |
writeHeader(HPROF_TRACE, 3 * (int)INT_SIZE + depth * (int)VM.getVM().getOopSize()); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
730 |
int stackSerialNum = numThreads + DUMMY_STACK_TRACE_ID; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
731 |
out.writeInt(stackSerialNum); // stack trace serial number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
732 |
out.writeInt(numThreads); // thread serial number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
733 |
out.writeInt(depth); // frame count |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
734 |
for (int j=1; j <= depth; j++) { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
735 |
writeObjectID(threadFrameStart + j); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
736 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
737 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
738 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
739 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
740 |
|
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
741 |
private void dumpStackFrame(int frameSN, int classSN, Method m, int bci) throws IOException { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
742 |
int lineNumber; |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
743 |
if (m.isNative()) { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
744 |
lineNumber = -3; // native frame |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
745 |
} else { |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
746 |
lineNumber = m.getLineNumberFromBCI(bci); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
747 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
748 |
writeHeader(HPROF_FRAME, 4 * (int)VM.getVM().getOopSize() + 2 * (int)INT_SIZE); |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
749 |
writeObjectID(frameSN); // frame serial number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
750 |
writeSymbolID(m.getName()); // method's name |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
751 |
writeSymbolID(m.getSignature()); // method's signature |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
752 |
writeSymbolID(m.getMethodHolder().getSourceFileName()); // source file name |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
753 |
out.writeInt(classSN); // class serial number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
754 |
out.writeInt(lineNumber); // line number |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
755 |
} |
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
756 |
|
1 | 757 |
protected void writeJavaThread(JavaThread jt, int index) throws IOException { |
758 |
out.writeByte((byte) HPROF_GC_ROOT_THREAD_OBJ); |
|
759 |
writeObjectID(jt.getThreadObj()); |
|
760 |
out.writeInt(index); |
|
761 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
762 |
writeLocalJNIHandles(jt, index); |
|
763 |
} |
|
764 |
||
765 |
protected void writeLocalJNIHandles(JavaThread jt, int index) throws IOException { |
|
766 |
final int threadIndex = index; |
|
767 |
JNIHandleBlock blk = jt.activeHandles(); |
|
768 |
if (blk != null) { |
|
769 |
try { |
|
770 |
blk.oopsDo(new AddressVisitor() { |
|
771 |
public void visitAddress(Address handleAddr) { |
|
772 |
try { |
|
773 |
if (handleAddr != null) { |
|
774 |
OopHandle oopHandle = handleAddr.getOopHandleAt(0); |
|
775 |
Oop oop = objectHeap.newOop(oopHandle); |
|
776 |
// exclude JNI handles hotspot internal objects |
|
777 |
if (oop != null && isJavaVisible(oop)) { |
|
778 |
out.writeByte((byte) HPROF_GC_ROOT_JNI_LOCAL); |
|
779 |
writeObjectID(oop); |
|
780 |
out.writeInt(threadIndex); |
|
781 |
out.writeInt(EMPTY_FRAME_DEPTH); |
|
782 |
} |
|
783 |
} |
|
784 |
} catch (IOException exp) { |
|
785 |
throw new RuntimeException(exp); |
|
786 |
} |
|
787 |
} |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
788 |
public void visitCompOopAddress(Address handleAddr) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
789 |
throw new RuntimeException( |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
790 |
" Should not reach here. JNIHandles are not compressed \n"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
791 |
} |
1 | 792 |
}); |
793 |
} catch (RuntimeException re) { |
|
794 |
handleRuntimeException(re); |
|
795 |
} |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
protected void writeGlobalJNIHandle(Address handleAddr) throws IOException { |
|
800 |
OopHandle oopHandle = handleAddr.getOopHandleAt(0); |
|
801 |
Oop oop = objectHeap.newOop(oopHandle); |
|
802 |
// exclude JNI handles of hotspot internal objects |
|
803 |
if (oop != null && isJavaVisible(oop)) { |
|
804 |
out.writeByte((byte) HPROF_GC_ROOT_JNI_GLOBAL); |
|
805 |
writeObjectID(oop); |
|
806 |
// use JNIHandle address as ID |
|
807 |
writeObjectID(getAddressValue(handleAddr)); |
|
808 |
} |
|
809 |
} |
|
810 |
||
811 |
protected void writeObjectArray(ObjArray array) throws IOException { |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
812 |
int headerSize = getArrayHeaderSize(true); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
813 |
final int length = calculateArrayMaxLength(array.getLength(), |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
814 |
headerSize, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
815 |
OBJ_ID_SIZE, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
816 |
"Object"); |
1 | 817 |
out.writeByte((byte) HPROF_GC_OBJ_ARRAY_DUMP); |
818 |
writeObjectID(array); |
|
819 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
820 |
out.writeInt(length); |
1 | 821 |
writeObjectID(array.getKlass().getJavaMirror()); |
822 |
for (int index = 0; index < length; index++) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
823 |
OopHandle handle = array.getOopHandleAt(index); |
1 | 824 |
writeObjectID(getAddressValue(handle)); |
825 |
} |
|
826 |
} |
|
827 |
||
828 |
protected void writePrimitiveArray(TypeArray array) throws IOException { |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
829 |
int headerSize = getArrayHeaderSize(false); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
830 |
TypeArrayKlass tak = (TypeArrayKlass) array.getKlass(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
831 |
final int type = (int) tak.getElementType(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
832 |
final String typeName = tak.getElementTypeName(); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
833 |
final long typeSize = getSizeForType(type); |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
834 |
final int length = calculateArrayMaxLength(array.getLength(), |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
835 |
headerSize, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
836 |
typeSize, |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
837 |
typeName); |
1 | 838 |
out.writeByte((byte) HPROF_GC_PRIM_ARRAY_DUMP); |
839 |
writeObjectID(array); |
|
840 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
841 |
out.writeInt(length); |
1 | 842 |
out.writeByte((byte) type); |
843 |
switch (type) { |
|
844 |
case TypeArrayKlass.T_BOOLEAN: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
845 |
writeBooleanArray(array, length); |
1 | 846 |
break; |
847 |
case TypeArrayKlass.T_CHAR: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
848 |
writeCharArray(array, length); |
1 | 849 |
break; |
850 |
case TypeArrayKlass.T_FLOAT: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
851 |
writeFloatArray(array, length); |
1 | 852 |
break; |
853 |
case TypeArrayKlass.T_DOUBLE: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
854 |
writeDoubleArray(array, length); |
1 | 855 |
break; |
856 |
case TypeArrayKlass.T_BYTE: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
857 |
writeByteArray(array, length); |
1 | 858 |
break; |
859 |
case TypeArrayKlass.T_SHORT: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
860 |
writeShortArray(array, length); |
1 | 861 |
break; |
862 |
case TypeArrayKlass.T_INT: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
863 |
writeIntArray(array, length); |
1 | 864 |
break; |
865 |
case TypeArrayKlass.T_LONG: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
866 |
writeLongArray(array, length); |
1 | 867 |
break; |
868 |
default: |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
869 |
throw new RuntimeException( |
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
870 |
"Should not reach here: Unknown type: " + type); |
1 | 871 |
} |
872 |
} |
|
873 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
874 |
private void writeBooleanArray(TypeArray array, int length) throws IOException { |
1 | 875 |
for (int index = 0; index < length; index++) { |
876 |
long offset = BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE; |
|
877 |
out.writeBoolean(array.getHandle().getJBooleanAt(offset)); |
|
878 |
} |
|
879 |
} |
|
880 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
881 |
private void writeByteArray(TypeArray array, int length) throws IOException { |
1 | 882 |
for (int index = 0; index < length; index++) { |
883 |
long offset = BYTE_BASE_OFFSET + index * BYTE_SIZE; |
|
884 |
out.writeByte(array.getHandle().getJByteAt(offset)); |
|
885 |
} |
|
886 |
} |
|
887 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
888 |
private void writeShortArray(TypeArray array, int length) throws IOException { |
1 | 889 |
for (int index = 0; index < length; index++) { |
890 |
long offset = SHORT_BASE_OFFSET + index * SHORT_SIZE; |
|
891 |
out.writeShort(array.getHandle().getJShortAt(offset)); |
|
892 |
} |
|
893 |
} |
|
894 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
895 |
private void writeIntArray(TypeArray array, int length) throws IOException { |
1 | 896 |
for (int index = 0; index < length; index++) { |
897 |
long offset = INT_BASE_OFFSET + index * INT_SIZE; |
|
898 |
out.writeInt(array.getHandle().getJIntAt(offset)); |
|
899 |
} |
|
900 |
} |
|
901 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
902 |
private void writeLongArray(TypeArray array, int length) throws IOException { |
1 | 903 |
for (int index = 0; index < length; index++) { |
904 |
long offset = LONG_BASE_OFFSET + index * LONG_SIZE; |
|
905 |
out.writeLong(array.getHandle().getJLongAt(offset)); |
|
906 |
} |
|
907 |
} |
|
908 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
909 |
private void writeCharArray(TypeArray array, int length) throws IOException { |
1 | 910 |
for (int index = 0; index < length; index++) { |
911 |
long offset = CHAR_BASE_OFFSET + index * CHAR_SIZE; |
|
912 |
out.writeChar(array.getHandle().getJCharAt(offset)); |
|
913 |
} |
|
914 |
} |
|
915 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
916 |
private void writeFloatArray(TypeArray array, int length) throws IOException { |
1 | 917 |
for (int index = 0; index < length; index++) { |
918 |
long offset = FLOAT_BASE_OFFSET + index * FLOAT_SIZE; |
|
919 |
out.writeFloat(array.getHandle().getJFloatAt(offset)); |
|
920 |
} |
|
921 |
} |
|
922 |
||
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
923 |
private void writeDoubleArray(TypeArray array, int length) throws IOException { |
1 | 924 |
for (int index = 0; index < length; index++) { |
925 |
long offset = DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE; |
|
926 |
out.writeDouble(array.getHandle().getJDoubleAt(offset)); |
|
927 |
} |
|
928 |
} |
|
929 |
||
930 |
protected void writeInstance(Instance instance) throws IOException { |
|
931 |
out.writeByte((byte) HPROF_GC_INSTANCE_DUMP); |
|
932 |
writeObjectID(instance); |
|
933 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
934 |
Klass klass = instance.getKlass(); |
|
935 |
writeObjectID(klass.getJavaMirror()); |
|
936 |
||
937 |
ClassData cd = (ClassData) classDataCache.get(klass); |
|
30235
000cc9f42b61
8044416: serviceability/sa/jmap-hashcode/Test8028623.java fails with AssertionFailure: can not get class data for java/lang/UNIXProcess$Platform$$Lambda
dsamersoff
parents:
22234
diff
changeset
|
938 |
|
1 | 939 |
if (Assert.ASSERTS_ENABLED) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
940 |
Assert.that(cd != null, "can not get class data for " + klass.getName().asString() + klass.getAddress()); |
1 | 941 |
} |
942 |
List fields = cd.fields; |
|
943 |
int size = cd.instSize; |
|
944 |
out.writeInt(size); |
|
945 |
for (Iterator itr = fields.iterator(); itr.hasNext();) { |
|
946 |
writeField((Field) itr.next(), instance); |
|
947 |
} |
|
948 |
} |
|
949 |
||
950 |
//-- Internals only below this point |
|
951 |
||
952 |
private void writeFieldDescriptors(List fields, InstanceKlass ik) |
|
953 |
throws IOException { |
|
954 |
// ik == null for instance fields. |
|
955 |
out.writeShort((short) fields.size()); |
|
956 |
for (Iterator itr = fields.iterator(); itr.hasNext();) { |
|
957 |
Field field = (Field) itr.next(); |
|
958 |
Symbol name = symTbl.probe(field.getID().getName()); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
959 |
writeSymbolID(name); |
1 | 960 |
char typeCode = (char) field.getSignature().getByteAt(0); |
961 |
int kind = signatureToHprofKind(typeCode); |
|
962 |
out.writeByte((byte)kind); |
|
963 |
if (ik != null) { |
|
964 |
// static field |
|
8729
cdb7525d39cb
7030300: more nightly failures after statics in Class changes
never
parents:
8076
diff
changeset
|
965 |
writeField(field, ik.getJavaMirror()); |
1 | 966 |
} |
967 |
} |
|
968 |
} |
|
969 |
||
970 |
public static int signatureToHprofKind(char ch) { |
|
971 |
switch (ch) { |
|
972 |
case JVM_SIGNATURE_CLASS: |
|
973 |
case JVM_SIGNATURE_ARRAY: |
|
974 |
return HPROF_NORMAL_OBJECT; |
|
975 |
case JVM_SIGNATURE_BOOLEAN: |
|
976 |
return HPROF_BOOLEAN; |
|
977 |
case JVM_SIGNATURE_CHAR: |
|
978 |
return HPROF_CHAR; |
|
979 |
case JVM_SIGNATURE_FLOAT: |
|
980 |
return HPROF_FLOAT; |
|
981 |
case JVM_SIGNATURE_DOUBLE: |
|
982 |
return HPROF_DOUBLE; |
|
983 |
case JVM_SIGNATURE_BYTE: |
|
984 |
return HPROF_BYTE; |
|
985 |
case JVM_SIGNATURE_SHORT: |
|
986 |
return HPROF_SHORT; |
|
987 |
case JVM_SIGNATURE_INT: |
|
988 |
return HPROF_INT; |
|
989 |
case JVM_SIGNATURE_LONG: |
|
990 |
return HPROF_LONG; |
|
991 |
default: |
|
992 |
throw new RuntimeException("should not reach here"); |
|
993 |
} |
|
994 |
} |
|
995 |
||
996 |
private void writeField(Field field, Oop oop) throws IOException { |
|
997 |
char typeCode = (char) field.getSignature().getByteAt(0); |
|
998 |
switch (typeCode) { |
|
999 |
case JVM_SIGNATURE_BOOLEAN: |
|
1000 |
out.writeBoolean(((BooleanField)field).getValue(oop)); |
|
1001 |
break; |
|
1002 |
case JVM_SIGNATURE_CHAR: |
|
1003 |
out.writeChar(((CharField)field).getValue(oop)); |
|
1004 |
break; |
|
1005 |
case JVM_SIGNATURE_BYTE: |
|
1006 |
out.writeByte(((ByteField)field).getValue(oop)); |
|
1007 |
break; |
|
1008 |
case JVM_SIGNATURE_SHORT: |
|
1009 |
out.writeShort(((ShortField)field).getValue(oop)); |
|
1010 |
break; |
|
1011 |
case JVM_SIGNATURE_INT: |
|
1012 |
out.writeInt(((IntField)field).getValue(oop)); |
|
1013 |
break; |
|
1014 |
case JVM_SIGNATURE_LONG: |
|
1015 |
out.writeLong(((LongField)field).getValue(oop)); |
|
1016 |
break; |
|
1017 |
case JVM_SIGNATURE_FLOAT: |
|
1018 |
out.writeFloat(((FloatField)field).getValue(oop)); |
|
1019 |
break; |
|
1020 |
case JVM_SIGNATURE_DOUBLE: |
|
1021 |
out.writeDouble(((DoubleField)field).getValue(oop)); |
|
1022 |
break; |
|
1023 |
case JVM_SIGNATURE_CLASS: |
|
1024 |
case JVM_SIGNATURE_ARRAY: { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1025 |
if (VM.getVM().isCompressedOopsEnabled()) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1026 |
OopHandle handle = ((NarrowOopField)field).getValueAsOopHandle(oop); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1027 |
writeObjectID(getAddressValue(handle)); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1028 |
} else { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1029 |
OopHandle handle = ((OopField)field).getValueAsOopHandle(oop); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1030 |
writeObjectID(getAddressValue(handle)); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1031 |
} |
1 | 1032 |
break; |
1033 |
} |
|
1034 |
default: |
|
1035 |
throw new RuntimeException("should not reach here"); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
||
1039 |
private void writeHeader(int tag, int len) throws IOException { |
|
1040 |
out.writeByte((byte)tag); |
|
1041 |
out.writeInt(0); // current ticks |
|
1042 |
out.writeInt(len); |
|
1043 |
} |
|
1044 |
||
1045 |
private void writeDummyTrace() throws IOException { |
|
1046 |
writeHeader(HPROF_TRACE, 3 * 4); |
|
1047 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
|
1048 |
out.writeInt(0); |
|
1049 |
out.writeInt(0); |
|
1050 |
} |
|
1051 |
||
1052 |
private void writeSymbols() throws IOException { |
|
1053 |
try { |
|
1054 |
symTbl.symbolsDo(new SymbolTable.SymbolVisitor() { |
|
1055 |
public void visit(Symbol sym) { |
|
1056 |
try { |
|
1057 |
writeSymbol(sym); |
|
1058 |
} catch (IOException exp) { |
|
1059 |
throw new RuntimeException(exp); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
}); |
|
1063 |
} catch (RuntimeException re) { |
|
1064 |
handleRuntimeException(re); |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
1068 |
private void writeSymbol(Symbol sym) throws IOException { |
|
1069 |
byte[] buf = sym.asString().getBytes("UTF-8"); |
|
1070 |
writeHeader(HPROF_UTF8, buf.length + OBJ_ID_SIZE); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1071 |
writeSymbolID(sym); |
1 | 1072 |
out.write(buf); |
1073 |
} |
|
1074 |
||
1075 |
private void writeClasses() throws IOException { |
|
1076 |
// write class list (id, name) association |
|
42889
0b0ae99d8639
8159127: hprof heap dumps broken for lambda classdata
dsamersoff
parents:
35217
diff
changeset
|
1077 |
ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph(); |
1 | 1078 |
try { |
46729 | 1079 |
cldGraph.classesDo(new ClassLoaderDataGraph.ClassVisitor() { |
1 | 1080 |
public void visit(Klass k) { |
1081 |
try { |
|
1082 |
Instance clazz = k.getJavaMirror(); |
|
1083 |
writeHeader(HPROF_LOAD_CLASS, 2 * (OBJ_ID_SIZE + 4)); |
|
1084 |
out.writeInt(serialNum); |
|
1085 |
writeObjectID(clazz); |
|
45371
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
1086 |
KlassMap.add(serialNum - 1, k); |
1 | 1087 |
out.writeInt(DUMMY_STACK_TRACE_ID); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1088 |
writeSymbolID(k.getName()); |
1 | 1089 |
serialNum++; |
1090 |
} catch (IOException exp) { |
|
1091 |
throw new RuntimeException(exp); |
|
1092 |
} |
|
1093 |
} |
|
1094 |
}); |
|
1095 |
} catch (RuntimeException re) { |
|
1096 |
handleRuntimeException(re); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
||
1100 |
// writes hprof binary file header |
|
1101 |
private void writeFileHeader() throws IOException { |
|
1102 |
// version string |
|
43671
a152f2d3320e
8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
42889
diff
changeset
|
1103 |
out.writeBytes(HPROF_HEADER_1_0_2); |
1 | 1104 |
out.writeByte((byte)'\0'); |
1105 |
||
1106 |
// write identifier size. we use pointers as identifiers. |
|
1107 |
out.writeInt(OBJ_ID_SIZE); |
|
1108 |
||
1109 |
// timestamp -- file creation time. |
|
1110 |
out.writeLong(System.currentTimeMillis()); |
|
1111 |
} |
|
1112 |
||
1113 |
// writes unique ID for an object |
|
1114 |
private void writeObjectID(Oop oop) throws IOException { |
|
1115 |
OopHandle handle = (oop != null)? oop.getHandle() : null; |
|
1116 |
long address = getAddressValue(handle); |
|
1117 |
writeObjectID(address); |
|
1118 |
} |
|
1119 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1120 |
private void writeSymbolID(Symbol sym) throws IOException { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1121 |
writeObjectID(getAddressValue(sym.getAddress())); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1122 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
5547
diff
changeset
|
1123 |
|
1 | 1124 |
private void writeObjectID(long address) throws IOException { |
1125 |
if (OBJ_ID_SIZE == 4) { |
|
1126 |
out.writeInt((int) address); |
|
1127 |
} else { |
|
1128 |
out.writeLong(address); |
|
1129 |
} |
|
1130 |
} |
|
1131 |
||
1132 |
private long getAddressValue(Address addr) { |
|
1133 |
return (addr == null)? 0L : dbg.getAddressValue(addr); |
|
1134 |
} |
|
1135 |
||
1136 |
// get all declared as well as inherited (directly/indirectly) fields |
|
1137 |
private static List/*<Field>*/ getInstanceFields(InstanceKlass ik) { |
|
1138 |
InstanceKlass klass = ik; |
|
1139 |
List res = new ArrayList(); |
|
1140 |
while (klass != null) { |
|
1141 |
List curFields = klass.getImmediateFields(); |
|
1142 |
for (Iterator itr = curFields.iterator(); itr.hasNext();) { |
|
1143 |
Field f = (Field) itr.next(); |
|
1144 |
if (! f.isStatic()) { |
|
1145 |
res.add(f); |
|
1146 |
} |
|
1147 |
} |
|
1148 |
klass = (InstanceKlass) klass.getSuper(); |
|
1149 |
} |
|
1150 |
return res; |
|
1151 |
} |
|
1152 |
||
1153 |
// get size in bytes (in stream) required for given fields. Note |
|
1154 |
// that this is not the same as object size in heap. The size in |
|
1155 |
// heap will include size of padding/alignment bytes as well. |
|
1156 |
private int getSizeForFields(List fields) { |
|
1157 |
int size = 0; |
|
1158 |
for (Iterator itr = fields.iterator(); itr.hasNext();) { |
|
1159 |
Field field = (Field) itr.next(); |
|
1160 |
char typeCode = (char) field.getSignature().getByteAt(0); |
|
1161 |
switch (typeCode) { |
|
1162 |
case JVM_SIGNATURE_BOOLEAN: |
|
1163 |
case JVM_SIGNATURE_BYTE: |
|
1164 |
size++; |
|
1165 |
break; |
|
1166 |
case JVM_SIGNATURE_CHAR: |
|
1167 |
case JVM_SIGNATURE_SHORT: |
|
1168 |
size += 2; |
|
1169 |
break; |
|
1170 |
case JVM_SIGNATURE_INT: |
|
1171 |
case JVM_SIGNATURE_FLOAT: |
|
1172 |
size += 4; |
|
1173 |
break; |
|
1174 |
case JVM_SIGNATURE_CLASS: |
|
1175 |
case JVM_SIGNATURE_ARRAY: |
|
1176 |
size += OBJ_ID_SIZE; |
|
1177 |
break; |
|
1178 |
case JVM_SIGNATURE_LONG: |
|
1179 |
case JVM_SIGNATURE_DOUBLE: |
|
1180 |
size += 8; |
|
1181 |
break; |
|
1182 |
default: |
|
1183 |
throw new RuntimeException("should not reach here"); |
|
1184 |
} |
|
1185 |
} |
|
1186 |
return size; |
|
1187 |
} |
|
1188 |
||
1189 |
// We don't have allocation site info. We write a dummy |
|
1190 |
// stack trace with this id. |
|
1191 |
private static final int DUMMY_STACK_TRACE_ID = 1; |
|
1192 |
private static final int EMPTY_FRAME_DEPTH = -1; |
|
1193 |
||
1194 |
private DataOutputStream out; |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1195 |
private FileOutputStream fos; |
1 | 1196 |
private Debugger dbg; |
1197 |
private ObjectHeap objectHeap; |
|
1198 |
private SymbolTable symTbl; |
|
45371
5d0b68ea07c3
6760477: Update SA to include stack traces in the heap dump
sballal
parents:
43671
diff
changeset
|
1199 |
private ArrayList<Klass> KlassMap; |
1 | 1200 |
|
1201 |
// oopSize of the debuggee |
|
1202 |
private int OBJ_ID_SIZE; |
|
1203 |
||
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1204 |
// Added for hprof file format 1.0.2 support |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1205 |
private boolean useSegmentedHeapDump; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1206 |
private long currentSegmentStart; |
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1207 |
|
1 | 1208 |
private long BOOLEAN_BASE_OFFSET; |
1209 |
private long BYTE_BASE_OFFSET; |
|
1210 |
private long CHAR_BASE_OFFSET; |
|
1211 |
private long SHORT_BASE_OFFSET; |
|
1212 |
private long INT_BASE_OFFSET; |
|
1213 |
private long LONG_BASE_OFFSET; |
|
1214 |
private long FLOAT_BASE_OFFSET; |
|
1215 |
private long DOUBLE_BASE_OFFSET; |
|
1216 |
private long OBJECT_BASE_OFFSET; |
|
1217 |
||
1218 |
private long BOOLEAN_SIZE; |
|
1219 |
private long BYTE_SIZE; |
|
1220 |
private long CHAR_SIZE; |
|
1221 |
private long SHORT_SIZE; |
|
1222 |
private long INT_SIZE; |
|
1223 |
private long LONG_SIZE; |
|
1224 |
private long FLOAT_SIZE; |
|
1225 |
private long DOUBLE_SIZE; |
|
1226 |
||
1227 |
private static class ClassData { |
|
1228 |
int instSize; |
|
1229 |
List fields; |
|
20388
2cf7b26682dc
6313383: SA: Update jmap to support HPROF binary format "JAVA PROFILE 1.0.2"
sla
parents:
17826
diff
changeset
|
1230 |
|
1 | 1231 |
ClassData(int instSize, List fields) { |
1232 |
this.instSize = instSize; |
|
1233 |
this.fields = fields; |
|
1234 |
} |
|
1235 |
} |
|
1236 |
||
1237 |
private Map classDataCache = new HashMap(); // <InstanceKlass, ClassData> |
|
1238 |
} |