improved gcfin handling a bit

attempted to use XLoadFontSet in the x11 plugin experimentally
This commit is contained in:
hyunghwan.chung
2017-07-27 08:32:16 +00:00
parent a46113abad
commit e65912ae72
11 changed files with 189 additions and 85 deletions

View File

@@ -1945,7 +1945,9 @@ retry:
break;
}
MOO_DEBUG3 (moo, "TOKEN: [%.*js] %d\n", (moo_ooi_t)moo->c->tok.name.len, moo->c->tok.name.ptr, (int)moo->c->tok.type);
#if defined(MOO_DEBUG_LEXER)
MOO_DEBUG3 (moo, "TOKEN: [%.*js] %d\n", (moo_ooi_t)moo->c->tok.name.len, moo->c->tok.name.ptr, (int)moo->c->tok.type);
#endif
return 0;
}

View File

@@ -4537,11 +4537,12 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo)
* having the following line causes to skip firing the
* timed semaphore that would expire between now and the
* moment the next inspection occurs. */
if (moo->processor->active != moo->nil_process) goto finalization;
if (moo->processor->active != moo->nil_process) goto switch_to_next;
}
else
{
/* no running process, no io semaphore */
if (moo->sem_gcfin != moo->_nil && moo->sem_gcfin_sigreq) goto signal_sem_gcfin;
vm_sleep (moo, &ft);
}
vm_gettime (moo, &now);
@@ -4576,11 +4577,14 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo)
}
}
if (moo->sem_gcfin_sigreq)
if ((moo_oop_t)moo->sem_gcfin != moo->_nil)
{
if ((moo_oop_t)moo->sem_gcfin != moo->_nil)
moo_oop_process_t proc;
if (moo->sem_gcfin_sigreq)
{
moo_oop_process_t proc;
signal_sem_gcfin:
MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signalled GCFIN semaphore\n");
proc = signal_semaphore (moo, moo->sem_gcfin);
@@ -4590,24 +4594,47 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo)
MOO_ASSERT (moo, proc == moo->processor->runnable.first);
switch_to_process_from_nil (moo, proc);
}
moo->sem_gcfin_sigreq = 0;
}
moo->sem_gcfin_sigreq = 0;
}
else
{
if ((moo_oop_t)moo->sem_gcfin != moo->_nil && moo->processor->active == moo->nil_process)
else
{
moo_oop_process_t proc;
proc = signal_semaphore (moo, moo->sem_gcfin);
if ((moo_oop_t)proc != moo->_nil)
/* the gcfin semaphore signalling is not requested and there are
* no runnable processes nor no waiting semaphores. if there is
* process waiting on the gcfin semaphore, i will just schedule
* it to run */
/* TODO: check if this is the best implementation practice */
if (moo->processor->active == moo->nil_process)
{
MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE));
MOO_ASSERT (moo, proc == moo->processor->runnable.first);
switch_to_process_from_nil (moo, proc);
MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Signalled GCFIN semaphore without gcfin signal request\n");
proc = signal_semaphore (moo, moo->sem_gcfin);
if ((moo_oop_t)proc != moo->_nil)
{
MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE));
MOO_ASSERT (moo, proc == moo->processor->runnable.first);
switch_to_process_from_nil (moo, proc);
}
}
}
}
#if 0
while (moo->sem_list_count > 0)
{
/* handle async signals */
--moo->sem_list_count;
signal_semaphore (moo, moo->sem_list[moo->sem_list_count]);
if (moo->processor->active == moo->nil_process)
{
}
}
/*
if (semaphore heap has pending request)
{
signal them...
}*/
#endif
if (moo->processor->active == moo->nil_process)
{
/* no more waiting semaphore and no more process */
@@ -4616,21 +4643,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo)
return 0;
}
finalization:
#if 0
while (moo->sem_list_count > 0)
{
/* handle async signals */
--moo->sem_list_count;
signal_semaphore (moo, moo->sem_list[moo->sem_list_count]);
}
#endif
/*
if (semaphore heap has pending request)
{
signal them...
}*/
switch_to_next:
/* TODO: implement different process switching scheme - time-slice or clock based??? */
#if defined(MOO_EXTERNAL_PROCESS_SWITCH)
if (!moo->proc_switched && moo->switch_proc) { switch_to_next_runnable_process (moo); }

View File

@@ -118,7 +118,7 @@ static kernel_class_info_t kernel_classes[] =
};
static void move_finalizable_objects (moo_t* moo);
static moo_oow_t move_finalizable_objects (moo_t* moo);
/* -----------------------------------------------------------------------
* BOOTSTRAPPER
@@ -630,6 +630,7 @@ void moo_gc (moo_t* moo)
moo_oop_t old_nil;
moo_oow_t i;
moo_cb_t* cb;
moo_oow_t gcfin_count;
if (moo->active_context)
{
@@ -712,10 +713,11 @@ void moo_gc (moo_t* moo)
/* scan the new heap to move referenced objects */
scan_ptr = scan_new_heap (moo, scan_ptr);
/* FINALIZATION */
move_finalizable_objects (moo);
/* check finalizable objects registered and scan the heap again.
* symbol table compation is placed after this phase assuming that
* no symbol is added to be finalized. */
gcfin_count = move_finalizable_objects (moo);
scan_ptr = scan_new_heap (moo, scan_ptr);
/* END FINALIZATION */
/* traverse the symbol table for unreferenced symbols.
* if the symbol has not moved to the new heap, the symbol
@@ -760,8 +762,7 @@ void moo_gc (moo_t* moo)
*/
if (moo->active_method) SET_ACTIVE_METHOD_CODE (moo); /* update moo->active_code */
/*if (moo->sem_gcfin_count > 0) signal_semaphore (moo, moo->sem_gcfin);*/
if (moo->sem_gcfin_count > 0) moo->sem_gcfin_sigreq = 1;
if (gcfin_count > 0) moo->sem_gcfin_sigreq = 1;
/* TODO: include some gc statstics like number of live objects, gc performance, etc */
MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO,
@@ -878,11 +879,11 @@ int moo_deregfinalizable (moo_t* moo, moo_oop_t oop)
return -1;
}
static void move_finalizable_objects (moo_t* moo)
static moo_oow_t move_finalizable_objects (moo_t* moo)
{
moo_finalizable_t* x, * y;
moo_oow_t count = 0;
moo->sem_gcfin_count = 0;
for (x = moo->collectable.first; x; x = x->next)
{
MOO_ASSERT (moo, (MOO_OBJ_GET_FLAGS_GCFIN(x->oop) & (MOO_GCFIN_FINALIZABLE | MOO_GCFIN_FINALIZED)) == MOO_GCFIN_FINALIZABLE);
@@ -914,7 +915,7 @@ static void move_finalizable_objects (moo_t* moo)
/* add it to the collectable list */
MOO_APPEND_TO_LIST (&moo->collectable, x);
moo->sem_gcfin_count++;
count++;
}
else
{
@@ -923,4 +924,6 @@ static void move_finalizable_objects (moo_t* moo)
x = y;
}
return count;
}

View File

@@ -31,6 +31,7 @@
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <locale.h>
#if !defined(__DOS__)
# define USE_THREAD
@@ -1758,6 +1759,8 @@ int main (int argc, char* argv[])
}
#endif
setlocale (LC_ALL, "");
memset (&vmprim, 0, MOO_SIZEOF(vmprim));
vmprim.dl_open = dl_open;
vmprim.dl_close = dl_close;

View File

@@ -47,6 +47,7 @@
#if !defined(NDEBUG)
/* this is for gc debugging */
#define MOO_DEBUG_GC
/*#define MOO_DEBUG_LEXER*/
#define MOO_DEBUG_COMPILER
/*#define MOO_DEBUG_VM_PROCESSOR*/
/*#define MOO_DEBUG_VM_EXEC*/

View File

@@ -386,9 +386,13 @@ void moo_freemem (moo_t* moo, void* ptr)
#if defined(MOO_ENABLE_STATIC_MODULE)
#include "../mod/console.h"
#include "../mod/_ffi.h"
#if defined(MOO_ENABLE_MOD_FFI)
# include "../mod/_ffi.h"
#endif
#include "../mod/_stdio.h"
#include "../mod/_x11.h"
#if defined(MOO_ENABLE_MOD_X11)
# include "../mod/_x11.h"
#endif
static struct
{

View File

@@ -1175,7 +1175,6 @@ struct moo_t
/* semaphore to notify finalizable objects */
moo_oop_semaphore_t sem_gcfin;
int sem_gcfin_sigreq;
moo_oow_t sem_gcfin_count;
moo_oop_t* tmp_stack[256]; /* stack for temporaries */
moo_oow_t tmp_count;