1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * - Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * - Neither the name of Oracle nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef HPROF_B_SPEC_H 33 #define HPROF_B_SPEC_H 34 35 /* Hprof binary format enums and spec. */ 36 37 /* Need to #define or typedef HprofId before including this file. 38 * hprof used ObjectIndex or 4 bytes, but it can be 4 or 8 byte type. 39 */ 40 41 /* -------------------------------------------------------------------- */ 42 /* -------------------------------------------------------------------- */ 43 /* -------------------------------------------------------------------- */ 44 45 /* 46 * hprof binary format: (result either written to a file or sent over 47 * the network). 48 * 49 * WARNING: This format is still under development, and is subject to 50 * change without notice. 51 * 52 * header "JAVA PROFILE 1.0.1" or "JAVA PROFILE 1.0.2" (0-terminated) 53 * u4 size of identifiers. Identifiers are used to represent 54 * UTF8 strings, objects, stack traces, etc. They usually 55 * have the same size as host pointers. For example, on 56 * Solaris and Win32, the size is 4. 57 * u4 high word 58 * u4 low word number of milliseconds since 0:00 GMT, 1/1/70 59 * [record]* a sequence of records. 60 */ 61 62 /* 63 * Record format: 64 * 65 * u1 a TAG denoting the type of the record 66 * u4 number of *microseconds* since the time stamp in the 67 * header. (wraps around in a little more than an hour) 68 * u4 number of bytes *remaining* in the record. Note that 69 * this number excludes the tag and the length field itself. 70 * [u1]* BODY of the record (a sequence of bytes) 71 */ 72 73 /* 74 * The following TAGs are supported: 75 * 76 * TAG BODY notes 77 *---------------------------------------------------------- 78 * HPROF_UTF8 a UTF8-encoded name 79 * 80 * id name ID 81 * [u1]* UTF8 characters (no trailing zero) 82 * 83 * HPROF_LOAD_CLASS a newly loaded class 84 * 85 * u4 class serial number (> 0) 86 * id class object ID 87 * u4 stack trace serial number 88 * id class name ID 89 * 90 * HPROF_UNLOAD_CLASS an unloading class 91 * 92 * u4 class serial_number 93 * 94 * HPROF_FRAME a Java stack frame 95 * 96 * id stack frame ID 97 * id method name ID 98 * id method signature ID 99 * id source file name ID 100 * u4 class serial number 101 * i4 line number. >0: normal 102 * -1: unknown 103 * -2: compiled method 104 * -3: native method 105 * 106 * HPROF_TRACE a Java stack trace 107 * 108 * u4 stack trace serial number 109 * u4 thread serial number 110 * u4 number of frames 111 * [id]* stack frame IDs 112 * 113 * 114 * HPROF_ALLOC_SITES a set of heap allocation sites, obtained after GC 115 * 116 * u2 flags 0x0001: incremental vs. complete 117 * 0x0002: sorted by allocation vs. live 118 * 0x0004: whether to force a GC 119 * u4 cutoff ratio 120 * u4 total live bytes 121 * u4 total live instances 122 * u8 total bytes allocated 123 * u8 total instances allocated 124 * u4 number of sites that follow 125 * [u1 is_array: 0: normal object 126 * 2: object array 127 * 4: boolean array 128 * 5: char array 129 * 6: float array 130 * 7: double array 131 * 8: byte array 132 * 9: short array 133 * 10: int array 134 * 11: long array 135 * u4 class serial number (may be zero during startup) 136 * u4 stack trace serial number 137 * u4 number of bytes alive 138 * u4 number of instances alive 139 * u4 number of bytes allocated 140 * u4]* number of instance allocated 141 * 142 * HPROF_START_THREAD a newly started thread. 143 * 144 * u4 thread serial number (> 0) 145 * id thread object ID 146 * u4 stack trace serial number 147 * id thread name ID 148 * id thread group name ID 149 * id thread group parent name ID 150 * 151 * HPROF_END_THREAD a terminating thread. 152 * 153 * u4 thread serial number 154 * 155 * HPROF_HEAP_SUMMARY heap summary 156 * 157 * u4 total live bytes 158 * u4 total live instances 159 * u8 total bytes allocated 160 * u8 total instances allocated 161 * 162 * HPROF_HEAP_DUMP or HPROF_HEAP_DUMP_SEGMENT denote a heap dump 163 * 164 * [heap dump sub-records]* 165 * 166 * There are four kinds of heap dump sub-records: 167 * 168 * u1 sub-record type 169 * 170 * HPROF_GC_ROOT_UNKNOWN unknown root 171 * 172 * id object ID 173 * 174 * HPROF_GC_ROOT_THREAD_OBJ thread object 175 * 176 * id thread object ID (may be 0 for a 177 * thread newly attached through JNI) 178 * u4 thread sequence number 179 * u4 stack trace sequence number 180 * 181 * HPROF_GC_ROOT_JNI_GLOBAL JNI global ref root 182 * 183 * id object ID 184 * id JNI global ref ID 185 * 186 * HPROF_GC_ROOT_JNI_LOCAL JNI local ref 187 * 188 * id object ID 189 * u4 thread serial number 190 * u4 frame # in stack trace (-1 for empty) 191 * 192 * HPROF_GC_ROOT_JAVA_FRAME Java stack frame 193 * 194 * id object ID 195 * u4 thread serial number 196 * u4 frame # in stack trace (-1 for empty) 197 * 198 * HPROF_GC_ROOT_NATIVE_STACK Native stack 199 * 200 * id object ID 201 * u4 thread serial number 202 * 203 * HPROF_GC_ROOT_STICKY_CLASS System class 204 * 205 * id object ID 206 * 207 * HPROF_GC_ROOT_THREAD_BLOCK Reference from thread block 208 * 209 * id object ID 210 * u4 thread serial number 211 * 212 * HPROF_GC_ROOT_MONITOR_USED Busy monitor 213 * 214 * id object ID 215 * 216 * HPROF_GC_CLASS_DUMP dump of a class object 217 * 218 * id class object ID 219 * u4 stack trace serial number 220 * id super class object ID 221 * id class loader object ID 222 * id signers object ID 223 * id protection domain object ID 224 * id reserved 225 * id reserved 226 * 227 * u4 instance size (in bytes) 228 * 229 * u2 size of constant pool 230 * [u2, constant pool index, 231 * ty, type 232 * 2: object 233 * 4: boolean 234 * 5: char 235 * 6: float 236 * 7: double 237 * 8: byte 238 * 9: short 239 * 10: int 240 * 11: long 241 * vl]* and value 242 * 243 * u2 number of static fields 244 * [id, static field name, 245 * ty, type, 246 * vl]* and value 247 * 248 * u2 number of inst. fields (not inc. super) 249 * [id, instance field name, 250 * ty]* type 251 * 252 * HPROF_GC_INSTANCE_DUMP dump of a normal object 253 * 254 * id object ID 255 * u4 stack trace serial number 256 * id class object ID 257 * u4 number of bytes that follow 258 * [vl]* instance field values (class, followed 259 * by super, super's super ...) 260 * 261 * HPROF_GC_OBJ_ARRAY_DUMP dump of an object array 262 * 263 * id array object ID 264 * u4 stack trace serial number 265 * u4 number of elements 266 * id array class ID 267 * [id]* elements 268 * 269 * HPROF_GC_PRIM_ARRAY_DUMP dump of a primitive array 270 * 271 * id array object ID 272 * u4 stack trace serial number 273 * u4 number of elements 274 * u1 element type 275 * 4: boolean array 276 * 5: char array 277 * 6: float array 278 * 7: double array 279 * 8: byte array 280 * 9: short array 281 * 10: int array 282 * 11: long array 283 * [u1]* elements 284 * 285 * HPROF_HEAP_DUMP_END terminates series of heap dump segments 286 * 287 * HPROF_CPU_SAMPLES a set of sample traces of running threads 288 * 289 * u4 total number of samples 290 * u4 # of traces 291 * [u4 # of samples 292 * u4]* stack trace serial number 293 * 294 * HPROF_CONTROL_SETTINGS the settings of on/off switches 295 * 296 * u4 0x00000001: alloc traces on/off 297 * 0x00000002: cpu sampling on/off 298 * u2 stack trace depth 299 * 300 */ 301 302 typedef enum HprofTag { 303 HPROF_UTF8 = 0x01, 304 HPROF_LOAD_CLASS = 0x02, 305 HPROF_UNLOAD_CLASS = 0x03, 306 HPROF_FRAME = 0x04, 307 HPROF_TRACE = 0x05, 308 HPROF_ALLOC_SITES = 0x06, 309 HPROF_HEAP_SUMMARY = 0x07, 310 HPROF_START_THREAD = 0x0A, 311 HPROF_END_THREAD = 0x0B, 312 HPROF_HEAP_DUMP = 0x0C, 313 HPROF_HEAP_DUMP_SEGMENT = 0x1C, /* 1.0.2 only */ 314 HPROF_HEAP_DUMP_END = 0x2C, /* 1.0.2 only */ 315 HPROF_CPU_SAMPLES = 0x0D, 316 HPROF_CONTROL_SETTINGS = 0x0E 317 } HprofTag; 318 319 /* 320 * Heap dump constants 321 */ 322 323 typedef enum HprofGcTag { 324 HPROF_GC_ROOT_UNKNOWN = 0xFF, 325 HPROF_GC_ROOT_JNI_GLOBAL = 0x01, 326 HPROF_GC_ROOT_JNI_LOCAL = 0x02, 327 HPROF_GC_ROOT_JAVA_FRAME = 0x03, 328 HPROF_GC_ROOT_NATIVE_STACK = 0x04, 329 HPROF_GC_ROOT_STICKY_CLASS = 0x05, 330 HPROF_GC_ROOT_THREAD_BLOCK = 0x06, 331 HPROF_GC_ROOT_MONITOR_USED = 0x07, 332 HPROF_GC_ROOT_THREAD_OBJ = 0x08, 333 HPROF_GC_CLASS_DUMP = 0x20, 334 HPROF_GC_INSTANCE_DUMP = 0x21, 335 HPROF_GC_OBJ_ARRAY_DUMP = 0x22, 336 HPROF_GC_PRIM_ARRAY_DUMP = 0x23 337 } HprofGcTag; 338 339 enum HprofType { 340 HPROF_ARRAY_OBJECT = 1, 341 HPROF_NORMAL_OBJECT = 2, 342 HPROF_BOOLEAN = 4, 343 HPROF_CHAR = 5, 344 HPROF_FLOAT = 6, 345 HPROF_DOUBLE = 7, 346 HPROF_BYTE = 8, 347 HPROF_SHORT = 9, 348 HPROF_INT = 10, 349 HPROF_LONG = 11 350 }; 351 typedef unsigned char HprofType; 352 353 #define HPROF_TYPE_SIZES \ 354 { \ 355 /*Object?*/ sizeof(HprofId), \ 356 /*Object?*/ sizeof(HprofId), \ 357 /*Array*/ sizeof(HprofId), \ 358 /*Object?*/ sizeof(HprofId), \ 359 /*jboolean*/ 1, \ 360 /*jchar*/ 2, \ 361 /*jfloat*/ 4, \ 362 /*jdouble*/ 8, \ 363 /*jbyte*/ 1, \ 364 /*jshort*/ 2, \ 365 /*jint*/ 4, \ 366 /*jlong*/ 8 \ 367 } 368 369 #define HPROF_TYPE_IS_PRIMITIVE(ty) ((ty)>=HPROF_BOOLEAN) 370 371 #endif