From 73771e4b192f3db62efb854affdfc95babba1d35 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 6 Dec 2022 12:56:51 +0100 Subject: 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. --- shape.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'shape.h') diff --git a/shape.h b/shape.h index 96feae99fd..ddb870f5e7 100644 --- a/shape.h +++ b/shape.h @@ -124,7 +124,6 @@ bool rb_shape_root_shape_p(rb_shape_t* shape); rb_shape_t * rb_shape_get_root_shape(void); uint8_t rb_shape_id_num_bits(void); int32_t rb_shape_id_offset(void); -unsigned int rb_shape_depth(rb_shape_t * shape); rb_shape_t* rb_shape_get_shape_by_id_without_assertion(shape_id_t shape_id); rb_shape_t * rb_shape_get_parent(rb_shape_t * shape); @@ -184,4 +183,12 @@ bool rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id); VALUE rb_obj_debug_shape(VALUE self, VALUE obj); VALUE rb_shape_flags_mask(void); +RUBY_SYMBOL_EXPORT_BEGIN +typedef void each_shape_callback(rb_shape_t * shape, void *data); +void rb_shape_each_shape(each_shape_callback callback, void *data); +size_t rb_shape_memsize(rb_shape_t *shape); +size_t rb_shape_edges_count(rb_shape_t *shape); +size_t rb_shape_depth(rb_shape_t *shape); +RUBY_SYMBOL_EXPORT_END + #endif -- cgit v1.2.3