mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
support theap for T_OBJECT.
* variable.c: now instance variable space has theap supports. obj_ivar_heap_alloc() tries to acquire memory from theap. * debug_counter.h: add some counters for theap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f926f799e9
commit
efe869c0e5
4 changed files with 152 additions and 50 deletions
|
@ -141,6 +141,7 @@ RB_DEBUG_COUNTER(gc_major_oldmalloc)
|
||||||
* * [attr]
|
* * [attr]
|
||||||
* * _ptr: R?? is not embed.
|
* * _ptr: R?? is not embed.
|
||||||
* * _embed: R?? is embed.
|
* * _embed: R?? is embed.
|
||||||
|
* * _transient: R?? uses transient heap.
|
||||||
* * type specific attr.
|
* * type specific attr.
|
||||||
* * str_shared: str is shared.
|
* * str_shared: str is shared.
|
||||||
* * str_nofree: nofree
|
* * str_nofree: nofree
|
||||||
|
@ -162,8 +163,9 @@ RB_DEBUG_COUNTER(obj_free)
|
||||||
RB_DEBUG_COUNTER(obj_promote)
|
RB_DEBUG_COUNTER(obj_promote)
|
||||||
RB_DEBUG_COUNTER(obj_wb_unprotect)
|
RB_DEBUG_COUNTER(obj_wb_unprotect)
|
||||||
|
|
||||||
RB_DEBUG_COUNTER(obj_obj_ptr)
|
|
||||||
RB_DEBUG_COUNTER(obj_obj_embed)
|
RB_DEBUG_COUNTER(obj_obj_embed)
|
||||||
|
RB_DEBUG_COUNTER(obj_obj_transient)
|
||||||
|
RB_DEBUG_COUNTER(obj_obj_ptr)
|
||||||
|
|
||||||
RB_DEBUG_COUNTER(obj_str_ptr)
|
RB_DEBUG_COUNTER(obj_str_ptr)
|
||||||
RB_DEBUG_COUNTER(obj_str_embed)
|
RB_DEBUG_COUNTER(obj_str_embed)
|
||||||
|
@ -171,8 +173,9 @@ RB_DEBUG_COUNTER(obj_str_shared)
|
||||||
RB_DEBUG_COUNTER(obj_str_nofree)
|
RB_DEBUG_COUNTER(obj_str_nofree)
|
||||||
RB_DEBUG_COUNTER(obj_str_fstr)
|
RB_DEBUG_COUNTER(obj_str_fstr)
|
||||||
|
|
||||||
RB_DEBUG_COUNTER(obj_ary_ptr)
|
|
||||||
RB_DEBUG_COUNTER(obj_ary_embed)
|
RB_DEBUG_COUNTER(obj_ary_embed)
|
||||||
|
RB_DEBUG_COUNTER(obj_ary_transient)
|
||||||
|
RB_DEBUG_COUNTER(obj_ary_ptr)
|
||||||
|
|
||||||
RB_DEBUG_COUNTER(obj_hash_empty)
|
RB_DEBUG_COUNTER(obj_hash_empty)
|
||||||
RB_DEBUG_COUNTER(obj_hash_under4)
|
RB_DEBUG_COUNTER(obj_hash_under4)
|
||||||
|
|
38
gc.c
38
gc.c
|
@ -2215,13 +2215,16 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
|
||||||
|
|
||||||
switch (BUILTIN_TYPE(obj)) {
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
if (!(RANY(obj)->as.basic.flags & ROBJECT_EMBED) &&
|
if ((RANY(obj)->as.basic.flags & ROBJECT_EMBED) ||
|
||||||
RANY(obj)->as.object.as.heap.ivptr) {
|
RANY(obj)->as.object.as.heap.ivptr == NULL) {
|
||||||
xfree(RANY(obj)->as.object.as.heap.ivptr);
|
RB_DEBUG_COUNTER_INC(obj_obj_embed);
|
||||||
RB_DEBUG_COUNTER_INC(obj_obj_ptr);
|
}
|
||||||
|
else if (ROBJ_TRANSIENT_P(obj)) {
|
||||||
|
RB_DEBUG_COUNTER_INC(obj_obj_transient);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RB_DEBUG_COUNTER_INC(obj_obj_embed);
|
xfree(RANY(obj)->as.object.as.heap.ivptr);
|
||||||
|
RB_DEBUG_COUNTER_INC(obj_obj_ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
|
@ -4717,10 +4720,18 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
|
||||||
|
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
{
|
{
|
||||||
|
const VALUE * const ptr = ROBJECT_IVPTR(obj);
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
uint32_t i, len = ROBJECT_NUMIV(obj);
|
uint32_t i, len = ROBJECT_NUMIV(obj);
|
||||||
VALUE *ptr = ROBJECT_IVPTR(obj);
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
gc_mark(objspace, *ptr++);
|
gc_mark(objspace, ptr[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objspace->mark_func_data == NULL &&
|
||||||
|
ROBJ_TRANSIENT_P(obj)) {
|
||||||
|
rb_transient_heap_mark(obj, ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -9645,6 +9656,19 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case T_OBJECT:
|
||||||
|
{
|
||||||
|
uint32_t len = ROBJECT_NUMIV(obj);
|
||||||
|
|
||||||
|
if (RANY(obj)->as.basic.flags & ROBJECT_EMBED) {
|
||||||
|
snprintf(buff, buff_size, "%s (embed) len:%d", buff, len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
VALUE *ptr = ROBJECT_IVPTR(obj);
|
||||||
|
snprintf(buff, buff_size, "%s len:%d ptr:%p", buff, len, ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case T_DATA: {
|
case T_DATA: {
|
||||||
const struct rb_block *block;
|
const struct rb_block *block;
|
||||||
const rb_iseq_t *iseq;
|
const rb_iseq_t *iseq;
|
||||||
|
|
|
@ -1922,6 +1922,9 @@ extern rb_encoding OnigEncodingUTF_8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* variable.c */
|
/* variable.c */
|
||||||
|
#define ROBJECT_TRANSIENT_FLAG FL_USER13
|
||||||
|
#define ROBJ_TRANSIENT_P(obj) FL_TEST_RAW((obj), ROBJECT_TRANSIENT_FLAG)
|
||||||
|
|
||||||
void rb_gc_mark_global_tbl(void);
|
void rb_gc_mark_global_tbl(void);
|
||||||
size_t rb_generic_ivar_memsize(VALUE);
|
size_t rb_generic_ivar_memsize(VALUE);
|
||||||
VALUE rb_search_class_path(VALUE);
|
VALUE rb_search_class_path(VALUE);
|
||||||
|
|
98
variable.c
98
variable.c
|
@ -22,6 +22,7 @@
|
||||||
#include "id_table.h"
|
#include "id_table.h"
|
||||||
#include "debug_counter.h"
|
#include "debug_counter.h"
|
||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
|
#include "transient_heap.h"
|
||||||
|
|
||||||
static struct rb_id_table *rb_global_tbl;
|
static struct rb_id_table *rb_global_tbl;
|
||||||
static ID autoload, classpath, tmp_classpath, classid;
|
static ID autoload, classpath, tmp_classpath, classid;
|
||||||
|
@ -1333,18 +1334,75 @@ generic_ivar_set(VALUE obj, ID id, VALUE val)
|
||||||
RB_OBJ_WRITTEN(obj, Qundef, val);
|
RB_OBJ_WRITTEN(obj, Qundef, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
static VALUE *
|
||||||
rb_ivar_set(VALUE obj, ID id, VALUE val)
|
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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG);
|
||||||
|
newptr = ALLOC_N(VALUE, newsize);
|
||||||
|
}
|
||||||
|
return newptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE *
|
||||||
|
obj_ivar_heap_realloc(VALUE obj, int32_t len, size_t newsize)
|
||||||
|
{
|
||||||
|
VALUE *newptr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (ROBJ_TRANSIENT_P(obj)) {
|
||||||
|
const VALUE *orig_ptr = ROBJECT(obj)->as.heap.ivptr;
|
||||||
|
if ((newptr = obj_ivar_heap_alloc(obj, newsize)) != NULL) {
|
||||||
|
/* ok */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newptr = ALLOC_N(VALUE, newsize);
|
||||||
|
FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG);
|
||||||
|
}
|
||||||
|
ROBJECT(obj)->as.heap.ivptr = newptr;
|
||||||
|
for (i=0; i<(int)len; i++) {
|
||||||
|
newptr[i] = orig_ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
REALLOC_N(ROBJECT(obj)->as.heap.ivptr, VALUE, newsize);
|
||||||
|
newptr = ROBJECT(obj)->as.heap.ivptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_obj_transient_heap_evacuate(VALUE obj, int promote)
|
||||||
|
{
|
||||||
|
if (ROBJ_TRANSIENT_P(obj)) {
|
||||||
|
uint32_t len = ROBJECT_NUMIV(obj);
|
||||||
|
const VALUE *old_ptr = ROBJECT_IVPTR(obj);
|
||||||
|
VALUE *new_ptr;
|
||||||
|
|
||||||
|
if (promote) {
|
||||||
|
new_ptr = ALLOC_N(VALUE, len);
|
||||||
|
FL_UNSET_RAW(obj, ROBJECT_TRANSIENT_FLAG);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_ptr = obj_ivar_heap_alloc(obj, len);
|
||||||
|
}
|
||||||
|
MEMCPY(new_ptr, old_ptr, VALUE, len);
|
||||||
|
ROBJECT(obj)->as.heap.ivptr = new_ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
obj_ivar_set(VALUE obj, ID id, VALUE val)
|
||||||
{
|
{
|
||||||
struct ivar_update ivup;
|
struct ivar_update ivup;
|
||||||
uint32_t i, len;
|
uint32_t i, len;
|
||||||
|
|
||||||
RB_DEBUG_COUNTER_INC(ivar_set_base);
|
|
||||||
|
|
||||||
rb_check_frozen(obj);
|
|
||||||
|
|
||||||
switch (BUILTIN_TYPE(obj)) {
|
|
||||||
case T_OBJECT:
|
|
||||||
ivup.iv_extended = 0;
|
ivup.iv_extended = 0;
|
||||||
ivup.u.iv_index_tbl = iv_index_tbl_make(obj);
|
ivup.u.iv_index_tbl = iv_index_tbl_make(obj);
|
||||||
iv_index_tbl_extend(&ivup, id);
|
iv_index_tbl_extend(&ivup, id);
|
||||||
|
@ -1363,23 +1421,37 @@ rb_ivar_set(VALUE obj, ID id, VALUE val)
|
||||||
uint32_t newsize = iv_index_tbl_newsize(&ivup);
|
uint32_t newsize = iv_index_tbl_newsize(&ivup);
|
||||||
|
|
||||||
if (RBASIC(obj)->flags & ROBJECT_EMBED) {
|
if (RBASIC(obj)->flags & ROBJECT_EMBED) {
|
||||||
newptr = ALLOC_N(VALUE, newsize);
|
newptr = obj_ivar_heap_alloc(obj, newsize);
|
||||||
|
// newptr = ALLOC_N(VALUE, newsize);
|
||||||
MEMCPY(newptr, ptr, VALUE, len);
|
MEMCPY(newptr, ptr, VALUE, len);
|
||||||
RBASIC(obj)->flags &= ~ROBJECT_EMBED;
|
RBASIC(obj)->flags &= ~ROBJECT_EMBED;
|
||||||
ROBJECT(obj)->as.heap.ivptr = newptr;
|
ROBJECT(obj)->as.heap.ivptr = newptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
REALLOC_N(ROBJECT(obj)->as.heap.ivptr, VALUE, newsize);
|
newptr = obj_ivar_heap_realloc(obj, len, newsize);
|
||||||
newptr = ROBJECT(obj)->as.heap.ivptr;
|
|
||||||
}
|
}
|
||||||
for (; len < newsize; len++)
|
for (; len < newsize; len++) {
|
||||||
newptr[len] = Qundef;
|
newptr[len] = Qundef;
|
||||||
|
}
|
||||||
ROBJECT(obj)->as.heap.numiv = newsize;
|
ROBJECT(obj)->as.heap.numiv = newsize;
|
||||||
ROBJECT(obj)->as.heap.iv_index_tbl = ivup.u.iv_index_tbl;
|
ROBJECT(obj)->as.heap.iv_index_tbl = ivup.u.iv_index_tbl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RB_OBJ_WRITE(obj, &ROBJECT_IVPTR(obj)[ivup.index], val);
|
RB_OBJ_WRITE(obj, &ROBJECT_IVPTR(obj)[ivup.index], val);
|
||||||
break;
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_ivar_set(VALUE obj, ID id, VALUE val)
|
||||||
|
{
|
||||||
|
RB_DEBUG_COUNTER_INC(ivar_set_base);
|
||||||
|
|
||||||
|
rb_check_frozen(obj);
|
||||||
|
|
||||||
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
|
case T_OBJECT:
|
||||||
|
return obj_ivar_set(obj, id, val);
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
if (!RCLASS_IV_TBL(obj)) RCLASS_IV_TBL(obj) = st_init_numtable();
|
if (!RCLASS_IV_TBL(obj)) RCLASS_IV_TBL(obj) = st_init_numtable();
|
||||||
|
|
Loading…
Reference in a new issue