From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 72EF26ECCD; Fri, 30 Oct 2026 15:26:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 72EF26ECCD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1793363180; bh=23ec/XcxY6aUj+E+OhSTLyfmGwvemkZD4TBHDCN8/4M=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=iH/7CG+G1JfHqsOmXivuDvXlXHTqezkuw+aeL0sLh8BT9cEjojmtfR2uveX3QeskC 58bWJWFjnRXO5yreIZRsgHXrvDJwcbh9xh3bXsQN2lfKiJWS70fvM7Wr9wL8y921rt QfLGSsAv7fl3wUYcIeepoeQZusqtVWgHlp8TW8LI= Received: from send240.i.mail.ru (send240.i.mail.ru [95.163.59.79]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 570616ECCD for ; Fri, 30 Oct 2026 15:26:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 570616ECCD Received: by exim-smtp-675c6798c6-sn85q with esmtpa (envelope-from ) id 1xMlgX-000000000h8-1063; Fri, 30 Oct 2026 15:26:17 +0300 Date: Fri, 30 Oct 2026 15:25:51 +0300 To: Sergey Bronnikov Cc: Sergey Bronnikov , tarantool-patches@dev.tarantool.org Message-ID: References: <02dcf0b6-e145-4bf4-a9c4-37726f80ea0d@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <02dcf0b6-e145-4bf4-a9c4-37726f80ea0d@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD943C6AEBB953A11868B9A05538DDD48EA808D1CAF36FB1EF61313CFAB8367EF908E2BE116634AD74DC733864240688D843DE06ABAFEAF6705CBDF517D1050985B4498001DB40F1C6EFA673BDF079014B0 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E5D7EAC6EBA58433EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566C490AAAA3202D1DC7189899DF35803E5B5073AAE481D6A8275088EFC7CB8CDBB389733CBF5DBD5E9D5E8D9A59859A8B636DA1BED736F9328CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE765B758295022C166731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A57AD4C834F1C6E6A35002B1117B3ED6965F3821434805C6A203803A57F48E4E5A3610D81D389A125CDE35189EBF2DEA28FEA14CD2CD220BB99C5DF10A05D560A9880EC71AF561E0AAD9143641EC25BB39B12B8507FEC247ED X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D65942F2F4B458FC2E0FFE4B287A862FDB63D5546DAE80F3C50CD6457CC60BC26FDC56B00A60E61B1086B8341EE9D5BE9A0AA9C7228D90604C99A64B32689162C5D5134035C45FC4EA9B6536EB022892E5344C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWEciujy+aTdjnNR0l9D9uPM= X-Mailru-Sender: 689FA8AB762F73937C9FA53A4753B313E1A6B94252BCD08B09947ACA4F395CF430D5272F2FE8C729E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Optionally return PC position in jit.util.tracesnap(). X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, Please consider remaining comments below. On 16.10.26, Sergey Bronnikov wrote: > Hi, Sergey, > > thanks for review! See my comments below. > > Sergey > > > >> Sergey Bronnikov: > >> * added the description and the test for the feature > >> --- > >> > >> Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-xxxx-tracesnap-getpos > >> > >> src/lib_jit.c | 9 +- > >> .../lj-1472-tracesnap-getpos.test.lua | 89 +++++++++++++++++++ > >> 2 files changed, 97 insertions(+), 1 deletion(-) > >> create mode 100644 test/tarantool-tests/lj-1472-tracesnap-getpos.test.lua > >> > >> diff --git a/src/lib_jit.c b/src/lib_jit.c > >> index 9f870f68f..5a0d38611 100644 > >> --- a/src/lib_jit.c > >> +++ b/src/lib_jit.c > >> +-- Return the name of the bytecode operation for the given > >> +-- instruction, that is encoded in the low byte. > >> +local function opname(ins) > >> + local oidx = BC_NAME_LENGTH * bit.band(ins, 0xff) > >> + local name = vmdef.bcnames:sub(oidx + 1, oidx + BC_NAME_LENGTH) > >> + return (name:gsub('%s+$', '')) > > Minor: I suggest the more readable: > > | return name:match('%a+') > > Feel free to ignore. > > this will break testcase: > > tarantool> a = "FORL  " > --- > ... > > tarantool> a:gsub('%a+', '') > --- > - '  ' > - 1 > ... > > tarantool> a:gsub('%s+', '') > --- > - FORL > - 1 > ... Don't get your example: | src/luajit -e 'local str = "FORL " print(str:match("%a+"), (str:gsub("%s+$", "")))' | FORL FORL > >> +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. > +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