summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-01 08:53:44 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-01 08:53:44 (GMT)
commitc39797e8724683e91618168bd993ac467b81eda8 (patch)
tree25bfba803716b7301a047bc579788bd8998cc29d
parentdcd0346265bfd346133e75c701b97fcb31c0ae6d (diff)
introduce USE_TRANSIENT_HEAP to enable/disable theap.
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro to enable/disable transient heap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--array.c20
-rw-r--r--hash.c5
-rw-r--r--include/ruby/ruby.h22
-rw-r--r--inits.c2
-rw-r--r--internal.h41
-rw-r--r--struct.c6
-rw-r--r--transient_heap.c2
-rw-r--r--transient_heap.h20
-rw-r--r--variable.c10
9 files changed, 107 insertions, 21 deletions
diff --git a/array.c b/array.c
index 47543be..c778a5f 100644
--- a/array.c
+++ b/array.c
@@ -57,7 +57,7 @@ VALUE rb_cArray;
#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)
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
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_capa)
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_capa)
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 ary, int transient, int promote)
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)
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)
diff --git a/hash.c b/hash.c
index 7bf5e11..b92e17c 100644
--- a/hash.c
+++ b/hash.c
@@ -499,8 +499,6 @@ hash_array_set(VALUE hash, struct li_table *li)
#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)
}
}
+#if USE_TRANSIENT_HEAP
void
rb_hash_transient_heap_evacuate(VALUE hash, int promote)
{
@@ -1056,7 +1055,7 @@ rb_hash_transient_heap_evacuate(VALUE hash, int promote)
}
hash_verify(hash);
}
-
+#endif
typedef int st_foreach_func(st_data_t, st_data_t, st_data_t);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 2cc0eb7..dba099a 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1013,6 +1013,10 @@ struct RString {
((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 {
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 {
#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 {
#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)
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);
}
diff --git a/inits.c b/inits.c
index 7eb5431..4da033b 100644
--- a/inits.c
+++ b/inits.c
@@ -16,7 +16,9 @@
void
rb_call_inits(void)
{
+#if USE_TRANSIENT_HEAP
CALL(TransientHeap);
+#endif
CALL(Method);
CALL(RandomSeedCore);
CALL(sym);
diff --git a/internal.h b/internal.h
index 219f5e2..8d287ec 100644
--- a/internal.h
+++ b/internal.h
@@ -712,8 +712,17 @@ void rb_hash_st_table_set(VALUE hash, st_table *st);
#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 {
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_entry *);
#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;
#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);
diff --git a/struct.c b/struct.c
index b2fd111..30dfbf2 100644
--- a/struct.c
+++ b/struct.c
@@ -661,15 +661,16 @@ struct_heap_alloc(VALUE st, size_t len)
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 obj, int promote)
RSTRUCT(obj)->as.heap.ptr = new_ptr;
}
}
+#endif
static VALUE
struct_alloc(VALUE klass)
diff --git a/transient_heap.c b/transient_heap.c
index 50c0a51..7b16bbb 100644
--- a/transient_heap.c
+++ b/transient_heap.c
@@ -15,6 +15,7 @@
#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)
transient_heap_verify(theap);
}
+#endif /* USE_TRANSIENT_HEAP */
diff --git a/transient_heap.h b/transient_heap.h
index 2ba0b63..a34aa1e 100644
--- a/transient_heap.h
+++ b/transient_heap.h
@@ -9,6 +9,10 @@
#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(VALUE ary, int promote);
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
diff --git a/variable.c b/variable.c
index d53e788..f2e0c98 100644
--- a/variable.c
+++ b/variable.c
@@ -1340,10 +1340,10 @@ obj_ivar_heap_alloc(VALUE obj, size_t newsize)
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 len, size_t newsize)
}
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 len, size_t newsize)
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, int promote)
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, int promote)
ROBJECT(obj)->as.heap.ivptr = new_ptr;
}
}
+#endif
static VALUE
obj_ivar_set(VALUE obj, ID id, VALUE val)