gh-131586: Avoid refcount contention in context managers (gh-131851)

This avoid reference count contention in the free threading build
when calling special methods like `__enter__` and `__exit__`.
This commit is contained in:
Sam Gross 2025-04-21 15:54:25 -04:00 committed by GitHub
parent 8dfa840773
commit da53660f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 247 additions and 207 deletions

View file

@ -1553,18 +1553,26 @@
break;
}
case _LOAD_SPECIAL: {
JitOptSymbol *attr;
JitOptSymbol *self_or_null;
attr = sym_new_not_null(ctx);
self_or_null = sym_new_unknown(ctx);
stack_pointer[-1] = attr;
stack_pointer[0] = self_or_null;
case _INSERT_NULL: {
JitOptSymbol *self;
JitOptSymbol **method_and_self;
self = stack_pointer[-1];
method_and_self = &stack_pointer[-1];
method_and_self[0] = sym_new_null(ctx);
method_and_self[1] = self;
stack_pointer += 1;
assert(WITHIN_STACK_BOUNDS());
break;
}
case _LOAD_SPECIAL: {
JitOptSymbol **method_and_self;
method_and_self = &stack_pointer[-2];
method_and_self[0] = sym_new_not_null(ctx);
method_and_self[1] = sym_new_unknown(ctx);
break;
}
case _WITH_EXCEPT_START: {
JitOptSymbol *res;
res = sym_new_not_null(ctx);