Chromium Code Reviews| 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 | |
| 1390 void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); } | 1389 void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); } |
| 1391 | 1390 |
| 1392 | 1391 |
| 1393 void NewSpace::Grow() { | 1392 void NewSpace::Grow() { |
| 1394 // Double the semispace size but only up to maximum capacity. | 1393 // Double the semispace size but only up to maximum capacity. |
| 1395 DCHECK(TotalCapacity() < MaximumCapacity()); | 1394 DCHECK(TotalCapacity() < MaximumCapacity()); |
| 1396 int new_capacity = | 1395 int new_capacity = |
| 1397 Min(MaximumCapacity(), | 1396 Min(MaximumCapacity(), |
| 1398 FLAG_semi_space_growth_factor * static_cast<int>(TotalCapacity())); | 1397 FLAG_semi_space_growth_factor * static_cast<int>(TotalCapacity())); |
| 1399 if (to_space_.GrowTo(new_capacity)) { | 1398 if (to_space_.GrowTo(new_capacity)) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1425 if (!to_space_.GrowTo(from_space_.current_capacity())) { | 1424 if (!to_space_.GrowTo(from_space_.current_capacity())) { |
| 1426 // We are in an inconsistent state because we could not | 1425 // We are in an inconsistent state because we could not |
| 1427 // commit/uncommit memory from new space. | 1426 // commit/uncommit memory from new space. |
| 1428 CHECK(false); | 1427 CHECK(false); |
| 1429 } | 1428 } |
| 1430 } | 1429 } |
| 1431 } | 1430 } |
| 1432 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1431 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
| 1433 } | 1432 } |
| 1434 | 1433 |
| 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 to_remove->Unlink(); | |
|
ulan
2016/06/14 15:38:51
Please add dcheck that we discussed offline.
Michael Lippautz
2016/06/15 06:49:30
Done.
| |
| 1452 heap()->memory_allocator()->Free<MemoryAllocator::kPooledAndQueue>( | |
| 1453 to_remove); | |
| 1454 } | |
| 1455 } | |
| 1456 while (actual_pages < expected_pages) { | |
| 1457 actual_pages++; | |
| 1458 current_page = | |
| 1459 heap()->memory_allocator()->AllocatePage<MemoryAllocator::kPooled>( | |
| 1460 Page::kAllocatableMemory, this, executable()); | |
| 1461 if (current_page == nullptr) return false; | |
| 1462 DCHECK_NOT_NULL(current_page); | |
| 1463 current_page->InsertAfter(anchor()); | |
| 1464 Bitmap::Clear(current_page); | |
| 1465 current_page->SetFlags(anchor()->prev_page()->GetFlags(), | |
| 1466 Page::kCopyAllFlags); | |
| 1467 heap()->CreateFillerObjectAt(current_page->area_start(), | |
| 1468 current_page->area_size(), | |
| 1469 ClearRecordedSlots::kNo); | |
| 1470 } | |
| 1471 } | |
| 1472 return true; | |
| 1473 } | |
| 1435 | 1474 |
| 1436 void LocalAllocationBuffer::Close() { | 1475 void LocalAllocationBuffer::Close() { |
| 1437 if (IsValid()) { | 1476 if (IsValid()) { |
| 1438 heap_->CreateFillerObjectAt( | 1477 heap_->CreateFillerObjectAt( |
| 1439 allocation_info_.top(), | 1478 allocation_info_.top(), |
| 1440 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), | 1479 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), |
| 1441 ClearRecordedSlots::kNo); | 1480 ClearRecordedSlots::kNo); |
| 1442 } | 1481 } |
| 1443 } | 1482 } |
| 1444 | 1483 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1867 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); | 1906 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); |
| 1868 } | 1907 } |
| 1869 } | 1908 } |
| 1870 | 1909 |
| 1871 | 1910 |
| 1872 void SemiSpace::Reset() { | 1911 void SemiSpace::Reset() { |
| 1873 DCHECK_NE(anchor_.next_page(), &anchor_); | 1912 DCHECK_NE(anchor_.next_page(), &anchor_); |
| 1874 current_page_ = anchor_.next_page(); | 1913 current_page_ = anchor_.next_page(); |
| 1875 } | 1914 } |
| 1876 | 1915 |
| 1877 bool SemiSpace::ReplaceWithEmptyPage(Page* old_page) { | 1916 void SemiSpace::RemovePage(Page* page) { |
| 1878 // TODO(mlippautz): We do not have to get a new page here when the semispace | 1917 if (current_page_ == page) { |
| 1879 // is uncommitted later on. | 1918 current_page_ = page->prev_page(); |
| 1880 Page* new_page = heap()->memory_allocator()->AllocatePage( | 1919 } |
| 1881 Page::kAllocatableMemory, this, executable()); | 1920 page->Unlink(); |
| 1882 if (new_page == nullptr) return false; | 1921 } |
| 1883 Bitmap::Clear(new_page); | 1922 |
| 1884 new_page->SetFlags(old_page->GetFlags(), Page::kCopyAllFlags); | 1923 void SemiSpace::PrependPage(Page* page) { |
| 1885 new_page->set_next_page(old_page->next_page()); | 1924 page->SetFlags(current_page()->GetFlags(), Page::kCopyAllFlags); |
| 1886 new_page->set_prev_page(old_page->prev_page()); | 1925 page->set_owner(this); |
| 1887 old_page->next_page()->set_prev_page(new_page); | 1926 page->InsertAfter(anchor()); |
| 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; | |
| 1892 } | 1927 } |
| 1893 | 1928 |
| 1894 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { | 1929 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { |
| 1895 // We won't be swapping semispaces without data in them. | 1930 // We won't be swapping semispaces without data in them. |
| 1896 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); | 1931 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); |
| 1897 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); | 1932 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); |
| 1898 | 1933 |
| 1899 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); | 1934 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); |
| 1900 | 1935 |
| 1901 // We swap all properties but id_. | 1936 // We swap all properties but id_. |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3220 object->ShortPrint(); | 3255 object->ShortPrint(); |
| 3221 PrintF("\n"); | 3256 PrintF("\n"); |
| 3222 } | 3257 } |
| 3223 printf(" --------------------------------------\n"); | 3258 printf(" --------------------------------------\n"); |
| 3224 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3259 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3225 } | 3260 } |
| 3226 | 3261 |
| 3227 #endif // DEBUG | 3262 #endif // DEBUG |
| 3228 } // namespace internal | 3263 } // namespace internal |
| 3229 } // namespace v8 | 3264 } // namespace v8 |
| OLD | NEW |