(scm_remember_upto_here_1, scm_remember_upto_here_2) [__GNUC__]:
[bpt/guile.git] / libguile / gc-segment.c
index e459291..332624d 100644 (file)
@@ -1,43 +1,19 @@
 /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- * As a special exception, the Free Software Foundation gives permission
- * for additional uses of the text contained in its release of GUILE.
- *
- * The exception is that, if you link the GUILE library with other files
- * to produce an executable, this does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * Your use of that executable is in no way restricted on account of
- * linking the GUILE library code into it.
- *
- * This exception does not however invalidate any other reasons why
- * the executable file might be covered by the GNU General Public License.
- *
- * This exception applies only to the code released by the
- * Free Software Foundation under the name GUILE.  If you copy
- * code from other Free Software Foundation releases into a copy of
- * GUILE, as the General Public License permits, the exception does
- * not apply to the code that you add in this way.  To avoid misleading
- * anyone as to the status of such modified files, you must delete
- * this exception notice from them.
- *
- * If you write modifications of your own for GUILE, it is your choice
- * whether to permit this exception to apply to your modifications.
- * If you do not wish that, delete this exception notice.  */
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
 
 #include <assert.h> 
 #include <stdio.h>
 
 
 
-#define SCM_GC_CARD_BVEC_SIZE_IN_LONGS \
-    ((SCM_GC_CARD_N_CELLS + SCM_C_BVEC_LONG_BITS - 1) / SCM_C_BVEC_LONG_BITS)
-#define SCM_GC_IN_CARD_HEADERP(x) \
-  (scm_t_cell *) (x) <  SCM_GC_CELL_CARD (x) + SCM_GC_CARD_N_HEADER_CELLS
 
 
 size_t scm_max_segment_size;
@@ -120,25 +92,11 @@ scm_i_initialize_heap_segment_data (scm_t_heap_segment * segment, size_t request
   
   bvec_ptr = (scm_t_c_bvec_long*) segment->bounds[1];
 
-
-  {
-    scm_t_cell *  ptr  = segment->bounds [0];
-
-    for (;
-        ptr < segment->bounds[1]; ptr += SCM_GC_CARD_N_CELLS)
-      {
-       SCM_GC_CELL_BVEC (ptr) = bvec_ptr;
-       if (segment->span == 2) 
-         SCM_GC_SET_CARD_DOUBLECELL (ptr);
-       bvec_ptr += SCM_GC_CARD_BVEC_SIZE_IN_LONGS;
-
-       /*
-         Don't init the mem. This is handled by lazy sweeping.
-        */
-      }
-  }
-
+  /*
+    Don't init the mem or the bitvector. This is handled by lazy
+    sweeping.
+  */
+  
   segment->next_free_card = segment->bounds[0];
   segment->first_time = 1;
   return 1;
@@ -170,6 +128,8 @@ scm_i_clear_segment_mark_space (scm_t_heap_segment *seg)
 }
 
 /*
+  Sweep cards from SEG until we've gather THRESHOLD cells
+  
   RETURN:
 
   Freelist. 
@@ -180,15 +140,15 @@ scm_i_sweep_some_cards (scm_t_heap_segment *seg)
   SCM cells = SCM_EOL;
   int threshold = 512;
   int collected = 0;
-  int (*sweeper) (scm_t_cell *, SCM *, int )
-    = (seg->first_time) ? &scm_init_card_freelist : &scm_i_sweep_card;
+  int (*sweeper) (scm_t_cell *, SCM *, scm_t_heap_segment* )
+    = (seg->first_time) ? &scm_i_init_card_freelist : &scm_i_sweep_card;
 
   scm_t_cell * next_free = seg->next_free_card;
   int cards_swept = 0;
   
   while (collected < threshold && next_free < seg->bounds[1])
     {
-      collected += (*sweeper) (next_free, &cells, seg->span);
+      collected += (*sweeper) (next_free, &cells, seg);
       next_free += SCM_GC_CARD_N_CELLS;
       cards_swept ++;
     }
@@ -314,7 +274,7 @@ scm_i_insert_segment (scm_t_heap_segment * seg)
       highest_cell = SCM_MAX (highest_cell, seg->bounds[1]);
     }
 
-  
+
   {
     int i = 0;
     int j = 0;
@@ -322,6 +282,17 @@ scm_i_insert_segment (scm_t_heap_segment * seg)
     while (i < scm_i_heap_segment_table_size
           && scm_i_heap_segment_table[i]->bounds[0] <= seg->bounds[0])
       i++;
+
+    /*
+      We insert a new entry; if that happens to be before the
+      "current" segment of a freelist, we must move the freelist index
+      as well.
+    */
+    if (scm_i_master_freelist.heap_segment_idx >= i)
+      scm_i_master_freelist.heap_segment_idx ++;
+    if (scm_i_master_freelist2.heap_segment_idx >= i)
+      scm_i_master_freelist2.heap_segment_idx ++;
+
     for (j = scm_i_heap_segment_table_size; j > i; --j)
       scm_i_heap_segment_table[j] = scm_i_heap_segment_table[j - 1];
 
@@ -438,7 +409,7 @@ scm_i_find_heap_segment_containing_object (SCM obj)
                }
            }
 
-         if (!DOUBLECELL_ALIGNED_P (obj) && scm_i_heap_segment_table[i]->span == 2)
+         if (!SCM_DOUBLECELL_ALIGNED_P (obj) && scm_i_heap_segment_table[i]->span == 2)
            return -1;
          else if (SCM_GC_IN_CARD_HEADERP (ptr))
            return -1;
@@ -469,11 +440,6 @@ scm_i_get_new_heap_segment (scm_t_cell_type_statistics *freelist, policy_on_erro
       abort ();
     }
 
-
-  /* Pick a size for the new heap segment.
-   * The rule for picking the size of a segment is explained in
-   * gc.h
-   */
   {
     /* Assure that the new segment is predicted to be large enough.
      *
@@ -488,13 +454,10 @@ scm_i_get_new_heap_segment (scm_t_cell_type_statistics *freelist, policy_on_erro
      *
      * This gives dh > (f * h - y) / (1 - f)
      */
-
-    /*
-      where is is this explanation supposed to be?  --hwn
-     */
-    int f = freelist->min_yield_fraction;
-    unsigned long h = SCM_HEAP_SIZE;
-    size_t min_cells = (f * h - 100 * (long) scm_gc_cells_collected) / (99 - f);
+    float f = freelist->min_yield_fraction / 100.0;
+    float h = SCM_HEAP_SIZE;
+    float min_cells
+      = (f * h - scm_gc_cells_collected) / (1.0 - f);
 
     /* Make heap grow with factor 1.5 */
     len =  freelist->heap_size / 2;
@@ -502,17 +465,14 @@ scm_i_get_new_heap_segment (scm_t_cell_type_statistics *freelist, policy_on_erro
     fprintf (stderr, "(%ld < %ld)", (long) len, (long) min_cells);
 #endif
 
-    /*
-      Original code adds freelist->cluster_size here.
-     */
     if (len < min_cells)
-      len = min_cells;  
+      len = (unsigned long) min_cells;  
     len *= sizeof (scm_t_cell);
     /* force new sampling */
     freelist->collected = LONG_MAX;
   }
 
-  if (len > SCM_MIN_HEAP_SEG_SIZE)
+  if (len < SCM_MIN_HEAP_SEG_SIZE)
     len = SCM_MIN_HEAP_SEG_SIZE;
 
   {
@@ -538,12 +498,15 @@ scm_i_get_new_heap_segment (scm_t_cell_type_statistics *freelist, policy_on_erro
   return -1;
 }
 
-
-
 void
-scm_i_make_initial_segment (size_t init_heap_size, scm_t_cell_type_statistics *freelist)
+scm_i_make_initial_segment (int init_heap_size, scm_t_cell_type_statistics *freelist)
 {
   scm_t_heap_segment * seg = scm_i_make_empty_heap_segment (freelist);
+
+  if (init_heap_size < 1)
+    {
+      init_heap_size =  SCM_DEFAULT_INIT_HEAP_SIZE_1;
+    }
  
   if (scm_i_initialize_heap_segment_data (seg, init_heap_size))
     {