Skip to content

Commit dddf5af

Browse files
committed
Add a counter for compaction
Keep track of the number of times the compactor ran. I would like to use this as a way to keep track of inline cache reference updates.
1 parent 597ec43 commit dddf5af

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ typedef struct rb_objspace {
748748
#if USE_RGENGC
749749
size_t minor_gc_count;
750750
size_t major_gc_count;
751+
size_t compact_count;
751752
#if RGENGC_PROFILE > 0
752753
size_t total_generated_normal_object_count;
753754
size_t total_generated_shady_object_count;
@@ -8549,6 +8550,8 @@ gc_compact_after_gc(rb_objspace_t *objspace, int use_toward_empty, int use_doubl
85498550

85508551
mjit_gc_start_hook(); // prevent MJIT from running while moving pointers related to ISeq
85518552

8553+
objspace->profile.compact_count++;
8554+
85528555
if (use_verifier) {
85538556
gc_verify_internal_consistency(objspace);
85548557
}
@@ -8890,6 +8893,7 @@ enum gc_stat_sym {
88908893
#if USE_RGENGC
88918894
gc_stat_sym_minor_gc_count,
88928895
gc_stat_sym_major_gc_count,
8896+
gc_stat_sym_compact_count,
88938897
gc_stat_sym_remembered_wb_unprotected_objects,
88948898
gc_stat_sym_remembered_wb_unprotected_objects_limit,
88958899
gc_stat_sym_old_objects,
@@ -8966,6 +8970,7 @@ setup_gc_stat_symbols(void)
89668970
#if USE_RGENGC
89678971
S(minor_gc_count);
89688972
S(major_gc_count);
8973+
S(compact_count);
89698974
S(remembered_wb_unprotected_objects);
89708975
S(remembered_wb_unprotected_objects_limit);
89718976
S(old_objects);
@@ -9138,6 +9143,7 @@ gc_stat_internal(VALUE hash_or_sym)
91389143
#if USE_RGENGC
91399144
SET(minor_gc_count, objspace->profile.minor_gc_count);
91409145
SET(major_gc_count, objspace->profile.major_gc_count);
9146+
SET(compact_count, objspace->profile.compact_count);
91419147
SET(remembered_wb_unprotected_objects, objspace->rgengc.uncollectible_wb_unprotected_objects);
91429148
SET(remembered_wb_unprotected_objects_limit, objspace->rgengc.uncollectible_wb_unprotected_objects_limit);
91439149
SET(old_objects, objspace->rgengc.old_objects);

test/ruby/test_gc_compact.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ def test_ast_compacts
5454
assert GC.compact
5555
walk_ast ast
5656
end
57+
58+
def test_compact_count
59+
count = GC.stat(:compact_count)
60+
GC.compact
61+
assert_equal count + 1, GC.stat(:compact_count)
62+
end
5763
end

0 commit comments

Comments
 (0)