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