From 3ef4db15e95740839a0ed6d0224b2c9562bb2544 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Tue, 9 Apr 2019 20:32:04 +0000 Subject: Adding `GC.compact` and compacting GC support. 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 --- include/ruby/intern.h | 5 +++++ include/ruby/ruby.h | 15 ++++++++++++--- include/ruby/st.h | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 17aafd7f8e..192347c8d5 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -507,10 +507,15 @@ COLDFUNC NORETURN(void rb_memerror(void)); PUREFUNC(int rb_during_gc(void)); void rb_gc_mark_locations(const VALUE*, const VALUE*); void rb_mark_tbl(struct st_table*); +void rb_mark_tbl_no_pin(struct st_table*); +void rb_gc_update_tbl_refs(st_table *ptr); void rb_mark_set(struct st_table*); void rb_mark_hash(struct st_table*); +void rb_update_st_references(struct st_table *ht); void rb_gc_mark_maybe(VALUE); void rb_gc_mark(VALUE); +void rb_gc_mark_no_pin(VALUE); +VALUE rb_gc_new_location(VALUE); void rb_gc_force_recycle(VALUE); void rb_gc(void); void rb_gc_copy_finalizer(VALUE,VALUE); diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 11387b540a..b22c4e3f2e 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -512,6 +512,7 @@ enum ruby_value_type { RUBY_T_NODE = 0x1b, RUBY_T_ICLASS = 0x1c, RUBY_T_ZOMBIE = 0x1d, + RUBY_T_MOVED = 0x1e, RUBY_T_MASK = 0x1f }; @@ -542,6 +543,7 @@ enum ruby_value_type { #define T_UNDEF RUBY_T_UNDEF #define T_NODE RUBY_T_NODE #define T_ZOMBIE RUBY_T_ZOMBIE +#define T_MOVED RUBY_T_MOVED #define T_MASK RUBY_T_MASK #define RB_BUILTIN_TYPE(x) (int)(((struct RBasic*)(x))->flags & RUBY_T_MASK) @@ -881,9 +883,14 @@ enum ruby_fl_type { RUBY_FL_SINGLETON = RUBY_FL_USER0 }; +struct RMoved { + VALUE flags; + VALUE destination; +}; + struct RUBY_ALIGNAS(SIZEOF_VALUE) RBasic { VALUE flags; - const VALUE klass; + VALUE klass; }; VALUE rb_obj_hide(VALUE obj); @@ -1105,7 +1112,7 @@ struct RArray { struct RRegexp { struct RBasic basic; struct re_pattern_buffer *ptr; - const VALUE src; + VALUE src; unsigned long usecnt; }; #define RREGEXP_PTR(r) (RREGEXP(r)->ptr) @@ -1144,7 +1151,8 @@ struct rb_data_type_struct { void (*dmark)(void*); void (*dfree)(void*); size_t (*dsize)(const void *); - void *reserved[2]; /* For future extension. + void (*dcompact)(void*); + void *reserved[1]; /* For future extension. This array *must* be filled with ZERO. */ } function; const rb_data_type_t *parent; @@ -1255,6 +1263,7 @@ int rb_big_sign(VALUE); #define RBIGNUM_NEGATIVE_P(b) (RBIGNUM_SIGN(b)==0) #define R_CAST(st) (struct st*) +#define RMOVED(obj) (R_CAST(RMoved)(obj)) #define RBASIC(obj) (R_CAST(RBasic)(obj)) #define ROBJECT(obj) (R_CAST(RObject)(obj)) #define RCLASS(obj) (R_CAST(RClass)(obj)) diff --git a/include/ruby/st.h b/include/ruby/st.h index 149e0ebaef..a7eb0c6d7c 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -96,7 +96,7 @@ struct st_table { #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0) -enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; +enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK, ST_REPLACE}; st_table *st_init_table(const struct st_hash_type *); st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t); @@ -118,6 +118,7 @@ typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t * results of hash() are same and compare() returns 0, otherwise the * behavior is undefined */ int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg); +int st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg); int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size); -- cgit v1.2.3