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 B54626ECE2; Fri, 27 Nov 2026 15:05:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B54626ECE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795781155; bh=kSn0fHvSdLefbberCrOUBVebBHEBvfrWj8U1SShxIPo=; 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=f2hGzv3+YVhz0c4bNt4+ZI6Z0AVjAIov7kmIO5dN3wmFfg7au7hwAi9+kpEeppWJd jiVz9133YgUF7y8C5/i2OE9T+pze/hlHgFVuZ2T7sUijpYLXVDD0xenOxWHK61yEVw SJdfpLo+4mnjpDAOdgrI3V7e0ZtOP9HjSKhCJQuI= Received: from send103.i.mail.ru (send103.i.mail.ru [89.221.237.198]) (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 895616ECE2 for ; Fri, 27 Nov 2026 15:05:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 895616ECE2 Received: by exim-smtp-canary-30-77684c7744-v4cbz with esmtpa (envelope-from ) id 1xWui5-000000001qu-10ZR; Fri, 27 Nov 2026 15:05:53 +0300 Message-ID: Date: Fri, 27 Nov 2026 15:05:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun Cc: Sergey Bronnikov , tarantool-patches@dev.tarantool.org References: <02dcf0b6-e145-4bf4-a9c4-37726f80ea0d@tarantool.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D70A5F1A44F40AC43D0E6C000425B11C04362336E679F555182A05F538085040F2AC3FFE4AC4D74C3DE06ABAFEAF6705EFA49958E6B13CE367124CC0921B35CC319BEE7C65456626 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE768D1C4AD116E0413EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566597B7DDA0B2A6E4B9AAEE997C5341D6C65803F2AEFEE11AC32376100D194F3C58EEF46B7454FC60B9742502CCDD46D0DD166953D3EA3826BF6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0A29E2F051442AF778941B15DA834481F9449624AB7ADAF37BA3038C0950A5D36D5E8D9A59859A8B6158D4E55945CAD4B76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A392EE3A9D0FB4FE0F99FD569F942444D75A43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A5AF069FDFF6F654B45002B1117B3ED696BB4EEB1A2C7151F7BFF4097FFC9E796F823CB91A9FED034534781492E4B8EEAD37F46C620FF2CAEEBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D6593AE78FA05B6FFAD4F59A10F203650442906534BA69017326C3C97AC4646648F579330D715BF44A93B8341EE9D5BE9A0AAD2B9455A3269D617193F84A83FF40B3EB04872BEB5DF9BA6536EB022892E5344C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWFdjL21m8vC/3KofJT2Itw4= X-Mailru-Sender: 520A125C2F17F0B17094CDC02B85F11B4B4E57BEA60B89D33DE06ABAFEAF6705EFA49958E6B13CE3C77752E0C033A69ED31FEA3FD9802FBF3DDE9B364B0DF289AE208404248635DF 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey, see the comment below Sergey On 10/30/26 15:25, Sergey Kaplun wrote: > 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 > > Updated to :match() as you suggested. > >>>> +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 >>>>