23
23
#include "Zend/zend_exceptions.h"
24
24
#include "Zend/zend_constants.h"
25
25
#include "zend_smart_str.h"
26
+ #include "Zend/zend_attributes.h"
26
27
#include "jit/zend_jit.h"
27
28
28
29
#ifdef HAVE_JIT
@@ -3233,21 +3234,38 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
3233
3234
return SUCCESS ;
3234
3235
}
3235
3236
3237
+ static int zend_disable_jit (const zend_op_array * op_array )
3238
+ {
3239
+ zend_attribute * jit = zend_get_attribute_str (op_array -> attributes , "opcache\\jit" , sizeof ("opcache\\jit" )- 1 , 0 );
3240
+
3241
+ if (jit == NULL || jit -> argc == 0 ) {
3242
+ return 0 ;
3243
+ }
3244
+
3245
+ if (Z_TYPE (jit -> argv [0 ]) == IS_FALSE ) {
3246
+ return 1 ;
3247
+ }
3248
+
3249
+ return 0 ;
3250
+ }
3251
+
3236
3252
static int zend_needs_manual_jit (const zend_op_array * op_array )
3237
3253
{
3238
- if (op_array -> doc_comment ) {
3239
- const char * s = ZSTR_VAL (op_array -> doc_comment );
3240
- const char * p = strstr (s , "@jit" );
3254
+ zend_attribute * jit = zend_get_attribute_str (op_array -> attributes , "opcache\\jit" , sizeof ("opcache\\jit" )- 1 , 0 );
3241
3255
3242
- if (p ) {
3243
- size_t l = ZSTR_LEN (op_array -> doc_comment );
3256
+ if (jit == NULL ) {
3257
+ return 0 ;
3258
+ }
3244
3259
3245
- if ((p == s + 3 || * (p - 1 ) <= ' ' ) &&
3246
- (p + 6 == s + l || * (p + 4 ) <= ' ' )) {
3247
- return 1 ;
3248
- }
3260
+ if (jit -> argc == 0 ) {
3261
+ return 1 ;
3262
+ } else if (jit -> argc == 1 ) {
3263
+ // todo: evaluate "trueish"?
3264
+ if (Z_TYPE (jit -> argv [0 ]) == IS_TRUE ) {
3265
+ return 1 ;
3249
3266
}
3250
3267
}
3268
+
3251
3269
return 0 ;
3252
3270
}
3253
3271
@@ -3259,6 +3277,14 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
3259
3277
return FAILURE ;
3260
3278
}
3261
3279
3280
+ if (zend_disable_jit (op_array ) == 1 ) {
3281
+ return SUCCESS ;
3282
+ }
3283
+
3284
+ if (zend_needs_manual_jit (op_array ) == 1 ) {
3285
+ return zend_real_jit_func (op_array , script , NULL );
3286
+ }
3287
+
3262
3288
if (zend_jit_trigger == ZEND_JIT_ON_FIRST_EXEC ) {
3263
3289
zend_op * opline = op_array -> opcodes ;
3264
3290
@@ -3294,12 +3320,6 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
3294
3320
return zend_jit_setup_hot_trace_counters (op_array );
3295
3321
} else if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD ) {
3296
3322
return zend_real_jit_func (op_array , script , NULL );
3297
- } else if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3298
- if (zend_needs_manual_jit (op_array )) {
3299
- return zend_real_jit_func (op_array , script , NULL );
3300
- } else {
3301
- return SUCCESS ;
3302
- }
3303
3323
} else {
3304
3324
ZEND_ASSERT (0 );
3305
3325
}
@@ -3335,21 +3355,8 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3335
3355
goto jit_failure ;
3336
3356
}
3337
3357
}
3338
- } else if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD ||
3339
- zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3358
+ } else if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD || zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE ) {
3340
3359
3341
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3342
- int do_jit = 0 ;
3343
- for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3344
- if (zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3345
- do_jit = 1 ;
3346
- break ;
3347
- }
3348
- }
3349
- if (!do_jit ) {
3350
- goto jit_failure ;
3351
- }
3352
- }
3353
3360
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3354
3361
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3355
3362
if (info ) {
@@ -3371,10 +3378,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3371
3378
}
3372
3379
3373
3380
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3374
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3375
- !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3381
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3382
+ continue ;
3383
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3376
3384
continue ;
3377
3385
}
3386
+
3378
3387
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3379
3388
if (info ) {
3380
3389
if (zend_jit_op_array_analyze2 (call_graph .op_arrays [i ], script , & info -> ssa ) != SUCCESS ) {
@@ -3386,10 +3395,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3386
3395
3387
3396
if (ZCG (accel_directives ).jit_debug & ZEND_JIT_DEBUG_SSA ) {
3388
3397
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3389
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3390
- !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3398
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3399
+ continue ;
3400
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3391
3401
continue ;
3392
3402
}
3403
+
3393
3404
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3394
3405
if (info ) {
3395
3406
zend_dump_op_array (call_graph .op_arrays [i ], ZEND_DUMP_HIDE_UNREACHABLE |ZEND_DUMP_RC_INFERENCE |ZEND_DUMP_SSA , "JIT" , & info -> ssa );
@@ -3398,10 +3409,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3398
3409
}
3399
3410
3400
3411
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3401
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3402
- !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3412
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3413
+ continue ;
3414
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3403
3415
continue ;
3404
3416
}
3417
+
3405
3418
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3406
3419
if (info ) {
3407
3420
if (zend_jit (call_graph .op_arrays [i ], & info -> ssa , NULL ) != SUCCESS ) {
@@ -3577,7 +3590,6 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
3577
3590
ZEND_EXT_API int zend_jit_startup (zend_long jit , void * buf , size_t size , zend_bool reattached )
3578
3591
{
3579
3592
int ret ;
3580
-
3581
3593
#ifdef ZTS
3582
3594
zend_jit_globals_id = ts_allocate_id (& zend_jit_globals_id , sizeof (zend_jit_globals ), (ts_allocate_ctor ) zend_jit_globals_ctor , NULL );
3583
3595
#else
0 commit comments