Skip to content

Latest commit

 

History

History
508 lines (432 loc) · 8.84 KB

File metadata and controls

508 lines (432 loc) · 8.84 KB

BMD File Format Reference

1. Design goals

  • Can be written sequentially without the need to keep records in memory.

  • Optimized for writing (not reading, as that can be done on a PC with more resources).

  • Flat structure, no more nested records like in HPROF.

  • Records allowed to be written in any order (no need to define strings before referencing them).

2. Optimizations

  • Remapping of ids (starting at 0 for more efficient storage)

  • Use varints (variable length integers) for all int/long fields

3. File format

The BMD file format is defined as one single header followed by any number of records. The ordering of these records is not defined and any order should be accepted by an application reading it. Although this might require additional passes when reading a file it also means that a BMD file can be created without the need to keep a large portion of the memory dump in RAM so that dependencies can be resolved before writing the output

.

3.1 Header

varint32 Version
varint32 Length of metadata
byte[] Metadata (can be used to store any arbitrary data related to the dump).

3.2 Records

The header is followed by a number of records, each one of them starting with a varint32 identifying the record type (also known as the tag).

3.2.1 String

varint32 Tag (value = 1)
varint32 String id (unique identifier for this string, ids can overlap with object ids).
varint32 Length of string data in bytes
byte[] String data (string as bytes, assumed to be UTF-8 encoded)

Example:

01 9803 17 6a6176612e6c616e672e7265662e5265666572656e6365
Tag String id (408) Data length (23) Data ("java.lang.ref.Reference")

3.2.2 Hashed string

varintt32 Tag (value = 2)
varint32 String id
varint32 String data length in bytes
varint32 String hashcode (calculated using String.hashCode())

Example:

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

02 76 24 9a81ec9a01
Tag (2) String id (118) Length (36) Hash (324731034)

3.2.3 Class definition

varint32 Tag (value = 3)
varint32 Class id
varint32 Super class id
varint32 Name string id
varint32 Constant count
→ varint32 Constant index
→ varint32 Constant type (see 3.2)
→ byte[] Constant data (length depending on Type)
varint32 Static field count
→ varint32 Field name string id
→ varint32 Type (see 3.2)
→ byte[] Static field data (length depending on Type)
varint32 Instance field count
→ varint32 Field name string id
→ varint32 Type (see 3.2)
varint32 Discarded instance field size (in bytes)

Example:

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

03 34 35 a842
Tag (3) Class id (52) Super class id (53) Name string id (8488)
00 02 e169 00
Constant count (0) Static count (2) Name (13537) Type (0 = Object)
36 c58302 07 a2c5f6d6b4829b85e901
Field data Name (33221) Type (7) Field data
00 00
Instance fields (0) Skipped (0)

3.2.4 Instance dump

varint32 Tag (value = 4)
varin32 Object id
varint32 Class id
byte[] Instance data (length is based on the class definition)

Example:

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

04 b901 be01 00
Tag Object id (185) Class id (190) Instance data

3.2.5 Root objects

varint32 Tag (value = 5)
varint32 Root count
→ varint32 Object id

Example:

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

05 02 f053r, e971
Tag (5) Root count (2) Object ids (10736, 14569)

3.2.6 Object Array

varint32 Tag (value = 6)
varint32 Object id
varint32 Element class id
varint32 Element count
→ varint32 Element object ids

Example

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

06 d203 d603 02 00,00
Tag (6) Object id (466) Element class (470) Count (2) Elements (null, null)

3.2.7 Primitive array placeholder

varint32 Tag (value = 7)
varint32 Object id
varint32 Element field type (see 3.2)
varint32 Element count

Example

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

07 9201 03 d801
Tag (7) Object id (146) Element type (3) Count (216)

3.2.8 Legacy record

Contains a standard HPROF record wrapped inside the *Record data *field. Used for HPROF records of either unknown or not supported type.

varint32 Tag (8)
varint32 Original record tag
varint32 Record length
byte[] Record data

Example

Please note that the example shows the decoded varint values and not the actual sequence of bytes stored.

08 05 12 000000000000000000000000
Tag (8) Original tag (5) Record length (12) Data

3.3 Field types

0 object
1 int
2 boolean
3 byte
4 char
5 float
6 double
7 long
8 short