@@ -3135,20 +3135,8 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
3135
3135
3136
3136
static int zend_needs_manual_jit (const zend_op_array * op_array )
3137
3137
{
3138
- if (op_array -> doc_comment ) {
3139
- const char * s = ZSTR_VAL (op_array -> doc_comment );
3140
- const char * p = strstr (s , "@jit" );
3141
-
3142
- if (p ) {
3143
- size_t l = ZSTR_LEN (op_array -> doc_comment );
3144
-
3145
- if ((p == s + 3 || * (p - 1 ) <= ' ' ) &&
3146
- (p + 6 == s + l || * (p + 4 ) <= ' ' )) {
3147
- return 1 ;
3148
- }
3149
- }
3150
- }
3151
- return 0 ;
3138
+ return op_array -> attributes &&
3139
+ zend_hash_str_exists (op_array -> attributes , "opcache\\jit" , sizeof ("opcache\\jit" )- 1 );
3152
3140
}
3153
3141
3154
3142
ZEND_EXT_API int zend_jit_op_array (zend_op_array * op_array , zend_script * script )
@@ -3190,7 +3178,7 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
3190
3178
return zend_jit_setup_hot_counters (op_array );
3191
3179
} else if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD ) {
3192
3180
return zend_real_jit_func (op_array , script , NULL );
3193
- } else if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3181
+ } else if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE ) {
3194
3182
if (zend_needs_manual_jit (op_array )) {
3195
3183
return zend_real_jit_func (op_array , script , NULL );
3196
3184
} else {
@@ -3231,9 +3219,9 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3231
3219
}
3232
3220
}
3233
3221
} else if (zend_jit_trigger == ZEND_JIT_ON_SCRIPT_LOAD ||
3234
- zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3222
+ zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE ) {
3235
3223
3236
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT ) {
3224
+ if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE ) {
3237
3225
int do_jit = 0 ;
3238
3226
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3239
3227
if (zend_needs_manual_jit (call_graph .op_arrays [i ])) {
@@ -3266,7 +3254,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3266
3254
}
3267
3255
3268
3256
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3269
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3257
+ if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE &&
3270
3258
!zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3271
3259
continue ;
3272
3260
}
@@ -3281,7 +3269,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3281
3269
3282
3270
if (ZCG (accel_directives ).jit_debug & ZEND_JIT_DEBUG_SSA ) {
3283
3271
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3284
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3272
+ if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE &&
3285
3273
!zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3286
3274
continue ;
3287
3275
}
@@ -3293,7 +3281,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
3293
3281
}
3294
3282
3295
3283
for (i = 0 ; i < call_graph .op_arrays_count ; i ++ ) {
3296
- if (zend_jit_trigger == ZEND_JIT_ON_DOC_COMMENT &&
3284
+ if (zend_jit_trigger == ZEND_JIT_ON_ATTRIBUTE &&
3297
3285
!zend_needs_manual_jit (call_graph .op_arrays [i ])) {
3298
3286
continue ;
3299
3287
}
@@ -3428,9 +3416,25 @@ static int zend_jit_make_stubs(void)
3428
3416
return 1 ;
3429
3417
}
3430
3418
3419
+ void zend_jit_validate_opcache_attribute (zval * attribute , int target )
3420
+ {
3421
+ if (target != ZEND_ATTRIBUTE_TARGET_METHOD && target != ZEND_ATTRIBUTE_TARGET_FUNCTION ) {
3422
+ zend_error (E_COMPILE_ERROR , "<<Opcache\\Jit>> attribute can only be declared on methods or functions." );
3423
+ }
3424
+ }
3425
+
3431
3426
ZEND_EXT_API int zend_jit_startup (zend_long jit , void * buf , size_t size , zend_bool reattached )
3432
3427
{
3433
3428
int ret ;
3429
+ zend_class_entry ce ;
3430
+ zend_attributes_internal_validator cb ;
3431
+
3432
+ INIT_NS_CLASS_ENTRY (ce , "Opcache\\Jit" , NULL );
3433
+ zend_ce_opcache_jit_attribute = zend_register_internal_class (& ce );
3434
+ zend_ce_opcache_jit_attribute -> ce_flags |= ZEND_ACC_FINAL ;
3435
+
3436
+ cb = zend_jit_validate_opcache_attribute ;
3437
+ zend_compiler_attribute_register (zend_ce_opcache_jit_attribute , & cb );
3434
3438
3435
3439
zend_jit_level = ZEND_JIT_LEVEL (jit );
3436
3440
zend_jit_trigger = ZEND_JIT_TRIGGER (jit );
0 commit comments