diff options
Diffstat (limited to 'yjit.rb')
| -rw-r--r-- | yjit.rb | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -1,14 +1,14 @@ # frozen_string_literal: true # :markup: markdown -# This module allows for introspection of \YJIT, CRuby's just-in-time compiler. +# This module allows for introspection of YJIT, CRuby's just-in-time compiler. # Everything in the module is highly implementation specific and the API might # be less stable compared to the standard library. # -# This module may not exist if \YJIT does not support the particular platform +# This module may not exist if YJIT does not support the particular platform # for which CRuby is built. module RubyVM::YJIT - # Check if \YJIT is enabled. + # Check if YJIT is enabled. def self.enabled? Primitive.cexpr! 'RBOOL(rb_yjit_enabled_p)' end @@ -33,8 +33,8 @@ module RubyVM::YJIT Primitive.rb_yjit_reset_stats_bang end - # Enable \YJIT compilation. `stats` option decides whether to enable \YJIT stats or not. `log` decides - # whether to enable \YJIT compilation logging or not. Optional `mem_size` and `call_threshold` can be + # Enable YJIT compilation. `stats` option decides whether to enable YJIT stats or not. `log` decides + # whether to enable YJIT compilation logging or not. Optional `mem_size` and `call_threshold` can be # provided to override default configuration. # # * `stats`: @@ -48,6 +48,11 @@ module RubyVM::YJIT def self.enable(stats: false, log: false, mem_size: nil, call_threshold: nil) return false if enabled? + if Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)' + warn("Only one JIT can be enabled at the same time.") + return false + end + if mem_size raise ArgumentError, "mem_size must be a Integer" unless mem_size.is_a?(Integer) raise ArgumentError, "mem_size must be between 1 and 2048 MB" unless (1..2048).include?(mem_size) @@ -59,7 +64,6 @@ module RubyVM::YJIT end at_exit { print_and_dump_stats } if stats - call_yjit_hooks Primitive.rb_yjit_enable(stats, stats != :quiet, log, log != :quiet, mem_size, call_threshold) end @@ -215,7 +219,7 @@ module RubyVM::YJIT if !self.enabled? warn( "YJIT needs to be enabled to produce disasm output, e.g.\n" + - "ruby --yjit-call-threshold=1 my_script.rb (see doc/yjit/yjit.md)" + "ruby --yjit-call-threshold=1 my_script.rb (see doc/jit/yjit.md)" ) return nil end @@ -225,7 +229,7 @@ module RubyVM::YJIT if !disasm_str warn( "YJIT disasm is only available when YJIT is built in dev mode, i.e.\n" + - "./configure --enable-yjit=dev (see doc/yjit/yjit.md)\n" + "./configure --enable-yjit=dev (see doc/jit/yjit.md)\n" ) return nil end @@ -260,23 +264,23 @@ module RubyVM::YJIT end # Blocks that are called when YJIT is enabled - @yjit_hooks = [] + @jit_hooks = [] class << self # :stopdoc: private # Register a block to be called when YJIT is enabled - def add_yjit_hook(hook) - @yjit_hooks << hook + def add_jit_hook(hook) + @jit_hooks << hook end - # Run YJIT hooks registered by RubyVM::YJIT.with_yjit - def call_yjit_hooks + # Run YJIT hooks registered by `#with_jit` + def call_jit_hooks # Skip using builtin methods in Ruby if --yjit-c-builtin is given return if Primitive.yjit_c_builtin_p - @yjit_hooks.each(&:call) - @yjit_hooks.clear + @jit_hooks.each(&:call) + @jit_hooks.clear end # Print stats and dump exit locations @@ -318,7 +322,6 @@ module RubyVM::YJIT leave objtostring opt_aref - opt_aref_with opt_aset opt_case_dispatch opt_div @@ -350,6 +353,9 @@ module RubyVM::YJIT # Number of failed compiler invocations compilation_failure = stats[:compilation_failure] + # Number of refused exceptional entries with an escaped environment + exceptional_entry_escaped_env = stats[:exceptional_entry_escaped_env] + code_region_overhead = stats[:code_region_size] - (stats[:inline_code_size] + stats[:outlined_code_size]) out.puts "num_send: " + format_number(13, stats[:num_send]) @@ -386,6 +392,7 @@ module RubyVM::YJIT out.puts "bindings_allocations: " + format_number(13, stats[:binding_allocations]) out.puts "bindings_set: " + format_number(13, stats[:binding_set]) out.puts "compilation_failure: " + format_number(13, compilation_failure) if compilation_failure != 0 + out.puts "exceptional_entry_escaped_env:" + format_number(6, exceptional_entry_escaped_env) if exceptional_entry_escaped_env != 0 out.puts "live_iseq_count: " + format_number(13, stats[:live_iseq_count]) out.puts "iseq_alloc_count: " + format_number(13, stats[:iseq_alloc_count]) out.puts "compiled_iseq_entry: " + format_number(13, stats[:compiled_iseq_entry]) |
