Skip to content

Commit 24a8065

Browse files
committed
Tracing JIT support for include() and generators
1 parent 1ca2fd2 commit 24a8065

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

Zend/zend_generators.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,11 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
742742
{
743743
/* Backup executor globals */
744744
zend_execute_data *original_execute_data = EG(current_execute_data);
745+
uint32_t original_jit_trace_num = EG(jit_trace_num);
745746

746747
/* Set executor globals */
747748
EG(current_execute_data) = generator->execute_data;
749+
EG(jit_trace_num) = 0;
748750

749751
/* We want the backtrace to look as if the generator function was
750752
* called from whatever method we are current running (e.g. next()).
@@ -777,6 +779,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
777779

778780
/* Restore executor globals */
779781
EG(current_execute_data) = original_execute_data;
782+
EG(jit_trace_num) = original_jit_trace_num;
780783

781784
/* If an exception was thrown in the generator we have to internally
782785
* rethrow it in the parent scope.

ext/opcache/Optimizer/zend_inference.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3511,7 +3511,6 @@ static zend_always_inline int _zend_update_type_info(
35113511
}
35123512
break;
35133513
case ZEND_CATCH:
3514-
case ZEND_INCLUDE_OR_EVAL:
35153514
/* Forbidden opcodes */
35163515
ZEND_UNREACHABLE();
35173516
break;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,10 +4456,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44564456
}
44574457
}
44584458
} else if (p->stop == ZEND_JIT_TRACE_STOP_LINK
4459+
|| p->stop == ZEND_JIT_TRACE_STOP_RETURN_HALT
44594460
|| p->stop == ZEND_JIT_TRACE_STOP_INTERPRETER) {
44604461
if (opline->opcode == ZEND_DO_UCALL
44614462
|| opline->opcode == ZEND_DO_FCALL
4462-
|| opline->opcode == ZEND_DO_FCALL_BY_NAME) {
4463+
|| opline->opcode == ZEND_DO_FCALL_BY_NAME
4464+
|| opline->opcode == ZEND_GENERATOR_CREATE
4465+
|| opline->opcode == ZEND_GENERATOR_RETURN
4466+
|| opline->opcode == ZEND_YIELD
4467+
|| opline->opcode == ZEND_YIELD_FROM
4468+
|| opline->opcode == ZEND_INCLUDE_OR_EVAL) {
44634469
zend_jit_trace_setup_ret_counter(opline, jit_extension->offset);
44644470
}
44654471
if (JIT_G(current_frame)
@@ -5499,12 +5505,6 @@ static zend_always_inline uint8_t zend_jit_trace_supported(const zend_op *opline
54995505
case ZEND_CATCH:
55005506
case ZEND_FAST_CALL:
55015507
case ZEND_FAST_RET:
5502-
case ZEND_GENERATOR_CREATE:
5503-
case ZEND_GENERATOR_RETURN:
5504-
case ZEND_EXIT:
5505-
case ZEND_YIELD:
5506-
case ZEND_YIELD_FROM:
5507-
case ZEND_INCLUDE_OR_EVAL:
55085508
return ZEND_JIT_TRACE_UNSUPPORTED;
55095509
default:
55105510
return ZEND_JIT_TRACE_SUPPORTED;

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
713713
if (EX(call)->func->type == ZEND_INTERNAL_FUNCTION) {
714714
TRACE_RECORD(ZEND_JIT_TRACE_DO_ICALL, 0, EX(call)->func);
715715
}
716+
} else if (opline->opcode == ZEND_INCLUDE_OR_EVAL) {
717+
stop = ZEND_JIT_TRACE_STOP_INTERPRETER;
718+
break;
716719
}
717720

718721
handler = (zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
@@ -975,7 +978,8 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
975978
TRACE_END(ZEND_JIT_TRACE_END, stop, end_opline);
976979

977980
#ifdef HAVE_GCC_GLOBAL_REGS
978-
if (stop != ZEND_JIT_TRACE_STOP_HALT) {
981+
if (stop != ZEND_JIT_TRACE_STOP_HALT
982+
&& stop != ZEND_JIT_TRACE_STOP_RETURN_HALT) {
979983
EX(opline) = opline;
980984
}
981985
#endif

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,10 @@ static int zend_jit_trace_handler(dasm_State **Dst, const zend_op_array *op_arra
31833183

31843184
if (zend_jit_trace_may_exit(op_array, opline)) {
31853185
// TODO: try to avoid this check ???
3186-
if (opline->opcode == ZEND_RETURN || opline->opcode == ZEND_RETURN_BY_REF) {
3186+
if (opline->opcode == ZEND_RETURN ||
3187+
opline->opcode == ZEND_RETURN_BY_REF ||
3188+
opline->opcode == ZEND_GENERATOR_CREATE) {
3189+
31873190
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
31883191
| cmp IP, zend_jit_halt_op
31893192
| je ->trace_halt
@@ -3194,8 +3197,17 @@ static int zend_jit_trace_handler(dasm_State **Dst, const zend_op_array *op_arra
31943197
| test eax, eax
31953198
| jl ->trace_halt
31963199
}
3200+
} else if (opline->opcode == ZEND_EXIT ||
3201+
opline->opcode == ZEND_GENERATOR_RETURN ||
3202+
opline->opcode == ZEND_YIELD ||
3203+
opline->opcode == ZEND_YIELD_FROM) {
3204+
| jmp ->trace_halt
31973205
}
3198-
if (trace->op != ZEND_JIT_TRACE_END || trace->stop != ZEND_JIT_TRACE_STOP_RETURN) {
3206+
if (trace->op != ZEND_JIT_TRACE_END ||
3207+
(trace->stop != ZEND_JIT_TRACE_STOP_RETURN &&
3208+
trace->stop != ZEND_JIT_TRACE_STOP_RETURN_HALT &&
3209+
trace->stop != ZEND_JIT_TRACE_STOP_INTERPRETER)) {
3210+
31993211
const zend_op *next_opline = trace->opline;
32003212
const zend_op *exit_opline = NULL;
32013213
uint32_t exit_point;

0 commit comments

Comments
 (0)