Module jit
The jit module has functions for tracing the
LuaJIT Just-In-Time compiler's progress, showing
the byte-code or assembler output that the compiler produces, and in
general providing information about what LuaJIT does with Lua code.
Below is a list of all jit functions.
Name | Use |
|---|---|
Print the byte code of a function | |
Print the i386 assembler code of a string of bytes | |
Print the x86-64 assembler code of a string of bytes | |
Print the intermediate or machine code of the following Lua code | |
Print a trace of LuaJIT's progress compiling and interpreting code |
jit_bc.dump(function)
Prints the byte code of a function.
Example:
tarantool> jit_bc = require('jit.bc')---...tarantool> function f()> print("D")> end---...tarantool> jit_bc.dump(f)-- BYTECODE -- 0x01113163c8:1-30001 GGET 0 0 ; "print"0002 KSTR 2 1 ; "D"0003 CALL 0 1 20004 RET0 0 1---...
function f()print("D")endrequire('jit.bc').dump(f)
For a list of available options, read the source code of bc.lua.
jit_dis_x86.disass(string)
Prints the i386 assembler code of a string of bytes.
Example:
tarantool> -- Disassemble hexadecimal 97 which is the x86 code for xchg eax, edi---...tarantool> jit_dis_x86 = require('jit.dis_x86')---...tarantool> jit_dis_86.disass('\x97')00000000 97 xchg eax, edi---...
For a list of available options, read the source code of dis_x86.lua.
jit_dis_x64.disass(string)
Prints the x86-64 assembler code of a string of bytes.
Example:
tarantool> -- Disassemble hexadecimal 97 which is the x86-64 code for xchg eax, edi---...tarantool> jit_dis_x64 = require('jit.dis_x64')---...tarantool> jit_dis_64.disass('\x97')00000000 97 xchg eax, edi---...
For a list of available options, read the source code of dis_x64.lua.
jit_dump.on(option [, output file]) jit_dump.off()
Prints the intermediate or machine code of the following Lua code.
Example:
tarantool> -- Show the machine code of a Lua "for" looptarantool> jit_dump = require('jit.dump')tarantool> jit_dump.on('m')tarantool> x = 0;tarantool> for i = 1, 1e6 do> x = x + i> end---- TRACE 1 start 0x01047fbc38:1---- TRACE 1 mcode 148104c29f6b mov dword [r14-0xed0], 0x1104c29f76 cvttsd2si ebp, [rdx]104c29f7a rorx rbx, [rdx-0x10], 0x2f104c29f81 shr rbx, 0x11104c29f85 mov rdx, [rbx+0x10]104c29f89 cmp dword [rdx+0x34], +0x3f104c29f8d jnz 0x104c1a010 ->0104c29f93 mov rcx, [rdx+0x28]104c29f97 mov rdi, 0xfffd8001046b3d58104c29fa1 cmp rdi, [rcx+0x320]104c29fa8 jnz 0x104c1a010 ->0104c29fae lea rax, [rcx+0x318]104c29fb5 cmp dword [rax+0x4], 0xfff90000104c29fbc jnb 0x104c1a010 ->0104c29fc2 xorps xmm7, xmm7104c29fc5 cvtsi2sd xmm7, ebp104c29fc9 addsd xmm7, [rax]104c29fcd movsd [rax], xmm7104c29fd1 add ebp, +0x01104c29fd4 cmp ebp, 0x000f4240104c29fda jg 0x104c1a014 ->1->LOOP:104c29fe0 xorps xmm6, xmm6104c29fe3 cvtsi2sd xmm6, ebp104c29fe7 addsd xmm7, xmm6104c29feb movsd [rax], xmm7104c29fef add ebp, +0x01104c29ff2 cmp ebp, 0x000f4240104c29ff8 jle 0x104c29fe0 ->LOOP104c29ffa jmp 0x104c1a01c ->3---- TRACE 1 stop -> loop---...tarantool> print(x)500000500000---...tarantool> jit_dump.off()---...
For a list of available options, read the source code of dump.lua.
jit_v.on(option [, output file]) jit_v.off()
Prints a trace of LuaJIT's progress compiling and interpreting code.
Example:
tarantool> -- Show what LuaJIT is doing for a Lua "for" looptarantool> jit_v = require('jit.v')tarantool> jit_v.on()tarantool> l = 0tarantool> for i = 1, 1e6 do> l = l + i> end[TRACE 3 "for i = 1, 1e6 dol = l + iend":1 loop]---...tarantool> print(l)500000500000---...tarantool> jit_v.off()---...
For a list of available options, read the source code of v.lua.