annotate agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java @ 17524:89152779163c

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