gc.c: use :debt instead of :threshold in GC.stat

Expose gc_debt directly as :debt in GC.stat without sign negation.
The debt model has no threshold ceiling, so :threshold was a
misleading name. Negative debt means credit, positive means GC
is behind on collection work.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-03-15 23:40:29 +09:00
parent 4d03f40204
commit 851da984b4
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -384,7 +384,7 @@ GC.disable # disable GC
GC.stat
# => {
# :live => 5432, # live object count
# :threshold => 1024, # GC credit (positive=headroom)
# :debt => -1024, # GC debt (negative=credit, positive=behind)
# :state => 0, # 0=root, 1=marking, 2=sweeping
# :generational => true, # generational mode enabled
# :full => false, # major GC in progress
+2 -2
View File
@@ -1785,7 +1785,7 @@ mrb_objspace_page_slot_size(void)
* GC.stat -> Hash
*
* Returns a Hash with GC statistics.
* Keys: :live, :threshold, :state, :generational, :full,
* Keys: :live, :debt, :state, :generational, :full,
* :step_limit, :malloc_increase, :malloc_threshold
* With MRB_GC_STATS: :total, :minor, :major
*
@@ -1798,7 +1798,7 @@ gc_stat(mrb_state *mrb, mrb_value self)
mrb_value hash = mrb_hash_new_capa(mrb, 8);
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "live")), mrb_int_value(mrb, (mrb_int)gc->live));
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "threshold")), mrb_int_value(mrb, -gc->gc_debt));
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "debt")), mrb_int_value(mrb, gc->gc_debt));
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "state")), mrb_int_value(mrb, (mrb_int)gc->state));
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "generational")), mrb_bool_value(gc->generational));
mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_lit(mrb, "full")), mrb_bool_value(gc->full));