[php-src] master: Merge branch 'PHP-8.6'

From: Date: Thu, 29 Oct 2026 21:12:56 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142965@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-10-29T22:12:43+01:00 Commit: https://github.com/php/php-src/commit/b3c2d71743b506016186ddc49f5c5bb19fd9b4c1 Raw diff: https://github.com/php/php-src/commit/b3c2d71743b506016186ddc49f5c5bb19fd9b4c1.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix preloaded functions JIT-compiled on load being overwritten after restart Changed paths: A ext/opcache/tests/jit/preload_restart_function_jit.phpt M ext/opcache/ZendAccelerator.c M ext/opcache/jit/zend_jit.c M ext/opcache/jit/zend_jit.h Diff: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 9eadc03bb16e..9c5a25c9227b 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -5086,6 +5086,9 @@ static zend_result accel_preload(const char *config, bool in_child) zend_shared_alloc_save_state(); accel_interned_strings_save_state(); +#ifdef HAVE_JIT + zend_jit_save_restart_point(); +#endif SHM_PROTECT(); HANDLE_UNBLOCK_INTERRUPTIONS(); diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 899b597aeda0..30e16f4f9828 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -3908,10 +3908,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached) zend_jit_trace_startup(reattached); - zend_jit_unprotect(); - /* save JIT buffer pos */ - dasm_ptr[1] = dasm_ptr[0]; - zend_jit_protect(); + zend_jit_save_restart_point(); } void zend_jit_shutdown(void) @@ -4063,4 +4060,15 @@ void zend_jit_restart(void) } } +/* Saves the current JIT buffer position as the one zend_jit_restart() rewinds to, + * so that the code generated so far is kept across restarts */ +void zend_jit_save_restart_point(void) +{ + if (dasm_ptr) { + zend_jit_unprotect(); + dasm_ptr[1] = dasm_ptr[0]; + zend_jit_protect(); + } +} + #endif /* HAVE_JIT */ diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index c4080d86bc6d..44d0b4eaf2aa 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -174,6 +174,7 @@ void zend_jit_deactivate(void); ZEND_EXT_API void zend_jit_status(zval *ret); ZEND_EXT_API void zend_jit_blacklist_function(zend_op_array *op_array); void zend_jit_restart(void); +void zend_jit_save_restart_point(void); #define ZREG_LOAD (1<<0) #define ZREG_STORE (1<<1) diff --git a/ext/opcache/tests/jit/preload_restart_function_jit.phpt b/ext/opcache/tests/jit/preload_restart_function_jit.phpt new file mode 100644 index 000000000000..5571b52dfc25 --- /dev/null +++ b/ext/opcache/tests/jit/preload_restart_function_jit.phpt @@ -0,0 +1,82 @@ +--TEST-- +Preloaded functions JIT-compiled on script load must survive an OPcache restart +--EXTENSIONS-- +opcache +--SKIPIF-- +<?php +if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows'); +if (ini_get('opcache.jit') === false) die('skip PHP is compiled without JIT'); +?> +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=disable +opcache.jit_buffer_size=16M +--CONFLICTS-- +server +--FILE-- +<?php +$dir = __DIR__ . '/preload_restart_function_jit'; +@mkdir($dir); + +file_put_contents($dir . '/preload.php', <<<'PHP' +<?php +function preloaded_sum(int $n): int { + $s = 0; + for ($i = 0; $i < $n; $i++) { + $s += ($i * 3) ^ ($i >> 2); + } + return $s; +} +function preloaded_str(string $x): string { + return strrev($x) . strlen($x); +} +PHP); + +file_put_contents($dir . '/call.php', <<<'PHP' +<?php +echo preloaded_sum(1000), " ", preloaded_str("hello"), "\n"; +PHP); + +file_put_contents($dir . '/reset.php', <<<'PHP' +<?php +var_dump(opcache_reset()); +PHP); + +/* Compiling a new script after the restart reuses the rewound JIT buffer */ +$code = "<?php\n"; +for ($i = 0; $i < 200; $i++) { + $code .= "function f$i(int \$n): int { \$s = $i; for (\$k = 0; \$k < \$n; \$k++) { \$s = (\$s * 31 + \$k) % 1000003; } return \$s; }\n"; +} +$code .= "echo f0(10) + f199(10), \"\\n\";\n"; +file_put_contents($dir . '/new.php', $code); + +include __DIR__ . '/../php_cli_server.inc'; + +$ini = '-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.jit=function -d opcache.jit_buffer_size=16M' + . ' -d opcache.validate_timestamps=0 -d opcache.file_update_protection=0 -d opcache.preload_user=root' + . ' -d opcache.preload=' . $dir . '/preload.php'; +if (file_exists(ini_get('extension_dir') . '/opcache.' . PHP_SHLIB_SUFFIX)) { + $ini .= ' -d zend_extension=opcache.' . PHP_SHLIB_SUFFIX; +} +php_cli_server_start($ini); + +$base = 'http://' . PHP_CLI_SERVER_ADDRESS . '/jit/preload_restart_function_jit/'; +foreach (['call', 'reset', 'new', 'call', 'call'] as $script) { + echo @file_get_contents($base . $script . '.php') ?: "no response\n"; +} +?> +--CLEAN-- +<?php +$dir = __DIR__ . '/preload_restart_function_jit'; +foreach (['preload', 'call', 'reset', 'new'] as $script) { + @unlink("$dir/$script.php"); +} +@rmdir($dir); +?> +--EXPECT-- +1502868 olleh5 +bool(true) +1289143 +1502868 olleh5 +1502868 olleh5

« previous php.cvs (#142965) next »