Skip to content

Commit ce6f35e

Browse files
committed
ObjectSpace.{dump,dump_all,dump_shapes} needs vm barrier.
1 parent 866e474 commit ce6f35e

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

ext/objspace/objspace_dump.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ruby/io.h"
3131
#include "vm_callinfo.h"
3232
#include "vm_core.h"
33+
#include "vm_sync.h"
3334

3435
RUBY_EXTERN const char ruby_hexdigits[];
3536

@@ -776,15 +777,21 @@ static VALUE
776777
objspace_dump(VALUE os, VALUE obj, VALUE output)
777778
{
778779
struct dump_config dc = {0,};
779-
if (!RB_SPECIAL_CONST_P(obj)) {
780-
dc.cur_page_slot_size = rb_gc_obj_slot_size(obj);
781-
}
780+
VALUE result = Qnil;
781+
RB_VM_LOCKING() {
782+
rb_vm_barrier();
783+
784+
if (!RB_SPECIAL_CONST_P(obj)) {
785+
dc.cur_page_slot_size = rb_gc_obj_slot_size(obj);
786+
}
782787

783-
dump_output(&dc, output, Qnil, Qnil, Qnil);
788+
dump_output(&dc, output, Qnil, Qnil, Qnil);
784789

785-
dump_object(obj, &dc);
790+
dump_object(obj, &dc);
786791

787-
return dump_result(&dc);
792+
result = dump_result(&dc);
793+
}
794+
return result;
788795
}
789796

790797
static void
@@ -840,35 +847,47 @@ static VALUE
840847
objspace_dump_all(VALUE os, VALUE output, VALUE full, VALUE since, VALUE shapes)
841848
{
842849
struct dump_config dc = {0,};
843-
dump_output(&dc, output, full, since, shapes);
850+
VALUE result = Qnil;
851+
RB_VM_LOCKING() {
852+
rb_vm_barrier();
844853

845-
if (!dc.partial_dump || dc.since == 0) {
846-
/* dump roots */
847-
rb_objspace_reachable_objects_from_root(root_obj_i, &dc);
848-
if (dc.roots) dump_append(&dc, "]}\n");
849-
}
854+
dump_output(&dc, output, full, since, shapes);
850855

851-
if (RTEST(shapes)) {
852-
rb_shape_each_shape_id(shape_id_i, &dc);
853-
}
856+
if (!dc.partial_dump || dc.since == 0) {
857+
/* dump roots */
858+
rb_objspace_reachable_objects_from_root(root_obj_i, &dc);
859+
if (dc.roots) dump_append(&dc, "]}\n");
860+
}
861+
862+
if (RTEST(shapes)) {
863+
rb_shape_each_shape_id(shape_id_i, &dc);
864+
}
854865

855-
/* dump all objects */
856-
rb_objspace_each_objects(heap_i, &dc);
866+
/* dump all objects */
867+
rb_objspace_each_objects(heap_i, &dc);
857868

858-
return dump_result(&dc);
869+
result = dump_result(&dc);
870+
}
871+
return result;
859872
}
860873

861874
/* :nodoc: */
862875
static VALUE
863876
objspace_dump_shapes(VALUE os, VALUE output, VALUE shapes)
864877
{
865878
struct dump_config dc = {0,};
866-
dump_output(&dc, output, Qfalse, Qnil, shapes);
879+
VALUE result = Qnil;
880+
RB_VM_LOCKING() {
881+
rb_vm_barrier();
882+
883+
dump_output(&dc, output, Qfalse, Qnil, shapes);
867884

868-
if (RTEST(shapes)) {
869-
rb_shape_each_shape_id(shape_id_i, &dc);
885+
if (RTEST(shapes)) {
886+
rb_shape_each_shape_id(shape_id_i, &dc);
887+
}
888+
result = dump_result(&dc);
870889
}
871-
return dump_result(&dc);
890+
return result;
872891
}
873892

874893
void

0 commit comments

Comments
 (0)