162306a36Sopenharmony_ciJITDUMP specification version 2
262306a36Sopenharmony_ciLast Revised: 09/15/2016
362306a36Sopenharmony_ciAuthor: Stephane Eranian <eranian@gmail.com>
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci--------------------------------------------------------
662306a36Sopenharmony_ci| Revision  |    Date    | Description                 |
762306a36Sopenharmony_ci--------------------------------------------------------
862306a36Sopenharmony_ci|   1       | 09/07/2016 | Initial revision            |
962306a36Sopenharmony_ci--------------------------------------------------------
1062306a36Sopenharmony_ci|   2       | 09/15/2016 | Add JIT_CODE_UNWINDING_INFO |
1162306a36Sopenharmony_ci--------------------------------------------------------
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciI/ Introduction
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciThis document describes the jitdump file format. The file is generated by Just-In-time compiler runtimes to save meta-data information about the generated code, such as address, size, and name of generated functions, the native code generated, the source line information. The data may then be used by performance tools, such as Linux perf to generate function and assembly level profiles.
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ciThe format is not specific to any particular programming language. It can be extended as need be.
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciThe format of the file is binary. It is self-describing in terms of endianness and is portable across multiple processor architectures.
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciII/ Overview of the format
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciThe format requires only sequential accesses, i.e., append only mode. The file starts with a fixed size file header describing the version of the specification, the endianness.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciThe header is followed by a series of records, each starting with a fixed size header describing the type of record and its size. It is, itself, followed by the payload for the record. Records can have a variable size even for a given type.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciEach entry in the file is timestamped. All timestamps must use the same clock source. The CLOCK_MONOTONIC clock source is recommended.
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciIII/ Jitdump file header format
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciEach jitdump file starts with a fixed size header containing the following fields in order:
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci* uint32_t magic     : a magic number tagging the file type. The value is 4-byte long and represents the string "JiTD" in ASCII form. It written is as 0x4A695444. The reader will detect an endian mismatch when it reads 0x4454694a.
4062306a36Sopenharmony_ci* uint32_t version   : a 4-byte value representing the format version. It is currently set to 1
4162306a36Sopenharmony_ci* uint32_t total_size: size in bytes of file header
4262306a36Sopenharmony_ci* uint32_t elf_mach  : ELF architecture encoding (ELF e_machine value as specified in /usr/include/elf.h)
4362306a36Sopenharmony_ci* uint32_t pad1      : padding. Reserved for future use
4462306a36Sopenharmony_ci* uint32_t pid       : JIT runtime process identification (OS specific)
4562306a36Sopenharmony_ci* uint64_t timestamp : timestamp of when the file was created
4662306a36Sopenharmony_ci* uint64_t flags     : a bitmask of flags
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciThe flags currently defined are as follows:
4962306a36Sopenharmony_ci * bit 0: JITDUMP_FLAGS_ARCH_TIMESTAMP : set if the jitdump file is using an architecture-specific timestamp clock source. For instance, on x86, one could use TSC directly
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciIV/ Record header
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ciThe file header is immediately followed by records. Each record starts with a fixed size header describing the record that follows.
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciThe record header is specified in order as follows:
5662306a36Sopenharmony_ci* uint32_t id        : a value identifying the record type (see below)
5762306a36Sopenharmony_ci* uint32_t total_size: the size in bytes of the record including the header.
5862306a36Sopenharmony_ci* uint64_t timestamp : a timestamp of when the record was created.
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciThe following record types are defined:
6162306a36Sopenharmony_ci * Value 0 : JIT_CODE_LOAD      : record describing a jitted function
6262306a36Sopenharmony_ci * Value 1 : JIT_CODE_MOVE      : record describing an already jitted function which is moved
6362306a36Sopenharmony_ci * Value 2 : JIT_CODE_DEBUG_INFO: record describing the debug information for a jitted function
6462306a36Sopenharmony_ci * Value 3 : JIT_CODE_CLOSE     : record marking the end of the jit runtime (optional)
6562306a36Sopenharmony_ci * Value 4 : JIT_CODE_UNWINDING_INFO: record describing a function unwinding information
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci The payload of the record must immediately follow the record header without padding.
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciV/ JIT_CODE_LOAD record
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci  The record has the following fields following the fixed-size record header in order:
7362306a36Sopenharmony_ci  * uint32_t pid: OS process id of the runtime generating the jitted code
7462306a36Sopenharmony_ci  * uint32_t tid: OS thread identification of the runtime thread generating the jitted code
7562306a36Sopenharmony_ci  * uint64_t vma: virtual address of jitted code start
7662306a36Sopenharmony_ci  * uint64_t code_addr: code start address for the jitted code. By default vma = code_addr
7762306a36Sopenharmony_ci  * uint64_t code_size: size in bytes of the generated jitted code
7862306a36Sopenharmony_ci  * uint64_t code_index: unique identifier for the jitted code (see below)
7962306a36Sopenharmony_ci  * char[n]: function name in ASCII including the null termination
8062306a36Sopenharmony_ci  * native code: raw byte encoding of the jitted code
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci  The record header total_size field is inclusive of all components:
8362306a36Sopenharmony_ci  * record header
8462306a36Sopenharmony_ci  * fixed-sized fields
8562306a36Sopenharmony_ci  * function name string, including termination
8662306a36Sopenharmony_ci  * native code length
8762306a36Sopenharmony_ci  * record specific variable data (e.g., array of data entries)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciThe code_index is used to uniquely identify each jitted function. The index can be a monotonically increasing 64-bit value. Each time a function is jitted it gets a new number. This value is used in case the code for a function is moved and avoids having to issue another JIT_CODE_LOAD record.
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ciThe format supports empty functions with no native code.
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciVI/ JIT_CODE_MOVE record
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci  The record type is optional.
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci  The record has the following fields following the fixed-size record header in order:
9962306a36Sopenharmony_ci  * uint32_t pid          : OS process id of the runtime generating the jitted code
10062306a36Sopenharmony_ci  * uint32_t tid          : OS thread identification of the runtime thread generating the jitted code
10162306a36Sopenharmony_ci  * uint64_t vma          : new virtual address of jitted code start
10262306a36Sopenharmony_ci  * uint64_t old_code_addr: previous code address for the same function
10362306a36Sopenharmony_ci  * uint64_t new_code_addr: alternate new code started address for the jitted code. By default it should be equal to the vma address.
10462306a36Sopenharmony_ci  * uint64_t code_size    : size in bytes of the jitted code
10562306a36Sopenharmony_ci  * uint64_t code_index   : index referring to the JIT_CODE_LOAD code_index record of when the function was initially jitted
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciThe MOVE record can be used in case an already jitted function is simply moved by the runtime inside the code cache.
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciThe JIT_CODE_MOVE record cannot come before the JIT_CODE_LOAD record for the same function name. The function cannot have changed name, otherwise a new JIT_CODE_LOAD record must be emitted.
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciThe code size of the function cannot change.
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ciVII/ JIT_DEBUG_INFO record
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciThe record type is optional.
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciThe record contains source lines debug information, i.e., a way to map a code address back to a source line. This information may be used by the performance tool.
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciThe record has the following fields following the fixed-size record header in order:
12262306a36Sopenharmony_ci  * uint64_t code_addr: address of function for which the debug information is generated
12362306a36Sopenharmony_ci  * uint64_t nr_entry : number of debug entries for the function
12462306a36Sopenharmony_ci  * debug_entry[n]: array of nr_entry debug entries for the function
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciThe debug_entry describes the source line information. It is defined as follows in order:
12762306a36Sopenharmony_ci* uint64_t code_addr: address of function for which the debug information is generated
12862306a36Sopenharmony_ci* uint32_t line     : source file line number (starting at 1)
12962306a36Sopenharmony_ci* uint32_t discrim  : column discriminator, 0 is default
13062306a36Sopenharmony_ci* char name[n]      : source file name in ASCII, including null termination
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ciThe debug_entry entries are saved in sequence but given that they have variable sizes due to the file name string, they cannot be indexed directly.
13362306a36Sopenharmony_ciThey need to be walked sequentially. The next debug_entry is found at sizeof(debug_entry) + strlen(name) + 1.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciIMPORTANT:
13662306a36Sopenharmony_ci  The JIT_CODE_DEBUG for a given function must always be generated BEFORE the JIT_CODE_LOAD for the function. This facilitates greatly the parser for the jitdump file.
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciVIII/ JIT_CODE_CLOSE record
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ciThe record type is optional.
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciThe record is used as a marker for the end of the jitted runtime. It can be replaced by the end of the file.
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ciThe JIT_CODE_CLOSE record does not have any specific fields, the record header contains all the information needed.
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ciIX/ JIT_CODE_UNWINDING_INFO
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciThe record type is optional.
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ciThe record is used to describe the unwinding information for a jitted function.
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ciThe record has the following fields following the fixed-size record header in order:
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciuint64_t unwind_data_size   : the size in bytes of the unwinding data table at the end of the record
15962306a36Sopenharmony_ciuint64_t eh_frame_hdr_size  : the size in bytes of the DWARF EH Frame Header at the start of the unwinding data table at the end of the record
16062306a36Sopenharmony_ciuint64_t mapped_size        : the size of the unwinding data mapped in memory
16162306a36Sopenharmony_ciconst char unwinding_data[n]: an array of unwinding data, consisting of the EH Frame Header, followed by the actual EH Frame
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciThe EH Frame header follows the Linux Standard Base (LSB) specification as described in the document at https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/ehframehdr.html
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ciThe EH Frame follows the LSB specification as described in the document at https://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ciNOTE: The mapped_size is generally either the same as unwind_data_size (if the unwinding data was mapped in memory by the running process) or zero (if the unwinding data is not mapped by the process). If the unwinding data was not mapped, then only the EH Frame Header will be read, which can be used to specify FP based unwinding for a function which does not have unwinding information.
171