0.8.15.17
[sbcl.git] / src / runtime / purify.c
index db80505..e212972 100644 (file)
 #include <strings.h>
 #include <errno.h>
 
+#include "sbcl.h"
 #include "runtime.h"
 #include "os.h"
-#include "sbcl.h"
 #include "globals.h"
 #include "validate.h"
 #include "interrupt.h"
 #include "purify.h"
 #include "interr.h"
+#include "fixnump.h"
 #include "gc.h"
 #include "gc-internal.h"
 #include "thread.h"
 
 #define PRINTNOISE
 
-#if defined(LISP_FEATURE_X86)
-/* again, what's so special about the x86 that this is differently
- * visible there than on other platforms? -dan 20010125 
+#if defined(LISP_FEATURE_GENCGC)
+/* this is another artifact of the poor integration between gencgc and
+ * the rest of the runtime: on cheney gc there is a global
+ * dynamic_space_free_pointer which is valid whenever foreign function
+ * call is active, but in gencgc there's no such variable and we have
+ * to keep our own
  */
 static lispobj *dynamic_space_free_pointer;
 #endif
@@ -77,9 +81,6 @@ later {
 } *later_blocks = NULL;
 static int later_count = 0;
 
-#define CEILING(x,y) (((x) + ((y) - 1)) & (~((y) - 1)))
-#define NWORDS(x,y) (CEILING((x),(y)) / (y))
-
 /* FIXME: Shouldn't this be defined in sbcl.h?  See also notes in
  * cheneygc.c */
 
@@ -113,7 +114,8 @@ dynamic_pointer_p(lispobj ptr)
 #endif
 }
 
-static inline newspace_alloc(int nwords, int constantp) 
+static inline lispobj *
+newspace_alloc(int nwords, int constantp) 
 {
     lispobj *ret;
     nwords=CEILING(nwords,2);
@@ -735,7 +737,11 @@ ptrans_code(lispobj thing)
     pscav_later(&new->debug_info, 1);
 
     /* FIXME: why would this be a fixnum? */
-    if (!(new->trace_table_offset & (EVEN_FIXNUM_LOWTAG|ODD_FIXNUM_LOWTAG)))
+    /* "why" is a hard word, but apparently for compiled functions the
+       trace_table_offset contains the length of the instructions, as
+       a fixnum.  See CODE-INST-AREA-LENGTH in
+       src/compiler/target-disassem.lisp.  -- CSR, 2004-01-08 */
+    if (!(fixnump(new->trace_table_offset)))
 #if 0
        pscav(&new->trace_table_offset, 1, 0);
 #else
@@ -852,7 +858,7 @@ ptrans_list(lispobj thing, boolean constant)
     struct cons *old, *new, *orig;
     int length;
 
-    orig = newspace_alloc(0,constant);
+    orig = (struct cons *) newspace_alloc(0,constant);
     length = 0;
 
     do {
@@ -1143,22 +1149,22 @@ pscav(lispobj *addr, int nwords, boolean constant)
 
               case SIMPLE_BASE_STRING_WIDETAG:
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length)+1,4)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length)+1,8)+2,2);
                 break;
 
               case SIMPLE_BIT_VECTOR_WIDETAG:
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),1)+2,2);
                 break;
 
               case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
                 break;
 
               case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
                 break;
 
               case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
@@ -1167,7 +1173,7 @@ pscav(lispobj *addr, int nwords, boolean constant)
               case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
 #endif
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length),4)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),8)+2,2);
                 break;
 
               case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
@@ -1176,7 +1182,7 @@ pscav(lispobj *addr, int nwords, boolean constant)
               case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
 #endif
                 vector = (struct vector *)addr;
-                count = CEILING(NWORDS(fixnum_value(vector->length),2)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),16)+2,2);
                 break;
 
               case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
@@ -1189,9 +1195,24 @@ pscav(lispobj *addr, int nwords, boolean constant)
               case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
 #endif
                 vector = (struct vector *)addr;
-                count = CEILING(fixnum_value(vector->length)+2,2);
+                count = CEILING(NWORDS(fixnum_value(vector->length),32)+2,2);
                 break;
 
+#if N_WORD_BITS == 64
+              case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG
+              case SIMPLE_ARRAY_SIGNED_BYTE_61_WIDETAG:
+              case SIMPLE_ARRAY_UNSIGNED_BYTE_60_WIDETAG:
+#endif
+#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
+              case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
+              case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
+#endif
+                vector = (struct vector *)addr;
+                count = CEILING(NWORDS(fixnum_value(vector->length),64)+2,2);
+                break;
+#endif
+
               case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
                 vector = (struct vector *)addr;
                 count = CEILING(fixnum_value(vector->length)+2,2);
@@ -1475,7 +1496,7 @@ purify(lispobj static_roots, lispobj read_only_roots)
     SetSymbolValue(READ_ONLY_SPACE_FREE_POINTER, (lispobj)read_only_free,0);
     SetSymbolValue(STATIC_SPACE_FREE_POINTER, (lispobj)static_free,0);
 
-#if !defined(LISP_FEATURE_X86)
+#if !defined(ALLOCATION_POINTER)
     dynamic_space_free_pointer = current_dynamic_space;
     set_auto_gc_trigger(bytes_consed_between_gcs);
 #else