Revision: 7736
Author: [email protected]
Date: Mon May 2 00:45:04 2011
Log: Make newspace semispaces be single page-sized memory chunks.
In anticipation of making them multi-paged.
Review URL: http://codereview.chromium.org/6905127
http://code.google.com/p/v8/source/detail?r=7736
Modified:
/branches/experimental/gc/src/heap.cc
/branches/experimental/gc/src/spaces.cc
/branches/experimental/gc/src/spaces.h
=======================================
--- /branches/experimental/gc/src/heap.cc Sun Apr 24 04:36:08 2011
+++ /branches/experimental/gc/src/heap.cc Mon May 2 00:45:04 2011
@@ -84,7 +84,7 @@
#else
reserved_semispace_size_(4*MB),
max_semispace_size_(4*MB),
- initial_semispace_size_(512*KB),
+ initial_semispace_size_(1*MB),
max_old_generation_size_(512*MB),
max_executable_size_(128*MB),
code_range_size_(0),
@@ -4644,7 +4644,12 @@
intptr_t max_executable_size) {
if (HasBeenSetup()) return false;
- if (max_semispace_size > 0) max_semispace_size_ = max_semispace_size;
+ if (max_semispace_size > 0) {
+ if (max_semispace_size < Page::kPageSize) {
+ max_semispace_size = Page::kPageSize;
+ }
+ max_semispace_size_ = max_semispace_size;
+ }
if (Snapshot::IsEnabled()) {
// If we are using a snapshot we always reserve the default amount
=======================================
--- /branches/experimental/gc/src/spaces.cc Sun Apr 24 04:36:08 2011
+++ /branches/experimental/gc/src/spaces.cc Mon May 2 00:45:04 2011
@@ -389,6 +389,16 @@
set_prev_page(this);
set_next_page(this);
}
+
+
+NewSpacePage* NewSpacePage::Initialize(Heap* heap, Address start) {
+ MemoryChunk* chunk = MemoryChunk::Initialize(heap,
+ start,
+ Page::kPageSize,
+ NOT_EXECUTABLE,
+ heap->new_space());
+ return static_cast<NewSpacePage*>(chunk);
+}
MemoryChunk* MemoryChunk::Initialize(Heap* heap,
@@ -1013,6 +1023,9 @@
return false;
}
committed_ = true;
+ // TODO(gc): When more than one page is present, initialize and
+ // chain them all.
+ current_page_ = NewSpacePage::Initialize(heap(), start_);
return true;
}
@@ -1040,11 +1053,16 @@
// otherwise. In the mark-compact collector, the memory region of the
from
// space is used as the marking stack. It requires contiguous memory
// addresses.
+ ASSERT(maximum_capacity >= Page::kPageSize);
+ if (initial_capacity < Page::kPageSize) {
+ initial_capacity = Page::kPageSize;
+ } else {
+ initial_capacity &= ~Page::kPageAlignmentMask;
+ }
initial_capacity_ = initial_capacity;
capacity_ = initial_capacity;
maximum_capacity_ = maximum_capacity;
committed_ = false;
-
start_ = start;
address_mask_ = ~(maximum_capacity - 1);
object_mask_ = address_mask_ | kHeapObjectTagMask;
@@ -1062,6 +1080,7 @@
bool SemiSpace::Grow() {
+ return false; // TODO(gc): Temporary hack while semispaces are only one
page.
// Double the semispace size but only up to maximum capacity.
int maximum_extra = maximum_capacity_ - capacity_;
int extra = Min(RoundUp(capacity_,
static_cast<int>(OS::AllocateAlignment())),
@@ -1076,6 +1095,7 @@
bool SemiSpace::GrowTo(int new_capacity) {
+ return false; // TODO(gc): Temporary hack while semispaces are only one
page.
ASSERT(new_capacity <= maximum_capacity_);
ASSERT(new_capacity > capacity_);
size_t delta = new_capacity - capacity_;
@@ -1090,6 +1110,7 @@
bool SemiSpace::ShrinkTo(int new_capacity) {
+ return false; // TODO(gc): Temporary hack while semispaces are only one
page.
ASSERT(new_capacity >= initial_capacity_);
ASSERT(new_capacity < capacity_);
size_t delta = capacity_ - new_capacity;
@@ -1129,7 +1150,8 @@
}
-void SemiSpaceIterator::Initialize(NewSpace* space, Address start,
+void SemiSpaceIterator::Initialize(NewSpace* space,
+ Address start,
Address end,
HeapObjectCallback size_func) {
ASSERT(space->ToSpaceContains(start));
@@ -1137,6 +1159,9 @@
&& end <= space->ToSpaceHigh());
space_ = &space->to_space_;
current_ = start;
+ NewSpacePage* page = NewSpacePage::FromAddress(start);
+ current_page_limit_ = page->body() + page->body_size();
+ if (current_page_limit_ > end) current_page_limit_ = end;
limit_ = end;
size_func_ = size_func;
}
=======================================
--- /branches/experimental/gc/src/spaces.h Sun Apr 24 04:36:08 2011
+++ /branches/experimental/gc/src/spaces.h Mon May 2 00:45:04 2011
@@ -1410,12 +1410,37 @@
#endif
+class NewSpacePage : public MemoryChunk {
+ public:
+ inline NewSpacePage* next_page() const {
+ return static_cast<NewSpacePage*>(next_chunk());
+ }
+
+ inline void set_next_page(NewSpacePage* page) {
+ set_next_chunk(page);
+ }
+ private:
+ // Finds the NewSpacePage containg the given address.
+ static NewSpacePage* FromAddress(Address address_in_page) {
+ Address page_start =
+
reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) &
+ ~Page::kPageAlignmentMask);
+ return reinterpret_cast<NewSpacePage*>(page_start);
+ }
+
+ static NewSpacePage* Initialize(Heap* heap, Address start);
+
+ friend class SemiSpace;
+ friend class SemiSpaceIterator;
+};
+
+
//
-----------------------------------------------------------------------------
// SemiSpace in young generation
//
-// A semispace is a contiguous chunk of memory. The mark-compact collector
-// uses the memory 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:
@@ -1451,9 +1476,15 @@
bool ShrinkTo(int new_capacity);
// Returns the start address of the space.
- Address low() { return start_; }
+ Address low() {
+ return NewSpacePage::FromAddress(start_)->body();
+ }
+
// Returns one past the end address of the space.
- Address high() { return low() + capacity_; }
+ Address high() {
+ // TODO(gc): Change when there is more than one page.
+ return current_page_->body() + current_page_->body_size();
+ }
// Age mark accessors.
Address age_mark() { return age_mark_; }
@@ -1492,6 +1523,9 @@
bool is_committed() { return committed_; }
bool Commit();
bool Uncommit();
+
+ NewSpacePage* first_page() { return NewSpacePage::FromAddress(start_); }
+ NewSpacePage* current_page() { return current_page_; }
#ifdef ENABLE_HEAP_PROTECTION
// Protect/unprotect the space by marking it read-only/writable.
@@ -1531,6 +1565,8 @@
bool committed_;
+ NewSpacePage* current_page_;
+
public:
TRACK_MEMORY("SemiSpace")
};
@@ -1551,6 +1587,9 @@
SemiSpaceIterator(NewSpace* space, Address start);
HeapObject* next() {
+ if (current_ == current_page_limit_) {
+ // TODO(gc): Add something here when we have more than one page.
+ }
if (current_ == limit_) return NULL;
HeapObject* object = HeapObject::FromAddress(current_);
@@ -1573,6 +1612,8 @@
SemiSpace* space_;
// The current iteration point.
Address current_;
+ // The end of the current page.
+ Address current_page_limit_;
// The end of iteration.
Address limit_;
// The callback function.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev