0.8.2.7:
[sbcl.git] / src / runtime / cheneygc.c
index b9fd6b2..53930cf 100644 (file)
@@ -29,6 +29,7 @@
 #include "interr.h"
 #include "genesis/static-symbols.h"
 #include "genesis/primitive-objects.h"
+#include "thread.h"
 
 /* So you need to debug? */
 #if 0
@@ -47,6 +48,9 @@ lispobj *new_space_free_pointer;
 
 static void scavenge_newspace(void);
 static void scavenge_interrupt_contexts(void);
+extern struct interrupt_data * global_interrupt_data;
+
+extern unsigned long bytes_consed_between_gcs;
 
 \f
 /* collecting garbage */
@@ -114,12 +118,16 @@ collect_garbage(unsigned ignore)
     double real_time, system_time, user_time;
     double percent_retained, gc_rate;
     unsigned long size_discarded;
-    unsigned long size_retained;
 #endif
+    unsigned long size_retained;
     lispobj *current_static_space_free_pointer;
     unsigned long static_space_size; 
     unsigned long control_stack_size, binding_stack_size; 
     sigset_t tmp, old;
+    struct thread *th=arch_os_get_current_thread();
+    struct interrupt_data *data=
+       th ? th->interrupt_data : global_interrupt_data;
+
 
 #ifdef PRINTNOISE
     printf("[Collecting garbage ... \n");
@@ -134,7 +142,7 @@ collect_garbage(unsigned ignore)
 
     current_static_space_free_pointer =
        (lispobj *) ((unsigned long)
-                    SymbolValue(STATIC_SPACE_FREE_POINTER));
+                    SymbolValue(STATIC_SPACE_FREE_POINTER,0));
 
 
     /* Set up from space and new space pointers. */
@@ -169,30 +177,30 @@ collect_garbage(unsigned ignore)
     printf("Scavenging interrupt handlers (%d bytes) ...\n",
           (int)sizeof(interrupt_handlers));
 #endif
-    scavenge((lispobj *) interrupt_handlers,
-            sizeof(interrupt_handlers) / sizeof(lispobj));
+    scavenge((lispobj *) data->interrupt_handlers,
+            sizeof(data->interrupt_handlers) / sizeof(lispobj));
        
     /* _size quantities are in units of sizeof(lispobj) - i.e. 4 */
     control_stack_size = 
        current_control_stack_pointer-
-       (lispobj *)CONTROL_STACK_START;
+       (lispobj *)th->control_stack_start;
 #ifdef PRINTNOISE
     printf("Scavenging the control stack at %p (%ld words) ...\n",
-          ((lispobj *)CONTROL_STACK_START), 
+          ((lispobj *)th->control_stack_start), 
           control_stack_size);
 #endif
-    scavenge(((lispobj *)CONTROL_STACK_START), control_stack_size);
+    scavenge(((lispobj *)th->control_stack_start), control_stack_size);
                 
 
     binding_stack_size = 
        current_binding_stack_pointer - 
-       (lispobj *)BINDING_STACK_START;
+       (lispobj *)th->binding_stack_start;
 #ifdef PRINTNOISE
     printf("Scavenging the binding stack %x - %x (%d words) ...\n",
-          BINDING_STACK_START,current_binding_stack_pointer,
+          th->binding_stack_start,current_binding_stack_pointer,
           (int)(binding_stack_size));
 #endif
-    scavenge(((lispobj *)BINDING_STACK_START), binding_stack_size);
+    scavenge(((lispobj *)th->binding_stack_start), binding_stack_size);
                 
     static_space_size = 
        current_static_space_free_pointer - (lispobj *) STATIC_SPACE_START;
@@ -235,15 +243,15 @@ collect_garbage(unsigned ignore)
 
 #ifdef PRINTNOISE
     size_discarded = (from_space_free_pointer - from_space) * sizeof(lispobj);
-    size_retained = (new_space_free_pointer - new_space) * sizeof(lispobj);
 #endif
+    size_retained = (new_space_free_pointer - new_space) * sizeof(lispobj);
 
     /* Zero stack. */
 #ifdef PRINTNOISE
     printf("Zeroing empty part of control stack ...\n");
 #endif
     zero_stack();
-
+    set_auto_gc_trigger(size_retained+bytes_consed_between_gcs);
     sigprocmask(SIG_SETMASK, &old, 0);
 
 
@@ -414,13 +422,18 @@ void scavenge_interrupt_contexts(void)
     int i, index;
     os_context_t *context;
 
-    index = fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX));
+    struct thread *th=arch_os_get_current_thread();
+    struct interrupt_data *data=
+       th ? th->interrupt_data : global_interrupt_data;
+
+    index = fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,0));
+
 
 #ifdef DEBUG_SCAVENGE_VERBOSE
     fprintf(stderr, "%d interrupt contexts to scan\n",index);
 #endif
     for (i = 0; i < index; i++) {
-       context = lisp_interrupt_contexts[i];
+       context = th->interrupt_contexts[i];
        scavenge_interrupt_context(context); 
     }
 }
@@ -584,11 +597,13 @@ gc_initialize_pointers(void)
 \f
 /* noise to manipulate the gc trigger stuff */
 
+/* Functions that substantially change the dynamic space free pointer
+ * (collect_garbage, purify) are responsible also for resettting the
+ * auto_gc_trigger */
 void set_auto_gc_trigger(os_vm_size_t dynamic_usage)
 {
     os_vm_address_t addr=(os_vm_address_t)current_dynamic_space 
        + dynamic_usage;
-       
     long length = DYNAMIC_SPACE_SIZE - dynamic_usage;
 
     if (addr < (os_vm_address_t)dynamic_space_free_pointer) {