Mercurial > hg > graal-compiler
annotate src/share/vm/services/heapDumper.cpp @ 2142:8012aa3ccede
4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed
author | never |
---|---|
date | Thu, 13 Jan 2011 22:15:41 -0800 |
parents | f95d63e2154a |
children | 17c778814856 |
rev | line source |
---|---|
0 | 1 /* |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/symbolTable.hpp" | |
27 #include "classfile/systemDictionary.hpp" | |
28 #include "classfile/vmSymbols.hpp" | |
29 #include "gc_implementation/shared/vmGCOperations.hpp" | |
30 #include "memory/genCollectedHeap.hpp" | |
31 #include "memory/universe.hpp" | |
32 #include "oops/objArrayKlass.hpp" | |
33 #include "runtime/javaCalls.hpp" | |
34 #include "runtime/jniHandles.hpp" | |
35 #include "runtime/reflectionUtils.hpp" | |
36 #include "runtime/vframe.hpp" | |
37 #include "runtime/vmThread.hpp" | |
38 #include "runtime/vm_operations.hpp" | |
39 #include "services/heapDumper.hpp" | |
40 #include "services/threadService.hpp" | |
41 #include "utilities/ostream.hpp" | |
42 #ifndef SERIALGC | |
43 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" | |
44 #endif | |
0 | 45 |
46 /* | |
47 * HPROF binary format - description copied from: | |
48 * src/share/demo/jvmti/hprof/hprof_io.c | |
49 * | |
50 * | |
51 * header "JAVA PROFILE 1.0.1" or "JAVA PROFILE 1.0.2" | |
52 * (0-terminated) | |
53 * | |
54 * u4 size of identifiers. Identifiers are used to represent | |
55 * UTF8 strings, objects, stack traces, etc. They usually | |
56 * have the same size as host pointers. For example, on | |
57 * Solaris and Win32, the size is 4. | |
58 * u4 high word | |
59 * u4 low word number of milliseconds since 0:00 GMT, 1/1/70 | |
60 * [record]* a sequence of records. | |
61 * | |
62 * | |
63 * Record format: | |
64 * | |
65 * u1 a TAG denoting the type of the record | |
66 * u4 number of *microseconds* since the time stamp in the | |
67 * header. (wraps around in a little more than an hour) | |
68 * u4 number of bytes *remaining* in the record. Note that | |
69 * this number excludes the tag and the length field itself. | |
70 * [u1]* BODY of the record (a sequence of bytes) | |
71 * | |
72 * | |
73 * The following TAGs are supported: | |
74 * | |
75 * TAG BODY notes | |
76 *---------------------------------------------------------- | |
77 * HPROF_UTF8 a UTF8-encoded name | |
78 * | |
79 * id name ID | |
80 * [u1]* UTF8 characters (no trailing zero) | |
81 * | |
82 * HPROF_LOAD_CLASS a newly loaded class | |
83 * | |
84 * u4 class serial number (> 0) | |
85 * id class object ID | |
86 * u4 stack trace serial number | |
87 * id class name ID | |
88 * | |
89 * HPROF_UNLOAD_CLASS an unloading class | |
90 * | |
91 * u4 class serial_number | |
92 * | |
93 * HPROF_FRAME a Java stack frame | |
94 * | |
95 * id stack frame ID | |
96 * id method name ID | |
97 * id method signature ID | |
98 * id source file name ID | |
99 * u4 class serial number | |
100 * i4 line number. >0: normal | |
101 * -1: unknown | |
102 * -2: compiled method | |
103 * -3: native method | |
104 * | |
105 * HPROF_TRACE a Java stack trace | |
106 * | |
107 * u4 stack trace serial number | |
108 * u4 thread serial number | |
109 * u4 number of frames | |
110 * [id]* stack frame IDs | |
111 * | |
112 * | |
113 * HPROF_ALLOC_SITES a set of heap allocation sites, obtained after GC | |
114 * | |
115 * u2 flags 0x0001: incremental vs. complete | |
116 * 0x0002: sorted by allocation vs. live | |
117 * 0x0004: whether to force a GC | |
118 * u4 cutoff ratio | |
119 * u4 total live bytes | |
120 * u4 total live instances | |
121 * u8 total bytes allocated | |
122 * u8 total instances allocated | |
123 * u4 number of sites that follow | |
124 * [u1 is_array: 0: normal object | |
125 * 2: object array | |
126 * 4: boolean array | |
127 * 5: char array | |
128 * 6: float array | |
129 * 7: double array | |
130 * 8: byte array | |
131 * 9: short array | |
132 * 10: int array | |
133 * 11: long array | |
134 * u4 class serial number (may be zero during startup) | |
135 * u4 stack trace serial number | |
136 * u4 number of bytes alive | |
137 * u4 number of instances alive | |
138 * u4 number of bytes allocated | |
139 * u4]* number of instance allocated | |
140 * | |
141 * HPROF_START_THREAD a newly started thread. | |
142 * | |
143 * u4 thread serial number (> 0) | |
144 * id thread object ID | |
145 * u4 stack trace serial number | |
146 * id thread name ID | |
147 * id thread group name ID | |
148 * id thread group parent name ID | |
149 * | |
150 * HPROF_END_THREAD a terminating thread. | |
151 * | |
152 * u4 thread serial number | |
153 * | |
154 * HPROF_HEAP_SUMMARY heap summary | |
155 * | |
156 * u4 total live bytes | |
157 * u4 total live instances | |
158 * u8 total bytes allocated | |
159 * u8 total instances allocated | |
160 * | |
161 * HPROF_HEAP_DUMP denote a heap dump | |
162 * | |
163 * [heap dump sub-records]* | |
164 * | |
165 * There are four kinds of heap dump sub-records: | |
166 * | |
167 * u1 sub-record type | |
168 * | |
169 * HPROF_GC_ROOT_UNKNOWN unknown root | |
170 * | |
171 * id object ID | |
172 * | |
173 * HPROF_GC_ROOT_THREAD_OBJ thread object | |
174 * | |
175 * id thread object ID (may be 0 for a | |
176 * thread newly attached through JNI) | |
177 * u4 thread sequence number | |
178 * u4 stack trace sequence number | |
179 * | |
180 * HPROF_GC_ROOT_JNI_GLOBAL JNI global ref root | |
181 * | |
182 * id object ID | |
183 * id JNI global ref ID | |
184 * | |
185 * HPROF_GC_ROOT_JNI_LOCAL JNI local ref | |
186 * | |
187 * id object ID | |
188 * u4 thread serial number | |
189 * u4 frame # in stack trace (-1 for empty) | |
190 * | |
191 * HPROF_GC_ROOT_JAVA_FRAME Java stack frame | |
192 * | |
193 * id object ID | |
194 * u4 thread serial number | |
195 * u4 frame # in stack trace (-1 for empty) | |
196 * | |
197 * HPROF_GC_ROOT_NATIVE_STACK Native stack | |
198 * | |
199 * id object ID | |
200 * u4 thread serial number | |
201 * | |
202 * HPROF_GC_ROOT_STICKY_CLASS System class | |
203 * | |
204 * id object ID | |
205 * | |
206 * HPROF_GC_ROOT_THREAD_BLOCK Reference from thread block | |
207 * | |
208 * id object ID | |
209 * u4 thread serial number | |
210 * | |
211 * HPROF_GC_ROOT_MONITOR_USED Busy monitor | |
212 * | |
213 * id object ID | |
214 * | |
215 * HPROF_GC_CLASS_DUMP dump of a class object | |
216 * | |
217 * id class object ID | |
218 * u4 stack trace serial number | |
219 * id super class object ID | |
220 * id class loader object ID | |
221 * id signers object ID | |
222 * id protection domain object ID | |
223 * id reserved | |
224 * id reserved | |
225 * | |
226 * u4 instance size (in bytes) | |
227 * | |
228 * u2 size of constant pool | |
229 * [u2, constant pool index, | |
230 * ty, type | |
231 * 2: object | |
232 * 4: boolean | |
233 * 5: char | |
234 * 6: float | |
235 * 7: double | |
236 * 8: byte | |
237 * 9: short | |
238 * 10: int | |
239 * 11: long | |
240 * vl]* and value | |
241 * | |
242 * u2 number of static fields | |
243 * [id, static field name, | |
244 * ty, type, | |
245 * vl]* and value | |
246 * | |
247 * u2 number of inst. fields (not inc. super) | |
248 * [id, instance field name, | |
249 * ty]* type | |
250 * | |
251 * HPROF_GC_INSTANCE_DUMP dump of a normal object | |
252 * | |
253 * id object ID | |
254 * u4 stack trace serial number | |
255 * id class object ID | |
256 * u4 number of bytes that follow | |
257 * [vl]* instance field values (class, followed | |
258 * by super, super's super ...) | |
259 * | |
260 * HPROF_GC_OBJ_ARRAY_DUMP dump of an object array | |
261 * | |
262 * id array object ID | |
263 * u4 stack trace serial number | |
264 * u4 number of elements | |
265 * id array class ID | |
266 * [id]* elements | |
267 * | |
268 * HPROF_GC_PRIM_ARRAY_DUMP dump of a primitive array | |
269 * | |
270 * id array object ID | |
271 * u4 stack trace serial number | |
272 * u4 number of elements | |
273 * u1 element type | |
274 * 4: boolean array | |
275 * 5: char array | |
276 * 6: float array | |
277 * 7: double array | |
278 * 8: byte array | |
279 * 9: short array | |
280 * 10: int array | |
281 * 11: long array | |
282 * [u1]* elements | |
283 * | |
284 * HPROF_CPU_SAMPLES a set of sample traces of running threads | |
285 * | |
286 * u4 total number of samples | |
287 * u4 # of traces | |
288 * [u4 # of samples | |
289 * u4]* stack trace serial number | |
290 * | |
291 * HPROF_CONTROL_SETTINGS the settings of on/off switches | |
292 * | |
293 * u4 0x00000001: alloc traces on/off | |
294 * 0x00000002: cpu sampling on/off | |
295 * u2 stack trace depth | |
296 * | |
297 * | |
298 * When the header is "JAVA PROFILE 1.0.2" a heap dump can optionally | |
299 * be generated as a sequence of heap dump segments. This sequence is | |
300 * terminated by an end record. The additional tags allowed by format | |
301 * "JAVA PROFILE 1.0.2" are: | |
302 * | |
303 * HPROF_HEAP_DUMP_SEGMENT denote a heap dump segment | |
304 * | |
305 * [heap dump sub-records]* | |
306 * The same sub-record types allowed by HPROF_HEAP_DUMP | |
307 * | |
308 * HPROF_HEAP_DUMP_END denotes the end of a heap dump | |
309 * | |
310 */ | |
311 | |
312 | |
313 // HPROF tags | |
314 | |
315 typedef enum { | |
316 // top-level records | |
317 HPROF_UTF8 = 0x01, | |
318 HPROF_LOAD_CLASS = 0x02, | |
319 HPROF_UNLOAD_CLASS = 0x03, | |
320 HPROF_FRAME = 0x04, | |
321 HPROF_TRACE = 0x05, | |
322 HPROF_ALLOC_SITES = 0x06, | |
323 HPROF_HEAP_SUMMARY = 0x07, | |
324 HPROF_START_THREAD = 0x0A, | |
325 HPROF_END_THREAD = 0x0B, | |
326 HPROF_HEAP_DUMP = 0x0C, | |
327 HPROF_CPU_SAMPLES = 0x0D, | |
328 HPROF_CONTROL_SETTINGS = 0x0E, | |
329 | |
330 // 1.0.2 record types | |
331 HPROF_HEAP_DUMP_SEGMENT = 0x1C, | |
332 HPROF_HEAP_DUMP_END = 0x2C, | |
333 | |
334 // field types | |
335 HPROF_ARRAY_OBJECT = 0x01, | |
336 HPROF_NORMAL_OBJECT = 0x02, | |
337 HPROF_BOOLEAN = 0x04, | |
338 HPROF_CHAR = 0x05, | |
339 HPROF_FLOAT = 0x06, | |
340 HPROF_DOUBLE = 0x07, | |
341 HPROF_BYTE = 0x08, | |
342 HPROF_SHORT = 0x09, | |
343 HPROF_INT = 0x0A, | |
344 HPROF_LONG = 0x0B, | |
345 | |
346 // data-dump sub-records | |
347 HPROF_GC_ROOT_UNKNOWN = 0xFF, | |
348 HPROF_GC_ROOT_JNI_GLOBAL = 0x01, | |
349 HPROF_GC_ROOT_JNI_LOCAL = 0x02, | |
350 HPROF_GC_ROOT_JAVA_FRAME = 0x03, | |
351 HPROF_GC_ROOT_NATIVE_STACK = 0x04, | |
352 HPROF_GC_ROOT_STICKY_CLASS = 0x05, | |
353 HPROF_GC_ROOT_THREAD_BLOCK = 0x06, | |
354 HPROF_GC_ROOT_MONITOR_USED = 0x07, | |
355 HPROF_GC_ROOT_THREAD_OBJ = 0x08, | |
356 HPROF_GC_CLASS_DUMP = 0x20, | |
357 HPROF_GC_INSTANCE_DUMP = 0x21, | |
358 HPROF_GC_OBJ_ARRAY_DUMP = 0x22, | |
359 HPROF_GC_PRIM_ARRAY_DUMP = 0x23 | |
360 } hprofTag; | |
361 | |
362 // Default stack trace ID (used for dummy HPROF_TRACE record) | |
363 enum { | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
364 STACK_TRACE_ID = 1, |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
365 INITIAL_CLASS_COUNT = 200 |
0 | 366 }; |
367 | |
368 // Supports I/O operations on a dump file | |
369 | |
370 class DumpWriter : public StackObj { | |
371 private: | |
372 enum { | |
373 io_buffer_size = 8*M | |
374 }; | |
375 | |
376 int _fd; // file descriptor (-1 if dump file not open) | |
377 jlong _bytes_written; // number of byte written to dump file | |
378 | |
379 char* _buffer; // internal buffer | |
380 int _size; | |
381 int _pos; | |
382 | |
383 char* _error; // error message when I/O fails | |
384 | |
385 void set_file_descriptor(int fd) { _fd = fd; } | |
386 int file_descriptor() const { return _fd; } | |
387 | |
388 char* buffer() const { return _buffer; } | |
389 int buffer_size() const { return _size; } | |
390 int position() const { return _pos; } | |
391 void set_position(int pos) { _pos = pos; } | |
392 | |
393 void set_error(const char* error) { _error = (char*)os::strdup(error); } | |
394 | |
395 // all I/O go through this function | |
396 void write_internal(void* s, int len); | |
397 | |
398 public: | |
399 DumpWriter(const char* path); | |
400 ~DumpWriter(); | |
401 | |
402 void close(); | |
403 bool is_open() const { return file_descriptor() >= 0; } | |
404 void flush(); | |
405 | |
406 // total number of bytes written to the disk | |
407 jlong bytes_written() const { return _bytes_written; } | |
408 | |
409 // adjust the number of bytes written to disk (used to keep the count | |
410 // of the number of bytes written in case of rewrites) | |
411 void adjust_bytes_written(jlong n) { _bytes_written += n; } | |
412 | |
413 // number of (buffered) bytes as yet unwritten to the dump file | |
414 jlong bytes_unwritten() const { return (jlong)position(); } | |
415 | |
416 char* error() const { return _error; } | |
417 | |
418 jlong current_offset(); | |
419 void seek_to_offset(jlong pos); | |
420 | |
421 // writer functions | |
422 void write_raw(void* s, int len); | |
423 void write_u1(u1 x) { write_raw((void*)&x, 1); } | |
424 void write_u2(u2 x); | |
425 void write_u4(u4 x); | |
426 void write_u8(u8 x); | |
427 void write_objectID(oop o); | |
428 void write_classID(Klass* k); | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
429 void write_id(u4 x); |
0 | 430 }; |
431 | |
432 DumpWriter::DumpWriter(const char* path) { | |
433 // try to allocate an I/O buffer of io_buffer_size. If there isn't | |
434 // sufficient memory then reduce size until we can allocate something. | |
435 _size = io_buffer_size; | |
436 do { | |
437 _buffer = (char*)os::malloc(_size); | |
438 if (_buffer == NULL) { | |
439 _size = _size >> 1; | |
440 } | |
441 } while (_buffer == NULL && _size > 0); | |
442 assert((_size > 0 && _buffer != NULL) || (_size == 0 && _buffer == NULL), "sanity check"); | |
443 _pos = 0; | |
444 _error = NULL; | |
445 _bytes_written = 0L; | |
446 _fd = os::create_binary_file(path, false); // don't replace existing file | |
447 | |
448 // if the open failed we record the error | |
449 if (_fd < 0) { | |
450 _error = (char*)os::strdup(strerror(errno)); | |
451 } | |
452 } | |
453 | |
454 DumpWriter::~DumpWriter() { | |
455 // flush and close dump file | |
456 if (file_descriptor() >= 0) { | |
457 close(); | |
458 } | |
459 if (_buffer != NULL) os::free(_buffer); | |
460 if (_error != NULL) os::free(_error); | |
461 } | |
462 | |
463 // closes dump file (if open) | |
464 void DumpWriter::close() { | |
465 // flush and close dump file | |
466 if (file_descriptor() >= 0) { | |
467 flush(); | |
468 ::close(file_descriptor()); | |
469 } | |
470 } | |
471 | |
472 // write directly to the file | |
473 void DumpWriter::write_internal(void* s, int len) { | |
474 if (is_open()) { | |
475 int n = ::write(file_descriptor(), s, len); | |
476 if (n > 0) { | |
477 _bytes_written += n; | |
478 } | |
479 if (n != len) { | |
480 if (n < 0) { | |
481 set_error(strerror(errno)); | |
482 } else { | |
483 set_error("file size limit"); | |
484 } | |
485 ::close(file_descriptor()); | |
486 set_file_descriptor(-1); | |
487 } | |
488 } | |
489 } | |
490 | |
491 // write raw bytes | |
492 void DumpWriter::write_raw(void* s, int len) { | |
493 if (is_open()) { | |
494 // flush buffer to make toom | |
495 if ((position()+ len) >= buffer_size()) { | |
496 flush(); | |
497 } | |
498 | |
499 // buffer not available or too big to buffer it | |
500 if ((buffer() == NULL) || (len >= buffer_size())) { | |
501 write_internal(s, len); | |
502 } else { | |
503 // Should optimize this for u1/u2/u4/u8 sizes. | |
504 memcpy(buffer() + position(), s, len); | |
505 set_position(position() + len); | |
506 } | |
507 } | |
508 } | |
509 | |
510 // flush any buffered bytes to the file | |
511 void DumpWriter::flush() { | |
512 if (is_open() && position() > 0) { | |
513 write_internal(buffer(), position()); | |
514 set_position(0); | |
515 } | |
516 } | |
517 | |
518 | |
519 jlong DumpWriter::current_offset() { | |
520 if (is_open()) { | |
521 // the offset is the file offset plus whatever we have buffered | |
522 jlong offset = os::current_file_offset(file_descriptor()); | |
523 assert(offset >= 0, "lseek failed"); | |
524 return offset + (jlong)position(); | |
525 } else { | |
526 return (jlong)-1; | |
527 } | |
528 } | |
529 | |
530 void DumpWriter::seek_to_offset(jlong off) { | |
531 assert(off >= 0, "bad offset"); | |
532 | |
533 // need to flush before seeking | |
534 flush(); | |
535 | |
536 // may be closed due to I/O error | |
537 if (is_open()) { | |
538 jlong n = os::seek_to_file_offset(file_descriptor(), off); | |
539 assert(n >= 0, "lseek failed"); | |
540 } | |
541 } | |
542 | |
543 void DumpWriter::write_u2(u2 x) { | |
544 u2 v; | |
545 Bytes::put_Java_u2((address)&v, x); | |
546 write_raw((void*)&v, 2); | |
547 } | |
548 | |
549 void DumpWriter::write_u4(u4 x) { | |
550 u4 v; | |
551 Bytes::put_Java_u4((address)&v, x); | |
552 write_raw((void*)&v, 4); | |
553 } | |
554 | |
555 void DumpWriter::write_u8(u8 x) { | |
556 u8 v; | |
557 Bytes::put_Java_u8((address)&v, x); | |
558 write_raw((void*)&v, 8); | |
559 } | |
560 | |
561 void DumpWriter::write_objectID(oop o) { | |
562 address a = (address)((uintptr_t)o); | |
563 #ifdef _LP64 | |
564 write_u8((u8)a); | |
565 #else | |
566 write_u4((u4)a); | |
567 #endif | |
568 } | |
569 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
570 void DumpWriter::write_id(u4 x) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
571 #ifdef _LP64 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
572 write_u8((u8) x); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
573 #else |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
574 write_u4(x); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
575 #endif |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
576 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
577 |
0 | 578 // We use java mirror as the class ID |
579 void DumpWriter::write_classID(Klass* k) { | |
580 write_objectID(k->java_mirror()); | |
581 } | |
582 | |
583 | |
584 | |
585 // Support class with a collection of functions used when dumping the heap | |
586 | |
587 class DumperSupport : AllStatic { | |
588 public: | |
589 | |
590 // write a header of the given type | |
591 static void write_header(DumpWriter* writer, hprofTag tag, u4 len); | |
592 | |
593 // returns hprof tag for the given type signature | |
594 static hprofTag sig2tag(symbolOop sig); | |
595 // returns hprof tag for the given basic type | |
596 static hprofTag type2tag(BasicType type); | |
597 | |
598 // returns the size of the instance of the given class | |
599 static u4 instance_size(klassOop k); | |
600 | |
601 // dump a jfloat | |
602 static void dump_float(DumpWriter* writer, jfloat f); | |
603 // dump a jdouble | |
604 static void dump_double(DumpWriter* writer, jdouble d); | |
605 // dumps the raw value of the given field | |
606 static void dump_field_value(DumpWriter* writer, char type, address addr); | |
607 // dumps static fields of the given class | |
608 static void dump_static_fields(DumpWriter* writer, klassOop k); | |
609 // dump the raw values of the instance fields of the given object | |
610 static void dump_instance_fields(DumpWriter* writer, oop o); | |
611 // dumps the definition of the instance fields for a given class | |
612 static void dump_instance_field_descriptors(DumpWriter* writer, klassOop k); | |
613 // creates HPROF_GC_INSTANCE_DUMP record for the given object | |
614 static void dump_instance(DumpWriter* writer, oop o); | |
615 // creates HPROF_GC_CLASS_DUMP record for the given class and each of its | |
616 // array classes | |
617 static void dump_class_and_array_classes(DumpWriter* writer, klassOop k); | |
618 // creates HPROF_GC_CLASS_DUMP record for a given primitive array | |
619 // class (and each multi-dimensional array class too) | |
620 static void dump_basic_type_array_class(DumpWriter* writer, klassOop k); | |
621 | |
622 // creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array | |
623 static void dump_object_array(DumpWriter* writer, objArrayOop array); | |
624 // creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array | |
625 static void dump_prim_array(DumpWriter* writer, typeArrayOop array); | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
626 // create HPROF_FRAME record for the given method and bci |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
627 static void dump_stack_frame(DumpWriter* writer, int frame_serial_num, int class_serial_num, methodOop m, int bci); |
0 | 628 }; |
629 | |
630 // write a header of the given type | |
631 void DumperSupport:: write_header(DumpWriter* writer, hprofTag tag, u4 len) { | |
632 writer->write_u1((u1)tag); | |
633 writer->write_u4(0); // current ticks | |
634 writer->write_u4(len); | |
635 } | |
636 | |
637 // returns hprof tag for the given type signature | |
638 hprofTag DumperSupport::sig2tag(symbolOop sig) { | |
639 switch (sig->byte_at(0)) { | |
640 case JVM_SIGNATURE_CLASS : return HPROF_NORMAL_OBJECT; | |
641 case JVM_SIGNATURE_ARRAY : return HPROF_NORMAL_OBJECT; | |
642 case JVM_SIGNATURE_BYTE : return HPROF_BYTE; | |
643 case JVM_SIGNATURE_CHAR : return HPROF_CHAR; | |
644 case JVM_SIGNATURE_FLOAT : return HPROF_FLOAT; | |
645 case JVM_SIGNATURE_DOUBLE : return HPROF_DOUBLE; | |
646 case JVM_SIGNATURE_INT : return HPROF_INT; | |
647 case JVM_SIGNATURE_LONG : return HPROF_LONG; | |
648 case JVM_SIGNATURE_SHORT : return HPROF_SHORT; | |
649 case JVM_SIGNATURE_BOOLEAN : return HPROF_BOOLEAN; | |
650 default : ShouldNotReachHere(); /* to shut up compiler */ return HPROF_BYTE; | |
651 } | |
652 } | |
653 | |
654 hprofTag DumperSupport::type2tag(BasicType type) { | |
655 switch (type) { | |
656 case T_BYTE : return HPROF_BYTE; | |
657 case T_CHAR : return HPROF_CHAR; | |
658 case T_FLOAT : return HPROF_FLOAT; | |
659 case T_DOUBLE : return HPROF_DOUBLE; | |
660 case T_INT : return HPROF_INT; | |
661 case T_LONG : return HPROF_LONG; | |
662 case T_SHORT : return HPROF_SHORT; | |
663 case T_BOOLEAN : return HPROF_BOOLEAN; | |
664 default : ShouldNotReachHere(); /* to shut up compiler */ return HPROF_BYTE; | |
665 } | |
666 } | |
667 | |
668 // dump a jfloat | |
669 void DumperSupport::dump_float(DumpWriter* writer, jfloat f) { | |
670 if (g_isnan(f)) { | |
671 writer->write_u4(0x7fc00000); // collapsing NaNs | |
672 } else { | |
673 union { | |
674 int i; | |
675 float f; | |
676 } u; | |
677 u.f = (float)f; | |
678 writer->write_u4((u4)u.i); | |
679 } | |
680 } | |
681 | |
682 // dump a jdouble | |
683 void DumperSupport::dump_double(DumpWriter* writer, jdouble d) { | |
684 union { | |
685 jlong l; | |
686 double d; | |
687 } u; | |
688 if (g_isnan(d)) { // collapsing NaNs | |
689 u.l = (jlong)(0x7ff80000); | |
690 u.l = (u.l << 32); | |
691 } else { | |
692 u.d = (double)d; | |
693 } | |
694 writer->write_u8((u8)u.l); | |
695 } | |
696 | |
697 // dumps the raw value of the given field | |
698 void DumperSupport::dump_field_value(DumpWriter* writer, char type, address addr) { | |
699 switch (type) { | |
700 case JVM_SIGNATURE_CLASS : | |
701 case JVM_SIGNATURE_ARRAY : { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
702 oop o; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
703 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
704 o = oopDesc::load_decode_heap_oop((narrowOop*)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
705 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
706 o = oopDesc::load_decode_heap_oop((oop*)addr); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
707 } |
0 | 708 |
709 // reflection and sun.misc.Unsafe classes may have a reference to a | |
710 // klassOop so filter it out. | |
711 if (o != NULL && o->is_klass()) { | |
712 o = NULL; | |
713 } | |
714 | |
715 // FIXME: When sharing is enabled we don't emit field references to objects | |
716 // in shared spaces. We can remove this once we write records for the classes | |
717 // and strings that are shared. | |
718 if (o != NULL && o->is_shared()) { | |
719 o = NULL; | |
720 } | |
721 writer->write_objectID(o); | |
722 break; | |
723 } | |
724 case JVM_SIGNATURE_BYTE : { | |
725 jbyte* b = (jbyte*)addr; | |
726 writer->write_u1((u1)*b); | |
727 break; | |
728 } | |
729 case JVM_SIGNATURE_CHAR : { | |
730 jchar* c = (jchar*)addr; | |
731 writer->write_u2((u2)*c); | |
732 break; | |
733 } | |
734 case JVM_SIGNATURE_SHORT : { | |
735 jshort* s = (jshort*)addr; | |
736 writer->write_u2((u2)*s); | |
737 break; | |
738 } | |
739 case JVM_SIGNATURE_FLOAT : { | |
740 jfloat* f = (jfloat*)addr; | |
741 dump_float(writer, *f); | |
742 break; | |
743 } | |
744 case JVM_SIGNATURE_DOUBLE : { | |
745 jdouble* f = (jdouble*)addr; | |
746 dump_double(writer, *f); | |
747 break; | |
748 } | |
749 case JVM_SIGNATURE_INT : { | |
750 jint* i = (jint*)addr; | |
751 writer->write_u4((u4)*i); | |
752 break; | |
753 } | |
754 case JVM_SIGNATURE_LONG : { | |
755 jlong* l = (jlong*)addr; | |
756 writer->write_u8((u8)*l); | |
757 break; | |
758 } | |
759 case JVM_SIGNATURE_BOOLEAN : { | |
760 jboolean* b = (jboolean*)addr; | |
761 writer->write_u1((u1)*b); | |
762 break; | |
763 } | |
764 default : ShouldNotReachHere(); | |
765 } | |
766 } | |
767 | |
768 // returns the size of the instance of the given class | |
769 u4 DumperSupport::instance_size(klassOop k) { | |
770 HandleMark hm; | |
771 instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k); | |
772 | |
773 int size = 0; | |
774 | |
775 for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) { | |
776 if (!fld.access_flags().is_static()) { | |
777 symbolOop sig = fld.signature(); | |
778 switch (sig->byte_at(0)) { | |
779 case JVM_SIGNATURE_CLASS : | |
780 case JVM_SIGNATURE_ARRAY : size += oopSize; break; | |
781 | |
782 case JVM_SIGNATURE_BYTE : | |
783 case JVM_SIGNATURE_BOOLEAN : size += 1; break; | |
784 | |
785 case JVM_SIGNATURE_CHAR : | |
786 case JVM_SIGNATURE_SHORT : size += 2; break; | |
787 | |
788 case JVM_SIGNATURE_INT : | |
789 case JVM_SIGNATURE_FLOAT : size += 4; break; | |
790 | |
791 case JVM_SIGNATURE_LONG : | |
792 case JVM_SIGNATURE_DOUBLE : size += 8; break; | |
793 | |
794 default : ShouldNotReachHere(); | |
795 } | |
796 } | |
797 } | |
798 return (u4)size; | |
799 } | |
800 | |
801 // dumps static fields of the given class | |
802 void DumperSupport::dump_static_fields(DumpWriter* writer, klassOop k) { | |
803 HandleMark hm; | |
804 instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k); | |
805 | |
806 // pass 1 - count the static fields | |
807 u2 field_count = 0; | |
808 for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) { | |
809 if (fldc.access_flags().is_static()) field_count++; | |
810 } | |
811 | |
812 writer->write_u2(field_count); | |
813 | |
814 // pass 2 - dump the field descriptors and raw values | |
815 for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) { | |
816 if (fld.access_flags().is_static()) { | |
817 symbolOop sig = fld.signature(); | |
818 | |
819 writer->write_objectID(fld.name()); // name | |
820 writer->write_u1(sig2tag(sig)); // type | |
821 | |
822 // value | |
823 int offset = fld.offset(); | |
824 address addr = (address)k + offset; | |
825 | |
826 dump_field_value(writer, sig->byte_at(0), addr); | |
827 } | |
828 } | |
829 } | |
830 | |
831 // dump the raw values of the instance fields of the given object | |
832 void DumperSupport::dump_instance_fields(DumpWriter* writer, oop o) { | |
833 HandleMark hm; | |
834 instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), o->klass()); | |
835 | |
836 for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) { | |
837 if (!fld.access_flags().is_static()) { | |
838 symbolOop sig = fld.signature(); | |
839 address addr = (address)o + fld.offset(); | |
840 | |
841 dump_field_value(writer, sig->byte_at(0), addr); | |
842 } | |
843 } | |
844 } | |
845 | |
846 // dumps the definition of the instance fields for a given class | |
847 void DumperSupport::dump_instance_field_descriptors(DumpWriter* writer, klassOop k) { | |
848 HandleMark hm; | |
849 instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k); | |
850 | |
851 // pass 1 - count the instance fields | |
852 u2 field_count = 0; | |
853 for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) { | |
854 if (!fldc.access_flags().is_static()) field_count++; | |
855 } | |
856 | |
857 writer->write_u2(field_count); | |
858 | |
859 // pass 2 - dump the field descriptors | |
860 for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) { | |
861 if (!fld.access_flags().is_static()) { | |
862 symbolOop sig = fld.signature(); | |
863 | |
864 writer->write_objectID(fld.name()); // name | |
865 writer->write_u1(sig2tag(sig)); // type | |
866 } | |
867 } | |
868 } | |
869 | |
870 // creates HPROF_GC_INSTANCE_DUMP record for the given object | |
871 void DumperSupport::dump_instance(DumpWriter* writer, oop o) { | |
872 klassOop k = o->klass(); | |
873 | |
874 writer->write_u1(HPROF_GC_INSTANCE_DUMP); | |
875 writer->write_objectID(o); | |
876 writer->write_u4(STACK_TRACE_ID); | |
877 | |
878 // class ID | |
879 writer->write_classID(Klass::cast(k)); | |
880 | |
881 // number of bytes that follow | |
882 writer->write_u4(instance_size(k) ); | |
883 | |
884 // field values | |
885 dump_instance_fields(writer, o); | |
886 } | |
887 | |
888 // creates HPROF_GC_CLASS_DUMP record for the given class and each of | |
889 // its array classes | |
890 void DumperSupport::dump_class_and_array_classes(DumpWriter* writer, klassOop k) { | |
891 Klass* klass = Klass::cast(k); | |
892 assert(klass->oop_is_instance(), "not an instanceKlass"); | |
893 instanceKlass* ik = (instanceKlass*)klass; | |
894 | |
895 writer->write_u1(HPROF_GC_CLASS_DUMP); | |
896 | |
897 // class ID | |
898 writer->write_classID(ik); | |
899 writer->write_u4(STACK_TRACE_ID); | |
900 | |
901 // super class ID | |
902 klassOop java_super = ik->java_super(); | |
903 if (java_super == NULL) { | |
904 writer->write_objectID(NULL); | |
905 } else { | |
906 writer->write_classID(Klass::cast(java_super)); | |
907 } | |
908 | |
909 writer->write_objectID(ik->class_loader()); | |
910 writer->write_objectID(ik->signers()); | |
911 writer->write_objectID(ik->protection_domain()); | |
912 | |
913 // reserved | |
914 writer->write_objectID(NULL); | |
915 writer->write_objectID(NULL); | |
916 | |
917 // instance size | |
918 writer->write_u4(DumperSupport::instance_size(k)); | |
919 | |
920 // size of constant pool - ignored by HAT 1.1 | |
921 writer->write_u2(0); | |
922 | |
923 // number of static fields | |
924 dump_static_fields(writer, k); | |
925 | |
926 // description of instance fields | |
927 dump_instance_field_descriptors(writer, k); | |
928 | |
929 // array classes | |
930 k = klass->array_klass_or_null(); | |
931 while (k != NULL) { | |
932 Klass* klass = Klass::cast(k); | |
933 assert(klass->oop_is_objArray(), "not an objArrayKlass"); | |
934 | |
935 writer->write_u1(HPROF_GC_CLASS_DUMP); | |
936 writer->write_classID(klass); | |
937 writer->write_u4(STACK_TRACE_ID); | |
938 | |
939 // super class of array classes is java.lang.Object | |
940 java_super = klass->java_super(); | |
941 assert(java_super != NULL, "checking"); | |
942 writer->write_classID(Klass::cast(java_super)); | |
943 | |
944 writer->write_objectID(ik->class_loader()); | |
945 writer->write_objectID(ik->signers()); | |
946 writer->write_objectID(ik->protection_domain()); | |
947 | |
948 writer->write_objectID(NULL); // reserved | |
949 writer->write_objectID(NULL); | |
950 writer->write_u4(0); // instance size | |
951 writer->write_u2(0); // constant pool | |
952 writer->write_u2(0); // static fields | |
953 writer->write_u2(0); // instance fields | |
954 | |
955 // get the array class for the next rank | |
956 k = klass->array_klass_or_null(); | |
957 } | |
958 } | |
959 | |
960 // creates HPROF_GC_CLASS_DUMP record for a given primitive array | |
961 // class (and each multi-dimensional array class too) | |
962 void DumperSupport::dump_basic_type_array_class(DumpWriter* writer, klassOop k) { | |
963 // array classes | |
964 while (k != NULL) { | |
965 Klass* klass = Klass::cast(k); | |
966 | |
967 writer->write_u1(HPROF_GC_CLASS_DUMP); | |
968 writer->write_classID(klass); | |
969 writer->write_u4(STACK_TRACE_ID); | |
970 | |
971 // super class of array classes is java.lang.Object | |
972 klassOop java_super = klass->java_super(); | |
973 assert(java_super != NULL, "checking"); | |
974 writer->write_classID(Klass::cast(java_super)); | |
975 | |
976 writer->write_objectID(NULL); // loader | |
977 writer->write_objectID(NULL); // signers | |
978 writer->write_objectID(NULL); // protection domain | |
979 | |
980 writer->write_objectID(NULL); // reserved | |
981 writer->write_objectID(NULL); | |
982 writer->write_u4(0); // instance size | |
983 writer->write_u2(0); // constant pool | |
984 writer->write_u2(0); // static fields | |
985 writer->write_u2(0); // instance fields | |
986 | |
987 // get the array class for the next rank | |
988 k = klass->array_klass_or_null(); | |
989 } | |
990 } | |
991 | |
992 // creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array | |
993 void DumperSupport::dump_object_array(DumpWriter* writer, objArrayOop array) { | |
994 | |
995 // filter this | |
996 if (array->klass() == Universe::systemObjArrayKlassObj()) return; | |
997 | |
998 writer->write_u1(HPROF_GC_OBJ_ARRAY_DUMP); | |
999 writer->write_objectID(array); | |
1000 writer->write_u4(STACK_TRACE_ID); | |
1001 writer->write_u4((u4)array->length()); | |
1002 | |
1003 // array class ID | |
1004 writer->write_classID(Klass::cast(array->klass())); | |
1005 | |
1006 // [id]* elements | |
1007 for (int index=0; index<array->length(); index++) { | |
1008 oop o = array->obj_at(index); | |
1009 writer->write_objectID(o); | |
1010 } | |
1011 } | |
1012 | |
1013 #define WRITE_ARRAY(Array, Type, Size) \ | |
1014 for (int i=0; i<Array->length(); i++) { writer->write_##Size((Size)array->Type##_at(i)); } | |
1015 | |
1016 | |
1017 // creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array | |
1018 void DumperSupport::dump_prim_array(DumpWriter* writer, typeArrayOop array) { | |
1019 BasicType type = typeArrayKlass::cast(array->klass())->element_type(); | |
1020 | |
1021 writer->write_u1(HPROF_GC_PRIM_ARRAY_DUMP); | |
1022 writer->write_objectID(array); | |
1023 writer->write_u4(STACK_TRACE_ID); | |
1024 writer->write_u4((u4)array->length()); | |
1025 writer->write_u1(type2tag(type)); | |
1026 | |
1027 // nothing to copy | |
1028 if (array->length() == 0) { | |
1029 return; | |
1030 } | |
1031 | |
1032 // If the byte ordering is big endian then we can copy most types directly | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
1033 int length_in_bytes = array->length() * type2aelembytes(type); |
0 | 1034 assert(length_in_bytes > 0, "nothing to copy"); |
1035 | |
1036 switch (type) { | |
1037 case T_INT : { | |
1038 if (Bytes::is_Java_byte_ordering_different()) { | |
1039 WRITE_ARRAY(array, int, u4); | |
1040 } else { | |
1041 writer->write_raw((void*)(array->int_at_addr(0)), length_in_bytes); | |
1042 } | |
1043 break; | |
1044 } | |
1045 case T_BYTE : { | |
1046 writer->write_raw((void*)(array->byte_at_addr(0)), length_in_bytes); | |
1047 break; | |
1048 } | |
1049 case T_CHAR : { | |
1050 if (Bytes::is_Java_byte_ordering_different()) { | |
1051 WRITE_ARRAY(array, char, u2); | |
1052 } else { | |
1053 writer->write_raw((void*)(array->char_at_addr(0)), length_in_bytes); | |
1054 } | |
1055 break; | |
1056 } | |
1057 case T_SHORT : { | |
1058 if (Bytes::is_Java_byte_ordering_different()) { | |
1059 WRITE_ARRAY(array, short, u2); | |
1060 } else { | |
1061 writer->write_raw((void*)(array->short_at_addr(0)), length_in_bytes); | |
1062 } | |
1063 break; | |
1064 } | |
1065 case T_BOOLEAN : { | |
1066 if (Bytes::is_Java_byte_ordering_different()) { | |
1067 WRITE_ARRAY(array, bool, u1); | |
1068 } else { | |
1069 writer->write_raw((void*)(array->bool_at_addr(0)), length_in_bytes); | |
1070 } | |
1071 break; | |
1072 } | |
1073 case T_LONG : { | |
1074 if (Bytes::is_Java_byte_ordering_different()) { | |
1075 WRITE_ARRAY(array, long, u8); | |
1076 } else { | |
1077 writer->write_raw((void*)(array->long_at_addr(0)), length_in_bytes); | |
1078 } | |
1079 break; | |
1080 } | |
1081 | |
1082 // handle float/doubles in a special value to ensure than NaNs are | |
1083 // written correctly. TO DO: Check if we can avoid this on processors that | |
1084 // use IEEE 754. | |
1085 | |
1086 case T_FLOAT : { | |
1087 for (int i=0; i<array->length(); i++) { | |
1088 dump_float( writer, array->float_at(i) ); | |
1089 } | |
1090 break; | |
1091 } | |
1092 case T_DOUBLE : { | |
1093 for (int i=0; i<array->length(); i++) { | |
1094 dump_double( writer, array->double_at(i) ); | |
1095 } | |
1096 break; | |
1097 } | |
1098 default : ShouldNotReachHere(); | |
1099 } | |
1100 } | |
1101 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1102 // create a HPROF_FRAME record of the given methodOop and bci |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1103 void DumperSupport::dump_stack_frame(DumpWriter* writer, |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1104 int frame_serial_num, |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1105 int class_serial_num, |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1106 methodOop m, |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1107 int bci) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1108 int line_number; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1109 if (m->is_native()) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1110 line_number = -3; // native frame |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1111 } else { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1112 line_number = m->line_number_from_bci(bci); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1113 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1114 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1115 write_header(writer, HPROF_FRAME, 4*oopSize + 2*sizeof(u4)); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1116 writer->write_id(frame_serial_num); // frame serial number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1117 writer->write_objectID(m->name()); // method's name |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1118 writer->write_objectID(m->signature()); // method's signature |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1119 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1120 assert(Klass::cast(m->method_holder())->oop_is_instance(), "not instanceKlass"); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1121 writer->write_objectID(instanceKlass::cast(m->method_holder())->source_file_name()); // source file name |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1122 writer->write_u4(class_serial_num); // class serial number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1123 writer->write_u4((u4) line_number); // line number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1124 } |
0 | 1125 |
1126 // Support class used to generate HPROF_UTF8 records from the entries in the | |
1127 // SymbolTable. | |
1128 | |
1129 class SymbolTableDumper : public OopClosure { | |
1130 private: | |
1131 DumpWriter* _writer; | |
1132 DumpWriter* writer() const { return _writer; } | |
1133 public: | |
1134 SymbolTableDumper(DumpWriter* writer) { _writer = writer; } | |
1135 void do_oop(oop* obj_p); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
1136 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
0 | 1137 }; |
1138 | |
1139 void SymbolTableDumper::do_oop(oop* obj_p) { | |
1140 ResourceMark rm; | |
1141 symbolOop sym = (symbolOop)*obj_p; | |
1142 | |
1143 int len = sym->utf8_length(); | |
1144 if (len > 0) { | |
1145 char* s = sym->as_utf8(); | |
1146 DumperSupport::write_header(writer(), HPROF_UTF8, oopSize + len); | |
1147 writer()->write_objectID(sym); | |
1148 writer()->write_raw(s, len); | |
1149 } | |
1150 } | |
1151 | |
1152 | |
1153 // Support class used to generate HPROF_GC_ROOT_JNI_LOCAL records | |
1154 | |
1155 class JNILocalsDumper : public OopClosure { | |
1156 private: | |
1157 DumpWriter* _writer; | |
1158 u4 _thread_serial_num; | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1159 int _frame_num; |
0 | 1160 DumpWriter* writer() const { return _writer; } |
1161 public: | |
1162 JNILocalsDumper(DumpWriter* writer, u4 thread_serial_num) { | |
1163 _writer = writer; | |
1164 _thread_serial_num = thread_serial_num; | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1165 _frame_num = -1; // default - empty stack |
0 | 1166 } |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1167 void set_frame_number(int n) { _frame_num = n; } |
0 | 1168 void do_oop(oop* obj_p); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
1169 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
0 | 1170 }; |
1171 | |
1172 | |
1173 void JNILocalsDumper::do_oop(oop* obj_p) { | |
1174 // ignore null or deleted handles | |
1175 oop o = *obj_p; | |
1176 if (o != NULL && o != JNIHandles::deleted_handle()) { | |
1177 writer()->write_u1(HPROF_GC_ROOT_JNI_LOCAL); | |
1178 writer()->write_objectID(o); | |
1179 writer()->write_u4(_thread_serial_num); | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1180 writer()->write_u4((u4)_frame_num); |
0 | 1181 } |
1182 } | |
1183 | |
1184 | |
1185 // Support class used to generate HPROF_GC_ROOT_JNI_GLOBAL records | |
1186 | |
1187 class JNIGlobalsDumper : public OopClosure { | |
1188 private: | |
1189 DumpWriter* _writer; | |
1190 DumpWriter* writer() const { return _writer; } | |
1191 | |
1192 public: | |
1193 JNIGlobalsDumper(DumpWriter* writer) { | |
1194 _writer = writer; | |
1195 } | |
1196 void do_oop(oop* obj_p); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
1197 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
0 | 1198 }; |
1199 | |
1200 void JNIGlobalsDumper::do_oop(oop* obj_p) { | |
1201 oop o = *obj_p; | |
1202 | |
1203 // ignore these | |
1204 if (o == NULL || o == JNIHandles::deleted_handle()) return; | |
1205 | |
1206 // we ignore global ref to symbols and other internal objects | |
1207 if (o->is_instance() || o->is_objArray() || o->is_typeArray()) { | |
1208 writer()->write_u1(HPROF_GC_ROOT_JNI_GLOBAL); | |
1209 writer()->write_objectID(o); | |
1210 writer()->write_objectID((oopDesc*)obj_p); // global ref ID | |
1211 } | |
1212 }; | |
1213 | |
1214 | |
1215 // Support class used to generate HPROF_GC_ROOT_MONITOR_USED records | |
1216 | |
1217 class MonitorUsedDumper : public OopClosure { | |
1218 private: | |
1219 DumpWriter* _writer; | |
1220 DumpWriter* writer() const { return _writer; } | |
1221 public: | |
1222 MonitorUsedDumper(DumpWriter* writer) { | |
1223 _writer = writer; | |
1224 } | |
1225 void do_oop(oop* obj_p) { | |
1226 writer()->write_u1(HPROF_GC_ROOT_MONITOR_USED); | |
1227 writer()->write_objectID(*obj_p); | |
1228 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
1229 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
0 | 1230 }; |
1231 | |
1232 | |
1233 // Support class used to generate HPROF_GC_ROOT_STICKY_CLASS records | |
1234 | |
1235 class StickyClassDumper : public OopClosure { | |
1236 private: | |
1237 DumpWriter* _writer; | |
1238 DumpWriter* writer() const { return _writer; } | |
1239 public: | |
1240 StickyClassDumper(DumpWriter* writer) { | |
1241 _writer = writer; | |
1242 } | |
1243 void do_oop(oop* obj_p); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
1244 void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); } |
0 | 1245 }; |
1246 | |
1247 void StickyClassDumper::do_oop(oop* obj_p) { | |
1248 if (*obj_p != NULL) { | |
1249 oop o = *obj_p; | |
1250 if (o->is_klass()) { | |
1251 klassOop k = klassOop(o); | |
1252 if (Klass::cast(k)->oop_is_instance()) { | |
1253 instanceKlass* ik = instanceKlass::cast(k); | |
1254 writer()->write_u1(HPROF_GC_ROOT_STICKY_CLASS); | |
1255 writer()->write_classID(ik); | |
1256 } | |
1257 } | |
1258 } | |
1259 } | |
1260 | |
1261 | |
1262 class VM_HeapDumper; | |
1263 | |
1264 // Support class using when iterating over the heap. | |
1265 | |
1266 class HeapObjectDumper : public ObjectClosure { | |
1267 private: | |
1268 VM_HeapDumper* _dumper; | |
1269 DumpWriter* _writer; | |
1270 | |
1271 VM_HeapDumper* dumper() { return _dumper; } | |
1272 DumpWriter* writer() { return _writer; } | |
1273 | |
1274 // used to indicate that a record has been writen | |
1275 void mark_end_of_record(); | |
1276 | |
1277 public: | |
1278 HeapObjectDumper(VM_HeapDumper* dumper, DumpWriter* writer) { | |
1279 _dumper = dumper; | |
1280 _writer = writer; | |
1281 } | |
1282 | |
1283 // called for each object in the heap | |
1284 void do_object(oop o); | |
1285 }; | |
1286 | |
1287 void HeapObjectDumper::do_object(oop o) { | |
1288 // hide the sentinel for deleted handles | |
1289 if (o == JNIHandles::deleted_handle()) return; | |
1290 | |
1291 // ignore KlassKlass objects | |
1292 if (o->is_klass()) return; | |
1293 | |
1294 // skip classes as these emitted as HPROF_GC_CLASS_DUMP records | |
1142 | 1295 if (o->klass() == SystemDictionary::Class_klass()) { |
0 | 1296 if (!java_lang_Class::is_primitive(o)) { |
1297 return; | |
1298 } | |
1299 } | |
1300 | |
1301 // create a HPROF_GC_INSTANCE record for each object | |
1302 if (o->is_instance()) { | |
1303 DumperSupport::dump_instance(writer(), o); | |
1304 mark_end_of_record(); | |
1305 } else { | |
1306 // create a HPROF_GC_OBJ_ARRAY_DUMP record for each object array | |
1307 if (o->is_objArray()) { | |
1308 DumperSupport::dump_object_array(writer(), objArrayOop(o)); | |
1309 mark_end_of_record(); | |
1310 } else { | |
1311 // create a HPROF_GC_PRIM_ARRAY_DUMP record for each type array | |
1312 if (o->is_typeArray()) { | |
1313 DumperSupport::dump_prim_array(writer(), typeArrayOop(o)); | |
1314 mark_end_of_record(); | |
1315 } | |
1316 } | |
1317 } | |
1318 } | |
1319 | |
1320 // The VM operation that performs the heap dump | |
1321 class VM_HeapDumper : public VM_GC_Operation { | |
1322 private: | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1323 static VM_HeapDumper* _global_dumper; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1324 static DumpWriter* _global_writer; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1325 DumpWriter* _local_writer; |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1326 JavaThread* _oome_thread; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1327 methodOop _oome_constructor; |
0 | 1328 bool _gc_before_heap_dump; |
1329 bool _is_segmented_dump; | |
1330 jlong _dump_start; | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1331 GrowableArray<Klass*>* _klass_map; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1332 ThreadStackTrace** _stack_traces; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1333 int _num_threads; |
0 | 1334 |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1335 // accessors and setters |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1336 static VM_HeapDumper* dumper() { assert(_global_dumper != NULL, "Error"); return _global_dumper; } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1337 static DumpWriter* writer() { assert(_global_writer != NULL, "Error"); return _global_writer; } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1338 void set_global_dumper() { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1339 assert(_global_dumper == NULL, "Error"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1340 _global_dumper = this; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1341 } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1342 void set_global_writer() { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1343 assert(_global_writer == NULL, "Error"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1344 _global_writer = _local_writer; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1345 } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1346 void clear_global_dumper() { _global_dumper = NULL; } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1347 void clear_global_writer() { _global_writer = NULL; } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1348 |
0 | 1349 bool is_segmented_dump() const { return _is_segmented_dump; } |
1350 void set_segmented_dump() { _is_segmented_dump = true; } | |
1351 jlong dump_start() const { return _dump_start; } | |
1352 void set_dump_start(jlong pos); | |
1353 | |
1354 bool skip_operation() const; | |
1355 | |
1356 // writes a HPROF_LOAD_CLASS record | |
1357 static void do_load_class(klassOop k); | |
1358 | |
1359 // writes a HPROF_GC_CLASS_DUMP record for the given class | |
1360 // (and each array class too) | |
1361 static void do_class_dump(klassOop k); | |
1362 | |
1363 // writes a HPROF_GC_CLASS_DUMP records for a given basic type | |
1364 // array (and each multi-dimensional array too) | |
1365 static void do_basic_type_array_class_dump(klassOop k); | |
1366 | |
1367 // HPROF_GC_ROOT_THREAD_OBJ records | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1368 int do_thread(JavaThread* thread, u4 thread_serial_num); |
0 | 1369 void do_threads(); |
1370 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1371 void add_class_serial_number(Klass* k, int serial_num) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1372 _klass_map->at_put_grow(serial_num, k); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1373 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1374 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1375 // HPROF_TRACE and HPROF_FRAME records |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1376 void dump_stack_traces(); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1377 |
0 | 1378 // writes a HPROF_HEAP_DUMP or HPROF_HEAP_DUMP_SEGMENT record |
1379 void write_dump_header(); | |
1380 | |
1381 // fixes up the length of the current dump record | |
1382 void write_current_dump_record_length(); | |
1383 | |
1384 // fixes up the current dump record )and writes HPROF_HEAP_DUMP_END | |
1385 // record in the case of a segmented heap dump) | |
1386 void end_of_dump(); | |
1387 | |
1388 public: | |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1389 VM_HeapDumper(DumpWriter* writer, bool gc_before_heap_dump, bool oome) : |
0 | 1390 VM_GC_Operation(0 /* total collections, dummy, ignored */, |
1391 0 /* total full collections, dummy, ignored */, | |
1392 gc_before_heap_dump) { | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1393 _local_writer = writer; |
0 | 1394 _gc_before_heap_dump = gc_before_heap_dump; |
1395 _is_segmented_dump = false; | |
1396 _dump_start = (jlong)-1; | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1397 _klass_map = new (ResourceObj::C_HEAP) GrowableArray<Klass*>(INITIAL_CLASS_COUNT, true); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1398 _stack_traces = NULL; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1399 _num_threads = 0; |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1400 if (oome) { |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1401 assert(!Thread::current()->is_VM_thread(), "Dump from OutOfMemoryError cannot be called by the VMThread"); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1402 // get OutOfMemoryError zero-parameter constructor |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1403 instanceKlass* oome_ik = instanceKlass::cast(SystemDictionary::OutOfMemoryError_klass()); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1404 _oome_constructor = oome_ik->find_method(vmSymbols::object_initializer_name(), |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1405 vmSymbols::void_method_signature()); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1406 // get thread throwing OOME when generating the heap dump at OOME |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1407 _oome_thread = JavaThread::current(); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1408 } else { |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1409 _oome_thread = NULL; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1410 _oome_constructor = NULL; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1411 } |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1412 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1413 ~VM_HeapDumper() { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1414 if (_stack_traces != NULL) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1415 for (int i=0; i < _num_threads; i++) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1416 delete _stack_traces[i]; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1417 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1418 FREE_C_HEAP_ARRAY(ThreadStackTrace*, _stack_traces); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1419 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1420 delete _klass_map; |
0 | 1421 } |
1422 | |
1423 VMOp_Type type() const { return VMOp_HeapDumper; } | |
1424 // used to mark sub-record boundary | |
1425 void check_segment_length(); | |
1426 void doit(); | |
1427 }; | |
1428 | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1429 VM_HeapDumper* VM_HeapDumper::_global_dumper = NULL; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1430 DumpWriter* VM_HeapDumper::_global_writer = NULL; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1431 |
0 | 1432 bool VM_HeapDumper::skip_operation() const { |
1433 return false; | |
1434 } | |
1435 | |
1436 // sets the dump starting position | |
1437 void VM_HeapDumper::set_dump_start(jlong pos) { | |
1438 _dump_start = pos; | |
1439 } | |
1440 | |
1441 // writes a HPROF_HEAP_DUMP or HPROF_HEAP_DUMP_SEGMENT record | |
1442 void VM_HeapDumper::write_dump_header() { | |
1443 if (writer()->is_open()) { | |
1444 if (is_segmented_dump()) { | |
1445 writer()->write_u1(HPROF_HEAP_DUMP_SEGMENT); | |
1446 } else { | |
1447 writer()->write_u1(HPROF_HEAP_DUMP); | |
1448 } | |
1449 writer()->write_u4(0); // current ticks | |
1450 | |
1451 // record the starting position for the dump (its length will be fixed up later) | |
1452 set_dump_start(writer()->current_offset()); | |
1453 writer()->write_u4(0); | |
1454 } | |
1455 } | |
1456 | |
1457 // fixes up the length of the current dump record | |
1458 void VM_HeapDumper::write_current_dump_record_length() { | |
1459 if (writer()->is_open()) { | |
1460 assert(dump_start() >= 0, "no dump start recorded"); | |
1461 | |
1462 // calculate the size of the dump record | |
1463 jlong dump_end = writer()->current_offset(); | |
1464 jlong dump_len = (dump_end - dump_start() - 4); | |
1465 | |
1466 // record length must fit in a u4 | |
1467 if (dump_len > (jlong)(4L*(jlong)G)) { | |
1468 warning("record is too large"); | |
1469 } | |
1470 | |
1471 // seek to the dump start and fix-up the length | |
1472 writer()->seek_to_offset(dump_start()); | |
1473 writer()->write_u4((u4)dump_len); | |
1474 | |
1475 // adjust the total size written to keep the bytes written correct. | |
1476 writer()->adjust_bytes_written(-((long) sizeof(u4))); | |
1477 | |
1478 // seek to dump end so we can continue | |
1479 writer()->seek_to_offset(dump_end); | |
1480 | |
1481 // no current dump record | |
1482 set_dump_start((jlong)-1); | |
1483 } | |
1484 } | |
1485 | |
1486 // used on a sub-record boundary to check if we need to start a | |
1487 // new segment. | |
1488 void VM_HeapDumper::check_segment_length() { | |
1489 if (writer()->is_open()) { | |
1490 if (is_segmented_dump()) { | |
1491 // don't use current_offset that would be too expensive on a per record basis | |
1492 jlong dump_end = writer()->bytes_written() + writer()->bytes_unwritten(); | |
1493 assert(dump_end == writer()->current_offset(), "checking"); | |
1494 jlong dump_len = (dump_end - dump_start() - 4); | |
1495 assert(dump_len >= 0 && dump_len <= max_juint, "bad dump length"); | |
1496 | |
1497 if (dump_len > (jlong)HeapDumpSegmentSize) { | |
1498 write_current_dump_record_length(); | |
1499 write_dump_header(); | |
1500 } | |
1501 } | |
1502 } | |
1503 } | |
1504 | |
1505 // fixes up the current dump record )and writes HPROF_HEAP_DUMP_END | |
1506 // record in the case of a segmented heap dump) | |
1507 void VM_HeapDumper::end_of_dump() { | |
1508 if (writer()->is_open()) { | |
1509 write_current_dump_record_length(); | |
1510 | |
1511 // for segmented dump we write the end record | |
1512 if (is_segmented_dump()) { | |
1513 writer()->write_u1(HPROF_HEAP_DUMP_END); | |
1514 writer()->write_u4(0); | |
1515 writer()->write_u4(0); | |
1516 } | |
1517 } | |
1518 } | |
1519 | |
1520 // marks sub-record boundary | |
1521 void HeapObjectDumper::mark_end_of_record() { | |
1522 dumper()->check_segment_length(); | |
1523 } | |
1524 | |
1525 // writes a HPROF_LOAD_CLASS record for the class (and each of its | |
1526 // array classes) | |
1527 void VM_HeapDumper::do_load_class(klassOop k) { | |
1528 static u4 class_serial_num = 0; | |
1529 | |
1530 // len of HPROF_LOAD_CLASS record | |
1531 u4 remaining = 2*oopSize + 2*sizeof(u4); | |
1532 | |
1533 // write a HPROF_LOAD_CLASS for the class and each array class | |
1534 do { | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1535 DumperSupport::write_header(writer(), HPROF_LOAD_CLASS, remaining); |
0 | 1536 |
1537 // class serial number is just a number | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1538 writer()->write_u4(++class_serial_num); |
0 | 1539 |
1540 // class ID | |
1541 Klass* klass = Klass::cast(k); | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1542 writer()->write_classID(klass); |
0 | 1543 |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1544 // add the klassOop and class serial number pair |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1545 dumper()->add_class_serial_number(klass, class_serial_num); |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1546 |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1547 writer()->write_u4(STACK_TRACE_ID); |
0 | 1548 |
1549 // class name ID | |
1550 symbolOop name = klass->name(); | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1551 writer()->write_objectID(name); |
0 | 1552 |
1553 // write a LOAD_CLASS record for the array type (if it exists) | |
1554 k = klass->array_klass_or_null(); | |
1555 } while (k != NULL); | |
1556 } | |
1557 | |
1558 // writes a HPROF_GC_CLASS_DUMP record for the given class | |
1559 void VM_HeapDumper::do_class_dump(klassOop k) { | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1560 DumperSupport::dump_class_and_array_classes(writer(), k); |
0 | 1561 } |
1562 | |
1563 // writes a HPROF_GC_CLASS_DUMP records for a given basic type | |
1564 // array (and each multi-dimensional array too) | |
1565 void VM_HeapDumper::do_basic_type_array_class_dump(klassOop k) { | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1566 DumperSupport::dump_basic_type_array_class(writer(), k); |
0 | 1567 } |
1568 | |
1569 // Walk the stack of the given thread. | |
1570 // Dumps a HPROF_GC_ROOT_JAVA_FRAME record for each local | |
1571 // Dumps a HPROF_GC_ROOT_JNI_LOCAL record for each JNI local | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1572 // |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1573 // It returns the number of Java frames in this thread stack |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1574 int VM_HeapDumper::do_thread(JavaThread* java_thread, u4 thread_serial_num) { |
0 | 1575 JNILocalsDumper blk(writer(), thread_serial_num); |
1576 | |
1577 oop threadObj = java_thread->threadObj(); | |
1578 assert(threadObj != NULL, "sanity check"); | |
1579 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1580 int stack_depth = 0; |
0 | 1581 if (java_thread->has_last_Java_frame()) { |
1582 | |
1583 // vframes are resource allocated | |
1584 Thread* current_thread = Thread::current(); | |
1585 ResourceMark rm(current_thread); | |
1586 HandleMark hm(current_thread); | |
1587 | |
1588 RegisterMap reg_map(java_thread); | |
1589 frame f = java_thread->last_frame(); | |
1590 vframe* vf = vframe::new_vframe(&f, ®_map, java_thread); | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1591 frame* last_entry_frame = NULL; |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1592 int extra_frames = 0; |
0 | 1593 |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1594 if (java_thread == _oome_thread && _oome_constructor != NULL) { |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1595 extra_frames++; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1596 } |
0 | 1597 while (vf != NULL) { |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1598 blk.set_frame_number(stack_depth); |
0 | 1599 if (vf->is_java_frame()) { |
1600 | |
1601 // java frame (interpreted, compiled, ...) | |
1602 javaVFrame *jvf = javaVFrame::cast(vf); | |
1603 if (!(jvf->method()->is_native())) { | |
1604 StackValueCollection* locals = jvf->locals(); | |
1605 for (int slot=0; slot<locals->size(); slot++) { | |
1606 if (locals->at(slot)->type() == T_OBJECT) { | |
1607 oop o = locals->obj_at(slot)(); | |
1608 | |
1609 if (o != NULL) { | |
1610 writer()->write_u1(HPROF_GC_ROOT_JAVA_FRAME); | |
1611 writer()->write_objectID(o); | |
1612 writer()->write_u4(thread_serial_num); | |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1613 writer()->write_u4((u4) (stack_depth + extra_frames)); |
0 | 1614 } |
1615 } | |
1616 } | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1617 } else { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1618 // native frame |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1619 if (stack_depth == 0) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1620 // JNI locals for the top frame. |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1621 java_thread->active_handles()->oops_do(&blk); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1622 } else { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1623 if (last_entry_frame != NULL) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1624 // JNI locals for the entry frame |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1625 assert(last_entry_frame->is_entry_frame(), "checking"); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1626 last_entry_frame->entry_frame_call_wrapper()->handles()->oops_do(&blk); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1627 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1628 } |
0 | 1629 } |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1630 // increment only for Java frames |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1631 stack_depth++; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1632 last_entry_frame = NULL; |
0 | 1633 |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1634 } else { |
0 | 1635 // externalVFrame - if it's an entry frame then report any JNI locals |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1636 // as roots when we find the corresponding native javaVFrame |
0 | 1637 frame* fr = vf->frame_pointer(); |
1638 assert(fr != NULL, "sanity check"); | |
1639 if (fr->is_entry_frame()) { | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1640 last_entry_frame = fr; |
0 | 1641 } |
1642 } | |
1643 vf = vf->sender(); | |
1644 } | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1645 } else { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1646 // no last java frame but there may be JNI locals |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1647 java_thread->active_handles()->oops_do(&blk); |
0 | 1648 } |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1649 return stack_depth; |
0 | 1650 } |
1651 | |
1652 | |
1653 // write a HPROF_GC_ROOT_THREAD_OBJ record for each java thread. Then walk | |
1654 // the stack so that locals and JNI locals are dumped. | |
1655 void VM_HeapDumper::do_threads() { | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1656 for (int i=0; i < _num_threads; i++) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1657 JavaThread* thread = _stack_traces[i]->thread(); |
0 | 1658 oop threadObj = thread->threadObj(); |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1659 u4 thread_serial_num = i+1; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1660 u4 stack_serial_num = thread_serial_num + STACK_TRACE_ID; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1661 writer()->write_u1(HPROF_GC_ROOT_THREAD_OBJ); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1662 writer()->write_objectID(threadObj); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1663 writer()->write_u4(thread_serial_num); // thread number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1664 writer()->write_u4(stack_serial_num); // stack trace serial number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1665 int num_frames = do_thread(thread, thread_serial_num); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1666 assert(num_frames == _stack_traces[i]->get_stack_depth(), |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1667 "total number of Java frames not matched"); |
0 | 1668 } |
1669 } | |
1670 | |
1671 | |
1672 // The VM operation that dumps the heap. The dump consists of the following | |
1673 // records: | |
1674 // | |
1675 // HPROF_HEADER | |
1676 // [HPROF_UTF8]* | |
1677 // [HPROF_LOAD_CLASS]* | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1678 // [[HPROF_FRAME]*|HPROF_TRACE]* |
0 | 1679 // [HPROF_GC_CLASS_DUMP]* |
1680 // HPROF_HEAP_DUMP | |
1681 // | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1682 // The HPROF_TRACE records represent the stack traces where the heap dump |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1683 // is generated and a "dummy trace" record which does not include |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1684 // any frames. The dummy trace record is used to be referenced as the |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1685 // unknown object alloc site. |
0 | 1686 // |
1687 // The HPROF_HEAP_DUMP record has a length following by sub-records. To allow | |
1688 // the heap dump be generated in a single pass we remember the position of | |
1689 // the dump length and fix it up after all sub-records have been written. | |
1690 // To generate the sub-records we iterate over the heap, writing | |
1691 // HPROF_GC_INSTANCE_DUMP, HPROF_GC_OBJ_ARRAY_DUMP, and HPROF_GC_PRIM_ARRAY_DUMP | |
1692 // records as we go. Once that is done we write records for some of the GC | |
1693 // roots. | |
1694 | |
1695 void VM_HeapDumper::doit() { | |
1696 | |
1697 HandleMark hm; | |
1698 CollectedHeap* ch = Universe::heap(); | |
1699 if (_gc_before_heap_dump) { | |
1700 ch->collect_as_vm_thread(GCCause::_heap_dump); | |
1701 } else { | |
1702 // make the heap parsable (no need to retire TLABs) | |
1703 ch->ensure_parsability(false); | |
1704 } | |
1705 | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1706 // At this point we should be the only dumper active, so |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1707 // the following should be safe. |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1708 set_global_dumper(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1709 set_global_writer(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1710 |
0 | 1711 // Write the file header - use 1.0.2 for large heaps, otherwise 1.0.1 |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1712 size_t used = ch->used(); |
0 | 1713 const char* header; |
1714 if (used > (size_t)SegmentedHeapDumpThreshold) { | |
1715 set_segmented_dump(); | |
1716 header = "JAVA PROFILE 1.0.2"; | |
1717 } else { | |
1718 header = "JAVA PROFILE 1.0.1"; | |
1719 } | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1720 |
0 | 1721 // header is few bytes long - no chance to overflow int |
1722 writer()->write_raw((void*)header, (int)strlen(header)); | |
1723 writer()->write_u1(0); // terminator | |
1724 writer()->write_u4(oopSize); | |
1725 writer()->write_u8(os::javaTimeMillis()); | |
1726 | |
1727 // HPROF_UTF8 records | |
1728 SymbolTableDumper sym_dumper(writer()); | |
1729 SymbolTable::oops_do(&sym_dumper); | |
1730 | |
1731 // write HPROF_LOAD_CLASS records | |
1732 SystemDictionary::classes_do(&do_load_class); | |
1733 Universe::basic_type_classes_do(&do_load_class); | |
1734 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1735 // write HPROF_FRAME and HPROF_TRACE records |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1736 // this must be called after _klass_map is built when iterating the classes above. |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1737 dump_stack_traces(); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1738 |
0 | 1739 // write HPROF_HEAP_DUMP or HPROF_HEAP_DUMP_SEGMENT |
1740 write_dump_header(); | |
1741 | |
1742 // Writes HPROF_GC_CLASS_DUMP records | |
1743 SystemDictionary::classes_do(&do_class_dump); | |
1744 Universe::basic_type_classes_do(&do_basic_type_array_class_dump); | |
1745 check_segment_length(); | |
1746 | |
1747 // writes HPROF_GC_INSTANCE_DUMP records. | |
1748 // After each sub-record is written check_segment_length will be invoked. When | |
1749 // generated a segmented heap dump this allows us to check if the current | |
1750 // segment exceeds a threshold and if so, then a new segment is started. | |
1751 // The HPROF_GC_CLASS_DUMP and HPROF_GC_INSTANCE_DUMP are the vast bulk | |
1752 // of the heap dump. | |
1753 HeapObjectDumper obj_dumper(this, writer()); | |
517
e9be0e04635a
6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents:
396
diff
changeset
|
1754 Universe::heap()->safe_object_iterate(&obj_dumper); |
0 | 1755 |
1756 // HPROF_GC_ROOT_THREAD_OBJ + frames + jni locals | |
1757 do_threads(); | |
1758 check_segment_length(); | |
1759 | |
1760 // HPROF_GC_ROOT_MONITOR_USED | |
1761 MonitorUsedDumper mon_dumper(writer()); | |
1762 ObjectSynchronizer::oops_do(&mon_dumper); | |
1763 check_segment_length(); | |
1764 | |
1765 // HPROF_GC_ROOT_JNI_GLOBAL | |
1766 JNIGlobalsDumper jni_dumper(writer()); | |
1767 JNIHandles::oops_do(&jni_dumper); | |
1768 check_segment_length(); | |
1769 | |
1770 // HPROF_GC_ROOT_STICKY_CLASS | |
1771 StickyClassDumper class_dumper(writer()); | |
1772 SystemDictionary::always_strong_oops_do(&class_dumper); | |
1773 | |
1774 // fixes up the length of the dump record. In the case of a segmented | |
1775 // heap then the HPROF_HEAP_DUMP_END record is also written. | |
1776 end_of_dump(); | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1777 |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1778 // Now we clear the global variables, so that a future dumper might run. |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1779 clear_global_dumper(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1780 clear_global_writer(); |
0 | 1781 } |
1782 | |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1783 void VM_HeapDumper::dump_stack_traces() { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1784 // write a HPROF_TRACE record without any frames to be referenced as object alloc sites |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1785 DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4)); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1786 writer()->write_u4((u4) STACK_TRACE_ID); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1787 writer()->write_u4(0); // thread number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1788 writer()->write_u4(0); // frame count |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1789 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1790 _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads()); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1791 int frame_serial_num = 0; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1792 for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1793 oop threadObj = thread->threadObj(); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1794 if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1795 // dump thread stack trace |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1796 ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1797 stack_trace->dump_stack_at_safepoint(-1); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1798 _stack_traces[_num_threads++] = stack_trace; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1799 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1800 // write HPROF_FRAME records for this thread's stack trace |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1801 int depth = stack_trace->get_stack_depth(); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1802 int thread_frame_start = frame_serial_num; |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1803 int extra_frames = 0; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1804 // write fake frame that makes it look like the thread, which caused OOME, |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1805 // is in the OutOfMemoryError zero-parameter constructor |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1806 if (thread == _oome_thread && _oome_constructor != NULL) { |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1807 int oome_serial_num = _klass_map->find(Klass::cast(_oome_constructor->method_holder())); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1808 // the class serial number starts from 1 |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1809 assert(oome_serial_num > 0, "OutOfMemoryError class not found"); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1810 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num, |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1811 _oome_constructor, 0); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1812 extra_frames++; |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1813 } |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1814 for (int j=0; j < depth; j++) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1815 StackFrameInfo* frame = stack_trace->stack_frame_at(j); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1816 methodOop m = frame->method(); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1817 int class_serial_num = _klass_map->find(Klass::cast(m->method_holder())); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1818 // the class serial number starts from 1 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1819 assert(class_serial_num > 0, "class not found"); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1820 DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, class_serial_num, m, frame->bci()); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1821 } |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1822 depth += extra_frames; |
396
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1823 |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1824 // write HPROF_TRACE record for one thread |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1825 DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4) + depth*oopSize); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1826 int stack_serial_num = _num_threads + STACK_TRACE_ID; |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1827 writer()->write_u4(stack_serial_num); // stack trace serial number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1828 writer()->write_u4((u4) _num_threads); // thread serial number |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1829 writer()->write_u4(depth); // frame count |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1830 for (int j=1; j <= depth; j++) { |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1831 writer()->write_id(thread_frame_start + j); |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1832 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1833 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1834 } |
4d05b7cb7842
6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents:
356
diff
changeset
|
1835 } |
0 | 1836 |
1837 // dump the heap to given path. | |
1838 int HeapDumper::dump(const char* path) { | |
1839 assert(path != NULL && strlen(path) > 0, "path missing"); | |
1840 | |
1841 // print message in interactive case | |
1842 if (print_to_tty()) { | |
1843 tty->print_cr("Dumping heap to %s ...", path); | |
1844 timer()->start(); | |
1845 } | |
1846 | |
1847 // create the dump writer. If the file can be opened then bail | |
1848 DumpWriter writer(path); | |
1849 if (!writer.is_open()) { | |
1850 set_error(writer.error()); | |
1851 if (print_to_tty()) { | |
1852 tty->print_cr("Unable to create %s: %s", path, | |
1853 (error() != NULL) ? error() : "reason unknown"); | |
1854 } | |
1855 return -1; | |
1856 } | |
1857 | |
1858 // generate the dump | |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1859 VM_HeapDumper dumper(&writer, _gc_before_heap_dump, _oome); |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1860 if (Thread::current()->is_VM_thread()) { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1861 assert(SafepointSynchronize::is_at_safepoint(), "Expected to be called at a safepoint"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1862 dumper.doit(); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1863 } else { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1864 VMThread::execute(&dumper); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1865 } |
0 | 1866 |
1867 // close dump file and record any error that the writer may have encountered | |
1868 writer.close(); | |
1869 set_error(writer.error()); | |
1870 | |
1871 // print message in interactive case | |
1872 if (print_to_tty()) { | |
1873 timer()->stop(); | |
1874 if (error() == NULL) { | |
1875 char msg[256]; | |
1876 sprintf(msg, "Heap dump file created [%s bytes in %3.3f secs]", | |
1877 os::jlong_format_specifier(), timer()->seconds()); | |
1878 tty->print_cr(msg, writer.bytes_written()); | |
1879 } else { | |
1880 tty->print_cr("Dump file is incomplete: %s", writer.error()); | |
1881 } | |
1882 } | |
1883 | |
1884 return (writer.error() == NULL) ? 0 : -1; | |
1885 } | |
1886 | |
1887 // stop timer (if still active), and free any error string we might be holding | |
1888 HeapDumper::~HeapDumper() { | |
1889 if (timer()->is_active()) { | |
1890 timer()->stop(); | |
1891 } | |
1892 set_error(NULL); | |
1893 } | |
1894 | |
1895 | |
1896 // returns the error string (resource allocated), or NULL | |
1897 char* HeapDumper::error_as_C_string() const { | |
1898 if (error() != NULL) { | |
1899 char* str = NEW_RESOURCE_ARRAY(char, strlen(error())+1); | |
1900 strcpy(str, error()); | |
1901 return str; | |
1902 } else { | |
1903 return NULL; | |
1904 } | |
1905 } | |
1906 | |
1907 // set the error string | |
1908 void HeapDumper::set_error(char* error) { | |
1909 if (_error != NULL) { | |
1910 os::free(_error); | |
1911 } | |
1912 if (error == NULL) { | |
1913 _error = NULL; | |
1914 } else { | |
1915 _error = os::strdup(error); | |
1916 assert(_error != NULL, "allocation failure"); | |
1917 } | |
1918 } | |
1919 | |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1920 // Called by out-of-memory error reporting by a single Java thread |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1921 // outside of a JVM safepoint |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1922 void HeapDumper::dump_heap_from_oome() { |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1923 HeapDumper::dump_heap(true); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1924 } |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1925 |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1926 // Called by error reporting by a single Java thread outside of a JVM safepoint, |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1927 // or by heap dumping by the VM thread during a (GC) safepoint. Thus, these various |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1928 // callers are strictly serialized and guaranteed not to interfere below. For more |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1929 // general use, however, this method will need modification to prevent |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1930 // inteference when updating the static variables base_path and dump_file_seq below. |
0 | 1931 void HeapDumper::dump_heap() { |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1932 HeapDumper::dump_heap(false); |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1933 } |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1934 |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1935 void HeapDumper::dump_heap(bool oome) { |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1936 static char base_path[JVM_MAXPATHLEN] = {'\0'}; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1937 static uint dump_file_seq = 0; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1938 char my_path[JVM_MAXPATHLEN] = {'\0'}; |
0 | 1939 |
1940 // The dump file defaults to java_pid<pid>.hprof in the current working | |
1941 // directory. HeapDumpPath=<file> can be used to specify an alternative | |
1942 // dump file name or a directory where dump file is created. | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1943 if (dump_file_seq == 0) { // first time in, we initialize base_path |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1944 bool use_default_filename = true; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1945 if (HeapDumpPath == NULL || HeapDumpPath[0] == '\0') { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1946 // HeapDumpPath=<file> not specified |
0 | 1947 } else { |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1948 assert(strlen(HeapDumpPath) < sizeof(base_path), "HeapDumpPath too long"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1949 strcpy(base_path, HeapDumpPath); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1950 // check if the path is a directory (must exist) |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1951 DIR* dir = os::opendir(base_path); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1952 if (dir == NULL) { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1953 use_default_filename = false; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1954 } else { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1955 // HeapDumpPath specified a directory. We append a file separator |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1956 // (if needed). |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1957 os::closedir(dir); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1958 size_t fs_len = strlen(os::file_separator()); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1959 if (strlen(base_path) >= fs_len) { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1960 char* end = base_path; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1961 end += (strlen(base_path) - fs_len); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1962 if (strcmp(end, os::file_separator()) != 0) { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1963 assert(strlen(base_path) + strlen(os::file_separator()) < sizeof(base_path), |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1964 "HeapDumpPath too long"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1965 strcat(base_path, os::file_separator()); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1966 } |
0 | 1967 } |
1968 } | |
1969 } | |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1970 // If HeapDumpPath wasn't a file name then we append the default name |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1971 if (use_default_filename) { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1972 char fn[32]; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1973 sprintf(fn, "java_pid%d", os::current_process_id()); |
1046 | 1974 assert(strlen(base_path) + strlen(fn) + strlen(".hprof") < sizeof(base_path), "HeapDumpPath too long"); |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1975 strcat(base_path, fn); |
1046 | 1976 strcat(base_path, ".hprof"); |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1977 } |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1978 assert(strlen(base_path) < sizeof(my_path), "Buffer too small"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1979 strcpy(my_path, base_path); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1980 } else { |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1981 // Append a sequence number id for dumps following the first |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1982 char fn[33]; |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1983 sprintf(fn, ".%d", dump_file_seq); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1984 assert(strlen(base_path) + strlen(fn) < sizeof(my_path), "HeapDumpPath too long"); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1985 strcpy(my_path, base_path); |
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1986 strcat(my_path, fn); |
0 | 1987 } |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1988 dump_file_seq++; // increment seq number for next time we dump |
0 | 1989 |
1990 HeapDumper dumper(false /* no GC before heap dump */, | |
1775
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1991 true /* send to tty */, |
30f67acf635d
6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents:
1552
diff
changeset
|
1992 oome /* pass along out-of-memory-error flag */); |
615
c6c601a0f2d6
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
517
diff
changeset
|
1993 dumper.dump(my_path); |
0 | 1994 } |