From 3ed7fa76e0dad293bf7d1b7a6672aa0f1589e0b2 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 7 Feb 2023 23:32:13 -0800 Subject: [PATCH] Implement counted exits --- lib/ruby_vm/mjit/insn_compiler.rb | 11 +++++++++-- mjit_c.h | 3 ++- mjit_c.rb | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index 285ba41102..cfbd1cd65d 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -571,7 +571,7 @@ module RubyVM::MJIT return CantCompile end asm.mov(:rax, [CFP, C.rb_control_frame_t.offsetof(:self)]) - guard_object_is_heap(asm, :rax, side_exit) # TODO: counted side exit + guard_object_is_heap(asm, :rax, counted_exit(side_exit, :getivar_not_heap)) case C.BUILTIN_TYPE(comptime_obj) when C.T_OBJECT @@ -589,7 +589,7 @@ module RubyVM::MJIT asm.comment('guard shape') asm.cmp(DwordPtr[:rax, C.rb_shape_id_offset], shape_id) - asm.jne(side_exit) # TODO: counted side exit + asm.jne(counted_exit(side_exit, :getivar_polymorphic)) index = C.rb_shape_get_iv_index(shape_id, ivar_id) if index @@ -935,6 +935,13 @@ module RubyVM::MJIT jit.side_exits[jit.pc] = @ocb.write(asm) end + def counted_exit(side_exit, name) + asm = Assembler.new + asm.incr_counter(name) + asm.jmp(side_exit) + @ocb.write(asm) + end + def def_iseq_ptr(cme_def) C.rb_iseq_check(cme_def.body.iseq.iseqptr) end diff --git a/mjit_c.h b/mjit_c.h index d84b0f92cc..e5471b96f7 100644 --- a/mjit_c.h +++ b/mjit_c.h @@ -119,8 +119,9 @@ MJIT_RUNTIME_COUNTERS( send_kwarg, send_tailcall, - getivar_not_embedded, + getivar_not_heap, getivar_not_t_object, + getivar_polymorphic, getivar_special_const, getivar_too_complex, diff --git a/mjit_c.rb b/mjit_c.rb index 980f3ee36c..525a9b8f4c 100644 --- a/mjit_c.rb +++ b/mjit_c.rb @@ -864,8 +864,9 @@ module RubyVM::MJIT # :nodoc: all send_args_splat: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_args_splat)")], send_kwarg: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_kwarg)")], send_tailcall: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_tailcall)")], - getivar_not_embedded: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_not_embedded)")], + getivar_not_heap: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_not_heap)")], getivar_not_t_object: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_not_t_object)")], + getivar_polymorphic: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_polymorphic)")], getivar_special_const: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_special_const)")], getivar_too_complex: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), getivar_too_complex)")], compiled_block_count: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), compiled_block_count)")],