From 6c40a29d5d55c7201e510d94e3ee89983ddfad91 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 3 Jul 2015 23:27:24 -0400 Subject: [PATCH] Upgrade to major GC if data heap exceeds limit --- runtime-main.h | 1 + runtime.c | 10 ++++++++++ runtime.h | 1 + 3 files changed, 12 insertions(+) diff --git a/runtime-main.h b/runtime-main.h index ce360427..1071aa58 100644 --- a/runtime-main.h +++ b/runtime-main.h @@ -65,6 +65,7 @@ static void main_main (stack_size,heap_size,stack_base) alloc_end = allocp + heap_size - 8; dhallocp = dhbottom = calloc(1, heap_size); + dhalloc_limit = dhallocp + (long)((heap_size - 8) * 0.90); dhalloc_end = dhallocp + heap_size - 8; #if DEBUG_SHOW_DIAG printf("main: heap_size=%ld allocp=%p alloc_end=%p\n", diff --git a/runtime.c b/runtime.c index 690255ed..cb7b6c12 100644 --- a/runtime.c +++ b/runtime.c @@ -42,6 +42,7 @@ char *alloc_end; copying to occur during GC */ char *dhbottom; /* Bottom of data heap */ char *dhallocp; /* Current place in data heap */ +char *dhalloc_limit; /* GC beyond this limit */ char *dhalloc_end; long no_gcs = 0; /* Count the number of GC's. */ long no_major_gcs = 0; /* Count the number of GC's. */ @@ -1674,6 +1675,14 @@ void GC_loop(int major, closure cont, object *ans, int num_ans) char *tmp_dhbottom = dhbottom; char *tmp_dhallocp = dhallocp; char *tmp_dhallocp_end = dhalloc_end; + + if (dhallocp > dhalloc_limit) { + // Upgrade to major GC + major = 1; + no_major_gcs++; + no_gcs--; + } + if (major) { // Initialize new heap (TODO: make a function for this) bottom = calloc(1,global_heap_size); @@ -1684,6 +1693,7 @@ void GC_loop(int major, closure cont, object *ans, int num_ans) old_heap_high_limit = tmp_alloc_end; dhallocp = dhbottom = calloc(1, global_heap_size); + dhalloc_limit = dhallocp + (long)((global_heap_size - 8) * 0.90); dhalloc_end = dhallocp + global_heap_size - 8; } diff --git a/runtime.h b/runtime.h index 519fdd63..abf75d16 100644 --- a/runtime.h +++ b/runtime.h @@ -224,6 +224,7 @@ extern char *alloc_end; copying to occur during GC */ extern char *dhbottom; /* Bottom of data heap */ extern char *dhallocp; /* Current place in data heap */ +extern char *dhalloc_limit; /* GC beyond this limit */ extern char *dhalloc_end; extern long no_gcs; /* Count the number of GC's. */ extern long no_major_gcs; /* Count the number of GC's. */