Skip to content

Commit 8032674

Browse files
committed
Synchronize access of ALLOCATIONS in ObjectSpace
1 parent 9b8b857 commit 8032674

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/truffle/objspace.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ def trace_object_allocations
193193
module_function :trace_object_allocations
194194

195195
def trace_object_allocations_clear
196-
ALLOCATIONS.clear
196+
Truffle::System.synchronized(ALLOCATIONS) do
197+
ALLOCATIONS.clear
198+
end
197199
end
198200
module_function :trace_object_allocations_clear
199201

@@ -213,21 +215,27 @@ def trace_object_allocations_stop
213215
module_function :trace_object_allocations_stop
214216

215217
def allocation_class_path(object)
216-
allocation = ALLOCATIONS[object]
218+
allocation = Truffle::System.synchronized(ALLOCATIONS) do
219+
ALLOCATIONS[object]
220+
end
217221
return nil if allocation.nil?
218222
allocation.class_path
219223
end
220224
module_function :allocation_class_path
221225

222226
def allocation_generation(object)
223-
allocation = ALLOCATIONS[object]
227+
allocation = Truffle::System.synchronized(ALLOCATIONS) do
228+
ALLOCATIONS[object]
229+
end
224230
return nil if allocation.nil?
225231
allocation.generation
226232
end
227233
module_function :allocation_generation
228234

229235
def allocation_method_id(object)
230-
allocation = ALLOCATIONS[object]
236+
allocation = Truffle::System.synchronized(ALLOCATIONS) do
237+
ALLOCATIONS[object]
238+
end
231239
return nil if allocation.nil?
232240

233241
method_id = allocation.method_id
@@ -238,14 +246,18 @@ def allocation_method_id(object)
238246
module_function :allocation_method_id
239247

240248
def allocation_sourcefile(object)
241-
allocation = ALLOCATIONS[object]
249+
allocation = Truffle::System.synchronized(ALLOCATIONS) do
250+
ALLOCATIONS[object]
251+
end
242252
return nil if allocation.nil?
243253
allocation.sourcefile
244254
end
245255
module_function :allocation_sourcefile
246256

247257
def allocation_sourceline(object)
248-
allocation = ALLOCATIONS[object]
258+
allocation = Truffle::System.synchronized(ALLOCATIONS) do
259+
ALLOCATIONS[object]
260+
end
249261
return nil if allocation.nil?
250262
allocation.sourceline
251263
end
@@ -256,7 +268,10 @@ def allocation_sourceline(object)
256268
ALLOCATIONS = {}.compare_by_identity
257269

258270
def trace_allocation(object, class_path, method_id, sourcefile, sourceline, generation)
259-
ALLOCATIONS[object] = Allocation.new(class_path, method_id, sourcefile, sourceline, generation)
271+
allocation = Allocation.new(class_path, method_id, sourcefile, sourceline, generation)
272+
Truffle::System.synchronized(ALLOCATIONS) do
273+
ALLOCATIONS[object] = allocation
274+
end
260275
end
261276
module_function :trace_allocation
262277

0 commit comments

Comments
 (0)