mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-09 22:17:33 +02:00
Debugging mark/sweep algorithms
This commit is contained in:
parent
e5277abfb8
commit
4ce75a2213
3 changed files with 12 additions and 11 deletions
4
gc.c
4
gc.c
|
@ -161,7 +161,7 @@ size_t gc_heap_total_size(gc_heap *h)
|
||||||
|
|
||||||
void gc_mark(gc_heap *h, object obj)
|
void gc_mark(gc_heap *h, object obj)
|
||||||
{
|
{
|
||||||
if (!obj || is_marked(obj))
|
if (nullp(obj) || is_value_type(obj) || mark(obj))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if GC_DEBUG_PRINTFS
|
#if GC_DEBUG_PRINTFS
|
||||||
|
@ -232,7 +232,7 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr)
|
||||||
// END DEBUG
|
// END DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!is_marked(p)) {
|
if (!mark(p)) {
|
||||||
#if GC_DEBUG_PRINTFS
|
#if GC_DEBUG_PRINTFS
|
||||||
fprintf(stdout, "sweep: object is not marked %p\n", p);
|
fprintf(stdout, "sweep: object is not marked %p\n", p);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,7 +51,6 @@ struct gc_header_type_t {
|
||||||
unsigned int mark; // mark bits (only need 2)
|
unsigned int mark; // mark bits (only need 2)
|
||||||
// TODO: forwarding address (probably not needed for mark/sweep), anything else???
|
// TODO: forwarding address (probably not needed for mark/sweep), anything else???
|
||||||
};
|
};
|
||||||
#define is_marked(x) (is_object_type(x) && ((list)x)->hdr.mark)
|
|
||||||
#define mark(x) (((list) x)->hdr.mark)
|
#define mark(x) (((list) x)->hdr.mark)
|
||||||
|
|
||||||
/* HEAP definitions */
|
/* HEAP definitions */
|
||||||
|
@ -76,13 +75,13 @@ gc_heap *gc_heap_last(gc_heap *h);
|
||||||
size_t gc_heap_total_size(gc_heap *h);
|
size_t gc_heap_total_size(gc_heap *h);
|
||||||
void gc_mark(gc_heap *h, object obj);
|
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);
|
size_t 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);
|
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
|
||||||
#define GC_DEBUG_PRINTFS 0
|
#define GC_DEBUG_PRINTFS 1
|
||||||
|
|
||||||
/* Show diagnostic information for the GC when program terminates */
|
/* Show diagnostic information for the GC when program terminates */
|
||||||
#define DEBUG_SHOW_DIAG 0
|
#define DEBUG_SHOW_DIAG 0
|
||||||
|
|
14
runtime.c
14
runtime.c
|
@ -2353,7 +2353,7 @@ void Cyc_apply_from_buf(int argc, object prim, object *buf) {
|
||||||
// if the heap was expanded during alloc, and after all the allocs are done
|
// if the heap was expanded during alloc, and after all the allocs are done
|
||||||
// after a minor GC (or during the minor GC), call into this function to
|
// after a minor GC (or during the minor GC), call into this function to
|
||||||
// free up unused space
|
// free up unused space
|
||||||
void gc_collect(gc_heap *h, size_t *sum_freed)
|
size_t gc_collect(gc_heap *h, size_t *sum_freed)
|
||||||
{
|
{
|
||||||
printf("(heap: %p size: %d)\n", h, (unsigned int)gc_heap_total_size(h));
|
printf("(heap: %p size: %d)\n", h, (unsigned int)gc_heap_total_size(h));
|
||||||
// Mark global variables
|
// Mark global variables
|
||||||
|
@ -2369,7 +2369,7 @@ void gc_collect(gc_heap *h, size_t *sum_freed)
|
||||||
// conservative mark?
|
// conservative mark?
|
||||||
// weak refs?
|
// weak refs?
|
||||||
// finalize?
|
// finalize?
|
||||||
gc_sweep(h, sum_freed);
|
return gc_sweep(h, sum_freed);
|
||||||
// debug print free stats
|
// debug print free stats
|
||||||
// return value from sweep??
|
// return value from sweep??
|
||||||
}
|
}
|
||||||
|
@ -2594,7 +2594,7 @@ void GC(cont, args, num_args) closure cont; object *args; int num_args;
|
||||||
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
|
||||||
int heap_grown = 0;
|
int heap_grown = 0;
|
||||||
|
|
||||||
fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG
|
//fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG
|
||||||
// Prevent overrunning buffer
|
// Prevent overrunning buffer
|
||||||
if (num_args > NUM_GC_ANS) {
|
if (num_args > NUM_GC_ANS) {
|
||||||
printf("Fatal error - too many arguments (%d) to GC\n", num_args);
|
printf("Fatal error - too many arguments (%d) to GC\n", num_args);
|
||||||
|
@ -2707,16 +2707,18 @@ fprintf(stdout, "DEBUG, started minor GC\n"); // JAE DEBUG
|
||||||
|
|
||||||
// Check if we need to do a major GC
|
// Check if we need to do a major GC
|
||||||
if (heap_grown) {
|
if (heap_grown) {
|
||||||
size_t freed = 0;
|
size_t freed = 0, max_freed = 0;
|
||||||
fprintf(stdout, "DEBUG, starting major mark/sweep GC\n"); // JAE DEBUG
|
fprintf(stdout, "DEBUG, starting major mark/sweep GC\n"); // JAE DEBUG
|
||||||
gc_mark(Cyc_heap, cont);
|
gc_mark(Cyc_heap, cont);
|
||||||
for (i = 0; i < num_args; i++){
|
for (i = 0; i < num_args; i++){
|
||||||
gc_mark(Cyc_heap, args[i]);
|
gc_mark(Cyc_heap, args[i]);
|
||||||
}
|
}
|
||||||
gc_collect(Cyc_heap, &freed);
|
max_freed = gc_collect(Cyc_heap, &freed);
|
||||||
|
printf("done, freed = %d, max_freed = %d\n", freed, max_freed);
|
||||||
|
exit(1); // JAE DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "DEBUG, finished minor GC\n"); // JAE DEBUG
|
//fprintf(stdout, "DEBUG, finished minor GC\n"); // JAE DEBUG
|
||||||
longjmp(jmp_main,1); // Return globals gc_cont, gc_ans
|
longjmp(jmp_main,1); // Return globals gc_cont, gc_ans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue