From b14d25afc9d648376b2773910e8ddd2dca63f2c1 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 20 Apr 2016 21:46:28 -0400 Subject: [PATCH] Decrease memory usage of object header --- gc.c | 10 +++++----- include/cyclone/types.h | 4 ++-- runtime.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gc.c b/gc.c index 170c6438..777eadc2 100644 --- a/gc.c +++ b/gc.c @@ -376,7 +376,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data *thd) case symbol_tag: break; default: - fprintf(stderr, "gc_copy_obj: bad tag obj=%p obj.tag=%ld\n",(object) obj, type_of(obj)); + fprintf(stderr, "gc_copy_obj: bad tag obj=%p obj.tag=%d\n",(object) obj, type_of(obj)); exit(1); } return (char *)obj; @@ -493,7 +493,7 @@ void *gc_alloc(gc_heap_root *hrt, size_t size, char *obj, gc_thread_data *thd, i } } #if GC_DEBUG_VERBOSE - fprintf(stderr, "alloc %p size = %zu, obj=%p, tag=%ld, mark=%d\n", result, size, obj, type_of(obj), mark(((object)result))); + fprintf(stderr, "alloc %p size = %zu, obj=%p, tag=%d, mark=%d\n", result, size, obj, type_of(obj), mark(((object)result))); // Debug check, should no longer be necessary //if (is_value_type(result)) { // printf("Invalid allocated address - is a value type %p\n", result); @@ -538,7 +538,7 @@ size_t gc_allocated_bytes(object obj, gc_free_list *q, gc_free_list *r) if (t == mutex_tag) return gc_heap_align(sizeof(mutex_type)); if (t == cond_var_tag) return gc_heap_align(sizeof(cond_var_type)); - fprintf(stderr, "gc_allocated_bytes: unexpected object %p of type %ld\n", obj, t); + fprintf(stderr, "gc_allocated_bytes: unexpected object %p of type %d\n", obj, t); exit(1); return 0; } @@ -626,7 +626,7 @@ size_t gc_sweep(gc_heap *h, int heap_type, size_t *sum_freed_ptr) if (mark(p) == gc_color_clear) { #if GC_DEBUG_VERBOSE - fprintf(stderr, "sweep is freeing unmarked obj: %p with tag %ld\n", p, type_of(p)); + fprintf(stderr, "sweep is freeing unmarked obj: %p with tag %d\n", p, type_of(p)); #endif mark(p) = gc_color_blue; // Needed? if (type_of(p) == mutex_tag) { @@ -1086,7 +1086,7 @@ void gc_collector_mark_gray(object parent, object obj) if (is_object_type(obj) && mark(obj) == gc_color_clear) { mark_stack = vpbuffer_add(mark_stack, &mark_stack_len, mark_stack_i++, obj); #if GC_DEBUG_VERBOSE - fprintf(stderr, "mark gray parent = %p (%ld) obj = %p\n", parent, type_of(parent), obj); + fprintf(stderr, "mark gray parent = %p (%d) obj = %p\n", parent, type_of(parent), obj); #endif } } diff --git a/include/cyclone/types.h b/include/cyclone/types.h index d4293054..219cf424 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -89,7 +89,7 @@ enum object_tag { }; // Define the size of object tags -typedef long tag_type; +typedef unsigned char tag_type; /* Threading */ typedef enum { CYC_THREAD_STATE_NEW, CYC_THREAD_STATE_RUNNABLE, @@ -166,7 +166,7 @@ struct gc_heap_root_t { typedef struct gc_header_type_t gc_header_type; struct gc_header_type_t { - unsigned int mark; // mark bits (TODO: only need 2, reduce size of type?) + unsigned char mark; // mark bits (only need 2) unsigned char grayed; // stack object to be grayed when moved to heap }; #define mark(x) (((list) x)->hdr.mark) diff --git a/runtime.c b/runtime.c index 6259dc52..a104424f 100644 --- a/runtime.c +++ b/runtime.c @@ -636,7 +636,7 @@ object Cyc_display(object x, FILE *port) fprintf(port, ")"); break; default: - fprintf(port, "Cyc_display: bad tag x=%ld\n", ((closure)x)->tag); + fprintf(port, "Cyc_display: bad tag x=%d\n", ((closure)x)->tag); exit(1); } return quote_void;} @@ -2632,7 +2632,7 @@ object apply(void *data, object cont, object func, object args){ } default: - printf("Invalid object type %ld\n", type_of(func)); + printf("Invalid object type %d\n", type_of(func)); exit(1); } return NULL; // Never reached @@ -2834,7 +2834,7 @@ char *gc_move(char *obj, gc_thread_data *thd, int *alloci, int *heap_grown) { case boolean_tag: break; case symbol_tag: break; // JAE TODO: raise an error here? Should not be possible in real code, though (IE, without GC DEBUG flag) default: - fprintf(stderr, "gc_move: bad tag obj=%p obj.tag=%ld\n",(object) obj, type_of(obj)); + fprintf(stderr, "gc_move: bad tag obj=%p obj.tag=%d\n",(object) obj, type_of(obj)); exit(1); } return (char *)obj; @@ -2908,7 +2908,7 @@ int gc_minor(void *data, object low_limit, object high_limit, closure cont, obje } else if (type_of(o) == forward_tag) { // Already transported, skip } else { - printf("Unexpected type %ld transporting mutation\n", type_of(o)); + printf("Unexpected type %d transporting mutation\n", type_of(o)); exit(1); } } @@ -2969,7 +2969,7 @@ int gc_minor(void *data, object low_limit, object high_limit, closure cont, obje case boolean_tag: default: fprintf(stderr, - "GC: unexpected object type %ld for object %p\n", type_of(obj), obj); + "GC: unexpected object type %d for object %p\n", type_of(obj), obj); exit(1); } scani++;