ruby-changes:58622
From: Aaron <ko1@a...>
Date: Fri, 8 Nov 2019 05:46:34 +0900 (JST)
Subject: [ruby-changes:58622] dddf5afb79 (master): Add a counter for compaction
https://git.ruby-lang.org/ruby.git/commit/?id=dddf5afb79 From dddf5afb7947f5aba1ff875e9f5eb163f8c3d6c7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 7 Nov 2019 12:46:14 -0800 Subject: 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. diff --git a/gc.c b/gc.c index e1bc984..ee8f62e 100644 --- a/gc.c +++ b/gc.c @@ -748,6 +748,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L748 #if USE_RGENGC size_t minor_gc_count; size_t major_gc_count; + size_t compact_count; #if RGENGC_PROFILE > 0 size_t total_generated_normal_object_count; 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 https://github.com/ruby/ruby/blob/trunk/gc.c#L8550 mjit_gc_start_hook(); // prevent MJIT from running while moving pointers related to ISeq + objspace->profile.compact_count++; + if (use_verifier) { gc_verify_internal_consistency(objspace); } @@ -8890,6 +8893,7 @@ enum gc_stat_sym { https://github.com/ruby/ruby/blob/trunk/gc.c#L8893 #if USE_RGENGC gc_stat_sym_minor_gc_count, gc_stat_sym_major_gc_count, + gc_stat_sym_compact_count, gc_stat_sym_remembered_wb_unprotected_objects, gc_stat_sym_remembered_wb_unprotected_objects_limit, gc_stat_sym_old_objects, @@ -8966,6 +8970,7 @@ setup_gc_stat_symbols(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L8970 #if USE_RGENGC S(minor_gc_count); S(major_gc_count); + S(compact_count); S(remembered_wb_unprotected_objects); S(remembered_wb_unprotected_objects_limit); S(old_objects); @@ -9138,6 +9143,7 @@ gc_stat_internal(VALUE hash_or_sym) https://github.com/ruby/ruby/blob/trunk/gc.c#L9143 #if USE_RGENGC SET(minor_gc_count, objspace->profile.minor_gc_count); SET(major_gc_count, objspace->profile.major_gc_count); + SET(compact_count, objspace->profile.compact_count); SET(remembered_wb_unprotected_objects, objspace->rgengc.uncollectible_wb_unprotected_objects); SET(remembered_wb_unprotected_objects_limit, objspace->rgengc.uncollectible_wb_unprotected_objects_limit); SET(old_objects, objspace->rgengc.old_objects); diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index bc26897..e93e775 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -54,4 +54,10 @@ class TestGCCompact < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc_compact.rb#L54 assert GC.compact walk_ast ast end + + def test_compact_count + count = GC.stat(:compact_count) + GC.compact + assert_equal count + 1, GC.stat(:compact_count) + end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/