From 585186f7d38e906860032fca395f2f71b249f9b1 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 5 Mar 2013 09:35:21 -0700 Subject: [PATCH] avoid allocating a new gen2 heap larger than the available heap capacity --- src/heap/heap.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/heap/heap.cpp b/src/heap/heap.cpp index d70286dd15..dcc888cacb 100644 --- a/src/heap/heap.cpp +++ b/src/heap/heap.cpp @@ -330,7 +330,8 @@ class Segment { unsigned capacity_; Map* map; - Segment(Context* context, Map* map, unsigned desired, unsigned minimum): + Segment(Context* context, Map* map, unsigned desired, unsigned minimum, + int64_t available = INT64_MAX): context(context), data(0), position_(0), @@ -346,9 +347,13 @@ class Segment { capacity_ = desired; while (data == 0) { - data = static_cast - (local::allocate - (context, (footprint(capacity_)) * BytesPerWord, false)); + if (static_cast(footprint(capacity_)) > available) { + data = 0; + } else { + data = static_cast + (local::allocate + (context, (footprint(capacity_)) * BytesPerWord, false)); + } if (data == 0) { if (capacity_ > minimum) { @@ -809,7 +814,11 @@ initNextGen2(Context* c) desired = InitialGen2CapacityInBytes / BytesPerWord; } - new (&(c->nextGen2)) Segment(c, &(c->nextHeapMap), desired, minimum); + new (&(c->nextGen2)) Segment + (c, &(c->nextHeapMap), desired, minimum, + static_cast(c->limit / BytesPerWord) + - (static_cast(c->count / BytesPerWord) + - c->gen2.footprint(c->gen2.capacity()))); if (Verbose2) { fprintf(stderr, "init nextGen2 to %d bytes\n",