moving heap creation to moo_ignite() from moo_init()

This commit is contained in:
hyunghwan.chung 2018-11-30 10:33:17 +00:00
parent 460a10a4c1
commit 4de478a9cc
6 changed files with 25 additions and 26 deletions

View File

@ -575,10 +575,18 @@ static int ignite_3 (moo_t* moo)
return 0;
}
int moo_ignite (moo_t* moo)
int moo_ignite (moo_t* moo, moo_oow_t heapsz)
{
MOO_ASSERT (moo, moo->_nil == MOO_NULL);
/*moo->permheap = moo_makeheap (moo, what is the best size???);
if (!moo->permheap) goto oops; */
if (moo->curheap) moo_killheap (moo, moo->curheap);
if (moo->newheap) moo_killheap (moo, moo->newheap);
moo->curheap = moo_makeheap(moo, heapsz);
moo->newheap = moo_makeheap(moo, heapsz);
if (!moo->curheap || !moo->newheap) return -1;
moo->_nil = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t));
if (!moo->_nil) return -1;

View File

@ -77,6 +77,7 @@ int main (int argc, char* argv[])
moo_oocs_t objname;
moo_oocs_t mthname;
moo_oow_t memsize;
int i, xret;
moo_bci_t c;
@ -122,9 +123,10 @@ int main (int argc, char* argv[])
memset (&cfg, 0, MOO_SIZEOF(cfg));
cfg.type = MOO_CFGSTD_OPTB;
cfg.memsize = MIN_MEMSIZE;
cfg.cmgr = moo_get_utf8_cmgr();
memsize = MIN_MEMSIZE;
while ((c = moo_getbopt(argc, argv, &opt)) != MOO_BCI_EOF)
{
switch (c)
@ -134,8 +136,8 @@ int main (int argc, char* argv[])
break;
case 'm':
cfg.memsize = strtoul(opt.arg, MOO_NULL, 0);
if (cfg.memsize <= MIN_MEMSIZE) cfg.memsize = MIN_MEMSIZE;
memsize = strtoul(opt.arg, MOO_NULL, 0);
if (memsize <= MIN_MEMSIZE) memsize = MIN_MEMSIZE;
break;
case '\0':
@ -221,7 +223,7 @@ int main (int argc, char* argv[])
moo_setoption (moo, MOO_LOG_MASK, &bm);
}
if (moo_ignite(moo) <= -1)
if (moo_ignite(moo, memsize) <= -1)
{
moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo));
moo_close (moo);

View File

@ -15,7 +15,6 @@ struct moo_cfgstd_t
{
moo_cfgstd_type_t type;
moo_oow_t memsize;
int large_pages;
moo_cmgr_t* cmgr;

View File

@ -26,7 +26,7 @@
#include "moo-prv.h"
moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_oow_t heapsize, moo_cmgr_t* cmgr, const moo_vmprim_t* vmprim, moo_errinf_t* errinfo)
moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_cmgr_t* cmgr, const moo_vmprim_t* vmprim, moo_errinf_t* errinfo)
{
moo_t* moo;
@ -36,7 +36,7 @@ moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_oow_t heapsize, moo_cm
moo = (moo_t*)MOO_MMGR_ALLOC(mmgr, MOO_SIZEOF(*moo) + xtnsize);
if (moo)
{
if (moo_init(moo, mmgr, heapsize, cmgr, vmprim) <= -1)
if (moo_init(moo, mmgr, cmgr, vmprim) <= -1)
{
if (errinfo) moo_geterrinf (moo, errinfo);
MOO_MMGR_FREE (mmgr, moo);
@ -98,7 +98,7 @@ static void free_heap (moo_t* moo, void* ptr)
MOO_MMGR_FREE(moo->mmgr, ptr);
}
int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_oow_t heapsz, moo_cmgr_t* cmgr, const moo_vmprim_t* vmprim)
int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_cmgr_t* cmgr, const moo_vmprim_t* vmprim)
{
int modtab_inited = 0;
@ -148,22 +148,11 @@ int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_oow_t heapsz, moo_cmgr_t* cmgr,
moo->proc_map_free_first = -1;
moo->proc_map_free_last = -1;
/* TODO: introduce a permanent heap */
/*moo->permheap = moo_makeheap (moo, what is the best size???);
if (!moo->permheap) goto oops; */
moo->curheap = moo_makeheap (moo, heapsz);
if (!moo->curheap) goto oops;
moo->newheap = moo_makeheap (moo, heapsz);
if (!moo->newheap) goto oops;
if (moo->vmprim.dl_startup) moo->vmprim.dl_startup (moo);
return 0;
oops:
if (modtab_inited) moo_rbt_fini (&moo->modtab);
if (moo->newheap) moo_killheap (moo, moo->newheap);
if (moo->curheap) moo_killheap (moo, moo->curheap);
if (moo->permheap) moo_killheap (moo, moo->permheap);
if (moo->log.ptr) moo_freemem (moo, moo->log.ptr);
moo->log.capa = 0;
return -1;
@ -256,8 +245,10 @@ void moo_fini (moo_t* moo)
/* TOOD: persistency? storing objects to image file? */
moo_killheap (moo, moo->newheap);
moo_killheap (moo, moo->curheap);
/* if the moo object is closed without moo_ignite(),
* the heap may not exist */
if (moo->newheap) moo_killheap (moo, moo->newheap);
if (moo->curheap) moo_killheap (moo, moo->curheap);
if (moo->permheap) moo_killheap (moo, moo->permheap);
for (i = 0; i < MOO_COUNTOF(moo->sbuf); i++)

View File

@ -1831,7 +1831,6 @@ extern "C" {
MOO_EXPORT moo_t* moo_open (
moo_mmgr_t* mmgr,
moo_oow_t xtnsize,
moo_oow_t heapsize,
moo_cmgr_t* cmgr,
const moo_vmprim_t* vmprim,
moo_errinf_t* errinfo
@ -1844,7 +1843,6 @@ MOO_EXPORT void moo_close (
MOO_EXPORT int moo_init (
moo_t* moo,
moo_mmgr_t* mmgr,
moo_oow_t heapsize,
moo_cmgr_t* cmgr,
const moo_vmprim_t* vmprim
);
@ -2017,7 +2015,8 @@ MOO_EXPORT moo_oop_t moo_shallowcopy (
* The moo_ignite() function creates key initial objects.
*/
MOO_EXPORT int moo_ignite (
moo_t* moo
moo_t* moo,
moo_oow_t memsize
);
/**

View File

@ -3580,7 +3580,7 @@ static void fini_moo (moo_t* moo)
vmprim.vm_muxwait = vm_muxwait;
vmprim.vm_sleep = vm_sleep;
moo = moo_open(&sys_mmgr, MOO_SIZEOF(xtn_t) + xtnsize, cfg->memsize,
moo = moo_open(&sys_mmgr, MOO_SIZEOF(xtn_t) + xtnsize,
(cfg->cmgr? cfg->cmgr: moo_get_utf8_cmgr()), &vmprim, errinfo);
if (!moo) return MOO_NULL;