[MLton-commit] r5411

Matthew Fluet fluet at mlton.org
Fri Mar 9 21:46:15 PST 2007


Getting -align 8 to work on amd64-linux.
This requires adding padding to the beginning of thread objects.

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

U   mlton/branches/on-20050822-x86_64-branch/mlton/backend/rep-type.fun
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/copy-thread.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/init-world.c
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/new-object.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.h

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

Modified: mlton/branches/on-20050822-x86_64-branch/mlton/backend/rep-type.fun
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/mlton/backend/rep-type.fun	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/mlton/backend/rep-type.fun	2007-03-10 05:46:12 UTC (rev 5411)
@@ -114,6 +114,7 @@
       val thread : unit -> t = fn () => 
          objptr ObjptrTycon.thread
 
+      val word0: t = word (Bits.fromInt 0)
       val word32: t = word (WordSize.bits WordSize.word32)
 
       val wordVector: Bits.t -> t = objptr o ObjptrTycon.wordVector
@@ -367,10 +368,23 @@
       val stack = Stack
 
       val thread = fn () =>
-         Normal {hasIdentity = true,
-                 ty = Type.seq (Vector.new3 (Type.csize (),
-                                             Type.exnStack (),
-                                             Type.stack ()))}
+         let
+            val padding =
+               case (!Control.align,
+                     Bits.toInt (Control.Target.Size.csize ()),
+                     Bits.toInt (Control.Target.Size.objptr ())) of
+                  (Control.Align4,32,32) => Type.word0
+                | (Control.Align8,32,32) => Type.word0
+                | (Control.Align4,64,64) => Type.word0
+                | (Control.Align8,64,64) => Type.word32
+                | _ => Error.bug "RepType.ObjectType.thread"
+         in
+            Normal {hasIdentity = true,
+                    ty = Type.seq (Vector.new4 (padding,
+                                                Type.csize (),
+                                                Type.exnStack (),
+                                                Type.stack ()))}
+         end
 
       (* Order in the following vector matters.  The basic pointer tycons must
        * correspond to the constants in 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-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/array.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -11,9 +11,9 @@
 /*
  * Array objects have the following layout:
  * 
- * counter word32 :: 
- * length word32 :: 
- * header word32 :: 
+ * counter :: 
+ * length :: 
+ * header :: 
  * ( (non heap-pointers)* :: (heap pointers)* )*
  *
  * The counter word is used by mark compact GC.  The length word is

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -29,7 +29,7 @@
     } else {
       if (DEBUG_WEAK)
         fprintf (stderr, "cleared\n");
-      *(getHeaderp((pointer)w - (offsetofWeak(s)))) = GC_WEAK_GONE_HEADER;
+      *(getHeaderp((pointer)w - offsetofWeak (s))) = GC_WEAK_GONE_HEADER;
       w->objptr = BOGUS_OBJPTR;
     }
   }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/copy-thread.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/copy-thread.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/copy-thread.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -14,9 +14,11 @@
   /* newThread may do a GC, which invalidates from.
    * Hence we need to stash from where the GC can find it.
    */
-  s->savedThread = pointerToObjptr((pointer)from, s->heap.start);
+  assert (s->savedThread == BOGUS_OBJPTR);
+  s->savedThread = pointerToObjptr((pointer)from - offsetofThread (s), s->heap.start);
   to = newThread (s, size);
-  from = (GC_thread)(objptrToPointer(s->savedThread, s->heap.start));
+  from = (GC_thread)(objptrToPointer(s->savedThread, s->heap.start) 
+                     + offsetofThread (s));
   s->savedThread = BOGUS_OBJPTR;
   if (DEBUG_THREADS) {
     fprintf (stderr, FMTPTR" = copyThread ("FMTPTR")\n",
@@ -39,10 +41,11 @@
   if (DEBUG_THREADS)
     fprintf (stderr, "GC_copyCurrentThread\n");
   enter (s);
-  fromThread = (GC_thread)(objptrToPointer(s->currentThread, s->heap.start));
-  fromStack = (GC_stack)(objptrToPointer((objptr)(fromThread->stack), s->heap.start));
+  fromThread = (GC_thread)(objptrToPointer(s->currentThread, s->heap.start) 
+                           + offsetofThread (s));
+  fromStack = (GC_stack)(objptrToPointer(fromThread->stack, s->heap.start));
   toThread = copyThread (s, fromThread, fromStack->used);
-  toStack = (GC_stack)(objptrToPointer((objptr)(toThread->stack), s->heap.start));
+  toStack = (GC_stack)(objptrToPointer(toThread->stack, s->heap.start));
   /* The following assert is no longer true, since alignment
    * restrictions can force the reserved to be slightly larger than
    * the used.
@@ -52,7 +55,8 @@
   leave (s);
   if (DEBUG_THREADS)
     fprintf (stderr, FMTPTR" = GC_copyCurrentThread\n", (uintptr_t)toThread);
-  s->savedThread = pointerToObjptr((pointer)toThread, s->heap.start);
+  assert (s->savedThread == BOGUS_OBJPTR);
+  s->savedThread = pointerToObjptr((pointer)toThread - offsetofThread (s), s->heap.start);
 }
 
 pointer GC_copyThread (GC_state s, pointer p) {
@@ -64,8 +68,8 @@
   if (DEBUG_THREADS)
     fprintf (stderr, "GC_copyThread ("FMTPTR")\n", (uintptr_t)p);
   enter (s);
-  fromThread = (GC_thread)p;
-  fromStack = (GC_stack)(objptrToPointer((objptr)(fromThread->stack), s->heap.start));
+  fromThread = (GC_thread)(p + offsetofThread (s));
+  fromStack = (GC_stack)(objptrToPointer(fromThread->stack, s->heap.start));
   /* The following assert is no longer true, since alignment
    * restrictions can force the reserved to be slightly larger than
    * the used.
@@ -77,12 +81,12 @@
    * restrictions can force the reserved to be slightly larger than
    * the used.
    */
-  toStack = (GC_stack)(objptrToPointer((objptr)(toThread->stack), s->heap.start));
+  toStack = (GC_stack)(objptrToPointer(toThread->stack, s->heap.start));
   /* assert (fromStack->reserved == fromStack->used); */
   assert (fromStack->reserved >= fromStack->used);
   leave (s);
   if (DEBUG_THREADS)
     fprintf (stderr, FMTPTR" = GC_copyThread ("FMTPTR")\n", 
              (uintptr_t)toThread, (uintptr_t)fromThread);
-  return (pointer)toThread;
+  return ((pointer)toThread - offsetofThread (s));
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -12,7 +12,7 @@
 
 GC_thread getThreadCurrent (GC_state s) {
   pointer p = objptrToPointer(getThreadCurrentObjptr(s), s->heap.start);
-  return (GC_thread)p;
+  return (GC_thread)(p + offsetofThread (s));
 }
 
 objptr getStackCurrentObjptr (GC_state s) {

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/foreach.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -189,6 +189,7 @@
                  "  front = "FMTPTR"  *back = "FMTPTR"\n",
                  (uintptr_t)front, (uintptr_t)(*back));
       pointer p = advanceToObjectData (s, front);
+      assert (isAligned ((size_t)p, s->alignment));
       front = foreachObjptrInObject (s, p, f, skipWeaks);
     }
     b = *back;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/forward.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -110,7 +110,7 @@
     if ((WEAK_TAG == tag) and (numObjptrs == 1)) {
       GC_weak w;
 
-      w = (GC_weak)(s->forwardState.back + GC_NORMAL_HEADER_SIZE + (offsetofWeak (s)));
+      w = (GC_weak)(s->forwardState.back + GC_NORMAL_HEADER_SIZE + offsetofWeak (s));
       if (DEBUG_WEAK)
         fprintf (stderr, "forwarding weak "FMTPTR" ",
                  (uintptr_t)w);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -10,7 +10,8 @@
   fprintf (stream,
            "GC state\n");
   fprintf (stream, "\tcurrentThread = "FMTOBJPTR"\n", s->currentThread);
-  displayThread (s, (GC_thread)(objptrToPointer (s->currentThread, s->heap.start)), 
+  displayThread (s, (GC_thread)(objptrToPointer (s->currentThread, s->heap.start)
+                                + offsetofThread (s)), 
                  stream);
   fprintf (stream, "\tgenerational\n");
   displayGenerationalMaps (s, &s->generationalMaps, 
@@ -155,28 +156,28 @@
   s->signalsInfo.gcSignalPending = b;
 }
 
-void GC_setCallFromCHandlerThread (GC_state s, GC_thread t) {
-  objptr op = pointerToObjptr ((pointer)t, s->heap.start);
+void GC_setCallFromCHandlerThread (GC_state s, pointer p) {
+  objptr op = pointerToObjptr (p, s->heap.start);
   s->callFromCHandlerThread = op;
 }
 
-GC_thread GC_getCurrentThread (GC_state s) {
+pointer GC_getCurrentThread (GC_state s) {
   pointer p = objptrToPointer (s->currentThread, s->heap.start);
-  return (GC_thread)p;
+  return p;
 }
 
-GC_thread GC_getSavedThread (GC_state s) {
+pointer GC_getSavedThread (GC_state s) {
   pointer p = objptrToPointer (s->savedThread, s->heap.start);
   s->savedThread = BOGUS_OBJPTR;
-  return (GC_thread)p;
+  return p;
 }
 
-void GC_setSavedThread (GC_state s, GC_thread t) {
-  objptr op = pointerToObjptr ((pointer)t, s->heap.start);
+void GC_setSavedThread (GC_state s, pointer p) {
+  objptr op = pointerToObjptr (p, s->heap.start);
   s->savedThread = op;
 }
 
-void GC_setSignalHandlerThread (GC_state s, GC_thread t) {
-  objptr op = pointerToObjptr ((pointer)t, s->heap.start);
+void GC_setSignalHandlerThread (GC_state s, pointer p) {
+  objptr op = pointerToObjptr (p, s->heap.start);
   s->signalHandlerThread = op;
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/gc_state.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -92,11 +92,11 @@
 void GC_setRusageMeasureGC (GC_state s, bool b);
 void GC_setHashConsDuringGC (GC_state s, bool b);
 
-GC_thread GC_getCurrentThread (GC_state s);
-GC_thread GC_getSavedThread (GC_state s);
-void GC_setCallFromCHandlerThread (GC_state s, GC_thread thread);
-void GC_setSavedThread (GC_state s, GC_thread thread);
-void GC_setSignalHandlerThread (GC_state s, GC_thread thread);
+pointer GC_getCurrentThread (GC_state s);
+pointer GC_getSavedThread (GC_state s);
+void GC_setCallFromCHandlerThread (GC_state s, pointer p);
+void GC_setSavedThread (GC_state s, pointer p);
+void GC_setSignalHandlerThread (GC_state s, pointer p);
 
 #endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/init-world.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/init-world.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/init-world.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -155,6 +155,6 @@
   s->heap.oldGenSize = s->frontier - s->heap.start;
   setGCStateCurrentHeap (s, 0, 0);
   thread = newThread (s, sizeofStackInitial (s));
-  switchToThread (s, pointerToObjptr((pointer)thread, s->heap.start));
+  switchToThread (s, pointerToObjptr((pointer)thread - offsetofThread (s), s->heap.start));
 }
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/init.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -220,10 +220,9 @@
   int res;
 
   assert (isAligned (sizeof (struct GC_stack), s->alignment));
-  assert (isAligned (GC_NORMAL_HEADER_SIZE + sizeof (struct GC_thread),
-                     s->alignment));
-  // While the following assert is manifestly true,
-  // it checks the asserts in sizeofWeak.
+  // While the following asserts are manifestly true,
+  // thye check the asserts in sizeofThread and sizeofWeak.
+  assert (sizeofThread (s) == sizeofThread (s));
   assert (sizeofWeak (s) == sizeofWeak (s));
 
   s->amInGC = TRUE;

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-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/mark-compact.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -77,7 +77,7 @@
     if (DEBUG_MARK_COMPACT or DEBUG_WEAK)
       fprintf (stderr, "clearIfWeakAndUnmarkedForMarkCompact ("FMTPTR")  header = "FMTHDR"\n",
                (uintptr_t)p, header);
-    w = (GC_weak)(p + (offsetofWeak(s)));
+    w = (GC_weak)(p + offsetofWeak (s));
     objptrHeader = getHeader (objptrToPointer(w->objptr, s->heap.start));
     /* If it's not threaded and unmarked, clear the weak pointer. */
     if ((GC_VALID_HEADER_MASK & objptrHeader)

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/new-object.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/new-object.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/new-object.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -70,12 +70,14 @@
 GC_thread newThread (GC_state s, size_t reserved) {
   GC_stack stack;
   GC_thread thread;
+  pointer res;
 
   ensureHasHeapBytesFree (s, 0, sizeofStackWithHeaderAligned (s, reserved) + sizeofThread (s));
   stack = newStack (s, reserved, FALSE);
-  thread = (GC_thread)(newObject (s, GC_THREAD_HEADER, 
-                                  sizeofThread (s), 
-                                  FALSE));
+  res = newObject (s, GC_THREAD_HEADER, 
+                   sizeofThread (s), 
+                   FALSE);
+  thread = (GC_thread)(res + offsetofThread (s));
   thread->bytesNeeded = 0;
   thread->exnStack = BOGUS_EXN_STACK;
   thread->stack = pointerToObjptr((pointer)stack, s->heap.start);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/object.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -38,6 +38,7 @@
  * 01 - 19   : type index bits, index into GC_state->objectTypes.
  * 20 - 30   : counter bits, used by mark compact GC (initially 0)
  *      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;
@@ -83,7 +84,7 @@
 /*
  * Normal objects have the following layout:
  *
- * header word32 :: 
+ * header :: 
  * (non heap-pointers)* :: 
  * (heap pointers)*
  *

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -11,19 +11,18 @@
 /*
  * Stack objects have the following layout:
  * 
- * header word32 ::
- * markTop native-pointer ::
- * markIndex word32 ::
+ * header ::
+ * markTop (native-pointer) ::
+ * markIndex (word32) ::
  * reserved ::
  * used ::
  * ... reserved bytes ...
  *
- * The markTop native-pointer and markIndex word32 are used by mark
- * compact GC.  The reserved size gives the number of bytes for the
- * stack (before the next ML object).  The used size gives the number
- * of bytes currently used by the stack.  The sequence of reserved
- * bytes correspond to ML stack frames, which will be discussed in
- * more detail in "frame.h".
+ * The markTop and markIndex are used by the mark-compact GC.  The
+ * reserved size gives the number of bytes for the stack (before the
+ * next ML object).  The used size gives the number of bytes currently
+ * used by the stack.  The sequence of reserved bytes correspond to ML
+ * stack frames, which will be discussed in more detail in "frame.h".
 */
 typedef struct GC_stack {       
   /* markTop and markIndex are only used during marking.  They record

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -11,7 +11,8 @@
     GC_thread thread;
     GC_stack stack;
 
-    thread = (GC_thread)(objptrToPointer (op, s->heap.start));
+    thread = (GC_thread)(objptrToPointer (op, s->heap.start)
+                         + offsetofThread (s));
     stack = (GC_stack)(objptrToPointer (thread->stack, s->heap.start));
 
     fprintf (stderr, "switchToThread ("FMTOBJPTR")  used = %zu  reserved = %zu\n",
@@ -21,10 +22,10 @@
   setGCStateCurrentThreadAndStack (s);
 }
 
-void GC_switchToThread (GC_state s, GC_thread t, size_t ensureBytesFree) {
+void GC_switchToThread (GC_state s, pointer p, size_t ensureBytesFree) {
   if (DEBUG_THREADS)
     fprintf (stderr, "GC_switchToThread ("FMTPTR", %zu)\n", 
-             (uintptr_t)t, ensureBytesFree);
+             (uintptr_t)p, ensureBytesFree);
   if (FALSE) {
     /* This branch is slower than the else branch, especially
      * when debugging is turned on, because it does an invariant
@@ -33,7 +34,7 @@
      */
     enter (s);
     getThreadCurrent(s)->bytesNeeded = ensureBytesFree;
-    switchToThread (s, pointerToObjptr((pointer)t, s->heap.start));
+    switchToThread (s, pointerToObjptr(p, s->heap.start));
     s->atomicState--;
     switchToSignalHandlerThreadIfNonAtomicAndSignalPending (s);
     ensureInvariantForMutator (s, FALSE);
@@ -47,7 +48,7 @@
     beginAtomic (s);
     /* END: enter(s); */
     getThreadCurrent(s)->bytesNeeded = ensureBytesFree;
-    switchToThread (s, pointerToObjptr((pointer)t, s->heap.start));
+    switchToThread (s, pointerToObjptr(p, s->heap.start));
     s->atomicState--;
     switchToSignalHandlerThreadIfNonAtomicAndSignalPending (s);
     /* BEGIN: ensureInvariantForMutator */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/switch-thread.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -14,6 +14,6 @@
 
 #if (defined (MLTON_GC_INTERNAL_BASIS))
 
-void GC_switchToThread (GC_state s, GC_thread t, size_t ensureBytesFree);
+void GC_switchToThread (GC_state s, pointer p, size_t ensureBytesFree);
 
 #endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -24,6 +24,7 @@
   size_t res;
 
   res = GC_NORMAL_HEADER_SIZE + sizeof (struct GC_thread);
+  res = align (res, s->alignment);
   if (DEBUG) {
     size_t check;
     uint16_t bytesNonObjptrs, numObjptrs;
@@ -36,12 +37,10 @@
                res, check);
     assert (check == res);
   }
-  /* The following assert depends on struct GC_thread being the right
-   * size.  Right now, it happens that res = 16, which is aligned mod
-   * 4 and mod 8, which is all that we need.  If the struct ever
-   * changes (possible) or we need more alignment (doubtful), we may
-   * need to put some padding at the beginning.
-   */
   assert (isAligned (res, s->alignment));
   return res;
 }
+
+size_t offsetofThread (GC_state s) {
+  return (sizeofThread (s)) - (GC_NORMAL_HEADER_SIZE + sizeof (struct GC_thread));
+}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/thread.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -8,18 +8,33 @@
 
 #if (defined (MLTON_GC_INTERNAL_TYPES))
 
+/*
+ * Thread objects are normal objects with the following layout:
+ * 
+ * header ::
+ * padding ::
+ * bytesNeeded (size_t) ::
+ * exnStack (word32) ::
+ * stack (object-pointer)
+ *
+ * There may be zero or more bytes of padding for alignment purposes.
+ *
+ * The bytesNeeded size_t is the number of bytes needed when returning
+ * to this thread.
+ *
+ * The exnStack uint32_t is an offset added to stackBottom that
+ * specifies the top of the exnStack.
+ *
+ * The final component is the stack object-pointer.
+ *
+ * Note that the order of the fields is important.  The non-objptr
+ * fields must be first, because a thread object must appear to be a
+ * normal object.
+ */
 typedef struct GC_thread {
-  /* The order of these fields is important.  The nonpointer fields
-   * must be first, because this object must appear to be a normal
-   * heap object.
-   */
-  size_t bytesNeeded; /* The number of bytes needed when returning
-                       * to this thread.
-                       */
-  uint32_t exnStack;  /* An offset added to stackBottom that specifies 
-                       * where the top of the exnStack is.
-                       */
-  objptr stack;       /* The stack for this thread. */
+  size_t bytesNeeded;
+  uint32_t exnStack;
+  objptr stack;
 } __attribute__ ((packed)) *GC_thread;
 
 COMPILE_TIME_ASSERT(GC_thread__packed,
@@ -41,5 +56,6 @@
 
 static void displayThread (GC_state s, GC_thread thread, FILE *stream);
 static inline size_t sizeofThread (GC_state s);
+static inline size_t offsetofThread (GC_state s);
 
 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c	2007-03-10 05:46:12 UTC (rev 5411)
@@ -17,6 +17,10 @@
 
     splitHeader (s, GC_WEAK_GONE_HEADER, NULL, NULL, &bytesNonObjptrs, &numObjptrs);
     check = GC_NORMAL_HEADER_SIZE + (bytesNonObjptrs + (numObjptrs * OBJPTR_SIZE));
+    if (DEBUG_DETAILED) 
+      fprintf (stderr,
+               "sizeofWeak: res = %zu  check = %zu\n",
+               res, check);
     assert (check == res);
   }
   assert (isAligned (res, s->alignment));
@@ -41,7 +45,7 @@
   GC_weak weak;
   pointer res;
 
-  weak = (GC_weak)(p + (offsetofWeak (s)));
+  weak = (GC_weak)(p + offsetofWeak (s));
   res = objptrToPointer(weak->objptr, s->heap.start);
   if (DEBUG_WEAK)
     fprintf (stderr, FMTPTR" = GC_weakGet ("FMTPTR")\n",
@@ -56,7 +60,7 @@
   res = newObject (s, header, 
                    sizeofWeak (s),
                    FALSE);
-  weak = (GC_weak)(res + (offsetofWeak (s)));
+  weak = (GC_weak)(res + offsetofWeak (s));
   weak->objptr = pointerToObjptr(p, s->heap.start);
   if (DEBUG_WEAK)
     fprintf (stderr, FMTPTR" = GC_weakNew ("FMTHDR", "FMTPTR")\n",

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.h	2007-03-09 15:40:00 UTC (rev 5410)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.h	2007-03-10 05:46:12 UTC (rev 5411)
@@ -11,10 +11,10 @@
 /*
  * Weak objects have the following layout:
  * 
- * header word32 ::
+ * header ::
  * padding ::
- * link native-pointer ::
- * object-pointer
+ * link (native-pointer) ::
+ * objptr (object-pointer)
  *
  * The object type indexed by the header determines whether the weak
  * is valid or not.  If the type has numObjptrs == 1, then the weak
@@ -27,12 +27,21 @@
  * during a copying gc and is otherwise unused.
  *
  * The final component is the weak object-pointer.
+ *
+ * Note that the order of the fields is important.  The non-objptr
+ * field must be first, because a weak object is sometimes treated as
+ * a normal object.
  */ 
 typedef struct GC_weak {
   struct GC_weak *link;
   objptr objptr;
 } *GC_weak;
 
+COMPILE_TIME_ASSERT(GC_weak__packed,
+                    sizeof(struct GC_weak) ==
+                    sizeof(struct GC_weak*)
+                    + sizeof(objptr));
+
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
 
 #if (defined (MLTON_GC_INTERNAL_FUNCS))




More information about the MLton-commit mailing list