Index: src/heap/spaces.cc |
diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc |
index a0eae92d69f994b9d78be8d544b86beb6bd8eacd..083bd934c3056710989003e0e7e7dd7eab04a8f2 100644 |
--- a/src/heap/spaces.cc |
+++ b/src/heap/spaces.cc |
@@ -1386,6 +1386,46 @@ void NewSpace::TearDown() { |
from_space_.TearDown(); |
} |
+void NewSpace::SwapFromSpacePageWithToSpacePage(Page* from_space_page) { |
+ // The method is called when replacing a *to* space page with a *from* space |
+ // page when moving a page within new space. Since there's still a full page |
+ // to move (which would've been copied otherwise) *to* space cannot be |
+ // on the last page. |
+ DCHECK(!to_space_.OnLastPage()); |
+ |
+ Page* to_space_page = to_space_.anchor()->prev_page(); |
+ Page* from_space_page_prev_page = from_space_page->prev_page(); |
+ SwapPages(from_space_page, to_space_page, to_space_.anchor(), |
+ from_space_page_prev_page); |
+ // Since we removed an unused to space page but added a used one we need |
+ // to increment the page counter. |
+ pages_used_++; |
+} |
+ |
+void NewSpace::SwapPages(Page* from_space_page, Page* to_space_page, |
+ Page* from_target, Page* to_target) { |
+ DCHECK(from_space_page->InFromSpace()); |
+ DCHECK(to_space_page->InToSpace()); |
+ to_space_page->Unlink(); |
+ from_space_page->Unlink(); |
+ // Swap owner. |
+ to_space_page->set_owner(&from_space_); |
+ from_space_page->set_owner(&to_space_); |
+ // Swap flags. |
+ intptr_t tmp_flags = to_space_page->GetFlags(); |
+ to_space_page->SetFlags(from_space_page->GetFlags(), Page::kCopyAllFlags); |
+ from_space_page->SetFlags(tmp_flags, Page::kCopyAllFlags); |
+ // Insert again. |
+ to_space_page->InsertAfter(to_target); |
+ from_space_page->InsertAfter(from_target); |
+ DCHECK(to_space_page->InFromSpace()); |
+ DCHECK(from_space_page->InToSpace()); |
+ // Update current page of space. |
+ if (from_space_.current_page() == from_space_page) |
+ from_space_.current_page_ = to_space_page; |
+ if (to_space_.current_page() == to_space_page) |
+ to_space_.current_page_ = from_space_page; |
+} |
void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); } |