[MLton-commit] r6570
Matthew Fluet
fluet at mlton.org
Mon Apr 7 11:56:06 PDT 2008
Refactor to share sizeofStackShrink between forward and mark-compact
----------------------------------------------------------------------
U mlton/trunk/runtime/gc/forward.c
U mlton/trunk/runtime/gc/mark-compact.c
U mlton/trunk/runtime/gc/stack.c
U mlton/trunk/runtime/gc/stack.h
----------------------------------------------------------------------
Modified: mlton/trunk/runtime/gc/forward.c
===================================================================
--- mlton/trunk/runtime/gc/forward.c 2008-04-07 18:56:03 UTC (rev 6569)
+++ mlton/trunk/runtime/gc/forward.c 2008-04-07 18:56:05 UTC (rev 6570)
@@ -61,6 +61,7 @@
skip = 0;
} else { /* Stack. */
bool active;
+ size_t reservedNew;
GC_stack stack;
assert (STACK_TAG == tag);
@@ -68,37 +69,7 @@
stack = (GC_stack)p;
active = getStackCurrent(s) == stack;
- size_t reservedMax, reservedShrink, reservedMin, reservedNew;
-
- if (active) {
- /* Shrink active stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackCurrentMaxReserved * stack->used);
- size_t reservedPermit =
- (size_t)(s->controls.ratios.stackCurrentPermitReserved * stack->used);
- reservedShrink =
- (reservedPermit >= stack->reserved)
- ? stack->reserved
- : (size_t)(s->controls.ratios.stackCurrentShrink * stack->used);
- reservedMin = sizeofStackMinimumReserved (s, stack);
- } else {
- /* Shrink paused stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackMaxReserved * stack->used);
- reservedShrink =
- (size_t)(s->controls.ratios.stackShrink * stack->reserved);
- reservedMin= stack->used;
- }
- reservedNew =
- alignStackReserved
- (s, max(min(reservedMax,reservedShrink),reservedMin));
- /* It's possible that new > stack->reserved for the active stack
- * if the stack invariant is violated. In that case, we want to
- * leave the stack alone, because some other part of the gc will
- * grow the stack. We cannot do any growing here because we may
- * run out of to space.
- */
- assert (active or reservedNew <= stack->reserved);
+ reservedNew = sizeofStackShrink (s, stack, active);
if (reservedNew < stack->reserved) {
if (DEBUG_STACKS or s->controls.messages)
fprintf (stderr,
Modified: mlton/trunk/runtime/gc/mark-compact.c
===================================================================
--- mlton/trunk/runtime/gc/mark-compact.c 2008-04-07 18:56:03 UTC (rev 6569)
+++ mlton/trunk/runtime/gc/mark-compact.c 2008-04-07 18:56:05 UTC (rev 6570)
@@ -143,6 +143,7 @@
skipGap = 0;
} else { /* Stack. */
bool active;
+ size_t reservedNew, reservedOld;
GC_stack stack;
assert (STACK_TAG == tag);
@@ -150,42 +151,8 @@
stack = (GC_stack)p;
active = currentStack == stack;
- size_t reservedMax, reservedShrink, reservedMin, reservedNew, reservedOld;
-
reservedOld = stack->reserved;
- if (active) {
- /* Shrink active stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackCurrentMaxReserved * stack->used);
- size_t reservedPermit =
- (size_t)(s->controls.ratios.stackCurrentPermitReserved * stack->used);
- reservedShrink =
- (reservedPermit >= stack->reserved)
- ? stack->reserved
- : (size_t)(s->controls.ratios.stackCurrentShrink * stack->used);
- reservedMin = sizeofStackMinimumReserved (s, stack);
- } else {
- /* Shrink paused stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackMaxReserved * stack->used);
- reservedShrink =
- (size_t)(s->controls.ratios.stackShrink * stack->reserved);
- reservedMin= stack->used;
- }
- reservedNew =
- alignStackReserved
- (s, max(min(reservedMax,reservedShrink),reservedMin));
- /* It's possible that new > stack->reserved for the active stack
- * if the stack invariant is violated. In that case, we want to
- * leave the stack alone, because some other part of the gc will
- * grow the stack. We cannot do any growing here because we may
- * run out of to space.
- */
- assert (active or reservedNew <= stack->reserved);
- if (reservedNew < stack->reserved) {
- } else {
- reservedNew = stack->reserved;
- }
+ reservedNew = sizeofStackShrink (s, stack, active);
objectBytes = sizeof (struct GC_stack) + stack->used;
skipFront = reservedOld - stack->used;
skipGap = reservedOld - reservedNew;
@@ -312,6 +279,7 @@
skipGap = 0;
} else { /* Stack. */
bool active;
+ size_t reservedNew, reservedOld;
GC_stack stack;
assert (STACK_TAG == tag);
@@ -319,38 +287,8 @@
stack = (GC_stack)p;
active = currentStack == stack;
- size_t reservedMax, reservedShrink, reservedMin, reservedNew, reservedOld;
-
reservedOld = stack->reserved;
- if (active) {
- /* Shrink active stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackCurrentMaxReserved * stack->used);
- size_t reservedPermit =
- (size_t)(s->controls.ratios.stackCurrentPermitReserved * stack->used);
- reservedShrink =
- (reservedPermit >= stack->reserved)
- ? stack->reserved
- : (size_t)(s->controls.ratios.stackCurrentShrink * stack->used);
- reservedMin = sizeofStackMinimumReserved (s, stack);
- } else {
- /* Shrink paused stacks. */
- reservedMax =
- (size_t)(s->controls.ratios.stackMaxReserved * stack->used);
- reservedShrink =
- (size_t)(s->controls.ratios.stackShrink * stack->reserved);
- reservedMin= stack->used;
- }
- reservedNew =
- alignStackReserved
- (s, max(min(reservedMax,reservedShrink),reservedMin));
- /* It's possible that new > stack->reserved for the active stack
- * if the stack invariant is violated. In that case, we want to
- * leave the stack alone, because some other part of the gc will
- * grow the stack. We cannot do any growing here because we may
- * run out of to space.
- */
- assert (active or reservedNew <= stack->reserved);
+ reservedNew = sizeofStackShrink (s, stack, active);
if (reservedNew < stack->reserved) {
if (DEBUG_STACKS or s->controls.messages)
fprintf (stderr,
@@ -359,8 +297,6 @@
uintmaxToCommaString(reservedNew),
uintmaxToCommaString(stack->used));
stack->reserved = reservedNew;
- } else {
- reservedNew = stack->reserved;
}
objectBytes = sizeof (struct GC_stack) + stack->used;
skipFront = reservedOld - stack->used;
Modified: mlton/trunk/runtime/gc/stack.c
===================================================================
--- mlton/trunk/runtime/gc/stack.c 2008-04-07 18:56:03 UTC (rev 6569)
+++ mlton/trunk/runtime/gc/stack.c 2008-04-07 18:56:05 UTC (rev 6570)
@@ -159,6 +159,42 @@
return res;
}
+size_t sizeofStackShrink (GC_state s, GC_stack stack, bool active) {
+ size_t reservedMax, reservedShrink, reservedMin, reservedNew;
+
+ if (active) {
+ /* Shrink active stacks. */
+ reservedMax =
+ (size_t)(s->controls.ratios.stackCurrentMaxReserved * stack->used);
+ size_t reservedPermit =
+ (size_t)(s->controls.ratios.stackCurrentPermitReserved * stack->used);
+ reservedShrink =
+ (reservedPermit >= stack->reserved)
+ ? stack->reserved
+ : (size_t)(s->controls.ratios.stackCurrentShrink * stack->used);
+ reservedMin = sizeofStackMinimumReserved (s, stack);
+ } else {
+ /* Shrink paused stacks. */
+ reservedMax =
+ (size_t)(s->controls.ratios.stackMaxReserved * stack->used);
+ reservedShrink =
+ (size_t)(s->controls.ratios.stackShrink * stack->reserved);
+ reservedMin= stack->used;
+ }
+ reservedNew =
+ alignStackReserved
+ (s, max(min(reservedMax,reservedShrink),reservedMin));
+ /* It's possible that reservedNew > stack->reserved for the
+ * active stack if the stack invariant is violated. In that
+ * case, we want to leave the stack alone, because some other
+ * part of the gc will grow the stack. We cannot do any growing
+ * here because we may run out of to space.
+ */
+ assert (active or reservedNew <= stack->reserved);
+ reservedNew = min (stack->reserved, reservedNew);
+ return reservedNew;
+}
+
void copyStack (GC_state s, GC_stack from, GC_stack to) {
pointer fromBottom, toBottom;
Modified: mlton/trunk/runtime/gc/stack.h
===================================================================
--- mlton/trunk/runtime/gc/stack.h 2008-04-07 18:56:03 UTC (rev 6569)
+++ mlton/trunk/runtime/gc/stack.h 2008-04-07 18:56:05 UTC (rev 6570)
@@ -78,6 +78,7 @@
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 void copyStack (GC_state s, GC_stack from, GC_stack to);
More information about the MLton-commit
mailing list