summaryrefslogtreecommitdiff
path: root/test/ruby/test_gc.rb
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2019-10-31 17:21:01 -0700
committerAaron Patterson <tenderlove@github.com>2019-11-06 14:59:53 -0800
commitbd2b314a05ae9192b3143e1e678a37c370d8a9ce (patch)
tree48b0eb3f52f84b3f256c3b2575864f270609e551 /test/ruby/test_gc.rb
parentd1630d41adb13c646a9d76cf541d3c26b6bbb10f (diff)
Use a monotonically increasing number for object_id
This changes object_id from being based on the objects location in memory (or a nearby memory location in the case of a conflict) to be based on an always increasing number. This number is a Ruby Integer which allows it to overflow the size of a pointer without issue (very unlikely to happen in real programs especially on 64-bit, but a nice guarantee). This changes obj_to_id_tbl and id_to_obj_tbl to both be maps of Ruby objects to Ruby objects (previously they were Ruby object to C integer) which simplifies updating them after compaction as we can run them through gc_update_table_refs. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2638
Diffstat (limited to 'test/ruby/test_gc.rb')
-rw-r--r--test/ruby/test_gc.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 1511ea3011..f42e098863 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -461,4 +461,12 @@ class TestGc < Test::Unit::TestCase
skip "finalizers did not get run" if @result.empty?
assert_equal([:c1, :c2], @result)
end
+
+ def test_object_ids_never_repeat
+ GC.start
+ a = 1000.times.map { Object.new.object_id }
+ GC.start
+ b = 1000.times.map { Object.new.object_id }
+ assert_empty(a & b)
+ end
end