-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
GH-104584: Remove ip_offset
and simplify EXIT_TRACE
#108961
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3006,6 +3006,7 @@ dummy_func( | |
tstate->py_recursion_remaining--; | ||
LOAD_SP(); | ||
LOAD_IP(); | ||
frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame)); | ||
#if LLTRACE && TIER_ONE | ||
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS()); | ||
if (lltrace < 0) { | ||
|
@@ -3794,7 +3795,7 @@ dummy_func( | |
} | ||
|
||
op(SAVE_IP, (--)) { | ||
frame->prev_instr = ip_offset + oparg; | ||
frame->prev_instr = (_Py_CODEUNIT *)(uintptr_t)operand; | ||
} | ||
|
||
op(SAVE_CURRENT_IP, (--)) { | ||
|
@@ -3808,10 +3809,7 @@ dummy_func( | |
} | ||
|
||
op(EXIT_TRACE, (--)) { | ||
frame->prev_instr--; // Back up to just before destination | ||
_PyFrame_SetStackPointer(frame, stack_pointer); | ||
Py_DECREF(self); | ||
return frame; | ||
goto deoptimize; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In uops debug mode ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It definitely is annoying. Actual deoptimizations are rare, but exiting a trace is common. So I get a lot of log spam containing endless repetitions of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is tier 2 only, so it doesn't matter much what the implementation is. I can see it changing quite a few times in the near future. |
||
} | ||
|
||
op(INSERT, (unused[oparg], top -- top, unused[oparg])) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,7 +396,7 @@ stack_pointer = _PyFrame_GetStackPointer(frame); | |
#if TIER_TWO | ||
|
||
#define LOAD_IP() \ | ||
do { ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive; } while (0) | ||
do {} while (0) | ||
Comment on lines
398
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be curious what @markshannon thinks of this change. It makes me think that the "abstractions" embodied by these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems good to me. (In this context "virtual" means tracked by the region selector ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
#define STORE_SP() \ | ||
_PyFrame_SetStackPointer(frame, stack_pointer) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,7 +479,6 @@ translate_bytecode_to_trace( | |
#define TRACE_STACK_PUSH() \ | ||
if (trace_stack_depth >= TRACE_STACK_SIZE) { \ | ||
DPRINTF(2, "Trace stack overflow\n"); \ | ||
ADD_TO_TRACE(SAVE_IP, 0, 0); \ | ||
goto done; \ | ||
} \ | ||
trace_stack[trace_stack_depth].code = code; \ | ||
|
@@ -503,7 +502,7 @@ translate_bytecode_to_trace( | |
top: // Jump here after _PUSH_FRAME | ||
for (;;) { | ||
RESERVE_RAW(2, "epilogue"); // Always need space for SAVE_IP and EXIT_TRACE | ||
ADD_TO_TRACE(SAVE_IP, INSTR_IP(instr, code), 0); | ||
ADD_TO_TRACE(SAVE_IP, 0, (uintptr_t)instr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I ask to keep (redundantly) the If you worry about the cost of computing Also, I think the operand may have to be printed in hex (both here and in executor.c) -- debug output like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we will ultimately want to change from instruction pointer back to the offset (as we had in 3.9 and earlier), so let's keep the redundant (for now) macro. The reason for wanting the offset, not the pointer is that we expect writes to |
||
|
||
uint32_t opcode = instr->op.code; | ||
uint32_t oparg = instr->op.arg; | ||
|
@@ -554,7 +553,7 @@ translate_bytecode_to_trace( | |
uint32_t uopcode = opcode == POP_JUMP_IF_TRUE ? | ||
_POP_JUMP_IF_TRUE : _POP_JUMP_IF_FALSE; | ||
ADD_TO_TRACE(uopcode, max_length, 0); | ||
ADD_TO_STUB(max_length, SAVE_IP, INSTR_IP(target_instr, code), 0); | ||
ADD_TO_STUB(max_length, SAVE_IP, 0, (uintptr_t)target_instr); | ||
ADD_TO_STUB(max_length + 1, EXIT_TRACE, 0, 0); | ||
break; | ||
} | ||
|
@@ -614,7 +613,7 @@ translate_bytecode_to_trace( | |
ADD_TO_TRACE(next_op, 0, 0); | ||
|
||
ADD_TO_STUB(max_length + 0, POP_TOP, 0, 0); | ||
ADD_TO_STUB(max_length + 1, SAVE_IP, INSTR_IP(target_instr, code), 0); | ||
ADD_TO_STUB(max_length + 1, SAVE_IP, 0, (uintptr_t)target_instr); | ||
ADD_TO_STUB(max_length + 2, EXIT_TRACE, 0, 0); | ||
break; | ||
} | ||
|
@@ -668,7 +667,7 @@ translate_bytecode_to_trace( | |
oparg = orig_oparg & 0xF; | ||
break; | ||
case OPARG_SAVE_IP: // op==SAVE_IP; oparg=next instr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the comment. |
||
oparg = INSTR_IP(instr + offset, code); | ||
operand = (uintptr_t)(instr + offset); | ||
break; | ||
|
||
default: | ||
|
@@ -707,15 +706,13 @@ translate_bytecode_to_trace( | |
PyUnicode_AsUTF8(new_code->co_qualname), | ||
PyUnicode_AsUTF8(new_code->co_filename), | ||
new_code->co_firstlineno); | ||
ADD_TO_TRACE(SAVE_IP, 0, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Because you added an assignment to |
||
goto done; | ||
} | ||
if (new_code->co_version != func_version) { | ||
// func.__code__ was updated. | ||
// Perhaps it may happen again, so don't bother tracing. | ||
// TODO: Reason about this -- is it better to bail or not? | ||
DPRINTF(2, "Bailing because co_version != func_version\n"); | ||
ADD_TO_TRACE(SAVE_IP, 0, 0); | ||
goto done; | ||
} | ||
// Increment IP to the return address | ||
|
@@ -731,7 +728,6 @@ translate_bytecode_to_trace( | |
2 * INSTR_IP(instr, code)); | ||
goto top; | ||
} | ||
ADD_TO_TRACE(SAVE_IP, 0, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to look twice before understanding how we even get here. :-) I think we could use a comment here explaining that here |
||
goto done; | ||
} | ||
} | ||
|
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.
See my comment in ceval_macros.c -- perhaps this should also be a macro?
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.
This is unnecessary,
frame->prev_instr
is set during frame creation.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.
And if we want to reuse this code for
SEND
we don't want to be messing withframe->prev_instr
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.
It's set to an index of -1 (since the frame hasn't started yet), which is invalid. So we either need to set it like this, or at least do an increment.