mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-115999: Add free-threaded specialization for SEND
(gh-127426)
No additional thread safety changes are required. Note that sending to a generator that is shared between threads is currently not safe in the free-threaded build.
This commit is contained in:
parent
13b68e1a61
commit
276cd66ccb
4 changed files with 50 additions and 15 deletions
|
@ -1117,7 +1117,7 @@ dummy_func(
|
|||
};
|
||||
|
||||
specializing op(_SPECIALIZE_SEND, (counter/1, receiver, unused -- receiver, unused)) {
|
||||
#if ENABLE_SPECIALIZATION
|
||||
#if ENABLE_SPECIALIZATION_FT
|
||||
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
|
||||
next_instr = this_instr;
|
||||
_Py_Specialize_Send(receiver, next_instr);
|
||||
|
@ -1125,7 +1125,7 @@ dummy_func(
|
|||
}
|
||||
OPCODE_DEFERRED_INC(SEND);
|
||||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
|
||||
op(_SEND, (receiver, v -- receiver, retval)) {
|
||||
|
|
4
Python/generated_cases.c.h
generated
4
Python/generated_cases.c.h
generated
|
@ -7065,7 +7065,7 @@
|
|||
receiver = stack_pointer[-2];
|
||||
uint16_t counter = read_u16(&this_instr[1].cache);
|
||||
(void)counter;
|
||||
#if ENABLE_SPECIALIZATION
|
||||
#if ENABLE_SPECIALIZATION_FT
|
||||
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
|
||||
next_instr = this_instr;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
|
@ -7075,7 +7075,7 @@
|
|||
}
|
||||
OPCODE_DEFERRED_INC(SEND);
|
||||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
// _SEND
|
||||
{
|
||||
|
|
|
@ -2627,28 +2627,21 @@ _Py_Specialize_Send(_PyStackRef receiver_st, _Py_CODEUNIT *instr)
|
|||
{
|
||||
PyObject *receiver = PyStackRef_AsPyObjectBorrow(receiver_st);
|
||||
|
||||
assert(ENABLE_SPECIALIZATION);
|
||||
assert(ENABLE_SPECIALIZATION_FT);
|
||||
assert(_PyOpcode_Caches[SEND] == INLINE_CACHE_ENTRIES_SEND);
|
||||
_PySendCache *cache = (_PySendCache *)(instr + 1);
|
||||
PyTypeObject *tp = Py_TYPE(receiver);
|
||||
if (tp == &PyGen_Type || tp == &PyCoro_Type) {
|
||||
if (_PyInterpreterState_GET()->eval_frame) {
|
||||
SPECIALIZATION_FAIL(SEND, SPEC_FAIL_OTHER);
|
||||
goto failure;
|
||||
}
|
||||
instr->op.code = SEND_GEN;
|
||||
goto success;
|
||||
specialize(instr, SEND_GEN);
|
||||
return;
|
||||
}
|
||||
SPECIALIZATION_FAIL(SEND,
|
||||
_PySpecialization_ClassifyIterator(receiver));
|
||||
failure:
|
||||
STAT_INC(SEND, failure);
|
||||
instr->op.code = SEND;
|
||||
cache->counter = adaptive_counter_backoff(cache->counter);
|
||||
return;
|
||||
success:
|
||||
STAT_INC(SEND, success);
|
||||
cache->counter = adaptive_counter_cooldown();
|
||||
unspecialize(instr);
|
||||
}
|
||||
|
||||
#ifdef Py_STATS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue