ruby-changes:69215
From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:23:51 +0900 (JST)
Subject: [ruby-changes:69215] 0a108601ef (master): Add counters for version invalidation reasons
https://git.ruby-lang.org/ruby.git/commit/?id=0a108601ef From 0a108601eff5a1e69a4dd5dc170e9eaa807d4788 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Wed, 22 Sep 2021 16:56:42 -0400 Subject: Add counters for version invalidation reasons I noticed that there were two st_table iterators that do exactly the same thing so I merged them into one. --- yjit.rb | 1 + yjit_codegen.c | 2 +- yjit_iface.c | 37 +++++++++++++++++++++++++++---------- yjit_iface.h | 7 +++++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/yjit.rb b/yjit.rb index f7e283dc05..29a8d39d27 100644 --- a/yjit.rb +++ b/yjit.rb @@ -160,6 +160,7 @@ module YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L160 print_counters(stats, prefix: 'oaref_', prompt: 'opt_aref exit reasons: ') print_counters(stats, prefix: 'expandarray_', prompt: 'expandarray exit reasons: ') print_counters(stats, prefix: 'opt_getinlinecache_', prompt: 'opt_getinlinecache exit reasons: ') + print_counters(stats, prefix: 'invalidate_', prompt: 'invalidation reasons: ') side_exits = total_exit_count(stats) total_exits = side_exits + stats[:leave_interp_return] diff --git a/yjit_codegen.c b/yjit_codegen.c index fddf460280..ac7f866d9e 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -4079,7 +4079,7 @@ gen_opt_getinlinecache(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4079 // Cache is keyed on a certain lexical scope. Use the interpreter's cache. uint8_t *side_exit = yjit_side_exit(jit, ctx); - // Call function to verify the cache + // Call function to verify the cache. It doesn't allocate or call methods. bool rb_vm_ic_hit_p(IC ic, const VALUE *reg_ep); mov(cb, C_ARG_REGS[0], const_ptr_opnd((void *)ic)); mov(cb, C_ARG_REGS[1], member_opnd(REG_CFP, rb_control_frame_t, ep)); diff --git a/yjit_iface.c b/yjit_iface.c index 8268440465..be4480b9d6 100644 --- a/yjit_iface.c +++ b/yjit_iface.c @@ -318,11 +318,13 @@ static const rb_data_type_t yjit_root_type = { https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L318 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; +// st_table iterator for invalidating blocks that are keys to the table. static int block_set_invalidate_i(st_data_t key, st_data_t v, st_data_t ignore) { block_t *version = (block_t *)key; + // Thankfully, st_table supports deleting while iterating. invalidate_block_version(version); return ST_CONTINUE; @@ -348,6 +350,11 @@ rb_yjit_method_lookup_change(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L350 rb_id_table_delete(id2blocks, mid); st_table *block_set = (st_table *)blocks; + +#if YJIT_STATS + yjit_runtime_counters.invalidate_method_lookup += block_set->num_entries; +#endif + st_foreach(block_set, block_set_invalidate_i, 0); st_free_table(block_set); @@ -374,6 +381,10 @@ rb_yjit_cme_invalidate(VALUE cme) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L381 if (st_delete(cme_validity_dependency, &cme_as_st_data, &blocks)) { st_table *block_set = (st_table *)blocks; +#if YJIT_STATS + yjit_runtime_counters.invalidate_method_lookup += block_set->num_entries; +#endif + // Invalidate each block st_foreach(block_set, block_set_invalidate_i, 0); @@ -569,19 +580,16 @@ iseq_end_index(VALUE self) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L580 return INT2NUM(block->end_idx); } -static int -block_invalidation_iterator(st_data_t key, st_data_t value, st_data_t data) { - block_t *block = (block_t *)key; - invalidate_block_version(block); // Thankfully, st_table supports deleteing while iterating - return ST_CONTINUE; -} - /* Called when a basic operation is redefined */ void rb_yjit_bop_redefined(VALUE klass, const rb_method_entry_t *me, enum ruby_basic_operators bop) { if (blocks_assuming_bops) { - st_foreach(blocks_assuming_bops, block_invalidation_iterator, 0); +#if YJIT_STATS + yjit_runtime_counters.invalidate_bop_redefined += blocks_assuming_bops->num_entries; +#endif + + st_foreach(blocks_assuming_bops, block_set_invalidate_i, 0); } } @@ -590,10 +598,12 @@ void https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L598 rb_yjit_constant_state_changed(void) { if (blocks_assuming_stable_global_constant_state) { - st_foreach(blocks_assuming_stable_global_constant_state, block_invalidation_iterator, 0); #if YJIT_STATS yjit_runtime_counters.constant_state_bumps++; + yjit_runtime_counters.invalidate_constant_state_bump += blocks_assuming_stable_global_constant_state->num_entries; #endif + + st_foreach(blocks_assuming_stable_global_constant_state, block_set_invalidate_i, 0); } } @@ -629,6 +639,9 @@ yjit_constant_ic_update(const rb_iseq_t *iseq, IC ic) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L639 rb_darray_for(getinlinecache_blocks, i) { block_t *block = rb_darray_get(getinlinecache_blocks, i); invalidate_block_version(block); +#if YJIT_STATS + yjit_runtime_counters.invalidate_constant_ic_fill++; +#endif } } else { @@ -642,7 +655,11 @@ void https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L655 rb_yjit_before_ractor_spawn(void) { if (blocks_assuming_single_ractor_mode) { - st_foreach(blocks_assuming_single_ractor_mode, block_invalidation_iterator, 0); +#if YJIT_STATS + yjit_runtime_counters.invalidate_ractor_spawn += blocks_assuming_single_ractor_mode->num_entries; +#endif + + st_foreach(blocks_assuming_single_ractor_mode, block_set_invalidate_i, 0); } } diff --git a/yjit_iface.h b/yjit_iface.h index ea57dc1282..7820cafc99 100644 --- a/yjit_iface.h +++ b/yjit_iface.h @@ -92,7 +92,14 @@ YJIT_DECLARE_COUNTERS( https://github.com/ruby/ruby/blob/trunk/yjit_iface.h#L92 vm_insns_count, compiled_iseq_count, compiled_block_count, + invalidation_count, + invalidate_method_lookup, + invalidate_bop_redefined, + invalidate_ractor_spawn, + invalidate_constant_state_bump, + invalidate_constant_ic_fill, + constant_state_bumps, expandarray_splat, -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/