diff --git a/ext/opcache/tests/jit/compile_interrupted.inc b/ext/opcache/tests/jit/compile_interrupted.inc new file mode 100644 index 000000000000..a2bc94276bca --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted.inc @@ -0,0 +1,70 @@ + 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; +} + +/* Kills a forked child with $signal while it is blocked writing the JIT SSA dump in the middle of a compile. */ +function compile_interrupted(callable $child, callable $parent, int $signal): void +{ + if (($_SERVER['argv'][1] ?? '') === 'inner') { + $pid = pcntl_fork(); + if ($pid === 0) { + $child(); + exit(0); + } + echo $pid, "\n"; + pcntl_waitpid($pid, $status); + echo pcntl_wifsignaled($status) ? pcntl_wtermsig($status) : -1, "\n"; + var_dump($parent()); + /* Each call reruns the whole script, so the inner process must not reach the next call. */ + exit(0); + } + + /* 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, $signal); + } + /* The child may defer SIGTERM until the compile ends, so let it finish writing. */ + stream_get_contents($pipes[2]); + var_dump((int) fgets($pipes[1]) === $signal); + 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..4ff553662579 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_first_exec.phpt @@ -0,0 +1,44 @@ +--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) +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..799feb8afcef --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_hot_counters.phpt @@ -0,0 +1,45 @@ +--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) +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..d823210f2777 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_prof_request.phpt @@ -0,0 +1,50 @@ +--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) +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..9a7e81d93fa7 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_trace_root.phpt @@ -0,0 +1,52 @@ +--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) +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..d0fb63030a86 --- /dev/null +++ b/ext/opcache/tests/jit/compile_interrupted_trace_side.phpt @@ -0,0 +1,51 @@ +--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) +bool(true) +bool(true) +int(6)