diff --git a/NEWS b/NEWS index 3f38dedf9cb..39edae4f2ca 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.3.0beta3 +- Opcache: + . Avoid resetting JIT counter handlers from multiple processes/threads. + (ilutov) 03 Aug 2023, PHP 8.3.0beta2 diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 1aa1655f43e..e958e8fd650 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -261,6 +261,7 @@ typedef struct _zend_accel_shared_globals { LONGLONG restart_in; #endif bool restart_in_progress; + bool jit_counters_stopped; /* Preloading */ zend_persistent_script *preload_script; diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 6099730cd8d..ccff174c7df 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -63,6 +63,7 @@ static int zend_jit_trace_startup(bool reattached) ZEND_JIT_EXIT_COUNTERS = 0; ZCSG(jit_traces) = zend_jit_traces; ZCSG(jit_exit_groups) = zend_jit_exit_groups; + ZCSG(jit_counters_stopped) = false; } else { zend_jit_traces = ZCSG(jit_traces); if (!zend_jit_traces) { @@ -7255,16 +7256,23 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script) /* Get all scripts which are accelerated by JIT */ static void zend_jit_stop_counter_handlers(void) { + if (ZCSG(jit_counters_stopped)) { + return; + } + zend_shared_alloc_lock(); /* mprotect has an extreme overhead, avoid calls to it for every function. */ SHM_UNPROTECT(); - for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) { - zend_accel_hash_entry *cache_entry; - for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) { - zend_persistent_script *script; - if (cache_entry->indirect) continue; - script = (zend_persistent_script *)cache_entry->data; - zend_jit_stop_persistent_script(script); + if (!ZCSG(jit_counters_stopped)) { + ZCSG(jit_counters_stopped) = true; + for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) { + zend_accel_hash_entry *cache_entry; + for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) { + zend_persistent_script *script; + if (cache_entry->indirect) continue; + script = (zend_persistent_script *)cache_entry->data; + zend_jit_stop_persistent_script(script); + } } } SHM_PROTECT(); @@ -8438,6 +8446,7 @@ static void zend_jit_trace_restart(void) ZEND_JIT_COUNTER_NUM = 0; ZEND_JIT_EXIT_NUM = 0; ZEND_JIT_EXIT_COUNTERS = 0; + ZCSG(jit_counters_stopped) = false; zend_jit_trace_init_caches(); }