diff options
author | Neil Schemenauer <nas-github@arctrix.com> | 2024-12-03 17:32:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 17:32:26 (GMT) |
commit | 0cb52220790d8bc70ec325fd89d52b5f3b7ad29c (patch) | |
tree | fb6d278b8932ce83053c9285638f76428a86f3d0 /Python/specialize.c | |
parent | 8ba9f5bca9c0ce6130e1f4ba761a68f74f8457d0 (diff) | |
download | cpython-0cb52220790d8bc70ec325fd89d52b5f3b7ad29c.zip cpython-0cb52220790d8bc70ec325fd89d52b5f3b7ad29c.tar.gz cpython-0cb52220790d8bc70ec325fd89d52b5f3b7ad29c.tar.bz2 |
gh-115999: Specialize `LOAD_SUPER_ATTR` in free-threaded builds (gh-127128)
Use existing helpers to atomically modify the bytecode. Add unit tests
to ensure specializing is happening as expected. Add test_specialize.py
that can be used with ThreadSanitizer to detect data races.
Fix thread safety issue with cell_set_contents().
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index ba13b02..0fe4e79 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -794,9 +794,8 @@ _Py_Specialize_LoadSuperAttr(_PyStackRef global_super_st, _PyStackRef cls_st, _P PyObject *global_super = PyStackRef_AsPyObjectBorrow(global_super_st); PyObject *cls = PyStackRef_AsPyObjectBorrow(cls_st); - assert(ENABLE_SPECIALIZATION); + assert(ENABLE_SPECIALIZATION_FT); assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR); - _PySuperAttrCache *cache = (_PySuperAttrCache *)(instr + 1); if (global_super != (PyObject *)&PySuper_Type) { SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED); goto fail; @@ -805,19 +804,11 @@ _Py_Specialize_LoadSuperAttr(_PyStackRef global_super_st, _PyStackRef cls_st, _P SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS); goto fail; } - instr->op.code = load_method ? LOAD_SUPER_ATTR_METHOD : LOAD_SUPER_ATTR_ATTR; - goto success; - -fail: - STAT_INC(LOAD_SUPER_ATTR, failure); - assert(!PyErr_Occurred()); - instr->op.code = LOAD_SUPER_ATTR; - cache->counter = adaptive_counter_backoff(cache->counter); + uint8_t load_code = load_method ? LOAD_SUPER_ATTR_METHOD : LOAD_SUPER_ATTR_ATTR; + specialize(instr, load_code); return; -success: - STAT_INC(LOAD_SUPER_ATTR, success); - assert(!PyErr_Occurred()); - cache->counter = adaptive_counter_cooldown(); +fail: + unspecialize(instr); } typedef enum { |