From 3cd0383d918a023885349fc22552ee417924b97b Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 16 May 2025 18:05:11 +0200 Subject: [PATCH] Adjust default value of opcache.jit_hot_loop to a prime number Loops whose number of iterations + 1 is a factor of opcache.jit_hot_loop will always be traced at the exact moment the loop condition evaluates to false. As a result, these loops can never be JIT'ed successfully. Here I adjust the default value of opcache.jit_hot_loop to a prime number, so this can not happen (unless number of iterations+1 is opcache.jit_hot_loop). Closes GH-18573 --- NEWS | 3 ++- UPGRADING | 3 +++ ext/opcache/zend_accelerator_module.c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 807d70236c7..d0a1d30fc9e 100644 --- a/NEWS +++ b/NEWS @@ -111,9 +111,10 @@ PHP NEWS . Added mysqlnd.collect_memory_statistics to ini quick reference. (hauk92) -- OPcache: +- Opcache: . Fixed ZTS OPcache build on Cygwin. (cmb) . Added opcache.file_cache_read_only. (Samuel Melrose) + . Updated default value of opcache.jit_hot_loop. (Arnaud) - Output: . Fixed calculation of aligned buffer size. (cmb) diff --git a/UPGRADING b/UPGRADING index 79ff29eae55..e120f445e24 100644 --- a/UPGRADING +++ b/UPGRADING @@ -460,6 +460,9 @@ PHP 8.5 UPGRADE NOTES Note: A cache generated with a different build of PHP, a different file path, or different settings (including which extensions are loaded), may be ignored. + . The default value of opcache.jit_hot_loop is now 61 (a prime) to prevent it + from being a multiple of loop iteration counts. + It is recommended that this parameter is set to a prime number. ======================================== 12. Windows Support diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 0c52b98dc45..203a41d93b4 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -323,7 +323,8 @@ ZEND_INI_BEGIN() STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_max_exit_counters" , "8192", PHP_INI_SYSTEM, OnUpdateLong, max_exit_counters, zend_jit_globals, jit_globals) - STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals) + /* Defautl value should be a prime number, to reduce the chances of loop iterations being a factor of opcache.jit_hot_loop */ + STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "61", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_return" , "8", PHP_INI_SYSTEM, OnUpdateCounter, hot_return, zend_jit_globals, jit_globals) STD_PHP_INI_ENTRY("opcache.jit_hot_side_exit" , "8", PHP_INI_ALL, OnUpdateCounter, hot_side_exit, zend_jit_globals, jit_globals)