added moo->igniting and attempted to allocate memory from permheap when it's 1.
relevant gc change is still pending
This commit is contained in:
parent
647edf3268
commit
e73c81e2b7
12
moo/lib/gc.c
12
moo/lib/gc.c
@ -583,15 +583,21 @@ int moo_ignite (moo_t* moo, moo_oow_t heapsz)
|
||||
moo->heap = moo_makeheap(moo, heapsz);
|
||||
if (!moo->heap) return -1;
|
||||
|
||||
moo->igniting = 1;
|
||||
moo->_nil = moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t));
|
||||
if (!moo->_nil) return -1;
|
||||
if (!moo->_nil) goto oops;
|
||||
|
||||
moo->_nil->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 1, 0, 0, 0);
|
||||
moo->_nil->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 1, 1, 0, 0, 0);
|
||||
moo->_nil->_size = 0;
|
||||
|
||||
if (ignite_1(moo) <= -1 || ignite_2(moo) <= -1 || ignite_3(moo)) return -1;
|
||||
if (ignite_1(moo) <= -1 || ignite_2(moo) <= -1 || ignite_3(moo)) goto oops;;
|
||||
|
||||
moo->igniting = 0;
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
moo->igniting = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
|
@ -26,8 +26,8 @@
|
||||
|
||||
#include "moo-prv.h"
|
||||
|
||||
#define MIN_HEAP_SIZE 65536 /* TODO: adjust this value? */
|
||||
#define PERM_SPACE_SIZE 2048 /* TODO: adjust perm space size depending on what's allocated in the permspace */
|
||||
#define MIN_HEAP_SIZE 65536 * 5 /* TODO: adjust this value? */
|
||||
#define PERM_SPACE_SIZE 65536 * 2 /* TODO: adjust perm space size depending on what's allocated in the permspace */
|
||||
|
||||
moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size)
|
||||
{
|
||||
|
@ -438,11 +438,12 @@ typedef enum moo_gcfin_t moo_gcfin_t;
|
||||
/* [NOTE] this macro doesn't check the range of the actual value.
|
||||
* make sure that the value of each bit fields given falls within the
|
||||
* possible range of the defined bits */
|
||||
#define MOO_OBJ_MAKE_FLAGS(t,u,e,k,m,g,r) ( \
|
||||
#define MOO_OBJ_MAKE_FLAGS(t,u,e,k,p,m,g,r) ( \
|
||||
(((moo_oow_t)(t)) << MOO_OBJ_FLAGS_TYPE_SHIFT) | \
|
||||
(((moo_oow_t)(u)) << MOO_OBJ_FLAGS_UNIT_SHIFT) | \
|
||||
(((moo_oow_t)(e)) << MOO_OBJ_FLAGS_EXTRA_SHIFT) | \
|
||||
(((moo_oow_t)(k)) << MOO_OBJ_FLAGS_KERNEL_SHIFT) | \
|
||||
(((moo_oow_t)(p)) << MOO_OBJ_FLAGS_PERM_SHIFT) | \
|
||||
(((moo_oow_t)(m)) << MOO_OBJ_FLAGS_MOVED_SHIFT) | \
|
||||
(((moo_oow_t)(g)) << MOO_OBJ_FLAGS_NGC_SHIFT) | \
|
||||
(((moo_oow_t)(r)) << MOO_OBJ_FLAGS_TRAILER_SHIFT) \
|
||||
@ -1410,7 +1411,9 @@ struct moo_t
|
||||
moo_ooch_t buf[MOO_ERRMSG_CAPA];
|
||||
moo_oow_t len;
|
||||
} errmsg;
|
||||
|
||||
int shuterr;
|
||||
int igniting;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -28,12 +28,18 @@
|
||||
|
||||
void* moo_allocbytes (moo_t* moo, moo_oow_t size)
|
||||
{
|
||||
moo_uint8_t* ptr;
|
||||
|
||||
#if defined(MOO_BUILD_DEBUG)
|
||||
if ((moo->option.trait & MOO_DEBUG_GC) && !(moo->option.trait & MOO_NOGC)) moo_gc (moo);
|
||||
#endif
|
||||
|
||||
if (MOO_UNLIKELY(moo->igniting))
|
||||
{
|
||||
/* you must increase the size of the permheap if this allocation fails */
|
||||
return (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->permspace, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
moo_uint8_t* ptr;
|
||||
ptr = (moo_uint8_t*)moo_allocheapspace(moo, &moo->heap->curspace, size);
|
||||
if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_NOGC))
|
||||
{
|
||||
@ -50,6 +56,7 @@ void* moo_allocbytes (moo_t* moo, moo_oow_t size)
|
||||
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size)
|
||||
{
|
||||
@ -69,7 +76,7 @@ moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size)
|
||||
hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
|
||||
if (!hdr) return MOO_NULL;
|
||||
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 0);
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, moo->igniting, 0, 0, 0);
|
||||
MOO_OBJ_SET_SIZE (hdr, size);
|
||||
MOO_OBJ_SET_CLASS (hdr, moo->_nil);
|
||||
|
||||
@ -91,7 +98,7 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_
|
||||
hdr = (moo_oop_oop_t)moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
|
||||
if (!hdr) return MOO_NULL;
|
||||
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 1);
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, moo->igniting, 0, 0, 1);
|
||||
MOO_OBJ_SET_SIZE (hdr, size);
|
||||
MOO_OBJ_SET_CLASS (hdr, moo->_nil);
|
||||
|
||||
@ -141,7 +148,7 @@ static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, mo
|
||||
if (!hdr) return MOO_NULL;
|
||||
}
|
||||
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(type, unit, extra, 0, 0, ngc, 0);
|
||||
hdr->_flags = MOO_OBJ_MAKE_FLAGS(type, unit, extra, 0, moo->igniting, 0, ngc, 0); /* TODO: review. ngc and perm flags seems to conflict with each other ... the diff is that ngc is malloc() and perm is allocated in the perm heap */
|
||||
hdr->_size = len;
|
||||
MOO_OBJ_SET_SIZE (hdr, len);
|
||||
MOO_OBJ_SET_CLASS (hdr, moo->_nil);
|
||||
|
Loading…
Reference in New Issue
Block a user