From 0013d31655b4747660231618302b81cda8266e06 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Fri, 18 Oct 2024 19:35:22 +0800 Subject: [PATCH] Querying number of removed entries and bins This is for the Rust part of the binding to visualize the number of entries and bins removed in specific work packets. --- include/ruby/st.h | 4 ++-- internal/mmtk.h | 14 +++++++------- st.c | 11 +++++++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/ruby/st.h b/include/ruby/st.h index fdd6835a732061..83d57ec6416e1e 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -190,8 +190,8 @@ void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE); #if USE_MMTK size_t rb_mmtk_st_get_num_entries(const st_table *tab); void rb_mmtk_st_get_size_info(const st_table *tab, size_t *entries_start, size_t *entries_bound, size_t *bins_num); -void rb_mmtk_st_update_entries_range(st_table *tab, size_t begin, size_t end, bool weak_keys, bool weak_records, bool forward); -void rb_mmtk_st_update_bins_range(st_table *tab, size_t begin, size_t end); +size_t rb_mmtk_st_update_entries_range(st_table *tab, size_t begin, size_t end, bool weak_keys, bool weak_records, bool forward); +size_t rb_mmtk_st_update_bins_range(st_table *tab, size_t begin, size_t end); void rb_mmtk_st_update_dedup_table(st_table *tab); #endif diff --git a/internal/mmtk.h b/internal/mmtk.h index bc09731c3f5fd0..800766ce7f3abd 100644 --- a/internal/mmtk.h +++ b/internal/mmtk.h @@ -103,13 +103,13 @@ typedef struct MMTk_RubyUpcalls { size_t *entries_start, size_t *entries_bound, size_t *bins_num); - void (*st_update_entries_range)(struct st_table *table, - size_t begin, - size_t end, - bool weak_keys, - bool weak_records, - bool forward); - void (*st_update_bins_range)(struct st_table *table, size_t begin, size_t end); + size_t (*st_update_entries_range)(struct st_table *table, + size_t begin, + size_t end, + bool weak_keys, + bool weak_records, + bool forward); + size_t (*st_update_bins_range)(struct st_table *table, size_t begin, size_t end); } MMTk_RubyUpcalls; typedef struct MMTk_RawVecOfObjRef { diff --git a/st.c b/st.c index ac511589dd2031..c10f54b055d79a 100644 --- a/st.c +++ b/st.c @@ -2380,7 +2380,7 @@ rb_mmtk_st_maybe_update_key_record(st_data_t *slot, bool weak, bool forward) return delete_entry; } -void +size_t rb_mmtk_st_update_entries_range(st_table *tab, size_t begin, size_t end, bool weak_keys, bool weak_records, bool forward) { // Either the keys or the values must be weak, otherwise it is a strong table. @@ -2417,15 +2417,19 @@ rb_mmtk_st_update_entries_range(st_table *tab, size_t begin, size_t end, bool we } rbimpl_atomic_size_sub(&tab->num_entries, deleted_entries); + + return deleted_entries; } -void +size_t rb_mmtk_st_update_bins_range(st_table *tab, size_t begin, size_t end) { RUBY_ASSERT(end <= get_bins_num(tab)); unsigned int const size_ind = get_size_ind(tab); + size_t deleted_bins = 0; + // Delete bins that point to deleted entries. for (st_index_t ind = begin; ind < end; ind++) { st_index_t bin = get_bin(tab->bins, size_ind, ind); @@ -2435,8 +2439,11 @@ rb_mmtk_st_update_bins_range(st_table *tab, size_t begin, size_t end) st_table_entry *entry = &tab->entries[bin - ENTRY_BASE]; if (DELETED_ENTRY_P(entry)) { MARK_BIN_DELETED(tab, ind); + deleted_bins++; } } + + return deleted_bins; } // Update a deduplication table.