Reviewers: Erik Corry,

Description:
Make newspace semispaces be single page-sized memory chunks.

In anticipation of making them multi-paged.


Please review this at http://codereview.chromium.org/6905127/

SVN Base: https://v8.googlecode.com/svn/branches/experimental/gc

Affected files:
  M src/heap.cc
  M src/spaces.h
  M src/spaces.cc


Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index e0c04d9633fa0d1e38776a6f26011623f07e19fb..c291365b37c81cb840271a69d8236d94dd8e2f57 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -84,7 +84,7 @@ Heap::Heap()
 #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 @@ bool Heap::ConfigureHeap(intptr_t max_semispace_size,
                          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
Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 3001c9fe89d79cb866a68cdd175e9b00ddf7e02d..570ce0f200a45f22b3e215be970dc3eeff15416c 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -391,6 +391,16 @@ void Page::InitializeAsAnchor(PagedSpace* owner) {
 }


+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,
                                      Address base,
                                      size_t size,
@@ -1013,6 +1023,9 @@ bool SemiSpace::Commit() {
     return false;
   }
   committed_ = true;
+  // FIXME: When more than one page is present, initialize and
+  // chain them all.
+  current_page_ = NewSpacePage::Initialize(heap(), start_);
   return true;
 }

@@ -1040,11 +1053,16 @@ bool SemiSpace::Setup(Address start,
// 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 @@ void SemiSpace::TearDown() {


 bool SemiSpace::Grow() {
+ return false; // FIXME: 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::Grow() {


 bool SemiSpace::GrowTo(int new_capacity) {
+ return false; // FIXME: 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::GrowTo(int new_capacity) {


 bool SemiSpace::ShrinkTo(int new_capacity) {
+ return false; // FIXME: 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 @@ SemiSpaceIterator::SemiSpaceIterator(NewSpace* space, Address start) {
 }


-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 @@ void SemiSpaceIterator::Initialize(NewSpace* space, Address start,
          && 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;
 }
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index cdcacbb43f0b2a4a0c53fa180f0b087192df2b84..585fe9a632fb04519dbad48c59348ce4edc07846 100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -1410,12 +1410,37 @@ class HistogramInfo: public NumberAndSizeInfo {
 #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 @@ class SemiSpace : public Space {
   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() {
+    // FIXME: 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_; }
@@ -1493,6 +1524,9 @@ class SemiSpace : public Space {
   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.
   virtual void Protect() {}
@@ -1531,6 +1565,8 @@ class SemiSpace : public Space {

   bool committed_;

+  NewSpacePage* current_page_;
+
  public:
   TRACK_MEMORY("SemiSpace")
 };
@@ -1551,6 +1587,9 @@ class SemiSpaceIterator : public ObjectIterator {
   SemiSpaceIterator(NewSpace* space, Address start);

   HeapObject* next() {
+    if (current_ == current_page_limit_) {
+      // FIXME: Add something here when we have more than one page.
+    }
     if (current_ == limit_) return NULL;

     HeapObject* object = HeapObject::FromAddress(current_);
@@ -1573,6 +1612,8 @@ class SemiSpaceIterator : public ObjectIterator {
   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

Reply via email to