-
Notifications
You must be signed in to change notification settings - Fork 8k
JIT for INIT_STATIC_METHOD_CALL #16206
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3020,6 +3020,9 @@ static void zend_jit_setup_disasm(void) | |||||
REGISTER_HELPER(zend_jit_find_method_tmp_helper); | ||||||
REGISTER_HELPER(zend_jit_push_static_metod_call_frame); | ||||||
REGISTER_HELPER(zend_jit_push_static_metod_call_frame_tmp); | ||||||
REGISTER_HELPER(zend_jit_find_class_helper); | ||||||
REGISTER_HELPER(zend_jit_find_static_method_helper); | ||||||
REGISTER_HELPER(zend_jit_push_this_metod_call_frame); | ||||||
REGISTER_HELPER(zend_jit_free_trampoline_helper); | ||||||
REGISTER_HELPER(zend_jit_verify_return_slow); | ||||||
REGISTER_HELPER(zend_jit_deprecated_helper); | ||||||
|
@@ -8542,6 +8545,9 @@ static int zend_jit_push_call_frame(zend_jit_ctx *jit, const zend_op *opline, co | |||||
ir_CONST_U32(ZEND_CALL_HAS_THIS | ZEND_CALL_RELEASE_THIS))); | ||||||
} | ||||||
} | ||||||
} else if (opline->opcode == ZEND_INIT_STATIC_METHOD_CALL) { | ||||||
// JIT: Z_CE(call->This) = called_scope; | ||||||
ir_STORE(jit_CALL(rx, This), this_ref); | ||||||
} else if (!is_closure) { | ||||||
// JIT: Z_CE(call->This) = called_scope; | ||||||
ir_STORE(jit_CALL(rx, This), IR_NULL); | ||||||
|
@@ -9061,6 +9067,208 @@ static int zend_jit_init_method_call(zend_jit_ctx *jit, | |||||
return 1; | ||||||
} | ||||||
|
||||||
static int zend_jit_init_static_method_call(zend_jit_ctx *jit, | ||||||
const zend_op *opline, | ||||||
uint32_t b, | ||||||
const zend_op_array *op_array, | ||||||
zend_ssa *ssa, | ||||||
const zend_ssa_op *ssa_op, | ||||||
int call_level, | ||||||
zend_jit_trace_rec *trace, | ||||||
int checked_stack) | ||||||
{ | ||||||
zend_func_info *info = ZEND_FUNC_INFO(op_array); | ||||||
zend_call_info *call_info = NULL; | ||||||
zend_class_entry *ce = NULL; | ||||||
zend_function *func = NULL; | ||||||
ir_ref func_ref, func_ref2, scope_ref, scope_ref2, if_cached, cold_path, ref; | ||||||
ir_ref if_static = IR_UNUSED; | ||||||
|
||||||
if (info) { | ||||||
call_info = info->callee_info; | ||||||
while (call_info && call_info->caller_init_opline != opline) { | ||||||
call_info = call_info->next_callee; | ||||||
} | ||||||
if (call_info && call_info->callee_func && !call_info->is_prototype) { | ||||||
func = call_info->callee_func; | ||||||
} | ||||||
} | ||||||
|
||||||
if (opline->op1_type == IS_CONST) { | ||||||
|
||||||
zval *zv = RT_CONSTANT(opline, opline->op1); | ||||||
zend_string *class_name; | ||||||
|
||||||
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); | ||||||
class_name = Z_STR_P(zv); | ||||||
ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); | ||||||
|
||||||
if (ce && (ce->type == ZEND_INTERNAL_CLASS || ce->info.user.filename != op_array->filename)) { | ||||||
ce = NULL; | ||||||
} | ||||||
} else { | ||||||
ZEND_ASSERT(opline->op1_type == IS_UNUSED); | ||||||
if ((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF) { | ||||||
ce = op_array->scope; | ||||||
} else { | ||||||
ZEND_ASSERT((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT); | ||||||
ce = op_array->scope; | ||||||
if (ce) { | ||||||
if (ce->parent) { | ||||||
ce = ce->parent; | ||||||
if (ce->type == ZEND_INTERNAL_CLASS || ce->info.user.filename != op_array->filename) { | ||||||
ce = NULL; | ||||||
} | ||||||
} else { | ||||||
ce = NULL; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
if (!func && ce) { | ||||||
zval *zv = RT_CONSTANT(opline, opline->op2); | ||||||
zend_string *method_name; | ||||||
|
||||||
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); | ||||||
method_name = Z_STR_P(zv); | ||||||
zv = zend_hash_find(&ce->function_table, method_name); | ||||||
if (zv) { | ||||||
zend_function *fn = Z_PTR_P(zv); | ||||||
|
||||||
if (fn->common.scope == op_array->scope | ||||||
|| (fn->common.fn_flags & ZEND_ACC_PUBLIC) | ||||||
|| ((fn->common.fn_flags & ZEND_ACC_PROTECTED) | ||||||
&& instanceof_function_slow(op_array->scope, fn->common.scope))) { | ||||||
func = fn; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
if (jit->delayed_call_level) { | ||||||
if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { | ||||||
return 0; | ||||||
} | ||||||
} | ||||||
|
||||||
// JIT: fbc = CACHED_PTR(opline->result.num + sizeof(void*)); | ||||||
func_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num + sizeof(void*))); | ||||||
|
||||||
// JIT: if (fbc) | ||||||
if_cached = ir_IF(func_ref); | ||||||
ir_IF_FALSE_cold(if_cached); | ||||||
|
||||||
jit_SET_EX_OPLINE(jit, opline); | ||||||
scope_ref2 = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_class_helper), jit_FP(jit)); | ||||||
ir_GUARD(scope_ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); | ||||||
|
||||||
func_ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_static_method_helper), jit_FP(jit), scope_ref2); | ||||||
ir_GUARD(func_ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); | ||||||
|
||||||
cold_path = ir_END(); | ||||||
|
||||||
ir_IF_TRUE(if_cached); | ||||||
if (ce && (ce->ce_flags & ZEND_ACC_IMMUTABLE) && (ce->ce_flags & ZEND_ACC_LINKED)) { | ||||||
scope_ref = ir_CONST_ADDR(ce); | ||||||
} else { | ||||||
scope_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num)); | ||||||
} | ||||||
|
||||||
ir_MERGE_2(cold_path, ir_END()); | ||||||
func_ref = ir_PHI_2(IR_ADDR, func_ref2, func_ref); | ||||||
scope_ref = ir_PHI_2(IR_ADDR, scope_ref2, scope_ref); | ||||||
|
||||||
if ((!func || zend_jit_may_be_modified(func, op_array)) | ||||||
&& trace | ||||||
&& trace->op == ZEND_JIT_TRACE_INIT_CALL | ||||||
&& trace->func | ||||||
#ifdef _WIN32 | ||||||
&& trace->func->type != ZEND_INTERNAL_FUNCTION | ||||||
#endif | ||||||
) { | ||||||
int32_t exit_point; | ||||||
const void *exit_addr; | ||||||
|
||||||
exit_point = zend_jit_trace_get_exit_point(opline, func ? ZEND_JIT_EXIT_INVALIDATE : 0); | ||||||
exit_addr = zend_jit_trace_get_exit_addr(exit_point); | ||||||
if (!exit_addr) { | ||||||
return 0; | ||||||
} | ||||||
|
||||||
// jit->trace->exit_info[exit_point].poly_func_ref = func_ref; | ||||||
// jit->trace->exit_info[exit_point].poly_this_ref = scope_ref; | ||||||
|
||||||
func = (zend_function*)trace->func; | ||||||
|
||||||
if (func->type == ZEND_USER_FUNCTION && | ||||||
(!(func->common.fn_flags & ZEND_ACC_IMMUTABLE) || | ||||||
(func->common.fn_flags & ZEND_ACC_CLOSURE) || | ||||||
!func->common.function_name)) { | ||||||
const zend_op *opcodes = func->op_array.opcodes; | ||||||
|
||||||
ir_GUARD( | ||||||
ir_EQ( | ||||||
ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, opcodes))), | ||||||
ir_CONST_ADDR(opcodes)), | ||||||
ir_CONST_ADDR(exit_addr)); | ||||||
} else { | ||||||
ir_GUARD(ir_EQ(func_ref, ir_CONST_ADDR(func)), ir_CONST_ADDR(exit_addr)); | ||||||
} | ||||||
} | ||||||
|
||||||
if (!func || !(func->common.fn_flags & ZEND_ACC_STATIC)) { | ||||||
if (!func) { | ||||||
// JIT: if (fbc->common.fn_flags & ZEND_ACC_STATIC) { | ||||||
if_static = ir_IF(ir_AND_U32( | ||||||
ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags))), | ||||||
ir_CONST_U32(ZEND_ACC_STATIC))); | ||||||
ir_IF_FALSE_cold(if_static); | ||||||
} | ||||||
|
||||||
ref = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_push_this_metod_call_frame), | ||||||
scope_ref, | ||||||
func_ref, | ||||||
ir_CONST_U32(opline->extended_value)); | ||||||
ir_GUARD(ref, jit_STUB_ADDR(jit, jit_stub_exception_handler)); | ||||||
jit_STORE_IP(jit, ref); | ||||||
|
||||||
if (!func) { | ||||||
cold_path = ir_END(); | ||||||
ir_IF_TRUE(if_static); | ||||||
} | ||||||
} | ||||||
|
||||||
if (!func || (func->common.fn_flags & ZEND_ACC_STATIC)) { | ||||||
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 { | ||||||
scope_ref = ir_LOAD_A(ir_ADD_OFFSET(jit_EX(This.value.ref), offsetof(zend_object, ce))); | ||||||
|
scope_ref = ir_LOAD_A(ir_ADD_OFFSET(jit_EX(This.value.ref), offsetof(zend_object, ce))); | |
scope_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You are right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: metod -> method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.