Commit 8391d425 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Cleanup SemiSpace

- Remove semispace target capacity: It's unused and adds some unneeded
  complexity

- Enforcing decl order for SemiSpace
- Move forward declarations in spaces.h to top
- Add all members to default constructor

BUG=chromium:581076
LOG=N

Review URL: https://codereview.chromium.org/1631713002

Cr-Commit-Position: refs/heads/master@{#33515}
parent a59653a2
......@@ -628,8 +628,6 @@ DEFINE_BOOL(always_inline_smi_code, false,
DEFINE_INT(min_semi_space_size, 0,
"min size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces")
DEFINE_INT(target_semi_space_size, 0,
"target size of a semi-space (in MBytes) before triggering a GC")
DEFINE_INT(max_semi_space_size, 0,
"max size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces")
......
......@@ -77,7 +77,6 @@ Heap::Heap()
reserved_semispace_size_(8 * (kPointerSize / 4) * MB),
max_semi_space_size_(8 * (kPointerSize / 4) * MB),
initial_semispace_size_(Page::kPageSize),
target_semispace_size_(Page::kPageSize),
max_old_generation_size_(700ul * (kPointerSize / 4) * MB),
initial_old_generation_size_(max_old_generation_size_ /
kInitalOldGenerationLimitFactor),
......@@ -4748,31 +4747,6 @@ bool Heap::ConfigureHeap(int max_semi_space_size, int max_old_space_size,
initial_semispace_size_ = Min(initial_semispace_size_, max_semi_space_size_);
if (FLAG_target_semi_space_size > 0) {
int target_semispace_size = FLAG_target_semi_space_size * MB;
if (target_semispace_size < initial_semispace_size_) {
target_semispace_size_ = initial_semispace_size_;
if (FLAG_trace_gc) {
PrintIsolate(isolate_,
"Target semi-space size cannot be less than the minimum "
"semi-space size of %d MB\n",
initial_semispace_size_ / MB);
}
} else if (target_semispace_size > max_semi_space_size_) {
target_semispace_size_ = max_semi_space_size_;
if (FLAG_trace_gc) {
PrintIsolate(isolate_,
"Target semi-space size cannot be less than the maximum "
"semi-space size of %d MB\n",
max_semi_space_size_ / MB);
}
} else {
target_semispace_size_ = ROUND_UP(target_semispace_size, Page::kPageSize);
}
}
target_semispace_size_ = Max(initial_semispace_size_, target_semispace_size_);
if (FLAG_semi_space_growth_factor < 2) {
FLAG_semi_space_growth_factor = 2;
}
......
......@@ -1183,7 +1183,6 @@ class Heap {
int MaxSemiSpaceSize() { return max_semi_space_size_; }
int ReservedSemiSpaceSize() { return reserved_semispace_size_; }
int InitialSemiSpaceSize() { return initial_semispace_size_; }
int TargetSemiSpaceSize() { return target_semispace_size_; }
intptr_t MaxOldGenerationSize() { return max_old_generation_size_; }
intptr_t MaxExecutableSize() { return max_executable_size_; }
......
......@@ -1322,8 +1322,6 @@ bool NewSpace::SetUp(int reserved_semispace_capacity,
// this chunk must be a power of two and it must be aligned to its size.
int initial_semispace_capacity = heap()->InitialSemiSpaceSize();
int target_semispace_capacity = heap()->TargetSemiSpaceSize();
size_t size = 2 * reserved_semispace_capacity;
Address base = heap()->isolate()->memory_allocator()->ReserveAlignedMemory(
size, size, &reservation_);
......@@ -1352,10 +1350,9 @@ bool NewSpace::SetUp(int reserved_semispace_capacity,
DCHECK(IsAddressAligned(chunk_base_, 2 * reserved_semispace_capacity, 0));
to_space_.SetUp(chunk_base_, initial_semispace_capacity,
target_semispace_capacity, maximum_semispace_capacity);
maximum_semispace_capacity);
from_space_.SetUp(chunk_base_ + reserved_semispace_capacity,
initial_semispace_capacity, target_semispace_capacity,
maximum_semispace_capacity);
initial_semispace_capacity, maximum_semispace_capacity);
if (!to_space_.Commit()) {
return false;
}
......@@ -1411,7 +1408,7 @@ void NewSpace::Grow() {
if (!from_space_.GrowTo(new_capacity)) {
// If we managed to grow to-space but couldn't grow from-space,
// attempt to shrink to-space.
if (!to_space_.ShrinkTo(from_space_.TotalCapacity())) {
if (!to_space_.ShrinkTo(from_space_.current_capacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
CHECK(false);
......@@ -1422,36 +1419,6 @@ void NewSpace::Grow() {
}
bool NewSpace::GrowOnePage() {
if (TotalCapacity() == MaximumCapacity()) return false;
int new_capacity = static_cast<int>(TotalCapacity()) + Page::kPageSize;
if (to_space_.GrowTo(new_capacity)) {
// Only grow from space if we managed to grow to-space and the from space
// is actually committed.
if (from_space_.is_committed()) {
if (!from_space_.GrowTo(new_capacity)) {
// If we managed to grow to-space but couldn't grow from-space,
// attempt to shrink to-space.
if (!to_space_.ShrinkTo(from_space_.TotalCapacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
CHECK(false);
}
return false;
}
} else {
if (!from_space_.SetTotalCapacity(new_capacity)) {
// Can't really happen, but better safe than sorry.
CHECK(false);
}
}
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
return true;
}
return false;
}
void NewSpace::Shrink() {
int new_capacity = Max(InitialTotalCapacity(), 2 * SizeAsInt());
int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize);
......@@ -1462,7 +1429,7 @@ void NewSpace::Shrink() {
if (!from_space_.ShrinkTo(rounded_new_capacity)) {
// If we managed to shrink to-space but couldn't shrink from
// space, attempt to grow to-space again.
if (!to_space_.GrowTo(from_space_.TotalCapacity())) {
if (!to_space_.GrowTo(from_space_.current_capacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
CHECK(false);
......@@ -1559,29 +1526,10 @@ void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) {
bool NewSpace::AddFreshPage() {
Address top = allocation_info_.top();
if (NewSpacePage::IsAtStart(top)) {
// The current page is already empty. Don't try to make another.
// We should only get here if someone asks to allocate more
// than what can be stored in a single page.
// TODO(gc): Change the limit on new-space allocation to prevent this
// from happening (all such allocations should go directly to LOSpace).
return false;
}
DCHECK(!NewSpacePage::IsAtStart(top));
if (!to_space_.AdvancePage()) {
// Check if we reached the target capacity yet. If not, try to commit a page
// and continue.
if ((to_space_.TotalCapacity() < to_space_.TargetCapacity()) &&
GrowOnePage()) {
if (!to_space_.AdvancePage()) {
// It doesn't make sense that we managed to commit a page, but can't use
// it.
CHECK(false);
}
} else {
// Failed to get a new page in to-space.
return false;
}
// No more pages left to advance.
return false;
}
// Clear remainder of current page.
......@@ -1766,24 +1714,15 @@ void NewSpace::Verify() {
// -----------------------------------------------------------------------------
// SemiSpace implementation
void SemiSpace::SetUp(Address start, int initial_capacity, int target_capacity,
void SemiSpace::SetUp(Address start, int initial_capacity,
int maximum_capacity) {
// Creates a space in the young generation. The constructor does not
// allocate memory from the OS. A SemiSpace is given a contiguous chunk of
// memory of size 'capacity' when set up, and does not grow or shrink
// otherwise. In the mark-compact collector, the memory region of the from
// space is used as the marking stack. It requires contiguous memory
// addresses.
DCHECK(maximum_capacity >= Page::kPageSize);
DCHECK(initial_capacity <= target_capacity);
DCHECK(target_capacity <= maximum_capacity);
initial_total_capacity_ = RoundDown(initial_capacity, Page::kPageSize);
total_capacity_ = initial_capacity;
target_capacity_ = RoundDown(target_capacity, Page::kPageSize);
maximum_total_capacity_ = RoundDown(maximum_capacity, Page::kPageSize);
DCHECK_GE(maximum_capacity, Page::kPageSize);
minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize);
current_capacity_ = minimum_capacity_;
maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize);
committed_ = false;
start_ = start;
address_mask_ = ~(maximum_capacity - 1);
address_mask_ = ~(maximum_capacity_ - 1);
object_mask_ = address_mask_ | kHeapObjectTagMask;
object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag;
age_mark_ = start_ + NewSpacePage::kObjectStartOffset;
......@@ -1791,43 +1730,43 @@ void SemiSpace::SetUp(Address start, int initial_capacity, int target_capacity,
void SemiSpace::TearDown() {
start_ = NULL;
total_capacity_ = 0;
start_ = nullptr;
current_capacity_ = 0;
}
bool SemiSpace::Commit() {
DCHECK(!is_committed());
int pages = total_capacity_ / Page::kPageSize;
if (!heap()->isolate()->memory_allocator()->CommitBlock(
start_, total_capacity_, executable())) {
start_, current_capacity_, executable())) {
return false;
}
AccountCommitted(total_capacity_);
AccountCommitted(current_capacity_);
NewSpacePage* current = anchor();
for (int i = 0; i < pages; i++) {
const int num_pages = current_capacity_ / Page::kPageSize;
for (int i = 0; i < num_pages; i++) {
NewSpacePage* new_page =
NewSpacePage::Initialize(heap(), start_ + i * Page::kPageSize, this);
new_page->InsertAfter(current);
current = new_page;
}
Reset();
SetCapacity(total_capacity_);
set_current_capacity(current_capacity_);
committed_ = true;
Reset();
return true;
}
bool SemiSpace::Uncommit() {
DCHECK(is_committed());
Address start = start_ + maximum_total_capacity_ - total_capacity_;
if (!heap()->isolate()->memory_allocator()->UncommitBlock(start,
total_capacity_)) {
Address start = start_ + maximum_capacity_ - current_capacity_;
if (!heap()->isolate()->memory_allocator()->UncommitBlock(
start, current_capacity_)) {
return false;
}
AccountUncommitted(total_capacity_);
AccountUncommitted(current_capacity_);
anchor()->set_next_page(anchor());
anchor()->set_prev_page(anchor());
......@@ -1852,23 +1791,23 @@ bool SemiSpace::GrowTo(int new_capacity) {
if (!is_committed()) {
if (!Commit()) return false;
}
DCHECK((new_capacity & Page::kPageAlignmentMask) == 0);
DCHECK(new_capacity <= maximum_total_capacity_);
DCHECK(new_capacity > total_capacity_);
int pages_before = total_capacity_ / Page::kPageSize;
DCHECK_EQ(new_capacity & Page::kPageAlignmentMask, 0);
DCHECK_LE(new_capacity, maximum_capacity_);
DCHECK_GT(new_capacity, current_capacity_);
int pages_before = current_capacity_ / Page::kPageSize;
int pages_after = new_capacity / Page::kPageSize;
size_t delta = new_capacity - total_capacity_;
size_t delta = new_capacity - current_capacity_;
DCHECK(IsAligned(delta, base::OS::AllocateAlignment()));
if (!heap()->isolate()->memory_allocator()->CommitBlock(
start_ + total_capacity_, delta, executable())) {
start_ + current_capacity_, delta, executable())) {
return false;
}
AccountCommitted(static_cast<intptr_t>(delta));
SetCapacity(new_capacity);
set_current_capacity(new_capacity);
NewSpacePage* last_page = anchor()->prev_page();
DCHECK(last_page != anchor());
DCHECK_NE(last_page, anchor());
for (int i = pages_before; i < pages_after; i++) {
Address page_address = start_ + i * Page::kPageSize;
NewSpacePage* new_page =
......@@ -1885,11 +1824,11 @@ bool SemiSpace::GrowTo(int new_capacity) {
bool SemiSpace::ShrinkTo(int new_capacity) {
DCHECK((new_capacity & Page::kPageAlignmentMask) == 0);
DCHECK(new_capacity >= initial_total_capacity_);
DCHECK(new_capacity < total_capacity_);
DCHECK_EQ(new_capacity & Page::kPageAlignmentMask, 0);
DCHECK_GE(new_capacity, minimum_capacity_);
DCHECK_LT(new_capacity, current_capacity_);
if (is_committed()) {
size_t delta = total_capacity_ - new_capacity;
size_t delta = current_capacity_ - new_capacity;
DCHECK(IsAligned(delta, base::OS::AllocateAlignment()));
MemoryAllocator* allocator = heap()->isolate()->memory_allocator();
......@@ -1906,34 +1845,23 @@ bool SemiSpace::ShrinkTo(int new_capacity) {
DCHECK((current_page_ >= first_page()) && (current_page_ <= new_last_page));
}
SetCapacity(new_capacity);
set_current_capacity(new_capacity);
return true;
}
bool SemiSpace::SetTotalCapacity(int new_capacity) {
CHECK(!is_committed());
if (new_capacity >= initial_total_capacity_ &&
new_capacity <= maximum_total_capacity_) {
total_capacity_ = new_capacity;
return true;
}
return false;
}
void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) {
anchor_.set_owner(this);
// Fixup back-pointers to anchor. Address of anchor changes
// when we swap.
// Fixup back-pointers to anchor. Address of anchor changes when we swap.
anchor_.prev_page()->set_next_page(&anchor_);
anchor_.next_page()->set_prev_page(&anchor_);
bool becomes_to_space = (id_ == kFromSpace);
id_ = becomes_to_space ? kToSpace : kFromSpace;
NewSpacePage* page = anchor_.next_page();
while (page != &anchor_) {
NewSpacePageIterator it(this);
while (it.has_next()) {
NewSpacePage* page = it.next();
page->set_owner(this);
page->SetFlags(flags, mask);
if (becomes_to_space) {
......@@ -1948,21 +1876,20 @@ void SemiSpace::FlipPages(intptr_t flags, intptr_t mask) {
DCHECK(page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE));
DCHECK(page->IsFlagSet(MemoryChunk::IN_TO_SPACE) ||
page->IsFlagSet(MemoryChunk::IN_FROM_SPACE));
page = page->next_page();
}
}
void SemiSpace::Reset() {
DCHECK(anchor_.next_page() != &anchor_);
DCHECK_NE(anchor_.next_page(), &anchor_);
current_page_ = anchor_.next_page();
}
void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) {
// We won't be swapping semispaces without data in them.
DCHECK(from->anchor_.next_page() != &from->anchor_);
DCHECK(to->anchor_.next_page() != &to->anchor_);
DCHECK_NE(from->anchor_.next_page(), &from->anchor_);
DCHECK_NE(to->anchor_.next_page(), &to->anchor_);
// Swap bits.
SemiSpace tmp = *from;
......@@ -1980,13 +1907,8 @@ void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) {
}
void SemiSpace::SetCapacity(int new_capacity) {
total_capacity_ = new_capacity;
}
void SemiSpace::set_age_mark(Address mark) {
DCHECK(NewSpacePage::FromLimit(mark)->semi_space() == this);
DCHECK_EQ(NewSpacePage::FromLimit(mark)->semi_space(), this);
age_mark_ = mark;
// Mark all pages up to the one containing mark.
NewSpacePageIterator it(space_start(), mark);
......@@ -2006,7 +1928,7 @@ void SemiSpace::Verify() {
NewSpacePage* page = anchor_.next_page();
CHECK(anchor_.semi_space() == this);
while (page != &anchor_) {
CHECK(page->semi_space() == this);
CHECK_EQ(page->semi_space(), this);
CHECK(page->InNewSpace());
CHECK(page->IsFlagSet(is_from_space ? MemoryChunk::IN_FROM_SPACE
: MemoryChunk::IN_TO_SPACE));
......@@ -2026,7 +1948,7 @@ void SemiSpace::Verify() {
// black marking on the page (if we make it match in new-space).
}
CHECK(page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE));
CHECK(page->prev_page()->next_page() == page);
CHECK_EQ(page->prev_page()->next_page(), page);
page = page->next_page();
}
}
......@@ -2043,7 +1965,7 @@ void SemiSpace::AssertValidRange(Address start, Address end) {
// or end address is on a later page in the linked list of
// semi-space pages.
if (page == end_page) {
CHECK(start <= end);
CHECK_LE(start, end);
} else {
while (page != end_page) {
page = page->next_page();
......
......@@ -19,9 +19,19 @@
namespace v8 {
namespace internal {
class AllocationInfo;
class CompactionSpace;
class CompactionSpaceCollection;
class FreeList;
class InlineAllocationObserver;
class Isolate;
class MemoryAllocator;
class MemoryChunk;
class PagedSpace;
class SemiSpace;
class SkipList;
class SlotsBuffer;
class Space;
// -----------------------------------------------------------------------------
// Heap structures:
......@@ -97,13 +107,6 @@ class Isolate;
#define DCHECK_MAP_PAGE_INDEX(index) \
DCHECK((0 <= index) && (index <= MapSpace::kMaxMapPageIndex))
class AllocationInfo;
class CompactionSpace;
class FreeList;
class MemoryAllocator;
class MemoryChunk;
class PagedSpace;
class Space;
class MarkBit {
public:
......@@ -285,9 +288,6 @@ class Bitmap {
};
class SkipList;
class SlotsBuffer;
// MemoryChunk represents a memory region owned by a specific space.
// It is divided into the header and the body. Chunk start is always
// 1MB aligned. Start of the body is aligned so it can accommodate
......@@ -2232,9 +2232,6 @@ class HistogramInfo : public NumberAndSizeInfo {
enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 };
class SemiSpace;
class NewSpacePage : public MemoryChunk {
public:
// GC related flags copied from from-space to to-space when
......@@ -2315,31 +2312,39 @@ class NewSpacePage : public MemoryChunk {
// -----------------------------------------------------------------------------
// SemiSpace in young generation
//
// A semispace is a contiguous chunk of memory holding page-like memory
// chunks. The mark-compact collector uses the memory of the first page in
// the from space as a marking stack when tracing live objects.
// A SemiSpace is a contiguous chunk of memory holding page-like memory chunks.
// The mark-compact collector uses the memory of the first page in the from
// space as a marking stack when tracing live objects.
class SemiSpace : public Space {
public:
// Constructor.
static void Swap(SemiSpace* from, SemiSpace* to);
SemiSpace(Heap* heap, SemiSpaceId semispace)
: Space(heap, NEW_SPACE, NOT_EXECUTABLE),
start_(NULL),
age_mark_(NULL),
current_capacity_(0),
maximum_capacity_(0),
minimum_capacity_(0),
start_(nullptr),
age_mark_(nullptr),
address_mask_(0),
object_mask_(0),
object_expected_(0),
committed_(false),
id_(semispace),
anchor_(this),
current_page_(NULL) {}
current_page_(nullptr) {}
// Sets up the semispace using the given chunk.
void SetUp(Address start, int initial_capacity, int target_capacity,
int maximum_capacity);
// Creates a space in the young generation. The constructor does not
// allocate memory from the OS. A SemiSpace is given a contiguous chunk of
// memory of size {initial_capacity} when set up.
void SetUp(Address start, int initial_capacity, int maximum_capacity);
// Tear down the space. Heap memory was not allocated by the space, so it
// is not deallocated here.
void TearDown();
// True if the space has been set up but not torn down.
bool HasBeenSetUp() { return start_ != NULL; }
bool HasBeenSetUp() { return start_ != nullptr; }
// Grow the semispace to the new capacity. The new capacity
// requested must be larger than the current capacity and less than
......@@ -2351,12 +2356,9 @@ class SemiSpace : public Space {
// semispace and less than the current capacity.
bool ShrinkTo(int new_capacity);
// Sets the total capacity. Only possible when the space is not committed.
bool SetTotalCapacity(int new_capacity);
// Returns the start address of the first page of the space.
Address space_start() {
DCHECK(anchor_.next_page() != &anchor_);
DCHECK_NE(anchor_.next_page(), &anchor_);
return anchor_.next_page()->area_start();
}
......@@ -2396,6 +2398,27 @@ class SemiSpace : public Space {
return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_;
}
bool is_committed() { return committed_; }
bool Commit();
bool Uncommit();
NewSpacePage* first_page() { return anchor_.next_page(); }
NewSpacePage* current_page() { return current_page_; }
// Returns the current total capacity of the semispace.
int current_capacity() { return current_capacity_; }
// Returns the maximum total capacity of the semispace.
int maximum_capacity() { return maximum_capacity_; }
// Returns the initial capacity of the semispace.
int minimum_capacity() { return minimum_capacity_; }
SemiSpaceId id() { return id_; }
// Approximate amount of physical memory committed for this space.
size_t CommittedPhysicalMemory() override;
// If we don't have these here then SemiSpace will be abstract. However
// they should never be called:
......@@ -2411,18 +2434,6 @@ class SemiSpace : public Space {
return 0;
}
bool is_committed() { return committed_; }
bool Commit();
bool Uncommit();
NewSpacePage* first_page() { return anchor_.next_page(); }
NewSpacePage* current_page() { return current_page_; }
#ifdef VERIFY_HEAP
virtual void Verify();
#endif
#ifdef DEBUG
void Print() override;
// Validate a range of of addresses in a SemiSpace.
......@@ -2434,40 +2445,29 @@ class SemiSpace : public Space {
inline static void AssertValidRange(Address from, Address to) {}
#endif
// Returns the current total capacity of the semispace.
int TotalCapacity() { return total_capacity_; }
// Returns the target for total capacity of the semispace.
int TargetCapacity() { return target_capacity_; }
// Returns the maximum total capacity of the semispace.
int MaximumTotalCapacity() { return maximum_total_capacity_; }
// Returns the initial capacity of the semispace.
int InitialTotalCapacity() { return initial_total_capacity_; }
SemiSpaceId id() { return id_; }
#ifdef VERIFY_HEAP
virtual void Verify();
#endif
static void Swap(SemiSpace* from, SemiSpace* to);
private:
NewSpacePage* anchor() { return &anchor_; }
// Approximate amount of physical memory committed for this space.
size_t CommittedPhysicalMemory() override;
void set_current_capacity(int new_capacity) {
current_capacity_ = new_capacity;
}
private:
// Flips the semispace between being from-space and to-space.
// Copies the flags into the masked positions on all pages in the space.
// Flips the semispace between being from-space and to-space. Copies the flags
// into the masked positions on all pages in the space.
void FlipPages(intptr_t flags, intptr_t flag_mask);
// Updates Capacity and MaximumCommitted based on new capacity.
void SetCapacity(int new_capacity);
// The currently committed space capacity.
int current_capacity_;
NewSpacePage* anchor() { return &anchor_; }
// The maximum capacity that can be used by this space.
int maximum_capacity_;
// The current and maximum total capacity of the space.
int total_capacity_;
int target_capacity_;
int maximum_total_capacity_;
int initial_total_capacity_;
// The mimnimum capacity for the space. A space cannot shrink below this size.
int minimum_capacity_;
// The start address of the space.
Address start_;
......@@ -2579,9 +2579,6 @@ class NewSpace : public Space {
// their maximum capacity.
void Grow();
// Grow the capacity of the semispaces by one page.
bool GrowOnePage();
// Shrink the capacity of the semispaces.
void Shrink();
......@@ -2610,16 +2607,16 @@ class NewSpace : public Space {
// Return the allocatable capacity of a semispace.
intptr_t Capacity() {
SLOW_DCHECK(to_space_.TotalCapacity() == from_space_.TotalCapacity());
return (to_space_.TotalCapacity() / Page::kPageSize) *
SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
return (to_space_.current_capacity() / Page::kPageSize) *
NewSpacePage::kAreaSize;
}
// Return the current size of a semispace, allocatable and non-allocatable
// memory.
intptr_t TotalCapacity() {
DCHECK(to_space_.TotalCapacity() == from_space_.TotalCapacity());
return to_space_.TotalCapacity();
DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
return to_space_.current_capacity();
}
// Committed memory for NewSpace is the committed memory of both semi-spaces
......@@ -2660,18 +2657,16 @@ class NewSpace : public Space {
// Return the maximum capacity of a semispace.
int MaximumCapacity() {
DCHECK(to_space_.MaximumTotalCapacity() ==
from_space_.MaximumTotalCapacity());
return to_space_.MaximumTotalCapacity();
DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity());
return to_space_.maximum_capacity();
}
bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); }
// Returns the initial capacity of a semispace.
int InitialTotalCapacity() {
DCHECK(to_space_.InitialTotalCapacity() ==
from_space_.InitialTotalCapacity());
return to_space_.InitialTotalCapacity();
DCHECK(to_space_.minimum_capacity() == from_space_.minimum_capacity());
return to_space_.minimum_capacity();
}
// Return the address of the allocation pointer in the active semispace.
......
......@@ -744,50 +744,6 @@ TEST(SizeOfFirstPageIsLargeEnough) {
CHECK(isolate->heap()->lo_space()->IsEmpty());
}
UNINITIALIZED_TEST(NewSpaceGrowsToTargetCapacity) {
FLAG_target_semi_space_size = 2 * (Page::kPageSize / MB);
if (FLAG_optimize_for_size) return;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Context::New(isolate)->Enter();
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
NewSpace* new_space = i_isolate->heap()->new_space();
// This test doesn't work if we start with a non-default new space
// configuration.
if (new_space->InitialTotalCapacity() == Page::kPageSize) {
CHECK_EQ(new_space->CommittedMemory(), new_space->InitialTotalCapacity());
// Fill up the first (and only) page of the semi space.
FillCurrentPage(new_space);
// Try to allocate out of the new space. A new page should be added and
// the
// allocation should succeed.
v8::internal::AllocationResult allocation =
new_space->AllocateRawUnaligned(80);
CHECK(!allocation.IsRetry());
CHECK_EQ(new_space->CommittedMemory(), 2 * Page::kPageSize);
// Turn the allocation into a proper object so isolate teardown won't
// crash.
HeapObject* free_space = NULL;
CHECK(allocation.To(&free_space));
new_space->heap()->CreateFillerObjectAt(free_space->address(), 80);
}
}
isolate->Dispose();
}
static HeapObject* AllocateUnaligned(NewSpace* space, int size) {
AllocationResult allocation = space->AllocateRawUnaligned(size);
CHECK(!allocation.IsRetry());
......
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