Confusion about the practice of trace #1

16 views
Skip to first unread message

tweyseo

unread,
Apr 8, 2019, 10:34:12 PM4/8/19
to openresty-en

the lua code:

require("jit.v").on("re_jit1.log")

for i = 1, max do
    local function f(v)
        return v + i
    end

    f(10)
end

the log of jit.v:

[TRACE --- t1.lua:4 -- NYI: bytecode 51 at t1.lua:7]
[TRACE --- t1.lua:4 -- NYI: bytecode 51 at t1.lua:7]

Create closure NYI, so i change the code:

require("jit.v").on("t1.log")

local wrapper = {}
setmetatable(wrapper, { __call = function(self, v)
        print(self.i)
        return v * self.i
    end})
local max = 100
for i = 1, max do
    wrapper.i = i
    wrapper(10)
end

the corresponding log:

[TRACE   1 t1.lua:8 loop]

the effect is excellent. but in this code:

require("jit.v").on("tailcall_jit1.log")

local function f1(val)
    if val <= 0 then
        return
    end

    f1(val - 1)
end

for i = 1, 100 do
    xpcall(f1, debug.traceback, i)
end

i have new problem:

[TRACE   1 tailcall_jit1.lua:3 up-recursion]
[TRACE --- (1/3) tailcall_jit1.lua:5 -- down-recursion, restarting at tailcall_jit1.lua:9]
[TRACE   2 tailcall_jit1.lua:9 down-recursion]
[TRACE   3 (1/1) tailcall_jit1.lua:5 -> 2]
[TRACE   4 (1/3) tailcall_jit1.lua:5 -> 2]
[TRACE   5 (1/4) tailcall_jit1.lua:5 -> 2]
[TRACE   6 tailcall_jit1.lua:11 -> 1]
[TRACE --- (2/3) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/1) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/1) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/1) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/1) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE   7 (2/1) tailcall_jit1.lua:9 -- fallback to interpreter]
[TRACE --- (2/2) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/3) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/2) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/3) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/2) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/3) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE --- (2/2) tailcall_jit1.lua:9 -- NYI: return to lower frame]
[TRACE   8 (2/3) tailcall_jit1.lua:9 -- fallback to interpreter]
[TRACE   9 (2/2) tailcall_jit1.lua:9 -- fallback to interpreter]

about NYI: return to lower frame, i search the wiki, it's said:

Tailcall. Some tailcalls to frames lower than the starting frame of the trace are not compiled.

or

Return from function. Returns to C frames and some returns to frames lower than the starting frame of the trace are not compiled.

So i dump the BC, and i found it's RET*, so i attempt to remove xpcall(), and the NYI was gone, then i found a commit, it said:

Don't try to record outermost pcall() return to lower frame.

i think i found the key, but i still confusion about this behavior, and if i have to use pcall/xpcall, how can i avoid this NYI?

Reply all
Reply to author
Forward
0 new messages