Skip to content

Commit 4dd445c

Browse files
committed
ext/opcache/jit/zend_jit_trace: move code to _zend_jit_compile_root_trace()
This eliminates `goto` and simplifies error handling.
1 parent b83ab47 commit 4dd445c

File tree

1 file changed

+85
-85
lines changed

1 file changed

+85
-85
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7037,13 +7037,93 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
70377037
return handler;
70387038
}
70397039

7040+
/**
7041+
* Helper function for zend_jit_compile_root_trace().
7042+
*/
7043+
static zend_jit_trace_stop _zend_jit_compile_root_trace(zend_jit_trace_rec *const trace_buffer, const zend_op *opline, zend_op_trace_info *const trace_info)
7044+
{
7045+
zend_jit_trace_exit_info exit_info[ZEND_JIT_TRACE_MAX_EXITS];
7046+
zend_jit_trace_info *const t = &zend_jit_traces[ZEND_JIT_TRACE_NUM];
7047+
7048+
t->id = ZEND_JIT_TRACE_NUM;
7049+
t->root = ZEND_JIT_TRACE_NUM;
7050+
t->parent = 0;
7051+
t->link = 0;
7052+
t->exit_count = 0;
7053+
t->child_count = 0;
7054+
t->stack_map_size = 0;
7055+
t->flags = 0;
7056+
t->polymorphism = 0;
7057+
t->jmp_table_size = 0;
7058+
t->op_array = trace_buffer[0].op_array;
7059+
t->opline = trace_buffer[1].opline;
7060+
t->exit_info = exit_info;
7061+
t->stack_map = NULL;
7062+
7063+
const uint8_t orig_trigger = JIT_G(trigger);
7064+
JIT_G(trigger) = ZEND_JIT_ON_HOT_TRACE;
7065+
7066+
const void *handler = zend_jit_trace(trace_buffer, 0, 0);
7067+
7068+
JIT_G(trigger) = orig_trigger;
7069+
7070+
if (handler) {
7071+
t->exit_info = NULL;
7072+
if (t->exit_count) {
7073+
/* reallocate exit_info into shared memory */
7074+
t->exit_info = (zend_jit_trace_exit_info*)zend_shared_alloc_copy(exit_info,
7075+
sizeof(zend_jit_trace_exit_info) * t->exit_count);
7076+
7077+
if (!t->exit_info) {
7078+
if (t->stack_map) {
7079+
efree(t->stack_map);
7080+
}
7081+
return ZEND_JIT_TRACE_STOP_NO_SHM;
7082+
}
7083+
}
7084+
7085+
if (t->stack_map_size) {
7086+
zend_jit_trace_stack *shared_stack_map = (zend_jit_trace_stack*)zend_shared_alloc_copy(
7087+
t->stack_map,
7088+
t->stack_map_size * sizeof(zend_jit_trace_stack));
7089+
efree(t->stack_map);
7090+
t->stack_map = shared_stack_map;
7091+
if (!shared_stack_map) {
7092+
return ZEND_JIT_TRACE_STOP_NO_SHM;
7093+
}
7094+
}
7095+
7096+
t->exit_counters = ZEND_JIT_EXIT_COUNTERS;
7097+
ZEND_JIT_EXIT_COUNTERS += t->exit_count;
7098+
7099+
((zend_op*)opline)->handler = handler;
7100+
7101+
ZEND_JIT_TRACE_NUM++;
7102+
trace_info->trace_flags |= ZEND_JIT_TRACE_JITED;
7103+
7104+
if ((JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_EXIT_INFO) != 0
7105+
&& t->exit_count > 0) {
7106+
zend_jit_dump_exit_info(t);
7107+
}
7108+
7109+
return ZEND_JIT_TRACE_STOP_COMPILED;
7110+
} else if (t->exit_count >= ZEND_JIT_TRACE_MAX_EXITS ||
7111+
ZEND_JIT_EXIT_COUNTERS + t->exit_count >= JIT_G(max_exit_counters)) {
7112+
if (t->stack_map) {
7113+
efree(t->stack_map);
7114+
}
7115+
return ZEND_JIT_TRACE_STOP_TOO_MANY_EXITS;
7116+
} else {
7117+
if (t->stack_map) {
7118+
efree(t->stack_map);
7119+
}
7120+
return ZEND_JIT_TRACE_STOP_COMPILER_ERROR;
7121+
}
7122+
}
7123+
70407124
static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace_buffer, const zend_op *opline, size_t offset)
70417125
{
70427126
zend_jit_trace_stop ret;
7043-
const void *handler;
7044-
uint8_t orig_trigger;
7045-
zend_jit_trace_info *t = NULL;
7046-
zend_jit_trace_exit_info exit_info[ZEND_JIT_TRACE_MAX_EXITS];
70477127
bool do_bailout = false;
70487128

70497129
zend_shared_alloc_lock();
@@ -7060,81 +7140,7 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace
70607140
SHM_UNPROTECT();
70617141
zend_jit_unprotect();
70627142

7063-
t = &zend_jit_traces[ZEND_JIT_TRACE_NUM];
7064-
7065-
t->id = ZEND_JIT_TRACE_NUM;
7066-
t->root = ZEND_JIT_TRACE_NUM;
7067-
t->parent = 0;
7068-
t->link = 0;
7069-
t->exit_count = 0;
7070-
t->child_count = 0;
7071-
t->stack_map_size = 0;
7072-
t->flags = 0;
7073-
t->polymorphism = 0;
7074-
t->jmp_table_size = 0;
7075-
t->op_array = trace_buffer[0].op_array;
7076-
t->opline = trace_buffer[1].opline;
7077-
t->exit_info = exit_info;
7078-
t->stack_map = NULL;
7079-
7080-
orig_trigger = JIT_G(trigger);
7081-
JIT_G(trigger) = ZEND_JIT_ON_HOT_TRACE;
7082-
7083-
handler = zend_jit_trace(trace_buffer, 0, 0);
7084-
7085-
JIT_G(trigger) = orig_trigger;
7086-
7087-
if (handler) {
7088-
t->exit_info = NULL;
7089-
if (t->exit_count) {
7090-
/* reallocate exit_info into shared memory */
7091-
t->exit_info = (zend_jit_trace_exit_info*)zend_shared_alloc_copy(exit_info,
7092-
sizeof(zend_jit_trace_exit_info) * t->exit_count);
7093-
7094-
if (!t->exit_info) {
7095-
if (t->stack_map) {
7096-
efree(t->stack_map);
7097-
}
7098-
ret = ZEND_JIT_TRACE_STOP_NO_SHM;
7099-
goto exit;
7100-
}
7101-
}
7102-
7103-
if (t->stack_map_size) {
7104-
zend_jit_trace_stack *shared_stack_map = (zend_jit_trace_stack*)zend_shared_alloc_copy(
7105-
t->stack_map,
7106-
t->stack_map_size * sizeof(zend_jit_trace_stack));
7107-
efree(t->stack_map);
7108-
t->stack_map = shared_stack_map;
7109-
if (!shared_stack_map) {
7110-
ret = ZEND_JIT_TRACE_STOP_NO_SHM;
7111-
goto exit;
7112-
}
7113-
}
7114-
7115-
t->exit_counters = ZEND_JIT_EXIT_COUNTERS;
7116-
ZEND_JIT_EXIT_COUNTERS += t->exit_count;
7117-
7118-
((zend_op*)opline)->handler = handler;
7119-
7120-
ZEND_JIT_TRACE_NUM++;
7121-
trace_info->trace_flags |= ZEND_JIT_TRACE_JITED;
7122-
7123-
ret = ZEND_JIT_TRACE_STOP_COMPILED;
7124-
} else if (t->exit_count >= ZEND_JIT_TRACE_MAX_EXITS ||
7125-
ZEND_JIT_EXIT_COUNTERS + t->exit_count >= JIT_G(max_exit_counters)) {
7126-
if (t->stack_map) {
7127-
efree(t->stack_map);
7128-
}
7129-
ret = ZEND_JIT_TRACE_STOP_TOO_MANY_EXITS;
7130-
} else {
7131-
if (t->stack_map) {
7132-
efree(t->stack_map);
7133-
}
7134-
ret = ZEND_JIT_TRACE_STOP_COMPILER_ERROR;
7135-
}
7136-
7137-
exit:;
7143+
ret = _zend_jit_compile_root_trace(trace_buffer, opline, trace_info);
71387144
} zend_catch {
71397145
do_bailout = true;
71407146
} zend_end_try();
@@ -7149,12 +7155,6 @@ exit:;
71497155
zend_bailout();
71507156
}
71517157

7152-
if ((JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_EXIT_INFO) != 0
7153-
&& ret == ZEND_JIT_TRACE_STOP_COMPILED
7154-
&& t->exit_count > 0) {
7155-
zend_jit_dump_exit_info(t);
7156-
}
7157-
71587158
return ret;
71597159
}
71607160

0 commit comments

Comments
 (0)