changed moo_makeheap() a bit
added the PERM bit to the object header
This commit is contained in:
parent
29b19e10b3
commit
647edf3268
34
moo/lib/gc.c
34
moo/lib/gc.c
@ -406,7 +406,7 @@ static moo_oop_class_t alloc_kernel_class (moo_t* moo, int class_flags, moo_oow_
|
||||
{
|
||||
moo_oop_class_t c;
|
||||
|
||||
c = (moo_oop_class_t)moo_allocoopobj (moo, MOO_CLASS_NAMED_INSTVARS + num_classvars);
|
||||
c = (moo_oop_class_t)moo_allocoopobj(moo, MOO_CLASS_NAMED_INSTVARS + num_classvars);
|
||||
if (!c) return MOO_NULL;
|
||||
|
||||
MOO_OBJ_SET_FLAGS_KERNEL (c, MOO_OBJ_FLAGS_KERNEL_IMMATURE);
|
||||
@ -434,12 +434,12 @@ static int ignite_1 (moo_t* moo)
|
||||
* The instance of Class can have indexed instance variables
|
||||
* which are actually class variables.
|
||||
* -------------------------------------------------------------- */
|
||||
moo->_class = alloc_kernel_class (
|
||||
moo->_class = alloc_kernel_class(
|
||||
moo, kernel_classes[KCI_CLASS].class_flags,
|
||||
kernel_classes[KCI_CLASS].class_num_classvars,
|
||||
MOO_CLASS_SPEC_MAKE (kernel_classes[KCI_CLASS].class_spec_named_instvars,
|
||||
kernel_classes[KCI_CLASS].class_spec_flags,
|
||||
kernel_classes[KCI_CLASS].class_spec_indexed_type));
|
||||
MOO_CLASS_SPEC_MAKE(kernel_classes[KCI_CLASS].class_spec_named_instvars,
|
||||
kernel_classes[KCI_CLASS].class_spec_flags,
|
||||
kernel_classes[KCI_CLASS].class_spec_indexed_type));
|
||||
if (!moo->_class) return -1;
|
||||
|
||||
MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(moo->_class) == MOO_NULL);
|
||||
@ -451,12 +451,12 @@ static int ignite_1 (moo_t* moo)
|
||||
|
||||
if (i == KCI_CLASS) continue; /* skip Class as it's created above */
|
||||
|
||||
tmp = alloc_kernel_class (
|
||||
tmp = alloc_kernel_class(
|
||||
moo, kernel_classes[i].class_flags,
|
||||
kernel_classes[i].class_num_classvars,
|
||||
MOO_CLASS_SPEC_MAKE (kernel_classes[i].class_spec_named_instvars,
|
||||
kernel_classes[i].class_spec_flags,
|
||||
kernel_classes[i].class_spec_indexed_type));
|
||||
MOO_CLASS_SPEC_MAKE(kernel_classes[i].class_spec_named_instvars,
|
||||
kernel_classes[i].class_spec_flags,
|
||||
kernel_classes[i].class_spec_indexed_type));
|
||||
if (!tmp) return -1;
|
||||
*(moo_oop_class_t*)((moo_uint8_t*)moo + kernel_classes[i].offset) = tmp;
|
||||
}
|
||||
@ -542,7 +542,7 @@ static int ignite_3 (moo_t* moo)
|
||||
|
||||
for (i = 0; i < MOO_COUNTOF(kernel_classes); i++)
|
||||
{
|
||||
sym = moo_makesymbol (moo, kernel_classes[i].name, kernel_classes[i].len);
|
||||
sym = moo_makesymbol(moo, kernel_classes[i].name, kernel_classes[i].len);
|
||||
if (!sym) return -1;
|
||||
|
||||
cls = *(moo_oop_class_t*)((moo_uint8_t*)moo + kernel_classes[i].offset);
|
||||
@ -560,15 +560,15 @@ static int ignite_3 (moo_t* moo)
|
||||
moo->sysdic->nsup = (moo_oop_t)moo->_system;
|
||||
|
||||
/* Make the process scheduler avaialble as the global name 'Processor' */
|
||||
sym = moo_makesymbol (moo, str_processor, MOO_COUNTOF(str_processor));
|
||||
sym = moo_makesymbol(moo, str_processor, MOO_COUNTOF(str_processor));
|
||||
if (!sym) return -1;
|
||||
if (!moo_putatsysdic(moo, sym, (moo_oop_t)moo->processor)) return -1;
|
||||
|
||||
sym = moo_makesymbol (moo, str_dicnew, MOO_COUNTOF(str_dicnew));
|
||||
sym = moo_makesymbol(moo, str_dicnew, MOO_COUNTOF(str_dicnew));
|
||||
if (!sym) return -1;
|
||||
moo->dicnewsym = (moo_oop_char_t)sym;
|
||||
|
||||
sym = moo_makesymbol (moo, str_dicputassoc, MOO_COUNTOF(str_dicputassoc));
|
||||
sym = moo_makesymbol(moo, str_dicputassoc, MOO_COUNTOF(str_dicputassoc));
|
||||
if (!sym) return -1;
|
||||
moo->dicputassocsym = (moo_oop_char_t)sym;
|
||||
|
||||
@ -586,7 +586,7 @@ int moo_ignite (moo_t* moo, moo_oow_t heapsz)
|
||||
moo->_nil = moo_allocbytes(moo, MOO_SIZEOF(moo_obj_t));
|
||||
if (!moo->_nil) return -1;
|
||||
|
||||
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, 0, 0, 0);
|
||||
moo->_nil->_size = 0;
|
||||
|
||||
if (ignite_1(moo) <= -1 || ignite_2(moo) <= -1 || ignite_3(moo)) return -1;
|
||||
@ -712,6 +712,8 @@ moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop)
|
||||
|
||||
if (!MOO_OOP_IS_POINTER(oop)) return oop;
|
||||
|
||||
if (MOO_OBJ_GET_FLAGS_PERM(oop)) return oop;
|
||||
|
||||
if (MOO_OBJ_GET_FLAGS_MOVED(oop))
|
||||
{
|
||||
/* this object has migrated to the new heap.
|
||||
@ -725,7 +727,7 @@ moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop)
|
||||
moo_oow_t nbytes_aligned;
|
||||
moo_oop_t tmp;
|
||||
|
||||
nbytes_aligned = get_payload_bytes (moo, oop);
|
||||
nbytes_aligned = get_payload_bytes(moo, oop);
|
||||
|
||||
/* allocate space in the new heap */
|
||||
tmp = moo_allocheapspace(moo, &moo->heap->newspace, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
|
||||
@ -743,7 +745,7 @@ moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop)
|
||||
MOO_MEMCPY (tmp, oop, MOO_SIZEOF(moo_obj_t) + nbytes_aligned);
|
||||
|
||||
/* mark the old object that it has migrated to the new heap */
|
||||
MOO_OBJ_SET_FLAGS_MOVED(oop, 1);
|
||||
MOO_OBJ_SET_FLAGS_MOVED (oop, 1);
|
||||
|
||||
/* let the class field of the old object point to the new
|
||||
* object allocated in the new heap. it is returned in
|
||||
|
@ -32,12 +32,11 @@
|
||||
moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size)
|
||||
{
|
||||
moo_heap_t* heap;
|
||||
moo_oow_t half_size;
|
||||
moo_oow_t space_size;
|
||||
|
||||
if (size < MIN_HEAP_SIZE) size = MIN_HEAP_SIZE;
|
||||
half_size = size / 2;
|
||||
|
||||
heap = (moo_heap_t*)moo->vmprim.alloc_heap(moo, MOO_SIZEOF(*heap) + PERM_SPACE_SIZE + size);
|
||||
heap = (moo_heap_t*)moo->vmprim.alloc_heap(moo, MOO_SIZEOF(*heap) + size);
|
||||
if (!heap)
|
||||
{
|
||||
const moo_ooch_t* oldmsg = moo_backuperrmsg(moo);
|
||||
@ -49,20 +48,22 @@ moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size)
|
||||
heap->base = (moo_uint8_t*)(heap + 1);
|
||||
heap->size = size;
|
||||
|
||||
/* TODO: consider placing permspace in a separate memory allocated block in case we have to grow
|
||||
space_size = (size - PERM_SPACE_SIZE) / 2;
|
||||
|
||||
/* TODO: consider placing permspace in a separate memory chunk in case we have to grow
|
||||
* other spaces. we may be able to realloc() the entire heap region without affecting the separately
|
||||
* allocated block. */
|
||||
* allocated chunk. */
|
||||
heap->permspace.base = (moo_uint8_t*)(heap + 1);
|
||||
heap->permspace.ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)heap->permspace.base), MOO_SIZEOF(moo_oop_t));
|
||||
heap->permspace.limit = heap->permspace.base + PERM_SPACE_SIZE;
|
||||
|
||||
heap->curspace.base = heap->permspace.limit;
|
||||
heap->curspace.ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)heap->curspace.base), MOO_SIZEOF(moo_oop_t));
|
||||
heap->curspace.limit = heap->curspace.base + half_size;
|
||||
heap->curspace.limit = heap->curspace.base + space_size;
|
||||
|
||||
heap->newspace.base = heap->curspace.limit; /*(moo_uint8_t*)(heap + 1) + half_size;*/
|
||||
heap->newspace.base = heap->curspace.limit;
|
||||
heap->newspace.ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)heap->newspace.base), MOO_SIZEOF(moo_oop_t));
|
||||
heap->newspace.limit = heap->newspace.base + half_size;
|
||||
heap->newspace.limit = heap->newspace.base + space_size;
|
||||
|
||||
/* if size is too small, space.ptr may go past space.limit even at
|
||||
* this moment depending on the alignment of space.base. subsequent
|
||||
|
@ -380,6 +380,7 @@ typedef enum moo_gcfin_t moo_gcfin_t;
|
||||
#define MOO_OBJ_FLAGS_UNIT_BITS 5
|
||||
#define MOO_OBJ_FLAGS_EXTRA_BITS 1
|
||||
#define MOO_OBJ_FLAGS_KERNEL_BITS 2
|
||||
#define MOO_OBJ_FLAGS_PERM_BITS 1
|
||||
#define MOO_OBJ_FLAGS_MOVED_BITS 1
|
||||
#define MOO_OBJ_FLAGS_NGC_BITS 1
|
||||
#define MOO_OBJ_FLAGS_RDONLY_BITS 1
|
||||
@ -389,7 +390,8 @@ typedef enum moo_gcfin_t moo_gcfin_t;
|
||||
#define MOO_OBJ_FLAGS_TYPE_SHIFT (MOO_OBJ_FLAGS_UNIT_BITS + MOO_OBJ_FLAGS_UNIT_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_UNIT_SHIFT (MOO_OBJ_FLAGS_EXTRA_BITS + MOO_OBJ_FLAGS_EXTRA_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_EXTRA_SHIFT (MOO_OBJ_FLAGS_KERNEL_BITS + MOO_OBJ_FLAGS_KERNEL_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_KERNEL_SHIFT (MOO_OBJ_FLAGS_MOVED_BITS + MOO_OBJ_FLAGS_MOVED_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_KERNEL_SHIFT (MOO_OBJ_FLAGS_PERM_BITS + MOO_OBJ_FLAGS_PERM_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_PERM_SHIFT (MOO_OBJ_FLAGS_MOVED_BITS + MOO_OBJ_FLAGS_MOVED_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_MOVED_SHIFT (MOO_OBJ_FLAGS_NGC_BITS + MOO_OBJ_FLAGS_NGC_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_NGC_SHIFT (MOO_OBJ_FLAGS_RDONLY_BITS + MOO_OBJ_FLAGS_RDONLY_SHIFT)
|
||||
#define MOO_OBJ_FLAGS_RDONLY_SHIFT (MOO_OBJ_FLAGS_GCFIN_BITS + MOO_OBJ_FLAGS_GCFIN_SHIFT)
|
||||
@ -400,6 +402,7 @@ typedef enum moo_gcfin_t moo_gcfin_t;
|
||||
#define MOO_OBJ_GET_FLAGS_UNIT(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_UNIT_SHIFT, MOO_OBJ_FLAGS_UNIT_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_EXTRA(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_EXTRA_SHIFT, MOO_OBJ_FLAGS_EXTRA_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_KERNEL(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_PERM(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PERM_SHIFT, MOO_OBJ_FLAGS_PERM_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_MOVED(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_NGC(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS)
|
||||
#define MOO_OBJ_GET_FLAGS_RDONLY(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_RDONLY_SHIFT, MOO_OBJ_FLAGS_RDONLY_BITS)
|
||||
@ -410,6 +413,7 @@ typedef enum moo_gcfin_t moo_gcfin_t;
|
||||
#define MOO_OBJ_SET_FLAGS_UNIT(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_UNIT_SHIFT, MOO_OBJ_FLAGS_UNIT_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_EXTRA(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_EXTRA_SHIFT, MOO_OBJ_FLAGS_EXTRA_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_KERNEL(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_PERM(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_PERM_SHIFT, MOO_OBJ_FLAGS_PERM_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_MOVED(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_NGC(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS, v)
|
||||
#define MOO_OBJ_SET_FLAGS_RDONLY(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_RDONLY_SHIFT, MOO_OBJ_FLAGS_RDONLY_BITS, v)
|
||||
|
Loading…
Reference in New Issue
Block a user