Commit 469259cd authored by ager@chromium.org's avatar ager@chromium.org

Reapply the semispace growth policy change in isolation.

Additionally fix NewSpace capacity bug by removing the duplicated
capacity and maximum capacity book keeping.  The capacity and maximum
capacity of NewSpace is the capacity and maximum capacity of one of
it's semispaces.

Review URL: http://codereview.chromium.org/174052

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2717 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fdf31f7f
...@@ -661,11 +661,11 @@ void Heap::Scavenge() { ...@@ -661,11 +661,11 @@ void Heap::Scavenge() {
if (new_space_.Capacity() < new_space_.MaximumCapacity() && if (new_space_.Capacity() < new_space_.MaximumCapacity() &&
survived_since_last_expansion_ > new_space_.Capacity()) { survived_since_last_expansion_ > new_space_.Capacity()) {
// Double the size of new space if there is room to grow and enough // Grow the size of new space if there is room to grow and enough
// data has survived scavenge since the last expansion. // data has survived scavenge since the last expansion.
// TODO(1240712): NewSpace::Double has a return value which is // TODO(1240712): NewSpace::Grow has a return value which is
// ignored here. // ignored here.
new_space_.Double(); new_space_.Grow();
survived_since_last_expansion_ = 0; survived_since_last_expansion_ = 0;
} }
......
...@@ -862,8 +862,6 @@ bool NewSpace::Setup(Address start, int size) { ...@@ -862,8 +862,6 @@ bool NewSpace::Setup(Address start, int size) {
ASSERT(initial_semispace_capacity <= maximum_semispace_capacity); ASSERT(initial_semispace_capacity <= maximum_semispace_capacity);
ASSERT(IsPowerOf2(maximum_semispace_capacity)); ASSERT(IsPowerOf2(maximum_semispace_capacity));
maximum_capacity_ = maximum_semispace_capacity;
capacity_ = initial_semispace_capacity;
// Allocate and setup the histogram arrays if necessary. // Allocate and setup the histogram arrays if necessary.
#if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
...@@ -876,15 +874,17 @@ bool NewSpace::Setup(Address start, int size) { ...@@ -876,15 +874,17 @@ bool NewSpace::Setup(Address start, int size) {
#undef SET_NAME #undef SET_NAME
#endif #endif
ASSERT(size == 2 * maximum_capacity_); ASSERT(size == 2 * maximum_semispace_capacity);
ASSERT(IsAddressAligned(start, size, 0)); ASSERT(IsAddressAligned(start, size, 0));
if (!to_space_.Setup(start, capacity_, maximum_capacity_)) { if (!to_space_.Setup(start,
initial_semispace_capacity,
maximum_semispace_capacity)) {
return false; return false;
} }
if (!from_space_.Setup(start + maximum_capacity_, if (!from_space_.Setup(start + maximum_semispace_capacity,
capacity_, initial_semispace_capacity,
maximum_capacity_)) { maximum_semispace_capacity)) {
return false; return false;
} }
...@@ -916,7 +916,6 @@ void NewSpace::TearDown() { ...@@ -916,7 +916,6 @@ void NewSpace::TearDown() {
#endif #endif
start_ = NULL; start_ = NULL;
capacity_ = 0;
allocation_info_.top = NULL; allocation_info_.top = NULL;
allocation_info_.limit = NULL; allocation_info_.limit = NULL;
mc_forwarding_info_.top = NULL; mc_forwarding_info_.top = NULL;
...@@ -952,13 +951,12 @@ void NewSpace::Flip() { ...@@ -952,13 +951,12 @@ void NewSpace::Flip() {
} }
bool NewSpace::Double() { bool NewSpace::Grow() {
ASSERT(capacity_ <= maximum_capacity_ / 2); ASSERT(Capacity() < MaximumCapacity());
// TODO(1240712): Failure to double the from space can result in // TODO(1240712): Failure to double the from space can result in
// semispaces of different sizes. In the event of that failure, the // semispaces of different sizes. In the event of that failure, the
// to space doubling should be rolled back before returning false. // to space doubling should be rolled back before returning false.
if (!to_space_.Double() || !from_space_.Double()) return false; if (!to_space_.Grow() || !from_space_.Grow()) return false;
capacity_ *= 2;
allocation_info_.limit = to_space_.high(); allocation_info_.limit = to_space_.high();
ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
return true; return true;
...@@ -1080,11 +1078,15 @@ void SemiSpace::TearDown() { ...@@ -1080,11 +1078,15 @@ void SemiSpace::TearDown() {
} }
bool SemiSpace::Double() { bool SemiSpace::Grow() {
if (!MemoryAllocator::CommitBlock(high(), capacity_, executable())) { // Commit 50% extra space but only up to maximum capacity.
int maximum_extra = maximum_capacity_ - capacity_;
int extra = Min(RoundUp(capacity_ / 2, OS::AllocateAlignment()),
maximum_extra);
if (!MemoryAllocator::CommitBlock(high(), extra, executable())) {
return false; return false;
} }
capacity_ *= 2; capacity_ += extra;
return true; return true;
} }
......
...@@ -1004,11 +1004,11 @@ class SemiSpace : public Space { ...@@ -1004,11 +1004,11 @@ class SemiSpace : public Space {
// True if the space has been set up but not torn down. // True if the space has been set up but not torn down.
bool HasBeenSetup() { return start_ != NULL; } bool HasBeenSetup() { return start_ != NULL; }
// Double the size of the semispace by committing extra virtual memory. // Grow the size of the semispace by committing extra virtual memory.
// Assumes that the caller has checked that the semispace has not reached // Assumes that the caller has checked that the semispace has not reached
// its maximum capacity (and thus there is space available in the reserved // its maximum capacity (and thus there is space available in the reserved
// address range to grow). // address range to grow).
bool Double(); bool Grow();
// Returns the start address of the space. // Returns the start address of the space.
Address low() { return start_; } Address low() { return start_; }
...@@ -1051,6 +1051,13 @@ class SemiSpace : public Space { ...@@ -1051,6 +1051,13 @@ class SemiSpace : public Space {
virtual void Verify(); virtual void Verify();
#endif #endif
// Returns the current capacity of the semi space.
int Capacity() { return capacity_; }
// Returns the maximum capacity of the semi space.
int MaximumCapacity() { return maximum_capacity_; }
private: private:
// The current and maximum capacity of the space. // The current and maximum capacity of the space.
int capacity_; int capacity_;
...@@ -1144,9 +1151,9 @@ class NewSpace : public Space { ...@@ -1144,9 +1151,9 @@ class NewSpace : public Space {
// Flip the pair of spaces. // Flip the pair of spaces.
void Flip(); void Flip();
// Doubles the capacity of the semispaces. Assumes that they are not at // Grow the capacity of the semispaces. Assumes that they are not at
// their maximum capacity. Returns a flag indicating success or failure. // their maximum capacity. Returns a flag indicating success or failure.
bool Double(); bool Grow();
// True if the address or object lies in the address range of either // True if the address or object lies in the address range of either
// semispace (not necessarily below the allocation pointer). // semispace (not necessarily below the allocation pointer).
...@@ -1161,12 +1168,18 @@ class NewSpace : public Space { ...@@ -1161,12 +1168,18 @@ class NewSpace : public Space {
// Return the allocated bytes in the active semispace. // Return the allocated bytes in the active semispace.
virtual int Size() { return top() - bottom(); } virtual int Size() { return top() - bottom(); }
// Return the current capacity of a semispace. // Return the current capacity of a semispace.
int Capacity() { return capacity_; } int Capacity() {
ASSERT(to_space_.Capacity() == from_space_.Capacity());
return to_space_.Capacity();
}
// Return the available bytes without growing in the active semispace. // Return the available bytes without growing in the active semispace.
int Available() { return Capacity() - Size(); } int Available() { return Capacity() - Size(); }
// Return the maximum capacity of a semispace. // Return the maximum capacity of a semispace.
int MaximumCapacity() { return maximum_capacity_; } int MaximumCapacity() {
ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity());
return to_space_.MaximumCapacity();
}
// Return the address of the allocation pointer in the active semispace. // Return the address of the allocation pointer in the active semispace.
Address top() { return allocation_info_.top; } Address top() { return allocation_info_.top; }
...@@ -1272,10 +1285,6 @@ class NewSpace : public Space { ...@@ -1272,10 +1285,6 @@ class NewSpace : public Space {
} }
private: private:
// The current and maximum capacities of a semispace.
int capacity_;
int maximum_capacity_;
// The semispaces. // The semispaces.
SemiSpace to_space_; SemiSpace to_space_;
SemiSpace from_space_; SemiSpace from_space_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment