Skip to content

Commit 91a6a3a

Browse files
committed
Synchronize zend_jit_stop_counter_handlers()
Avoid stopping counters repeatedly from different threads/processes. Fixes phpGH-11609
1 parent 585bdf2 commit 91a6a3a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

ext/opcache/ZendAccelerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ typedef struct _zend_accel_shared_globals {
266266
LONGLONG restart_in;
267267
#endif
268268
bool restart_in_progress;
269+
bool jit_counters_stopped;
269270

270271
/* Preloading */
271272
zend_persistent_script *preload_script;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static int zend_jit_trace_startup(bool reattached)
6363
ZEND_JIT_EXIT_COUNTERS = 0;
6464
ZCSG(jit_traces) = zend_jit_traces;
6565
ZCSG(jit_exit_groups) = zend_jit_exit_groups;
66+
ZCSG(jit_counters_stopped) = false;
6667
} else {
6768
zend_jit_traces = ZCSG(jit_traces);
6869
if (!zend_jit_traces) {
@@ -7255,16 +7256,23 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script)
72557256
/* Get all scripts which are accelerated by JIT */
72567257
static void zend_jit_stop_counter_handlers(void)
72577258
{
7259+
if (ZCSG(jit_counters_stopped)) {
7260+
return;
7261+
}
7262+
72587263
zend_shared_alloc_lock();
72597264
/* mprotect has an extreme overhead, avoid calls to it for every function. */
72607265
SHM_UNPROTECT();
7261-
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
7262-
zend_accel_hash_entry *cache_entry;
7263-
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
7264-
zend_persistent_script *script;
7265-
if (cache_entry->indirect) continue;
7266-
script = (zend_persistent_script *)cache_entry->data;
7267-
zend_jit_stop_persistent_script(script);
7266+
if (!ZCSG(jit_counters_stopped)) {
7267+
ZCSG(jit_counters_stopped) = true;
7268+
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
7269+
zend_accel_hash_entry *cache_entry;
7270+
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
7271+
zend_persistent_script *script;
7272+
if (cache_entry->indirect) continue;
7273+
script = (zend_persistent_script *)cache_entry->data;
7274+
zend_jit_stop_persistent_script(script);
7275+
}
72687276
}
72697277
}
72707278
SHM_PROTECT();
@@ -8438,6 +8446,7 @@ static void zend_jit_trace_restart(void)
84388446
ZEND_JIT_COUNTER_NUM = 0;
84398447
ZEND_JIT_EXIT_NUM = 0;
84408448
ZEND_JIT_EXIT_COUNTERS = 0;
8449+
ZCSG(jit_counters_stopped) = false;
84418450

84428451
zend_jit_trace_init_caches();
84438452
}

0 commit comments

Comments
 (0)