Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit v1 3/5] test: allow `jit.parse` to return aborted traces
Date: Mon, 22 Apr 2024 11:49:56 +0300	[thread overview]
Message-ID: <7c0a7be30070d085d6ddd3b56c4338686e1c2baa.1713773432.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1713773432.git.skaplun@tarantool.org>

Now information about the abort of the trace is saved in the
`abort_reason` field of the corresponding structure. The
`jit.parse.finish()` returns now the second table containing aborted
traces. Each table key is a trace number containing an array of
potentially traces with this number, which was aborted.

Needed for tarantool/tarantool#9924
---
 .../unit-jit-parse-abort.test.lua             | 38 +++++++++++++++++++
 test/tarantool-tests/utils/jit/parse.lua      | 22 ++++++++---
 2 files changed, 55 insertions(+), 5 deletions(-)
 create mode 100644 test/tarantool-tests/unit-jit-parse-abort.test.lua

diff --git a/test/tarantool-tests/unit-jit-parse-abort.test.lua b/test/tarantool-tests/unit-jit-parse-abort.test.lua
new file mode 100644
index 00000000..91af5a56
--- /dev/null
+++ b/test/tarantool-tests/unit-jit-parse-abort.test.lua
@@ -0,0 +1,38 @@
+local tap = require('tap')
+local test = tap.test('unit-jit-parse'):skipcond({
+  ['Test requires JIT enabled'] = not jit.status(),
+  ['Disabled on *BSD due to #4819'] = jit.os == 'BSD',
+})
+
+local jparse = require('utils').jit.parse
+
+-- XXX: Avoid other traces compilation due to hotcount collisions
+-- for predictable results.
+jit.off()
+jit.flush()
+
+test:plan(1)
+
+jit.on()
+-- We only need the abort reason in the test.
+jparse.start('t')
+
+-- XXX: A trace always has at least 3 IR constants: for `nil`,
+-- `false`, and `true`. Always fails to record with the set
+-- `maxirconst` limit.
+jit.opt.start('hotloop=1', 'maxirconst=1')
+
+for _ = 1, 3 do end
+
+local _, aborted_traces = jparse.finish()
+
+jit.off()
+
+assert(aborted_traces and aborted_traces[1], 'aborted trace is persisted')
+
+-- We tried to compile only one trace.
+local reason = aborted_traces[1][1].abort_reason
+
+test:like(reason, 'trace too long', 'abort reason is correct')
+
+test:done(true)
diff --git a/test/tarantool-tests/utils/jit/parse.lua b/test/tarantool-tests/utils/jit/parse.lua
index bcef5b35..0ce7f7c8 100644
--- a/test/tarantool-tests/utils/jit/parse.lua
+++ b/test/tarantool-tests/utils/jit/parse.lua
@@ -22,6 +22,7 @@ local function trace_new(n)
     parent = nil,
     parent_exitno = nil,
     is_stitched = false,
+    abort_reason = nil,
     start_loc = nil,
     bc = {},
     ir = {},
@@ -87,9 +88,17 @@ local header_handlers = {
     ctx.parsing_trace = nil
     ctx.parsing = nil
   end,
-  abort = function(ctx, trace_num)
+  abort = function(ctx, trace_num, line)
     local traces = ctx.traces
     assert(ctx.parsing_trace == trace_num)
+
+    local aborted_traces = ctx.aborted_traces
+    if not aborted_traces[trace_num] then
+      aborted_traces[trace_num] = {}
+    end
+    traces[trace_num].abort_reason = line:match('-- (.+)$')
+    table.insert(aborted_traces[trace_num], traces[trace_num])
+
     ctx.parsing_trace = nil
     ctx.parsing = nil
     traces[trace_num] = nil
@@ -137,11 +146,14 @@ end
 local JDUMP_FILE
 
 local function parse_jit_dump()
-  local ctx = {traces = {}}
+  local ctx = {
+    aborted_traces = {},
+    traces = {},
+  }
   for line in io.lines(JDUMP_FILE) do
     parse_line(ctx, line)
   end
-  return ctx.traces
+  return ctx.traces, ctx.aborted_traces
 end
 
 -- Start `jit.dump()` utility with the given flags, saving the
@@ -167,10 +179,10 @@ M.finish = function()
   -- Enable traces compilation for `jit.dump` back.
   jit.on(jdump.on, true)
   jit.on(jdump.off, true)
-  local traces = parse_jit_dump()
+  local traces, aborted_traces = parse_jit_dump()
   os.remove(JDUMP_FILE)
   JDUMP_FILE = nil
-  return traces
+  return traces, aborted_traces
 end
 
 -- Turn off compilation for the module to avoid side effects.
-- 
2.44.0


  parent reply	other threads:[~2024-04-22  8:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22  8:49 [Tarantool-patches] [PATCH luajit v1 0/5] Handle all errors during stitching Sergey Kaplun via Tarantool-patches
2024-04-22  8:49 ` [Tarantool-patches] [PATCH luajit v1 1/5] build: introduce option LUAJIT_ENABLE_TABLE_BUMP Sergey Kaplun via Tarantool-patches
2024-05-05 12:39   ` Maxim Kokryashkin via Tarantool-patches
2024-04-22  8:49 ` [Tarantool-patches] [PATCH luajit v1 2/5] ci: add tablebump flavor for exotic builds Sergey Kaplun via Tarantool-patches
2024-05-05 12:40   ` Maxim Kokryashkin via Tarantool-patches
2024-04-22  8:49 ` Sergey Kaplun via Tarantool-patches [this message]
2024-05-05 12:55   ` [Tarantool-patches] [PATCH luajit v1 3/5] test: allow `jit.parse` to return aborted traces Maxim Kokryashkin via Tarantool-patches
2024-04-22  8:49 ` [Tarantool-patches] [PATCH luajit v1 4/5] Handle all types of errors during trace stitching Sergey Kaplun via Tarantool-patches
2024-05-06  8:25   ` Maxim Kokryashkin via Tarantool-patches
2024-04-22  8:49 ` [Tarantool-patches] [PATCH luajit v1 5/5] Use generic trace error for OOM " Sergey Kaplun via Tarantool-patches
2024-05-06  8:27   ` Maxim Kokryashkin 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=7c0a7be30070d085d6ddd3b56c4338686e1c2baa.1713773432.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v1 3/5] test: allow `jit.parse` to return aborted traces' \
    /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