Skip to content

Commit

Permalink
Move gloabl_object_list from objspace to VM
Browse files Browse the repository at this point in the history
This is to be consistent with the mark_object_ary that is in the VM.
  • Loading branch information
peterzhu2118 committed Mar 14, 2024
1 parent b0be296 commit 4559a16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
36 changes: 8 additions & 28 deletions gc.c
Expand Up @@ -735,11 +735,6 @@ struct heap_page_body {
/* RVALUE values[]; */
};

struct gc_list {
VALUE *varptr;
struct gc_list *next;
};

#define STACK_CHUNK_SIZE 500

typedef struct stack_chunk {
Expand Down Expand Up @@ -904,7 +899,6 @@ typedef struct rb_objspace {
size_t weak_references_count;
size_t retained_weak_references_count;
} profile;
struct gc_list *global_list;

VALUE gc_stress_mode;

Expand Down Expand Up @@ -1160,7 +1154,6 @@ VALUE *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
#define during_gc objspace->flags.during_gc
#define finalizing objspace->atomic_flags.finalizing
#define finalizer_table objspace->finalizer_table
#define global_list objspace->global_list
#define ruby_gc_stressful objspace->flags.gc_stressful
#define ruby_gc_stress_mode objspace->gc_stress_mode
#if GC_DEBUG_STRESS_TO_CLASS
Expand Down Expand Up @@ -1932,13 +1925,6 @@ rb_objspace_free(rb_objspace_t *objspace)
free(objspace->profile.records);
objspace->profile.records = NULL;

if (global_list) {
struct gc_list *list, *next;
for (list = global_list; list; list = next) {
next = list->next;
xfree(list);
}
}
if (heap_pages_sorted) {
size_t i;
size_t total_heap_pages = heap_allocated_pages;
Expand Down Expand Up @@ -7098,7 +7084,6 @@ show_mark_ticks(void)
static void
gc_mark_roots(rb_objspace_t *objspace, const char **categoryp)
{
struct gc_list *list;
rb_execution_context_t *ec = GET_EC();
rb_vm_t *vm = rb_ec_vm_ptr(ec);

Expand Down Expand Up @@ -7148,10 +7133,6 @@ gc_mark_roots(rb_objspace_t *objspace, const char **categoryp)
mark_current_machine_context(objspace, ec);

/* mark protected global variables */
MARK_CHECKPOINT("global_list");
for (list = global_list; list; list = list->next) {
gc_mark_maybe(objspace, *list->varptr);
}

MARK_CHECKPOINT("end_proc");
rb_mark_end_proc();
Expand Down Expand Up @@ -8754,15 +8735,14 @@ rb_gc_register_mark_object(VALUE obj)
void
rb_gc_register_address(VALUE *addr)
{
rb_objspace_t *objspace = &rb_objspace;
struct gc_list *tmp;
rb_vm_t *vm = GET_VM();

VALUE obj = *addr;

tmp = ALLOC(struct gc_list);
tmp->next = global_list;
struct global_object_list *tmp = ALLOC(struct global_object_list);
tmp->next = vm->gloabl_object_list;
tmp->varptr = addr;
global_list = tmp;
vm->gloabl_object_list = tmp;

/*
* Because some C extensions have assignment-then-register bugs,
Expand All @@ -8779,17 +8759,17 @@ rb_gc_register_address(VALUE *addr)
void
rb_gc_unregister_address(VALUE *addr)
{
rb_objspace_t *objspace = &rb_objspace;
struct gc_list *tmp = global_list;
rb_vm_t *vm = GET_VM();
struct global_object_list *tmp = vm->gloabl_object_list;

if (tmp->varptr == addr) {
global_list = tmp->next;
vm->gloabl_object_list = tmp->next;
xfree(tmp);
return;
}
while (tmp->next) {
if (tmp->next->varptr == addr) {
struct gc_list *t = tmp->next;
struct global_object_list *t = tmp->next;

tmp->next = tmp->next->next;
xfree(t);
Expand Down
11 changes: 11 additions & 0 deletions vm.c
Expand Up @@ -2960,6 +2960,10 @@ rb_vm_mark(void *ptr)
rb_gc_mark(rb_ractor_self(r));
}

for (struct global_object_list *list = vm->gloabl_object_list; list; list = list->next) {
rb_gc_mark_maybe(*list->varptr);
}

rb_gc_mark_movable(vm->mark_object_ary);
rb_gc_mark_movable(vm->load_path);
rb_gc_mark_movable(vm->load_path_snapshot);
Expand Down Expand Up @@ -3101,6 +3105,13 @@ ruby_vm_destruct(rb_vm_t *vm)
vm->frozen_strings = 0;
}
RB_ALTSTACK_FREE(vm->main_altstack);

struct global_object_list *next;
for (struct global_object_list *list = vm->gloabl_object_list; list; list = next) {
next = list->next;
xfree(list);
}

if (objspace) {
if (rb_free_at_exit) {
rb_objspace_free_objects(objspace);
Expand Down
6 changes: 6 additions & 0 deletions vm_core.h
Expand Up @@ -624,6 +624,11 @@ typedef struct rb_hook_list_struct {
// see builtin.h for definition
typedef const struct rb_builtin_function *RB_BUILTIN;

struct global_object_list {
VALUE *varptr;
struct global_object_list *next;
};

typedef struct rb_vm_struct {
VALUE self;

Expand Down Expand Up @@ -705,6 +710,7 @@ typedef struct rb_vm_struct {

/* object management */
VALUE mark_object_ary;
struct global_object_list *gloabl_object_list;
const VALUE special_exceptions[ruby_special_error_count];

/* load */
Expand Down

0 comments on commit 4559a16

Please sign in to comment.