From 63371a52d58825419bf8c885e0e33a8d435d5be4 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 25 Dec 2018 16:00:47 +0000 Subject: [PATCH] used more macros for object slot access. found a gc bug that have yet to be debugged --- moo/lib/Makefile.in | 1 - moo/lib/exec.c | 5 ++-- moo/lib/gc.c | 59 ++++++++++++++++++--------------------------- moo/lib/main.c | 4 +++ moo/lib/moo.h | 6 ++--- 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/moo/lib/Makefile.in b/moo/lib/Makefile.in index 17bfdac..7b793b1 100644 --- a/moo/lib/Makefile.in +++ b/moo/lib/Makefile.in @@ -404,7 +404,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/moo/lib/exec.c b/moo/lib/exec.c index da768e2..c4974c8 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1787,7 +1787,6 @@ TODO: overcome this problem - accept parameters.... moo_pushtmp (moo, (moo_oop_t*)&mth); tmp_count++; moo_pushtmp (moo, (moo_oop_t*)&ass); tmp_count++; #else - startup.ptr = str_startup; startup.len = 7; mth = moo_findmethod(moo, (moo_oop_t)moo->_system, &startup, 0); @@ -1806,11 +1805,11 @@ TODO: overcome this problem - accept parameters.... /* TODO: check if it's variadic.... it should be. and accept more than 2... */ moo_pushtmp (moo, (moo_oop_t*)&mth); tmp_count++; - s1 = moo_makesymbol (moo, objname->ptr, objname->len); + s1 = moo_makesymbol(moo, objname->ptr, objname->len); if (!s1) goto oops; moo_pushtmp (moo, (moo_oop_t*)&s1); tmp_count++; - s2 = moo_makesymbol (moo, mthname->ptr, mthname->len); + s2 = moo_makesymbol(moo, mthname->ptr, mthname->len); if (!s2) goto oops; moo_pushtmp (moo, (moo_oop_t*)&s2); tmp_count++; diff --git a/moo/lib/gc.c b/moo/lib/gc.c index 260de28..f84a8c4 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -616,7 +616,7 @@ oops: static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) { moo_oop_oop_t bucket; - moo_oop_char_t symbol; + moo_oop_t tmp; moo_oow_t i, x, y, z; moo_oow_t bucket_size, index; moo_ooi_t tally; @@ -639,40 +639,43 @@ static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) for (index = 0; index < bucket_size; ) { - if (MOO_OBJ_GET_FLAGS_PERM(bucket->slot[index]) || - MOO_OBJ_GET_FLAGS_MOVED(bucket->slot[index])) + tmp = MOO_OBJ_GET_OOP_VAL(bucket, index); + if (MOO_OBJ_GET_FLAGS_PERM(tmp) || MOO_OBJ_GET_FLAGS_MOVED(tmp)) { index++; continue; } - MOO_ASSERT (moo, bucket->slot[index] != _nil); + MOO_ASSERT (moo, tmp != _nil); for (i = 0, x = index, y = index; i < bucket_size; i++) { y = (y + 1) % bucket_size; /* done if the slot at the current hash index is _nil */ - if (bucket->slot[y] == _nil) break; + tmp = MOO_OBJ_GET_OOP_VAL(bucket, y); + if (tmp == _nil) break; /* get the natural hash index for the data in the slot * at the current hash index */ - symbol = (moo_oop_char_t)bucket->slot[y]; + MOO_ASSERT (moo, MOO_CLASSOF(moo,tmp) == moo->_symbol); + z = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(tmp), MOO_OBJ_GET_SIZE(tmp)) % bucket_size; - MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); - - z = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(symbol), MOO_OBJ_GET_SIZE(symbol)) % bucket_size; + MOO_LOG2 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Compacting away a symbol - %.*js\n", MOO_OBJ_GET_SIZE(tmp), MOO_OBJ_GET_CHAR_SLOT(tmp)); /* move an element if necessary */ if ((y > x && (z <= x || z > y)) || (y < x && (z <= x && z > y))) { - bucket->slot[x] = bucket->slot[y]; + tmp = MOO_OBJ_GET_OOP_VAL(bucket, y); + /* this function is called as part of garbage collection. + * i must not use MOO_STORE_OOP for object relocation */ + MOO_OBJ_SET_OOP_VAL (bucket, x, tmp); x = y; } } - bucket->slot[x] = _nil; + MOO_OBJ_SET_OOP_VAL (bucket, x, _nil); tally--; } @@ -705,14 +708,13 @@ static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop) MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_UNIT(oop) == MOO_SIZEOF(moo_oow_t)); MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ - nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + \ - (moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)]; + nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + MOO_OBJ_GET_TRAILER_SIZE(oop); nbytes_aligned = MOO_ALIGN (nbytes, MOO_SIZEOF(moo_oop_t)); } else { /* calculate the payload size in bytes */ - nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); + nbytes_aligned = MOO_ALIGN(MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); } return nbytes_aligned; @@ -780,28 +782,12 @@ static moo_uint8_t* scan_heap_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t** moo_oop_t oop; oop = (moo_oop_t)ptr; - - if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) - { - moo_oow_t nbytes; - - MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP); - MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_UNIT(oop) == MOO_SIZEOF(moo_oow_t)); - MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ - - nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + \ - (moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)]; - nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); - } - else - { - nbytes_aligned = MOO_ALIGN(MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); - } + nbytes_aligned = get_payload_bytes(moo, oop); MOO_OBJ_SET_CLASS (oop, moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(oop))); if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP) { - moo_oop_oop_t xtmp; + register moo_oop_t tmp; moo_oow_t size; /* TODO: is it better to use a flag bit in the header to @@ -820,12 +806,15 @@ static moo_uint8_t* scan_heap_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t** size = MOO_OBJ_GET_SIZE(oop); } - xtmp = (moo_oop_oop_t)oop; for (i = 0; i < size; i++) { - if (MOO_OOP_IS_POINTER(xtmp->slot[i])) + tmp = MOO_OBJ_GET_OOP_VAL(oop, i); + if (MOO_OOP_IS_POINTER(tmp)) { - xtmp->slot[i] = moo_moveoop(moo, xtmp->slot[i]); + /* i must not use MOO_STORE_OOP() as this operation is + * part of garbage collection. */ + tmp = moo_moveoop(moo, tmp); + MOO_OBJ_SET_OOP_VAL (oop, i, tmp); } } } diff --git a/moo/lib/main.c b/moo/lib/main.c index 971f340..098f3d5 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -218,13 +218,17 @@ int main (int argc, char* argv[]) { moo_bitmask_t bm = 0; + moo_getoption (moo, MOO_TRAIT, &bm); /*bm |= MOO_NOGC;*/ bm |= MOO_AWAIT_PROCS; moo_setoption (moo, MOO_TRAIT, &bm); +#if 0 /* disable GC logs */ + moo_getoption (moo, MOO_LOG_MASK, &bm); bm = ~MOO_LOG_GC; moo_setoption (moo, MOO_LOG_MASK, &bm); +#endif } if (moo_ignite(moo, memsize) <= -1) diff --git a/moo/lib/moo.h b/moo/lib/moo.h index c94f9cc..6989114 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -635,9 +635,9 @@ struct moo_methsig_t MOO_OBJ_HEADER; moo_oop_interface_t owner; /* Interface */ - moo_oop_char_t name; /* Symbol, method name */ - moo_oop_t preamble; /* SmallInteger, includes only preamble flags based on modifiers specified */ - moo_oop_t tmpr_nargs; /* SmallInteger */ + moo_oop_char_t name; /* Symbol, method name */ + moo_oop_t preamble; /* SmallInteger, includes only preamble flags based on modifiers specified */ + moo_oop_t tmpr_nargs; /* SmallInteger */ }; #if defined(MOO_USE_METHOD_TRAILER)