[MLton-commit] r5517

Matthew Fluet fluet at mlton.org
Wed Apr 11 14:14:38 PDT 2007


Simplified GC_MODEL specification
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h	2007-04-11 21:14:37 UTC (rev 5517)
@@ -20,29 +20,28 @@
  * the number of elements in the array.  Array elements have the same
  * individual layout as normal objects, omitting the header word.
  */
-#ifdef GC_MODEL_NATIVE32
-typedef uint32_t GC_arrayLength;
+
+#define GC_ARRLEN_TYPE__(z) uint ## z ## _t
+#define GC_ARRLEN_TYPE_(z) GC_ARRLEN_TYPE__(z)
+#define GC_ARRLEN_TYPE GC_ARRLEN_TYPE_(GC_MODEL_ARRLEN_SIZE)
+typedef GC_ARRLEN_TYPE GC_arrayLength;
 #define GC_ARRAY_LENGTH_SIZE sizeof(GC_arrayLength)
-#define PRIxARRLEN PRIu32
+#define PRIxARRLEN__(z) PRIx ## z
+#define PRIxARRLEN_(z) PRIxARRLEN__(z)
+#define PRIxARRLEN PRIxARRLEN_(GC_MODEL_ARRLEN_SIZE)
 #define FMTARRLEN "%"PRIxARRLEN
 typedef GC_arrayLength GC_arrayCounter;
 #define GC_ARRAY_COUNTER_SIZE sizeof(GC_arrayCounter)
 #define PRIxARRCTR PRIxARRLEN
 #define FMTARRCTR "%"PRIxARRCTR
 #define GC_ARRAY_HEADER_SIZE (GC_ARRAY_COUNTER_SIZE + GC_ARRAY_LENGTH_SIZE + GC_HEADER_SIZE)
-#endif
-#ifdef GC_MODEL_NATIVE64
-typedef uint64_t GC_arrayLength;
-#define GC_ARRAY_LENGTH_SIZE sizeof(GC_arrayLength)
-#define PRIxARRLEN PRIu64
-#define FMTARRLEN "%"PRIxARRLEN
-typedef GC_arrayLength GC_arrayCounter;
-#define GC_ARRAY_COUNTER_SIZE sizeof(GC_arrayCounter)
-#define PRIxARRCTR PRIxARRLEN
-#define FMTARRCTR "%"PRIxARRCTR
-#define GC_ARRAY_HEADER_SIZE (GC_ARRAY_COUNTER_SIZE + GC_ARRAY_LENGTH_SIZE + GC_HEADER_SIZE)
-#endif
 
+COMPILE_TIME_ASSERT(sizeof_header__le__sizeof_arrlen,
+                    sizeof(GC_header) <= sizeof(GC_arrayLength));
+COMPILE_TIME_ASSERT(sizeof_arrlen__eq__sizeof_arrctr,
+                    sizeof(GC_arrayLength) == sizeof(GC_arrayCounter));
+
+
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
 
 #if (defined (MLTON_GC_INTERNAL_FUNCS))

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2007-04-11 21:14:37 UTC (rev 5517)
@@ -219,9 +219,10 @@
   char *worldFile;
   int res;
 
+  assert (s->alignment >= GC_MODEL_MINALIGN);
   assert (isAligned (sizeof (struct GC_stack), s->alignment));
   // While the following asserts are manifestly true,
-  // thye check the asserts in sizeofThread and sizeofWeak.
+  // they check the asserts in sizeofThread and sizeofWeak.
   assert (sizeofThread (s) == sizeofThread (s));
   assert (sizeofWeak (s) == sizeofWeak (s));
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c	2007-04-11 21:14:37 UTC (rev 5517)
@@ -11,7 +11,6 @@
 /* ---------------------------------------------------------------- */
 
 void copyForThreadInternal (pointer dst, pointer src) {
-
   if (OBJPTR_SIZE > GC_HEADER_SIZE) {
     size_t count;
 
@@ -36,7 +35,6 @@
       dst -= OBJPTR_SIZE;
       src += OBJPTR_SIZE;
     }
-
   } else /* (GC_HEADER_SIZE == OBJPTR_SIZE) */ {
     *((GC_header*)dst) = *((GC_header*)src);
   }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/model.h	2007-04-11 21:14:37 UTC (rev 5517)
@@ -137,75 +137,23 @@
 manageable set for users.
 */
 
-#if (defined (GC_MODEL_A) || defined (GC_MODEL_NATIVE32))
-#define GC_MODEL_BITSIZE  32
-#define GC_MODEL_SHIFT    0
-#define GC_MODEL_USEBASE  FALSE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_AX))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   0
-#define GC_MODEL_USEBASE TRUE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_B))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   1
-#define GC_MODEL_USEBASE FALSE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_BX))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   1
-#define GC_MODEL_USEBASE TRUE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_C))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   2
-#define GC_MODEL_USEBASE FALSE
-#define GC_MODEL_MINALIGN_SHIFT 3
-#elif (defined (GC_MODEL_CX))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   2
-#define GC_MODEL_USEBASE TRUE
-#define GC_MODEL_MINALIGN_SHIFT 3
-#elif (defined (GC_MODEL_D))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   2
-#define GC_MODEL_USEBASE FALSE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_DX))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   2
-#define GC_MODEL_USEBASE TRUE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_E))
-#define GC_MODEL_BITSIZE 32
-#define GC_MODEL_SHIFT   3
-#define GC_MODEL_USEBASE FALSE
-#define GC_MODEL_MINALIGN_SHIFT 3
-#elif (defined (GC_MODEL_EX))
-#define GC_MODEL_BITSIZE  32
-#define GC_MODEL_SHIFT    3
-#define GC_MODEL_USEBASE  TRUE
-#define GC_MODEL_MINALIGN_SHIFT 3
-#elif (defined (GC_MODEL_F))
-#define GC_MODEL_BITSIZE  40
-#define GC_MODEL_SHIFT    0
-#define GC_MODEL_USEBASE  FALSE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_FX))
-#define GC_MODEL_BITSIZE  40
-#define GC_MODEL_SHIFT    0
-#define GC_MODEL_USEBASE  TRUE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#elif (defined (GC_MODEL_G) || defined (GC_MODEL_NATIVE64))
-#define GC_MODEL_BITSIZE  64
-#define GC_MODEL_SHIFT    0
-#define GC_MODEL_USEBASE  FALSE
-#define GC_MODEL_MINALIGN_SHIFT 2
-#else 
-#error gc model unknown
+#if defined (GC_MODEL_NATIVE32)
+#define GC_MODEL_OBJPTR_SIZE 32
+#define GC_MODEL_OBJPTR_SHIFT 0
+#define GC_MODEL_OBJPTR_BASE 0
+#define GC_MODEL_HEADER_SIZE 32
+#define GC_MODEL_ARRLEN_SIZE 32
+#elif defined (GC_MODEL_NATIVE64)
+#define GC_MODEL_OBJPTR_SIZE 64
+#define GC_MODEL_OBJPTR_SHIFT 0
+#define GC_MODEL_OBJPTR_BASE 0
+#define GC_MODEL_HEADER_SIZE 64
+#define GC_MODEL_ARRLEN_SIZE 64
+#else
+#error GC_MODEL_* unspecified
 #endif
-#define GC_MODEL_NONOBJPTR ((GC_MODEL_MINALIGN_SHIFT - GC_MODEL_SHIFT) > 0)
+
+#define GC_MODEL_MINALIGN_SHIFT max(2, GC_MODEL_OBJPTR_SHIFT + 1)
 #define GC_MODEL_MINALIGN TWOPOWER(GC_MODEL_MINALIGN_SHIFT)
 
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h	2007-04-11 21:14:37 UTC (rev 5517)
@@ -40,23 +40,20 @@
  *      31   : mark bit, used by mark compact GC (initially 0)
  * 32 - 63   : 0wx00000000  (only w/ 64-bit header)
  */
-#ifdef GC_MODEL_NATIVE32
-typedef uint32_t GC_header;
+
+#define GC_HEADER_TYPE__(z) uint ## z ## _t
+#define GC_HEADER_TYPE_(z) GC_HEADER_TYPE__(z)
+#define GC_HEADER_TYPE GC_HEADER_TYPE_(GC_MODEL_HEADER_SIZE)
+typedef GC_HEADER_TYPE GC_header;
 #define GC_HEADER_SIZE sizeof(GC_header)
-#define PRIxHDR PRIx32
-#define FMTHDR "0x%08"PRIxHDR
-#endif
-#ifdef GC_MODEL_NATIVE64
-typedef uint64_t GC_header;
-#define GC_HEADER_SIZE sizeof(GC_header)
-#define PRIxHDR PRIx64
-#define FMTHDR "0x%08"PRIxHDR
-#endif
-#ifdef GC_HEADER_SIZE
-#else
-#error GC_header undefined
-#endif
+#define PRIxHDR__(z) PRIx ## z
+#define PRIxHDR_(z) PRIxHDR__(z)
+#define PRIxHDR PRIxHDR_(GC_MODEL_HEADER_SIZE)
+#define FMTHDR "%08"PRIxHDR
 
+COMPILE_TIME_ASSERT(sizeof_objptr__eq__sizeof_header,
+                    sizeof(objptr) == sizeof(GC_header));
+
 #define GC_VALID_HEADER_MASK ((GC_header)0x1)
 #define TYPE_INDEX_BITS    19
 #define TYPE_INDEX_MASK    ((GC_header)0x000FFFFE)

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.c	2007-04-11 21:14:37 UTC (rev 5517)
@@ -7,23 +7,19 @@
 
 /* isObjptr returns true if p looks like an object pointer. */
 bool isObjptr (objptr p) {
-  if GC_MODEL_NONOBJPTR {
-    unsigned int shift = GC_MODEL_MINALIGN_SHIFT - GC_MODEL_SHIFT;
-    objptr mask = ~((~((objptr)0)) << shift);
-    return (0 == (p & mask));
-  } else {
-    return TRUE;
-  }
+  unsigned int shift = GC_MODEL_MINALIGN_SHIFT - GC_MODEL_OBJPTR_SHIFT;
+  objptr mask = ~((~((objptr)0)) << shift);
+  return (0 == (p & mask));
 }
 
 pointer objptrToPointer (objptr O, pointer B) {
   uintptr_t O_ = (uintptr_t)O;
   uintptr_t B_;
-  unsigned int S_ = GC_MODEL_SHIFT;
+  unsigned int S_ = GC_MODEL_OBJPTR_SHIFT;
   uintptr_t P_;
   pointer P;
 
-  if (GC_MODEL_USEBASE) {
+  if (GC_MODEL_OBJPTR_BASE) {
     B_ = (uintptr_t)B;
   } else {
     B_ = 0;
@@ -40,11 +36,11 @@
 objptr pointerToObjptr (pointer P, pointer B) {
   uintptr_t P_ = (uintptr_t)P;
   uintptr_t B_;
-  unsigned int S_ = GC_MODEL_SHIFT;
+  unsigned int S_ = GC_MODEL_OBJPTR_SHIFT;
   uintptr_t O_;
   objptr O;
 
-  if (GC_MODEL_USEBASE) {
+  if (GC_MODEL_OBJPTR_BASE) {
     B_ = (uintptr_t)B;
   } else {
     B_ = 0;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/objptr.h	2007-04-11 21:14:37 UTC (rev 5517)
@@ -9,19 +9,18 @@
 
 #define OBJPTR_TYPE__(z) uint ## z ## _t
 #define OBJPTR_TYPE_(z) OBJPTR_TYPE__(z)
-#define OBJPTR_TYPE OBJPTR_TYPE_(GC_MODEL_BITSIZE)
+#define OBJPTR_TYPE OBJPTR_TYPE_(GC_MODEL_OBJPTR_SIZE)
 typedef OBJPTR_TYPE objptr;
 #define OBJPTR_SIZE sizeof(objptr)
 #define PRIxOBJPTR__(z) PRIx ## z
 #define PRIxOBJPTR_(z) PRIxOBJPTR__(z)
-#define PRIxOBJPTR PRIxOBJPTR_(GC_MODEL_BITSIZE)
+#define PRIxOBJPTR PRIxOBJPTR_(GC_MODEL_OBJPTR_SIZE)
 #define FMTOBJPTR "0x%016"PRIxOBJPTR
 
-#if GC_MODEL_NONOBJPTR
+COMPILE_TIME_ASSERT(sizeof_voidStar__gte__sizeof_objptr,
+                    sizeof(void*) >= sizeof(objptr));
+
 #define BOGUS_OBJPTR (objptr)0x1
-#else
-#error gc model does not admit bogus object pointer
-#endif
 
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc.c	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc.c	2007-04-11 21:14:37 UTC (rev 5517)
@@ -10,7 +10,6 @@
 #define MLTON_GC_INTERNAL_FUNCS
 #define MLTON_GC_INTERNAL_BASIS
 #include "platform.h"
-#include "gc/rusage.h"
 
 #include "gc/virtual-memory.c"
 #include "gc/align.c"

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2007-04-11 21:01:44 UTC (rev 5516)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2007-04-11 21:14:37 UTC (rev 5517)
@@ -9,13 +9,8 @@
 #ifndef _MLTON_GC_H_
 #define _MLTON_GC_H_
 
-#include "cenv.h"
-#include "util.h"
-#include "ml-types.h"
-#include "c-types.h"
+#include "platform.h"
 
-#include "gc/debug.h"
-
 struct GC_state;
 typedef struct GC_state *GC_state;
 typedef GC_state GCState_t;
@@ -26,12 +21,14 @@
 #elif __WORDSIZE == 64
 #define GC_MODEL_NATIVE64
 #else
-#error __WORDSIZE unknown
+#error unknown __WORDSIZE
 #endif
 #else
 #define GC_MODEL_NATIVE32
 #endif
 
+#include "gc/debug.h"
+
 #include "gc/align.h"
 #include "gc/model.h"
 #include "gc/pointer.h"
@@ -71,6 +68,7 @@
 #include "gc/sources.h"
 #include "gc/call-stack.h"
 #include "gc/profiling.h"
+#include "gc/rusage.h"
 #include "gc/gc_state.h"
 #include "gc/init-world.h"
 #include "gc/world.h"




More information about the MLton-commit mailing list