summaryrefslogtreecommitdiff
path: root/test/objspace/test_objspace.rb
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2022-12-06 12:56:51 +0100
committerJean Boussier <jean.boussier@gmail.com>2022-12-08 18:46:16 +0100
commit73771e4b192f3db62efb854affdfc95babba1d35 (patch)
tree6f15d7fea885b5e639c82b51d5c3fd50b9200735 /test/objspace/test_objspace.rb
parentb19490f75dd790f2f886df2c05ed8fba947326a9 (diff)
ObjectSpace.dump_all: dump shapes as well
I see several arguments in doing so. First they use a non trivial amount of memory, so for various memory profiling/mapping tools it is relevant to have visibility of the space occupied by shapes. Then, some pathological code can create a tons of shape, so it is valuable to have a way to have a way to observe shapes without having to compile Ruby with `SHAPE_DEBUG=1`. And additionally it's likely much faster to dump then this way than to use `RubyVM::Shape`. There are however a few open questions: - Shapes can't respect the `since:` argument. Not sure what to do when it is provided. Would probably make sense to not dump them. - Maybe it would make more sense to have a separate `ObjectSpace.dump_shapes`? - Maybe instead `dump_all` should take a `shapes: false` argument? Additionally, `ObjectSpace.dump_shapes` is added for the use case of debugging the evolution of the shape tree.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6868
Diffstat (limited to 'test/objspace/test_objspace.rb')
-rw-r--r--test/objspace/test_objspace.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 1eded6a439..7eda077260 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -414,7 +414,7 @@ class TestObjSpace < Test::Unit::TestCase
@obj1 = Object.new
GC.start
@obj2 = Object.new
- ObjectSpace.dump_all(output: :stdout, since: gc_gen)
+ ObjectSpace.dump_all(output: :stdout, since: gc_gen, shapes: false)
end
p dump_my_heap_please
@@ -422,7 +422,7 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal 'nil', output.pop
since = output.shift.to_i
assert_operator output.size, :>, 0
- generations = output.map { |l| JSON.parse(l)["generation"] }.uniq.sort
+ generations = output.map { |l| JSON.parse(l) }.map { |o| o["generation"] }.uniq.sort
assert_equal [since, since + 1], generations
end
end
@@ -479,6 +479,7 @@ class TestObjSpace < Test::Unit::TestCase
output.each { |l|
obj = JSON.parse(l)
next if obj["type"] == "ROOT"
+ next if obj["type"] == "SHAPE"
assert_not_nil obj["slot_size"]
assert_equal 0, obj["slot_size"] % GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
@@ -794,6 +795,16 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal name, JSON.parse(dump)["method"], dump
end
+ def test_dump_shapes
+ json = ObjectSpace.dump_shapes(output: :string)
+ json.each_line do |line|
+ assert_include(line, '"type":"SHAPE"')
+ end
+
+ assert_empty ObjectSpace.dump_shapes(output: :string, since: RubyVM.stat(:next_shape_id))
+ assert_equal 2, ObjectSpace.dump_shapes(output: :string, since: RubyVM.stat(:next_shape_id) - 2).lines.size
+ end
+
private
def utf8_❨╯°□°❩╯︵┻━┻