|
29 | 29 | #include "ruby/util.h" |
30 | 30 | #include "ruby/io.h" |
31 | 31 | #include "vm_callinfo.h" |
32 | | -#include "vm_core.h" |
| 32 | +#include "vm_sync.h" |
33 | 33 |
|
34 | 34 | RUBY_EXTERN const char ruby_hexdigits[]; |
35 | 35 |
|
@@ -59,6 +59,7 @@ dump_flush(struct dump_config *dc) |
59 | 59 | { |
60 | 60 | if (dc->buffer_len) { |
61 | 61 | if (dc->stream) { |
| 62 | + // use raw fwrite, don't allow context switch |
62 | 63 | size_t written = fwrite(dc->buffer, sizeof(dc->buffer[0]), dc->buffer_len, dc->stream); |
63 | 64 | if (written < dc->buffer_len) { |
64 | 65 | MEMMOVE(dc->buffer, dc->buffer + written, char, dc->buffer_len - written); |
@@ -776,15 +777,23 @@ static VALUE |
776 | 777 | objspace_dump(VALUE os, VALUE obj, VALUE output) |
777 | 778 | { |
778 | 779 | 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_LOCK_LOCK(); |
| 782 | + { |
| 783 | + rb_vm_barrier(); |
| 784 | + |
| 785 | + if (!RB_SPECIAL_CONST_P(obj)) { |
| 786 | + dc.cur_page_slot_size = rb_gc_obj_slot_size(obj); |
| 787 | + } |
782 | 788 |
|
783 | | - dump_output(&dc, output, Qnil, Qnil, Qnil); |
| 789 | + dump_output(&dc, output, Qnil, Qnil, Qnil); |
784 | 790 |
|
785 | | - dump_object(obj, &dc); |
| 791 | + dump_object(obj, &dc); |
786 | 792 |
|
787 | | - return dump_result(&dc); |
| 793 | + result = dump_result(&dc); |
| 794 | + } |
| 795 | + RB_VM_LOCK_UNLOCK(); |
| 796 | + return result; |
788 | 797 | } |
789 | 798 |
|
790 | 799 | static void |
@@ -840,35 +849,51 @@ static VALUE |
840 | 849 | objspace_dump_all(VALUE os, VALUE output, VALUE full, VALUE since, VALUE shapes) |
841 | 850 | { |
842 | 851 | struct dump_config dc = {0,}; |
843 | | - dump_output(&dc, output, full, since, shapes); |
| 852 | + VALUE result = Qnil; |
| 853 | + RB_VM_LOCK_LOCK(); |
| 854 | + { |
| 855 | + rb_vm_barrier(); |
844 | 856 |
|
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 | | - } |
| 857 | + dump_output(&dc, output, full, since, shapes); |
850 | 858 |
|
851 | | - if (RTEST(shapes)) { |
852 | | - rb_shape_each_shape_id(shape_id_i, &dc); |
853 | | - } |
| 859 | + if (!dc.partial_dump || dc.since == 0) { |
| 860 | + /* dump roots */ |
| 861 | + rb_objspace_reachable_objects_from_root(root_obj_i, &dc); |
| 862 | + if (dc.roots) dump_append(&dc, "]}\n"); |
| 863 | + } |
| 864 | + |
| 865 | + if (RTEST(shapes)) { |
| 866 | + rb_shape_each_shape_id(shape_id_i, &dc); |
| 867 | + } |
854 | 868 |
|
855 | | - /* dump all objects */ |
856 | | - rb_objspace_each_objects(heap_i, &dc); |
| 869 | + /* dump all objects */ |
| 870 | + rb_objspace_each_objects(heap_i, &dc); |
857 | 871 |
|
858 | | - return dump_result(&dc); |
| 872 | + result = dump_result(&dc); |
| 873 | + } |
| 874 | + RB_VM_LOCK_UNLOCK(); |
| 875 | + return result; |
859 | 876 | } |
860 | 877 |
|
861 | 878 | /* :nodoc: */ |
862 | 879 | static VALUE |
863 | 880 | objspace_dump_shapes(VALUE os, VALUE output, VALUE shapes) |
864 | 881 | { |
865 | 882 | struct dump_config dc = {0,}; |
866 | | - dump_output(&dc, output, Qfalse, Qnil, shapes); |
| 883 | + VALUE result = Qnil; |
| 884 | + RB_VM_LOCK_LOCK(); |
| 885 | + { |
| 886 | + rb_vm_barrier(); |
| 887 | + |
| 888 | + dump_output(&dc, output, Qfalse, Qnil, shapes); |
867 | 889 |
|
868 | | - if (RTEST(shapes)) { |
869 | | - rb_shape_each_shape_id(shape_id_i, &dc); |
| 890 | + if (RTEST(shapes)) { |
| 891 | + rb_shape_each_shape_id(shape_id_i, &dc); |
| 892 | + } |
| 893 | + result = dump_result(&dc); |
870 | 894 | } |
871 | | - return dump_result(&dc); |
| 895 | + RB_VM_LOCK_UNLOCK(); |
| 896 | + return result; |
872 | 897 | } |
873 | 898 |
|
874 | 899 | void |
|
0 commit comments