mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Try harder to make objects move
Sometimes the objects we allocated may not get compacted. This change is to increase the likelyhood that they will move git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db14ceae42
commit
6c4fd432d0
1 changed files with 42 additions and 30 deletions
|
@ -14,13 +14,17 @@ class TestGCCompact < Test::Unit::TestCase
|
||||||
list.count - same_count
|
list.count - same_count
|
||||||
end
|
end
|
||||||
|
|
||||||
def big_list
|
def big_list(level = 10)
|
||||||
|
if level > 0
|
||||||
|
big_list(level - 1)
|
||||||
|
else
|
||||||
1000.times.map {
|
1000.times.map {
|
||||||
# try to make some empty slots by allocating an object and discarding
|
# try to make some empty slots by allocating an object and discarding
|
||||||
Object.new
|
Object.new
|
||||||
Object.new
|
Object.new
|
||||||
} # likely next to each other
|
} # likely next to each other
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Find an object that's allocated in a slot that had a previous
|
# Find an object that's allocated in a slot that had a previous
|
||||||
# tenant, and that tenant moved and is still alive
|
# tenant, and that tenant moved and is still alive
|
||||||
|
@ -37,7 +41,8 @@ class TestGCCompact < Test::Unit::TestCase
|
||||||
new_object
|
new_object
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_collided_object
|
def try_to_move_objects
|
||||||
|
10.times do
|
||||||
list_of_objects = big_list
|
list_of_objects = big_list
|
||||||
|
|
||||||
ids = list_of_objects.map(&:object_id) # store id in map
|
ids = list_of_objects.map(&:object_id) # store id in map
|
||||||
|
@ -61,7 +66,14 @@ class TestGCCompact < Test::Unit::TestCase
|
||||||
assert_equal ids, new_ids
|
assert_equal ids, new_ids
|
||||||
|
|
||||||
new_tenant = find_object_in_recycled_slot(addresses)
|
new_tenant = find_object_in_recycled_slot(addresses)
|
||||||
assert new_tenant
|
return [list_of_objects, addresses, new_tenant] if new_tenant
|
||||||
|
end
|
||||||
|
|
||||||
|
flunk "Couldn't get objects to move"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_collided_object
|
||||||
|
list_of_objects, addresses, new_tenant = try_to_move_objects
|
||||||
|
|
||||||
# This is the object that used to be in new_object's position
|
# This is the object that used to be in new_object's position
|
||||||
previous_tenant = list_of_objects[addresses.index(memory_location(new_tenant))]
|
previous_tenant = list_of_objects[addresses.index(memory_location(new_tenant))]
|
||||||
|
|
Loading…
Add table
Reference in a new issue