Skip to content

Commit 14150bb

Browse files
Don't call hash tombstone compaction from GC compaction
Tombstone removal may possibly require allocation, and we're not allowed to allocate during GC. This commit also renames `set_compact` to `set_gc_compact` to differentiate tombstone removal compaction with GC object compaction. Co-Authored-By: Max Bernstein <max.bernstein@shopify.com>
1 parent d46389e commit 14150bb

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

set.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ set_replace_ref(st_data_t *key, st_data_t argp, int existing)
179179
}
180180

181181
static void
182-
set_compact(void *ptr)
182+
set_gc_compact(void *ptr)
183183
{
184184
struct set_object *sobj = ptr;
185-
set_compact_table(&sobj->table);
186185
set_foreach_with_replace(&sobj->table, set_foreach_replace, set_replace_ref, 0);
187186
}
188187

@@ -192,7 +191,7 @@ static const rb_data_type_t set_data_type = {
192191
.dmark = set_mark,
193192
.dfree = set_free,
194193
.dsize = set_size,
195-
.dcompact = set_compact,
194+
.dcompact = set_gc_compact,
196195
},
197196
.flags = RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE
198197
};

test/ruby/test_set.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ def test_reset
864864
assert_equal(klass.new([a]), set, klass.name)
865865
}
866866
end
867+
868+
def test_set_gc_compact_does_not_allocate
869+
assert_in_out_err([], <<-"end;", [], [])
870+
def x
871+
s = Set.new
872+
s << Object.new
873+
s
874+
end
875+
876+
m = x
877+
Process.warmup
878+
end;
879+
end
867880
end
868881

869882
class TC_Enumerable < Test::Unit::TestCase

0 commit comments

Comments
 (0)