ruby-changes:53277
From: ko1 <ko1@a...>
Date: Thu, 1 Nov 2018 17:53:49 +0900 (JST)
Subject: [ruby-changes:53277] ko1:r65492 (trunk): introduce USE_TRANSIENT_HEAP to enable/disable theap.
ko1 2018-11-01 17:53:44 +0900 (Thu, 01 Nov 2018) New Revision: 65492 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65492 Log: introduce USE_TRANSIENT_HEAP to enable/disable theap. * include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro to enable/disable transient heap. Modified files: trunk/array.c trunk/hash.c trunk/include/ruby/ruby.h trunk/inits.c trunk/internal.h trunk/struct.c trunk/transient_heap.c trunk/transient_heap.h trunk/variable.c Index: variable.c =================================================================== --- variable.c (revision 65491) +++ variable.c (revision 65492) @@ -1340,10 +1340,10 @@ obj_ivar_heap_alloc(VALUE obj, size_t ne https://github.com/ruby/ruby/blob/trunk/variable.c#L1340 VALUE *newptr = rb_transient_heap_alloc(obj, sizeof(VALUE) * newsize); if (newptr != NULL) { - FL_SET_RAW(obj, ROBJECT_TRANSIENT_FLAG); + ROBJ_TRANSIENT_SET(obj); } else { - FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG); + ROBJ_TRANSIENT_UNSET(obj); newptr = ALLOC_N(VALUE, newsize); } return newptr; @@ -1362,7 +1362,7 @@ obj_ivar_heap_realloc(VALUE obj, int32_t https://github.com/ruby/ruby/blob/trunk/variable.c#L1362 } else { newptr = ALLOC_N(VALUE, newsize); - FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG); + ROBJ_TRANSIENT_UNSET(obj); } ROBJECT(obj)->as.heap.ivptr = newptr; for (i=0; i<(int)len; i++) { @@ -1377,6 +1377,7 @@ obj_ivar_heap_realloc(VALUE obj, int32_t https://github.com/ruby/ruby/blob/trunk/variable.c#L1377 return newptr; } +#if USE_TRANSIENT_HEAP void rb_obj_transient_heap_evacuate(VALUE obj, int promote) { @@ -1387,7 +1388,7 @@ rb_obj_transient_heap_evacuate(VALUE obj https://github.com/ruby/ruby/blob/trunk/variable.c#L1388 if (promote) { new_ptr = ALLOC_N(VALUE, len); - FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG); + ROBJ_TRANSIENT_UNSET(obj); } else { new_ptr = obj_ivar_heap_alloc(obj, len); @@ -1396,6 +1397,7 @@ rb_obj_transient_heap_evacuate(VALUE obj https://github.com/ruby/ruby/blob/trunk/variable.c#L1397 ROBJECT(obj)->as.heap.ivptr = new_ptr; } } +#endif static VALUE obj_ivar_set(VALUE obj, ID id, VALUE val) Index: inits.c =================================================================== --- inits.c (revision 65491) +++ inits.c (revision 65492) @@ -16,7 +16,9 @@ https://github.com/ruby/ruby/blob/trunk/inits.c#L16 void rb_call_inits(void) { +#if USE_TRANSIENT_HEAP CALL(TransientHeap); +#endif CALL(Method); CALL(RandomSeedCore); CALL(sym); Index: hash.c =================================================================== --- hash.c (revision 65491) +++ hash.c (revision 65492) @@ -499,8 +499,6 @@ hash_array_set(VALUE hash, struct li_tab https://github.com/ruby/ruby/blob/trunk/hash.c#L499 #define RHASH_SET_ST_FLAG(h) FL_SET_RAW(h, RHASH_ST_TABLE_FLAG) #define RHASH_UNSET_ST_FLAG(h) FL_UNSET_RAW(h, RHASH_ST_TABLE_FLAG) -#define RHASH_SET_TRANSIENT_FLAG(h) FL_SET_RAW(h, RHASH_TRANSIENT_FLAG) -#define RHASH_UNSET_TRANSIENT_FLAG(h) FL_UNSET_RAW(h, RHASH_TRANSIENT_FLAG) #define RHASH_ARRAY_BOUND_SET(h, n) do { \ long tmp_n = n; \ @@ -1030,6 +1028,7 @@ linear_clear(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1028 } } +#if USE_TRANSIENT_HEAP void rb_hash_transient_heap_evacuate(VALUE hash, int promote) { @@ -1056,7 +1055,7 @@ rb_hash_transient_heap_evacuate(VALUE ha https://github.com/ruby/ruby/blob/trunk/hash.c#L1055 } hash_verify(hash); } - +#endif typedef int st_foreach_func(st_data_t, st_data_t, st_data_t); Index: internal.h =================================================================== --- internal.h (revision 65491) +++ internal.h (revision 65492) @@ -712,8 +712,17 @@ void rb_hash_st_table_set(VALUE hash, st https://github.com/ruby/ruby/blob/trunk/internal.h#L712 #define RHASH_ARRAY_SIZE_SHIFT RHASH_ARRAY_SIZE_SHIFT #define RHASH_ARRAY_BOUND_MASK (VALUE)RHASH_ARRAY_BOUND_MASK #define RHASH_ARRAY_BOUND_SHIFT RHASH_ARRAY_BOUND_SHIFT + +#if USE_TRANSIENT_HEAP #define RHASH_TRANSIENT_FLAG FL_USER14 #define RHASH_TRANSIENT_P(hash) FL_TEST_RAW((hash), RHASH_TRANSIENT_FLAG) +#define RHASH_SET_TRANSIENT_FLAG(h) FL_SET_RAW(h, RHASH_TRANSIENT_FLAG) +#define RHASH_UNSET_TRANSIENT_FLAG(h) FL_UNSET_RAW(h, RHASH_TRANSIENT_FLAG) +#else +#define RHASH_TRANSIENT_P(hash) 0 +#define RHASH_SET_TRANSIENT_FLAG(h) ((void)0) +#define RHASH_UNSET_TRANSIENT_FLAG(h) ((void)0) +#endif #define RHASH_ARRAY_MAX_SIZE 8 #define RHASH_ARRAY_MAX_BOUND RHASH_ARRAY_MAX_SIZE @@ -775,7 +784,15 @@ enum { https://github.com/ruby/ruby/blob/trunk/internal.h#L784 RSTRUCT_ENUM_END }; +#if USE_TRANSIENT_HEAP #define RSTRUCT_TRANSIENT_P(st) FL_TEST_RAW((obj), RSTRUCT_TRANSIENT_FLAG) +#define RSTRUCT_TRANSIENT_SET(st) FL_SET_RAW((st), RSTRUCT_TRANSIENT_FLAG) +#define RSTRUCT_TRANSIENT_UNSET(st) FL_UNSET_RAW((st), RSTRUCT_TRANSIENT_FLAG) +#else +#define RSTRUCT_TRANSIENT_P(st) 0 +#define RSTRUCT_TRANSIENT_SET(st) ((void)0) +#define RSTRUCT_TRANSIENT_UNSET(st) ((void)0) +#endif struct RStruct { struct RBasic basic; @@ -1171,6 +1188,17 @@ VALUE rb_gvar_defined(struct rb_global_e https://github.com/ruby/ruby/blob/trunk/internal.h#L1188 #endif +#if USE_TRANSIENT_HEAP +#define RARY_TRANSIENT_SET(ary) FL_SET_RAW((ary), RARRAY_TRANSIENT_FLAG); +#define RARY_TRANSIENT_UNSET(ary) FL_UNSET_RAW((ary), RARRAY_TRANSIENT_FLAG); +#else +#undef RARRAY_TRANSIENT_P +#define RARRAY_TRANSIENT_P(a) 0 +#define RARY_TRANSIENT_SET(ary) ((void)0) +#define RARY_TRANSIENT_UNSET(ary) ((void)0) +#endif + + VALUE rb_ary_last(int, const VALUE *, VALUE); void rb_ary_set_len(VALUE, long); void rb_ary_delete_same(VALUE, VALUE); @@ -2010,9 +2038,16 @@ extern rb_encoding OnigEncodingUTF_8; https://github.com/ruby/ruby/blob/trunk/internal.h#L2038 #endif /* variable.c */ -#define ROBJECT_TRANSIENT_FLAG FL_USER13 -#define ROBJ_TRANSIENT_P(obj) FL_TEST_RAW((obj), ROBJECT_TRANSIENT_FLAG) - +#if USE_TRANSIENT_HEAP +#define ROBJECT_TRANSIENT_FLAG FL_USER13 +#define ROBJ_TRANSIENT_P(obj) FL_TEST_RAW((obj), ROBJECT_TRANSIENT_FLAG) +#define ROBJ_TRANSIENT_SET(obj) FL_SET_RAW((obj), ROBJECT_TRANSIENT_FLAG) +#define ROBJ_TRANSIENT_UNSET(obj) FL_UNSET_RAW((obj), ROBJECT_TRANSIENT_FLAG) +#else +#define ROBJ_TRANSIENT_P(obj) 0 +#define ROBJ_TRANSIENT_SET(obj) ((void)0) +#define ROBJ_TRANSIENT_UNSET(obj) ((void)0) +#endif void rb_gc_mark_global_tbl(void); size_t rb_generic_ivar_memsize(VALUE); VALUE rb_search_class_path(VALUE); Index: array.c =================================================================== --- array.c (revision 65491) +++ array.c (revision 65492) @@ -57,7 +57,7 @@ VALUE rb_cArray; https://github.com/ruby/ruby/blob/trunk/array.c#L57 #define FL_SET_EMBED(a) do { \ assert(!ARY_SHARED_P(a)); \ FL_SET((a), RARRAY_EMBED_FLAG); \ - FL_UNSET_RAW((a), RARRAY_TRANSIENT_FLAG); \ + RARY_TRANSIENT_UNSET(a); \ ary_verify(a); \ } while (0) #define FL_UNSET_EMBED(ary) FL_UNSET((ary), RARRAY_EMBED_FLAG|RARRAY_EMBED_LEN_MASK) @@ -278,10 +278,10 @@ ary_heap_alloc(VALUE ary, size_t capa) https://github.com/ruby/ruby/blob/trunk/array.c#L278 VALUE *ptr = rb_transient_heap_alloc(ary, sizeof(VALUE) * capa); if (ptr != NULL) { - FL_SET_RAW(ary, RARRAY_TRANSIENT_FLAG); + RARY_TRANSIENT_SET(ary); } else { - FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG); + RARY_TRANSIENT_UNSET(ary); ptr = ALLOC_N(VALUE, capa); } @@ -303,7 +303,7 @@ static void https://github.com/ruby/ruby/blob/trunk/array.c#L303 ary_heap_free(VALUE ary) { if (RARRAY_TRANSIENT_P(ary)) { - FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG); + RARY_TRANSIENT_UNSET(ary); } else { ary_heap_free_ptr(ary, ARY_HEAP_PTR(ary), ARY_HEAP_SIZE(ary)); @@ -324,7 +324,7 @@ ary_heap_realloc(VALUE ary, size_t new_c https://github.com/ruby/ruby/blob/trunk/array.c#L324 if (new_ptr == NULL) { new_ptr = ALLOC_N(VALUE, new_capa); - FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG); + RARY_TRANSIENT_UNSET(ary); } MEMCPY(new_ptr, ARY_HEAP_PTR(ary), VALUE, old_capa); @@ -337,6 +337,7 @@ ary_heap_realloc(VALUE ary, size_t new_c https://github.com/ruby/ruby/blob/trunk/array.c#L337 ary_verify(ary); } +#if USE_TRANSIENT_HEAP static inline void rb_ary_transient_heap_evacuate_(VALUE ary, int transient, int promote) { @@ -356,7 +357,7 @@ rb_ary_transient_heap_evacuate_(VALUE ar https://github.com/ruby/ruby/blob/trunk/array.c#L357 if (promote) { new_ptr = ALLOC_N(VALUE, capa); - FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG); + RARY_TRANSIENT_UNSET(ary); } else { new_ptr = ary_heap_alloc(ary, capa); @@ -382,6 +383,13 @@ rb_ary_detransient(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L383 assert(RARRAY_TRANSIENT_P(ary)); rb_ary_transient_heap_evacuate_(ary, TRUE, TRUE); } +#else +void +rb_ary_detransient(VALUE ary) +{ + /* do nothing */ +} +#endif static void ary_resize_capa(VALUE ary, long capacity) Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 65491) +++ include/ruby/ruby.h (revision 65492) @@ -1013,6 +1013,10 @@ struct RString { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1013 ((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \ ((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len)) +#ifndef USE_TRANSIENT_HEAP +#define USE_TRANSIENT_HEAP 1 +#endif + enum ruby_rarray_flags { RARRAY_EMBED_LEN_MAX = 3, RARRAY_EMBED_FLAG = RUBY_FL_USER1, @@ -1020,7 +1024,12 @@ enum ruby_rarray_flags { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1024 RARRAY_EMBED_LEN_MASK = (RUBY_FL_USER4|RUBY_FL_USER3), RARRAY_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+3), +#if USE_TRANSIENT_HEAP RARRAY_TRANSIENT_FLAG = RUBY_FL_USER13, +#define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG +#else +#define RARRAY_TRANSIENT_FLAG 0 +#endif RARRAY_ENUM_END }; @@ -1028,7 +1037,7 @@ enum ruby_rarray_flags { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1037 #define RARRAY_EMBED_LEN_MASK (VALUE)RARRAY_EMBED_LEN_MASK #define RARRAY_EMBED_LEN_MAX RARRAY_EMBED_LEN_MAX #define RARRAY_EMBED_LEN_SHIFT RARRAY_EMBED_LEN_SHIFT -#define RARRAY_TRANSIENT_FLAG RARRAY_TRANSIENT_FLAG + struct RArray { struct RBasic basic; union { @@ -1050,7 +1059,12 @@ struct RArray { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1059 #define RARRAY_LENINT(ary) rb_long2int(RARRAY_LEN(ary)) #define RARRAY_CONST_PTR(a) rb_array_const_ptr(a) #define RARRAY_CONST_PTR_TRANSIENT(a) rb_array_const_ptr_transient(a) + +#if USE_TRANSIENT_HEAP #define RARRAY_TRANSIENT_P(ary) FL_TEST_RAW((ary), RARRAY_TRANSIENT_FLAG) +#else +#define RARRAY_TRANSIENT_P(ary) 0 +#endif VALUE *rb_ary_ptr_use_start(VALUE ary); void rb_ary_ptr_use_end(VALUE ary); @@ -2127,14 +2141,16 @@ rb_array_const_ptr_transient(VALUE a) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2141 RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr); } -void rb_ary_detransient(VALUE a); - static inline const VALUE * rb_array_const_ptr(VALUE a) { +#if USE_TRANSIENT_HEAP + void rb_ary_detransient(VALUE a); + if (RARRAY_TRANSIENT_P(a)) { rb_ary_detransient(a); } +#endif return rb_array_const_ptr_transient(a); } Index: transient_heap.c =================================================================== --- transient_heap.c (revision 65491) +++ transient_heap.c (revision 65492) @@ -15,6 +15,7 @@ https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L15 #include "transient_heap.h" #include "debug_counter.h" +#if USE_TRANSIENT_HEAP /* USE_TRANSIENT_HEAP */ /* * 1: enable assertions * 2: enable verify all transient heaps @@ -854,3 +855,4 @@ rb_transient_heap_finish_marking(void) https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L855 transient_heap_verify(theap); } +#endif /* USE_TRANSIENT_HEAP */ Index: transient_heap.h =================================================================== --- transient_heap.h (revision 65491) +++ transient_heap.h (revision 65492) @@ -9,6 +9,10 @@ https://github.com/ruby/ruby/blob/trunk/transient_heap.h#L9 #ifndef RUBY_TRANSIENT_HEAP_H #define RUBY_TRANSIENT_HEAP_H +#include "internal.h" + +#if USE_TRANSIENT_HEAP + /* public API */ /* Allocate req_size bytes from transient_heap. @@ -37,4 +41,20 @@ void rb_ary_transient_heap_evacuate(VALU https://github.com/ruby/ruby/blob/trunk/transient_heap.h#L41 void rb_obj_transient_heap_evacuate(VALUE obj, int promote); void rb_hash_transient_heap_evacuate(VALUE hash, int promote); void rb_struct_transient_heap_evacuate(VALUE st, int promote); + +#else /* USE_TRANSIENT_HEAP */ + +#define rb_transient_heap_alloc(o, s) NULL +#define rb_transient_heap_verify() ((void)0) +#define rb_transient_heap_promote(obj) ((void)0) +#define rb_transient_heap_start_marking(full_marking) ((void)0) +#define rb_transient_heap_finish_marking() ((void)0) +#define rb_transient_heap_mark(obj, ptr) ((void)0) + +#define rb_ary_transient_heap_evacuate(x, y) ((void)0) +#define rb_obj_transient_heap_evacuate(x, y) ((void)0) +#define rb_hash_transient_heap_evacuate(x, y) ((void)0) +#define rb_struct_transient_heap_evacuate(x, y) ((void)0) + +#endif /* USE_TRANSIENT_HEAP */ #endif Index: struct.c =================================================================== --- struct.c (revision 65491) +++ struct.c (revision 65492) @@ -661,15 +661,16 @@ struct_heap_alloc(VALUE st, size_t len) https://github.com/ruby/ruby/blob/trunk/struct.c#L661 VALUE *ptr = rb_transient_heap_alloc((VALUE)st, sizeof(VALUE) * len); if (ptr) { - FL_SET_RAW(st, RSTRUCT_TRANSIENT_FLAG); + RSTRUCT_TRANSIENT_SET(st); return ptr; } else { - FL_UNSET_RAW(st, RSTRUCT_TRANSIENT_FLAG); + RSTRUCT_TRANSIENT_UNSET(st); return ALLOC_N(VALUE, len); } } +#if USE_TRANSIENT_HEAP void rb_struct_transient_heap_evacuate(VALUE obj, int promote) { @@ -689,6 +690,7 @@ rb_struct_transient_heap_evacuate(VALUE https://github.com/ruby/ruby/blob/trunk/struct.c#L690 RSTRUCT(obj)->as.heap.ptr = new_ptr; } } +#endif static VALUE struct_alloc(VALUE klass) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/