trying to improve hash handling with moving gc

This commit is contained in:
hyunghwan.chung 2019-09-17 23:15:20 +00:00
parent ee9064bf8f
commit 3db6820932
5 changed files with 50 additions and 27 deletions

View File

@ -148,7 +148,7 @@ class System(Apex)
method(#class) __os_sig_handler: caller method(#class) __os_sig_handler: caller
{ {
| os_intr_sem tmp sh | | os_intr_sem signo sh |
os_intr_sem := Semaphore new. os_intr_sem := Semaphore new.
os_intr_sem signalOnInput: System _getSigfd. os_intr_sem signalOnInput: System _getSigfd.
@ -156,23 +156,23 @@ class System(Apex)
[ [
while (true) while (true)
{ {
until ((tmp := self _getSig) isError) until ((signo := self _getSig) isError)
{ {
// TODO: Do i have to protected this in an exception handler??? // 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 // user-defined signal handler is not allowed for 16rFF
if (tmp == 16rFF) { goto done }. if (signo == 16rFF) { goto done }.
ifnot (self.shr isEmpty) ifnot (self.shr isEmpty)
{ {
self.shr do: [ :handler | handler value ] self.shr do: [ :handler | handler value: signo ]
} }
else else
{ {
if (tmp == 2) { goto done }. if (signo == 2) { goto done }.
}. }.
}. }.
os_intr_sem wait. os_intr_sem wait.

View File

@ -810,6 +810,7 @@ class MyObject(Object)
method initialize method initialize
{ {
self.on_sig := [:sig | self.on_sig := [:sig |
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx' dump.
self.disp1 requestToExit. self.disp1 requestToExit.
self.disp2 requestToExit. self.disp2 requestToExit.
]. ].

View File

@ -2221,7 +2221,19 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
default: default:
/* MOO_OBJ_TYPE_OOP, ... */ /* MOO_OBJ_TYPE_OOP, ... */
moo_seterrbfmt(moo, MOO_ENOIMPL, "no builtin hash implemented for %O", rcv); /* TODO: better error code? */ 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; break;

View File

@ -726,10 +726,12 @@ static void compact_symbol_table (moo_t* moo, moo_oop_t _nil)
moo->symtab->tally = MOO_SMOOI_TO_OOP(tally); 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_oow_t nbytes;
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop));
if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) if (MOO_OBJ_GET_FLAGS_TRAILER(oop))
{ {
/* only an OOP object can have the trailer. /* 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 */ 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); nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + MOO_OBJ_GET_TRAILER_SIZE(oop);
} }
else 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); 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) 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 else
{ {
moo_oow_t nbytes_aligned; moo_oow_t nbytes_aligned, extra_bytes = 0;
moo_oop_t tmp; 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 */ /* 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 /* allocation here must not fail because
* i'm allocating the new space in a new heap for * 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. */ * the 'if' block at the top of this function. */
MOO_OBJ_SET_CLASS (oop, tmp); 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 the new object */
return tmp; 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; oop = (moo_oop_t)ptr;
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); 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)); tmp = moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(oop));
MOO_OBJ_SET_CLASS (oop, tmp); 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_oop_t z;
moo_oow_t total_bytes; 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? */ /* TODO: exclude trailer and hash space? exclde hash space at least? */

View File

@ -1251,6 +1251,8 @@ int moo_regfinalizable (moo_t* moo, moo_oop_t oop);
int moo_deregfinalizable (moo_t* moo, moo_oop_t oop); int moo_deregfinalizable (moo_t* moo, moo_oop_t oop);
void moo_deregallfinalizables (moo_t* moo); void moo_deregallfinalizables (moo_t* moo);
moo_oow_t moo_getobjpayloadbytes (moo_t* moo, moo_oop_t oop);
/* ========================================================================= */ /* ========================================================================= */
/* bigint.c */ /* bigint.c */
/* ========================================================================= */ /* ========================================================================= */