Added moveBuf and helper functions

This commit is contained in:
Justin Ethier 2015-10-16 22:14:52 -04:00
parent d7640c988b
commit e941b19db4
4 changed files with 29 additions and 2 deletions

13
gc.c
View file

@ -262,6 +262,19 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr)
return max_freed;
}
void gc_thr_grow_move_buffer(gc_thread_data *d){
if (!d) return;
if (d->moveBufLen == 0) { // Special case
d->moveBufLen = 128;
d->moveBuf = NULL;
} else {
d->moveBufLen *= 2;
}
d->moveBuf = realloc(d->moveBuf, d->moveBufLen);
}
// void gc_init()
// {
// }

View file

@ -13,7 +13,6 @@
long global_stack_size = 0;
long global_heap_size = 0;
gc_heap *Cyc_heap;
static void c_entry_pt(int,closure,closure);
static void Cyc_main(long stack_size,long heap_size,char *stack_base);
@ -59,6 +58,10 @@ static void Cyc_main (stack_size,heap_size,stack_base)
#endif
Cyc_heap = gc_heap_create(heap_size, 0);
Cyc_thread = (gc_thread_data *)malloc(sizeof(gc_thread_data));
Cyc_thread->moveBufLen = 0;
gc_thr_grow_move_buffer(Cyc_thread); // Initialize the buffer
// JAE TODO: clean up below (and all of this old code, really)
bottom = calloc(1,heap_size);

View file

@ -20,6 +20,13 @@
/* Define general object type. */
typedef void *object;
/* Thread data structures */
typedef struct gc_thread_data_t gc_thread_data;
struct gc_thread_data_t {
char *moveBuf; /* list of objects moved to heap during GC */
int moveBufLen;
};
/* GC data structures */
typedef struct gc_free_list_t gc_free_list;
@ -69,6 +76,7 @@ size_t gc_heap_total_size(gc_heap *h);
void gc_mark(gc_heap *h, object obj);
size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr);
void gc_collect(gc_heap *h, size_t *sum_freed);
void gc_thr_grow_move_buffer(gc_thread_data *d);
/* GC debugging flags */
//#define DEBUG_GC 0

View file

@ -9,6 +9,9 @@
#include "cyclone/types.h"
#include "cyclone/runtime.h"
gc_heap *Cyc_heap;
gc_thread_data *Cyc_thread;
/* Error checking section - type mismatch, num args, etc */
/* Type names to use for error messages */
const char *tag_names[21] = { \
@ -2405,7 +2408,7 @@ char *gc_move(char *obj) {
} \
}
void GC(cont,ans,num_ans) closure cont; object *args; int num_args;
void GC(cont, args, num_args) closure cont; object *args; int num_args;
{
char tmp;
object temp;