used more macros for object slot access.

found a gc bug that have yet to be debugged
This commit is contained in:
hyunghwan.chung 2018-12-25 16:00:47 +00:00
parent e97ca41d8c
commit 63371a52d5
5 changed files with 33 additions and 42 deletions

View File

@ -404,7 +404,6 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@

View File

@ -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*)&mth); tmp_count++;
moo_pushtmp (moo, (moo_oop_t*)&ass); tmp_count++; moo_pushtmp (moo, (moo_oop_t*)&ass); tmp_count++;
#else #else
startup.ptr = str_startup; startup.ptr = str_startup;
startup.len = 7; startup.len = 7;
mth = moo_findmethod(moo, (moo_oop_t)moo->_system, &startup, 0); 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... */ /* TODO: check if it's variadic.... it should be. and accept more than 2... */
moo_pushtmp (moo, (moo_oop_t*)&mth); tmp_count++; 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; if (!s1) goto oops;
moo_pushtmp (moo, (moo_oop_t*)&s1); tmp_count++; 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; if (!s2) goto oops;
moo_pushtmp (moo, (moo_oop_t*)&s2); tmp_count++; moo_pushtmp (moo, (moo_oop_t*)&s2); tmp_count++;

View File

@ -616,7 +616,7 @@ oops:
static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) static void compact_symbol_table (moo_t* moo, moo_oop_t _nil)
{ {
moo_oop_oop_t bucket; moo_oop_oop_t bucket;
moo_oop_char_t symbol; moo_oop_t tmp;
moo_oow_t i, x, y, z; moo_oow_t i, x, y, z;
moo_oow_t bucket_size, index; moo_oow_t bucket_size, index;
moo_ooi_t tally; 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; ) for (index = 0; index < bucket_size; )
{ {
if (MOO_OBJ_GET_FLAGS_PERM(bucket->slot[index]) || tmp = MOO_OBJ_GET_OOP_VAL(bucket, index);
MOO_OBJ_GET_FLAGS_MOVED(bucket->slot[index])) if (MOO_OBJ_GET_FLAGS_PERM(tmp) || MOO_OBJ_GET_FLAGS_MOVED(tmp))
{ {
index++; index++;
continue; continue;
} }
MOO_ASSERT (moo, bucket->slot[index] != _nil); MOO_ASSERT (moo, tmp != _nil);
for (i = 0, x = index, y = index; i < bucket_size; i++) for (i = 0, x = index, y = index; i < bucket_size; i++)
{ {
y = (y + 1) % bucket_size; y = (y + 1) % bucket_size;
/* done if the slot at the current hash index is _nil */ /* 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 /* get the natural hash index for the data in the slot
* at the current hash index */ * 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); 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));
z = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(symbol), MOO_OBJ_GET_SIZE(symbol)) % bucket_size;
/* move an element if necessary */ /* move an element if necessary */
if ((y > x && (z <= x || z > y)) || if ((y > x && (z <= x || z > y)) ||
(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; x = y;
} }
} }
bucket->slot[x] = _nil; MOO_OBJ_SET_OOP_VAL (bucket, x, _nil);
tally--; 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_UNIT(oop) == MOO_SIZEOF(moo_oow_t));
MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ 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) + \ nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + MOO_OBJ_GET_TRAILER_SIZE(oop);
(moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)];
nbytes_aligned = MOO_ALIGN (nbytes, MOO_SIZEOF(moo_oop_t)); nbytes_aligned = MOO_ALIGN (nbytes, MOO_SIZEOF(moo_oop_t));
} }
else else
{ {
/* calculate the payload size in bytes */ /* 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; 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; moo_oop_t oop;
oop = (moo_oop_t)ptr; oop = (moo_oop_t)ptr;
nbytes_aligned = get_payload_bytes(moo, oop);
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));
}
MOO_OBJ_SET_CLASS (oop, moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(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) 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; moo_oow_t size;
/* TODO: is it better to use a flag bit in the header to /* 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); size = MOO_OBJ_GET_SIZE(oop);
} }
xtmp = (moo_oop_oop_t)oop;
for (i = 0; i < size; i++) 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);
} }
} }
} }

View File

@ -218,13 +218,17 @@ int main (int argc, char* argv[])
{ {
moo_bitmask_t bm = 0; moo_bitmask_t bm = 0;
moo_getoption (moo, MOO_TRAIT, &bm);
/*bm |= MOO_NOGC;*/ /*bm |= MOO_NOGC;*/
bm |= MOO_AWAIT_PROCS; bm |= MOO_AWAIT_PROCS;
moo_setoption (moo, MOO_TRAIT, &bm); moo_setoption (moo, MOO_TRAIT, &bm);
#if 0
/* disable GC logs */ /* disable GC logs */
moo_getoption (moo, MOO_LOG_MASK, &bm);
bm = ~MOO_LOG_GC; bm = ~MOO_LOG_GC;
moo_setoption (moo, MOO_LOG_MASK, &bm); moo_setoption (moo, MOO_LOG_MASK, &bm);
#endif
} }
if (moo_ignite(moo, memsize) <= -1) if (moo_ignite(moo, memsize) <= -1)