From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Ostanevich <sergos@tarantool.org>,
Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit] Actually implement maxirconst trace limit.
Date: Wed, 29 Dec 2021 15:27:31 +0300 [thread overview]
Message-ID: <20211229122731.31617-1-skaplun@tarantool.org> (raw)
From: Mike Pall <mike>
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
next reply other threads:[~2021-12-29 12:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-29 12:27 Sergey Kaplun via Tarantool-patches [this message]
2022-01-27 23:18 ` Igor Munkin via Tarantool-patches
2022-01-28 8:42 ` Sergey Kaplun via Tarantool-patches
2022-01-28 11:55 ` Igor Munkin via Tarantool-patches
2022-01-28 12:35 ` Sergey Kaplun via Tarantool-patches
2022-01-28 14:16 ` sergos via Tarantool-patches
2022-01-28 15:09 ` Sergey Kaplun via Tarantool-patches
2022-01-28 21:28 ` Sergey Ostanevich via Tarantool-patches
2022-01-28 21:45 ` Igor Munkin via Tarantool-patches
2022-01-29 1:17 ` Sergey Kaplun via Tarantool-patches
2022-02-11 19:09 ` Igor Munkin via Tarantool-patches
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=20211229122731.31617-1-skaplun@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imun@tarantool.org \
--cc=sergos@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit] Actually implement maxirconst trace limit.' \
/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