Skip to content
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

Enable GC.auto_compact in test suite #101

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions ext/vernier/vernier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,9 @@ class BaseCollector {
rb_gc_mark(stack_table_value);
};

virtual void compact() {
};

virtual VALUE get_markers() {
return rb_ary_new();
};
Expand Down Expand Up @@ -1547,6 +1550,23 @@ class RetainedCollector : public BaseCollector {
rb_gc_mark(tp_newobj);
rb_gc_mark(tp_freeobj);
}

void compact() {
RetainedCollector *collector = this;
for (auto& obj: collector->object_list) {
VALUE reloc_obj = rb_gc_location(obj);

const auto search = collector->object_frames.find(obj);
if (search != collector->object_frames.end()) {
int stack_index = search->second;

collector->object_frames.erase(search);
collector->object_frames.emplace(reloc_obj, stack_index);
}

obj = reloc_obj;
}
}
};

class GlobalSignalHandler {
Expand Down Expand Up @@ -1969,12 +1989,19 @@ collector_free(void *data) {
delete collector;
}

static void
collector_compact(void *data) {
BaseCollector *collector = static_cast<BaseCollector *>(data);
collector->compact();
}

static const rb_data_type_t rb_collector_type = {
.wrap_struct_name = "vernier/collector",
.function = {
//.dmemsize = rb_collector_memsize,
.dmark = collector_mark,
.dfree = collector_free,
.dcompact = collector_compact,
},
};

Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ def assert_valid_result(result)
end
end
end

GC.auto_compact = true
Loading