From 102fa8abf438de707921e81a9767500d979a7118 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 24 Jun 2016 15:01:51 +0000 Subject: [PATCH] removed more unused code --- stix/kernel/Context.st | 30 +------- stix/lib/exec.c | 167 +++++++++-------------------------------- stix/lib/gc.c | 26 ++----- stix/lib/stix.h | 40 ++++------ 4 files changed, 56 insertions(+), 207 deletions(-) diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index 4606dfa..7dca0c3 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -370,18 +370,7 @@ ## -------------------------------------------------- ## -------------------------------------------------- - ## If VM is built without STIX_USE_PROCSTK - ## -------------------------------------------------- - ## | pc sp | - ## sp := thisContext sp. - ## pc := thisContext pcplus1. - ## self value ifFalse: [ ^nil "^self" ]. - ## aBlock value. - ## thisContext pc: pc sp: sp. - ## -------------------------------------------------- - - ## -------------------------------------------------- - ## If VM is built with STIX_USE_PROCSTK + ## Non-recursive implementation ## -------------------------------------------------- | pc sp | @@ -404,7 +393,7 @@ ## self whileTrue. ## -------------------------------------------------- - ## If VM is built with STIX_USE_PROCSTK + ## Non-recursive implementation ## -------------------------------------------------- | pc | pc := thisContext pcplus1. @@ -424,18 +413,7 @@ ## -------------------------------------------------- ## -------------------------------------------------- - ## If VM is built without STIX_USE_PROCSTK - ## -------------------------------------------------- - ## | pc sp | - ## sp := thisContext sp. - ## pc := thisContext pcplus1. - ## self value ifTrue: [ ^nil "^self" ]. - ## aBlock value. - ## thisContext pc: pc sp: sp. - ## -------------------------------------------------- - - ## -------------------------------------------------- - ## If VM is built with STIX_USE_PROCSTK + ## Non-recursive implementation ## -------------------------------------------------- ## The assignment to 'pc' uses the POP_INTO_TEMPVAR_1. ## It pops a value off the stack top, stores it to the second @@ -463,7 +441,7 @@ ## self whileFalse. ## -------------------------------------------------- - ## If VM is built with STIX_USE_PROCSTK + ## Non-recursive implementation ## -------------------------------------------------- | pc | pc := thisContext pcplus1. diff --git a/stix/lib/exec.c b/stix/lib/exec.c index a564244..e8c771c 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -50,6 +50,12 @@ # endif #endif +#if defined(USE_DYNCALL) +/* TODO: defined dcAllocMem and dcFreeMeme before builing the dynload and dyncall library */ +# include /* TODO: remove this. make dyXXXX calls to callbacks */ +#endif + + #define PROC_STATE_RUNNING 3 #define PROC_STATE_WAITING 2 #define PROC_STATE_RUNNABLE 1 @@ -70,18 +76,6 @@ (STIX_OOP_TO_SMOOI((x)->heap_ftime_sec) == STIX_OOP_TO_SMOOI((y)->heap_ftime_sec) && STIX_OOP_TO_SMOOI((x)->heap_ftime_nsec) < STIX_OOP_TO_SMOOI((y)->heap_ftime_nsec)) \ ) -#if defined(USE_DYNCALL) -/* TODO: defined dcAllocMem and dcFreeMeme before builing the dynload and dyncall library */ -# include /* TODO: remove this. make dyXXXX calls to callbacks */ -#endif - -/* TODO: context's stack overflow check in various part of this file */ -/* TOOD: determine the right stack size */ -#if defined(STIX_USE_PROCSTK) -# define CONTEXT_STACK_SIZE 0 -#else -# define CONTEXT_STACK_SIZE 96 -#endif #define LOAD_IP(stix, v_ctx) ((stix)->ip = STIX_OOP_TO_SMOOI((v_ctx)->ip)) #define STORE_IP(stix, v_ctx) ((v_ctx)->ip = STIX_SMOOI_TO_OOP((stix)->ip)) @@ -92,38 +86,18 @@ #define LOAD_ACTIVE_IP(stix) LOAD_IP(stix, (stix)->active_context) #define STORE_ACTIVE_IP(stix) STORE_IP(stix, (stix)->active_context) -#if defined(STIX_USE_PROCSTK) - #define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->processor->active) - #define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->processor->active) -#else - #define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->active_context) - #define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->active_context) -#endif +#define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->processor->active) +#define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->processor->active) - -#if defined(STIX_USE_PROCSTK) - #define SWITCH_ACTIVE_CONTEXT(stix,v_ctx) \ - do \ - { \ - STORE_ACTIVE_IP (stix); \ - (stix)->active_context = (v_ctx); \ - (stix)->active_method = (stix_oop_method_t)(stix)->active_context->origin->method_or_nargs; \ - SET_ACTIVE_METHOD_CODE(stix); \ - LOAD_ACTIVE_IP (stix); \ - } while (0) -#else - #define SWITCH_ACTIVE_CONTEXT(stix,v_ctx) \ - do \ - { \ - STORE_ACTIVE_IP (stix); \ - STORE_ACTIVE_SP (stix); \ - (stix)->active_context = (v_ctx); \ - (stix)->active_method = (stix_oop_method_t)(stix)->active_context->origin->method_or_nargs; \ - SET_ACTIVE_METHOD_CODE(stix); \ - LOAD_ACTIVE_IP (stix); \ - LOAD_ACTIVE_SP (stix); \ - } while (0) -#endif +#define SWITCH_ACTIVE_CONTEXT(stix,v_ctx) \ + do \ + { \ + STORE_ACTIVE_IP (stix); \ + (stix)->active_context = (v_ctx); \ + (stix)->active_method = (stix_oop_method_t)(stix)->active_context->origin->method_or_nargs; \ + SET_ACTIVE_METHOD_CODE(stix); \ + LOAD_ACTIVE_IP (stix); \ + } while (0) #define FETCH_BYTE_CODE(stix) ((stix)->active_code[(stix)->ip++]) #define FETCH_BYTE_CODE_TO(stix, v_ooi) (v_ooi = FETCH_BYTE_CODE(stix)) @@ -317,11 +291,7 @@ static STIX_INLINE void sleep_active_process (stix_t* stix, int state) STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - put process %O context %O ip=%zd to sleep\n", stix->processor->active, stix->active_context, stix->ip); #endif -#if defined(STIX_USE_PROCSTK) STORE_ACTIVE_SP(stix); -#else - /* nothing special */ -#endif /* store the current active context to the current process. * it is the suspended context of the process to be suspended */ @@ -336,11 +306,7 @@ static STIX_INLINE void wake_new_process (stix_t* stix, stix_oop_process_t proc) proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING); stix->processor->active = proc; -#if defined(STIX_USE_PROCSTK) LOAD_ACTIVE_SP(stix); -#else - /* nothing special */ -#endif /* activate the suspended context of the new process */ SWITCH_ACTIVE_CONTEXT (stix, proc->current_context); @@ -921,50 +887,21 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth) STIX_ASSERT (ntmprs >= 0); STIX_ASSERT (nargs <= ntmprs); -#if defined(STIX_USE_PROCSTK) - /* nothing special */ -#else - /* message sending requires a receiver to be pushed. - * the stack pointer of the sending context cannot be -1. - * if one-argumented message is invoked the stack of the - * sending context looks like this. - * - * Sending Context - * - * +---------------------+ - * | fixed part | - * | | - * | | - * | | - * +---------------------+ - * | .... | slot[0] - * | .... | slot[..] - * | .... | slot[..] - * | receiver | slot[..] <-- sp - nargs(1) - * | arg1 | slot[..] <-- sp - * | .... | slot[..] - * | | slot[stack_size - 1] - * +---------------------+ - */ - STIX_ASSERT (stix->sp >= 0); - STIX_ASSERT (stix->sp >= nargs); -#endif stix_pushtmp (stix, (stix_oop_t*)&mth); - ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, ntmprs + CONTEXT_STACK_SIZE); + ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, ntmprs); stix_poptmp (stix); if (!ctx) return -1; ctx->sender = stix->active_context; ctx->ip = STIX_SMOOI_TO_OOP(0); - -#if defined(STIX_USE_PROCSTK) /* ctx->sp will be set further down */ -#else - /* the front part of a stack has temporary variables including arguments. - * - * New Context + + /* A context is compose of a fixed part and a variable part. + * the variable part hold temporary varibles including arguments. * + * Assuming a method context with 2 arguments and 3 local temporary + * variables, the context will look like this. * +---------------------+ * | fixed part | * | | @@ -973,18 +910,12 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth) * +---------------------+ * | tmp1 (arg1) | slot[0] * | tmp2 (arg2) | slot[1] - * | .... | slot[..] - * | tmpX | slot[..] <-- initial sp - * | | slot[..] - * | | slot[..] - * | | slot[stack_size - 2] - * | | slot[stack_size - 1] + * | tmp3 | slot[2] + * | tmp4 | slot[3] + * | tmp5 | slot[4] * +---------------------+ - * - * if no temporaries exist, the initial sp is -1. */ - ctx->sp = STIX_SMOOI_TO_OOP(ntmprs - 1); -#endif + ctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs); ctx->method_or_nargs = (stix_oop_t)mth; /* the 'home' field of a method context is always stix->_nil. @@ -1024,18 +955,13 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth) STIX_ASSERT (stix->sp >= -1); -#if defined(STIX_USE_PROCSTK) - /* when process stack is used, the stack pointer in a context - * is a stack pointer of a process before it is activated. - * this stack pointer is stored to the context so that it is - * used to restore the process stack pointer upon returning from - * a method context. */ + /* the stack pointer in a context is a stack pointer of a process + * before it is activated. this stack pointer is stored to the context + * so that it is used to restore the process stack pointer upon returning + * from a method context. */ ctx->sp = STIX_SMOOI_TO_OOP(stix->sp); -#else - /* do nothing */ -#endif - /* switch the active context */ + /* switch the active context to the newly instantiated one*/ SWITCH_ACTIVE_CONTEXT (stix, ctx); return 0; @@ -1134,15 +1060,8 @@ static int start_initial_process_and_context (stix_t* stix, const stix_oocs_t* o stix_oop_method_t mth; stix_oop_process_t proc; - /* create a fake initial context */ -#if defined(STIX_USE_PROCSTK) + /* create a fake initial context. */ ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, 0); -#else - /* stack size is set to 1 because it needs sapce to push the receiver - * referenced by 'objname' */ -/* TODO: increase the stack size to allow arguments to the intial methods */ - ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, 1); -#endif if (!ctx) return -1; ass = stix_lookupsysdic (stix, objname); @@ -1664,7 +1583,7 @@ STIX_DEBUG0 (stix, "PRIM BlockContext value FAIL - NARGS MISMATCH\n"); STIX_ASSERT (local_ntmprs >= actual_arg_count); /* create a new block context to clone rcv_blkctx */ - blkctx = (stix_oop_context_t) stix_instantiate (stix, stix->_block_context, STIX_NULL, local_ntmprs + CONTEXT_STACK_SIZE); + blkctx = (stix_oop_context_t) stix_instantiate (stix, stix->_block_context, STIX_NULL, local_ntmprs); if (!blkctx) return -1; /* get rcv_blkctx again to be GC-safe for stix_instantiate() above */ @@ -1712,11 +1631,7 @@ STIX_DEBUG0 (stix, "PRIM BlockContext value FAIL - NARGS MISMATCH\n"); STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ STIX_ASSERT (blkctx->home != stix->_nil); -#if defined(STIX_USE_PROCSTK) blkctx->sp = STIX_SMOOI_TO_OOP(-1); /* not important at all */ -#else - blkctx->sp = STIX_SMOOI_TO_OOP(local_ntmprs - 1); -#endif blkctx->sender = stix->active_context; *pblkctx = blkctx; @@ -3931,12 +3846,8 @@ return -1; } STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); - #if defined(STIX_USE_PROCSTK) /* restore the stack pointer */ stix->sp = STIX_OOP_TO_SMOOI(stix->active_context->origin->sp); - #else - /* do nothing */ - #endif SWITCH_ACTIVE_CONTEXT (stix, stix->active_context->origin->sender); if (unwind_protect) @@ -4011,19 +3922,9 @@ return -1; /* it is a normal block return as the active block context * is not the initial context of a process */ - #if defined(STIX_USE_PROCSTK) /* the process stack is shared. the return value * doesn't need to get moved. */ SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)stix->active_context->sender); - #else - /* NOTE: GC must not performed between here and */ - return_value = STIX_STACK_GETTOP(stix); - STIX_STACK_POP (stix); /* pop off the return value */ - - SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)stix->active_context->sender); - STIX_STACK_PUSH (stix, return_value); /* push it to the sender */ - /* NOTE: here. if so, return_value will point to a garbage. */ - #endif } break; diff --git a/stix/lib/gc.c b/stix/lib/gc.c index 0b76bfe..dc20a63 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -221,7 +221,6 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr) stix_oop_oop_t xtmp; stix_oow_t size; - #if defined(STIX_USE_PROCSTK) if (stix->_process && STIX_OBJ_GET_CLASS(oop) == stix->_process) { /* the stack in a process object doesn't need to be @@ -231,18 +230,6 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr) STIX_OOP_TO_SMOOI(((stix_oop_process_t)oop)->sp) + 1; STIX_ASSERT (size <= STIX_OBJ_GET_SIZE(oop)); } - #else - if ((stix->_method_context && STIX_OBJ_GET_CLASS(oop) == stix->_method_context) || - (stix->_block_context && STIX_OBJ_GET_CLASS(oop) == stix->_block_context)) - { - /* the stack in a context object doesn't need to be - * scanned in full. the slots above the stack pointer - * are garbages. */ - size = STIX_CONTEXT_NAMED_INSTVARS + - STIX_OOP_TO_SMOOI(((stix_oop_context_t)oop)->sp) + 1; - STIX_ASSERT (size <= STIX_OBJ_GET_SIZE(oop)); - } - #endif else { size = STIX_OBJ_GET_SIZE(oop); @@ -280,14 +267,11 @@ void stix_gc (stix_t* stix) if (stix->active_context) { /* TODO: verify if this is correct */ - #if defined(STIX_USE_PROCSTK) - /*STIX_ASSERT ((stix_oop_t)stix->processor != stix->_nil); - if ((stix_oop_t)stix->processor->active != stix->_nil)*/ - stix->processor->active->sp = STIX_SMOOI_TO_OOP(stix->sp); - #else - /* store the stack pointer to the active context */ - stix->active_context->sp = STIX_SMOOI_TO_OOP(stix->sp); - #endif + + STIX_ASSERT ((stix_oop_t)stix->processor != stix->_nil); + STIX_ASSERT ((stix_oop_t)stix->processor->active != stix->_nil); + /* store the stack pointer to the active process */ + stix->processor->active->sp = STIX_SMOOI_TO_OOP(stix->sp); /* store the instruction pointer to the active context */ stix->active_context->ip = STIX_SMOOI_TO_OOP(stix->ip); diff --git a/stix/lib/stix.h b/stix/lib/stix.h index bc616d8..8a4026e 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -33,9 +33,6 @@ /* TODO: move this macro out to the build files.... */ #define STIX_INCLUDE_COMPILER -/* define this to use the stack allocated inside process stack */ -#define STIX_USE_PROCSTK - /* 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. */ @@ -531,9 +528,11 @@ struct stix_context_t /* SmallInteger, instruction pointer */ stix_oop_t ip; - /* SmallInteger, stack pointer. - * For a method context, this pointer stores the stack pointer - * of the active process before it gets activated. */ + /* SmallInteger, stack pointer. the actual stack pointer is in the active + * process. For a method context, it stores the stack pointer of the active + * process before it gets activated. the stack pointer of the active + * process is restored using this value upon returning. This field is + * almost useless for a block context. */ stix_oop_t sp; /* SmallInteger. Number of temporaries. @@ -541,7 +540,6 @@ struct stix_context_t * defined its 'home'. */ stix_oop_t ntmprs; - /* CompiledMethod for a method context, * SmallInteger for a block context */ stix_oop_t method_or_nargs; @@ -862,27 +860,16 @@ struct stix_t #endif }; -#if defined(STIX_USE_PROCSTK) + /* TODO: stack bound check when pushing */ - #define STIX_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->processor->active->slot[(stix)->sp] = v; \ - } while (0) +#define STIX_STACK_PUSH(stix,v) \ + do { \ + (stix)->sp = (stix)->sp + 1; \ + (stix)->processor->active->slot[(stix)->sp] = v; \ + } while (0) - #define STIX_STACK_GET(stix,v_sp) ((stix)->processor->active->slot[v_sp]) - #define STIX_STACK_SET(stix,v_sp,v_obj) ((stix)->processor->active->slot[v_sp] = v_obj) - -#else - #define STIX_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->active_context->slot[(stix)->sp] = v; \ - } while (0) - - #define STIX_STACK_GET(stix,v_sp) ((stix)->active_context->slot[v_sp]) - #define STIX_STACK_SET(stix,v_sp,v_obj) ((stix)->active_context->slot[v_sp] = v_obj) -#endif +#define STIX_STACK_GET(stix,v_sp) ((stix)->processor->active->slot[v_sp]) +#define STIX_STACK_SET(stix,v_sp,v_obj) ((stix)->processor->active->slot[v_sp] = v_obj) #define STIX_STACK_GETTOP(stix) STIX_STACK_GET(stix, (stix)->sp) #define STIX_STACK_SETTOP(stix,v_obj) STIX_STACK_SET(stix, (stix)->sp, v_obj) @@ -891,7 +878,6 @@ struct stix_t #define STIX_STACK_POPS(stix,count) ((stix)->sp = (stix)->sp - (count)) #define STIX_STACK_ISEMPTY(stix) ((stix)->sp <= -1) - /* ========================================================================= * STIX VM LOGGING * ========================================================================= */