summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c99
1 files changed, 62 insertions, 37 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 2ff3805..e101efa 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -183,9 +183,9 @@ dummy_func(
tstate, oparg > 0, frame, next_instr-1);
stack_pointer = _PyFrame_GetStackPointer(frame);
ERROR_IF(err, error);
- if (frame->prev_instr != next_instr-1) {
+ if (frame->instr_ptr != next_instr-1) {
/* Instrumentation has jumped */
- next_instr = frame->prev_instr;
+ next_instr = frame->instr_ptr;
DISPATCH();
}
}
@@ -657,7 +657,8 @@ dummy_func(
new_frame->localsplus[0] = container;
new_frame->localsplus[1] = sub;
SKIP_OVER(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR;
DISPATCH_INLINED(new_frame);
}
@@ -790,10 +791,9 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
LOAD_SP();
- LOAD_IP();
+ LOAD_IP(frame->return_offset);
#if LLTRACE && TIER_ONE
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
if (lltrace < 0) {
@@ -819,8 +819,8 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
+ LOAD_IP(frame->return_offset);
goto resume_frame;
}
@@ -843,8 +843,8 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
- frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
+ LOAD_IP(frame->return_offset);
goto resume_frame;
}
@@ -980,7 +980,8 @@ dummy_func(
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
- frame->return_offset = oparg;
+ assert(1 + INLINE_CACHE_ENTRIES_SEND == next_instr - frame->instr_ptr);
+ frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_SEND + oparg);
DISPATCH_INLINED(gen_frame);
}
if (Py_IsNone(v) && PyIter_Check(receiver)) {
@@ -1018,13 +1019,15 @@ dummy_func(
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
- frame->return_offset = oparg;
+ assert(1 + INLINE_CACHE_ENTRIES_SEND == next_instr - frame->instr_ptr);
+ frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_SEND + oparg);
DISPATCH_INLINED(gen_frame);
}
inst(INSTRUMENTED_YIELD_VALUE, (retval -- unused)) {
assert(frame != &entry_frame);
assert(oparg >= 0); /* make the generator identify this as HAS_ARG */
+ frame->instr_ptr = next_instr;
PyGenObject *gen = _PyFrame_GetGenerator(frame);
gen->gi_frame_state = FRAME_SUSPENDED;
_PyFrame_SetStackPointer(frame, stack_pointer - 1);
@@ -1039,6 +1042,9 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
+ /* We don't know which of these is relevant here, so keep them equal */
+ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
+ LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
goto resume_frame;
}
@@ -1048,6 +1054,7 @@ dummy_func(
// or throw() call.
assert(oparg >= 0); /* make the generator identify this as HAS_ARG */
assert(frame != &entry_frame);
+ frame->instr_ptr = next_instr;
PyGenObject *gen = _PyFrame_GetGenerator(frame);
gen->gi_frame_state = FRAME_SUSPENDED;
_PyFrame_SetStackPointer(frame, stack_pointer - 1);
@@ -1058,6 +1065,9 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
+ /* We don't know which of these is relevant here, so keep them equal */
+ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER);
+ LOAD_IP(1 + INLINE_CACHE_ENTRIES_SEND);
goto resume_frame;
}
@@ -1071,7 +1081,7 @@ dummy_func(
if (oparg) {
PyObject *lasti = values[0];
if (PyLong_Check(lasti)) {
- frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame)) + PyLong_AsLong(lasti);
+ frame->instr_ptr = _PyCode_CODE(_PyFrame_GetCode(frame)) + PyLong_AsLong(lasti);
assert(!_PyErr_Occurred(tstate));
}
else {
@@ -2009,7 +2019,8 @@ dummy_func(
STACK_SHRINK(1);
new_frame->localsplus[0] = owner;
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_LOAD_ATTR == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_LOAD_ATTR;
DISPATCH_INLINED(new_frame);
}
@@ -2036,7 +2047,8 @@ dummy_func(
new_frame->localsplus[0] = owner;
new_frame->localsplus[1] = Py_NewRef(name);
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_LOAD_ATTR == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_LOAD_ATTR;
DISPATCH_INLINED(new_frame);
}
@@ -2304,13 +2316,14 @@ dummy_func(
_PyExecutorObject *executor = (_PyExecutorObject *)code->co_executors->executors[oparg&255];
int original_oparg = executor->vm_data.oparg | (oparg & 0xfffff00);
JUMPBY(1-original_oparg);
- frame->prev_instr = next_instr - 1;
+ frame->instr_ptr = next_instr;
Py_INCREF(executor);
frame = executor->execute(executor, frame, stack_pointer);
if (frame == NULL) {
frame = tstate->current_frame;
goto resume_with_error;
}
+ next_instr = frame->instr_ptr;
goto resume_frame;
}
@@ -2476,7 +2489,7 @@ dummy_func(
}
inst(INSTRUMENTED_FOR_ITER, ( -- )) {
- _Py_CODEUNIT *here = next_instr-1;
+ _Py_CODEUNIT *here = frame->instr_ptr;
_Py_CODEUNIT *target;
PyObject *iter = TOP();
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
@@ -2672,7 +2685,8 @@ dummy_func(
SKIP_OVER(INLINE_CACHE_ENTRIES_FOR_ITER);
assert(next_instr[oparg].op.code == END_FOR ||
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
- frame->return_offset = oparg;
+ assert(1 + INLINE_CACHE_ENTRIES_FOR_ITER == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg;
DISPATCH_INLINED(gen_frame);
}
@@ -2983,7 +2997,8 @@ dummy_func(
goto error;
}
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
DISPATCH_INLINED(new_frame);
}
/* Callable is not a normal Python function */
@@ -3070,7 +3085,6 @@ dummy_func(
op(_PUSH_FRAME, (new_frame: _PyInterpreterFrame* -- unused)) {
// Write it out explicitly because it's subtly different.
// Eventually this should be the only occurrence of this code.
- frame->return_offset = 0;
assert(tstate->interp->eval_frame == NULL);
STORE_SP();
new_frame->previous = frame;
@@ -3078,7 +3092,7 @@ dummy_func(
frame = tstate->current_frame = new_frame;
tstate->py_recursion_remaining--;
LOAD_SP();
- LOAD_IP();
+ LOAD_IP(0);
#if LLTRACE && TIER_ONE
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
if (lltrace < 0) {
@@ -3095,7 +3109,7 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS +
- _SAVE_CURRENT_IP + // Sets frame->prev_instr
+ _SAVE_RETURN_OFFSET +
_PUSH_FRAME;
macro(CALL_PY_EXACT_ARGS) =
@@ -3104,7 +3118,7 @@ dummy_func(
_CHECK_FUNCTION_EXACT_ARGS +
_CHECK_STACK_SPACE +
_INIT_CALL_PY_EXACT_ARGS +
- _SAVE_CURRENT_IP + // Sets frame->prev_instr
+ _SAVE_RETURN_OFFSET +
_PUSH_FRAME;
inst(CALL_PY_WITH_DEFAULTS, (unused/1, func_version/2, callable, self_or_null, args[oparg] -- unused)) {
@@ -3138,7 +3152,8 @@ dummy_func(
// Manipulate stack and cache directly since we leave using DISPATCH_INLINED().
STACK_SHRINK(oparg + 2);
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
DISPATCH_INLINED(new_frame);
}
@@ -3203,7 +3218,7 @@ dummy_func(
Py_DECREF(tp);
_PyInterpreterFrame *shim = _PyFrame_PushTrampolineUnchecked(
tstate, (PyCodeObject *)&_Py_InitCleanup, 1);
- assert(_PyCode_CODE((PyCodeObject *)shim->f_executable)[1].op.code == EXIT_INIT_CHECK);
+ assert(_PyCode_CODE((PyCodeObject *)shim->f_executable)[0].op.code == EXIT_INIT_CHECK);
/* Push self onto stack of shim */
Py_INCREF(self);
shim->localsplus[0] = self;
@@ -3215,8 +3230,8 @@ dummy_func(
init_frame->localsplus[i+1] = args[i];
}
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
- frame->prev_instr = next_instr - 1;
- frame->return_offset = 0;
+ assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - frame->instr_ptr);
+ frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
STACK_SHRINK(oparg+2);
_PyFrame_SetStackPointer(frame, stack_pointer);
/* Link frames */
@@ -3585,7 +3600,8 @@ dummy_func(
if (new_frame == NULL) {
goto error;
}
- frame->return_offset = 0;
+ assert(next_instr - frame->instr_ptr == 1);
+ frame->return_offset = 1;
DISPATCH_INLINED(new_frame);
}
/* Callable is not a normal Python function */
@@ -3681,7 +3697,8 @@ dummy_func(
if (new_frame == NULL) {
goto error;
}
- frame->return_offset = 0;
+ assert(next_instr - frame->instr_ptr == 1);
+ frame->return_offset = 1;
DISPATCH_INLINED(new_frame);
}
result = PyObject_Call(func, callargs, kwargs);
@@ -3744,6 +3761,7 @@ dummy_func(
assert(EMPTY());
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
+ frame->instr_ptr = next_instr;
_PyFrame_Copy(frame, gen_frame);
assert(frame->frame_obj == NULL);
gen->gi_frame_state = FRAME_CREATED;
@@ -3754,6 +3772,7 @@ dummy_func(
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
_PyFrame_StackPush(frame, (PyObject *)gen);
+ LOAD_IP(frame->return_offset);
goto resume_frame;
}
@@ -3836,18 +3855,20 @@ dummy_func(
}
inst(INSTRUMENTED_JUMP_FORWARD, ( -- )) {
- INSTRUMENTED_JUMP(next_instr-1, next_instr+oparg, PY_MONITORING_EVENT_JUMP);
+ _Py_CODEUNIT *here = frame->instr_ptr;
+ INSTRUMENTED_JUMP(here, next_instr + oparg, PY_MONITORING_EVENT_JUMP);
}
inst(INSTRUMENTED_JUMP_BACKWARD, ( -- )) {
+ _Py_CODEUNIT *here = frame->instr_ptr;
CHECK_EVAL_BREAKER();
- INSTRUMENTED_JUMP(next_instr-1, next_instr+1-oparg, PY_MONITORING_EVENT_JUMP);
+ INSTRUMENTED_JUMP(here, next_instr + 1 - oparg, PY_MONITORING_EVENT_JUMP);
}
inst(INSTRUMENTED_POP_JUMP_IF_TRUE, (unused/1 -- )) {
PyObject *cond = POP();
assert(PyBool_Check(cond));
- _Py_CODEUNIT *here = next_instr - 1;
+ _Py_CODEUNIT *here = frame->instr_ptr;
int flag = Py_IsTrue(cond);
int offset = flag * oparg;
#if ENABLE_SPECIALIZATION
@@ -3859,7 +3880,7 @@ dummy_func(
inst(INSTRUMENTED_POP_JUMP_IF_FALSE, (unused/1 -- )) {
PyObject *cond = POP();
assert(PyBool_Check(cond));
- _Py_CODEUNIT *here = next_instr - 1;
+ _Py_CODEUNIT *here = frame->instr_ptr;
int flag = Py_IsFalse(cond);
int offset = flag * oparg;
#if ENABLE_SPECIALIZATION
@@ -3870,7 +3891,7 @@ dummy_func(
inst(INSTRUMENTED_POP_JUMP_IF_NONE, (unused/1 -- )) {
PyObject *value = POP();
- _Py_CODEUNIT *here = next_instr - 1;
+ _Py_CODEUNIT *here = frame->instr_ptr;
int flag = Py_IsNone(value);
int offset;
if (flag) {
@@ -3888,7 +3909,7 @@ dummy_func(
inst(INSTRUMENTED_POP_JUMP_IF_NOT_NONE, (unused/1 -- )) {
PyObject *value = POP();
- _Py_CODEUNIT *here = next_instr-1;
+ _Py_CODEUNIT *here = frame->instr_ptr;
int offset;
int nflag = Py_IsNone(value);
if (nflag) {
@@ -3943,16 +3964,20 @@ dummy_func(
op(_SET_IP, (--)) {
TIER_TWO_ONLY
- frame->prev_instr = ip_offset + oparg;
+ frame->instr_ptr = ip_offset + oparg;
}
- op(_SAVE_CURRENT_IP, (--)) {
- TIER_ONE_ONLY
- frame->prev_instr = next_instr - 1;
+ op(_SAVE_RETURN_OFFSET, (--)) {
+ #if TIER_ONE
+ frame->return_offset = (uint16_t)(next_instr - frame->instr_ptr);
+ #endif
+ #if TIER_TWO
+ frame->return_offset = oparg;
+ #endif
}
op(_EXIT_TRACE, (--)) {
- frame->prev_instr--; // Back up to just before destination
+ TIER_TWO_ONLY
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);