[MLton-commit] r6577
Matthew Fluet
fluet at mlton.org
Mon Apr 7 11:56:21 PDT 2008
Functions returning a stack-reserved size return a size that is
properly stack-reserved aligned.
----------------------------------------------------------------------
U mlton/trunk/runtime/gc/copy-thread.c
U mlton/trunk/runtime/gc/forward.c
U mlton/trunk/runtime/gc/garbage-collection.c
U mlton/trunk/runtime/gc/init-world.c
U mlton/trunk/runtime/gc/mark-compact.c
U mlton/trunk/runtime/gc/new-object.c
U mlton/trunk/runtime/gc/stack.c
U mlton/trunk/runtime/gc/stack.h
----------------------------------------------------------------------
Modified: mlton/trunk/runtime/gc/copy-thread.c
===================================================================
--- mlton/trunk/runtime/gc/copy-thread.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/copy-thread.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -6,7 +6,7 @@
* See the file MLton-LICENSE for details.
*/
-GC_thread copyThread (GC_state s, GC_thread from, size_t size) {
+GC_thread copyThread (GC_state s, GC_thread from, size_t used) {
GC_thread to;
if (DEBUG_THREADS)
@@ -16,7 +16,7 @@
*/
assert (s->savedThread == BOGUS_OBJPTR);
s->savedThread = pointerToObjptr((pointer)from - offsetofThread (s), s->heap.start);
- to = newThread (s, size);
+ to = newThread (s, alignStackReserved(s, used));
from = (GC_thread)(objptrToPointer(s->savedThread, s->heap.start) + offsetofThread (s));
s->savedThread = BOGUS_OBJPTR;
if (DEBUG_THREADS) {
Modified: mlton/trunk/runtime/gc/forward.c
===================================================================
--- mlton/trunk/runtime/gc/forward.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/forward.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -69,7 +69,7 @@
stack = (GC_stack)p;
current = getStackCurrent(s) == stack;
- reservedNew = sizeofStackShrink (s, stack, current);
+ reservedNew = sizeofStackShrinkReserved (s, stack, current);
if (reservedNew < stack->reserved) {
if (DEBUG_STACKS or s->controls.messages)
fprintf (stderr,
Modified: mlton/trunk/runtime/gc/garbage-collection.c
===================================================================
--- mlton/trunk/runtime/gc/garbage-collection.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/garbage-collection.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -48,18 +48,18 @@
}
void growStackCurrent (GC_state s) {
- size_t size;
+ size_t reserved;
GC_stack stack;
- size = sizeofStackGrow (s, getStackCurrent(s));
+ reserved = sizeofStackGrowReserved (s, getStackCurrent(s));
if (DEBUG_STACKS or s->controls.messages)
fprintf (stderr,
"[GC: Growing stack of size %s bytes to size %s bytes, using %s bytes.]\n",
uintmaxToCommaString(getStackCurrent(s)->reserved),
- uintmaxToCommaString(alignStackReserved (s, size)),
+ uintmaxToCommaString(reserved),
uintmaxToCommaString(getStackCurrent(s)->used));
- assert (hasHeapBytesFree (s, sizeofStackWithHeaderAligned (s, size), 0));
- stack = newStack (s, size, TRUE);
+ assert (hasHeapBytesFree (s, sizeofStackWithHeader (s, reserved), 0));
+ stack = newStack (s, reserved, TRUE);
copyStack (s, getStackCurrent(s), stack);
getThreadCurrent(s)->stack = pointerToObjptr ((pointer)stack, s->heap.start);
markCard (s, objptrToPointer (getThreadCurrentObjptr(s), s->heap.start));
@@ -134,7 +134,7 @@
stackBytesRequested =
stackTopOk
? 0
- : sizeofStackWithHeaderAligned (s, sizeofStackGrow (s, getStackCurrent (s)));
+ : sizeofStackWithHeader (s, sizeofStackGrowReserved (s, getStackCurrent (s)));
totalBytesRequested =
oldGenBytesRequested
+ nurseryBytesRequested
Modified: mlton/trunk/runtime/gc/init-world.c
===================================================================
--- mlton/trunk/runtime/gc/init-world.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/init-world.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -154,6 +154,6 @@
assert ((size_t)(s->frontier - start) <= s->lastMajorStatistics.bytesLive);
s->heap.oldGenSize = s->frontier - s->heap.start;
setGCStateCurrentHeap (s, 0, 0);
- thread = newThread (s, sizeofStackInitial (s));
+ thread = newThread (s, sizeofStackInitialReserved (s));
switchToThread (s, pointerToObjptr((pointer)thread - offsetofThread (s), s->heap.start));
}
Modified: mlton/trunk/runtime/gc/mark-compact.c
===================================================================
--- mlton/trunk/runtime/gc/mark-compact.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/mark-compact.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -152,7 +152,7 @@
current = currentStack == stack;
reservedOld = stack->reserved;
- reservedNew = sizeofStackShrink (s, stack, current);
+ reservedNew = sizeofStackShrinkReserved (s, stack, current);
objectBytes = sizeof (struct GC_stack) + stack->used;
skipFront = reservedOld - stack->used;
skipGap = reservedOld - reservedNew;
@@ -288,7 +288,7 @@
current = currentStack == stack;
reservedOld = stack->reserved;
- reservedNew = sizeofStackShrink (s, stack, current);
+ reservedNew = sizeofStackShrinkReserved (s, stack, current);
if (reservedNew < stack->reserved) {
if (DEBUG_STACKS or s->controls.messages)
fprintf (stderr,
Modified: mlton/trunk/runtime/gc/new-object.c
===================================================================
--- mlton/trunk/runtime/gc/new-object.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/new-object.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -52,11 +52,11 @@
bool allocInOldGen) {
GC_stack stack;
- reserved = alignStackReserved (s, reserved);
+ assert (isStackReservedAligned (s, reserved));
if (reserved > s->cumulativeStatistics.maxStackSize)
s->cumulativeStatistics.maxStackSize = reserved;
stack = (GC_stack)(newObject (s, GC_STACK_HEADER,
- sizeofStackWithHeaderAligned (s, reserved),
+ sizeofStackWithHeader (s, reserved),
allocInOldGen));
stack->reserved = reserved;
stack->used = 0;
@@ -72,7 +72,8 @@
GC_thread thread;
pointer res;
- ensureHasHeapBytesFree (s, 0, sizeofStackWithHeaderAligned (s, reserved) + sizeofThread (s));
+ assert (isStackReservedAligned (s, reserved));
+ ensureHasHeapBytesFree (s, 0, sizeofStackWithHeader (s, reserved) + sizeofThread (s));
stack = newStack (s, reserved, FALSE);
res = newObject (s, GC_THREAD_HEADER,
sizeofThread (s),
Modified: mlton/trunk/runtime/gc/stack.c
===================================================================
--- mlton/trunk/runtime/gc/stack.c 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/stack.c 2008-04-07 18:56:20 UTC (rev 6577)
@@ -35,9 +35,6 @@
return (size_t)(2 * s->maxFrameSize);
}
-size_t sizeofStackInitial (GC_state s) {
- return sizeofStackSlop (s);
-}
/* Pointer to the bottommost word in use on the stack. */
pointer getStackBottom (__attribute__ ((unused)) GC_state s, GC_stack stack) {
@@ -75,7 +72,6 @@
return res;
}
-
GC_frameIndex getCachedStackTopFrameIndex (GC_state s) {
GC_frameIndex res;
@@ -116,16 +112,7 @@
return layout->size;
}
-size_t sizeofStackMinimumReserved (GC_state s, GC_stack stack) {
- size_t res;
- res =
- stack->used
- + sizeofStackSlop (s)
- - getStackTopFrameSize(s, stack);
- return res;
-}
-
size_t alignStackReserved (GC_state s, size_t reserved) {
size_t res;
@@ -137,25 +124,39 @@
return res;
}
-size_t sizeofStackWithHeaderAligned (GC_state s, size_t reserved) {
+size_t sizeofStackWithHeader (__attribute__ ((unused)) GC_state s,
+ size_t reserved) {
size_t res;
- res =
- align (GC_STACK_HEADER_SIZE
- + sizeof (struct GC_stack)
- + reserved,
- s->alignment);
+ assert (isStackReservedAligned (s, reserved));
+ res = GC_STACK_HEADER_SIZE + sizeof (struct GC_stack) + reserved;
if (DEBUG_STACKS)
- fprintf (stderr, "%"PRIuMAX" = sizeofStackWithHeaderAligned (%"PRIuMAX")\n",
+ fprintf (stderr, "%"PRIuMAX" = sizeofStackWithHeader (%"PRIuMAX")\n",
(uintmax_t)res, (uintmax_t)reserved);
+ assert (isAligned (res, s->alignment));
return res;
}
-size_t sizeofStackGrow (GC_state s, GC_stack stack) {
+size_t sizeofStackInitialReserved (GC_state s) {
+ return alignStackReserved(s, sizeofStackSlop (s));
+}
+
+size_t sizeofStackMinimumReserved (GC_state s, GC_stack stack) {
+ size_t res;
+
+ res =
+ stack->used
+ + sizeofStackSlop (s)
+ - getStackTopFrameSize(s, stack);
+ return res;
+}
+
+size_t sizeofStackGrowReserved (GC_state s, GC_stack stack) {
double reservedD;
size_t reservedGrow, reservedMin, reservedNew;
const size_t RESERVED_MAX = (SIZE_MAX >> 2);
+ assert (isStackReservedAligned (s, stack->reserved));
reservedD = (double)(stack->reserved);
double reservedGrowD =
(double)s->controls.ratios.stackCurrentGrow * reservedD;
@@ -164,15 +165,19 @@
? RESERVED_MAX
: (size_t)reservedGrowD;
reservedMin = sizeofStackMinimumReserved (s, stack);
- reservedNew = max (reservedGrow, reservedMin);
+ reservedNew =
+ alignStackReserved
+ (s, max (reservedGrow, reservedMin));
+ assert (isStackReservedAligned (s, reservedNew));
return reservedNew;
}
-size_t sizeofStackShrink (GC_state s, GC_stack stack, bool current) {
+size_t sizeofStackShrinkReserved (GC_state s, GC_stack stack, bool current) {
double usedD, reservedD;
size_t reservedMax, reservedShrink, reservedMin, reservedNew;
const size_t RESERVED_MAX = (SIZE_MAX >> 2);
+ assert (isStackReservedAligned (s, stack->reserved));
usedD = (double)(stack->used);
reservedD = (double)(stack->reserved);
if (current) {
@@ -217,6 +222,7 @@
*/
assert (current or reservedNew <= stack->reserved);
reservedNew = min (stack->reserved, reservedNew);
+ assert (isStackReservedAligned (s, reservedNew));
return reservedNew;
}
Modified: mlton/trunk/runtime/gc/stack.h
===================================================================
--- mlton/trunk/runtime/gc/stack.h 2008-04-07 18:56:18 UTC (rev 6576)
+++ mlton/trunk/runtime/gc/stack.h 2008-04-07 18:56:20 UTC (rev 6577)
@@ -62,7 +62,6 @@
#endif
static inline size_t sizeofStackSlop (GC_state s);
-static inline size_t sizeofStackInitial (GC_state s);
static inline pointer getStackBottom (GC_state s, GC_stack stack);
static inline pointer getStackTop (GC_state s, GC_stack stack);
@@ -74,11 +73,12 @@
static inline GC_frameLayout getStackTopFrameLayout (GC_state s, GC_stack stack);
static inline uint16_t getStackTopFrameSize (GC_state s, GC_stack stack);
+static inline size_t alignStackReserved (GC_state s, size_t reserved);
+static inline size_t sizeofStackWithHeader (GC_state s, size_t reserved);
+static inline size_t sizeofStackInitialReserved (GC_state s);
static inline size_t sizeofStackMinimumReserved (GC_state s, GC_stack stack);
-static inline size_t alignStackReserved (GC_state s, size_t reserved);
-static inline size_t sizeofStackWithHeaderAligned (GC_state s, size_t reserved);
-static inline size_t sizeofStackGrow (GC_state s, GC_stack stack);
-static inline size_t sizeofStackShrink (GC_state s, GC_stack stack, bool active);
+static inline size_t sizeofStackGrowReserved (GC_state s, GC_stack stack);
+static inline size_t sizeofStackShrinkReserved (GC_state s, GC_stack stack, bool current);
static inline void copyStack (GC_state s, GC_stack from, GC_stack to);
More information about the MLton-commit
mailing list