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.
Примечание
- In this document, we will use:
jit_dis_x64
forrequire('jit.dis_x64')
,jit_v
forrequire('jit.v')
,jit_dump
forrequire('jit.dump')
.
Name | Use |
---|---|
jit_bc.dump() | Print the byte code of a function |
jit_dis_x86.disass() | Print the i386 assembler code of a string of bytes |
jit_dis_x64.disass() | Print the x86-64 assembler code of a string of bytes |
jit_dump.on(), jit_dump.off() | Print the intermediate or machine code of the following Lua code |
jit_v.on(), jit_v.off() | 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-3 0001 GGET 0 0 ; "print" 0002 KSTR 2 1 ; "D" 0003 CALL 0 1 2 0004 RET0 0 1 --- ...
function f() print("D") end require('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" loop tarantool> 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 148 104c29f6b mov dword [r14-0xed0], 0x1 104c29f76 cvttsd2si ebp, [rdx] 104c29f7a rorx rbx, [rdx-0x10], 0x2f 104c29f81 shr rbx, 0x11 104c29f85 mov rdx, [rbx+0x10] 104c29f89 cmp dword [rdx+0x34], +0x3f 104c29f8d jnz 0x104c1a010 ->0 104c29f93 mov rcx, [rdx+0x28] 104c29f97 mov rdi, 0xfffd8001046b3d58 104c29fa1 cmp rdi, [rcx+0x320] 104c29fa8 jnz 0x104c1a010 ->0 104c29fae lea rax, [rcx+0x318] 104c29fb5 cmp dword [rax+0x4], 0xfff90000 104c29fbc jnb 0x104c1a010 ->0 104c29fc2 xorps xmm7, xmm7 104c29fc5 cvtsi2sd xmm7, ebp 104c29fc9 addsd xmm7, [rax] 104c29fcd movsd [rax], xmm7 104c29fd1 add ebp, +0x01 104c29fd4 cmp ebp, 0x000f4240 104c29fda jg 0x104c1a014 ->1 ->LOOP: 104c29fe0 xorps xmm6, xmm6 104c29fe3 cvtsi2sd xmm6, ebp 104c29fe7 addsd xmm7, xmm6 104c29feb movsd [rax], xmm7 104c29fef add ebp, +0x01 104c29ff2 cmp ebp, 0x000f4240 104c29ff8 jle 0x104c29fe0 ->LOOP 104c29ffa 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" loop tarantool> jit_v = require('jit.v') tarantool> jit_v.on() tarantool> l = 0 tarantool> for i = 1, 1e6 do > l = l + i > end [TRACE 3 "for i = 1, 1e6 do l = l + i end":1 loop] --- ... tarantool> print(l) 500000500000 --- ... tarantool> jit_v.off() --- ...
For a list of available options, read the source code of v.lua.