moved gcfin_should_exit from Processor to System

This commit is contained in:
hyunghwan.chung 2019-08-26 14:43:41 +00:00
parent 87cf4f4b6a
commit 652f13246f
5 changed files with 18 additions and 13 deletions

View File

@ -421,7 +421,7 @@ class SemaphoreHeap(Object)
class(#final,#limited) ProcessScheduler(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(#get) runnable_count := 0.
var runnable_head, runnable_tail. var runnable_head, runnable_tail.
var(#get) suspended_count := 0. var(#get) suspended_count := 0.

View File

@ -11,6 +11,8 @@
class System(Apex) class System(Apex)
{ {
var(#class) asyncsg. var(#class) asyncsg.
var(#class) gcfin_sem.
var(#class) gcfin_should_exit := false.
pooldic Log pooldic Log
{ {
@ -74,12 +76,13 @@ class System(Apex)
method(#class) __gc_finalizer method(#class) __gc_finalizer
{ {
| tmp gc gcfin_sem | | tmp gc |
gc := false. 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) while (true)
@ -95,7 +98,8 @@ class System(Apex)
}. }.
//if (Processor total_count == 1) //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 // exit from this loop when there are no other processes running except this finalizer process
if (gc) if (gc)
@ -113,10 +117,10 @@ class System(Apex)
gc := false. gc := false.
}. }.
gcfin_sem wait. self.gcfin_sem wait.
} }
] ensure: [ ] ensure: [
gcfin_sem unsignal. self.gcfin_sem unsignal.
System logNl: 'End of GC finalization process ' & (thisProcess id) asString. System logNl: 'End of GC finalization process ' & (thisProcess id) asString.
]. ].
} }
@ -172,9 +176,12 @@ class System(Apex)
/* TODO: end redo */ /* TODO: end redo */
caller terminate. 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. 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.
]. ].
} }

View File

@ -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->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE));
MOO_ASSERT (moo, proc == moo->processor->runnable.first); 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 */ switch_to_process_from_nil (moo, proc); /* sechedule the gc finalizer process */
} }
} }

View File

@ -397,7 +397,7 @@ static kernel_class_info_t kernel_classes[] =
{ 6, { 6,
{ 'S','y','s','t','e','m' }, { 'S','y','s','t','e','m' },
0, 0,
1, /* asyncsg */ 3, /* asyncsg, gcfin_sem, gcfin_should_exit*/
0, 0,
0, 0,
MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_OOP,
@ -552,7 +552,6 @@ static int ignite_2 (moo_t* moo)
if (!tmp) return -1; if (!tmp) return -1;
moo->processor = (moo_oop_process_scheduler_t)tmp; moo->processor = (moo_oop_process_scheduler_t)tmp;
moo->processor->active = moo->nil_process; moo->processor->active = moo->nil_process;
moo->processor->gcfin_should_exit = moo->_false;
moo->processor->total_count = MOO_SMOOI_TO_OOP(0); moo->processor->total_count = MOO_SMOOI_TO_OOP(0);
moo->processor->runnable.count = MOO_SMOOI_TO_OOP(0); moo->processor->runnable.count = MOO_SMOOI_TO_OOP(0);
moo->processor->suspended.count = MOO_SMOOI_TO_OOP(0); moo->processor->suspended.count = MOO_SMOOI_TO_OOP(0);

View File

@ -866,14 +866,13 @@ struct moo_semaphore_group_t
moo_oop_t sem_count; /* the total number of semaphores in the group */ 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_process_scheduler_t;
typedef struct moo_process_scheduler_t* moo_oop_process_scheduler_t; typedef struct moo_process_scheduler_t* moo_oop_process_scheduler_t;
struct moo_process_scheduler_t struct moo_process_scheduler_t
{ {
MOO_OBJ_HEADER; MOO_OBJ_HEADER;
moo_oop_process_t active; /* pointer to an active process in the runnable process list */ 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 */ moo_oop_t total_count; /* SmallIntger, total number of processes - runnable/running/suspended */
struct struct