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