|
| 1 | +local tap = require('tap') |
| 2 | +local test = tap.test('lj-624-jloop-snapshot-pc'):skipcond({ |
| 3 | + ['Test requires JIT enabled'] = not jit.status(), |
| 4 | +}) |
| 5 | + |
| 6 | +test:plan(1) |
| 7 | +-- XXX: The test case below triggers the assertion that was |
| 8 | +-- added in the patch if tested without the fix itself. It |
| 9 | +-- is hard to create a stable reproducer without turning off |
| 10 | +-- ASLR and VM randomizations, which is not suitable for testing. |
| 11 | + |
| 12 | +-- Reproducer below produces the following traces: |
| 13 | +-- ---- TRACE 1 start test.lua:2 |
| 14 | +-- 0001 KSHORT 1 2 |
| 15 | +-- 0002 ISGE 0 1 |
| 16 | +-- 0003 JMP 1 => 0006 |
| 17 | +-- 0006 UGET 1 0 ; fib |
| 18 | +-- 0007 SUBVN 2 0 0 ; 1 |
| 19 | +-- 0008 CALL 1 2 2 |
| 20 | +-- 0000 . FUNCF 4 ; test.lua:2 |
| 21 | +-- 0001 . KSHORT 1 2 |
| 22 | +-- 0002 . ISGE 0 1 |
| 23 | +-- 0003 . JMP 1 => 0006 |
| 24 | +-- 0006 . UGET 1 0 ; fib |
| 25 | +-- 0007 . SUBVN 2 0 0 ; 1 |
| 26 | +-- 0008 . CALL 1 2 2 |
| 27 | +-- 0000 . . FUNCF 4 ; test.lua:2 |
| 28 | +-- 0001 . . KSHORT 1 2 |
| 29 | +-- 0002 . . ISGE 0 1 |
| 30 | +-- 0003 . . JMP 1 => 0006 |
| 31 | +-- 0006 . . UGET 1 0 ; fib |
| 32 | +-- 0007 . . SUBVN 2 0 0 ; 1 |
| 33 | +-- 0008 . . CALL 1 2 2 |
| 34 | +-- 0000 . . . FUNCF 4 ; test.lua:2 |
| 35 | +-- ---- TRACE 1 stop -> up-recursion |
| 36 | +-- |
| 37 | +-- ---- TRACE 1 exit 1 |
| 38 | +-- ---- TRACE 2 start 1/1 test.lua:3 |
| 39 | +-- 0004 ISTC 1 0 |
| 40 | +-- 0005 JMP 1 => 0013 |
| 41 | +-- 0013 RET1 1 2 |
| 42 | +-- 0009 UGET 2 0 ; fib |
| 43 | +-- 0010 SUBVN 3 0 1 ; 2 |
| 44 | +-- 0011 CALL 2 2 2 |
| 45 | +-- 0000 . JFUNCF 4 1 ; test.lua:2 |
| 46 | +-- ---- TRACE 2 stop -> 1 |
| 47 | +-- |
| 48 | +-- ---- TRACE 2 exit 1 |
| 49 | +-- ---- TRACE 3 start 2/1 test.lua:3 |
| 50 | +-- 0013 RET1 1 2 |
| 51 | +-- 0012 ADDVV 1 1 2 |
| 52 | +-- 0013 RET1 1 2 |
| 53 | +-- ---- TRACE 3 abort test.lua:3 -- down-recursion, restarting |
| 54 | +-- |
| 55 | +-- ---- TRACE 3 start test.lua:3 |
| 56 | +-- 0013 RET1 1 2 |
| 57 | +-- 0009 UGET 2 0 ; fib |
| 58 | +-- 0010 SUBVN 3 0 1 ; 2 |
| 59 | +-- 0011 CALL 2 2 2 |
| 60 | +-- 0000 . JFUNCF 4 1 ; test.lua:2 |
| 61 | +-- ---- TRACE 3 stop -> 1 |
| 62 | +-- |
| 63 | +-- ---- TRACE 2 exit 1 |
| 64 | +-- ---- TRACE 4 start 2/1 test.lua:3 |
| 65 | +-- 0013 RET1 1 2 |
| 66 | +-- 0012 ADDVV 1 1 2 |
| 67 | +-- 0013 JLOOP 3 3 |
| 68 | +-- |
| 69 | +-- The assertion introduced in the previous patch is triggered during |
| 70 | +-- recording of the last 0013 JLOOP. |
| 71 | +-- |
| 72 | +-- See also: |
| 73 | +-- https://github.com/luaJIT/LuaJIT/issues/624 |
| 74 | + |
| 75 | +jit.opt.start('hotloop=1', 'hotexit=1') |
| 76 | +local function fib(n) |
| 77 | + return n < 2 and n or fib(n - 1) + fib(n - 2) |
| 78 | +end |
| 79 | + |
| 80 | +fib(5) |
| 81 | + |
| 82 | +test:ok(true, 'snapshot pc is correct') |
| 83 | +test:done(true) |
0 commit comments