From 69967ee64eac9ce65b83533a566d69d12a6046d0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 25 Mar 2022 20:29:09 +0900 Subject: Revert "Finer-grained inline constant cache invalidation" This reverts commits for [Feature #18589]: * 8008fb7352abc6fba433b99bf20763cf0d4adb38 "Update formatting per feedback" * 8f6eaca2e19828e92ecdb28b0fe693d606a03f96 "Delete ID from constant cache table if it becomes empty on ISEQ free" * 629908586b4bead1103267652f8b96b1083573a8 "Finer-grained inline constant cache invalidation" MSWin builds on AppVeyor have been crashing since the merger. --- vm.c | 61 +++++++++---------------------------------------------------- 1 file changed, 9 insertions(+), 52 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index b0e31ec6f9..abeef4a635 100644 --- a/vm.c +++ b/vm.c @@ -496,16 +496,6 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id, return FALSE; } -// Iterator function to loop through each entry in the constant cache and add -// its associated size into the given Hash. -static enum rb_id_table_iterator_result -vm_stat_constant_cache_i(ID id, VALUE table, void *constant_cache) -{ - st_index_t size = ((st_table *) table)->num_entries; - rb_hash_aset((VALUE) constant_cache, ID2SYM(id), LONG2NUM(size)); - return ID_TABLE_CONTINUE; -} - /* * call-seq: * RubyVM.stat -> Hash @@ -514,10 +504,10 @@ vm_stat_constant_cache_i(ID id, VALUE table, void *constant_cache) * * Returns a Hash containing implementation-dependent counters inside the VM. * - * This hash includes information about method/constant caches: + * This hash includes information about method/constant cache serials: * * { - * :constant_cache=>{:RubyVM=>3}, + * :global_constant_state=>481, * :class_serial=>9029 * } * @@ -526,10 +516,11 @@ vm_stat_constant_cache_i(ID id, VALUE table, void *constant_cache) * * This method is only expected to work on C Ruby. */ + static VALUE vm_stat(int argc, VALUE *argv, VALUE self) { - static VALUE sym_constant_cache, sym_class_serial, sym_global_cvar_state; + static VALUE sym_global_constant_state, sym_class_serial, sym_global_cvar_state; VALUE arg = Qnil; VALUE hash = Qnil, key = Qnil; @@ -546,11 +537,13 @@ vm_stat(int argc, VALUE *argv, VALUE self) hash = rb_hash_new(); } + if (sym_global_constant_state == 0) { #define S(s) sym_##s = ID2SYM(rb_intern_const(#s)) - S(constant_cache); + S(global_constant_state); S(class_serial); S(global_cvar_state); #undef S + } #define SET(name, attr) \ if (key == sym_##name) \ @@ -558,25 +551,11 @@ vm_stat(int argc, VALUE *argv, VALUE self) else if (hash != Qnil) \ rb_hash_aset(hash, sym_##name, SERIALT2NUM(attr)); + SET(global_constant_state, ruby_vm_global_constant_state); SET(class_serial, ruby_vm_class_serial); SET(global_cvar_state, ruby_vm_global_cvar_state); #undef SET - // Here we're going to set up the constant cache hash that has key-value - // pairs of { name => count }, where name is a Symbol that represents the - // ID in the cache and count is an Integer representing the number of inline - // constant caches associated with that Symbol. - if (key == sym_constant_cache || hash != Qnil) { - VALUE constant_cache = rb_hash_new(); - rb_id_table_foreach(GET_VM()->constant_cache, vm_stat_constant_cache_i, (void *) constant_cache); - - if (key == sym_constant_cache) { - return constant_cache; - } else { - rb_hash_aset(hash, sym_constant_cache, constant_cache); - } - } - if (!NIL_P(key)) { /* matched key should return above */ rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key)); } @@ -2836,26 +2815,6 @@ size_t rb_vm_memsize_workqueue(struct list_head *workqueue); // vm_trace.c // Used for VM memsize reporting. Returns the size of the at_exit list by // looping through the linked list and adding up the size of the structs. -static enum rb_id_table_iterator_result -vm_memsize_constant_cache_i(ID id, VALUE ics, void *size) -{ - *((size_t *) size) += rb_st_memsize((st_table *) ics); - return ID_TABLE_CONTINUE; -} - -// Returns a size_t representing the memory footprint of the VM's constant -// cache, which is the memsize of the table as well as the memsize of all of the -// nested tables. -static size_t -vm_memsize_constant_cache(void) -{ - rb_vm_t *vm = GET_VM(); - size_t size = rb_id_table_memsize(vm->constant_cache); - - rb_id_table_foreach(vm->constant_cache, vm_memsize_constant_cache_i, &size); - return size; -} - static size_t vm_memsize_at_exit_list(rb_at_exit_list *at_exit) { @@ -2899,8 +2858,7 @@ vm_memsize(const void *ptr) rb_st_memsize(vm->frozen_strings) + vm_memsize_builtin_function_table(vm->builtin_function_table) + rb_id_table_memsize(vm->negative_cme_table) + - rb_st_memsize(vm->overloaded_cme_table) + - vm_memsize_constant_cache() + rb_st_memsize(vm->overloaded_cme_table) ); // TODO @@ -3974,7 +3932,6 @@ Init_BareVM(void) ruby_current_vm_ptr = vm; vm->negative_cme_table = rb_id_table_create(16); vm->overloaded_cme_table = st_init_numtable(); - vm->constant_cache = rb_id_table_create(0); Init_native_thread(th); th->vm = vm; -- cgit v1.2.3