2015-04-30 15:56:05 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2016-02-12 16:23:26 +00:00
|
|
|
Copyright (c) 2014-2016 Chung, Hyung-Hwan. All rights reserved.
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stix-prv.h"
|
|
|
|
|
2015-05-08 14:29:35 +00:00
|
|
|
static void compact_symbol_table (stix_t* stix, stix_oop_t _nil)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
2015-05-07 15:58:04 +00:00
|
|
|
stix_oop_char_t symbol;
|
2015-11-20 09:05:55 +00:00
|
|
|
stix_oow_t i, x, y, z;
|
|
|
|
stix_oow_t bucket_size, index;
|
|
|
|
stix_ooi_t tally;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
#if defined(STIX_SUPPORT_GC_DURING_IGNITION)
|
|
|
|
if (!stix->symtab) return; /* symbol table has not been created */
|
|
|
|
#endif
|
|
|
|
|
2015-11-20 09:05:55 +00:00
|
|
|
/* the symbol table doesn't allow more data items than STIX_SMOOI_MAX.
|
|
|
|
* so stix->symtab->tally must always be a small integer */
|
|
|
|
STIX_ASSERT (STIX_OOP_IS_SMOOI(stix->symtab->tally));
|
2015-11-12 06:57:35 +00:00
|
|
|
tally = STIX_OOP_TO_SMOOI(stix->symtab->tally);
|
2015-11-20 09:05:55 +00:00
|
|
|
STIX_ASSERT (tally >= 0); /* it must not be less than 0 */
|
2015-04-30 15:56:05 +00:00
|
|
|
if (tally <= 0) return;
|
|
|
|
|
2015-11-20 09:05:55 +00:00
|
|
|
/* NOTE: in theory, the bucket size can be greater than STIX_SMOOI_MAX
|
|
|
|
* as it is an internal header field and is of an unsigned type */
|
|
|
|
bucket_size = STIX_OBJ_GET_SIZE(stix->symtab->bucket);
|
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
for (index = 0; index < bucket_size; )
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
2015-05-07 15:58:04 +00:00
|
|
|
if (STIX_OBJ_GET_FLAGS_MOVED(stix->symtab->bucket->slot[index]))
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
|
|
|
index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
STIX_ASSERT (stix->symtab->bucket->slot[index] != _nil);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
for (i = 0, x = index, y = index; i < bucket_size; i++)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
2015-05-07 15:58:04 +00:00
|
|
|
y = (y + 1) % bucket_size;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* done if the slot at the current hash index is _nil */
|
2015-05-07 15:58:04 +00:00
|
|
|
if (stix->symtab->bucket->slot[y] == _nil) break;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* get the natural hash index for the data in the slot
|
|
|
|
* at the current hash index */
|
2015-05-07 15:58:04 +00:00
|
|
|
symbol = (stix_oop_char_t)stix->symtab->bucket->slot[y];
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
STIX_ASSERT (STIX_CLASSOF(stix,symbol) == stix->_symbol);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-10-28 14:58:58 +00:00
|
|
|
z = stix_hashchars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % bucket_size;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* move an element if necessary */
|
|
|
|
if ((y > x && (z <= x || z > y)) ||
|
|
|
|
(y < x && (z <= x && z > y)))
|
|
|
|
{
|
2015-05-07 15:58:04 +00:00
|
|
|
stix->symtab->bucket->slot[x] = stix->symtab->bucket->slot[y];
|
2015-04-30 15:56:05 +00:00
|
|
|
x = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
stix->symtab->bucket->slot[x] = _nil;
|
2015-04-30 15:56:05 +00:00
|
|
|
tally--;
|
|
|
|
}
|
|
|
|
|
2015-11-20 09:05:55 +00:00
|
|
|
STIX_ASSERT (tally >= 0);
|
2015-11-12 06:57:35 +00:00
|
|
|
STIX_ASSERT (tally <= STIX_SMOOI_MAX);
|
|
|
|
stix->symtab->tally = STIX_SMOOI_TO_OOP(tally);
|
2015-04-30 15:56:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 15:36:37 +00:00
|
|
|
|
|
|
|
static STIX_INLINE stix_oow_t get_payload_bytes (stix_t* stix, stix_oop_t oop)
|
|
|
|
{
|
|
|
|
stix_oow_t nbytes_aligned;
|
|
|
|
|
|
|
|
#if defined(STIX_USE_OBJECT_TRAILER)
|
|
|
|
if (STIX_OBJ_GET_FLAGS_TRAILER(oop))
|
|
|
|
{
|
|
|
|
stix_oow_t nbytes;
|
|
|
|
|
|
|
|
/* only an OOP object can have the trailer.
|
|
|
|
*
|
|
|
|
* | _flags |
|
|
|
|
* | _size | <-- if it's 3
|
|
|
|
* | _class |
|
|
|
|
* | X |
|
|
|
|
* | X |
|
|
|
|
* | X |
|
|
|
|
* | Y | <-- it may exist if EXTRA is set in _flags.
|
|
|
|
* | Z | <-- if TRAILER is set, it is the number of bytes in the trailer
|
|
|
|
* | | | | |
|
|
|
|
*/
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP);
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t));
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */
|
|
|
|
|
|
|
|
nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \
|
|
|
|
(stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)];
|
|
|
|
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
/* calculate the payload size in bytes */
|
|
|
|
nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t));
|
|
|
|
#if defined(STIX_USE_OBJECT_TRAILER)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return nbytes_aligned;
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:10:49 +00:00
|
|
|
stix_oop_t stix_moveoop (stix_t* stix, stix_oop_t oop)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
2015-05-07 15:58:04 +00:00
|
|
|
#if defined(STIX_SUPPORT_GC_DURING_IGNITION)
|
|
|
|
if (!oop) return oop;
|
|
|
|
#endif
|
|
|
|
|
2015-07-15 08:39:18 +00:00
|
|
|
if (!STIX_OOP_IS_POINTER(oop)) return oop;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-05-03 17:10:30 +00:00
|
|
|
if (STIX_OBJ_GET_FLAGS_MOVED(oop))
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
|
|
|
/* this object has migrated to the new heap.
|
|
|
|
* the class field has been updated to the new object
|
|
|
|
* in the 'else' block below. i can simply return it
|
|
|
|
* without further migration. */
|
2015-05-07 15:58:04 +00:00
|
|
|
return STIX_OBJ_GET_CLASS(oop);
|
2015-04-30 15:56:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-08 14:29:35 +00:00
|
|
|
stix_oow_t nbytes_aligned;
|
2015-04-30 15:56:05 +00:00
|
|
|
stix_oop_t tmp;
|
|
|
|
|
2015-10-30 15:36:37 +00:00
|
|
|
nbytes_aligned = get_payload_bytes (stix, oop);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* allocate space in the new heap */
|
2015-05-03 17:10:30 +00:00
|
|
|
tmp = stix_allocheapmem (stix, stix->newheap, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* allocation here must not fail because
|
|
|
|
* i'm allocating the new space in a new heap for
|
|
|
|
* moving an existing object in the current heap.
|
|
|
|
*
|
|
|
|
* assuming the new heap is as large as the old heap,
|
|
|
|
* and garbage collection doesn't allocate more objects
|
|
|
|
* than in the old heap, it must not fail. */
|
|
|
|
STIX_ASSERT (tmp != STIX_NULL);
|
|
|
|
|
|
|
|
/* copy the payload to the new object */
|
|
|
|
STIX_MEMCPY (tmp, oop, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
|
|
|
|
|
|
|
|
/* mark the old object that it has migrated to the new heap */
|
2015-05-03 17:10:30 +00:00
|
|
|
STIX_OBJ_SET_FLAGS_MOVED(oop, 1);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* let the class field of the old object point to the new
|
|
|
|
* object allocated in the new heap. it is returned in
|
|
|
|
* the 'if' block at the top of this function. */
|
2015-05-07 15:58:04 +00:00
|
|
|
STIX_OBJ_SET_CLASS (oop, tmp);
|
|
|
|
|
2015-04-30 15:56:05 +00:00
|
|
|
/* return the new object */
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr)
|
|
|
|
{
|
2016-02-12 16:23:26 +00:00
|
|
|
while (ptr < stix->newheap->ptr)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
|
|
|
stix_oow_t i;
|
2015-05-08 14:29:35 +00:00
|
|
|
stix_oow_t nbytes_aligned;
|
2015-04-30 15:56:05 +00:00
|
|
|
stix_oop_t oop;
|
|
|
|
|
|
|
|
oop = (stix_oop_t)ptr;
|
2015-07-01 15:01:39 +00:00
|
|
|
|
2016-02-15 18:13:26 +00:00
|
|
|
#if defined(STIX_USE_OBJECT_TRAILER)
|
2015-07-01 15:01:39 +00:00
|
|
|
if (STIX_OBJ_GET_FLAGS_TRAILER(oop))
|
|
|
|
{
|
|
|
|
stix_oow_t nbytes;
|
|
|
|
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP);
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t));
|
|
|
|
STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */
|
|
|
|
|
|
|
|
nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \
|
|
|
|
(stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)];
|
|
|
|
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-15 18:13:26 +00:00
|
|
|
#endif
|
2015-07-01 15:01:39 +00:00
|
|
|
nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t));
|
2016-02-15 18:13:26 +00:00
|
|
|
#if defined(STIX_USE_OBJECT_TRAILER)
|
2015-07-01 15:01:39 +00:00
|
|
|
}
|
2016-02-15 18:13:26 +00:00
|
|
|
#endif
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-05-25 17:10:49 +00:00
|
|
|
STIX_OBJ_SET_CLASS (oop, stix_moveoop(stix, STIX_OBJ_GET_CLASS(oop)));
|
2015-05-03 17:10:30 +00:00
|
|
|
if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
2015-06-11 09:11:18 +00:00
|
|
|
stix_oop_oop_t xtmp;
|
|
|
|
stix_oow_t size;
|
|
|
|
|
2016-02-15 18:13:26 +00:00
|
|
|
#if defined(STIX_USE_PROCSTK)
|
|
|
|
if (stix->_process && STIX_OBJ_GET_CLASS(oop) == stix->_process)
|
|
|
|
{
|
|
|
|
/* the stack in a process object doesn't need to be
|
|
|
|
* scanned in full. the slots above the stack pointer
|
|
|
|
* are garbages. */
|
|
|
|
size = STIX_PROCESS_NAMED_INSTVARS +
|
|
|
|
STIX_OOP_TO_SMOOI(((stix_oop_process_t)oop)->sp) + 1;
|
|
|
|
STIX_ASSERT (size <= STIX_OBJ_GET_SIZE(oop));
|
|
|
|
}
|
|
|
|
#else
|
2015-06-25 13:37:50 +00:00
|
|
|
if ((stix->_method_context && STIX_OBJ_GET_CLASS(oop) == stix->_method_context) ||
|
|
|
|
(stix->_block_context && STIX_OBJ_GET_CLASS(oop) == stix->_block_context))
|
2015-06-11 09:11:18 +00:00
|
|
|
{
|
2016-02-12 16:23:26 +00:00
|
|
|
/* the stack in a context object doesn't need to be
|
2015-06-21 16:22:50 +00:00
|
|
|
* scanned in full. the slots above the stack pointer
|
|
|
|
* are garbages. */
|
2015-06-11 09:11:18 +00:00
|
|
|
size = STIX_CONTEXT_NAMED_INSTVARS +
|
2015-11-12 06:57:35 +00:00
|
|
|
STIX_OOP_TO_SMOOI(((stix_oop_context_t)oop)->sp) + 1;
|
2016-02-12 16:23:26 +00:00
|
|
|
STIX_ASSERT (size <= STIX_OBJ_GET_SIZE(oop));
|
|
|
|
}
|
2016-02-15 18:13:26 +00:00
|
|
|
#endif
|
2015-06-11 09:11:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
size = STIX_OBJ_GET_SIZE(oop);
|
|
|
|
}
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
xtmp = (stix_oop_oop_t)oop;
|
2015-06-11 09:11:18 +00:00
|
|
|
for (i = 0; i < size; i++)
|
2015-04-30 15:56:05 +00:00
|
|
|
{
|
|
|
|
if (STIX_OOP_IS_POINTER(xtmp->slot[i]))
|
2015-05-25 17:10:49 +00:00
|
|
|
xtmp->slot[i] = stix_moveoop (stix, xtmp->slot[i]);
|
2015-04-30 15:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-07 15:58:04 +00:00
|
|
|
|
2016-02-12 16:23:26 +00:00
|
|
|
ptr = ptr + STIX_SIZEOF(stix_obj_t) + nbytes_aligned;
|
2015-04-30 15:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return the pointer to the beginning of the free space in the heap */
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stix_gc (stix_t* stix)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* move a referenced object to the new heap.
|
|
|
|
* inspect the fields of the moved object in the new heap.
|
|
|
|
* move objects pointed to by the fields to the new heap.
|
|
|
|
* finally perform some tricky symbol table clean-up.
|
|
|
|
*/
|
|
|
|
stix_uint8_t* ptr;
|
|
|
|
stix_heap_t* tmp;
|
2015-05-07 15:58:04 +00:00
|
|
|
stix_oop_t old_nil;
|
|
|
|
stix_oow_t i;
|
2015-05-25 17:10:49 +00:00
|
|
|
stix_cb_t* cb;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
2015-06-20 03:07:11 +00:00
|
|
|
if (stix->active_context)
|
2015-06-11 09:11:18 +00:00
|
|
|
{
|
|
|
|
/* TODO: verify if this is correct */
|
2016-02-12 16:23:26 +00:00
|
|
|
#if defined(STIX_USE_PROCSTK)
|
|
|
|
/*STIX_ASSERT ((stix_oop_t)stix->processor != stix->_nil);
|
|
|
|
if ((stix_oop_t)stix->processor->active != stix->_nil)*/
|
|
|
|
stix->processor->active->sp = STIX_SMOOI_TO_OOP(stix->sp);
|
|
|
|
#else
|
|
|
|
/* store the stack pointer to the active context */
|
2015-11-12 06:57:35 +00:00
|
|
|
stix->active_context->sp = STIX_SMOOI_TO_OOP(stix->sp);
|
2016-02-12 16:23:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* store the instruction pointer to the active context */
|
2015-11-12 06:57:35 +00:00
|
|
|
stix->active_context->ip = STIX_SMOOI_TO_OOP(stix->ip);
|
2015-06-11 09:11:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 16:23:26 +00:00
|
|
|
#if defined(STIX_DEBUG_GC_002)
|
|
|
|
printf ("STARTING GC curheap base %p ptr %p newheap base %p ptr %p\n",
|
|
|
|
stix->curheap->base, stix->curheap->ptr, stix->newheap->base, stix->newheap->ptr);
|
|
|
|
#endif
|
2015-04-30 15:56:05 +00:00
|
|
|
/* TODO: allocate common objects like _nil and the root dictionary
|
|
|
|
* in the permanant heap. minimize moving around */
|
2015-05-07 15:58:04 +00:00
|
|
|
old_nil = stix->_nil;
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* move _nil and the root object table */
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_nil = stix_moveoop (stix, stix->_nil);
|
|
|
|
stix->_true = stix_moveoop (stix, stix->_true);
|
|
|
|
stix->_false = stix_moveoop (stix, stix->_false);
|
2015-05-07 15:58:04 +00:00
|
|
|
|
2015-07-14 13:35:18 +00:00
|
|
|
stix->_apex = stix_moveoop (stix, stix->_apex);
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_class = stix_moveoop (stix, stix->_class);
|
2015-07-14 13:35:18 +00:00
|
|
|
stix->_undefined_object = stix_moveoop (stix, stix->_undefined_object);
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_object = stix_moveoop (stix, stix->_object);
|
|
|
|
stix->_array = stix_moveoop (stix, stix->_array);
|
2015-05-31 16:44:56 +00:00
|
|
|
stix->_byte_array = stix_moveoop (stix, stix->_byte_array);
|
2015-12-02 15:24:13 +00:00
|
|
|
|
2015-05-26 16:31:47 +00:00
|
|
|
stix->_string = stix_moveoop (stix, stix->_string);
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_symbol = stix_moveoop (stix, stix->_symbol);
|
|
|
|
stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set);
|
|
|
|
stix->_system_dictionary = stix_moveoop (stix, stix->_system_dictionary);
|
2015-07-10 14:06:07 +00:00
|
|
|
stix->_namespace = stix_moveoop (stix, stix->_namespace);
|
2015-07-14 13:35:18 +00:00
|
|
|
stix->_pool_dictionary = stix_moveoop (stix, stix->_pool_dictionary);
|
2015-05-28 16:51:37 +00:00
|
|
|
stix->_method_dictionary = stix_moveoop (stix, stix->_method_dictionary);
|
2015-05-31 16:44:56 +00:00
|
|
|
stix->_method = stix_moveoop (stix, stix->_method);
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_association = stix_moveoop (stix, stix->_association);
|
2015-06-25 13:37:50 +00:00
|
|
|
stix->_method_context = stix_moveoop (stix, stix->_method_context);
|
2015-06-04 18:34:37 +00:00
|
|
|
stix->_block_context = stix_moveoop (stix, stix->_block_context);
|
2016-02-18 17:49:56 +00:00
|
|
|
stix->_semaphore = stix_moveoop (stix, stix->_semaphore);
|
2015-10-14 14:01:33 +00:00
|
|
|
stix->_process = stix_moveoop (stix, stix->_process);
|
2015-10-15 14:40:08 +00:00
|
|
|
stix->_process_scheduler = stix_moveoop (stix, stix->_process_scheduler);
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->_true_class = stix_moveoop (stix, stix->_true_class);
|
|
|
|
stix->_false_class = stix_moveoop (stix, stix->_false_class);
|
|
|
|
stix->_character = stix_moveoop (stix, stix->_character);
|
2015-10-29 15:24:46 +00:00
|
|
|
|
|
|
|
stix->_small_integer = stix_moveoop (stix, stix->_small_integer);
|
|
|
|
stix->_large_positive_integer = stix_moveoop (stix, stix->_large_positive_integer);
|
|
|
|
stix->_large_negative_integer = stix_moveoop (stix, stix->_large_negative_integer);
|
2015-05-07 15:58:04 +00:00
|
|
|
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->sysdic = (stix_oop_set_t) stix_moveoop (stix, (stix_oop_t)stix->sysdic);
|
2015-10-22 02:47:25 +00:00
|
|
|
stix->processor = (stix_oop_process_scheduler_t) stix_moveoop (stix, (stix_oop_t)stix->processor);
|
2016-02-12 16:23:26 +00:00
|
|
|
stix->nil_process = (stix_oop_process_t) stix_moveoop (stix, (stix_oop_t)stix->nil_process);
|
2015-05-07 15:58:04 +00:00
|
|
|
|
2016-03-16 02:27:18 +00:00
|
|
|
for (i = 0; i < stix->sem_list_count; i++)
|
2016-02-29 15:27:10 +00:00
|
|
|
{
|
2016-05-19 03:49:23 +00:00
|
|
|
stix->sem_list[i] = (stix_oop_semaphore_t)stix_moveoop (stix, (stix_oop_t)stix->sem_list[i]);
|
2016-03-22 14:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < stix->sem_heap_count; i++)
|
|
|
|
{
|
2016-05-19 03:49:23 +00:00
|
|
|
stix->sem_heap[i] = (stix_oop_semaphore_t)stix_moveoop (stix, (stix_oop_t)stix->sem_heap[i]);
|
2016-02-29 15:27:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 15:58:04 +00:00
|
|
|
for (i = 0; i < stix->tmp_count; i++)
|
|
|
|
{
|
2015-06-01 15:59:16 +00:00
|
|
|
*stix->tmp_stack[i] = stix_moveoop (stix, *stix->tmp_stack[i]);
|
2015-05-25 17:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-15 15:51:41 +00:00
|
|
|
if (stix->initial_context)
|
|
|
|
stix->initial_context = (stix_oop_context_t)stix_moveoop (stix, (stix_oop_t)stix->initial_context);
|
2016-02-12 16:23:26 +00:00
|
|
|
if (stix->active_context)
|
|
|
|
stix->active_context = (stix_oop_context_t)stix_moveoop (stix, (stix_oop_t)stix->active_context);
|
|
|
|
if (stix->active_method)
|
|
|
|
stix->active_method = (stix_oop_method_t)stix_moveoop (stix, (stix_oop_t)stix->active_method);
|
2015-06-08 13:24:02 +00:00
|
|
|
|
2015-05-25 17:10:49 +00:00
|
|
|
for (cb = stix->cblist; cb; cb = cb->next)
|
|
|
|
{
|
|
|
|
if (cb->gc) cb->gc (stix);
|
2015-05-07 15:58:04 +00:00
|
|
|
}
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* scan the new heap to move referenced objects */
|
|
|
|
ptr = (stix_uint8_t*) STIX_ALIGN ((stix_uintptr_t)stix->newheap->base, STIX_SIZEOF(stix_oop_t));
|
|
|
|
ptr = scan_new_heap (stix, ptr);
|
|
|
|
|
|
|
|
/* traverse the symbol table for unreferenced symbols.
|
|
|
|
* if the symbol has not moved to the new heap, the symbol
|
|
|
|
* is not referenced by any other objects than the symbol
|
|
|
|
* table itself */
|
2015-05-08 14:29:35 +00:00
|
|
|
compact_symbol_table (stix, old_nil);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* move the symbol table itself */
|
2015-05-25 17:10:49 +00:00
|
|
|
stix->symtab = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->symtab);
|
2015-04-30 15:56:05 +00:00
|
|
|
|
|
|
|
/* scan the new heap again from the end position of
|
|
|
|
* the previous scan to move referenced objects by
|
|
|
|
* the symbol table. */
|
|
|
|
ptr = scan_new_heap (stix, ptr);
|
|
|
|
|
2015-05-08 14:29:35 +00:00
|
|
|
/* the contents of the current heap is not needed any more.
|
|
|
|
* reset the upper bound to the base. don't forget to align the heap
|
|
|
|
* pointer to the OOP size. See stix_makeheap() also */
|
|
|
|
stix->curheap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)stix->curheap->base), STIX_SIZEOF(stix_oop_t));
|
|
|
|
|
2015-04-30 15:56:05 +00:00
|
|
|
/* swap the current heap and old heap */
|
|
|
|
tmp = stix->curheap;
|
|
|
|
stix->curheap = stix->newheap;
|
|
|
|
stix->newheap = tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
stix_oow_t index;
|
|
|
|
stix_oop_oop_t buc;
|
|
|
|
printf ("=== SURVIVING SYMBOLS ===\n");
|
|
|
|
buc = (stix_oop_oop_t) stix->symtab->slot[STIX_SYMTAB_BUCKET];
|
|
|
|
for (index = 0; index < buc->size; index++)
|
|
|
|
{
|
|
|
|
if ((stix_oop_t)buc->slot[index] != stix->_nil)
|
|
|
|
{
|
|
|
|
const stix_oop_char_t* p = ((stix_oop_char_t)buc->slot[index])->slot;
|
|
|
|
printf ("SYM [");
|
|
|
|
while (*p) printf ("%c", *p++);
|
|
|
|
printf ("]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("===========================\n");
|
|
|
|
}
|
|
|
|
*/
|
2015-07-01 15:01:39 +00:00
|
|
|
if (stix->active_method) SET_ACTIVE_METHOD_CODE (stix); /* update stix->active_code */
|
2015-04-30 15:56:05 +00:00
|
|
|
}
|
2015-05-07 15:58:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
void stix_pushtmp (stix_t* stix, stix_oop_t* oop_ptr)
|
|
|
|
{
|
|
|
|
/* if you have too many temporaries pushed, something must be wrong.
|
|
|
|
* change your code not to exceede the stack limit */
|
|
|
|
STIX_ASSERT (stix->tmp_count < STIX_COUNTOF(stix->tmp_stack));
|
|
|
|
stix->tmp_stack[stix->tmp_count++] = oop_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stix_poptmp (stix_t* stix)
|
|
|
|
{
|
|
|
|
STIX_ASSERT (stix->tmp_count > 0);
|
|
|
|
stix->tmp_count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stix_poptmps (stix_t* stix, stix_oow_t count)
|
|
|
|
{
|
|
|
|
STIX_ASSERT (stix->tmp_count >= count);
|
|
|
|
stix->tmp_count -= count;
|
|
|
|
}
|
2015-10-30 15:36:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
stix_oop_t stix_shallowcopy (stix_t* stix, stix_oop_t oop)
|
|
|
|
{
|
|
|
|
if (STIX_OOP_IS_POINTER(oop) && STIX_OBJ_GET_CLASS(oop) != stix->_symbol)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
stix_oop_t z;
|
|
|
|
stix_oop_class_t c;
|
|
|
|
|
|
|
|
c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop);
|
|
|
|
stix_pushtmp (stix, &oop);
|
2015-11-12 06:57:35 +00:00
|
|
|
z = stix_instantiate (stix, (stix_oop_t)c, STIX_NULL, STIX_OBJ_GET_SIZE(oop) - STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMOOI(c->spec)));
|
2015-10-30 15:36:37 +00:00
|
|
|
stix_poptmp(stix);
|
|
|
|
|
|
|
|
if (!z) return z;
|
|
|
|
|
|
|
|
/* copy the payload */
|
|
|
|
STIX_MEMCPY (z + 1, oop + 1, get_payload_bytes(stix, oop));
|
|
|
|
|
|
|
|
return z;
|
|
|
|
#else
|
|
|
|
stix_oop_t z;
|
|
|
|
stix_oow_t total_bytes;
|
|
|
|
|
|
|
|
total_bytes = STIX_SIZEOF(stix_obj_t) + get_payload_bytes(stix, oop);
|
|
|
|
|
|
|
|
stix_pushtmp (stix, &oop);
|
|
|
|
z = stix_allocbytes (stix, total_bytes);
|
|
|
|
stix_poptmp(stix);
|
|
|
|
|
|
|
|
STIX_MEMCPY (z, oop, total_bytes);
|
|
|
|
return z;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return oop;
|
|
|
|
}
|