Skip to content

Commit 83bf054

Browse files
committed
Implement heap_free_slots in GC.stat_heap
[Feature #20408]
1 parent fa02d7a commit 83bf054

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

gc/default/default.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7593,6 +7593,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
75937593
enum gc_stat_heap_sym {
75947594
gc_stat_heap_sym_slot_size,
75957595
gc_stat_heap_sym_heap_live_slots,
7596+
gc_stat_heap_sym_heap_free_slots,
75967597
gc_stat_heap_sym_heap_eden_pages,
75977598
gc_stat_heap_sym_heap_eden_slots,
75987599
gc_stat_heap_sym_total_allocated_pages,
@@ -7612,6 +7613,7 @@ setup_gc_stat_heap_symbols(void)
76127613
#define S(s) gc_stat_heap_symbols[gc_stat_heap_sym_##s] = ID2SYM(rb_intern_const(#s))
76137614
S(slot_size);
76147615
S(heap_live_slots);
7616+
S(heap_free_slots);
76157617
S(heap_eden_pages);
76167618
S(heap_eden_slots);
76177619
S(total_allocated_pages);
@@ -7634,6 +7636,7 @@ stat_one_heap(rb_heap_t *heap, VALUE hash, VALUE key)
76347636

76357637
SET(slot_size, heap->slot_size);
76367638
SET(heap_live_slots, heap->total_allocated_objects - heap->total_freed_objects - heap->final_slots_count);
7639+
SET(heap_free_slots, heap->total_slots - (heap->total_allocated_objects - heap->total_freed_objects));
76377640
SET(heap_eden_pages, heap->total_pages);
76387641
SET(heap_eden_slots, heap->total_slots);
76397642
SET(total_allocated_pages, heap->total_allocated_pages);

test/ruby/test_gc.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def test_stat_heap
232232

233233
assert_equal (GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + GC::INTERNAL_CONSTANTS[:RVALUE_OVERHEAD]) * (2**i), stat_heap[:slot_size]
234234
assert_operator stat_heap[:heap_live_slots], :<=, stat[:heap_live_slots]
235+
assert_operator stat_heap[:heap_free_slots], :<=, stat[:heap_free_slots]
235236
assert_operator stat_heap[:heap_eden_pages], :<=, stat[:heap_eden_pages]
236237
assert_operator stat_heap[:heap_eden_slots], :>=, 0
237238
assert_operator stat_heap[:total_allocated_pages], :>=, 0
@@ -262,7 +263,7 @@ def test_stat_heap_all
262263
GC.stat_heap(i, stat_heap)
263264

264265
# Remove keys that can vary between invocations
265-
%i(total_allocated_objects heap_live_slots).each do |sym|
266+
%i(total_allocated_objects heap_live_slots heap_free_slots).each do |sym|
266267
stat_heap[sym] = stat_heap_all[i][sym] = 0
267268
end
268269

@@ -288,6 +289,7 @@ def test_stat_heap_constraints
288289
end
289290

290291
assert_equal stat[:heap_live_slots], stat_heap_sum[:heap_live_slots]
292+
assert_equal stat[:heap_free_slots], stat_heap_sum[:heap_free_slots]
291293
assert_equal stat[:heap_eden_pages], stat_heap_sum[:heap_eden_pages]
292294
assert_equal stat[:heap_available_slots], stat_heap_sum[:heap_eden_slots]
293295
assert_equal stat[:total_allocated_objects], stat_heap_sum[:total_allocated_objects]

0 commit comments

Comments
 (0)