Skip to content

Commit d441a0a

Browse files
committed
keep timelimit check for jruby
1 parent f740856 commit d441a0a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module Debugger
77

88
module OverflowMessageType
99
NIL_MESSAGE = lambda {|e| nil}
10-
EXCEPTION_MESSAGE = lambda {|e| e.message}
11-
SPECIAL_SYMBOL_MESSAGE = lambda {|e| '<?>'}
10+
EXCEPTION_MESSAGE = lambda {|e| e.message}
11+
SPECIAL_SYMBOL_MESSAGE = lambda {|e| '<?>'}
1212
end
1313

1414
class MemoryLimitError < StandardError
@@ -166,31 +166,35 @@ def print_string(string)
166166
end
167167

168168
def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, overflow_message_type)
169+
check_memory_limit = true
169170
if (defined?(JRUBY_VERSION) || ENV['DEBUGGER_MEMORY_LIMIT'].to_i <= 0)
170-
return value.send exec_method
171+
check_memory_limit = false
171172
end
172173
curr_thread = Thread.current
173174
result = nil
174175
inspect_thread = DebugThread.start {
175-
start_alloc_size = ObjectSpace.memsize_of_all
176+
177+
start_alloc_size = ObjectSpace.memsize_of_all if (check_memory_limit)
176178
start_time = Time.now.to_f
177179

178180
trace = TracePoint.new(:c_call, :call) do |tp|
179181

180182
if (rand > 0.75)
181-
curr_alloc_size = ObjectSpace.memsize_of_all
182183
curr_time = Time.now.to_f
183184

184185
if ((curr_time - start_time) * 1e3 > time_limit)
185186
curr_thread.raise TimeLimitError.new("Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.", "#{caller.map {|l| "\t#{l}"}.join("\n")}")
186187
inspect_thread.kill
187188
end
188189

189-
start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size)
190+
if (check_memory_limit)
191+
curr_alloc_size = ObjectSpace.memsize_of_all
192+
start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size)
190193

191-
if (curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
192-
curr_thread.raise MemoryLimitError.new("Out of memory: evaluation of #{exec_method} took more than #{memory_limit}mb.", "#{caller.map {|l| "\t#{l}"}.join("\n")}")
193-
inspect_thread.kill
194+
if (curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
195+
curr_thread.raise MemoryLimitError.new("Out of memory: evaluation of #{exec_method} took more than #{memory_limit}mb.", "#{caller.map {|l| "\t#{l}"}.join("\n")}")
196+
inspect_thread.kill
197+
end
194198
end
195199
end
196200
end.enable {

0 commit comments

Comments
 (0)