From 652f13246f857be60fdbaa30b1f23dfec9a2f1f5 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 26 Aug 2019 14:43:41 +0000 Subject: [PATCH] moved gcfin_should_exit from Processor to System --- moo/kernel/Process.moo | 2 +- moo/kernel/System.moo | 21 ++++++++++++++------- moo/lib/exec.c | 2 +- moo/lib/gc.c | 3 +-- moo/lib/moo.h | 3 +-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/moo/kernel/Process.moo b/moo/kernel/Process.moo index e5d9882..3052c82 100644 --- a/moo/kernel/Process.moo +++ b/moo/kernel/Process.moo @@ -421,7 +421,7 @@ class SemaphoreHeap(Object) class(#final,#limited) ProcessScheduler(Object) { - var(#get) active, gcfin_should_exit := false, total_count := 0. + var(#get) active, total_count := 0. var(#get) runnable_count := 0. var runnable_head, runnable_tail. var(#get) suspended_count := 0. diff --git a/moo/kernel/System.moo b/moo/kernel/System.moo index 39196b0..b5927b6 100644 --- a/moo/kernel/System.moo +++ b/moo/kernel/System.moo @@ -11,6 +11,8 @@ class System(Apex) { var(#class) asyncsg. + var(#class) gcfin_sem. + var(#class) gcfin_should_exit := false. pooldic Log { @@ -74,12 +76,13 @@ class System(Apex) method(#class) __gc_finalizer { - | tmp gc gcfin_sem | + | tmp gc | gc := false. - gcfin_sem := Semaphore new. - gcfin_sem signalOnGCFin. // tell VM to signal this semaphore when it schedules gc finalization. + self.gcfin_should_exit := false. + self.gcfin_sem := Semaphore new. + self.gcfin_sem signalOnGCFin. // tell VM to signal this semaphore when it schedules gc finalization. [ while (true) @@ -95,7 +98,8 @@ class System(Apex) }. //if (Processor total_count == 1) - if (Processor gcfin_should_exit) + //if (Processor gcfin_should_exit) + if (self.gcfin_should_exit) { // exit from this loop when there are no other processes running except this finalizer process if (gc) @@ -113,10 +117,10 @@ class System(Apex) gc := false. }. - gcfin_sem wait. + self.gcfin_sem wait. } ] ensure: [ - gcfin_sem unsignal. + self.gcfin_sem unsignal. System logNl: 'End of GC finalization process ' & (thisProcess id) asString. ]. } @@ -172,9 +176,12 @@ class System(Apex) /* TODO: end redo */ caller terminate. - (Processor _processById: 1) resume. //<---- i shouldn't do ths. but, this system causes VM assertion failure. fix it.... System logNl: '>>>>End of OS signal handler process ' & (thisProcess id) asString. + + //(Processor _processById: 1) resume. //<---- i shouldn't do ths. but, this system causes VM assertion failure. fix it.... + self.gcfin_should_exit := true. + self.gcfin_sem signal. // wake the gcfin process. ]. } diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 331d462..356c595 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -4900,7 +4900,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) { MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); MOO_ASSERT (moo, proc == moo->processor->runnable.first); - moo->processor->gcfin_should_exit = moo->_true; /* prepare to inform the gc finalizer process */ + moo->_system->cvar[2] = moo->_true; /* set gcfin_should_exit in System to true. if the postion of the class variable changes, the index must get changed, too. */ switch_to_process_from_nil (moo, proc); /* sechedule the gc finalizer process */ } } diff --git a/moo/lib/gc.c b/moo/lib/gc.c index 2065735..6d75762 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -397,7 +397,7 @@ static kernel_class_info_t kernel_classes[] = { 6, { 'S','y','s','t','e','m' }, 0, - 1, /* asyncsg */ + 3, /* asyncsg, gcfin_sem, gcfin_should_exit*/ 0, 0, MOO_OBJ_TYPE_OOP, @@ -552,7 +552,6 @@ static int ignite_2 (moo_t* moo) if (!tmp) return -1; moo->processor = (moo_oop_process_scheduler_t)tmp; moo->processor->active = moo->nil_process; - moo->processor->gcfin_should_exit = moo->_false; moo->processor->total_count = MOO_SMOOI_TO_OOP(0); moo->processor->runnable.count = MOO_SMOOI_TO_OOP(0); moo->processor->suspended.count = MOO_SMOOI_TO_OOP(0); diff --git a/moo/lib/moo.h b/moo/lib/moo.h index bfa068b..ef42b72 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -866,14 +866,13 @@ struct moo_semaphore_group_t moo_oop_t sem_count; /* the total number of semaphores in the group */ }; -#define MOO_PROCESS_SCHEDULER_NAMED_INSTVARS 9 +#define MOO_PROCESS_SCHEDULER_NAMED_INSTVARS 8 typedef struct moo_process_scheduler_t moo_process_scheduler_t; typedef struct moo_process_scheduler_t* moo_oop_process_scheduler_t; struct moo_process_scheduler_t { MOO_OBJ_HEADER; moo_oop_process_t active; /* pointer to an active process in the runnable process list */ - moo_oop_t gcfin_should_exit; /* Boolean */ moo_oop_t total_count; /* SmallIntger, total number of processes - runnable/running/suspended */ struct