@@ -425,20 +425,12 @@ Address MemoryAllocator::AllocateAlignedMemory(
425
425
return base;
426
426
}
427
427
428
-
429
- void Page::InitializeAsAnchor (PagedSpace* owner) {
430
- set_owner (owner);
431
- set_prev_page (this );
432
- set_next_page (this );
433
- }
434
-
435
- void NewSpacePage::InitializeAsAnchor (SemiSpace* semi_space) {
436
- set_owner (semi_space);
428
+ void Page::InitializeAsAnchor (Space* space) {
429
+ set_owner (space);
437
430
set_next_chunk (this );
438
431
set_prev_chunk (this );
439
- // Flags marks this invalid page as not being in new-space.
440
- // All real new-space pages will be in new-space.
441
432
SetFlags (0 , ~0 );
433
+ SetFlag (ANCHOR);
442
434
}
443
435
444
436
MemoryChunk* MemoryChunk::Initialize (Heap* heap, Address base, size_t size,
@@ -772,12 +764,11 @@ template void MemoryAllocator::Free<MemoryAllocator::kRegular>(
772
764
template void MemoryAllocator::Free<MemoryAllocator::kPooled >(
773
765
MemoryChunk* chunk);
774
766
775
- template <typename PageType, MemoryAllocator::AllocationMode mode,
776
- typename SpaceType>
777
- PageType* MemoryAllocator::AllocatePage (intptr_t size, SpaceType* owner,
778
- Executability executable) {
767
+ template <MemoryAllocator::AllocationMode alloc_mode, typename SpaceType>
768
+ Page* MemoryAllocator::AllocatePage (intptr_t size, SpaceType* owner,
769
+ Executability executable) {
779
770
MemoryChunk* chunk = nullptr ;
780
- if (mode == kPooled ) {
771
+ if (alloc_mode == kPooled ) {
781
772
DCHECK_EQ (size, static_cast <intptr_t >(MemoryChunk::kAllocatableMemory ));
782
773
DCHECK_EQ (executable, NOT_EXECUTABLE);
783
774
chunk = AllocatePagePooled (owner);
@@ -786,21 +777,27 @@ PageType* MemoryAllocator::AllocatePage(intptr_t size, SpaceType* owner,
786
777
chunk = AllocateChunk (size, size, executable, owner);
787
778
}
788
779
if (chunk == nullptr ) return nullptr ;
789
- return PageType::Initialize (isolate_->heap (), chunk, executable, owner);
780
+ return Page::Initialize (isolate_->heap (), chunk, executable, owner);
781
+ }
782
+
783
+ template Page*
784
+ MemoryAllocator::AllocatePage<MemoryAllocator::kRegular , PagedSpace>(
785
+ intptr_t size, PagedSpace* owner, Executability executable);
786
+ template Page*
787
+ MemoryAllocator::AllocatePage<MemoryAllocator::kRegular , SemiSpace>(
788
+ intptr_t size, SemiSpace* owner, Executability executable);
789
+ template Page*
790
+ MemoryAllocator::AllocatePage<MemoryAllocator::kPooled , SemiSpace>(
791
+ intptr_t size, SemiSpace* owner, Executability executable);
792
+
793
+ LargePage* MemoryAllocator::AllocateLargePage (intptr_t size,
794
+ LargeObjectSpace* owner,
795
+ Executability executable) {
796
+ MemoryChunk* chunk = AllocateChunk (size, size, executable, owner);
797
+ if (chunk == nullptr ) return nullptr ;
798
+ return LargePage::Initialize (isolate_->heap (), chunk, executable, owner);
790
799
}
791
800
792
- template Page* MemoryAllocator::AllocatePage<Page, MemoryAllocator::kRegular ,
793
- PagedSpace>(intptr_t , PagedSpace*,
794
- Executability);
795
-
796
- template LargePage*
797
- MemoryAllocator::AllocatePage<LargePage, MemoryAllocator::kRegular , Space>(
798
- intptr_t , Space*, Executability);
799
-
800
- template NewSpacePage* MemoryAllocator::AllocatePage<
801
- NewSpacePage, MemoryAllocator::kPooled , SemiSpace>(intptr_t , SemiSpace*,
802
- Executability);
803
-
804
801
template <typename SpaceType>
805
802
MemoryChunk* MemoryAllocator::AllocatePagePooled (SpaceType* owner) {
806
803
if (chunk_pool_.is_empty ()) return nullptr ;
@@ -1041,13 +1038,11 @@ void Space::AllocationStep(Address soon_object, int size) {
1041
1038
1042
1039
PagedSpace::PagedSpace (Heap* heap, AllocationSpace space,
1043
1040
Executability executable)
1044
- : Space (heap, space, executable), free_list_ (this ) {
1041
+ : Space (heap, space, executable), anchor_ ( this ), free_list_ (this ) {
1045
1042
area_size_ = MemoryAllocator::PageAreaSize (space);
1046
1043
accounting_stats_.Clear ();
1047
1044
1048
1045
allocation_info_.Reset (nullptr , nullptr );
1049
-
1050
- anchor_.InitializeAsAnchor (this );
1051
1046
}
1052
1047
1053
1048
@@ -1180,8 +1175,7 @@ bool PagedSpace::Expand() {
1180
1175
1181
1176
if (!heap ()->CanExpandOldGeneration (size)) return false ;
1182
1177
1183
- Page* p =
1184
- heap ()->memory_allocator ()->AllocatePage <Page>(size, this , executable ());
1178
+ Page* p = heap ()->memory_allocator ()->AllocatePage (size, this , executable ());
1185
1179
if (p == nullptr ) return false ;
1186
1180
1187
1181
AccountCommitted (static_cast <intptr_t >(p->size ()));
@@ -1240,7 +1234,7 @@ void PagedSpace::ReleasePage(Page* page) {
1240
1234
free_list_.EvictFreeListItems (page);
1241
1235
DCHECK (!free_list_.ContainsPageFreeListItems (page));
1242
1236
1243
- if (Page::FromAllocationTop (allocation_info_.top ()) == page) {
1237
+ if (Page::FromAllocationAreaAddress (allocation_info_.top ()) == page) {
1244
1238
allocation_info_.Reset (nullptr , nullptr );
1245
1239
}
1246
1240
@@ -1269,7 +1263,7 @@ void PagedSpace::Verify(ObjectVisitor* visitor) {
1269
1263
while (page_iterator.has_next ()) {
1270
1264
Page* page = page_iterator.next ();
1271
1265
CHECK (page->owner () == this );
1272
- if (page == Page::FromAllocationTop (allocation_info_.top ())) {
1266
+ if (page == Page::FromAllocationAreaAddress (allocation_info_.top ())) {
1273
1267
allocation_pointer_found_in_space = true ;
1274
1268
}
1275
1269
CHECK (page->SweepingDone ());
@@ -1488,22 +1482,22 @@ void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) {
1488
1482
1489
1483
bool NewSpace::AddFreshPage () {
1490
1484
Address top = allocation_info_.top ();
1491
- DCHECK (!NewSpacePage::IsAtStart (top));
1485
+ DCHECK (!Page::IsAtObjectStart (top));
1492
1486
if (!to_space_.AdvancePage ()) {
1493
1487
// No more pages left to advance.
1494
1488
return false ;
1495
1489
}
1496
1490
1497
1491
// Clear remainder of current page.
1498
- Address limit = NewSpacePage::FromLimit (top)->area_end ();
1492
+ Address limit = Page::FromAllocationAreaAddress (top)->area_end ();
1499
1493
if (heap ()->gc_state () == Heap::SCAVENGE) {
1500
1494
heap ()->promotion_queue ()->SetNewLimit (limit);
1501
1495
}
1502
1496
1503
1497
int remaining_in_page = static_cast <int >(limit - top);
1504
1498
heap ()->CreateFillerObjectAt (top, remaining_in_page, ClearRecordedSlots::kNo );
1505
1499
pages_used_++;
1506
- allocated_since_last_gc_ += NewSpacePage ::kAllocatableMemory ;
1500
+ allocated_since_last_gc_ += Page ::kAllocatableMemory ;
1507
1501
UpdateAllocationInfo ();
1508
1502
1509
1503
return true ;
@@ -1622,9 +1616,9 @@ void NewSpace::Verify() {
1622
1616
CHECK_EQ (current, to_space_.space_start ());
1623
1617
1624
1618
while (current != top ()) {
1625
- if (!NewSpacePage::IsAtEnd (current)) {
1619
+ if (!Page::IsAlignedToPageSize (current)) {
1626
1620
// The allocation pointer should not be in the middle of an object.
1627
- CHECK (!NewSpacePage::FromLimit (current)->ContainsLimit (top ()) ||
1621
+ CHECK (!Page::FromAllocationAreaAddress (current)->ContainsLimit (top ()) ||
1628
1622
current < top ());
1629
1623
1630
1624
HeapObject* object = HeapObject::FromAddress (current);
@@ -1650,7 +1644,7 @@ void NewSpace::Verify() {
1650
1644
current += size;
1651
1645
} else {
1652
1646
// At end of page, switch to next page.
1653
- NewSpacePage * page = NewSpacePage::FromLimit (current)->next_page ();
1647
+ Page * page = Page::FromAllocationAreaAddress (current)->next_page ();
1654
1648
// Next page should be valid.
1655
1649
CHECK (!page->is_anchor ());
1656
1650
current = page->area_start ();
@@ -1686,14 +1680,12 @@ void SemiSpace::TearDown() {
1686
1680
1687
1681
bool SemiSpace::Commit () {
1688
1682
DCHECK (!is_committed ());
1689
- NewSpacePage * current = anchor ();
1683
+ Page * current = anchor ();
1690
1684
const int num_pages = current_capacity_ / Page::kPageSize ;
1691
1685
for (int pages_added = 0 ; pages_added < num_pages; pages_added++) {
1692
- NewSpacePage* new_page =
1693
- heap ()
1694
- ->memory_allocator ()
1695
- ->AllocatePage <NewSpacePage, MemoryAllocator::kPooled >(
1696
- NewSpacePage::kAllocatableMemory , this , executable ());
1686
+ Page* new_page =
1687
+ heap ()->memory_allocator ()->AllocatePage <MemoryAllocator::kPooled >(
1688
+ Page::kAllocatableMemory , this , executable ());
1697
1689
if (new_page == nullptr ) {
1698
1690
RewindPages (current, pages_added);
1699
1691
return false ;
@@ -1740,39 +1732,36 @@ bool SemiSpace::GrowTo(int new_capacity) {
1740
1732
if (!is_committed ()) {
1741
1733
if (!Commit ()) return false ;
1742
1734
}
1743
- DCHECK_EQ (new_capacity & NewSpacePage ::kPageAlignmentMask , 0 );
1735
+ DCHECK_EQ (new_capacity & Page ::kPageAlignmentMask , 0 );
1744
1736
DCHECK_LE (new_capacity, maximum_capacity_);
1745
1737
DCHECK_GT (new_capacity, current_capacity_);
1746
1738
const int delta = new_capacity - current_capacity_;
1747
1739
DCHECK (IsAligned (delta, base::OS::AllocateAlignment ()));
1748
- const int delta_pages = delta / NewSpacePage ::kPageSize ;
1749
- NewSpacePage * last_page = anchor ()->prev_page ();
1740
+ const int delta_pages = delta / Page ::kPageSize ;
1741
+ Page * last_page = anchor ()->prev_page ();
1750
1742
DCHECK_NE (last_page, anchor ());
1751
1743
for (int pages_added = 0 ; pages_added < delta_pages; pages_added++) {
1752
- NewSpacePage* new_page =
1753
- heap ()
1754
- ->memory_allocator ()
1755
- ->AllocatePage <NewSpacePage, MemoryAllocator::kPooled >(
1756
- NewSpacePage::kAllocatableMemory , this , executable ());
1744
+ Page* new_page =
1745
+ heap ()->memory_allocator ()->AllocatePage <MemoryAllocator::kPooled >(
1746
+ Page::kAllocatableMemory , this , executable ());
1757
1747
if (new_page == nullptr ) {
1758
1748
RewindPages (last_page, pages_added);
1759
1749
return false ;
1760
1750
}
1761
1751
new_page->InsertAfter (last_page);
1762
1752
Bitmap::Clear (new_page);
1763
1753
// Duplicate the flags that was set on the old page.
1764
- new_page->SetFlags (last_page->GetFlags (),
1765
- NewSpacePage::kCopyOnFlipFlagsMask );
1754
+ new_page->SetFlags (last_page->GetFlags (), Page::kCopyOnFlipFlagsMask );
1766
1755
last_page = new_page;
1767
1756
}
1768
1757
AccountCommitted (static_cast <intptr_t >(delta));
1769
1758
current_capacity_ = new_capacity;
1770
1759
return true ;
1771
1760
}
1772
1761
1773
- void SemiSpace::RewindPages (NewSpacePage * start, int num_pages) {
1774
- NewSpacePage * new_last_page = nullptr ;
1775
- NewSpacePage * last_page = start;
1762
+ void SemiSpace::RewindPages (Page * start, int num_pages) {
1763
+ Page * new_last_page = nullptr ;
1764
+ Page * last_page = start;
1776
1765
while (num_pages > 0 ) {
1777
1766
DCHECK_NE (last_page, anchor ());
1778
1767
new_last_page = last_page->prev_page ();
@@ -1784,15 +1773,15 @@ void SemiSpace::RewindPages(NewSpacePage* start, int num_pages) {
1784
1773
}
1785
1774
1786
1775
bool SemiSpace::ShrinkTo (int new_capacity) {
1787
- DCHECK_EQ (new_capacity & NewSpacePage ::kPageAlignmentMask , 0 );
1776
+ DCHECK_EQ (new_capacity & Page ::kPageAlignmentMask , 0 );
1788
1777
DCHECK_GE (new_capacity, minimum_capacity_);
1789
1778
DCHECK_LT (new_capacity, current_capacity_);
1790
1779
if (is_committed ()) {
1791
1780
const int delta = current_capacity_ - new_capacity;
1792
1781
DCHECK (IsAligned (delta, base::OS::AllocateAlignment ()));
1793
- int delta_pages = delta / NewSpacePage ::kPageSize ;
1794
- NewSpacePage * new_last_page;
1795
- NewSpacePage * last_page;
1782
+ int delta_pages = delta / Page ::kPageSize ;
1783
+ Page * new_last_page;
1784
+ Page * last_page;
1796
1785
while (delta_pages > 0 ) {
1797
1786
last_page = anchor ()->prev_page ();
1798
1787
new_last_page = last_page->prev_page ();
@@ -1809,13 +1798,12 @@ bool SemiSpace::ShrinkTo(int new_capacity) {
1809
1798
1810
1799
void SemiSpace::FixPagesFlags (intptr_t flags, intptr_t mask) {
1811
1800
anchor_.set_owner (this );
1812
- // Fixup back-pointers to anchor. Address of anchor changes when we swap.
1813
1801
anchor_.prev_page ()->set_next_page (&anchor_);
1814
1802
anchor_.next_page ()->set_prev_page (&anchor_);
1815
1803
1816
1804
NewSpacePageIterator it (this );
1817
1805
while (it.has_next ()) {
1818
- NewSpacePage * page = it.next ();
1806
+ Page * page = it.next ();
1819
1807
page->set_owner (this );
1820
1808
page->SetFlags (flags, mask);
1821
1809
if (id_ == kToSpace ) {
@@ -1838,12 +1826,11 @@ void SemiSpace::Reset() {
1838
1826
current_page_ = anchor_.next_page ();
1839
1827
}
1840
1828
1841
- void SemiSpace::ReplaceWithEmptyPage (NewSpacePage* old_page) {
1842
- NewSpacePage* new_page =
1843
- heap ()->memory_allocator ()->AllocatePage <NewSpacePage>(
1844
- NewSpacePage::kAllocatableMemory , this , executable ());
1829
+ void SemiSpace::ReplaceWithEmptyPage (Page* old_page) {
1830
+ Page* new_page = heap ()->memory_allocator ()->AllocatePage (
1831
+ Page::kAllocatableMemory , this , executable ());
1845
1832
Bitmap::Clear (new_page);
1846
- new_page->SetFlags (old_page->GetFlags (), NewSpacePage ::kCopyAllFlags );
1833
+ new_page->SetFlags (old_page->GetFlags (), Page ::kCopyAllFlags );
1847
1834
new_page->set_next_page (old_page->next_page ());
1848
1835
new_page->set_prev_page (old_page->prev_page ());
1849
1836
old_page->next_page ()->set_prev_page (new_page);
@@ -1868,13 +1855,13 @@ void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) {
1868
1855
std::swap (from->anchor_ , to->anchor_ );
1869
1856
std::swap (from->current_page_ , to->current_page_ );
1870
1857
1871
- to->FixPagesFlags (saved_to_space_flags, NewSpacePage ::kCopyOnFlipFlagsMask );
1858
+ to->FixPagesFlags (saved_to_space_flags, Page ::kCopyOnFlipFlagsMask );
1872
1859
from->FixPagesFlags (0 , 0 );
1873
1860
}
1874
1861
1875
1862
1876
1863
void SemiSpace::set_age_mark (Address mark) {
1877
- DCHECK_EQ (NewSpacePage::FromLimit (mark)->semi_space (), this );
1864
+ DCHECK_EQ (Page::FromAllocationAreaAddress (mark)->owner (), this );
1878
1865
age_mark_ = mark;
1879
1866
// Mark all pages up to the one containing mark.
1880
1867
NewSpacePageIterator it (space_start (), mark);
@@ -1891,10 +1878,10 @@ void SemiSpace::Print() {}
1891
1878
#ifdef VERIFY_HEAP
1892
1879
void SemiSpace::Verify () {
1893
1880
bool is_from_space = (id_ == kFromSpace );
1894
- NewSpacePage * page = anchor_.next_page ();
1895
- CHECK (anchor_.semi_space () == this );
1881
+ Page * page = anchor_.next_page ();
1882
+ CHECK (anchor_.owner () == this );
1896
1883
while (page != &anchor_) {
1897
- CHECK_EQ (page->semi_space (), this );
1884
+ CHECK_EQ (page->owner (), this );
1898
1885
CHECK (page->InNewSpace ());
1899
1886
CHECK (page->IsFlagSet (is_from_space ? MemoryChunk::IN_FROM_SPACE
1900
1887
: MemoryChunk::IN_TO_SPACE));
@@ -1922,10 +1909,10 @@ void SemiSpace::Verify() {
1922
1909
#ifdef DEBUG
1923
1910
void SemiSpace::AssertValidRange (Address start, Address end) {
1924
1911
// Addresses belong to same semi-space
1925
- NewSpacePage * page = NewSpacePage::FromLimit (start);
1926
- NewSpacePage * end_page = NewSpacePage::FromLimit (end);
1927
- SemiSpace* space = page->semi_space ( );
1928
- CHECK_EQ (space, end_page->semi_space ());
1912
+ Page * page = Page::FromAllocationAreaAddress (start);
1913
+ Page * end_page = Page::FromAllocationAreaAddress (end);
1914
+ SemiSpace* space = reinterpret_cast <SemiSpace*>( page->owner () );
1915
+ CHECK_EQ (space, end_page->owner ());
1929
1916
// Start address is before end address, either on same page,
1930
1917
// or end address is on a later page in the linked list of
1931
1918
// semi-space pages.
@@ -2599,7 +2586,7 @@ void PagedSpace::RepairFreeListsAfterDeserialization() {
2599
2586
void PagedSpace::EvictEvacuationCandidatesFromLinearAllocationArea () {
2600
2587
if (allocation_info_.top () >= allocation_info_.limit ()) return ;
2601
2588
2602
- if (!Page::FromAllocationTop (allocation_info_.top ())->CanAllocate ()) {
2589
+ if (!Page::FromAllocationAreaAddress (allocation_info_.top ())->CanAllocate ()) {
2603
2590
// Create filler object to keep page iterable if it was iterable.
2604
2591
int remaining =
2605
2592
static_cast <int >(allocation_info_.limit () - allocation_info_.top ());
@@ -2908,7 +2895,7 @@ AllocationResult LargeObjectSpace::AllocateRaw(int object_size,
2908
2895
return AllocationResult::Retry (identity ());
2909
2896
}
2910
2897
2911
- LargePage* page = heap ()->memory_allocator ()->AllocatePage <LargePage> (
2898
+ LargePage* page = heap ()->memory_allocator ()->AllocateLargePage (
2912
2899
object_size, this , executable);
2913
2900
if (page == NULL ) return AllocationResult::Retry (identity ());
2914
2901
DCHECK (page->area_size () >= object_size);
@@ -2977,7 +2964,7 @@ LargePage* LargeObjectSpace::FindPage(Address a) {
2977
2964
if (e != NULL ) {
2978
2965
DCHECK (e->value != NULL );
2979
2966
LargePage* page = reinterpret_cast <LargePage*>(e->value );
2980
- DCHECK (page-> is_valid ( ));
2967
+ DCHECK (LargePage::IsValid (page ));
2981
2968
if (page->Contains (a)) {
2982
2969
return page;
2983
2970
}
0 commit comments