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 9FB356E226; Wed, 29 Dec 2021 15:29:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9FB356E226 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1640780965; bh=+kfuuV516SLlB8c4Tg81r7vPrQ9IBv5zUydx0E/SVE0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VzeUQ4SoQz+gLbNSIXwJUuxzvPCJYJBnNV3Zo7PK0eh8nj8LdCJKRXwuxPLoXhHd5 QHOEHTtqtAL+fSF3fX2d3Udg8VmNyJxU3rzsk1/pxkHtLIcpj+/B03o4/LZXOHrynK lXQhioZswvUFMrro9M8ttdgBz7e6M8itEeQ16BZ4= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2D7456E226 for ; Wed, 29 Dec 2021 15:29:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D7456E226 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1n2Y55-0005dT-7J; Wed, 29 Dec 2021 15:29:23 +0300 To: Sergey Ostanevich , Igor Munkin Date: Wed, 29 Dec 2021 15:27:31 +0300 Message-Id: <20211229122731.31617-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD94D5EF110843E6A676E515EAF4FD70AA3725BF6578192D028182A05F53808504077ED2034EB6ED3BD43B67A73BD64498ED78566AD416348F30F8D9D0CE0BE199C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE706EA9E10470DC775EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372F19B29C465B909E8F08D7030A58E5AD1A62830130A00468AEEEE3FBA3A834EE7353EFBB5533756698DCDA00E01585922D493CC78C90D42A83004E26305D8B58A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7850F8B975A76562C9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3CF36E64A7E3F8E58117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637A7EFCB0EB5ACB161EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C98DCDA00E01585922D493CC78C90D42A83004E26305D8B589C2B6934AE262D3EE7EAB7254005DCED6BB2BF071322A0961E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0588BE6097D4A97A98E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343C45ADCD169245FA45B242DB1C49E8ABD0E266B2D0873C88E15895B2DB0139847FB0F16CD4F0C0731D7E09C32AA3244CB9373351F67ADAA339201BD6910264D5B4DF56057A86259F927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXY22XoowekDXP4pNfAJ4Ww== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4564D9C7331F6232E53EF7654740910DBAF19E46FE0E80F3EF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] Actually implement maxirconst trace limit. 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 Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Suggested by spacewander. (cherry picked from 9ff94c4a1fcec2c310dcb092da694f23186e23) `maxirconst` should restrict the amount of IR constants for 1 trace. Nevertheless, its value isn't checked anywhere. This patch adds the corresponding check after instruction recording. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#6548 --- Issue: https://github.com/LuaJIT/LuaJIT/issues/430 Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-430-maxirconst-actually-implement-full-ci Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/lj-430-maxirconst-actually-implement-full-ci src/lj_record.c | 5 ++- .../lj-430-maxirconst.test.lua | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/tarantool-tests/lj-430-maxirconst.test.lua diff --git a/src/lj_record.c b/src/lj_record.c index 42af09e5..f839ade2 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -2470,8 +2470,9 @@ void lj_record_ins(jit_State *J) #undef rbv #undef rcv - /* Limit the number of recorded IR instructions. */ - if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord]) + /* Limit the number of recorded IR instructions and constants. */ + if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord] || + J->cur.nk < REF_BIAS-(IRRef)J->param[JIT_P_maxirconst]) lj_trace_err(J, LJ_TRERR_TRACEOV); } diff --git a/test/tarantool-tests/lj-430-maxirconst.test.lua b/test/tarantool-tests/lj-430-maxirconst.test.lua new file mode 100644 index 00000000..1829b37d --- /dev/null +++ b/test/tarantool-tests/lj-430-maxirconst.test.lua @@ -0,0 +1,43 @@ +-- XXX: avoid any other traces compilation due to hotcount +-- collisions for predictible results. +jit.off() +jit.flush() + +-- Disabled on *BSD due to #4819. +require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819') + +local tap = require('tap') + +local test = tap.test('lj-430-maxirconst') +test:plan(2) + +-- XXX: trace always has at least 3 IR constants: for nil, false +-- and true. +jit.opt.start('hotloop=1', 'maxirconst=3') + +-- This function has only 3 IR constant. +local function irconst3() +end + +-- This function has 4 IR constants before optimizations. +local function irconst4() + local _ = 42 +end + +local ntrace_old = misc.getmetrics().jit_trace_num +jit.on() +irconst3() +irconst3() +jit.off() +test:ok(ntrace_old + 1 == misc.getmetrics().jit_trace_num, + 'trace number increases') + +ntrace_old = misc.getmetrics().jit_trace_num +jit.on() +irconst4() +irconst4() +jit.off() +test:ok(ntrace_old == misc.getmetrics().jit_trace_num, + 'trace number is the same') + +os.exit(test:check() and 0 or 1) -- 2.34.1