Skip to content

Commit 828f0d8

Browse files
viuginick1valich
authored andcommitted
let timeout checks for jruby and little refactoring
1 parent da413e4 commit 828f0d8

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
@@ -309,7 +313,7 @@ def print_catchpoint_deleted(exception_class_name)
309313
def print_expressions(exps)
310314
print_element "expressions" do
311315
exps.each_with_index do |(exp, value), idx|
312-
print_expression(exp, value, idx+1)
316+
print_expression(exp, value, idx + 1)
313317
end
314318
end unless exps.empty?
315319
end
@@ -335,11 +339,11 @@ def print_list(b, e, file, line)
335339
print "[%d, %d] in %s\n", b, e, file
336340
if (lines = Debugger.source_for(file))
337341
b.upto(e) do |n|
338-
if n > 0 && lines[n-1]
342+
if n > 0 && lines[n - 1]
339343
if n == line
340-
print "=> %d %s\n", n, lines[n-1].chomp
344+
print "=> %d %s\n", n, lines[n - 1].chomp
341345
else
342-
print " %d %s\n", n, lines[n-1].chomp
346+
print " %d %s\n", n, lines[n - 1].chomp
343347
end
344348
end
345349
end
@@ -397,7 +401,7 @@ def print_inspect(eval_result)
397401
end
398402
end
399403

400-
def print_load_result(file, exception=nil)
404+
def print_load_result(file, exception = nil)
401405
if exception
402406
print("<loadResult file=\"%s\" exceptionType=\"%s\" exceptionMessage=\"%s\"/>", file, exception.class, CGI.escapeHTML(exception.to_s))
403407
else
@@ -456,7 +460,7 @@ def compact_array_str(value)
456460
compact = exec_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :inspect, OverflowMessageType::NIL_MESSAGE)
457461

458462
if compact && value.size != slice.size
459-
compact[0..compact.size-2] + ", ...]"
463+
compact[0..compact.size - 2] + ", ...]"
460464
end
461465
compact
462466
end

0 commit comments

Comments
 (0)