[Tarantool-patches] [PATCH luajit 3/3] test: fix fix-mips64-spare-side-exit-patching

Sergey Kaplun skaplun at tarantool.org
Mon Sep 4 18:50:26 MSK 2023


This test may be flaky due to a non-monotonic filling of the vector with
traces. Hence, `misc.getmetrics().jit_trace_num` (which is the total
number of traces) is not the last trace number, so there is no mcode for
it.

This patch fixes flakyness from two sides:
* The `fillmcode()` function now starts a search from the given trace
  itself, so there is no possible inconsistency with the growing vector.
* The finding of the last trace number in the aforementioned test is now
  more bulletproof: we scan all numbers from the metrics value to the
  maxtrace value. The last number with an existing mcode is chosen as
  the resulting last trace number.
---
 ...x-mips64-spare-side-exit-patching.test.lua | 22 ++++++++++++++++---
 test/tarantool-tests/utils/jit/generators.lua |  5 ++---
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua b/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
index 62933df9..703d8e69 100644
--- a/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
+++ b/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
@@ -8,9 +8,26 @@ local test = tap.test('fix-mips64-spare-side-exit-patching'):skipcond({
 
 local generators = require('utils').jit.generators
 local frontend = require('utils').frontend
+local jutil = require('jit.util')
+
+-- Allow compilation of up to 2000 traces to avoid flushes.
+local MAXTRACE = 2000;
 
 test:plan(1)
 
+local function find_last_trace()
+  local candidate = misc.getmetrics().jit_trace_num
+  for traceno = candidate, MAXTRACE do
+    -- There is no need for heavy calls here. Just use the
+    -- simplest one to invoke `lj_checktrace()`.
+    if jutil.tracemc(traceno) then
+      candidate = traceno
+    end
+  end
+  assert(jutil.tracemc(candidate), 'tracenum candidate is invalid')
+  return candidate
+end
+
 -- Make compiler work hard.
 jit.opt.start(
   -- No optimizations at all to produce more mcode.
@@ -18,8 +35,7 @@ jit.opt.start(
   -- Try to compile all compiled paths as early as JIT can.
   'hotloop=1',
   'hotexit=1',
-  -- Allow compilation of up to 2000 traces to avoid flushes.
-  'maxtrace=2000',
+  ('maxtrace=%d'):format(MAXTRACE),
   -- Allow to compile 8Mb of mcode to be sure the issue occurs.
   'maxmcode=8192',
   -- Use big mcode area for traces to avoid usage of different
@@ -59,7 +75,7 @@ for i = 1, MAX_SPARE_SLOT + 1 do
   parent(i)
   parent(i)
   parent(i)
-  last_traceno = misc.getmetrics().jit_trace_num
+  last_traceno = find_last_trace()
 end
 
 test:ok(true, 'all traces executed correctly')
diff --git a/test/tarantool-tests/utils/jit/generators.lua b/test/tarantool-tests/utils/jit/generators.lua
index 0189cd2a..14e0e3c3 100644
--- a/test/tarantool-tests/utils/jit/generators.lua
+++ b/test/tarantool-tests/utils/jit/generators.lua
@@ -32,9 +32,7 @@ function M.fillmcode(trace_from, size)
   -- Marker to check that traces are not flushed.
   local maxtraceno = getlast_traceno()
   local FLUSH_ERR = 'Traces are flushed, check your maxtrace, maxmcode options'
-
-  local _, last_addr = jutil.tracemc(maxtraceno)
-  last_addr = canonicalize_address(last_addr)
+  local last_addr = addr_from
 
   -- Addresses of traces may increase or decrease depending on OS,
   -- so use absolute diff.
@@ -104,6 +102,7 @@ function M.fillmcode(trace_from, size)
 
     -- Calculate the address of the last trace start.
     maxtraceno = last_traceno
+    local _
     _, last_addr = jutil.tracemc(last_traceno)
     if not last_addr then
       error(FLUSH_ERR)
-- 
2.42.0



More information about the Tarantool-patches mailing list