1b3151ea5SStephane EranianJITDUMP specification version 2 2b3151ea5SStephane EranianLast Revised: 09/15/2016 3b3151ea5SStephane EranianAuthor: Stephane Eranian <eranian@gmail.com> 4b3151ea5SStephane Eranian 5b3151ea5SStephane Eranian-------------------------------------------------------- 6b3151ea5SStephane Eranian| Revision | Date | Description | 7b3151ea5SStephane Eranian-------------------------------------------------------- 8b3151ea5SStephane Eranian| 1 | 09/07/2016 | Initial revision | 9b3151ea5SStephane Eranian-------------------------------------------------------- 10b3151ea5SStephane Eranian| 2 | 09/15/2016 | Add JIT_CODE_UNWINDING_INFO | 11b3151ea5SStephane Eranian-------------------------------------------------------- 12b3151ea5SStephane Eranian 13b3151ea5SStephane Eranian 14b3151ea5SStephane EranianI/ Introduction 15b3151ea5SStephane Eranian 16b3151ea5SStephane Eranian 17b3151ea5SStephane EranianThis 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. 18b3151ea5SStephane Eranian 19b3151ea5SStephane EranianThe format is not specific to any particular programming language. It can be extended as need be. 20b3151ea5SStephane Eranian 21b3151ea5SStephane EranianThe format of the file is binary. It is self-describing in terms of endianness and is portable across multiple processor architectures. 22b3151ea5SStephane Eranian 23b3151ea5SStephane Eranian 24b3151ea5SStephane EranianII/ Overview of the format 25b3151ea5SStephane Eranian 26b3151ea5SStephane Eranian 27b3151ea5SStephane EranianThe 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. 28b3151ea5SStephane Eranian 29b3151ea5SStephane EranianThe 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. 30b3151ea5SStephane Eranian 31b3151ea5SStephane EranianEach entry in the file is timestamped. All timestamps must use the same clock source. The CLOCK_MONOTONIC clock source is recommended. 32b3151ea5SStephane Eranian 33b3151ea5SStephane Eranian 34b3151ea5SStephane EranianIII/ Jitdump file header format 35b3151ea5SStephane Eranian 36b3151ea5SStephane EranianEach jitdump file starts with a fixed size header containing the following fields in order: 37b3151ea5SStephane Eranian 38b3151ea5SStephane Eranian 392657983bSSteve MacLean* 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. 402657983bSSteve MacLean* uint32_t version : a 4-byte value representing the format version. It is currently set to 1 41b3151ea5SStephane Eranian* uint32_t total_size: size in bytes of file header 42b3151ea5SStephane Eranian* uint32_t elf_mach : ELF architecture encoding (ELF e_machine value as specified in /usr/include/elf.h) 43b3151ea5SStephane Eranian* uint32_t pad1 : padding. Reserved for future use 44b3151ea5SStephane Eranian* uint32_t pid : JIT runtime process identification (OS specific) 45b3151ea5SStephane Eranian* uint64_t timestamp : timestamp of when the file was created 46b3151ea5SStephane Eranian* uint64_t flags : a bitmask of flags 47b3151ea5SStephane Eranian 48b3151ea5SStephane EranianThe flags currently defined are as follows: 49b3151ea5SStephane Eranian * 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 50b3151ea5SStephane Eranian 51b3151ea5SStephane EranianIV/ Record header 52b3151ea5SStephane Eranian 53b3151ea5SStephane EranianThe file header is immediately followed by records. Each record starts with a fixed size header describing the record that follows. 54b3151ea5SStephane Eranian 55b3151ea5SStephane EranianThe record header is specified in order as follows: 56b3151ea5SStephane Eranian* uint32_t id : a value identifying the record type (see below) 57b3151ea5SStephane Eranian* uint32_t total_size: the size in bytes of the record including the header. 58b3151ea5SStephane Eranian* uint64_t timestamp : a timestamp of when the record was created. 59b3151ea5SStephane Eranian 60b3151ea5SStephane EranianThe following record types are defined: 61b3151ea5SStephane Eranian * Value 0 : JIT_CODE_LOAD : record describing a jitted function 62b3151ea5SStephane Eranian * Value 1 : JIT_CODE_MOVE : record describing an already jitted function which is moved 63b3151ea5SStephane Eranian * Value 2 : JIT_CODE_DEBUG_INFO: record describing the debug information for a jitted function 64b3151ea5SStephane Eranian * Value 3 : JIT_CODE_CLOSE : record marking the end of the jit runtime (optional) 65b3151ea5SStephane Eranian * Value 4 : JIT_CODE_UNWINDING_INFO: record describing a function unwinding information 66b3151ea5SStephane Eranian 67b3151ea5SStephane Eranian The payload of the record must immediately follow the record header without padding. 68b3151ea5SStephane Eranian 69b3151ea5SStephane EranianV/ JIT_CODE_LOAD record 70b3151ea5SStephane Eranian 71b3151ea5SStephane Eranian 72b3151ea5SStephane Eranian The record has the following fields following the fixed-size record header in order: 73b3151ea5SStephane Eranian * uint32_t pid: OS process id of the runtime generating the jitted code 74b3151ea5SStephane Eranian * uint32_t tid: OS thread identification of the runtime thread generating the jitted code 75b3151ea5SStephane Eranian * uint64_t vma: virtual address of jitted code start 76b3151ea5SStephane Eranian * uint64_t code_addr: code start address for the jitted code. By default vma = code_addr 77b3151ea5SStephane Eranian * uint64_t code_size: size in bytes of the generated jitted code 78b3151ea5SStephane Eranian * uint64_t code_index: unique identifier for the jitted code (see below) 79b3151ea5SStephane Eranian * char[n]: function name in ASCII including the null termination 80b3151ea5SStephane Eranian * native code: raw byte encoding of the jitted code 81b3151ea5SStephane Eranian 82b3151ea5SStephane Eranian The record header total_size field is inclusive of all components: 83b3151ea5SStephane Eranian * record header 84b3151ea5SStephane Eranian * fixed-sized fields 85b3151ea5SStephane Eranian * function name string, including termination 86b3151ea5SStephane Eranian * native code length 87b3151ea5SStephane Eranian * record specific variable data (e.g., array of data entries) 88b3151ea5SStephane Eranian 89b3151ea5SStephane EranianThe 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. 90b3151ea5SStephane Eranian 91b3151ea5SStephane EranianThe format supports empty functions with no native code. 92b3151ea5SStephane Eranian 93b3151ea5SStephane Eranian 94b3151ea5SStephane EranianVI/ JIT_CODE_MOVE record 95b3151ea5SStephane Eranian 96b3151ea5SStephane Eranian The record type is optional. 97b3151ea5SStephane Eranian 98b3151ea5SStephane Eranian The record has the following fields following the fixed-size record header in order: 99b3151ea5SStephane Eranian * uint32_t pid : OS process id of the runtime generating the jitted code 100b3151ea5SStephane Eranian * uint32_t tid : OS thread identification of the runtime thread generating the jitted code 101b3151ea5SStephane Eranian * uint64_t vma : new virtual address of jitted code start 102b3151ea5SStephane Eranian * uint64_t old_code_addr: previous code address for the same function 103b3151ea5SStephane Eranian * uint64_t new_code_addr: alternate new code started address for the jitted code. By default it should be equal to the vma address. 104b3151ea5SStephane Eranian * uint64_t code_size : size in bytes of the jitted code 105b3151ea5SStephane Eranian * uint64_t code_index : index referring to the JIT_CODE_LOAD code_index record of when the function was initially jitted 106b3151ea5SStephane Eranian 107b3151ea5SStephane Eranian 108b3151ea5SStephane EranianThe MOVE record can be used in case an already jitted function is simply moved by the runtime inside the code cache. 109b3151ea5SStephane Eranian 110b3151ea5SStephane EranianThe 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. 111b3151ea5SStephane Eranian 112b3151ea5SStephane EranianThe code size of the function cannot change. 113b3151ea5SStephane Eranian 114b3151ea5SStephane Eranian 115b3151ea5SStephane EranianVII/ JIT_DEBUG_INFO record 116b3151ea5SStephane Eranian 117b3151ea5SStephane EranianThe record type is optional. 118b3151ea5SStephane Eranian 119b3151ea5SStephane EranianThe 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. 120b3151ea5SStephane Eranian 121b3151ea5SStephane EranianThe record has the following fields following the fixed-size record header in order: 122b3151ea5SStephane Eranian * uint64_t code_addr: address of function for which the debug information is generated 123b3151ea5SStephane Eranian * uint64_t nr_entry : number of debug entries for the function 124b3151ea5SStephane Eranian * debug_entry[n]: array of nr_entry debug entries for the function 125b3151ea5SStephane Eranian 126b3151ea5SStephane EranianThe debug_entry describes the source line information. It is defined as follows in order: 127b3151ea5SStephane Eranian* uint64_t code_addr: address of function for which the debug information is generated 128b3151ea5SStephane Eranian* uint32_t line : source file line number (starting at 1) 129b3151ea5SStephane Eranian* uint32_t discrim : column discriminator, 0 is default 130b3151ea5SStephane Eranian* char name[n] : source file name in ASCII, including null termination 131b3151ea5SStephane Eranian 132b3151ea5SStephane EranianThe 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. 133b3151ea5SStephane EranianThey need to be walked sequentially. The next debug_entry is found at sizeof(debug_entry) + strlen(name) + 1. 134b3151ea5SStephane Eranian 135b3151ea5SStephane EranianIMPORTANT: 136b3151ea5SStephane Eranian 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. 137b3151ea5SStephane Eranian 138b3151ea5SStephane Eranian 139b3151ea5SStephane EranianVIII/ JIT_CODE_CLOSE record 140b3151ea5SStephane Eranian 141b3151ea5SStephane Eranian 142b3151ea5SStephane EranianThe record type is optional. 143b3151ea5SStephane Eranian 144b3151ea5SStephane EranianThe record is used as a marker for the end of the jitted runtime. It can be replaced by the end of the file. 145b3151ea5SStephane Eranian 146b3151ea5SStephane EranianThe JIT_CODE_CLOSE record does not have any specific fields, the record header contains all the information needed. 147b3151ea5SStephane Eranian 148b3151ea5SStephane Eranian 149b3151ea5SStephane EranianIX/ JIT_CODE_UNWINDING_INFO 150b3151ea5SStephane Eranian 151b3151ea5SStephane Eranian 152b3151ea5SStephane EranianThe record type is optional. 153b3151ea5SStephane Eranian 154b3151ea5SStephane EranianThe record is used to describe the unwinding information for a jitted function. 155b3151ea5SStephane Eranian 156b3151ea5SStephane EranianThe record has the following fields following the fixed-size record header in order: 157b3151ea5SStephane Eranian 158b3151ea5SStephane Eranianuint64_t unwind_data_size : the size in bytes of the unwinding data table at the end of the record 159b3151ea5SStephane Eranianuint64_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 160b3151ea5SStephane Eranianuint64_t mapped_size : the size of the unwinding data mapped in memory 161b3151ea5SStephane Eranianconst char unwinding_data[n]: an array of unwinding data, consisting of the EH Frame Header, followed by the actual EH Frame 162b3151ea5SStephane Eranian 163b3151ea5SStephane Eranian 164b3151ea5SStephane EranianThe 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 165b3151ea5SStephane Eranian 166b3151ea5SStephane Eranian 167*4da6552cSLike XuThe 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 168b3151ea5SStephane Eranian 169b3151ea5SStephane Eranian 170b3151ea5SStephane EranianNOTE: 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