Skip to content

Implement RECV class cache slot #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Zend/Optimizer/compact_literals.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
case ZEND_RECV:
case ZEND_RECV_VARIADIC:
{
size_t num_classes = type_num_classes(op_array, opline->op1.num);
if (num_classes) {
opline->extended_value = cache_size;
cache_size += num_classes * sizeof(void *);
}
size_t num_classes = 1 + type_num_classes(op_array, opline->op1.num);
opline->extended_value = cache_size;
cache_size += num_classes * sizeof(void *);
break;
}
case ZEND_VERIFY_RETURN_TYPE:
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7757,7 +7757,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
if (type_ast) {
/* Allocate cache slot to speed-up run-time class resolution */
opline->extended_value =
zend_alloc_cache_slots(zend_type_get_num_classes(arg_info->type));
zend_alloc_cache_slots(1 + zend_type_get_num_classes(arg_info->type));
}

uint32_t arg_info_flags = _ZEND_ARG_INFO_FLAGS(is_ref, is_variadic, /* is_tentative */ 0)
Expand Down
12 changes: 9 additions & 3 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -5671,10 +5671,14 @@ ZEND_VM_HELPER(zend_verify_recv_arg_type_helper, ANY, ANY, zval *op_1)
USE_OPLINE

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

if (EXPECTED(Z_TYPE_P(op_1) == IS_OBJECT)) {
CACHE_PTR(opline->extended_value, Z_OBJCE_P(op_1));
}

ZEND_VM_NEXT_OPCODE();
}

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

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

if (UNEXPECTED(!(opline->op2.num & (1u << Z_TYPE_P(param))))) {
if (UNEXPECTED(!(opline->op2.num & (1u << Z_TYPE_P(param))))
&& !(EXPECTED(Z_TYPE_P(param) == IS_OBJECT)
&& CACHED_PTR(opline->extended_value) == Z_OBJCE_P(param))) {
ZEND_VM_DISPATCH_TO_HELPER(zend_verify_recv_arg_type_helper, op_1, param);
}

Expand Down Expand Up @@ -5749,7 +5755,7 @@ ZEND_VM_HOT_HANDLER(64, ZEND_RECV_INIT, NUM, CONST, CACHE_SLOT)
ZEND_VM_C_LABEL(recv_init_check_type):
if ((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) {
SAVE_OPLINE();
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, CACHE_ADDR(opline->extended_value)))) {
if (UNEXPECTED(!zend_verify_recv_arg_type(EX(func), arg_num, param, CACHE_ADDR(opline->extended_value) + 1))) {
HANDLE_EXCEPTION();
}
}
Expand Down
12 changes: 9 additions & 3 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg
const zend_op *opline = EX(opline);
void **cache_slot = CACHE_ADDR(opline->extended_value);
bool ret = zend_check_user_type_slow(
&arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ false);
&arg_info->type, arg, /* ref */ NULL, cache_slot + 1, /* is_return_type */ false);
if (UNEXPECTED(!ret)) {
zend_verify_arg_error(EX(func), arg_info, opline->op1.num, arg);
return 0;
Expand Down
Loading