From e4a824f7695a8de9afb90978ccda038b7d280372 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 27 Dec 2022 23:04:53 -0800 Subject: [PATCH] Fix broken rebase --- lib/ruby_vm/mjit/c_pointer.rb | 6 +- lib/ruby_vm/mjit/c_type.rb | 2 +- lib/ruby_vm/mjit/compiler.rb | 10 +-- lib/{ => ruby_vm}/mjit/context.rb | 0 lib/ruby_vm/mjit/hooks.rb | 32 --------- lib/{ => ruby_vm}/mjit/insn_compiler.rb | 0 lib/{ => ruby_vm}/mjit/jit_state.rb | 0 lib/{ => ruby_vm}/mjit/stats.rb | 0 lib/{ => ruby_vm}/mjit/x86_assembler.rb | 0 mjit.c | 86 ------------------------- mjit.rb | 6 +- vm_insnhelper.c | 1 - vm_method.c | 4 -- 13 files changed, 12 insertions(+), 135 deletions(-) rename lib/{ => ruby_vm}/mjit/context.rb (100%) delete mode 100644 lib/ruby_vm/mjit/hooks.rb rename lib/{ => ruby_vm}/mjit/insn_compiler.rb (100%) rename lib/{ => ruby_vm}/mjit/jit_state.rb (100%) rename lib/{ => ruby_vm}/mjit/stats.rb (100%) rename lib/{ => ruby_vm}/mjit/x86_assembler.rb (100%) diff --git a/lib/ruby_vm/mjit/c_pointer.rb b/lib/ruby_vm/mjit/c_pointer.rb index 0ba9baa7cd..6bdf92b6cf 100644 --- a/lib/ruby_vm/mjit/c_pointer.rb +++ b/lib/ruby_vm/mjit/c_pointer.rb @@ -1,4 +1,4 @@ -module RubyVM::MJIT # :nodoc: all +module RubyVM::MJIT # Every class under this namespace is a pointer. Even if the type is # immediate, it shouldn't be dereferenced until `*` is called. module CPointer @@ -293,12 +293,12 @@ module RubyVM::MJIT # :nodoc: all # Dereference def * - byte = Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_CHAR].unpack1('c') + byte = Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_CHAR].unpack('c').first if @width == 1 bit = (1 & (byte >> @offset)) bit == 1 elsif @width <= 8 && @offset == 0 - bitmask = @width.times.sum { |i| 1 << i } + bitmask = @width.times.map { |i| 1 << i }.sum byte & bitmask else raise NotImplementedError.new("not-implemented bit field access: width=#{@width} offset=#{@offset}") diff --git a/lib/ruby_vm/mjit/c_type.rb b/lib/ruby_vm/mjit/c_type.rb index 9c965ad2fb..9e45d8d41c 100644 --- a/lib/ruby_vm/mjit/c_type.rb +++ b/lib/ruby_vm/mjit/c_type.rb @@ -2,7 +2,7 @@ require 'fiddle' require 'fiddle/pack' require_relative 'c_pointer' -module RubyVM::MJIT # :nodoc: all +module RubyVM::MJIT module CType module Struct # @param name [String] diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index 3dfea7088e..396e93cb04 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -1,8 +1,8 @@ -require 'mjit/context' -require 'mjit/insn_compiler' -require 'mjit/instruction' -require 'mjit/jit_state' -require 'mjit/x86_assembler' +require 'ruby_vm/mjit/context' +require 'ruby_vm/mjit/insn_compiler' +require 'ruby_vm/mjit/instruction' +require 'ruby_vm/mjit/jit_state' +require 'ruby_vm/mjit/x86_assembler' module RubyVM::MJIT # Compilation status diff --git a/lib/mjit/context.rb b/lib/ruby_vm/mjit/context.rb similarity index 100% rename from lib/mjit/context.rb rename to lib/ruby_vm/mjit/context.rb diff --git a/lib/ruby_vm/mjit/hooks.rb b/lib/ruby_vm/mjit/hooks.rb deleted file mode 100644 index 3fb1004111..0000000000 --- a/lib/ruby_vm/mjit/hooks.rb +++ /dev/null @@ -1,32 +0,0 @@ -module RubyVM::MJIT::Hooks # :nodoc: all - C = RubyVM::MJIT.const_get(:C, false) - - def self.on_bop_redefined(_redefined_flag, _bop) - C.mjit_cancel_all("BOP is redefined") - end - - def self.on_cme_invalidate(_cme) - # to be used later - end - - def self.on_ractor_spawn - C.mjit_cancel_all("Ractor is spawned") - end - - def self.on_constant_state_changed(_id) - # to be used later - end - - def self.on_constant_ic_update(_iseq, _ic, _insn_idx) - # to be used later - end - - def self.on_tracing_invalidate_all(new_iseq_events) - # Stop calling all JIT-ed code. We can't rewrite existing JIT-ed code to trace_ insns for now. - # :class events are triggered only in ISEQ_TYPE_CLASS, but mjit_target_iseq_p ignores such iseqs. - # Thus we don't need to cancel JIT-ed code for :class events. - if new_iseq_events != C.RUBY_EVENT_CLASS - C.mjit_cancel_all("TracePoint is enabled") - end - end -end diff --git a/lib/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb similarity index 100% rename from lib/mjit/insn_compiler.rb rename to lib/ruby_vm/mjit/insn_compiler.rb diff --git a/lib/mjit/jit_state.rb b/lib/ruby_vm/mjit/jit_state.rb similarity index 100% rename from lib/mjit/jit_state.rb rename to lib/ruby_vm/mjit/jit_state.rb diff --git a/lib/mjit/stats.rb b/lib/ruby_vm/mjit/stats.rb similarity index 100% rename from lib/mjit/stats.rb rename to lib/ruby_vm/mjit/stats.rb diff --git a/lib/mjit/x86_assembler.rb b/lib/ruby_vm/mjit/x86_assembler.rb similarity index 100% rename from lib/mjit/x86_assembler.rb rename to lib/ruby_vm/mjit/x86_assembler.rb diff --git a/mjit.c b/mjit.c index 9c3637b133..9dd48ff311 100644 --- a/mjit.c +++ b/mjit.c @@ -129,92 +129,6 @@ static VALUE rb_mMJITC = 0; static VALUE rb_MJITCompiler = 0; // RubyVM::MJIT::CPointer::Struct_rb_iseq_t static VALUE rb_cMJITIseqPtr = 0; -// RubyVM::MJIT::CPointer::Struct_IC -static VALUE rb_cMJITICPtr = 0; -// RubyVM::MJIT::Compiler -static VALUE rb_mMJITHooks = 0; - -#define WITH_MJIT_DISABLED(stmt) do { \ - bool original_call_p = mjit_call_p; \ - mjit_call_p = false; \ - stmt; \ - mjit_call_p = original_call_p; \ - if (mjit_cancel_p) mjit_call_p = false; \ -} while (0); - -// Hook MJIT when BOP is redefined. -MJIT_FUNC_EXPORTED void -rb_mjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - WITH_MJIT_DISABLED({ - rb_funcall(rb_mMJITHooks, rb_intern("on_bop_redefined"), 2, INT2NUM(redefined_flag), INT2NUM((int)bop)); - }); -} - -// Hook MJIT when CME is invalidated. -MJIT_FUNC_EXPORTED void -rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - WITH_MJIT_DISABLED({ - VALUE cme_klass = rb_funcall(rb_mMJITC, rb_intern("rb_callable_method_entry_struct"), 0); - VALUE cme_ptr = rb_funcall(cme_klass, rb_intern("new"), 1, SIZET2NUM((size_t)cme)); - rb_funcall(rb_mMJITHooks, rb_intern("on_cme_invalidate"), 1, cme_ptr); - }); -} - -// Hook MJIT when Ractor is spawned. -void -rb_mjit_before_ractor_spawn(void) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - WITH_MJIT_DISABLED({ - rb_funcall(rb_mMJITHooks, rb_intern("on_ractor_spawn"), 0); - }); -} - -static void -mjit_constant_state_changed(void *data) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - ID id = (ID)data; - WITH_MJIT_DISABLED({ - rb_funcall(rb_mMJITHooks, rb_intern("on_constant_state_changed"), 1, ID2SYM(id)); - }); -} - -// Hook MJIT when constant state is changed. -MJIT_FUNC_EXPORTED void -rb_mjit_constant_state_changed(ID id) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - // Asynchronously hook the Ruby code since this is hooked during a "Ruby critical section". - extern int rb_workqueue_register(unsigned flags, rb_postponed_job_func_t func, void *data); - rb_workqueue_register(0, mjit_constant_state_changed, (void *)id); -} - -// Hook MJIT when constant IC is updated. -MJIT_FUNC_EXPORTED void -rb_mjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - WITH_MJIT_DISABLED({ - VALUE iseq_ptr = rb_funcall(rb_cMJITIseqPtr, rb_intern("new"), 1, SIZET2NUM((size_t)iseq)); - VALUE ic_ptr = rb_funcall(rb_cMJITICPtr, rb_intern("new"), 1, SIZET2NUM((size_t)ic)); - rb_funcall(rb_mMJITHooks, rb_intern("on_constant_ic_update"), 3, iseq_ptr, ic_ptr, UINT2NUM(insn_idx)); - }); -} - -// Hook MJIT when TracePoint is enabled. -MJIT_FUNC_EXPORTED void -rb_mjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events) -{ - if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; - WITH_MJIT_DISABLED({ - rb_funcall(rb_mMJITHooks, rb_intern("on_tracing_invalidate_all"), 1, UINT2NUM(new_iseq_events)); - }); -} void rb_mjit_add_iseq_to_process(const rb_iseq_t *iseq) diff --git a/mjit.rb b/mjit.rb index e6f142b030..0c048f1b27 100644 --- a/mjit.rb +++ b/mjit.rb @@ -23,7 +23,7 @@ if RubyVM::MJIT.enabled? return # miniruby doesn't support MJIT end - require 'mjit/c_type' - require 'mjit/compiler' - require 'mjit/stats' + require 'ruby_vm/mjit/c_type' + require 'ruby_vm/mjit/compiler' + require 'ruby_vm/mjit/stats' end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index b2321ed7c8..ea3220fe5d 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -5530,7 +5530,6 @@ vm_ic_update(const rb_iseq_t *iseq, IC ic, VALUE val, const VALUE *reg_ep, const RUBY_ASSERT(pc >= ISEQ_BODY(iseq)->iseq_encoded); unsigned pos = (unsigned)(pc - ISEQ_BODY(iseq)->iseq_encoded); rb_yjit_constant_ic_update(iseq, ic, pos); - rb_mjit_constant_ic_update(iseq, ic, pos); } static VALUE diff --git a/vm_method.c b/vm_method.c index 98af316fe6..82c29624c1 100644 --- a/vm_method.c +++ b/vm_method.c @@ -124,7 +124,6 @@ vm_cme_invalidate(rb_callable_method_entry_t *cme) RB_DEBUG_COUNTER_INC(cc_cme_invalidate); rb_yjit_cme_invalidate(cme); - rb_mjit_cme_invalidate(cme); } static int @@ -150,7 +149,6 @@ rb_clear_constant_cache_for_id(ID id) } rb_yjit_constant_state_changed(id); - rb_mjit_constant_state_changed(id); } static void @@ -190,7 +188,6 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, &ccs_data)) { struct rb_class_cc_entries *ccs = (struct rb_class_cc_entries *)ccs_data; rb_yjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme); - rb_mjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme); if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid); rb_vm_ccs_free(ccs); rb_id_table_delete(cc_tbl, mid); @@ -203,7 +200,6 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) VALUE cme; if (rb_yjit_enabled_p() && rb_id_table_lookup(cm_tbl, mid, &cme)) { rb_yjit_cme_invalidate((rb_callable_method_entry_t *)cme); - rb_mjit_cme_invalidate((rb_callable_method_entry_t *)cme); } rb_id_table_delete(cm_tbl, mid); RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable);