avoid allocating a new gen2 heap larger than the available heap capacity

This commit is contained in:
Joel Dice 2013-03-05 09:35:21 -07:00
parent 84f99f0dca
commit 585186f7d3

View File

@ -330,7 +330,8 @@ class Segment {
unsigned capacity_; unsigned capacity_;
Map* map; 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), context(context),
data(0), data(0),
position_(0), position_(0),
@ -346,9 +347,13 @@ class Segment {
capacity_ = desired; capacity_ = desired;
while (data == 0) { while (data == 0) {
data = static_cast<uintptr_t*> if (static_cast<int64_t>(footprint(capacity_)) > available) {
(local::allocate data = 0;
(context, (footprint(capacity_)) * BytesPerWord, false)); } else {
data = static_cast<uintptr_t*>
(local::allocate
(context, (footprint(capacity_)) * BytesPerWord, false));
}
if (data == 0) { if (data == 0) {
if (capacity_ > minimum) { if (capacity_ > minimum) {
@ -809,7 +814,11 @@ initNextGen2(Context* c)
desired = InitialGen2CapacityInBytes / BytesPerWord; desired = InitialGen2CapacityInBytes / BytesPerWord;
} }
new (&(c->nextGen2)) Segment(c, &(c->nextHeapMap), desired, minimum); new (&(c->nextGen2)) Segment
(c, &(c->nextHeapMap), desired, minimum,
static_cast<int64_t>(c->limit / BytesPerWord)
- (static_cast<int64_t>(c->count / BytesPerWord)
- c->gen2.footprint(c->gen2.capacity())));
if (Verbose2) { if (Verbose2) {
fprintf(stderr, "init nextGen2 to %d bytes\n", fprintf(stderr, "init nextGen2 to %d bytes\n",