From 3db6820932b9c314692490867d8b5b90ce4c8305 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 17 Sep 2019 23:15:20 +0000 Subject: [PATCH] trying to improve hash handling with moving gc --- moo/kernel/System.moo | 14 ++++++------- moo/kernel/X11.moo | 1 + moo/lib/exec.c | 14 ++++++++++++- moo/lib/gc.c | 46 +++++++++++++++++++++++++------------------ moo/lib/moo-prv.h | 2 ++ 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 1de7d72..b524dc0 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -148,7 +148,7 @@ class System(Apex) method(#class) __os_sig_handler: caller { - | os_intr_sem tmp sh | + | os_intr_sem signo sh | os_intr_sem := Semaphore new. os_intr_sem signalOnInput: System _getSigfd. @@ -156,23 +156,23 @@ class System(Apex) [ while (true) { - until ((tmp := self _getSig) isError) + until ((signo := self _getSig) isError) { // TODO: Do i have to protected this in an exception handler??? - //TODO: Execute Handler for tmp. + //TODO: Execute Handler for signo. - System logNl: 'Interrupt dectected - signal no - ' & tmp asString. + System logNl: 'Interrupt dectected - signal no - ' & signo asString. // user-defined signal handler is not allowed for 16rFF - if (tmp == 16rFF) { goto done }. + if (signo == 16rFF) { goto done }. ifnot (self.shr isEmpty) { - self.shr do: [ :handler | handler value ] + self.shr do: [ :handler | handler value: signo ] } else { - if (tmp == 2) { goto done }. + if (signo == 2) { goto done }. }. }. os_intr_sem wait. diff --git a/moo/kernel/X11.moo b/moo/kernel/X11.moo index 7be4848..451a025 100644 --- a/moo/kernel/X11.moo +++ b/moo/kernel/X11.moo @@ -810,6 +810,7 @@ class MyObject(Object) method initialize { self.on_sig := [:sig | +'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx' dump. self.disp1 requestToExit. self.disp2 requestToExit. ]. diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 9ca6194..56d54e9 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -2221,7 +2221,19 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) default: /* MOO_OBJ_TYPE_OOP, ... */ moo_seterrbfmt(moo, MOO_ENOIMPL, "no builtin hash implemented for %O", rcv); /* TODO: better error code? */ - return MOO_PF_FAILURE; + switch (MOO_OBJ_GET_FLAGS_HASH(rcv)) + { + case 0: + MOO_OBJ_SET_FLAGS_HASH (rcv, 1); + /* fall thru */ + case 1: + hv = (moo_oow_t)rcv; + break; + + case 2: + hv = *(moo_oow_t*)((moo_uint8_t*)rcv + MOO_SIZEOF(moo_obj_t) + moo_getobjpayloadbytes(moo, rcv) - MOO_SIZEOF(moo_oow_t)); + break; + } } } break; diff --git a/moo/lib/gc.c b/moo/lib/gc.c index 35a7b97..3c99489 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -726,10 +726,12 @@ static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) moo->symtab->tally = MOO_SMOOI_TO_OOP(tally); } -static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop) +moo_oow_t moo_getobjpayloadbytes (moo_t* moo, moo_oop_t oop) { moo_oow_t nbytes; + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); + if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) { /* only an OOP object can have the trailer. @@ -749,7 +751,6 @@ static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop) 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_OBJ_GET_TRAILER_SIZE(oop); - } else { @@ -757,9 +758,14 @@ static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop) nbytes = MOO_OBJ_BYTESOF(oop); } - if (MOO_OBJ_GET_FLAGS_HASH(oop) == 2) nbytes += MOO_SIZEOF(moo_oow_t); + nbytes = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); + if (MOO_OBJ_GET_FLAGS_HASH(oop) == 2) + { + MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oop_t) == MOO_SIZEOF(moo_oow_t)); + nbytes += MOO_SIZEOF(moo_oow_t); + } - return MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); + return nbytes; } moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop) @@ -782,13 +788,19 @@ moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop) } else { - moo_oow_t nbytes_aligned; + moo_oow_t nbytes_aligned, extra_bytes = 0; moo_oop_t tmp; - nbytes_aligned = get_payload_bytes(moo, oop); + nbytes_aligned = moo_getobjpayloadbytes(moo, oop); + + if (MOO_OBJ_GET_FLAGS_HASH(oop) == 1) + { + MOO_STATIC_ASSERT (MOO_SIZEOF(moo_oop_t) == MOO_SIZEOF(moo_oow_t)); /* don't need explicit alignment */ + extra_bytes = MOO_SIZEOF(moo_oow_t); /* MOO_ALIGN(MOO_SIZEOF(moo_oow_t), MOO_SIZEOF(moo_oop_t)); */ + } /* allocate space in the new heap */ - tmp = moo_allocheapspace(moo, &moo->heap->newspace, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); + tmp = moo_allocheapspace(moo, &moo->heap->newspace, MOO_SIZEOF(moo_obj_t) + nbytes_aligned + extra_bytes); /* allocation here must not fail because * i'm allocating the new space in a new heap for @@ -810,6 +822,12 @@ moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop) * the 'if' block at the top of this function. */ MOO_OBJ_SET_CLASS (oop, tmp); + if (extra_bytes) + { + MOO_OBJ_SET_FLAGS_HASH (tmp, 2); + *(moo_oow_t*)((moo_uint8_t*)tmp + MOO_SIZEOF(moo_obj_t) + nbytes_aligned) = (moo_oow_t)oop; + } + /* return the new object */ return tmp; } @@ -826,18 +844,8 @@ static moo_uint8_t* scan_heap_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t** oop = (moo_oop_t)ptr; MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); - nbytes_aligned = get_payload_bytes(moo, oop); + nbytes_aligned = moo_getobjpayloadbytes(moo, oop); -/* -if (MOO_OBJ_GET_HASH_FLAGS(oop) == 1) -{ -TODO: use the unaligned bytes and align after this addition - nbytes_aligned += MOO_SIZEOF(moo_oow_t); - -change the hash flags to 2. -store the existing address to the extra hash field -} -*/ tmp = moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(oop)); MOO_OBJ_SET_CLASS (oop, tmp); @@ -1109,7 +1117,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) moo_oop_t z; moo_oow_t total_bytes; - total_bytes = MOO_SIZEOF(moo_obj_t) + get_payload_bytes(moo, oop); + total_bytes = MOO_SIZEOF(moo_obj_t) + moo_getobjpayloadbytes(moo, oop); /* TODO: exclude trailer and hash space? exclde hash space at least? */ diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index cd54fbe..87671bf 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -1251,6 +1251,8 @@ int moo_regfinalizable (moo_t* moo, moo_oop_t oop); int moo_deregfinalizable (moo_t* moo, moo_oop_t oop); void moo_deregallfinalizables (moo_t* moo); +moo_oow_t moo_getobjpayloadbytes (moo_t* moo, moo_oop_t oop); + /* ========================================================================= */ /* bigint.c */ /* ========================================================================= */