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 // 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 } |
1435 | 1476 |
1436 void LocalAllocationBuffer::Close() { | 1477 void LocalAllocationBuffer::Close() { |
1437 if (IsValid()) { | 1478 if (IsValid()) { |
1438 heap_->CreateFillerObjectAt( | 1479 heap_->CreateFillerObjectAt( |
1439 allocation_info_.top(), | 1480 allocation_info_.top(), |
1440 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), | 1481 static_cast<int>(allocation_info_.limit() - allocation_info_.top()), |
1441 ClearRecordedSlots::kNo); | 1482 ClearRecordedSlots::kNo); |
1442 } | 1483 } |
1443 } | 1484 } |
1444 | 1485 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); | 1908 page->IsFlagSet(MemoryChunk::IN_FROM_SPACE)); |
1868 } | 1909 } |
1869 } | 1910 } |
1870 | 1911 |
1871 | 1912 |
1872 void SemiSpace::Reset() { | 1913 void SemiSpace::Reset() { |
1873 DCHECK_NE(anchor_.next_page(), &anchor_); | 1914 DCHECK_NE(anchor_.next_page(), &anchor_); |
1874 current_page_ = anchor_.next_page(); | 1915 current_page_ = anchor_.next_page(); |
1875 } | 1916 } |
1876 | 1917 |
1877 bool SemiSpace::ReplaceWithEmptyPage(Page* old_page) { | 1918 void SemiSpace::RemovePage(Page* page) { |
1878 // TODO(mlippautz): We do not have to get a new page here when the semispace | 1919 if (current_page_ == page) { |
1879 // is uncommitted later on. | 1920 current_page_ = page->prev_page(); |
1880 Page* new_page = heap()->memory_allocator()->AllocatePage( | 1921 } |
1881 Page::kAllocatableMemory, this, executable()); | 1922 page->Unlink(); |
1882 if (new_page == nullptr) return false; | 1923 } |
1883 Bitmap::Clear(new_page); | 1924 |
1884 new_page->SetFlags(old_page->GetFlags(), Page::kCopyAllFlags); | 1925 void SemiSpace::PrependPage(Page* page) { |
1885 new_page->set_next_page(old_page->next_page()); | 1926 page->SetFlags(current_page()->GetFlags(), Page::kCopyAllFlags); |
1886 new_page->set_prev_page(old_page->prev_page()); | 1927 page->set_owner(this); |
1887 old_page->next_page()->set_prev_page(new_page); | 1928 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 } | 1929 } |
1893 | 1930 |
1894 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { | 1931 void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) { |
1895 // We won't be swapping semispaces without data in them. | 1932 // We won't be swapping semispaces without data in them. |
1896 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); | 1933 DCHECK_NE(from->anchor_.next_page(), &from->anchor_); |
1897 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); | 1934 DCHECK_NE(to->anchor_.next_page(), &to->anchor_); |
1898 | 1935 |
1899 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); | 1936 intptr_t saved_to_space_flags = to->current_page()->GetFlags(); |
1900 | 1937 |
1901 // We swap all properties but id_. | 1938 // We swap all properties but id_. |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3220 object->ShortPrint(); | 3257 object->ShortPrint(); |
3221 PrintF("\n"); | 3258 PrintF("\n"); |
3222 } | 3259 } |
3223 printf(" --------------------------------------\n"); | 3260 printf(" --------------------------------------\n"); |
3224 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3261 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3225 } | 3262 } |
3226 | 3263 |
3227 #endif // DEBUG | 3264 #endif // DEBUG |
3228 } // namespace internal | 3265 } // namespace internal |
3229 } // namespace v8 | 3266 } // namespace v8 |
OLD | NEW |