123456789_123456789_123456789_123456789_123456789_

Module: RubyVM::ZJIT

Relationships & Source Files
Defined in: zjit.rb

Overview

This module allows for introspection of ZJIT, 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 ZJIT does not support the particular platform for which CRuby is built.

Class Attribute Summary

Class Method Summary

Class Attribute Details

.enabled?Boolean (readonly)

Check if ZJIT is enabled

[ GitHub ]

  
# File 'zjit.rb', line 18

def enabled?
  Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)'
end

.stats_enabled?Boolean (readonly)

Check if –zjit-stats is used

[ GitHub ]

  
# File 'zjit.rb', line 23

def stats_enabled?
  Primitive.rb_zjit_stats_enabled_p
end

Class Method Details

.assert_compiles

This method is for internal use only.

Assert that any future ZJIT compilation will return a function pointer

[ GitHub ]

  
# File 'zjit.rb', line 94

def assert_compiles # :nodoc:
  Primitive.rb_zjit_assert_compiles
end

.number_with_delimiter(number) (private)

This method is for internal use only.
[ GitHub ]

  
# File 'zjit.rb', line 101

def number_with_delimiter(number)
  s = number.to_s
  i = s.index('.') || s.size
  s.insert(i -= 3, ',') while i > 3
  s
end

.stats(key = nil)

Return ZJIT statistics as a ::Hash

[ GitHub ]

  
# File 'zjit.rb', line 28

def stats(key = nil)
  stats = Primitive.rb_zjit_stats(key)
  return stats if stats.nil? || !key.nil?

  if stats.key?(:vm_insns_count) && stats.key?(:zjit_insns_count)
    stats[:total_insns_count] = stats[:vm_insns_count] + stats[:zjit_insns_count]
    stats[:ratio_in_zjit] = 100.0 * stats[:zjit_insns_count] / stats[:total_insns_count]
  end

  stats
end

.stats_string

Get the summary of ZJIT statistics as a ::String

[ GitHub ]

  
# File 'zjit.rb', line 41

def stats_string
  buf = +"***ZJIT: Printing ZJIT statistics on exit***\n"
  stats = self.stats

  print_counters_with_prefix(prefix: 'failed_', prompt: 'compilation failure reasons', buf:, stats:)
  print_counters([
    :compiled_iseq_count,
    :compilation_failure,

    :compile_time_ns,
    :profile_time_ns,
    :gc_time_ns,
    :invalidation_time_ns,

    :total_insns_count,
    :vm_insns_count,
    :zjit_insns_count,
    :ratio_in_zjit,
  ], buf:, stats:)

  buf
end