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,10 +3355,9 @@ 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 ) {
3360
+ if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE ) {
3342
3361
int do_jit = 0 ;
3343
3362
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3344
3363
if (zend_needs_manual_jit (call_graph .op_arrays [i ])) {
@@ -3350,6 +3369,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3350
3369
goto jit_failure ;
3351
3370
}
3352
3371
}
3372
+
3353
3373
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3354
3374
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3355
3375
if (info ) {
@@ -3371,10 +3391,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3371
3391
}
3372
3392
3373
3393
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 ])) {
3394
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3395
+ continue ;
3396
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3376
3397
continue ;
3377
3398
}
3399
+
3378
3400
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3379
3401
if (info ) {
3380
3402
if (zend_jit_op_array_analyze2 (call_graph .op_arrays [i ], script , & info -> ssa ) != SUCCESS ) {
@@ -3386,10 +3408,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3386
3408
3387
3409
if (ZCG (accel_directives ).jit_debug & ZEND_JIT_DEBUG_SSA ) {
3388
3410
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 ])) {
3411
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3412
+ continue ;
3413
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3391
3414
continue ;
3392
3415
}
3416
+
3393
3417
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3394
3418
if (info ) {
3395
3419
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 +3422,12 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3398
3422
}
3399
3423
3400
3424
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 ])) {
3425
+ if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD && zend_disable_jit (call_graph .op_arrays [i ])) {
3426
+ continue ;
3427
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE && !zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3403
3428
continue ;
3404
3429
}
3430
+
3405
3431
info = ZEND_FUNC_INFO (call_graph .op_arrays [i ]);
3406
3432
if (info ) {
3407
3433
if (zend_jit (call_graph .op_arrays [i ], & info -> ssa , NULL ) != SUCCESS ) {
@@ -3577,7 +3603,6 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
3577
3603
ZEND_EXT_API int zend_jit_startup (zend_long jit , void * buf , size_t size , zend_bool reattached )
3578
3604
{
3579
3605
int ret ;
3580
-
3581
3606
#ifdef ZTS
3582
3607
zend_jit_globals_id = ts_allocate_id (& zend_jit_globals_id , sizeof (zend_jit_globals ), (ts_allocate_ctor ) zend_jit_globals_ctor , NULL );
3583
3608
#else
0 commit comments