forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysprof: fix crash during FFUNC stream
Sometimes, the Lua stack can be inconsistent during the FFUNC execution, which may lead to a sysprof crash during the stack unwinding. This patch replaces the `top_frame` property of `global_State` with `lj_sysprof_topframe` structure, which contains `top_frame` and `ffid` properties. `ffid` property makes sense only when the LuaJIT VM state is set to `FFUNC`. That property is set to the ffid of the fast function that VM is about to execute. In the same time, `top_frame` property is not updated now, so the top frame of the Lua stack can be streamed based on the ffid, and the rest of the Lua stack can be streamed as usual. Also, this patch fixes the build via Makefile.original by adding the `LJ_HASSYSPROF` flag support to it. Resolves tarantool/tarantool#8594
- Loading branch information
1 parent
e6b25e6
commit b0eb569
Showing
6 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local tap = require('tap') | ||
local test = tap.test('gh-8594-sysprof-ffunc-crash'):skipcond({ | ||
['Sysprof is implemented for x86_64 only'] = jit.arch ~= 'x86' and | ||
jit.arch ~= 'x64', | ||
['Sysprof is implemented for Linux only'] = jit.os ~= 'Linux', | ||
}) | ||
|
||
test:plan(1) | ||
|
||
jit.off() | ||
-- XXX: Run JIT tuning functions in a safe frame to avoid errors | ||
-- thrown when LuaJIT is compiled with JIT engine disabled. | ||
pcall(jit.flush) | ||
|
||
local TMP_BINFILE = '/dev/null' | ||
|
||
-- XXX: The best way to test the issue is to set the profile | ||
-- interval to be as short as possible. However, our CI is | ||
-- not capable of handling such intense testing, so it was a | ||
-- forced decision to reduce the sampling frequency for it. As a | ||
-- result, it is now less likely to reproduce the issue | ||
-- statistically, but the test case is still valid. | ||
|
||
-- GitHub always sets[1] the `CI` environment variable to `true` | ||
-- for every step in a workflow. | ||
-- [1]: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables | ||
local CI = os.getenv('CI') == 'true' | ||
|
||
-- Profile interval and number of iterations for CI are | ||
-- empirical. Non-CI profile interval is set to be as short | ||
-- as possible, so the issue is more likely to reproduce. | ||
-- Non-CI number of iterations is greater for the same reason. | ||
local PROFILE_INTERVAL = CI and 3 or 1 | ||
local N_ITERATIONS = CI and 1e5 or 1e6 | ||
|
||
local res, err = misc.sysprof.start{ | ||
mode = 'C', | ||
interval = PROFILE_INTERVAL, | ||
path = TMP_BINFILE, | ||
} | ||
assert(res, err) | ||
|
||
for i = 1, N_ITERATIONS do | ||
-- XXX: `tostring` is FFUNC. | ||
tostring(i) | ||
end | ||
|
||
res, err = misc.sysprof.stop() | ||
assert(res, err) | ||
|
||
test:ok(true, 'sysprof finished successfully') | ||
|
||
os.exit(test:check() and 0 or 1) |