From 5dd67859d79fa6a09f0d80e400a94ae73cd2a634 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sat, 29 Dec 2018 15:16:58 +0000 Subject: [PATCH] change the ngc bit to the proc bit to determine the process object. added temporary work around the faulty gc --- moo/lib/exec.c | 1 + moo/lib/gc.c | 6 ++++-- moo/lib/moo.h | 12 ++++++------ moo/lib/obj.c | 32 ++++++++++++-------------------- moo/lib/pf-basic.c | 5 ++--- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 4c283bd..9a1c16e 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -328,6 +328,7 @@ static moo_oop_process_t make_process (moo_t* moo, moo_oop_context_t c) moo_popvolat (moo); if (!proc) return MOO_NULL; + MOO_OBJ_SET_FLAGS_PROC (proc, 1); /* a special flag to indicate an object is a process instance */ proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED); /* assign a process id to the process */ diff --git a/moo/lib/gc.c b/moo/lib/gc.c index e6441ba..297099c 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -495,6 +495,7 @@ static int ignite_2 (moo_t* moo) moo->_false = moo_instantiate(moo, moo->_false_class, MOO_NULL, 0); if (!moo->_true || !moo->_false) return -1; +moo->igniting = 0; /* Create the symbol table */ tmp = moo_instantiate(moo, moo->_symbol_table, MOO_NULL, 0); if (!tmp) return -1; @@ -509,6 +510,7 @@ static int ignite_2 (moo_t* moo) tmp = moo_instantiate(moo, moo->_array, MOO_NULL, moo->option.dfl_symtab_size); if (!tmp) return -1; moo->symtab->bucket = (moo_oop_oop_t)tmp; +moo->igniting = 1; /* Create the system dictionary */ tmp = (moo_oop_t)moo_makensdic(moo, moo->_namespace, moo->option.dfl_sysdic_size); @@ -794,7 +796,7 @@ static moo_uint8_t* scan_heap_space (moo_t* moo, moo_uint8_t* ptr, moo_uint8_t** /* TODO: is it better to use a flag bit in the header to * determine that it is an instance of process? * for example, if (MOO_OBJ_GET_FLAGS_PROC(oop))... */ - if (moo->_process && MOO_OBJ_GET_CLASS(oop) == moo->_process) + if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(oop))) { /* the stack in a process object doesn't need to be * scanned in full. the slots above the stack pointer @@ -976,7 +978,7 @@ void moo_gc (moo_t* moo) * if the symbol has not moved to the new heap, the symbol * is not referenced by any other objects than the symbol * table itself */ - /*compact_symbol_table (moo, old_nil); <---- this causes a problem when gc debugging is on, debug it */ + compact_symbol_table (moo, old_nil); /* move the symbol table itself */ moo->symtab = (moo_oop_dic_t)moo_moveoop(moo, (moo_oop_t)moo->symtab); diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 08a8bab..7aef821 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -382,7 +382,7 @@ typedef enum moo_gcfin_t moo_gcfin_t; #define MOO_OBJ_FLAGS_KERNEL_BITS 2 #define MOO_OBJ_FLAGS_PERM_BITS 1 #define MOO_OBJ_FLAGS_MOVED_BITS 1 -#define MOO_OBJ_FLAGS_NGC_BITS 1 +#define MOO_OBJ_FLAGS_PROC_BITS 1 #define MOO_OBJ_FLAGS_RDONLY_BITS 1 #define MOO_OBJ_FLAGS_GCFIN_BITS 4 #define MOO_OBJ_FLAGS_TRAILER_BITS 1 @@ -392,8 +392,8 @@ typedef enum moo_gcfin_t moo_gcfin_t; #define MOO_OBJ_FLAGS_EXTRA_SHIFT (MOO_OBJ_FLAGS_KERNEL_BITS + MOO_OBJ_FLAGS_KERNEL_SHIFT) #define MOO_OBJ_FLAGS_KERNEL_SHIFT (MOO_OBJ_FLAGS_PERM_BITS + MOO_OBJ_FLAGS_PERM_SHIFT) #define MOO_OBJ_FLAGS_PERM_SHIFT (MOO_OBJ_FLAGS_MOVED_BITS + MOO_OBJ_FLAGS_MOVED_SHIFT) -#define MOO_OBJ_FLAGS_MOVED_SHIFT (MOO_OBJ_FLAGS_NGC_BITS + MOO_OBJ_FLAGS_NGC_SHIFT) -#define MOO_OBJ_FLAGS_NGC_SHIFT (MOO_OBJ_FLAGS_RDONLY_BITS + MOO_OBJ_FLAGS_RDONLY_SHIFT) +#define MOO_OBJ_FLAGS_MOVED_SHIFT (MOO_OBJ_FLAGS_PROC_BITS + MOO_OBJ_FLAGS_PROC_SHIFT) +#define MOO_OBJ_FLAGS_PROC_SHIFT (MOO_OBJ_FLAGS_RDONLY_BITS + MOO_OBJ_FLAGS_RDONLY_SHIFT) #define MOO_OBJ_FLAGS_RDONLY_SHIFT (MOO_OBJ_FLAGS_GCFIN_BITS + MOO_OBJ_FLAGS_GCFIN_SHIFT) #define MOO_OBJ_FLAGS_GCFIN_SHIFT (MOO_OBJ_FLAGS_TRAILER_BITS + MOO_OBJ_FLAGS_TRAILER_SHIFT) #define MOO_OBJ_FLAGS_TRAILER_SHIFT (0) @@ -404,7 +404,7 @@ typedef enum moo_gcfin_t moo_gcfin_t; #define MOO_OBJ_GET_FLAGS_KERNEL(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS) #define MOO_OBJ_GET_FLAGS_PERM(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PERM_SHIFT, MOO_OBJ_FLAGS_PERM_BITS) #define MOO_OBJ_GET_FLAGS_MOVED(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS) -#define MOO_OBJ_GET_FLAGS_NGC(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS) +#define MOO_OBJ_GET_FLAGS_PROC(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PROC_SHIFT, MOO_OBJ_FLAGS_PROC_BITS) #define MOO_OBJ_GET_FLAGS_RDONLY(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_RDONLY_SHIFT, MOO_OBJ_FLAGS_RDONLY_BITS) #define MOO_OBJ_GET_FLAGS_GCFIN(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_GCFIN_SHIFT, MOO_OBJ_FLAGS_GCFIN_BITS) #define MOO_OBJ_GET_FLAGS_TRAILER(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TRAILER_SHIFT, MOO_OBJ_FLAGS_TRAILER_BITS) @@ -415,7 +415,7 @@ typedef enum moo_gcfin_t moo_gcfin_t; #define MOO_OBJ_SET_FLAGS_KERNEL(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS, v) #define MOO_OBJ_SET_FLAGS_PERM(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PERM_SHIFT, MOO_OBJ_FLAGS_PERM_BITS, v) #define MOO_OBJ_SET_FLAGS_MOVED(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS, v) -#define MOO_OBJ_SET_FLAGS_NGC(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS, v) +#define MOO_OBJ_SET_FLAGS_PROC(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PROC_SHIFT, MOO_OBJ_FLAGS_PROC_BITS, v) #define MOO_OBJ_SET_FLAGS_RDONLY(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_RDONLY_SHIFT, MOO_OBJ_FLAGS_RDONLY_BITS, v) #define MOO_OBJ_SET_FLAGS_GCFIN(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_GCFIN_SHIFT, MOO_OBJ_FLAGS_GCFIN_BITS, v) #define MOO_OBJ_SET_FLAGS_TRAILER(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TRAILER_SHIFT, MOO_OBJ_FLAGS_TRAILER_BITS, v) @@ -446,7 +446,7 @@ typedef enum moo_gcfin_t moo_gcfin_t; (((moo_oow_t)(k)) << MOO_OBJ_FLAGS_KERNEL_SHIFT) | \ (((moo_oow_t)(p)) << MOO_OBJ_FLAGS_PERM_SHIFT) | \ (((moo_oow_t)(m)) << MOO_OBJ_FLAGS_MOVED_SHIFT) | \ - (((moo_oow_t)(g)) << MOO_OBJ_FLAGS_NGC_SHIFT) | \ + (((moo_oow_t)(g)) << MOO_OBJ_FLAGS_PROC_SHIFT) | \ (((moo_oow_t)(r)) << MOO_OBJ_FLAGS_TRAILER_SHIFT) \ ) diff --git a/moo/lib/obj.c b/moo/lib/obj.c index 0af8af2..a7dcd23 100644 --- a/moo/lib/obj.c +++ b/moo/lib/obj.c @@ -127,7 +127,7 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_ return (moo_oop_t)hdr; } -static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, moo_oow_t len, moo_obj_type_t type, moo_oow_t unit, int extra, int ngc) +static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, moo_oow_t len, moo_obj_type_t type, moo_oow_t unit, int extra) { /* allocate a variable object */ @@ -142,22 +142,14 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); /* TODO: check overflow in size calculation*/ - if (MOO_UNLIKELY(ngc)) - { - hdr = (moo_oop_t)moo_callocmem(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); - if (!hdr) return MOO_NULL; - } - else - { - /* making the number of bytes to allocate a multiple of - * MOO_SIZEOF(moo_oop_t) will guarantee the starting address - * of the allocated space to be an even number. - * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ - hdr = (moo_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); - if (!hdr) return MOO_NULL; - } + /* making the number of bytes to allocate a multiple of + * MOO_SIZEOF(moo_oop_t) will guarantee the starting address + * of the allocated space to be an even number. + * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ + hdr = (moo_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); + if (!hdr) return MOO_NULL; - hdr->_flags = MOO_OBJ_MAKE_FLAGS(type, unit, extra, 0, moo->igniting, 0, ngc, 0); /* TODO: review. ngc and perm flags seems to conflict with each other ... the diff is that ngc is malloc() and perm is allocated in the perm heap */ + hdr->_flags = MOO_OBJ_MAKE_FLAGS(type, unit, extra, 0, moo->igniting, 0, 0, 0); /* TODO: review. ngc and perm flags seems to conflict with each other ... the diff is that ngc is malloc() and perm is allocated in the perm heap */ hdr->_size = len; MOO_OBJ_SET_SIZE (hdr, len); MOO_OBJ_SET_CLASS (hdr, moo->_nil); @@ -179,22 +171,22 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo MOO_INLINE moo_oop_t moo_alloccharobj (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_CHAR, MOO_SIZEOF(moo_ooch_t), 1, 0); + return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_CHAR, MOO_SIZEOF(moo_ooch_t), 1); } MOO_INLINE moo_oop_t moo_allocbyteobj (moo_t* moo, const moo_oob_t* ptr, moo_oow_t len) { - return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_BYTE, MOO_SIZEOF(moo_oob_t), 0, 0); + return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_BYTE, MOO_SIZEOF(moo_oob_t), 0); } MOO_INLINE moo_oop_t moo_allochalfwordobj (moo_t* moo, const moo_oohw_t* ptr, moo_oow_t len) { - return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_HALFWORD, MOO_SIZEOF(moo_oohw_t), 0, 0); + return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_HALFWORD, MOO_SIZEOF(moo_oohw_t), 0); } MOO_INLINE moo_oop_t moo_allocwordobj (moo_t* moo, const moo_oow_t* ptr, moo_oow_t len) { - return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_WORD, MOO_SIZEOF(moo_oow_t), 0, 0); + return alloc_numeric_array(moo, ptr, len, MOO_OBJ_TYPE_WORD, MOO_SIZEOF(moo_oow_t), 0); } static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t num_flexi_fields, moo_obj_type_t* type, moo_oow_t* outlen) diff --git a/moo/lib/pf-basic.c b/moo/lib/pf-basic.c index 6cd8541..0595f74 100644 --- a/moo/lib/pf-basic.c +++ b/moo/lib/pf-basic.c @@ -122,13 +122,12 @@ static int _equal_objects (moo_t* moo, moo_oop_t rcv, moo_oop_t arg) return -1; #else - if (moo->_process && MOO_OBJ_GET_CLASS(rcv) == moo->_process) + if (MOO_UNLIKELY(MOO_OBJ_GET_FLAGS_PROC(rcv))) { /* the stack in a process object doesn't need to be * scanned in full. the slots above the stack pointer * are garbages. */ - size = MOO_PROCESS_NAMED_INSTVARS + - MOO_OOP_TO_SMOOI(((moo_oop_process_t)rcv)->sp) + 1; + size = MOO_PROCESS_NAMED_INSTVARS + MOO_OOP_TO_SMOOI(((moo_oop_process_t)rcv)->sp) + 1; MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(rcv)); } else