[MLton-commit] r4111
Matthew Fluet
MLton@mlton.org
Sun, 16 Oct 2005 17:44:36 -0700
More heap manipulations
----------------------------------------------------------------------
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.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_size.c
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c
----------------------------------------------------------------------
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile 2005-10-17 00:44:33 UTC (rev 4111)
@@ -75,10 +75,10 @@
gc_prefix.c \
util.c \
safe.c \
+ rusage.c \
debug.c \
align.c \
virtual-memory.c \
- rusage.c \
pointer_predicates.c \
pointer.c \
model_predicates.c \
@@ -95,11 +95,11 @@
generational.c \
heap_predicates.c \
heap.c \
- gc_state.c \
+ current.c \
new_object.c \
ratios_predicates.c \
- current.c \
atomic.c \
+ gc_state.c \
invariant.c \
enter_leave.c \
cheney-copy.c \
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 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/cheney-copy.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -339,7 +339,7 @@
fprintf (stderr, "Forwarding inter-generational pointers done.\n");
}
-static void minorGC (GC_state s) {
+static void minorCheneyCopyGC (GC_state s) {
size_t bytesAllocated;
size_t bytesCopied;
struct rusage ru_start;
@@ -357,7 +357,7 @@
bytesCopied = 0;
} else {
if (DEBUG_GENERATIONAL or s->controls.messages)
- fprintf (stderr, "Minor GC.\n");
+ fprintf (stderr, "Minor copying GC.\n");
if (detailedGCTime (s))
startTiming (&ru_start);
s->amInMinorGC = TRUE;
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/current.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -29,6 +29,8 @@
return s->stackTop - s->stackBottom;
}
+
+
static void setCurrentStack (GC_state s) {
GC_thread thread;
GC_stack stack;
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/heap.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -405,3 +405,58 @@
assert (heapHasBytesFree (s, oldGenBytesRequested, nurseryBytesRequested));
}
+/* heapResize (s, minSize)
+ */
+static void heapResize (GC_state s, size_t minSize) {
+ size_t desiredSize;
+
+ if (DEBUG_RESIZING)
+ fprintf (stderr, "heapResize minSize = %zu size = %zu\n",
+ /*ullongToCommaString*/(minSize),
+ /*uintToCommaString*/(s->heap.size));
+ desiredSize = heapDesiredSize (s, minSize, s->heap.size);
+ assert (minSize <= desiredSize);
+ if (desiredSize <= s->heap.size)
+ heapShrink (s, &s->heap, desiredSize);
+ else {
+ heapRelease (s, &s->secondaryHeap);
+ heapGrow (s, desiredSize, minSize);
+ }
+ resizeCardMapAndCrossMap (s);
+ assert (s->heap.size >= minSize);
+}
+
+/* secondaryHeapResize (s)
+ */
+static void secondaryHeapResize (GC_state s) {
+ size_t primarySize;
+ size_t secondarySize;
+
+ primarySize = s->heap.size;
+ secondarySize = s->secondaryHeap.size;
+ if (DEBUG_RESIZING)
+ fprintf (stderr, "secondaryHeapResize\n");
+ if (0 == secondarySize)
+ return;
+ if (2 * primarySize > s->sysvals.ram)
+ /* Holding on to heap2 might cause paging. So don't. */
+ heapRelease (s, &s->secondaryHeap);
+ else if (secondarySize < primarySize) {
+ unless (heapRemap (s, &s->secondaryHeap, primarySize, primarySize))
+ heapRelease (s, &s->secondaryHeap);
+ } else if (secondarySize > primarySize)
+ heapShrink (s, &s->secondaryHeap, primarySize);
+ assert (0 == s->secondaryHeap.size
+ or s->heap.size == s->secondaryHeap.size);
+}
+
+/* secondaryHeapCreate (s, desiredSize)
+ */
+static bool secondaryHeapCreate (GC_state s, size_t desiredSize) {
+ if ((s->controls.fixedHeap > 0
+ and s->heap.size + desiredSize > s->controls.fixedHeap)
+ or (s->controls.maxHeap > 0
+ and s->heap.size + desiredSize > s->controls.maxHeap))
+ return FALSE;
+ return heapCreate (s, &s->secondaryHeap, desiredSize, s->heap.oldGenSize);
+}
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 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/new_object.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -55,7 +55,7 @@
if (reserved > s->cumulativeStatistics.maxStackSizeSeen)
s->cumulativeStatistics.maxStackSizeSeen = reserved;
stack = (GC_stack) newObject (s, GC_STACK_HEADER,
- stackNumBytes (s, reserved),
+ stackSizeTotalAligned (s, reserved),
allocInOldGen);
stack->reserved = reserved;
stack->used = 0;
@@ -65,3 +65,23 @@
reserved);
return stack;
}
+
+static inline size_t stackGrowSize (GC_state s) {
+ return max (2 * currentThreadStack(s)->reserved,
+ stackMinimumReserved (s, currentThreadStack(s)));
+}
+
+static void stackGrow (GC_state s) {
+ size_t size;
+ GC_stack stack;
+
+ size = stackGrowSize (s);
+ if (DEBUG_STACKS or s->controls.messages)
+ fprintf (stderr, "Growing stack to size %zu.\n",
+ /*uintToCommaString*/(stackSizeTotalAligned (s, size)));
+ assert (heapHasBytesFree (s, stackSizeTotalAligned (s, size), 0));
+ stack = newStack (s, size, TRUE);
+ stackCopy (s, currentThreadStack(s), stack);
+ currentThread(s)->stack = pointerToObjptr ((pointer)stack, s->heap.start);
+ markCard (s, objptrToPointer (currentThreadObjptr(s), s->heap.start));
+}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/object_size.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/object_size.c 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/object_size.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -20,6 +20,17 @@
}
}
+static inline size_t normalSizeNoHeader (__attribute__ ((unused)) GC_state s,
+ uint16_t numNonObjptrs,
+ uint16_t numObjptrs) {
+ size_t result;
+
+ result =
+ numNonObjptrsToBytes (numNonObjptrs, NORMAL_TAG)
+ + (numObjptrs * OBJPTR_SIZE);
+ return result;
+}
+
static inline size_t arraySizeNoHeader (GC_state s,
pointer p,
uint16_t numNonObjptrs,
@@ -39,6 +50,25 @@
return pad (s, result, GC_ARRAY_HEADER_SIZE);
}
+static inline size_t weakSizeNoHeader (__attribute__ ((unused)) GC_state s,
+ uint16_t numNonObjptrs,
+ uint16_t numObjptrs) {
+ size_t result;
+
+ result =
+ numNonObjptrsToBytes (numNonObjptrs, WEAK_TAG)
+ + (numObjptrs * OBJPTR_SIZE);
+ return result;
+}
+
+static inline size_t stackSizeNoHeader (__attribute__ ((unused)) GC_state s,
+ pointer p) {
+ size_t result;
+
+ result = sizeof (struct GC_stack) + ((GC_stack)p)->reserved;
+ return result;
+}
+
static inline size_t objectSize (GC_state s, pointer p) {
size_t headerBytes, objectBytes;
GC_header header;
@@ -47,34 +77,19 @@
header = getHeader (p);
splitHeader (s, header, &tag, NULL, &numNonObjptrs, &numObjptrs);
- if (NORMAL_TAG == tag) { /* Fixed size object. */
+ if (NORMAL_TAG == tag) {
headerBytes = GC_NORMAL_HEADER_SIZE;
- objectBytes =
- numNonObjptrsToBytes (numNonObjptrs, NORMAL_TAG)
- + (numObjptrs * OBJPTR_SIZE);
+ objectBytes = normalSizeNoHeader (s, numNonObjptrs, numObjptrs);
} else if (ARRAY_TAG == tag) {
headerBytes = GC_ARRAY_HEADER_SIZE;
objectBytes = arraySizeNoHeader (s, p, numNonObjptrs, numObjptrs);
} else if (WEAK_TAG == tag) {
headerBytes = GC_NORMAL_HEADER_SIZE;
- objectBytes =
- numNonObjptrsToBytes (numNonObjptrs, NORMAL_TAG)
- + (numObjptrs * OBJPTR_SIZE);
+ objectBytes = weakSizeNoHeader (s, numNonObjptrs, numObjptrs);
} else { /* Stack. */
assert (STACK_TAG == tag);
headerBytes = GC_STACK_HEADER_SIZE;
- objectBytes = sizeof (struct GC_stack) + ((GC_stack)p)->reserved;
+ objectBytes = stackSizeNoHeader (s, p);
}
return headerBytes + objectBytes;
}
-
-
-static inline size_t stackNumBytes (GC_state s, size_t size) {
- size_t res;
-
- res = align (GC_STACK_HEADER_SIZE + sizeof (struct GC_stack) + size,
- s->alignment);
- if (DEBUG_STACKS)
- fprintf (stderr, "%zu = stackNumBytes (%zu)\n", res, size);
- return res;
-}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c 2005-10-16 23:34:20 UTC (rev 4110)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c 2005-10-17 00:44:33 UTC (rev 4111)
@@ -96,3 +96,13 @@
from->used);
GC_memcpy (fromBottom, toBottom, from->used);
}
+
+static inline size_t stackSizeTotalAligned (GC_state s, size_t reserved) {
+ size_t res;
+
+ res = align (GC_STACK_HEADER_SIZE + sizeof (struct GC_stack) + reserved,
+ s->alignment);
+ if (DEBUG_STACKS)
+ fprintf (stderr, "%zu = stackSizeTotalAligned (%zu)\n", res, reserved);
+ return res;
+}