From 1b0795771842902cf0f16befd45023feeac8641a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 4 Oct 2020 19:07:21 +0000 Subject: [PATCH] fixed a gc error not fixed in the previous commit --- lib/exec.c | 7 +++++-- lib/gc.c | 38 ++++++++++---------------------------- lib/hcl-prv.h | 8 -------- lib/obj.c | 4 +--- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/lib/exec.c b/lib/exec.c index de00741..8690da7 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -64,7 +64,6 @@ static HCL_INLINE const char* proc_state_to_string (int state) (HCL_OOP_TO_SMOOI((x)->heap_ftime_sec) == HCL_OOP_TO_SMOOI((y)->heap_ftime_sec) && HCL_OOP_TO_SMOOI((x)->heap_ftime_nsec) < HCL_OOP_TO_SMOOI((y)->heap_ftime_nsec)) \ ) - #define LOAD_IP(hcl, v_ctx) ((hcl)->ip = HCL_OOP_TO_SMOOI((v_ctx)->ip)) #define STORE_IP(hcl, v_ctx) ((v_ctx)->ip = HCL_SMOOI_TO_OOP((hcl)->ip)) @@ -1356,6 +1355,7 @@ static int start_initial_process_and_context (hcl_t* hcl, hcl_ooi_t initial_ip) HCL_ASSERT (hcl, proc == hcl->processor->active); hcl->initial_context = proc->initial_context; + return activate_context(hcl, 0); } @@ -1671,7 +1671,8 @@ static int execute (hcl_t* hcl) b1 = bcode & 0x7; /* low 3 bits */ push_literal: LOG_INST_1 (hcl, "push_literal @%zu", b1); - HCL_STACK_PUSH (hcl, hcl->active_function->literal_frame[b1]); + //HCL_STACK_PUSH (hcl, hcl->active_function->literal_frame[b1]); + HCL_STACK_PUSH (hcl, hcl->code.lit.arr->slot[b1]); break; /* ------------------------------------------------- */ @@ -1698,6 +1699,7 @@ static int execute (hcl_t* hcl) b1 = bcode & 0x3; /* low 2 bits */ handle_object: + /*ass = hcl->code.lit.arr->slot[b1];*/ ass = (hcl_oop_cons_t)hcl->active_function->literal_frame[b1]; HCL_ASSERT (hcl, HCL_IS_CONS(hcl, ass)); @@ -1935,6 +1937,7 @@ static int execute (hcl_t* hcl) FETCH_BYTE_CODE_TO (hcl, b2); handle_objvar: + /*t = hcl->code.lit.arr->slot[b2];*/ t = (hcl_oop_oop_t)hcl->active_function->literal_frame[b2]; HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(t) == HCL_OBJ_TYPE_OOP); HCL_ASSERT (hcl, b1 < HCL_OBJ_GET_SIZE(t)); diff --git a/lib/gc.c b/lib/gc.c index 5286727..a6bd488 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -120,7 +120,6 @@ static HCL_INLINE hcl_oow_t get_payload_bytes (hcl_t* hcl, hcl_oop_t oop) { hcl_oow_t nbytes_aligned; -#if defined(HCL_USE_OBJECT_TRAILER) if (HCL_OBJ_GET_FLAGS_TRAILER(oop)) { hcl_oow_t nbytes; @@ -146,12 +145,9 @@ static HCL_INLINE hcl_oow_t get_payload_bytes (hcl_t* hcl, hcl_oop_t oop) } else { -#endif /* calculate the payload size in bytes */ nbytes_aligned = HCL_ALIGN(HCL_OBJ_BYTESOF(oop), HCL_SIZEOF(hcl_oop_t)); -#if defined(HCL_USE_OBJECT_TRAILER) } -#endif return nbytes_aligned; } @@ -214,32 +210,16 @@ static hcl_uint8_t* scan_new_heap (hcl_t* hcl, hcl_uint8_t* ptr) { hcl_oow_t i; hcl_oow_t nbytes_aligned; - hcl_oop_t oop; + hcl_oop_t oop, tmp; oop = (hcl_oop_t)ptr; + HCL_ASSERT (hcl, HCL_OOP_IS_POINTER(oop)); - #if defined(HCL_USE_OBJECT_TRAILER) - if (HCL_OBJ_GET_FLAGS_TRAILER(oop)) - { - hcl_oow_t nbytes; + nbytes_aligned = get_payload_bytes(hcl, oop); - HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(oop) == HCL_OBJ_TYPE_OOP); - HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_UNIT(oop) == HCL_SIZEOF(hcl_oow_t)); - HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ + tmp = hcl_moveoop(hcl, HCL_OBJ_GET_CLASS(oop)); + HCL_OBJ_SET_CLASS (oop, tmp); - nbytes = HCL_OBJ_BYTESOF(oop) + HCL_SIZEOF(hcl_oow_t) + \ - (hcl_oow_t)((hcl_oop_oop_t)oop)->slot[HCL_OBJ_GET_SIZE(oop)]; - nbytes_aligned = HCL_ALIGN (nbytes, HCL_SIZEOF(hcl_oop_t)); - } - else - { - #endif - nbytes_aligned = HCL_ALIGN (HCL_OBJ_BYTESOF(oop), HCL_SIZEOF(hcl_oop_t)); - #if defined(HCL_USE_OBJECT_TRAILER) - } - #endif - - HCL_OBJ_SET_CLASS (oop, hcl_moveoop(hcl, HCL_OBJ_GET_CLASS(oop))); if (HCL_OBJ_GET_FLAGS_TYPE(oop) == HCL_OBJ_TYPE_OOP) { hcl_oop_oop_t xtmp; @@ -308,9 +288,9 @@ void hcl_gc (hcl_t* hcl) old_nil = hcl->_nil; /* move _nil and the root object table */ - hcl->_nil = hcl_moveoop(hcl, hcl->_nil); - hcl->_true = hcl_moveoop(hcl, hcl->_true); - hcl->_false = hcl_moveoop(hcl, hcl->_false); + hcl->_nil = hcl_moveoop(hcl, hcl->_nil); + hcl->_true = hcl_moveoop(hcl, hcl->_true); + hcl->_false = hcl_moveoop(hcl, hcl->_false); for (i = 0; i < HCL_COUNTOF(syminfo); i++) { @@ -356,6 +336,8 @@ void hcl_gc (hcl_t* hcl) hcl->active_context = (hcl_oop_context_t)hcl_moveoop(hcl, (hcl_oop_t)hcl->active_context); if (hcl->initial_function) hcl->initial_function = (hcl_oop_function_t)hcl_moveoop(hcl, (hcl_oop_t)hcl->initial_function); + if (hcl->active_function) + hcl->active_function = (hcl_oop_function_t)hcl_moveoop(hcl, (hcl_oop_t)hcl->active_function); if (hcl->last_retv) hcl->last_retv = hcl_moveoop(hcl, hcl->last_retv); diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index 3a4c79c..e9ecdd3 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -42,12 +42,6 @@ #define HCL_KARATSUBA_CUTOFF 32 #define HCL_KARATSUBA_CUTOFF_DEBUG 3 -/* define this to allow an pointer(OOP) object to have trailing bytes - * this is used to embed bytes codes into the back of a compile method - * object instead of putting in in a separate byte array. */ -#define HCL_USE_OBJECT_TRAILER - - #if defined(HCL_BUILD_DEBUG) #define HCL_DEBUG_LEXER 1 #define HCL_DEBUG_VM_PROCESSOR 1 @@ -715,7 +709,6 @@ hcl_oop_t hcl_allocoopobj ( hcl_oow_t size ); -#if defined(HCL_USE_OBJECT_TRAILER) hcl_oop_t hcl_allocoopobjwithtrailer ( hcl_t* hcl, int brand, @@ -723,7 +716,6 @@ hcl_oop_t hcl_allocoopobjwithtrailer ( const hcl_oob_t* tptr, hcl_oow_t tlen ); -#endif hcl_oop_t hcl_alloccharobj ( hcl_t* hcl, diff --git a/lib/obj.c b/lib/obj.c index d6b7f91..b3c7585 100644 --- a/lib/obj.c +++ b/lib/obj.c @@ -92,7 +92,6 @@ hcl_oop_t hcl_allocoopobj (hcl_t* hcl, int brand, hcl_oow_t size) return alloc_oop_array(hcl, brand, size, 0); } -#if defined(HCL_USE_OBJECT_TRAILER) hcl_oop_t hcl_allocoopobjwithtrailer (hcl_t* hcl, int brand, hcl_oow_t size, const hcl_oob_t* bptr, hcl_oow_t blen) { hcl_oop_oop_t hdr; @@ -104,7 +103,7 @@ hcl_oop_t hcl_allocoopobjwithtrailer (hcl_t* hcl, int brand, hcl_oow_t size, con nbytes_aligned = HCL_ALIGN(nbytes, HCL_SIZEOF(hcl_oop_t)); hdr = (hcl_oop_oop_t)hcl_allocbytes(hcl, HCL_SIZEOF(hcl_obj_t) + nbytes_aligned); - if (!hdr) return HCL_NULL; + if (HCL_UNLIKELY(!hdr)) return HCL_NULL; hdr->_flags = HCL_OBJ_MAKE_FLAGS(HCL_OBJ_TYPE_OOP, HCL_SIZEOF(hcl_oop_t), 0, 0, 0, 0, 1, 0); HCL_OBJ_SET_SIZE (hdr, size); @@ -127,7 +126,6 @@ hcl_oop_t hcl_allocoopobjwithtrailer (hcl_t* hcl, int brand, hcl_oow_t size, con return (hcl_oop_t)hdr; } -#endif static HCL_INLINE hcl_oop_t alloc_numeric_array (hcl_t* hcl, int brand, const void* ptr, hcl_oow_t len, hcl_obj_type_t type, hcl_oow_t unit, int extra, int ngc) {