Skip to content

Commit dd5b6e2

Browse files
committed
Implement RECV class cache slot
1 parent 1f6fdde commit dd5b6e2

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

Zend/Optimizer/compact_literals.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
508508
case ZEND_RECV:
509509
case ZEND_RECV_VARIADIC:
510510
{
511-
size_t num_classes = type_num_classes(op_array, opline->op1.num);
512-
if (num_classes) {
513-
opline->extended_value = cache_size;
514-
cache_size += num_classes * sizeof(void *);
515-
}
511+
size_t num_classes = 1 + type_num_classes(op_array, opline->op1.num);
512+
opline->extended_value = cache_size;
513+
cache_size += num_classes * sizeof(void *);
516514
break;
517515
}
518516
case ZEND_VERIFY_RETURN_TYPE:

Zend/zend_compile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7757,7 +7757,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
77577757
if (type_ast) {
77587758
/* Allocate cache slot to speed-up run-time class resolution */
77597759
opline->extended_value =
7760-
zend_alloc_cache_slots(zend_type_get_num_classes(arg_info->type));
7760+
zend_alloc_cache_slots(1 + zend_type_get_num_classes(arg_info->type));
77617761
}
77627762

77637763
uint32_t arg_info_flags = _ZEND_ARG_INFO_FLAGS(is_ref, is_variadic, /* is_tentative */ 0)

Zend/zend_vm_def.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -5671,10 +5671,14 @@ ZEND_VM_HELPER(zend_verify_recv_arg_type_helper, ANY, ANY, zval *op_1)
56715671
USE_OPLINE
56725672

56735673
SAVE_OPLINE();
5674-
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), opline->op1.num, op_1, CACHE_ADDR(opline->extended_value)))) {
5674+
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), opline->op1.num, op_1, CACHE_ADDR(opline->extended_value) + 1))) {
56755675
HANDLE_EXCEPTION();
56765676
}
56775677

5678+
if (EXPECTED(Z_TYPE_P(op_1) == IS_OBJECT)) {
5679+
CACHE_PTR(opline->extended_value, Z_OBJCE_P(op_1));
5680+
}
5681+
56785682
ZEND_VM_NEXT_OPCODE();
56795683
}
56805684

@@ -5690,7 +5694,9 @@ ZEND_VM_HOT_HANDLER(63, ZEND_RECV, NUM, UNUSED, CACHE_SLOT)
56905694

56915695
param = EX_VAR(opline->result.var);
56925696

5693-
if (UNEXPECTED(!(opline->op2.num & (1u << Z_TYPE_P(param))))) {
5697+
if (UNEXPECTED(!(opline->op2.num & (1u << Z_TYPE_P(param))))
5698+
&& !(EXPECTED(Z_TYPE_P(param) == IS_OBJECT)
5699+
&& CACHED_PTR(opline->extended_value) == Z_OBJCE_P(param))) {
56945700
ZEND_VM_DISPATCH_TO_HELPER(zend_verify_recv_arg_type_helper, op_1, param);
56955701
}
56965702

@@ -5749,7 +5755,7 @@ ZEND_VM_HOT_HANDLER(64, ZEND_RECV_INIT, NUM, CONST, CACHE_SLOT)
57495755
ZEND_VM_C_LABEL(recv_init_check_type):
57505756
if ((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) {
57515757
SAVE_OPLINE();
5752-
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, CACHE_ADDR(opline->extended_value)))) {
5758+
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, CACHE_ADDR(opline->extended_value) + 1))) {
57535759
HANDLE_EXCEPTION();
57545760
}
57555761
}

Zend/zend_vm_execute.h

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/jit/zend_jit_helpers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg
19021902
const zend_op *opline = EX(opline);
19031903
void **cache_slot = CACHE_ADDR(opline->extended_value);
19041904
bool ret = zend_check_user_type_slow(
1905-
&arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ false);
1905+
&arg_info->type, arg, /* ref */ NULL, cache_slot + 1, /* is_return_type */ false);
19061906
if (UNEXPECTED(!ret)) {
19071907
zend_verify_arg_error(EX(func), arg_info, opline->op1.num, arg);
19081908
return 0;

0 commit comments

Comments
 (0)