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