Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: src/heap/spaces.cc

Issue 1863363004: [heap] Fix SemiSpace::Commit/GrowTo to deal with OOM (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix compilation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/spaces.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/spaces.h" 5 #include "src/heap/spaces.h"
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/full-codegen/full-codegen.h" 9 #include "src/full-codegen/full-codegen.h"
10 #include "src/heap/slot-set.h" 10 #include "src/heap/slot-set.h"
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // Properly uncommit memory to keep the allocator counters in sync. 1664 // Properly uncommit memory to keep the allocator counters in sync.
1665 if (is_committed()) Uncommit(); 1665 if (is_committed()) Uncommit();
1666 current_capacity_ = maximum_capacity_ = 0; 1666 current_capacity_ = maximum_capacity_ = 0;
1667 } 1667 }
1668 1668
1669 1669
1670 bool SemiSpace::Commit() { 1670 bool SemiSpace::Commit() {
1671 DCHECK(!is_committed()); 1671 DCHECK(!is_committed());
1672 NewSpacePage* current = anchor(); 1672 NewSpacePage* current = anchor();
1673 const int num_pages = current_capacity_ / Page::kPageSize; 1673 const int num_pages = current_capacity_ / Page::kPageSize;
1674 for (int i = 0; i < num_pages; i++) { 1674 for (int pages_added = 0; pages_added < num_pages; pages_added++) {
1675 NewSpacePage* new_page = 1675 NewSpacePage* new_page =
1676 heap() 1676 heap()
1677 ->memory_allocator() 1677 ->memory_allocator()
1678 ->AllocatePage<NewSpacePage, MemoryAllocator::kPooled>( 1678 ->AllocatePage<NewSpacePage, MemoryAllocator::kPooled>(
1679 NewSpacePage::kAllocatableMemory, this, executable()); 1679 NewSpacePage::kAllocatableMemory, this, executable());
1680 if (new_page == nullptr) {
1681 RewindPages(current, pages_added);
1682 return false;
1683 }
1680 new_page->InsertAfter(current); 1684 new_page->InsertAfter(current);
1681 current = new_page; 1685 current = new_page;
1682 } 1686 }
1683 Reset(); 1687 Reset();
1684 AccountCommitted(current_capacity_); 1688 AccountCommitted(current_capacity_);
1685 if (age_mark_ == nullptr) { 1689 if (age_mark_ == nullptr) {
1686 age_mark_ = first_page()->area_start(); 1690 age_mark_ = first_page()->area_start();
1687 } 1691 }
1688 committed_ = true; 1692 committed_ = true;
1689 return true; 1693 return true;
(...skipping 27 matching lines...) Expand all
1717 1721
1718 bool SemiSpace::GrowTo(int new_capacity) { 1722 bool SemiSpace::GrowTo(int new_capacity) {
1719 if (!is_committed()) { 1723 if (!is_committed()) {
1720 if (!Commit()) return false; 1724 if (!Commit()) return false;
1721 } 1725 }
1722 DCHECK_EQ(new_capacity & NewSpacePage::kPageAlignmentMask, 0); 1726 DCHECK_EQ(new_capacity & NewSpacePage::kPageAlignmentMask, 0);
1723 DCHECK_LE(new_capacity, maximum_capacity_); 1727 DCHECK_LE(new_capacity, maximum_capacity_);
1724 DCHECK_GT(new_capacity, current_capacity_); 1728 DCHECK_GT(new_capacity, current_capacity_);
1725 const int delta = new_capacity - current_capacity_; 1729 const int delta = new_capacity - current_capacity_;
1726 DCHECK(IsAligned(delta, base::OS::AllocateAlignment())); 1730 DCHECK(IsAligned(delta, base::OS::AllocateAlignment()));
1727 int delta_pages = delta / NewSpacePage::kPageSize; 1731 const int delta_pages = delta / NewSpacePage::kPageSize;
1728 NewSpacePage* last_page = anchor()->prev_page(); 1732 NewSpacePage* last_page = anchor()->prev_page();
1729 DCHECK_NE(last_page, anchor()); 1733 DCHECK_NE(last_page, anchor());
1730 while (delta_pages > 0) { 1734 for (int pages_added = 0; pages_added < delta_pages; pages_added++) {
1731 NewSpacePage* new_page = 1735 NewSpacePage* new_page =
1732 heap() 1736 heap()
1733 ->memory_allocator() 1737 ->memory_allocator()
1734 ->AllocatePage<NewSpacePage, MemoryAllocator::kPooled>( 1738 ->AllocatePage<NewSpacePage, MemoryAllocator::kPooled>(
1735 NewSpacePage::kAllocatableMemory, this, executable()); 1739 NewSpacePage::kAllocatableMemory, this, executable());
1740 if (new_page == nullptr) {
1741 RewindPages(last_page, pages_added);
1742 return false;
1743 }
1736 new_page->InsertAfter(last_page); 1744 new_page->InsertAfter(last_page);
1737 Bitmap::Clear(new_page); 1745 Bitmap::Clear(new_page);
1738 // Duplicate the flags that was set on the old page. 1746 // Duplicate the flags that was set on the old page.
1739 new_page->SetFlags(last_page->GetFlags(), 1747 new_page->SetFlags(last_page->GetFlags(),
1740 NewSpacePage::kCopyOnFlipFlagsMask); 1748 NewSpacePage::kCopyOnFlipFlagsMask);
1741 last_page = new_page; 1749 last_page = new_page;
1742 delta_pages--;
1743 } 1750 }
1744 AccountCommitted(static_cast<intptr_t>(delta)); 1751 AccountCommitted(static_cast<intptr_t>(delta));
1745 current_capacity_ = new_capacity; 1752 current_capacity_ = new_capacity;
1746 return true; 1753 return true;
1747 } 1754 }
1748 1755
1756 void SemiSpace::RewindPages(NewSpacePage* start, int num_pages) {
1757 NewSpacePage* new_last_page = nullptr;
1758 NewSpacePage* last_page = start;
1759 while (num_pages > 0) {
1760 DCHECK_NE(last_page, anchor());
1761 new_last_page = last_page->prev_page();
1762 last_page->prev_page()->set_next_page(last_page->next_page());
1763 last_page->next_page()->set_prev_page(last_page->prev_page());
1764 last_page = new_last_page;
1765 num_pages--;
1766 }
1767 }
1749 1768
1750 bool SemiSpace::ShrinkTo(int new_capacity) { 1769 bool SemiSpace::ShrinkTo(int new_capacity) {
1751 DCHECK_EQ(new_capacity & NewSpacePage::kPageAlignmentMask, 0); 1770 DCHECK_EQ(new_capacity & NewSpacePage::kPageAlignmentMask, 0);
1752 DCHECK_GE(new_capacity, minimum_capacity_); 1771 DCHECK_GE(new_capacity, minimum_capacity_);
1753 DCHECK_LT(new_capacity, current_capacity_); 1772 DCHECK_LT(new_capacity, current_capacity_);
1754 if (is_committed()) { 1773 if (is_committed()) {
1755 const int delta = current_capacity_ - new_capacity; 1774 const int delta = current_capacity_ - new_capacity;
1756 DCHECK(IsAligned(delta, base::OS::AllocateAlignment())); 1775 DCHECK(IsAligned(delta, base::OS::AllocateAlignment()));
1757 int delta_pages = delta / NewSpacePage::kPageSize; 1776 int delta_pages = delta / NewSpacePage::kPageSize;
1758 NewSpacePage* new_last_page; 1777 NewSpacePage* new_last_page;
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
3117 object->ShortPrint(); 3136 object->ShortPrint();
3118 PrintF("\n"); 3137 PrintF("\n");
3119 } 3138 }
3120 printf(" --------------------------------------\n"); 3139 printf(" --------------------------------------\n");
3121 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3140 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3122 } 3141 }
3123 3142
3124 #endif // DEBUG 3143 #endif // DEBUG
3125 } // namespace internal 3144 } // namespace internal
3126 } // namespace v8 3145 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698