not logged in | [Login]
LuaJIT has some undocumented facilities for tracing program execution and what the trace compiler is doing. What follows is a bit rough, inaccurate, subject to change and very incomplete. There's probably a good reason this is undocumented.
These functions are used in several of the -j library files.
dump.lua is probably a good place to start.
You can attach callbacks to a number of compiler events with
jit.attach. The callback can be called:
Set a callback with
jit.attach(callback, "event") and clear the same callback with
The arguments passed to the callback depend on the event being reported:
funcis the function that's just been recorded.
callback(what, tr, func, pc, otr, oex)
whatis a description of the trace event: "flush", "start", "stop", "abort". Available for all events.
tris the trace number. Not available for flush.
funcis the function being traced. Available for start and abort.
pcis the program counter - the bytecode number of the function being recorded (if this a Lua function). Available for start and abort.
otrstart: the parent trace number if this is a side trace, abort: abort code (integer)?
oexstart: the exit number for the parent trace, abort: abort reason (string)
callback(tr, func, pc, depth). The first arguments are the same as for trace start.
depthis the depth of the inlining of the current bytecode.
callback(tr, ex, ngpr, nfpr).
tris the trace number as before
exis the exit number
nfprare the number of general-purpose and floating point registers that are active at the exit.
pc from a
jit.util.funcinfo returns a table of information about the function,
The fields of the table are:
linedefined: as for
lastlinedefined: as for
params: the number of parameters the function takes
stackslots: the number of stack slots the function's local variable use
upvalues: the number of upvalues the function uses
bytecodes: the number of bytecodes it the compiled function
currentline: as for
isvararg: if the function is a vararg function`
source: as for
loc: a string describing the source and currentline, like "<source>:<line>"
ffid: the fast function id of the function (if it is one). In this case only
addrbelow are valid
addr: the address of the function (if it is not a Lua function). If it's a C function rather than a fast function, only
upvaluesabove is valid