4646#include "ext/pcre/php_pcre.h"
4747#include "ext/standard/md5.h"
4848
49+ #ifdef HAVE_JIT
50+ # include "jit/zend_jit.h"
51+ #endif
52+
4953#ifndef ZEND_WIN32
5054#include <netdb.h>
5155#endif
@@ -2394,13 +2398,25 @@ int accel_activate(INIT_FUNC_ARGS)
23942398 accel_reset_pcre_cache ();
23952399 }
23962400
2401+
2402+ #ifdef HAVE_JIT
2403+ zend_jit_activate ();
2404+ #endif
2405+
23972406 if (ZCSG (preload_script )) {
23982407 preload_activate ();
23992408 }
24002409
24012410 return SUCCESS ;
24022411}
24032412
2413+ #ifdef HAVE_JIT
2414+ void accel_deactivate (void )
2415+ {
2416+ zend_jit_deactivate ();
2417+ }
2418+ #endif
2419+
24042420int accel_post_deactivate (void )
24052421{
24062422 if (ZCG (cwd )) {
@@ -2813,12 +2829,46 @@ static int accel_post_startup(void)
28132829 }
28142830 }
28152831
2832+ /* Initialize zend_func_info_rid */
2833+ zend_optimizer_startup ();
2834+
28162835/********************************************/
28172836/* End of non-SHM dependent initializations */
28182837/********************************************/
28192838 file_cache_only = ZCG (accel_directives ).file_cache_only ;
28202839 if (!file_cache_only ) {
2821- switch (zend_shared_alloc_startup (ZCG (accel_directives ).memory_consumption )) {
2840+ size_t shm_size = ZCG (accel_directives ).memory_consumption ;
2841+ #ifdef HAVE_JIT
2842+ size_t jit_size = 0 ;
2843+ zend_bool reattached = 0 ;
2844+
2845+ if (ZCG (accel_directives ).jit &&
2846+ ZCG (accel_directives ).jit_buffer_size ) {
2847+ size_t page_size ;
2848+
2849+ # ifdef _WIN32
2850+ SYSTEM_INFO system_info ;
2851+ GetSystemInfo (& system_info );
2852+ page_size = system_info .dwPageSize ;
2853+ # else
2854+ page_size = getpagesize ();
2855+ # endif
2856+ if (!page_size || (page_size & (page_size - 1 ))) {
2857+ zend_accel_error (ACCEL_LOG_FATAL , "Failure to initialize shared memory structures - can't get page size." );
2858+ abort ();
2859+ }
2860+ jit_size = ZCG (accel_directives ).jit_buffer_size ;
2861+ jit_size = ZEND_MM_ALIGNED_SIZE_EX (jit_size , page_size );
2862+ shm_size += jit_size ;
2863+ } else {
2864+ ZCG (accel_directives ).jit = 0 ;
2865+ ZCG (accel_directives ).jit_buffer_size = 0 ;
2866+ }
2867+
2868+ switch (zend_shared_alloc_startup (shm_size , jit_size )) {
2869+ #else
2870+ switch (zend_shared_alloc_startup (shm_size , 0 )) {
2871+ #endif
28222872 case ALLOC_SUCCESS :
28232873 if (zend_accel_init_shm () == FAILURE ) {
28242874 accel_startup_ok = 0 ;
@@ -2830,6 +2880,9 @@ static int accel_post_startup(void)
28302880 zend_accel_error (ACCEL_LOG_FATAL , "Failure to initialize shared memory structures - probably not enough shared memory." );
28312881 return SUCCESS ;
28322882 case SUCCESSFULLY_REATTACHED :
2883+ #ifdef HAVE_JIT
2884+ reattached = 1 ;
2885+ #endif
28332886 zend_shared_alloc_lock ();
28342887 accel_shared_globals = (zend_accel_shared_globals * ) ZSMMG (app_shared_globals );
28352888 zend_interned_strings_set_request_storage_handlers (accel_new_interned_string_for_php , accel_init_interned_string_for_php );
@@ -2861,6 +2914,16 @@ static int accel_post_startup(void)
28612914 zend_accel_init_auto_globals ();
28622915
28632916 zend_shared_alloc_lock ();
2917+ #ifdef HAVE_JIT
2918+ if (ZCG (accel_directives ).jit &&
2919+ ZCG (accel_directives ).jit_buffer_size &&
2920+ ZSMMG (reserved )) {
2921+ zend_jit_startup (ZCG (accel_directives ).jit , ZSMMG (reserved ), jit_size , reattached );
2922+ } else {
2923+ ZCG (accel_directives ).jit = 0 ;
2924+ ZCG (accel_directives ).jit_buffer_size = 0 ;
2925+ }
2926+ #endif
28642927 zend_shared_alloc_save_state ();
28652928 zend_shared_alloc_unlock ();
28662929
@@ -2944,6 +3007,10 @@ void accel_shutdown(void)
29443007 zend_ini_entry * ini_entry ;
29453008 zend_bool _file_cache_only = 0 ;
29463009
3010+ #ifdef HAVE_JIT
3011+ zend_jit_shutdown ();
3012+ #endif
3013+
29473014 zend_optimizer_shutdown ();
29483015
29493016 zend_accel_blacklist_shutdown (& accel_blacklist );
@@ -4244,7 +4311,11 @@ ZEND_EXT_API zend_extension zend_extension_entry = {
42444311 accel_startup , /* startup */
42454312 NULL , /* shutdown */
42464313 NULL , /* per-script activation */
4314+ #ifdef HAVE_JIT
4315+ accel_deactivate , /* per-script deactivation */
4316+ #else
42474317 NULL , /* per-script deactivation */
4318+ #endif
42484319 NULL , /* message handler */
42494320 NULL , /* op_array handler */
42504321 NULL , /* extended statement handler */
0 commit comments