Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 266 additions & 34 deletions array.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ COMMONOBJS = array.$(OBJEXT) \
thread.$(OBJEXT) \
time.$(OBJEXT) \
transcode.$(OBJEXT) \
transient_heap.$(OBJEXT) \
util.$(OBJEXT) \
variable.$(OBJEXT) \
version.$(OBJEXT) \
Expand Down Expand Up @@ -2903,6 +2904,7 @@ transcode.$(OBJEXT): {$(VPATH)}st.h
transcode.$(OBJEXT): {$(VPATH)}subst.h
transcode.$(OBJEXT): {$(VPATH)}transcode.c
transcode.$(OBJEXT): {$(VPATH)}transcode_data.h
transient_heap.$(OBJEXT): {$(VPATH)}transient_heap.c
util.$(OBJEXT): $(hdrdir)/ruby/ruby.h
util.$(OBJEXT): $(top_srcdir)/include/ruby.h
util.$(OBJEXT): {$(VPATH)}config.h
Expand Down
7 changes: 6 additions & 1 deletion encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,18 @@ rb_enc_set_index(VALUE obj, int idx)
must_encindex(idx);
enc_set_index(obj, idx);
}

#include "gc.h"
#include "vm_debug.h"
VALUE
rb_enc_associate_index(VALUE obj, int idx)
{
rb_encoding *enc;
int oldidx, oldtermlen, termlen;

if (!enc_capable(obj)) {
rb_bug("rb_enc_associate_index: not enc_capable");
}

/* enc_check_capable(obj);*/
rb_check_frozen(obj);
oldidx = rb_enc_get_index(obj);
Expand Down
88 changes: 70 additions & 18 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <sys/types.h>
#include "ruby_assert.h"
#include "debug_counter.h"
#include "transient_heap.h"
#include "mjit.h"

#undef rb_data_object_wrap
Expand Down Expand Up @@ -1188,6 +1189,7 @@ RVALUE_PAGE_OLD_UNCOLLECTIBLE_SET(rb_objspace_t *objspace, struct heap_page *pag
{
MARK_IN_BITMAP(&page->uncollectible_bits[0], obj);
objspace->rgengc.old_objects++;
rb_transient_heap_promote(obj);

#if RGENGC_PROFILE >= 2
objspace->profile.total_promoted_count++;
Expand Down Expand Up @@ -2246,9 +2248,12 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
rb_str_free(obj);
break;
case T_ARRAY:
rb_ary_free(obj);
rb_ary_free(obj);
break;
case T_HASH:
if (RANY(obj)->as.hash.ltbl) {
free(RANY(obj)->as.hash.ltbl);
}
if (RANY(obj)->as.hash.ntbl) {
st_free_table(RANY(obj)->as.hash.ntbl);
}
Expand Down Expand Up @@ -3262,6 +3267,9 @@ obj_memsize_of(VALUE obj, int use_all_types)
size += rb_ary_memsize(obj);
break;
case T_HASH:
if (RHASH(obj)->ltbl) {
size += sizeof(li_table);
}
if (RHASH(obj)->ntbl) {
size += st_memsize(RHASH(obj)->ntbl);
}
Expand Down Expand Up @@ -4156,6 +4164,16 @@ mark_hash(rb_objspace_t *objspace, st_table *tbl)
st_foreach(tbl, mark_keyvalue, (st_data_t)objspace);
}

static void
mark_hash_linear(rb_objspace_t *objspace, VALUE obj)
{
if (RHASH(obj)->ltbl)
linear_foreach(RHASH(obj)->ltbl, mark_keyvalue, (st_data_t)objspace);
else if (RHASH(obj)->ntbl)
st_foreach(RHASH(obj)->ntbl, mark_keyvalue, (st_data_t)objspace);
gc_mark(objspace, RHASH(obj)->ifnone);
}

void
rb_mark_hash(st_table *tbl)
{
Expand Down Expand Up @@ -4602,21 +4620,28 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
break;

case T_ARRAY:
if (FL_TEST(obj, ELTS_SHARED)) {
gc_mark(objspace, any->as.array.as.heap.aux.shared);
if (FL_TEST(obj, ELTS_SHARED)) {
VALUE root = any->as.array.as.heap.aux.shared;
gc_mark(objspace, root);
}
else {
long i, len = RARRAY_LEN(obj);
const VALUE *ptr = RARRAY_CONST_PTR(obj);
for (i=0; i < len; i++) {
gc_mark(objspace, *ptr++);
gc_mark(objspace, ptr[i]);
}
}

if (objspace->mark_func_data == NULL) {
if (!FL_TEST_RAW(obj, RARRAY_EMBED_FLAG) &&
ARY_TRANSIENT_P(obj)) {
rb_transient_heap_mark(obj, ptr);
}
}
}
break;

case T_HASH:
mark_hash(objspace, any->as.hash.ntbl);
gc_mark(objspace, any->as.hash.ifnone);
mark_hash_linear(objspace, obj);
break;

case T_STRING:
Expand Down Expand Up @@ -5602,6 +5627,8 @@ gc_marks_finish(rb_objspace_t *objspace)
#endif
}

rb_transient_heap_finish_marking();

gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_END_MARK, 0);

return TRUE;
Expand Down Expand Up @@ -6471,6 +6498,7 @@ gc_start(rb_objspace_t *objspace, int reason)
objspace->profile.heap_used_at_gc_start = heap_allocated_pages;
gc_prof_setup_new_record(objspace, reason);
gc_reset_malloc_info(objspace);
rb_transient_heap_start_marking(do_full_mark);

gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_START, 0 /* TODO: pass minor/immediate flag? */);
GC_ASSERT(during_gc);
Expand Down Expand Up @@ -9454,13 +9482,21 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
#if USE_RGENGC
const int age = RVALUE_FLAGS_AGE(RBASIC(obj)->flags);

snprintf(buff, buff_size, "%p [%d%s%s%s%s] %s",
(void *)obj, age,
C(RVALUE_UNCOLLECTIBLE_BITMAP(obj), "L"),
C(RVALUE_MARK_BITMAP(obj), "M"),
C(RVALUE_MARKING_BITMAP(obj), "R"),
C(RVALUE_WB_UNPROTECTED_BITMAP(obj), "U"),
obj_type_name(obj));
if (is_pointer_to_heap(&rb_objspace, (void *)obj)) {
snprintf(buff, buff_size, "%p [%d%s%s%s%s] %s",
(void *)obj, age,
C(RVALUE_UNCOLLECTIBLE_BITMAP(obj), "L"),
C(RVALUE_MARK_BITMAP(obj), "M"),
C(RVALUE_MARKING_BITMAP(obj), "R"),
C(RVALUE_WB_UNPROTECTED_BITMAP(obj), "U"),
obj_type_name(obj));
}
else {
/* fake */
snprintf(buff, buff_size, "%p [%dXXXX] %s",
(void *)obj, age,
obj_type_name(obj));
}
#else
snprintf(buff, buff_size, "%p [%s] %s",
(void *)obj,
Expand Down Expand Up @@ -9490,10 +9526,25 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
UNEXPECTED_NODE(rb_raw_obj_info);
break;
case T_ARRAY:
snprintf(buff, buff_size, "%s [%s%s] len: %d", buff,
C(ARY_EMBED_P(obj), "E"),
C(ARY_SHARED_P(obj), "S"),
(int)RARRAY_LEN(obj));
if (FL_TEST(obj, ELTS_SHARED)) {
snprintf(buff, buff_size, "%s shared -> %s", buff,
rb_obj_info(RARRAY(obj)->as.heap.aux.shared));
}
else if (FL_TEST(obj, RARRAY_EMBED_FLAG)) {
snprintf(buff, buff_size, "%s [%s%s] len: %d (embed)", buff,
C(ARY_EMBED_P(obj), "E"),
C(ARY_SHARED_P(obj), "S"),
(int)RARRAY_LEN(obj));
}
else {
snprintf(buff, buff_size, "%s [%s%s%s] len: %d, capa:%d ptr:%p", buff,
C(ARY_EMBED_P(obj), "E"),
C(ARY_SHARED_P(obj), "S"),
C(ARY_TRANSIENT_P(obj), "T"),
(int)RARRAY_LEN(obj),
ARY_EMBED_P(obj) ? -1 : (int)RARRAY(obj)->as.heap.aux.capa,
RARRAY_CONST_PTR(obj));
}
break;
case T_STRING: {
snprintf(buff, buff_size, "%s %s", buff, RSTRING_PTR(obj));
Expand Down Expand Up @@ -9855,6 +9906,7 @@ Init_GC(void)

/* internal methods */
rb_define_singleton_method(rb_mGC, "verify_internal_consistency", gc_verify_internal_consistency, 0);
rb_define_singleton_method(rb_mGC, "verify_transient_heap_internal_consistency", rb_transient_heap_verify, 0);
#if MALLOC_ALLOCATED_SIZE
rb_define_singleton_method(rb_mGC, "malloc_allocated_size", gc_malloc_allocated_size, 0);
rb_define_singleton_method(rb_mGC, "malloc_allocations", gc_malloc_allocations, 0);
Expand Down
Loading