From bd2b314a05ae9192b3143e1e678a37c370d8a9ce Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 31 Oct 2019 17:21:01 -0700 Subject: 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 --- bootstraptest/test_objectspace.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_objectspace.rb b/bootstraptest/test_objectspace.rb index 24a1a0ce2c..63a8d99322 100644 --- a/bootstraptest/test_objectspace.rb +++ b/bootstraptest/test_objectspace.rb @@ -44,3 +44,12 @@ assert_normal_exit %q{ Thread.new {} end }, '[ruby-core:37858]' + +assert_equal 'ok', %q{ + objects_and_ids = 1000.times.map { o = Object.new; [o, o.object_id] } + objects_and_ids.each { |expected, id| + actual = ObjectSpace._id2ref(id) + raise "expected #{expected.inspect}, got #{actual.inspect}" unless actual.equal?(expected) + } + 'ok' +} -- cgit v1.2.3