8000 gh-112529: Implement GC for free-threaded builds by colesbury · Pull Request #114262 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112529: Implement GC for free-threaded builds #114262

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

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename "from_block" and add comment to ob_tid definition
  • Loading branch information
colesbury committed Jan 24, 2024
commit 56769832f64db9845e9b02833db03780a044de7b
4 changes: 3 additions & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ struct _object {
struct _PyMutex { uint8_t v; };

struct _object {
uintptr_t ob_tid; // thread id (or zero)
// ob_tid stores the thread id (or zero). It is also used by the GC to
// store linked lists and the computed "gc_refs" refcount.
uintptr_t ob_tid;
uint16_t _padding;
struct _PyMutex ob_mutex; // per-object lock
uint8_t ob_gc_bits; // gc-related state
10000 Expand Down
22 changes: 11 additions & 11 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ gc_restore_tid(PyObject *op)
// Given a mimalloc memory block return the PyObject stored in it or NULL if
// the block is not allocated or the object is not tracked or is immortal.
static PyObject *
from_block(void *block, void *arg, bool include_frozen)
op_from_block(void *block, void *arg, bool include_frozen)
{
struct visitor_args *a = arg;
if (block == NULL) {
Expand Down Expand Up @@ -273,7 +273,7 @@ static bool
update_refs(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, false);
PyObject *op = op_from_block(block, args, false);
if (op == NULL) {
return true;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ static bool
validate_gc_objects(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, false);
PyObject *op = op_from_block(block, args, false);
if (op == NULL) {
return true;
}
Expand All @@ -373,7 +373,7 @@ static bool
mark_heap_visitor(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, false);
PyObject *op = op_from_block(block, args, false);
if (op == NULL) {
return true;
}
Expand Down Expand Up @@ -404,7 +404,7 @@ static bool
scan_heap_visitor(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, false);
PyObject *op = op_from_block(block, args, false);
if (op == NULL) {
return true;
}
Expand Down Expand Up @@ -1137,7 +1137,7 @@ static bool
visit_get_referrers(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, true);
PyObject *op = op_from_block(block, args, true);
if (op == NULL) {
return true;
}
Expand Down Expand Up @@ -1192,7 +1192,7 @@ static bool
visit_get_objects(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, true);
PyObject *op = op_from_block(block, args, true);
if (op == NULL) {
return true;
}
Expand Down Expand Up @@ -1240,7 +1240,7 @@ static bool
visit_freeze(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, true);
PyObject *op = op_from_block(block, args, true);
if (op != NULL) {
op->ob_gc_bits |= _PyGC_BITS_FROZEN;
}
Expand All @@ -1258,7 +1258,7 @@ static bool
visit_unfreeze(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, true);
PyObject *op = op_from_block(block, args, true);
if (op != NULL) {
op->ob_gc_bits &= ~_PyGC_BITS_FROZEN;
}
Expand All @@ -1281,7 +1281,7 @@ static bool
visit_count_frozen(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, true);
PyObject *op = op_from_block(block, args, true);
if (op != NULL && (op->ob_gc_bits & _PyGC_BITS_FROZEN) != 0) {
struct count_frozen_args *arg = (struct count_frozen_args *)args;
arg->count++;
Expand Down Expand Up @@ -1630,7 +1630,7 @@ static bool
custom_visitor_wrapper(const mi_heap_t *heap, const mi_heap_area_t *area,
void *block, size_t block_size, void *args)
{
PyObject *op = from_block(block, args, false);
PyObject *op = op_from_block(block, args, false);
if (op == NULL) {
return true;
}
Expand Down
0