@@ -72,38 +72,56 @@ def run_bisect(command, items)
7272 bisect_impl ( command , [ ] , items )
7373end
7474
75+ def run_ruby *cmd
76+ stdout_data = nil
77+ stderr_data = nil
78+ status = nil
79+ Open3 . popen3 ( Shellwords . join cmd ) do |stdin , stdout , stderr , wait_thr |
80+ pid = wait_thr . pid
81+ begin
82+ Timeout . timeout ( ARGS [ :timeout ] ) do
83+ stdout_data = stdout . read
84+ stderr_data = stderr . read
85+ status = wait_thr . value
86+ end
87+ rescue Timeout ::Error
88+ Process . kill ( "KILL" , pid )
89+ stderr_data = "(killed due to timeout)"
90+ # Wait for the process to be reaped
91+ wait_thr . value
92+ status = 1
93+ end
94+ end
95+ [ stdout_data , stderr_data , status ]
96+ end
97+
7598def run_with_jit_list ( ruby , options , jit_list )
7699 # Make a new temporary file containing the JIT list
77100 Tempfile . create ( "jit_list" ) do |temp_file |
78101 temp_file . write ( jit_list . join ( "\n " ) )
79102 temp_file . flush
80103 temp_file . close
81104 # Run the JIT with the temporary file
82- command = Shellwords . join [ ruby , "--zjit-allowed-iseqs=#{ temp_file . path } " , *options ]
83- Open3 . capture3 ( command )
105+ run_ruby ruby , "--zjit-allowed-iseqs=#{ temp_file . path } " , *options
84106 end
85107end
86108
87109# Try running with no JIT list to get a stable baseline
88- _ , stderr , status = run_with_jit_list ( RUBY , OPTIONS , [ ] )
89- if ! status . success?
110+ _ , stderr , exitcode = run_with_jit_list ( RUBY , OPTIONS , [ ] )
111+ if exitcode != 0
90112 raise "Command failed with empty JIT list: #{ stderr } "
91113end
92114# Collect the JIT list from the failing Ruby process
93115jit_list = nil
94116Tempfile . create "jit_list" do |temp_file |
95- command = Shellwords . join [ RUBY , "--zjit-log-compiled-iseqs=#{ temp_file . path } " , *OPTIONS ]
96- Open3 . capture3 ( command )
117+ run_ruby RUBY , "--zjit-log-compiled-iseqs=#{ temp_file . path } " , *OPTIONS
97118 jit_list = File . readlines ( temp_file . path ) . map ( &:strip ) . reject ( &:empty? )
98119end
99120LOGGER . info ( "Starting with JIT list of #{ jit_list . length } items." )
100121# Now narrow it down
101122command = lambda do |items |
102- status = Timeout . timeout ( ARGS [ :timeout ] ) do
103- _ , _ , status = run_with_jit_list ( RUBY , OPTIONS , items )
104- status
105- end
106- status . success?
123+ _ , _ , exitcode = run_with_jit_list ( RUBY , OPTIONS , items )
124+ exitcode == 0
107125end
108126result = run_bisect ( command , jit_list )
109127File . open ( "jitlist.txt" , "w" ) do |file |
0 commit comments