@@ -166,31 +166,35 @@ def print_string(string)
166
166
end
167
167
168
168
def exec_with_allocation_control ( value , memory_limit , time_limit , exec_method , overflow_message_type )
169
+ check_memory_limit = true
169
170
if ( defined? ( JRUBY_VERSION ) || ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i <= 0 )
170
- return value . send exec_method
171
+ check_memory_limit = false
171
172
end
172
173
curr_thread = Thread . current
173
174
result = nil
174
175
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 )
176
178
start_time = Time . now . to_f
177
179
178
180
trace = TracePoint . new ( :c_call , :call ) do |tp |
179
181
180
182
if ( rand > 0.75 )
181
- curr_alloc_size = ObjectSpace . memsize_of_all
182
183
curr_time = Time . now . to_f
183
184
184
185
if ( ( curr_time - start_time ) * 1e3 > time_limit )
185
186
curr_thread . raise TimeLimitError . new ( "Timeout: evaluation of #{ exec_method } took longer than #{ time_limit } ms." , "#{ caller . map { |l | "\t #{ l } " } . join ( "\n " ) } " )
186
187
inspect_thread . kill
187
188
end
188
189
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 )
190
193
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
194
198
end
195
199
end
196
200
end . enable {
@@ -309,7 +313,7 @@ def print_catchpoint_deleted(exception_class_name)
309
313
def print_expressions ( exps )
310
314
print_element "expressions" do
311
315
exps . each_with_index do |( exp , value ) , idx |
312
- print_expression ( exp , value , idx + 1 )
316
+ print_expression ( exp , value , idx + 1 )
313
317
end
314
318
end unless exps . empty?
315
319
end
@@ -335,11 +339,11 @@ def print_list(b, e, file, line)
335
339
print "[%d, %d] in %s\n " , b , e , file
336
340
if ( lines = Debugger . source_for ( file ) )
337
341
b . upto ( e ) do |n |
338
- if n > 0 && lines [ n - 1 ]
342
+ if n > 0 && lines [ n - 1 ]
339
343
if n == line
340
- print "=> %d %s\n " , n , lines [ n - 1 ] . chomp
344
+ print "=> %d %s\n " , n , lines [ n - 1 ] . chomp
341
345
else
342
- print " %d %s\n " , n , lines [ n - 1 ] . chomp
346
+ print " %d %s\n " , n , lines [ n - 1 ] . chomp
343
347
end
344
348
end
345
349
end
@@ -397,7 +401,7 @@ def print_inspect(eval_result)
397
401
end
398
402
end
399
403
400
- def print_load_result ( file , exception = nil )
404
+ def print_load_result ( file , exception = nil )
401
405
if exception
402
406
print ( "<loadResult file=\" %s\" exceptionType=\" %s\" exceptionMessage=\" %s\" />" , file , exception . class , CGI . escapeHTML ( exception . to_s ) )
403
407
else
@@ -456,7 +460,7 @@ def compact_array_str(value)
456
460
compact = exec_with_allocation_control ( slice , ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i , ENV [ 'INSPECT_TIME_LIMIT' ] . to_i , :inspect , OverflowMessageType ::NIL_MESSAGE )
457
461
458
462
if compact && value . size != slice . size
459
- compact [ 0 ..compact . size - 2 ] + ", ...]"
463
+ compact [ 0 ..compact . size - 2 ] + ", ...]"
460
464
end
461
465
compact
462
466
end
0 commit comments