From 9126ecd608b8d2790a3315f1f049e0de64cc5642 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Tue, 1 Dec 2026 10:42:03 +0100 Subject: [PATCH] Add tests for JIT state left by killed processes Covers the first-exec, hot counter, profiling, root trace and side trace compiles fixed in GH-25842. --- ext/opcache/tests/jit/compile_interrupted.inc | 68 +++++++++++++++++++ .../jit/compile_interrupted_first_exec.phpt | 38 +++++++++++ .../jit/compile_interrupted_hot_counters.phpt | 39 +++++++++++ .../jit/compile_interrupted_prof_request.phpt | 44 ++++++++++++ .../jit/compile_interrupted_trace_root.phpt | 46 +++++++++++++ .../jit/compile_interrupted_trace_side.phpt | 45 ++++++++++++ 6 files changed, 280 insertions(+) create mode 100644 ext/opcache/tests/jit/compile_interrupted.inc create mode 100644 ext/opcache/tests/jit/compile_interrupted_first_exec.phpt create mode 100644 ext/opcache/tests/jit/compile_interrupted_hot_counters.phpt create mode 100644 ext/opcache/tests/jit/compile_interrupted_prof_request.phpt create mode 100644 ext/opcache/tests/jit/compile_interrupted_trace_root.phpt create mode 100644 ext/opcache/tests/jit/compile_interrupted_trace_side.phpt diff --git a/ext/opcache/tests/jit/compile_interrupted.inc b/ext/opcache/tests/jit/compile_interrupted.inc new file mode 100644 index 000000000000..db930ee761be --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted.inc @@ -0,0 +1,68 @@ + 1) { + PHP; + $code .= str_repeat(" \$n = (\$n ^ 7) + 1;\n", 2000); + $code .= <<<'PHP' + } + return helper($n); + } + function caller(int $n): int { + return big(0, $n) + helper($n); + } + PHP; + file_put_contents($file, $code); + require $file; +} + +/* Sends SIGTERM to a forked child while it is blocked writing the JIT SSA dump in the middle of a compile. */ +function compile_interrupted(callable $child, callable $parent): void +{ + if (($_SERVER['argv'][1] ?? '') === 'inner') { + $pid = pcntl_fork(); + if ($pid === 0) { + $child(); + exit(0); + } + echo $pid, "\n"; + pcntl_waitpid($pid, $status); + var_dump(pcntl_wtermsig($status) === SIGTERM); + var_dump($parent()); + return; + } + + /* fclose(STDERR) would close libc's stderr too, so the script reruns with stderr on a pipe the child inherits. */ + $cmd = escapeshellarg(PHP_BINARY) . ' ' . getenv('TEST_PHP_EXTRA_ARGS') . ' ' + . escapeshellarg($_SERVER['SCRIPT_FILENAME']) . ' inner'; + $proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + $pid = (int) fgets($pipes[1]); + var_dump(fread($pipes[2], 1) !== ''); + if ($pid > 0) { + posix_kill($pid, SIGTERM); + } + /* The child may defer SIGTERM until the compile ends, so let it finish writing. */ + stream_get_contents($pipes[2]); + echo stream_get_contents($pipes[1]); + $status = proc_close($proc); + if ($status !== 0) { + echo "Inner process exited with status $status\n"; + } +} diff --git a/ext/opcache/tests/jit/compile_interrupted_first_exec.phpt b/ext/opcache/tests/jit/compile_interrupted_first_exec.phpt new file mode 100644 index 000000000000..6d69acbb806c --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_first_exec.phpt @@ -0,0 +1,38 @@ +--TEST-- +JIT: func_info left by a killed first-exec compile is not reused +--EXTENSIONS-- +opcache +pcntl +posix +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=1215 +opcache.jit_buffer_size=16M +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +int(4) diff --git a/ext/opcache/tests/jit/compile_interrupted_hot_counters.phpt b/ext/opcache/tests/jit/compile_interrupted_hot_counters.phpt new file mode 100644 index 000000000000..bbb9ece16302 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_hot_counters.phpt @@ -0,0 +1,39 @@ +--TEST-- +JIT: func_info left by a killed hot counter compile is not reused +--EXTENSIONS-- +opcache +pcntl +posix +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=1235 +opcache.jit_buffer_size=16M +opcache.jit_hot_func=1 +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +int(4) diff --git a/ext/opcache/tests/jit/compile_interrupted_prof_request.phpt b/ext/opcache/tests/jit/compile_interrupted_prof_request.phpt new file mode 100644 index 000000000000..86bac9c45881 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_prof_request.phpt @@ -0,0 +1,44 @@ +--TEST-- +JIT: func_info left by a killed profiling compile is not reused +--EXTENSIONS-- +opcache +pcntl +posix +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=1225 +opcache.jit_buffer_size=16M +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +int(40) diff --git a/ext/opcache/tests/jit/compile_interrupted_trace_root.phpt b/ext/opcache/tests/jit/compile_interrupted_trace_root.phpt new file mode 100644 index 000000000000..2dcf250468e3 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_trace_root.phpt @@ -0,0 +1,46 @@ +--TEST-- +JIT: func_info left by a killed root trace compile is not reused +--EXTENSIONS-- +opcache +pcntl +posix +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=tracing +opcache.jit_buffer_size=16M +opcache.jit_hot_loop=1 +opcache.jit_hot_func=1 +opcache.jit_hot_return=1 +opcache.jit_hot_side_exit=1 +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +int(6) diff --git a/ext/opcache/tests/jit/compile_interrupted_trace_side.phpt b/ext/opcache/tests/jit/compile_interrupted_trace_side.phpt new file mode 100644 index 000000000000..e3747f1806fd --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_trace_side.phpt @@ -0,0 +1,45 @@ +--TEST-- +JIT: func_info left by a killed side trace compile is not reused +--EXTENSIONS-- +opcache +pcntl +posix +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=tracing +opcache.jit_buffer_size=16M +opcache.jit_hot_loop=1 +opcache.jit_hot_func=1 +opcache.jit_hot_return=1 +opcache.jit_hot_side_exit=1 +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) +int(6)