[MLton-commit] r6440

spoons at mlton.org spoons at mlton.org
Mon Mar 3 07:20:15 PST 2008


Add support for dummy objects to fill unused gaps in the heap.

These objects should never by copied or preserved across collections.
There are two forms of these objects: fill objects and header-only
objects.  Header-only objects are used to fill extremely small gaps:
those of only GC_HEADER_SIZE bytes.  Fill objects are used to fill
larger gaps and behave much like arrays (whose length is given as a
32-bit integer).

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

U   mlton/branches/shared-heap-multicore/mlton/backend/object-type.sig
U   mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.fun
U   mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.sig
U   mlton/branches/shared-heap-multicore/mlton/backend/rep-type.fun
U   mlton/branches/shared-heap-multicore/mlton/backend/runtime.fun
U   mlton/branches/shared-heap-multicore/mlton/backend/runtime.sig
U   mlton/branches/shared-heap-multicore/mlton/codegen/c-codegen/c-codegen.fun
U   mlton/branches/shared-heap-multicore/runtime/gc/foreach.c
U   mlton/branches/shared-heap-multicore/runtime/gc/object-size.c
U   mlton/branches/shared-heap-multicore/runtime/gc/object.c
U   mlton/branches/shared-heap-multicore/runtime/gc/object.h

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

Modified: mlton/branches/shared-heap-multicore/mlton/backend/object-type.sig
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/object-type.sig	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/object-type.sig	2008-03-03 15:20:13 UTC (rev 6440)
@@ -19,6 +19,8 @@
        | Stack
        | Weak of ty (* in Weak t, must have Type.isPointer t *)
        | WeakGone
+       | HeaderOnly
+       | Fill
 
       val basic: unit -> (ObjptrTycon.t * t) vector
       val isOk: t -> bool

Modified: mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.fun
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.fun	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.fun	2008-03-03 15:20:13 UTC (rev 6440)
@@ -60,4 +60,7 @@
        | _ => Error.bug "ObjptrTycon.wordVector"
 end
 
+val headerOnly = new ()
+val fill = new ()
+
 end

Modified: mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.sig
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.sig	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/objptr-tycon.sig	2008-03-03 15:20:13 UTC (rev 6440)
@@ -32,4 +32,6 @@
       val thread: t
       val weakGone: t
       val wordVector: Bits.t -> t
+      val headerOnly: t
+      val fill: t
    end

Modified: mlton/branches/shared-heap-multicore/mlton/backend/rep-type.fun
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/rep-type.fun	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/rep-type.fun	2008-03-03 15:20:13 UTC (rev 6440)
@@ -363,6 +363,8 @@
        | Stack
        | Weak of Type.t
        | WeakGone
+       | HeaderOnly
+       | Fill
 
       fun layout (t: t) =
          let
@@ -380,6 +382,8 @@
              | Stack => str "Stack"
              | Weak t => seq [str "Weak ", Type.layout t]
              | WeakGone => str "WeakGone"
+             | HeaderOnly => str "HeaderOnly"
+             | Fill => str "Fill"
          end
 
       fun isOk (t: t): bool =
@@ -397,6 +401,8 @@
           | Stack => true
           | Weak t => Type.isObjptr t
           | WeakGone => true
+          | HeaderOnly => true
+          | Fill => true
 
       val stack = Stack
 
@@ -428,6 +434,9 @@
        * WORD16_VECTOR_TYPE_INDEX,
        * WORD32_VECTOR_TYPE_INDEX.
        * WORD64_VECTOR_TYPE_INDEX.
+       * ZERO_WORD_TYPE_INDEX,
+       * ONE_WORD_TYPE_INDEX,
+       * TWO_WORD_TYPE_INDEX.
        *)
       val basic = fn () => 
          let
@@ -447,7 +456,9 @@
              wordVec 8,
              wordVec 32,
              wordVec 16,
-             wordVec 64]
+             wordVec 64,
+             (ObjptrTycon.headerOnly, HeaderOnly),
+             (ObjptrTycon.fill, Fill)]
          end
 
       local
@@ -474,6 +485,8 @@
              | Stack => R.Stack
              | Weak _ => R.Weak
              | WeakGone => R.WeakGone
+             | HeaderOnly => R.HeaderOnly
+             | Fill => R.Fill
       end
    end
 

Modified: mlton/branches/shared-heap-multicore/mlton/backend/runtime.fun
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/runtime.fun	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/runtime.fun	2008-03-03 15:20:13 UTC (rev 6440)
@@ -173,6 +173,8 @@
        | Stack
        | Weak
        | WeakGone
+       | HeaderOnly
+       | Fill
 
       fun layout (t: t): Layout.t =
          let
@@ -192,6 +194,9 @@
              | Stack => str "Stack"
              | Weak => str "Weak"
              | WeakGone => str "WeakGone"
+             | HeaderOnly => str "HeaderOnly"
+             | Fill => str "Fill"
+
          end
       val _ = layout (* quell unused warning *)
    end

Modified: mlton/branches/shared-heap-multicore/mlton/backend/runtime.sig
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/backend/runtime.sig	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/backend/runtime.sig	2008-03-03 15:20:13 UTC (rev 6440)
@@ -86,6 +86,8 @@
              | Stack
              | Weak
              | WeakGone
+             | HeaderOnly
+             | Fill
          end
 
       val allocTooLarge: Bytes.t

Modified: mlton/branches/shared-heap-multicore/mlton/codegen/c-codegen/c-codegen.fun
===================================================================
--- mlton/branches/shared-heap-multicore/mlton/codegen/c-codegen/c-codegen.fun	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/mlton/codegen/c-codegen/c-codegen.fun	2008-03-03 15:20:13 UTC (rev 6440)
@@ -370,6 +370,8 @@
                         | (Control.Align4,64,64) => (3, false, 16, 0)
                         | (Control.Align8,64,64) => (3, false, 16, 0)
                         | _ => Error.bug "CCodegen.declareObjectTypes")
+                 | HeaderOnly => (4, false, 0, 0)
+                 | Fill => (5, false, 0, 0)
           in
              concat ["{ ", C.int tag, ", ",
                      C.bool hasIdentity, ", ",

Modified: mlton/branches/shared-heap-multicore/runtime/gc/foreach.c
===================================================================
--- mlton/branches/shared-heap-multicore/runtime/gc/foreach.c	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/runtime/gc/foreach.c	2008-03-03 15:20:13 UTC (rev 6440)
@@ -118,7 +118,7 @@
       p -= dataBytes;
     }
     p += alignWithExtra (s, dataBytes, GC_ARRAY_HEADER_SIZE);
-  } else { /* stack */
+  } else if (STACK_TAG == tag) {
     GC_stack stack; 
     pointer top, bottom; 
     unsigned int i;
@@ -126,7 +126,6 @@
     GC_frameLayout frameLayout;
     GC_frameOffsets frameOffsets;
 
-    assert (STACK_TAG == tag);
     stack = (GC_stack)p;
     bottom = getStackBottom (s, stack); 
     top = getStackTop (s, stack);
@@ -155,6 +154,18 @@
     assert(top == bottom);
     p += sizeof (struct GC_stack) + stack->reserved;
   }
+  else if (HEADER_ONLY_TAG == tag) {
+  }
+  else if (FILL_TAG == tag) {
+    GC_smallGapSize bytes;
+    bytes = *((GC_smallGapSize *)p);
+    p += GC_SMALL_GAP_SIZE_SIZE;
+    p += bytes;
+  }
+  else {
+    assert (0 and "unknown object tag type");
+  }
+
   return p;
 }
 

Modified: mlton/branches/shared-heap-multicore/runtime/gc/object-size.c
===================================================================
--- mlton/branches/shared-heap-multicore/runtime/gc/object-size.c	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/runtime/gc/object-size.c	2008-03-03 15:20:13 UTC (rev 6440)
@@ -43,10 +43,24 @@
     headerBytes = GC_ARRAY_HEADER_SIZE;
     objectBytes = sizeofArrayNoHeader (s, getArrayLength (p), 
                                        bytesNonObjptrs, numObjptrs);
-  } else { /* Stack. */
-    assert (STACK_TAG == tag);
+  } else if (STACK_TAG == tag) {
     headerBytes = GC_STACK_HEADER_SIZE;
     objectBytes = sizeofStackNoHeader (s, (GC_stack)p);
   }
+  else if (HEADER_ONLY_TAG == tag) {
+    headerBytes = GC_HEADER_SIZE;
+    objectBytes = 0;
+  }
+  else if (FILL_TAG == tag) {
+    GC_smallGapSize bytes;
+    headerBytes = GC_HEADER_SIZE;
+    bytes = *((GC_smallGapSize *)p);
+    objectBytes = GC_SMALL_GAP_SIZE_SIZE + bytes;
+  }
+  else {
+    headerBytes = 0;
+    objectBytes = 0;
+    assert (0 and "unknown tag in sizeofObject");
+  }
   return headerBytes + objectBytes;
 }

Modified: mlton/branches/shared-heap-multicore/runtime/gc/object.c
===================================================================
--- mlton/branches/shared-heap-multicore/runtime/gc/object.c	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/runtime/gc/object.c	2008-03-03 15:20:13 UTC (rev 6440)
@@ -16,6 +16,10 @@
     return "STACK";
   case WEAK_TAG:
     return "WEAK";
+  case HEADER_ONLY_TAG:
+    return "HEADER_ONLY";
+  case FILL_TAG:
+    return "FILL";
   default:
     die ("bad GC_objectTypeTag %u", tag);
   }

Modified: mlton/branches/shared-heap-multicore/runtime/gc/object.h
===================================================================
--- mlton/branches/shared-heap-multicore/runtime/gc/object.h	2008-03-03 15:18:40 UTC (rev 6439)
+++ mlton/branches/shared-heap-multicore/runtime/gc/object.h	2008-03-03 15:20:13 UTC (rev 6440)
@@ -11,12 +11,17 @@
 /* 
  * There are four kinds of ML objects: 
  *   array, normal (fixed size), stack, and weak.
+ * Plus three additional tags that are used to fill gaps:
+ *   zero, one, and two word objects
+ *   (that is, {0,1,2} words in addition to the header)
  */
 typedef enum { 
   ARRAY_TAG,
   NORMAL_TAG,
   STACK_TAG,
   WEAK_TAG,
+  HEADER_ONLY_TAG,
+  FILL_TAG
 } GC_objectTypeTag;
 
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
@@ -143,6 +148,8 @@
   WORD32_VECTOR_TYPE_INDEX = 4,
   WORD16_VECTOR_TYPE_INDEX = 5,
   WORD64_VECTOR_TYPE_INDEX = 6,
+  HEADER_ONLY_TYPE_INDEX =   7,
+  FILL_TYPE_INDEX =          8
 };
 
 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
@@ -157,6 +164,9 @@
 #define GC_WORD32_VECTOR_HEADER buildHeaderFromTypeIndex (WORD32_VECTOR_TYPE_INDEX)
 #define GC_WORD64_VECTOR_HEADER buildHeaderFromTypeIndex (WORD64_VECTOR_TYPE_INDEX)
 
+#define GC_HEADER_ONLY_HEADER buildHeaderFromTypeIndex (HEADER_ONLY_TYPE_INDEX)
+#define GC_FILL_HEADER buildHeaderFromTypeIndex (FILL_TYPE_INDEX)
+
 static inline void splitHeader (GC_state s, GC_header header,
                                 GC_objectTypeTag *tagRet, bool *hasIdentityRet,
                                 uint16_t *bytesNonObjptrsRet, uint16_t *numObjptrsRet);




More information about the MLton-commit mailing list