0.8.13.47:
[sbcl.git] / src / runtime / gc-common.c
index acbadae..3246b72 100644 (file)
  */
 
 /*
- * GENerational Conservative Garbage Collector for SBCL x86
- */
-
-/*
- * This software is part of the SBCL system. See the README file for
- * more information.
- *
- * This software is derived from the CMU CL system, which was
- * written at Carnegie Mellon University and released into the
- * public domain. The software is in the public domain and is
- * provided with absolutely no warranty. See the COPYING and CREDITS
- * files for more information.
- */
-
-/*
  * For a review of garbage collection techniques (e.g. generational
  * GC) and terminology (e.g. "scavenging") see Paul R. Wilson,
  * "Uniprocessor Garbage Collection Techniques". As of 20000618, this
@@ -42,8 +27,9 @@
 
 #include <stdio.h>
 #include <signal.h>
-#include "runtime.h"
+#include <string.h>
 #include "sbcl.h"
+#include "runtime.h"
 #include "os.h"
 #include "interr.h"
 #include "globals.h"
@@ -112,7 +98,6 @@ copy_object(lispobj object, int nwords)
 {
     int tag;
     lispobj *new;
-    lispobj *source, *dest;
 
     gc_assert(is_lisp_pointer(object));
     gc_assert(from_space_p(object));
@@ -124,18 +109,8 @@ copy_object(lispobj object, int nwords)
     /* Allocate space. */
     new = gc_general_alloc(nwords*4,ALLOC_BOXED,ALLOC_QUICK);
 
-    dest = new;
-    source = (lispobj *) native_pointer(object);
-
     /* Copy the object. */
-    while (nwords > 0) {
-       dest[0] = source[0];
-       dest[1] = source[1];
-       dest += 2;
-       source += 2;
-       nwords -= 2;
-    }
-
+    memcpy(new,native_pointer(object),nwords*4);
     return make_lispobj(new,tag);
 }
 
@@ -144,14 +119,12 @@ static int scav_lose(lispobj *where, lispobj object); /* forward decl */
 /* FIXME: Most calls end up going to some trouble to compute an
  * 'n_words' value for this function. The system might be a little
  * simpler if this function used an 'end' parameter instead. */
-
 void
 scavenge(lispobj *start, long n_words)
 {
     lispobj *end = start + n_words;
     lispobj *object_ptr;
     int n_words_scavenged;
-    
     for (object_ptr = start;
         object_ptr < end;
         object_ptr += n_words_scavenged) {
@@ -327,7 +300,7 @@ trans_code(struct code *code)
                
        /* fix self pointer. */
        nfheaderp->self =
-#ifdef LISP_FEATURE_GENCGC     /* GENCGC?  Maybe x86 is better conditional  */
+#ifdef LISP_FEATURE_X86
            FUN_RAW_ADDR_OFFSET +
 #endif
            nfheaderl; 
@@ -407,6 +380,7 @@ size_code_header(lispobj *where)
     return nwords;
 }
 
+#ifndef LISP_FEATURE_X86
 static int
 scav_return_pc_header(lispobj *where, lispobj object)
 {
@@ -415,6 +389,7 @@ scav_return_pc_header(lispobj *where, lispobj object)
         (unsigned long) object);
     return 0; /* bogus return value to satisfy static type checking */
 }
+#endif /* LISP_FEATURE_X86 */
 
 static lispobj
 trans_return_pc_header(lispobj object)
@@ -459,6 +434,7 @@ scav_closure_header(lispobj *where, lispobj object)
 }
 #endif
 
+#ifndef LISP_FEATURE_X86
 static int
 scav_fun_header(lispobj *where, lispobj object)
 {
@@ -467,6 +443,7 @@ scav_fun_header(lispobj *where, lispobj object)
         (unsigned long) object);
     return 0; /* bogus return value to satisfy static type checking */
 }
+#endif /* LISP_FEATURE_X86 */
 
 static lispobj
 trans_fun_header(lispobj object)
@@ -766,8 +743,6 @@ size_unboxed(lispobj *where)
 static int\f
 /* vector-like objects */
 
-#define NWORDS(x,y) (CEILING((x),(y)) / (y))
-
 scav_base_string(lispobj *where, lispobj object)
 {
     struct vector *vector;
@@ -778,7 +753,7 @@ scav_base_string(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length) + 1;
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return nwords;
 }
@@ -796,7 +771,7 @@ trans_base_string(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length) + 1;
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -813,7 +788,7 @@ size_base_string(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length) + 1;
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return nwords;
 }
@@ -875,7 +850,7 @@ scav_vector_bit(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 32) + 2, 2);
+    nwords = CEILING(NWORDS(length, 1) + 2, 2);
 
     return nwords;
 }
@@ -890,7 +865,7 @@ trans_vector_bit(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 32) + 2, 2);
+    nwords = CEILING(NWORDS(length, 1) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -903,7 +878,7 @@ size_vector_bit(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 32) + 2, 2);
+    nwords = CEILING(NWORDS(length, 1) + 2, 2);
 
     return nwords;
 }
@@ -916,7 +891,7 @@ scav_vector_unsigned_byte_2(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 16) + 2, 2);
+    nwords = CEILING(NWORDS(length, 2) + 2, 2);
 
     return nwords;
 }
@@ -931,7 +906,7 @@ trans_vector_unsigned_byte_2(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 16) + 2, 2);
+    nwords = CEILING(NWORDS(length, 2) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -944,7 +919,7 @@ size_vector_unsigned_byte_2(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 16) + 2, 2);
+    nwords = CEILING(NWORDS(length, 2) + 2, 2);
 
     return nwords;
 }
@@ -957,7 +932,7 @@ scav_vector_unsigned_byte_4(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 8) + 2, 2);
+    nwords = CEILING(NWORDS(length, 4) + 2, 2);
 
     return nwords;
 }
@@ -972,7 +947,7 @@ trans_vector_unsigned_byte_4(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 8) + 2, 2);
+    nwords = CEILING(NWORDS(length, 4) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -984,7 +959,7 @@ size_vector_unsigned_byte_4(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 8) + 2, 2);
+    nwords = CEILING(NWORDS(length, 4) + 2, 2);
 
     return nwords;
 }
@@ -998,7 +973,7 @@ scav_vector_unsigned_byte_8(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return nwords;
 }
@@ -1017,7 +992,7 @@ trans_vector_unsigned_byte_8(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -1030,7 +1005,7 @@ size_vector_unsigned_byte_8(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 4) + 2, 2);
+    nwords = CEILING(NWORDS(length, 8) + 2, 2);
 
     return nwords;
 }
@@ -1044,7 +1019,7 @@ scav_vector_unsigned_byte_16(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 2) + 2, 2);
+    nwords = CEILING(NWORDS(length, 16) + 2, 2);
 
     return nwords;
 }
@@ -1059,7 +1034,7 @@ trans_vector_unsigned_byte_16(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 2) + 2, 2);
+    nwords = CEILING(NWORDS(length, 16) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -1072,7 +1047,7 @@ size_vector_unsigned_byte_16(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(NWORDS(length, 2) + 2, 2);
+    nwords = CEILING(NWORDS(length, 16) + 2, 2);
 
     return nwords;
 }
@@ -1085,7 +1060,7 @@ scav_vector_unsigned_byte_32(lispobj *where, lispobj object)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(length + 2, 2);
+    nwords = CEILING(NWORDS(length, 32) + 2, 2);
 
     return nwords;
 }
@@ -1100,7 +1075,7 @@ trans_vector_unsigned_byte_32(lispobj object)
 
     vector = (struct vector *) native_pointer(object);
     length = fixnum_value(vector->length);
-    nwords = CEILING(length + 2, 2);
+    nwords = CEILING(NWORDS(length, 32) + 2, 2);
 
     return copy_large_unboxed_object(object, nwords);
 }
@@ -1113,11 +1088,54 @@ size_vector_unsigned_byte_32(lispobj *where)
 
     vector = (struct vector *) where;
     length = fixnum_value(vector->length);
-    nwords = CEILING(length + 2, 2);
+    nwords = CEILING(NWORDS(length, 32) + 2, 2);
 
     return nwords;
 }
 
+#if N_WORD_BITS == 64
+static int
+scav_vector_unsigned_byte_64(lispobj *where, lispobj object)
+{
+    struct vector *vector;
+    int length, nwords;
+
+    vector = (struct vector *) where;
+    length = fixnum_value(vector->length);
+    nwords = CEILING(NWORDS(length, 64) + 2, 2);
+
+    return nwords;
+}
+
+static lispobj
+trans_vector_unsigned_byte_64(lispobj object)
+{
+    struct vector *vector;
+    int length, nwords;
+
+    gc_assert(is_lisp_pointer(object));
+
+    vector = (struct vector *) native_pointer(object);
+    length = fixnum_value(vector->length);
+    nwords = CEILING(NWORDS(length, 64) + 2, 2);
+
+    return copy_large_unboxed_object(object, nwords);
+}
+
+static int
+size_vector_unsigned_byte_64(lispobj *where)
+{
+    struct vector *vector;
+    int length, nwords;
+
+    vector = (struct vector *) where;
+    length = fixnum_value(vector->length);
+    nwords = CEILING(NWORDS(length, 64) + 2, 2);
+
+    return nwords;
+}
+#endif
+
 static int
 scav_vector_single_float(lispobj *where, lispobj object)
 {
@@ -1543,12 +1561,26 @@ gc_init_tables(void)
        scav_vector_unsigned_byte_16;
     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
        scav_vector_unsigned_byte_16;
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_29_WIDETAG
     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
        scav_vector_unsigned_byte_32;
+#endif
     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
        scav_vector_unsigned_byte_32;
     scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
        scav_vector_unsigned_byte_32;
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
+    scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
+       scav_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
+    scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
+       scav_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
+    scavtab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
+       scav_vector_unsigned_byte_64;
+#endif
 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = scav_vector_unsigned_byte_8;
 #endif
@@ -1564,6 +1596,14 @@ gc_init_tables(void)
     scavtab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
        scav_vector_unsigned_byte_32;
 #endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
+    scavtab[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
+       scav_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
+    scavtab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
+       scav_vector_unsigned_byte_64;
+#endif
     scavtab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = scav_vector_single_float;
     scavtab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = scav_vector_double_float;
 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
@@ -1647,12 +1687,26 @@ gc_init_tables(void)
        trans_vector_unsigned_byte_16;
     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
        trans_vector_unsigned_byte_16;
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
        trans_vector_unsigned_byte_32;
+#endif
     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
        trans_vector_unsigned_byte_32;
     transother[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
        trans_vector_unsigned_byte_32;
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
+    transother[SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG] =
+       trans_vector_unsigned_byte_32;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
+    transother[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
+       trans_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
+    transother[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
+       trans_vector_unsigned_byte_64;
+#endif
 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
     transother[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] =
        trans_vector_unsigned_byte_8;
@@ -1669,6 +1723,14 @@ gc_init_tables(void)
     transother[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
        trans_vector_unsigned_byte_32;
 #endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
+    transother[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
+       trans_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
+    transother[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
+       trans_vector_unsigned_byte_64;
+#endif
     transother[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] =
        trans_vector_single_float;
     transother[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] =
@@ -1712,14 +1774,14 @@ gc_init_tables(void)
     for (i = 0; i < ((sizeof sizetab)/(sizeof sizetab[0])); i++)
        sizetab[i] = size_lose;
     for (i = 0; i < (1<<(N_WIDETAG_BITS-N_LOWTAG_BITS)); i++) {
-       sizetab[EVEN_FIXNUM_LOWTAG|(i<<3)] = size_immediate;
-       sizetab[FUN_POINTER_LOWTAG|(i<<3)] = size_pointer;
+       sizetab[EVEN_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = size_immediate;
+       sizetab[FUN_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
        /* skipping OTHER_IMMEDIATE_0_LOWTAG */
-       sizetab[LIST_POINTER_LOWTAG|(i<<3)] = size_pointer;
-       sizetab[ODD_FIXNUM_LOWTAG|(i<<3)] = size_immediate;
-       sizetab[INSTANCE_POINTER_LOWTAG|(i<<3)] = size_pointer;
+       sizetab[LIST_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
+       sizetab[ODD_FIXNUM_LOWTAG|(i<<N_LOWTAG_BITS)] = size_immediate;
+       sizetab[INSTANCE_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
        /* skipping OTHER_IMMEDIATE_1_LOWTAG */
-       sizetab[OTHER_POINTER_LOWTAG|(i<<3)] = size_pointer;
+       sizetab[OTHER_POINTER_LOWTAG|(i<<N_LOWTAG_BITS)] = size_pointer;
     }
     sizetab[BIGNUM_WIDETAG] = size_unboxed;
     sizetab[RATIO_WIDETAG] = size_boxed;
@@ -1755,12 +1817,26 @@ gc_init_tables(void)
        size_vector_unsigned_byte_16;
     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG] =
        size_vector_unsigned_byte_16;
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG
     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_29_WIDETAG] =
        size_vector_unsigned_byte_32;
+#endif
     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG] =
        size_vector_unsigned_byte_32;
     sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG] =
        size_vector_unsigned_byte_32;
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG
+    sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG] =
+       size_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
+    sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG] =
+       size_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
+    sizetab[SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG] =
+       size_vector_unsigned_byte_64;
+#endif
 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG] = size_vector_unsigned_byte_8;
 #endif
@@ -1776,6 +1852,14 @@ gc_init_tables(void)
     sizetab[SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG] =
        size_vector_unsigned_byte_32;
 #endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
+    sizetab[SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG] =
+       size_vector_unsigned_byte_64;
+#endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
+    sizetab[SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG] =
+       size_vector_unsigned_byte_64;
+#endif
     sizetab[SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG] = size_vector_single_float;
     sizetab[SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG] = size_vector_double_float;
 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
@@ -1815,3 +1899,25 @@ gc_init_tables(void)
     sizetab[INSTANCE_HEADER_WIDETAG] = size_boxed;
     sizetab[FDEFN_WIDETAG] = size_boxed;
 }
+
+\f
+/* Find the code object for the given pc, or return NULL on
+   failure. */
+lispobj *
+component_ptr_from_pc(lispobj *pc)
+{
+    lispobj *object = NULL;
+
+    if ( (object = search_read_only_space(pc)) )
+       ;
+    else if ( (object = search_static_space(pc)) )
+       ;
+    else
+       object = search_dynamic_space(pc);
+
+    if (object) /* if we found something */
+       if (widetag_of(*object) == CODE_HEADER_WIDETAG)
+           return(object);
+
+    return (NULL);
+}