[clean up memory allocation code in rts, do out of memory checking always.
John Meacham <john@repetae.net>**20080313103902] hunk ./data/rts/jhc_rts.c 40
-#if _JHC_GC == _JHC_GC_NONE
-        fprintf(stderr, "Memory Allocated: %llu bytes\n", (unsigned long long)(jhc_mem - jhc_memstart));
-#endif
+        jhc_alloc_print_stats();
hunk ./data/rts/jhc_rts_alloc.c 2
+// some default definitions
+
+#define jhc_malloc_whnf jhc_malloc
+#define jhc_malloc_suspension jhc_malloc
+#define jhc_malloc_atomic jhc_malloc
+#define jhc_malloc_atomic_whnf jhc_malloc_atomic
+#define jhc_malloc_sanity(p,t) (1)
+
+extern void _start,_end;
+
+
hunk ./data/rts/jhc_rts_alloc.c 16
+
hunk ./data/rts/jhc_rts_alloc.c 18
-#define jhc_malloc_whnf GC_malloc
-#define jhc_malloc_suspension GC_malloc
+#undef  jhc_malloc_atomic
hunk ./data/rts/jhc_rts_alloc.c 20
-#define jhc_malloc_atomic_whnf GC_malloc_atomic
hunk ./data/rts/jhc_rts_alloc.c 22
-static inline void
-jhc_malloc_init(void)
-{
-        GC_INIT();
-}
+static inline void jhc_malloc_init(void) { GC_INIT(); }
+static inline void jhc_alloc_print_stats(void) { GC_dump(); }
hunk ./data/rts/jhc_rts_alloc.c 25
-#else
+#elif _JHC_GC == _JHC_GC_NONE
hunk ./data/rts/jhc_rts_alloc.c 27
-static void *jhc_mem = NULL;
-static void *jhc_memstart;
+static void *jhc_current_chunk;
+static unsigned mem_chunks,mem_offset;
hunk ./data/rts/jhc_rts_alloc.c 30
+// memory allocated in 1MB chunks.
+#define JHC_MEM_CHUNK_SIZE (1 << 20)
hunk ./data/rts/jhc_rts_alloc.c 34
-jhc_malloc_init(void)
-{
-        size_t mem_size = 1000000000;
-        while(!jhc_mem) {
-                jhc_mem = malloc(mem_size);
-                mem_size *= 0.80;
-        }
-        jhc_memstart = jhc_mem;
-}
-
+jhc_malloc_init(void) { return; }
hunk ./data/rts/jhc_rts_alloc.c 36
-#if _JHC_DEBUG
-
-struct jhcm_header {
-        unsigned short line_number;
-};
+static void
+jhc_alloc_print_stats(void) {
+        fprintf(stderr, "Memory Allocated: %llu bytes\n", (JHC_MEM_CHUNK_SIZE*((unsigned long long)mem_chunks - 1)) + mem_offset);
hunk ./data/rts/jhc_rts_alloc.c 40
+}
hunk ./data/rts/jhc_rts_alloc.c 42
-extern void _start;
-extern void _end;
+static void
+jhc_malloc_grow(void) {
+        void *c = malloc(JHC_MEM_CHUNK_SIZE);
+        if(!c) {
+                fputs("Out of memory!\n",stderr);
+                abort();
+        }
+        mem_chunks++;
+        jhc_current_chunk = c;
+        mem_offset = 0;
+}
hunk ./data/rts/jhc_rts_alloc.c 54
-static int
-jhc_malloc_sanity(void *p,int tag)
-{
-        assert((p >= jhc_memstart && p < jhc_mem) || (p >= &_start && p < &_end));
-        return 1;
+static inline void * A_MALLOC
+jhc_malloc_basic(size_t n) {
+        n = ALIGN(sizeof(void *),n);
+        if (n > (JHC_MEM_CHUNK_SIZE - mem_offset))
+                jhc_malloc_grow();
+        void *ret = jhc_current_chunk + mem_offset;
+        mem_offset += n;
+        return ret;
hunk ./data/rts/jhc_rts_alloc.c 65
+#if _JHC_DEBUG
+
hunk ./data/rts/jhc_rts_alloc.c 70
-jhc_malloc_debug(size_t n,int line)
-{
-        void *ret = jhc_mem;
-        jhc_mem += ALIGN(__alignof__(void *),sizeof(uintptr_t) + n);
+jhc_malloc_debug(size_t n,int line) {
+        void *ret = jhc_malloc_basic(n + sizeof(uintptr_t));
hunk ./data/rts/jhc_rts_alloc.c 79
-jhc_malloc(size_t n)
-{
-        void *ret = jhc_mem;
-        jhc_mem += ALIGN(__alignof__(void *),n);
-        return ret;
-}
+jhc_malloc(size_t n) { return jhc_malloc_basic(n); }
hunk ./data/rts/jhc_rts_alloc.c 81
-#define jhc_malloc_sanity(p,t) do {} while(0)
hunk ./data/rts/jhc_rts_alloc.c 84
-#define jhc_malloc_atomic(x)      jhc_malloc(x)
-#define jhc_malloc_atomic_whnf(x) jhc_malloc(x)
-#define jhc_malloc_whnf(x)        jhc_malloc(x)
-#define jhc_malloc_suspension(x)  jhc_malloc(x)
+#elif _JHC_GC == _JHC_GC_JGC
hunk ./data/rts/jhc_rts_alloc.c 86
+#error "jgc not supported yet."
hunk ./data/rts/jhc_rts_alloc.c 90
+
hunk ./data/rts/jhc_rts_header.h 21
-#define _JHC_GC_JUDY  1
+#define _JHC_JGC      1
hunk ./data/rts/jhc_rts_header.h 45
-#define A_NORETURN __attribute__ ((noreturn))
-#define A_PURE __attribute__ ((pure))
-#define A_CONST __attribute__ ((const))
-#define A_UNUSED __attribute__ ((unused))
-#define A_MALLOC __attribute__ ((malloc))
+#define A_ALIGNED  __attribute__ ((aligned))
+#define A_CONST    __attribute__ ((const))
+#define A_MALLOC   __attribute__ ((malloc))
hunk ./data/rts/jhc_rts_header.h 49
+#define A_NORETURN __attribute__ ((noreturn))
+#define A_PURE     __attribute__ ((pure))
+#define A_UNUSED   __attribute__ ((unused))
hunk ./data/rts/jhc_rts_header.h 60
+#define A_ALIGNED
+#define A_CONST
+#define A_MALLOC
hunk ./data/rts/jhc_rts_header.h 66
-#define A_CONST
hunk ./data/rts/jhc_rts_header.h 67
-#define A_MALLOC