OLD | NEW |
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/base/platform/semaphore.h" | 9 #include "src/base/platform/semaphore.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 DeleteArray(promoted_histogram_); | 1379 DeleteArray(promoted_histogram_); |
1380 promoted_histogram_ = NULL; | 1380 promoted_histogram_ = NULL; |
1381 } | 1381 } |
1382 | 1382 |
1383 allocation_info_.Reset(nullptr, nullptr); | 1383 allocation_info_.Reset(nullptr, nullptr); |
1384 | 1384 |
1385 to_space_.TearDown(); | 1385 to_space_.TearDown(); |
1386 from_space_.TearDown(); | 1386 from_space_.TearDown(); |
1387 } | 1387 } |
1388 | 1388 |
| 1389 |
1389 void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); } | 1390 void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); } |
1390 | 1391 |
1391 | 1392 |
1392 void NewSpace::Grow() { | 1393 void NewSpace::Grow() { |
1393 // Double the semispace size but only up to maximum capacity. | 1394 // Double the semispace size but only up to maximum capacity. |
1394 DCHECK(TotalCapacity() < MaximumCapacity()); | 1395 DCHECK(TotalCapacity() < MaximumCapacity()); |
1395 int new_capacity = | 1396 int new_capacity = |
1396 Min(MaximumCapacity(), | 1397 Min(MaximumCapacity(), |
1397 FLAG_semi_space_growth_factor * static_cast<int>(TotalCapacity())); | 1398 FLAG_semi_space_growth_factor * static_cast<int>(TotalCapacity())); |
1398 if (to_space_.GrowTo(new_capacity)) { | 1399 if (to_space_.GrowTo(new_capacity)) { |
(...skipping 25 matching lines...) Expand all Loading... |
1424 if (!to_space_.GrowTo(from_space_.current_capacity())) { | 1425 if (!to_space_.GrowTo(from_space_.current_capacity())) { |
1425 // We are in an inconsistent state because we could not | 1426 // We are in an inconsistent state because we could not |
1426 // commit/uncommit memory from new space. | 1427 // commit/uncommit memory from new space. |
1427 CHECK(false); | 1428 CHECK(false); |
1428 } | 1429 } |
1429 } | 1430 } |
1430 } | 1431 } |
1431 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1432 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
1432 } | 1433 } |
1433 | 1434 |
1434 bool NewSpace::Rebalance() { | |
1435 CHECK(heap()->promotion_queue()->is_empty()); | |
1436 // Order here is important to make use of the page pool. | |
1437 return to_space_.EnsureCurrentCapacity() && | |
1438 from_space_.EnsureCurrentCapacity(); | |
1439 } | |
1440 | |
1441 bool SemiSpace::EnsureCurrentCapacity() { | |
1442 if (is_committed()) { | |
1443 const int expected_pages = current_capacity_ / Page::kPageSize; | |
1444 int actual_pages = 0; | |
1445 Page* current_page = anchor()->next_page(); | |
1446 while (current_page != anchor()) { | |
1447 actual_pages++; | |
1448 current_page = current_page->next_page(); | |
1449 if (actual_pages > expected_pages) { | |
1450 Page* to_remove = current_page->prev_page(); | |
1451 // Make sure we don't overtake the actual top pointer. | |
1452 DCHECK_NE(to_remove, current_page_); | |
1453 to_remove->Unlink(); | |
1454 heap()->memory_allocator()->Free<MemoryAllocator::kPooledAndQueue>( | |
1455 to_remove); | |
1456 } | |
1457 } | |
1458 while (actual_pages < expected_pages) { | |
1459 actual_pages++; | |
1460 current_page = | |
1461 heap()->memory_allocator()->AllocatePage<MemoryAllocator::kPooled>( | |
1462 Page::kAllocatableMemory, this, executable()); | |
1463 if (current_page == nullptr) return false; | |
1464 DCHECK_NOT_NULL(current_page); | |
1465 current_page->InsertAfter(anchor()); | |
1466 Bitmap::Clear(current_page); | |
1467 current_page->SetFlags(anchor()->prev_page()->GetFlags(), | |
1468 Page::kCopyAllFlags); | |
1469 heap()->CreateFillerObjectAt(current_page->area_start(), | |
1470 current_page->area_size(), | |
1471 ClearRecordedSlots::kNo); | |
1472 } | |
1473 } | |
1474 return true; | |
1475 } | |
1476 | 1435 |
1477 void LocalAllocationBuffer::Close() { | 1436 void LocalAllocationBuffer::Close() { |
1478 if (IsValid()) { | 1437 if (IsValid()) { |
1479 heap_->CreateFillerObjectAt( | 1438 heap_->CreateFillerObjectAt( |
1480 allocation_info_.top(), | 1439 allocation_info_.top(), |
1481 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), | 1440 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), |
1482 ClearRecordedSlots::kNo); | 1441 ClearRecordedSlots::kNo); |
1483 } | 1442 } |
1484 } | 1443 } |
1485 | 1444 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); | 1867 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); |
1909 } | 1868 } |
1910 } | 1869 } |
1911 | 1870 |
1912 | 1871 |
1913 void SemiSpace::Reset() { | 1872 void SemiSpace::Reset() { |
1914 DCHECK_NE(anchor_.next_page(), &anchor_); | 1873 DCHECK_NE(anchor_.next_page(), &anchor_); |
1915 current_page_ = anchor_.next_page(); | 1874 current_page_ = anchor_.next_page(); |
1916 } | 1875 } |
1917 | 1876 |
1918 void SemiSpace::RemovePage(Page* page) { | 1877 bool SemiSpace::ReplaceWithEmptyPage(Page* old_page) { |
1919 if (current_page_ == page) { | 1878 // TODO(mlippautz): We do not have to get a new page here when the semispace |
1920 current_page_ = page->prev_page(); | 1879 // is uncommitted later on. |
1921 } | 1880 Page* new_page = heap()->memory_allocator()->AllocatePage( |
1922 page->Unlink(); | 1881 Page::kAllocatableMemory, this, executable()); |
1923 } | 1882 if (new_page == nullptr) return false; |
1924 | 1883 Bitmap::Clear(new_page); |
1925 void SemiSpace::PrependPage(Page* page) { | 1884 new_page->SetFlags(old_page->GetFlags(), Page::kCopyAllFlags); |
1926 page->SetFlags(current_page()->GetFlags(), Page::kCopyAllFlags); | 1885 new_page->set_next_page(old_page->next_page()); |
1927 page->set_owner(this); | 1886 new_page->set_prev_page(old_page->prev_page()); |
1928 page->InsertAfter(anchor()); | 1887 old_page->next_page()->set_prev_page(new_page); |
| 1888 old_page->prev_page()->set_next_page(new_page); |
| 1889 heap()->CreateFillerObjectAt(new_page->area_start(), new_page->area_size(), |
| 1890 ClearRecordedSlots::kNo); |
| 1891 return true; |
1929 } | 1892 } |
1930 | 1893 |
1931 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { | 1894 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { |
1932 // We won't be swapping semispaces without data in them. | 1895 // We won't be swapping semispaces without data in them. |
1933 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); | 1896 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); |
1934 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); | 1897 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); |
1935 | 1898 |
1936 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); | 1899 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); |
1937 | 1900 |
1938 // We swap all properties but id_. | 1901 // We swap all properties but id_. |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3257 object->ShortPrint(); | 3220 object->ShortPrint(); |
3258 PrintF("\n"); | 3221 PrintF("\n"); |
3259 } | 3222 } |
3260 printf(" --------------------------------------\n"); | 3223 printf(" --------------------------------------\n"); |
3261 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3224 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3262 } | 3225 } |
3263 | 3226 |
3264 #endif // DEBUG | 3227 #endif // DEBUG |
3265 } // namespace internal | 3228 } // namespace internal |
3266 } // namespace v8 | 3229 } // namespace v8 |
OLD | NEW |