[Tarantool-patches] [PATCH luajit] Fix interaction between profiler hooks and finalizers.
imun at tarantool.org
Thu Jun 30 15:10:24 MSK 2022
I've checked the patch into all long-term branches in tarantool/luajit
and bumped a new version in master, 2.10 and 1.10.
On 06.06.22, Sergey Kaplun wrote:
> From: Mike Pall <mike>
> Thanks to Julien Desgats.
> (cherry picked from commit 92fa45f9eb5d9aa732c6b972a85c26120d7612b4)
> Embedded LuaJIT profiler uses the following approach:
> * Create trigger on timer signals, which set `HOOK_PROFILE` flag on
> `g->hookmask` (if not set already) and update all BC instructions
> * When any of instruction is executed, callback set by user on profiler
> initialize is called. After the dispatch table updated again to
> the old static values, and flags are reset.
> * `HOOK_PROFILE` flag will set again and dispatch will updated at the next
> tick of the timer.
> Before call to __gc finalizer the old hookmask is saved to be restored
> later. When the second step is happening on call of __gc metamethod
> `HOOK_PROFILE` flag is reset. But right after that the old hook
> disposition (with `HOOK_PROFILE`) is restored, when we leaving
> `gc_call_finalizer()` without updating the dispatch table, so the
> profiler callback is never called again.
> This patch updates dispatch table right after hooks manipulation in
> `gc_call_finalizer()` and prevent ticks influence inside finalizer
> Sergey Kaplun:
> * added the description and the test for the problem
> Part of tarantool/tarantool#6548
> Side note: PR has 2 extra commits because the tarantool/luajit master
> (tarantool branch) isn't bumped in the tarantool yet.
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-512-profiler-hook-finalizers-full-ci
> Tarantool PR: https://github.com/tarantool/tarantool/pull/7237
> Related issues:
> * https://github.com/LuaJIT/LuaJIT/issues/512
> * https://github.com/tarantool/tarantool/issues/6548
> src/lj_gc.c | 2 ++
> src/lj_obj.h | 3 +-
> src/lj_profile.c | 2 +-
> .../lj-512-profiler-hook-finalizers.test.lua | 31 +++++++++++++++++++
> 4 files changed, 36 insertions(+), 2 deletions(-)
> create mode 100644 test/tarantool-tests/lj-512-profiler-hook-finalizers.test.lua
More information about the Tarantool-patches