Skip to content

Commit

Permalink
Adding GC.compact and compacting GC support.
Browse files Browse the repository at this point in the history
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tenderlove committed Apr 9, 2019
1 parent c09e35d commit 3ef4db1
Show file tree
Hide file tree
Showing 27 changed files with 1,798 additions and 252 deletions.
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ JIT::

* Default value of +--jit-min-calls+ is changed from 5 to 10,000

GC::

* New `GC.compact` method for compacting the heap.
This function compacts live objects in the heap so that fewer pages may
be used, and the heap may be more CoW friendly. [Feature #15626]

Details on the algorithm and caveats can be found here:
https://bugs.ruby-lang.org/issues/15626

=== Miscellaneous changes

* Require compilers to support C99 [Misc #15347]
Expand Down
8 changes: 8 additions & 0 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ boot_defclass(const char *name, VALUE super)

rb_name_class(obj, id);
rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
rb_vm_add_root_module(id, obj);
return obj;
}

Expand Down Expand Up @@ -730,6 +731,9 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super)
" (%"PRIsVALUE" is given but was %"PRIsVALUE")",
outer, rb_id2str(id), RCLASS_SUPER(klass), super);
}
/* Class may have been defined in Ruby and not pin-rooted */
rb_vm_add_root_module(id, klass);

return klass;
}
if (!super) {
Expand All @@ -740,6 +744,7 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super)
rb_set_class_path_string(klass, outer, rb_id2str(id));
rb_const_set(outer, id, klass);
rb_class_inherited(super, klass);
rb_vm_add_root_module(id, klass);
rb_gc_register_mark_object(klass);

return klass;
Expand Down Expand Up @@ -777,10 +782,13 @@ rb_define_module(const char *name)
rb_raise(rb_eTypeError, "%s is not a module (%"PRIsVALUE")",
name, rb_obj_class(module));
}
/* Module may have been defined in Ruby and not pin-rooted */
rb_vm_add_root_module(id, module);
return module;
}
module = rb_define_module_id(id);
rb_vm_add_root_module(id, module);
rb_gc_register_mark_object(module);
rb_const_set(rb_cObject, id, module);

return module;
Expand Down
4 changes: 2 additions & 2 deletions constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ typedef enum {
typedef struct rb_const_entry_struct {
rb_const_flag_t flag;
int line;
const VALUE value; /* should be mark */
const VALUE file; /* should be mark */
VALUE value; /* should be mark */
VALUE file; /* should be mark */
} rb_const_entry_t;

VALUE rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj);
Expand Down

0 comments on commit 3ef4db1

Please sign in to comment.