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, ...@@ -628,8 +628,6 @@ DEFINE_BOOL(always_inline_smi_code, false,
DEFINE_INT(min_semi_space_size, 0, DEFINE_INT(min_semi_space_size, 0,
"min size of a semi-space (in MBytes), the new space consists of two" "min size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces") "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, DEFINE_INT(max_semi_space_size, 0,
"max size of a semi-space (in MBytes), the new space consists of two" "max size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces") "semi-spaces")
......
...@@ -77,7 +77,6 @@ Heap::Heap() ...@@ -77,7 +77,6 @@ Heap::Heap()
reserved_semispace_size_(8 * (kPointerSize / 4) * MB), reserved_semispace_size_(8 * (kPointerSize / 4) * MB),
max_semi_space_size_(8 * (kPointerSize / 4) * MB), max_semi_space_size_(8 * (kPointerSize / 4) * MB),
initial_semispace_size_(Page::kPageSize), initial_semispace_size_(Page::kPageSize),
target_semispace_size_(Page::kPageSize),
max_old_generation_size_(700ul * (kPointerSize / 4) * MB), max_old_generation_size_(700ul * (kPointerSize / 4) * MB),
initial_old_generation_size_(max_old_generation_size_ / initial_old_generation_size_(max_old_generation_size_ /
kInitalOldGenerationLimitFactor), kInitalOldGenerationLimitFactor),
...@@ -4748,31 +4747,6 @@ bool Heap::ConfigureHeap(int max_semi_space_size, int max_old_space_size, ...@@ -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_); 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) { if (FLAG_semi_space_growth_factor < 2) {
FLAG_semi_space_growth_factor = 2; FLAG_semi_space_growth_factor = 2;
} }
......
...@@ -1183,7 +1183,6 @@ class Heap { ...@@ -1183,7 +1183,6 @@ class Heap {
int MaxSemiSpaceSize() { return max_semi_space_size_; } int MaxSemiSpaceSize() { return max_semi_space_size_; }
int ReservedSemiSpaceSize() { return reserved_semispace_size_; } int ReservedSemiSpaceSize() { return reserved_semispace_size_; }
int InitialSemiSpaceSize() { return initial_semispace_size_; } int InitialSemiSpaceSize() { return initial_semispace_size_; }
int TargetSemiSpaceSize() { return target_semispace_size_; }
intptr_t MaxOldGenerationSize() { return max_old_generation_size_; } intptr_t MaxOldGenerationSize() { return max_old_generation_size_; }
intptr_t MaxExecutableSize() { return max_executable_size_; } intptr_t MaxExecutableSize() { return max_executable_size_; }
......
This diff is collapsed.
...@@ -19,9 +19,19 @@ ...@@ -19,9 +19,19 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class AllocationInfo;
class CompactionSpace;
class CompactionSpaceCollection; class CompactionSpaceCollection;
class FreeList;
class InlineAllocationObserver; class InlineAllocationObserver;
class Isolate; class Isolate;
class MemoryAllocator;
class MemoryChunk;
class PagedSpace;
class SemiSpace;
class SkipList;
class SlotsBuffer;
class Space;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Heap structures: // Heap structures:
...@@ -97,13 +107,6 @@ class Isolate; ...@@ -97,13 +107,6 @@ class Isolate;
#define DCHECK_MAP_PAGE_INDEX(index) \ #define DCHECK_MAP_PAGE_INDEX(index) \
DCHECK((0 <= index) && (index <= MapSpace::kMaxMapPageIndex)) DCHECK((0 <= index) && (index <= MapSpace::kMaxMapPageIndex))
class AllocationInfo;
class CompactionSpace;
class FreeList;
class MemoryAllocator;
class MemoryChunk;
class PagedSpace;
class Space;
class MarkBit { class MarkBit {
public: public:
...@@ -285,9 +288,6 @@ class Bitmap { ...@@ -285,9 +288,6 @@ class Bitmap {
}; };
class SkipList;
class SlotsBuffer;
// MemoryChunk represents a memory region owned by a specific space. // MemoryChunk represents a memory region owned by a specific space.
// It is divided into the header and the body. Chunk start is always // 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 // 1MB aligned. Start of the body is aligned so it can accommodate
...@@ -2232,9 +2232,6 @@ class HistogramInfo : public NumberAndSizeInfo { ...@@ -2232,9 +2232,6 @@ class HistogramInfo : public NumberAndSizeInfo {
enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 }; enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 };
class SemiSpace;
class NewSpacePage : public MemoryChunk { class NewSpacePage : public MemoryChunk {
public: public:
// GC related flags copied from from-space to to-space when // GC related flags copied from from-space to to-space when
...@@ -2315,31 +2312,39 @@ class NewSpacePage : public MemoryChunk { ...@@ -2315,31 +2312,39 @@ class NewSpacePage : public MemoryChunk {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// SemiSpace in young generation // SemiSpace in young generation
// //
// A semispace is a contiguous chunk of memory holding page-like memory // A SemiSpace is a contiguous chunk of memory holding page-like memory chunks.
// chunks. The mark-compact collector uses the memory of the first page in // The mark-compact collector uses the memory of the first page in the from
// the from space as a marking stack when tracing live objects. // space as a marking stack when tracing live objects.
class SemiSpace : public Space { class SemiSpace : public Space {
public: public:
// Constructor. static void Swap(SemiSpace* from, SemiSpace* to);
SemiSpace(Heap* heap, SemiSpaceId semispace) SemiSpace(Heap* heap, SemiSpaceId semispace)
: Space(heap, NEW_SPACE, NOT_EXECUTABLE), : Space(heap, NEW_SPACE, NOT_EXECUTABLE),
start_(NULL), current_capacity_(0),
age_mark_(NULL), maximum_capacity_(0),
minimum_capacity_(0),
start_(nullptr),
age_mark_(nullptr),
address_mask_(0),
object_mask_(0),
object_expected_(0),
committed_(false),
id_(semispace), id_(semispace),
anchor_(this), anchor_(this),
current_page_(NULL) {} current_page_(nullptr) {}
// Sets up the semispace using the given chunk. // Creates a space in the young generation. The constructor does not
void SetUp(Address start, int initial_capacity, int target_capacity, // allocate memory from the OS. A SemiSpace is given a contiguous chunk of
int maximum_capacity); // 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 // Tear down the space. Heap memory was not allocated by the space, so it
// is not deallocated here. // is not deallocated here.
void TearDown(); void TearDown();
// 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_ != nullptr; }
// Grow the semispace to the new capacity. The new capacity // Grow the semispace to the new capacity. The new capacity
// requested must be larger than the current capacity and less than // requested must be larger than the current capacity and less than
...@@ -2351,12 +2356,9 @@ class SemiSpace : public Space { ...@@ -2351,12 +2356,9 @@ class SemiSpace : public Space {
// semispace and less than the current capacity. // semispace and less than the current capacity.
bool ShrinkTo(int new_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. // Returns the start address of the first page of the space.
Address space_start() { Address space_start() {
DCHECK(anchor_.next_page() != &anchor_); DCHECK_NE(anchor_.next_page(), &anchor_);
return anchor_.next_page()->area_start(); return anchor_.next_page()->area_start();
} }
...@@ -2396,6 +2398,27 @@ class SemiSpace : public Space { ...@@ -2396,6 +2398,27 @@ class SemiSpace : public Space {
return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; 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 // If we don't have these here then SemiSpace will be abstract. However
// they should never be called: // they should never be called:
...@@ -2411,18 +2434,6 @@ class SemiSpace : public Space { ...@@ -2411,18 +2434,6 @@ class SemiSpace : public Space {
return 0; 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 #ifdef DEBUG
void Print() override; void Print() override;
// Validate a range of of addresses in a SemiSpace. // Validate a range of of addresses in a SemiSpace.
...@@ -2434,40 +2445,29 @@ class SemiSpace : public Space { ...@@ -2434,40 +2445,29 @@ class SemiSpace : public Space {
inline static void AssertValidRange(Address from, Address to) {} inline static void AssertValidRange(Address from, Address to) {}
#endif #endif
// Returns the current total capacity of the semispace. #ifdef VERIFY_HEAP
int TotalCapacity() { return total_capacity_; } virtual void Verify();
#endif
// 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_; }
static void Swap(SemiSpace* from, SemiSpace* to); private:
NewSpacePage* anchor() { return &anchor_; }
// Approximate amount of physical memory committed for this space. void set_current_capacity(int new_capacity) {
size_t CommittedPhysicalMemory() override; current_capacity_ = new_capacity;
}
private: // Flips the semispace between being from-space and to-space. Copies the flags
// Flips the semispace between being from-space and to-space. // into the masked positions on all pages in the space.
// Copies the flags into the masked positions on all pages in the space.
void FlipPages(intptr_t flags, intptr_t flag_mask); void FlipPages(intptr_t flags, intptr_t flag_mask);
// Updates Capacity and MaximumCommitted based on new capacity. // The currently committed space capacity.
void SetCapacity(int new_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. // The mimnimum capacity for the space. A space cannot shrink below this size.
int total_capacity_; int minimum_capacity_;
int target_capacity_;
int maximum_total_capacity_;
int initial_total_capacity_;
// The start address of the space. // The start address of the space.
Address start_; Address start_;
...@@ -2579,9 +2579,6 @@ class NewSpace : public Space { ...@@ -2579,9 +2579,6 @@ class NewSpace : public Space {
// their maximum capacity. // their maximum capacity.
void Grow(); void Grow();
// Grow the capacity of the semispaces by one page.
bool GrowOnePage();
// Shrink the capacity of the semispaces. // Shrink the capacity of the semispaces.
void Shrink(); void Shrink();
...@@ -2610,16 +2607,16 @@ class NewSpace : public Space { ...@@ -2610,16 +2607,16 @@ class NewSpace : public Space {
// Return the allocatable capacity of a semispace. // Return the allocatable capacity of a semispace.
intptr_t Capacity() { intptr_t Capacity() {
SLOW_DCHECK(to_space_.TotalCapacity() == from_space_.TotalCapacity()); SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
return (to_space_.TotalCapacity() / Page::kPageSize) * return (to_space_.current_capacity() / Page::kPageSize) *
NewSpacePage::kAreaSize; NewSpacePage::kAreaSize;
} }
// Return the current size of a semispace, allocatable and non-allocatable // Return the current size of a semispace, allocatable and non-allocatable
// memory. // memory.
intptr_t TotalCapacity() { intptr_t TotalCapacity() {
DCHECK(to_space_.TotalCapacity() == from_space_.TotalCapacity()); DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
return to_space_.TotalCapacity(); return to_space_.current_capacity();
} }
// Committed memory for NewSpace is the committed memory of both semi-spaces // Committed memory for NewSpace is the committed memory of both semi-spaces
...@@ -2660,18 +2657,16 @@ class NewSpace : public Space { ...@@ -2660,18 +2657,16 @@ class NewSpace : public Space {
// Return the maximum capacity of a semispace. // Return the maximum capacity of a semispace.
int MaximumCapacity() { int MaximumCapacity() {
DCHECK(to_space_.MaximumTotalCapacity() == DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity());
from_space_.MaximumTotalCapacity()); return to_space_.maximum_capacity();
return to_space_.MaximumTotalCapacity();
} }
bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); } bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); }
// Returns the initial capacity of a semispace. // Returns the initial capacity of a semispace.
int InitialTotalCapacity() { int InitialTotalCapacity() {
DCHECK(to_space_.InitialTotalCapacity() == DCHECK(to_space_.minimum_capacity() == from_space_.minimum_capacity());
from_space_.InitialTotalCapacity()); return to_space_.minimum_capacity();
return to_space_.InitialTotalCapacity();
} }
// Return the address of the allocation pointer in the active semispace. // Return the address of the allocation pointer in the active semispace.
......
...@@ -744,50 +744,6 @@ TEST(SizeOfFirstPageIsLargeEnough) { ...@@ -744,50 +744,6 @@ TEST(SizeOfFirstPageIsLargeEnough) {
CHECK(isolate->heap()->lo_space()->IsEmpty()); 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) { static HeapObject* AllocateUnaligned(NewSpace* space, int size) {
AllocationResult allocation = space->AllocateRawUnaligned(size); AllocationResult allocation = space->AllocateRawUnaligned(size);
CHECK(!allocation.IsRetry()); 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