From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Bronnikov <sergeyb@tarantool.org>
Cc: Sergey Bronnikov <estetus@gmail.com>,
tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] Optionally return PC position in jit.util.tracesnap().
Date: Fri, 27 Nov 2026 16:01:42 +0300 [thread overview]
Message-ID: <awl_NnvIEB4cP2b-@root> (raw)
In-Reply-To: <cf998e66-fac3-4aa3-a0dc-f1f01be2d171@tarantool.org>
Sergey,
Thanks for the fixes!
LGTM.
Side note: the second comment is also fixed (I've checked it on
branch). Just not mentioned here.
On 27.11.26, Sergey Bronnikov wrote:
> Hi, Sergey,
>
> see the comment below
>
<snipped>
> >>>> +local snap, pos = jutil.tracesnap(1, 0, true)
> >>>> +test:istable(snap, 'the snapshot table is returned')
> >>>> +test:is(pos, loop_entry, 'the PC position points to the loop entry')
> >>>> +
> >>>> +local _, pos_without = jutil.tracesnap(1, 0)
> >>>> +test:is(pos_without, nil, 'no PC position without getpos')
> >>>> +
> >>>> +local _, pos_false = jutil.tracesnap(1, 0, false)
> >>>> +test:is(pos_false, nil, 'no PC position with getpos=false')
> >>>> +
> >>>> +local all_valid = true
> >>>> +for sn = 0, info.nexit - 1 do
> >>>> + local _, p = jutil.tracesnap(1, sn, true)
> >>>> + if type(p) ~= 'number' or p < 0 or p >= nbc or
> >>>> + jutil.funcbc(payload, p) == nil then
> >>>> + all_valid = false
> >>>> + end
> >>>> +end
> >>>> +test:ok(all_valid, 'positions of all snapshots are valid offsets')
> >>>> +
> >>>> +test:is(select('#', jutil.tracesnap(1, info.nexit, true)), 0,
> >>>> + 'out-of-range snapshot returns nothing')
> >>>> +
> >>> It would be nice to add any correctness test.
> >>> The most trivial in mind is the following:
> >>>
> >>> | src/luajit -Ohotloop=1 -e '
> >>> | local jutil = require"jit.util"
> >>> | local function trivial()
> >>> | local a = 0
> >>> | return a
> >>> | end
> >>> | trivial()
> >>> | trivial()
> >>> |
> >>> | local _, b = jutil.tracesnap(1, 0, true)
> >>> | print(b)
> >>> | local _, b = jutil.tracesnap(1, 1, true)
> >>> | print(b)
> >>> | '
> >>> | 1
> >>> | 2
> >>>
> >>> The snapshot is emitted at the function entry and before returning the
> >>> result which makes it trivial to detect:
> >>>
> >>> | ---- TRACE 1 start (command line):3
> >>> | 0001 KSHORT 0 0
> >>> | 0002 RET1 0 2
> >>> | ---- TRACE 1 IR
> >>> | .... SNAP #0 [ ---- ]
> >>> | .... SNAP #1 [ ---- +0 ]
> >>>
> >>> Don't forget to reset the hotcounters during the recording of this
> >>> example.
> >> ok, thanks, added:
> >>
> >> })
> >>
> >> -test:plan(8)
> >> +test:plan(10)
> >>
> >> -- Entries in `vmdef.bcnames` are 6 characters long.
> >> local BC_NAME_LENGTH = 6
> >> @@ -87,4 +87,21 @@ test:ok(all_valid, 'positions of all snapshots are
> >> valid offsets')
> >> test:is(select('#', jutil.tracesnap(1, info.nexit, true)), 0,
> >> 'out-of-range snapshot returns nothing')
> >>
> >> +-- The same correctness check for a trace without a loop: the
> >> +-- first and the last snapshots of the trivial function point to
> >> +-- its first and second bytecode instructions, respectively.
> >> +jit.flush()
> > You should update the hotloop counters after flush to avoid clashing.
Fixed on branch.
> >
> >> +local function trivial()
> >> + local a = 0
> >> + return a
> >> +end
> >> +trivial()
> >> +trivial()
> >> +
> >> +local _, pos_first = jutil.tracesnap(1, 0, true)
> >> +test:is(pos_first, 1, 'the first snapshot points to the first instruction')
> >> +
> >> +local _, pos_last = jutil.tracesnap(1, 1, true)
> >> +test:is(pos_last, 2, 'the second snapshot points to the second
> >> instruction')
> >> +
> >> test:done(true)
> >>
> >>>> +test:done(true)
> >>>> --
> >>>> 2.51.0
> >>>>
--
Best regards,
Sergey Kaplun
prev parent reply other threads:[~2026-11-27 12:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 11:44 Sergey Bronnikov via Tarantool-patches
2026-10-13 13:41 ` Sergey Kaplun via Tarantool-patches
2026-10-16 14:25 ` Sergey Bronnikov via Tarantool-patches
2026-10-23 15:55 ` Evgeniy Temirgaleev via Tarantool-patches
2026-10-30 12:25 ` Sergey Kaplun via Tarantool-patches
2026-11-27 12:05 ` Sergey Bronnikov via Tarantool-patches
2026-11-27 13:01 ` Sergey Kaplun via Tarantool-patches [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awl_NnvIEB4cP2b-@root \
--to=tarantool-patches@dev.tarantool.org \
--cc=estetus@gmail.com \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit] Optionally return PC position in jit.util.tracesnap().' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox