mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Added move to buffer function
This commit is contained in:
parent
076a9316e0
commit
dfdfd52a54
3 changed files with 22 additions and 13 deletions
15
gc.c
15
gc.c
|
@ -262,7 +262,8 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr)
|
||||||
return max_freed;
|
return max_freed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gc_thr_grow_move_buffer(gc_thread_data *d){
|
void gc_thr_grow_move_buffer(gc_thread_data *d)
|
||||||
|
{
|
||||||
if (!d) return;
|
if (!d) return;
|
||||||
|
|
||||||
if (d->moveBufLen == 0) { // Special case
|
if (d->moveBufLen == 0) { // Special case
|
||||||
|
@ -272,7 +273,17 @@ void gc_thr_grow_move_buffer(gc_thread_data *d){
|
||||||
d->moveBufLen *= 2;
|
d->moveBufLen *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->moveBuf = realloc(d->moveBuf, d->moveBufLen);
|
d->moveBuf = realloc(d->moveBuf, d->moveBufLen * sizeof(void *));
|
||||||
|
}
|
||||||
|
|
||||||
|
void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj)
|
||||||
|
{
|
||||||
|
if (*alloci == d->moveBufLen) {
|
||||||
|
gc_thr_grow_move_buffer(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
d->moveBuf[*alloci] = obj;
|
||||||
|
(*alloci)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void gc_init()
|
// void gc_init()
|
||||||
|
|
|
@ -23,7 +23,7 @@ typedef void *object;
|
||||||
/* Thread data structures */
|
/* Thread data structures */
|
||||||
typedef struct gc_thread_data_t gc_thread_data;
|
typedef struct gc_thread_data_t gc_thread_data;
|
||||||
struct gc_thread_data_t {
|
struct gc_thread_data_t {
|
||||||
char *moveBuf; /* list of objects moved to heap during GC */
|
void **moveBuf; /* list of objects moved to heap during GC */
|
||||||
int moveBufLen;
|
int moveBufLen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ void gc_mark(gc_heap *h, object obj);
|
||||||
size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr);
|
size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr);
|
||||||
void gc_collect(gc_heap *h, size_t *sum_freed);
|
void gc_collect(gc_heap *h, size_t *sum_freed);
|
||||||
void gc_thr_grow_move_buffer(gc_thread_data *d);
|
void gc_thr_grow_move_buffer(gc_thread_data *d);
|
||||||
|
void gc_thr_add_to_move_buffer(gc_thread_data *d, int *alloci, object obj);
|
||||||
|
|
||||||
/* GC debugging flags */
|
/* GC debugging flags */
|
||||||
//#define DEBUG_GC 0
|
//#define DEBUG_GC 0
|
||||||
|
|
17
runtime.c
17
runtime.c
|
@ -2378,7 +2378,7 @@ void gc_collect(gc_heap *h, size_t *sum_freed)
|
||||||
// TODO: move globals to thread-specific structures.
|
// TODO: move globals to thread-specific structures.
|
||||||
// for example - gc_cont, gc_ans, gc_num_ans
|
// for example - gc_cont, gc_ans, gc_num_ans
|
||||||
|
|
||||||
char *gc_move(char *obj) {
|
char *gc_move(char *obj, gc_thread_data *thd, int *alloci) {
|
||||||
if (!is_object_type(obj)) return obj;
|
if (!is_object_type(obj)) return obj;
|
||||||
|
|
||||||
switch(type_of(obj)){
|
switch(type_of(obj)){
|
||||||
|
@ -2390,10 +2390,9 @@ char *gc_move(char *obj) {
|
||||||
cdr(hobj) = cdr(hobj);
|
cdr(hobj) = cdr(hobj);
|
||||||
forward(obj) = hobj;
|
forward(obj) = hobj;
|
||||||
type_of(obj) = forward_tag;
|
type_of(obj) = forward_tag;
|
||||||
// TODO: add hobj to bump pointer, so we can scan/move the whole live object 'tree'
|
// keep track of each allocation so we can scan/move
|
||||||
// will require we pass the 'bump' space to this function,
|
// the whole live object 'tree'
|
||||||
// and will require us to check somewhere for overflow of this space, and
|
gc_thr_add_to_move_buffer(thd, alloci, hobj);
|
||||||
// realloc/expand it if necessary
|
|
||||||
return (char *)hobj;
|
return (char *)hobj;
|
||||||
}
|
}
|
||||||
// TODO: other types
|
// TODO: other types
|
||||||
|
@ -2404,7 +2403,7 @@ char *gc_move(char *obj) {
|
||||||
temp = obj; \
|
temp = obj; \
|
||||||
if (check_overflow(low_limit, temp) && \
|
if (check_overflow(low_limit, temp) && \
|
||||||
check_overflow(temp, high_limit)){ \
|
check_overflow(temp, high_limit)){ \
|
||||||
(obj) = (object) gc_move(temp); \
|
(obj) = (object) gc_move(temp, Cyc_thread, &alloci); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2415,13 +2414,11 @@ void GC(cont, args, num_args) closure cont; object *args; int num_args;
|
||||||
object low_limit = &tmp; // This is one end of the stack...
|
object low_limit = &tmp; // This is one end of the stack...
|
||||||
object high_limit = stack_begin; // TODO: move to thread-specific struct
|
object high_limit = stack_begin; // TODO: move to thread-specific struct
|
||||||
int i;
|
int i;
|
||||||
int moveBufLen = 128, mbIdx = 0;
|
|
||||||
void **moved = alloca(sizeof(void *) * moveBufLen);
|
|
||||||
int scani = 0, alloci = 0; // TODO: not quite sure how to do this yet, want to user pointers but realloc can move them... need to think about how this will work
|
int scani = 0, alloci = 0; // TODO: not quite sure how to do this yet, want to user pointers but realloc can move them... need to think about how this will work
|
||||||
|
|
||||||
// Prevent overrunning buffer
|
// Prevent overrunning buffer
|
||||||
if (num_ans > NUM_GC_ANS) {
|
if (num_args > NUM_GC_ANS) {
|
||||||
printf("Fatal error - too many arguments (%d) to GC\n", num_ans);
|
printf("Fatal error - too many arguments (%d) to GC\n", num_args);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue