Skip to content
Open
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
3 changes: 2 additions & 1 deletion ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
&& (opline->op2_type == IS_CONST
|| (opline->op2_type == IS_UNUSED
&& ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT))))) {
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_STATIC))))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any test - is there any way, like opcache dump, to dump the JIT and unit test this?

break;
}
if (!zend_jit_fetch_static_prop(&ctx, opline, op_array)) {
Expand Down
61 changes: 45 additions & 16 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -9281,6 +9281,31 @@ static int zend_jit_init_method_call(zend_jit_ctx *jit,
return 1;
}

/* Called scope of the current frame, as used by static:: and inherited by self::/parent:: calls. */
static ir_ref jit_called_scope(zend_jit_ctx *jit, const zend_op_array *op_array)
{
if (op_array->fn_flags & ZEND_ACC_STATIC) {
// JIT: Z_CE(EX(This))
return ir_LOAD_A(jit_EX(This.value.ref));
} else if (op_array->scope
&& op_array->function_name
&& !(op_array->fn_flags & ZEND_ACC_CLOSURE)) {
// JIT: Z_OBJCE(EX(This))
return ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce)));
} else {
/* Closures can be unbound, file/eval inherits This from the existing frame's scope. */
ir_ref if_object, values = IR_UNUSED;

if_object = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, jit_EX(This)), ir_CONST_U8(IS_OBJECT)));
ir_IF_TRUE(if_object);
ir_END_PHI_list(values,
ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce))));
ir_IF_FALSE(if_object);
ir_END_PHI_list(values, ir_LOAD_A(jit_EX(This.value.ref)));
return ir_PHI_list(values);
}
}

static int zend_jit_init_static_method_call(zend_jit_ctx *jit,
const zend_op *opline,
uint32_t b,
Expand Down Expand Up @@ -9412,21 +9437,7 @@ static int zend_jit_init_static_method_call(zend_jit_ctx *jit,
if (opline->op1_type == IS_UNUSED
&& ((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT ||
(opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF)) {
if (op_array->fn_flags & ZEND_ACC_STATIC) {
scope_ref = ir_LOAD_A(jit_EX(This.value.ref));
} else if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
ir_ref if_object, values = IR_UNUSED;

if_object = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, jit_EX(This)), ir_CONST_U8(IS_OBJECT)));
ir_IF_TRUE(if_object);
ir_END_PHI_list(values,
ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce))));
ir_IF_FALSE(if_object);
ir_END_PHI_list(values, ir_LOAD_A(jit_EX(This.value.ref)));
scope_ref = ir_PHI_list(values);
} else {
scope_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce)));
}
scope_ref = jit_called_scope(jit, op_array);
}
if (!zend_jit_push_call_frame(jit, opline, op_array, func, false, false, checked_stack, func_ref, scope_ref)) {
return 0;
Expand Down Expand Up @@ -16328,11 +16339,14 @@ static int zend_jit_fetch_static_prop(zend_jit_ctx *jit, const zend_op *opline,
uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS;
uint32_t flags;
ir_ref ref, ref2, if_cached, fast_path, cold_path, prop_info_ref, if_typed, if_def;
ir_ref slow_inputs = IR_UNUSED;
int fetch_type;
zend_property_info *known_prop_info = NULL;
zend_class_entry *ce;
bool is_static = opline->op2_type == IS_UNUSED
&& (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_STATIC;

ce = zend_get_known_class(op_array, opline, opline->op2_type, opline->op2);
ce = is_static ? NULL : zend_get_known_class(op_array, opline, opline->op2_type, opline->op2);
if (ce) {
zval *zv = RT_CONSTANT(opline, opline->op1);
zend_string *prop_name;
Expand Down Expand Up @@ -16375,6 +16389,17 @@ static int zend_jit_fetch_static_prop(zend_jit_ctx *jit, const zend_op *opline,
default: ZEND_UNREACHABLE();
}

if (is_static) {
/* The cache slot is polymorphic on the called scope. */
// JIT: if (CACHED_PTR(cache_slot) == called_scope)
ir_ref if_scope = ir_IF(ir_EQ(
ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), cache_slot)),
jit_called_scope(jit, op_array)));
ir_IF_FALSE_cold(if_scope);
ir_END_list(slow_inputs);
ir_IF_TRUE(if_scope);
}

// JIT: result = CACHED_PTR(cache_slot + sizeof(void *));
ref = ir_LOAD_A(
ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), cache_slot + sizeof(void*)));
Expand Down Expand Up @@ -16450,6 +16475,10 @@ static int zend_jit_fetch_static_prop(zend_jit_ctx *jit, const zend_op *opline,
fast_path = ir_END();

ir_IF_FALSE_cold(if_cached);
if (slow_inputs) {
ir_END_list(slow_inputs);
ir_MERGE_list(slow_inputs);
}
jit_SET_EX_OPLINE(jit, opline);
ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_fetch_static_property), jit_FP(jit), ir_CONST_I32(fetch_type));
zend_jit_check_exception_undef_result(jit, opline);
Expand Down
3 changes: 2 additions & 1 deletion ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6172,7 +6172,8 @@ static zend_vm_opcode_handler_t zend_jit_trace(zend_jit_trace_rec *trace_buffer,
&& (opline->op2_type == IS_CONST
|| (opline->op2_type == IS_UNUSED
&& ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT))))) {
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT
|| (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_STATIC))))) {
break;
}
if (!zend_jit_fetch_static_prop(&ctx, opline, op_array)) {
Expand Down
Loading