Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ enum gc_stat_sym {
gc_stat_sym_free_bytes,
gc_stat_sym_starting_heap_address,
gc_stat_sym_last_heap_address,
gc_stat_sym_weak_references_count,
gc_stat_sym_last
};

Expand All @@ -1428,6 +1429,7 @@ setup_gc_stat_symbols(void)
S(free_bytes);
S(starting_heap_address);
S(last_heap_address);
S(weak_references_count);
}
}

Expand Down Expand Up @@ -1463,6 +1465,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
SET(free_bytes, mmtk_free_bytes());
SET(starting_heap_address, (size_t)mmtk_starting_heap_address());
SET(last_heap_address, (size_t)mmtk_last_heap_address());
SET(weak_references_count, mmtk_weak_references_count());
#undef SET

if (!NIL_P(key)) {
Expand Down
2 changes: 2 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void mmtk_declare_weak_references(MMTk_ObjectReference object);

bool mmtk_weak_references_alive_p(MMTk_ObjectReference object);

size_t mmtk_weak_references_count(void);

void mmtk_register_pinning_obj(MMTk_ObjectReference obj);

void mmtk_object_reference_write_post(MMTk_Mutator *mutator, MMTk_ObjectReference object);
Expand Down
5 changes: 5 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ pub extern "C" fn mmtk_weak_references_alive_p(object: ObjectReference) -> bool
object.is_reachable()
}

#[no_mangle]
pub extern "C" fn mmtk_weak_references_count() -> usize {
binding().weak_proc.weak_references_count()
}

// =============== Compaction ===============

#[no_mangle]
Expand Down
4 changes: 4 additions & 0 deletions gc/mmtk/src/weak_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ impl WeakProcessor {
weak_references.push(object);
}

pub fn weak_references_count(&self) -> usize {
self.weak_references.lock().unwrap().len()
}

pub fn process_weak_stuff(
&self,
worker: &mut GCWorker<Ruby>,
Expand Down
17 changes: 17 additions & 0 deletions test/mmtk/test_stat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require_relative "helper"

module MMTk
class TestStat < TestCase
def test_weak_references_count
assert_operator(GC.stat(:weak_references_count), :>, 0)

EnvUtil.without_gc do
before = GC.stat(:weak_references_count)
ObjectSpace::WeakMap.new
assert_operator(GC.stat(:weak_references_count), :>, before)
end
end
end
end