Skip to content

Commit

Permalink
Update ci_table
Browse files Browse the repository at this point in the history
This newly introduced table is a weak de-duplication table, too, like
fstring_table.
  • Loading branch information
wks committed Mar 14, 2024
1 parent 84c8c55 commit ff16207
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
26 changes: 25 additions & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14636,11 +14636,15 @@ rb_mmtk_on_overloaded_cme_delete(st_data_t key, st_data_t value, void *arg)
void
rb_mmtk_update_frozen_strings_table(void)
{
// The frozen strings table is a deduplicating table for frozen strings.
// Used as a HashSet (key always equals value).
// Hashed by string content.

#if USE_RUBY_DEBUG_LOG
size_t size1 = GET_VM()->frozen_strings->num_entries;
#endif

rb_mmtk_st_update_fstring_table(GET_VM()->frozen_strings);
rb_mmtk_st_update_dedup_table(GET_VM()->frozen_strings);

#if USE_RUBY_DEBUG_LOG
size_t size2 = GET_VM()->frozen_strings->num_entries;
Expand Down Expand Up @@ -14714,6 +14718,26 @@ rb_mmtk_update_overloaded_cme_table(void)
NULL);
}

void
rb_mmtk_update_ci_table(void)
{
// The CI table is a deduplicating table for callinfo.
// Used as a HashSet (key always equals value).
// Compared and hashed by callinfo fields. Two CIs are equal if all fields are equal.

#if USE_RUBY_DEBUG_LOG
size_t size1 = GET_VM()->ci_table->num_entries;
#endif

rb_mmtk_st_update_dedup_table(GET_VM()->ci_table);

#if USE_RUBY_DEBUG_LOG
size_t size2 = GET_VM()->ci_table->num_entries;
#endif

RUBY_DEBUG_LOG("CI table size: %zu -> %zu. Removed: %zu\n",
size1, size2, size1-size2);
}
/////////////// END: Global table updating ////////////////

// Workaround private functions
Expand Down
2 changes: 1 addition & 1 deletion include/ruby/st.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ CONSTFUNC(st_index_t rb_st_hash_start(st_index_t h));
void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE);

#if USE_MMTK
void rb_mmtk_st_update_fstring_table(st_table *tab);
void rb_mmtk_st_update_dedup_table(st_table *tab);
#endif

RUBY_SYMBOL_EXPORT_END
Expand Down
1 change: 1 addition & 0 deletions internal/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef struct MMTk_RubyUpcalls {
void (*update_obj_id_tables)(void);
void (*update_global_symbols_table)(void);
void (*update_overloaded_cme_table)(void);
void (*update_ci_table)(void);
void *(*get_original_givtbl)(MMTk_ObjectReference object);
void (*move_givtbl)(MMTk_ObjectReference old_objref, MMTk_ObjectReference new_objref);
size_t (*vm_live_bytes)(void);
Expand Down
2 changes: 2 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ void rb_mmtk_update_finalizer_table(void); // Defined in gc.c
void rb_mmtk_update_obj_id_tables(void); // Defined in gc.c
void rb_mmtk_update_global_symbols_table(void); // Defined in gc.c
void rb_mmtk_update_overloaded_cme_table(void); // Defined in gc.c
void rb_mmtk_update_ci_table(void); // Defined in gc.c

MMTk_RubyUpcalls ruby_upcalls = {
rb_mmtk_init_gc_worker_thread,
Expand All @@ -1549,6 +1550,7 @@ MMTk_RubyUpcalls ruby_upcalls = {
rb_mmtk_update_obj_id_tables,
rb_mmtk_update_global_symbols_table,
rb_mmtk_update_overloaded_cme_table,
rb_mmtk_update_ci_table,
rb_mmtk_get_original_givtbl,
rb_mmtk_move_givtbl,
rb_mmtk_vm_live_bytes,
Expand Down
17 changes: 16 additions & 1 deletion st.c
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,19 @@ rb_st_compact_table(st_table *tab)
}

#if USE_MMTK
// Update a deduplication table.
//
// This function forwards reachable entries and removes dead entries of deduplication tables.
// The frozen string table and the CI table are such tables. We assume keys are always equal to
// their respective values.
//
// This function is intended to be faster than existing updating functions based on st_foreach.
// This function never attempts to compare elements by value or by hash (which is unsafe during GC
// because some value-comparing or hash-computing operations may depend on weak tables or fields
// which are not yet updated), and never touches entries that hold non-reference values
// (SPECIAL_CONST_P).
void
rb_mmtk_st_update_fstring_table(st_table *tab)
rb_mmtk_st_update_dedup_table(st_table *tab)
{
for (st_index_t ind = tab->entries_start; ind < tab->entries_bound; ind++) {
if (DELETED_ENTRY_P(&tab->entries[ind])) {
Expand Down Expand Up @@ -2373,6 +2384,10 @@ rb_mmtk_st_update_fstring_table(st_table *tab)
}
}

if (tab->bins == NULL) {
return;
}

st_index_t num_bins = get_bins_num(tab);
unsigned int const size_ind = get_size_ind(tab);

Expand Down

0 comments on commit ff16207

Please sign in to comment.