Skip to content

Commit a75cf0c

Browse files
committed
JIT support for opcache restart
1 parent 06da048 commit a75cf0c

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

ext/opcache/ZendAccelerator.c

+5
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,11 @@ int accel_activate(INIT_FUNC_ARGS)
25062506
if (ZCSG(preload_script)) {
25072507
preload_restart();
25082508
}
2509+
2510+
#ifdef HAVE_JIT
2511+
zend_jit_restart();
2512+
#endif
2513+
25092514
ZCSG(accelerator_enabled) = ZCSG(cache_status_before_restart);
25102515
if (ZCSG(last_restart_time) < ZCG(request_time)) {
25112516
ZCSG(last_restart_time) = ZCG(request_time);

ext/opcache/jit/zend_jit.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, zend_bool reattached)
37983798
}
37993799
#endif
38003800

3801-
dasm_ptr = dasm_end = (void*)(((char*)dasm_buf) + size - sizeof(*dasm_ptr));
3801+
dasm_ptr = dasm_end = (void*)(((char*)dasm_buf) + size - sizeof(*dasm_ptr) * 2);
38023802
if (!reattached) {
38033803
zend_jit_unprotect();
38043804
*dasm_ptr = dasm_buf;
@@ -3847,6 +3847,11 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, zend_bool reattached)
38473847
return FAILURE;
38483848
}
38493849

3850+
/* save JIT buffer pos */
3851+
zend_jit_unprotect();
3852+
dasm_ptr[1] = dasm_ptr[0];
3853+
zend_jit_protect();
3854+
38503855
return SUCCESS;
38513856
}
38523857

@@ -3926,4 +3931,18 @@ ZEND_EXT_API void zend_jit_deactivate(void)
39263931
}
39273932
}
39283933

3934+
ZEND_EXT_API void zend_jit_restart(void)
3935+
{
3936+
if (dasm_buf) {
3937+
zend_jit_unprotect();
3938+
3939+
/* restore JIT buffer pos */
3940+
dasm_ptr[0] = dasm_ptr[1];
3941+
3942+
zend_jit_trace_restart();
3943+
3944+
zend_jit_protect();
3945+
}
3946+
}
3947+
39293948
#endif /* HAVE_JIT */

ext/opcache/jit/zend_jit.h

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ ZEND_EXT_API void zend_jit_shutdown(void);
140140
ZEND_EXT_API void zend_jit_activate(void);
141141
ZEND_EXT_API void zend_jit_deactivate(void);
142142
ZEND_EXT_API void zend_jit_status(zval *ret);
143+
ZEND_EXT_API void zend_jit_restart(void);
143144

144145
typedef struct _zend_lifetime_interval zend_lifetime_interval;
145146
typedef struct _zend_life_range zend_life_range;

ext/opcache/jit/zend_jit_trace.c

+10
Original file line numberDiff line numberDiff line change
@@ -5606,3 +5606,13 @@ static void zend_jit_trace_init_caches(void)
56065606
static void zend_jit_trace_reset_caches(void)
56075607
{
56085608
}
5609+
5610+
static void zend_jit_trace_restart(void)
5611+
{
5612+
ZEND_JIT_TRACE_NUM = 1;
5613+
ZEND_JIT_COUNTER_NUM = 0;
5614+
ZEND_JIT_EXIT_NUM = 0;
5615+
ZEND_JIT_EXIT_COUNTERS = 0;
5616+
5617+
zend_jit_trace_init_caches();
5618+
}

0 commit comments

Comments
 (0)