11#!/usr/bin/env ruby
22require 'logger'
33require 'open3'
4+ require 'shellwords'
45require 'tempfile'
56require 'timeout'
67
78RUBY = ARGV [ 0 ] || raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> <options>" )
8- OPTIONS = ARGV [ 1 ] || raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> <options>" )
9+ OPTIONS = ARGV [ 1 ..]
10+ raise ( "Usage: ruby jit_bisect.rb <path_to_ruby> -- <options>" ) if OPTIONS . empty?
911TIMEOUT_SEC = 5
1012LOGGER = Logger . new ( $stdout)
1113
@@ -65,7 +67,8 @@ def run_with_jit_list(ruby, options, jit_list)
6567 temp_file . flush
6668 temp_file . close
6769 # Run the JIT with the temporary file
68- Open3 . capture3 ( "#{ ruby } --zjit-allowed-iseqs=#{ temp_file . path } #{ options } " )
70+ command = Shellwords . join [ ruby , "--zjit-allowed-iseqs=#{ temp_file . path } " , *options ]
71+ Open3 . capture3 ( command )
6972 end
7073end
7174
@@ -77,7 +80,8 @@ def run_with_jit_list(ruby, options, jit_list)
7780# Collect the JIT list from the failing Ruby process
7881jit_list = nil
7982Tempfile . create "jit_list" do |temp_file |
80- Open3 . capture3 ( "#{ RUBY } --zjit-log-compiled-iseqs=#{ temp_file . path } #{ OPTIONS } " )
83+ command = Shellwords . join [ RUBY , "--zjit-log-compiled-iseqs=#{ temp_file . path } " , *OPTIONS ]
84+ Open3 . capture3 ( command )
8185 jit_list = File . readlines ( temp_file . path ) . map ( &:strip ) . reject ( &:empty? )
8286end
8387LOGGER . info ( "Starting with JIT list of #{ jit_list . length } items." )
@@ -94,6 +98,7 @@ def run_with_jit_list(ruby, options, jit_list)
9498 file . puts ( result )
9599end
96100puts "Run:"
97- puts "#{ RUBY } --zjit-allowed-iseqs=jitlist.txt #{ OPTIONS } "
101+ command = Shellwords . join [ RUBY , "--zjit-allowed-iseqs=jitlist.txt" , *OPTIONS ]
102+ puts command
98103puts "Reduced JIT list (available in jitlist.txt):"
99104puts result
0 commit comments