| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Initialize(space, | 67 Initialize(space, |
| 68 NULL, | 68 NULL, |
| 69 NULL, | 69 NULL, |
| 70 kAllPagesInSpace, | 70 kAllPagesInSpace, |
| 71 size_func); | 71 size_func); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 HeapObjectIterator::HeapObjectIterator(Page* page, | 75 HeapObjectIterator::HeapObjectIterator(Page* page, |
| 76 HeapObjectCallback size_func) { | 76 HeapObjectCallback size_func) { |
| 77 Initialize(page->owner(), | 77 Space* owner = page->owner(); |
| 78 ASSERT(owner == Heap::old_pointer_space() || |
| 79 owner == Heap::old_data_space() || |
| 80 owner == Heap::map_space() || |
| 81 owner == Heap::cell_space() || |
| 82 owner == Heap::code_space()); |
| 83 Initialize(reinterpret_cast<PagedSpace*>(owner), |
| 78 page->ObjectAreaStart(), | 84 page->ObjectAreaStart(), |
| 79 page->ObjectAreaEnd(), | 85 page->ObjectAreaEnd(), |
| 80 kOnePageOnly, | 86 kOnePageOnly, |
| 81 size_func); | 87 size_func); |
| 82 ASSERT(!page->IsFlagSet(Page::WAS_SWEPT_CONSERVATIVELY)); | 88 ASSERT(!page->IsFlagSet(Page::WAS_SWEPT_CONSERVATIVELY)); |
| 83 } | 89 } |
| 84 | 90 |
| 85 | 91 |
| 86 void HeapObjectIterator::Initialize(PagedSpace* space, | 92 void HeapObjectIterator::Initialize(PagedSpace* space, |
| 87 Address cur, Address end, | 93 Address cur, Address end, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 VirtualMemory::ReleaseRegion(base, *allocated_size); | 387 VirtualMemory::ReleaseRegion(base, *allocated_size); |
| 382 size_ -= *allocated_size; | 388 size_ -= *allocated_size; |
| 383 return NULL; | 389 return NULL; |
| 384 } | 390 } |
| 385 | 391 |
| 386 return base; | 392 return base; |
| 387 } | 393 } |
| 388 | 394 |
| 389 | 395 |
| 390 void Page::InitializeAsAnchor(PagedSpace* owner) { | 396 void Page::InitializeAsAnchor(PagedSpace* owner) { |
| 391 owner_ = owner; | 397 set_owner(owner); |
| 392 set_prev_page(this); | 398 set_prev_page(this); |
| 393 set_next_page(this); | 399 set_next_page(this); |
| 394 } | 400 } |
| 395 | 401 |
| 396 | 402 |
| 397 MemoryChunk* MemoryChunk::Initialize(Address base, | 403 MemoryChunk* MemoryChunk::Initialize(Address base, |
| 398 size_t size, | 404 size_t size, |
| 399 Executability executable, | 405 Executability executable, |
| 400 Space* owner) { | 406 Space* owner) { |
| 401 MemoryChunk* chunk = FromAddress(base); | 407 MemoryChunk* chunk = FromAddress(base); |
| 402 | 408 |
| 403 ASSERT(base == chunk->address()); | 409 ASSERT(base == chunk->address()); |
| 404 | 410 |
| 405 chunk->size_ = size; | 411 chunk->size_ = size; |
| 406 chunk->flags_ = 0; | 412 chunk->flags_ = 0; |
| 407 chunk->owner_ = owner; | 413 chunk->set_owner(owner); |
| 408 chunk->markbits()->Clear(); | 414 chunk->markbits()->Clear(); |
| 415 chunk->set_scan_on_scavenge(false); |
| 409 | 416 |
| 410 if (executable == EXECUTABLE) chunk->SetFlag(IS_EXECUTABLE); | 417 if (executable == EXECUTABLE) chunk->SetFlag(IS_EXECUTABLE); |
| 411 | 418 |
| 412 if (owner == Heap::old_data_space()) chunk->SetFlag(CONTAINS_ONLY_DATA); | 419 if (owner == Heap::old_data_space()) chunk->SetFlag(CONTAINS_ONLY_DATA); |
| 413 | 420 |
| 414 return chunk; | 421 return chunk; |
| 415 } | 422 } |
| 416 | 423 |
| 417 | 424 |
| 418 void MemoryChunk::InsertAfter(MemoryChunk* other) { | 425 void MemoryChunk::InsertAfter(MemoryChunk* other) { |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 void OldSpaceFreeList::Reset() { | 1425 void OldSpaceFreeList::Reset() { |
| 1419 available_ = 0; | 1426 available_ = 0; |
| 1420 small_list_ = NULL; | 1427 small_list_ = NULL; |
| 1421 medium_list_ = NULL; | 1428 medium_list_ = NULL; |
| 1422 large_list_ = NULL; | 1429 large_list_ = NULL; |
| 1423 huge_list_ = NULL; | 1430 huge_list_ = NULL; |
| 1424 } | 1431 } |
| 1425 | 1432 |
| 1426 | 1433 |
| 1427 int OldSpaceFreeList::Free(Address start, int size_in_bytes) { | 1434 int OldSpaceFreeList::Free(Address start, int size_in_bytes) { |
| 1428 #ifdef DEBUG | |
| 1429 MemoryAllocator::ZapBlock(start, size_in_bytes); | |
| 1430 #endif | |
| 1431 if (size_in_bytes == 0) return 0; | 1435 if (size_in_bytes == 0) return 0; |
| 1432 FreeListNode* node = FreeListNode::FromAddress(start); | 1436 FreeListNode* node = FreeListNode::FromAddress(start); |
| 1433 node->set_size(size_in_bytes); | 1437 node->set_size(size_in_bytes); |
| 1434 | 1438 |
| 1435 // Early return to drop too-small blocks on the floor. | 1439 // Early return to drop too-small blocks on the floor. |
| 1436 if (size_in_bytes < kSmallListMin) return size_in_bytes; | 1440 if (size_in_bytes < kSmallListMin) return size_in_bytes; |
| 1437 | 1441 |
| 1438 // Insert other blocks at the head of a free list of the appropriate | 1442 // Insert other blocks at the head of a free list of the appropriate |
| 1439 // magnitude. | 1443 // magnitude. |
| 1440 if (size_in_bytes <= kSmallListMax) { | 1444 if (size_in_bytes <= kSmallListMax) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 // space than the minimum NewSpace size. | 1584 // space than the minimum NewSpace size. |
| 1581 ASSERT(bytes <= InitialCapacity()); | 1585 ASSERT(bytes <= InitialCapacity()); |
| 1582 Address limit = allocation_info_.limit; | 1586 Address limit = allocation_info_.limit; |
| 1583 Address top = allocation_info_.top; | 1587 Address top = allocation_info_.top; |
| 1584 return limit - top >= bytes; | 1588 return limit - top >= bytes; |
| 1585 } | 1589 } |
| 1586 | 1590 |
| 1587 | 1591 |
| 1588 void PagedSpace::PrepareForMarkCompact(bool will_compact) { | 1592 void PagedSpace::PrepareForMarkCompact(bool will_compact) { |
| 1589 ASSERT(!will_compact); | 1593 ASSERT(!will_compact); |
| 1594 // We don't have a linear allocation area while sweeping. It will be restored |
| 1595 // on the first allocation after the sweep. |
| 1596 // Mark the old linear allocation area with a free space map so it can be |
| 1597 // skipped when scanning the heap. |
| 1598 int old_linear_size = limit() - top(); |
| 1599 Free(top(), old_linear_size); |
| 1600 SetTop(NULL, NULL); |
| 1590 } | 1601 } |
| 1591 | 1602 |
| 1592 | 1603 |
| 1593 bool PagedSpace::ReserveSpace(int size_in_bytes) { | 1604 bool PagedSpace::ReserveSpace(int size_in_bytes) { |
| 1594 ASSERT(size_in_bytes <= Page::kMaxHeapObjectSize); | 1605 ASSERT(size_in_bytes <= Page::kMaxHeapObjectSize); |
| 1595 ASSERT(size_in_bytes == RoundUp(size_in_bytes, kPointerSize)); | 1606 ASSERT(size_in_bytes == RoundUp(size_in_bytes, kPointerSize)); |
| 1596 Address current_top = allocation_info_.top; | 1607 Address current_top = allocation_info_.top; |
| 1597 Address new_top = current_top + size_in_bytes; | 1608 Address new_top = current_top + size_in_bytes; |
| 1598 if (new_top <= allocation_info_.limit) return true; | 1609 if (new_top <= allocation_info_.limit) return true; |
| 1599 | 1610 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 } | 1784 } |
| 1774 | 1785 |
| 1775 | 1786 |
| 1776 void PagedSpace::ReportStatistics() { | 1787 void PagedSpace::ReportStatistics() { |
| 1777 int pct = static_cast<int>(Available() * 100 / Capacity()); | 1788 int pct = static_cast<int>(Available() * 100 / Capacity()); |
| 1778 PrintF(" capacity: %" V8_PTR_PREFIX "d" | 1789 PrintF(" capacity: %" V8_PTR_PREFIX "d" |
| 1779 ", waste: %" V8_PTR_PREFIX "d" | 1790 ", waste: %" V8_PTR_PREFIX "d" |
| 1780 ", available: %" V8_PTR_PREFIX "d, %%%d\n", | 1791 ", available: %" V8_PTR_PREFIX "d, %%%d\n", |
| 1781 Capacity(), Waste(), Available(), pct); | 1792 Capacity(), Waste(), Available(), pct); |
| 1782 | 1793 |
| 1794 if (was_swept_conservatively_) return; |
| 1783 ClearHistograms(); | 1795 ClearHistograms(); |
| 1784 HeapObjectIterator obj_it(this); | 1796 HeapObjectIterator obj_it(this); |
| 1785 for (HeapObject* obj = obj_it.Next(); obj != NULL; obj = obj_it.Next()) | 1797 for (HeapObject* obj = obj_it.Next(); obj != NULL; obj = obj_it.Next()) |
| 1786 CollectHistogramInfo(obj); | 1798 CollectHistogramInfo(obj); |
| 1787 ReportHistogram(true); | 1799 ReportHistogram(true); |
| 1788 } | 1800 } |
| 1789 #endif | 1801 #endif |
| 1790 | 1802 |
| 1791 // ----------------------------------------------------------------------------- | 1803 // ----------------------------------------------------------------------------- |
| 1792 // FixedSpace implementation | 1804 // FixedSpace implementation |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 2151 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
| 2140 if (obj->IsCode()) { | 2152 if (obj->IsCode()) { |
| 2141 Code* code = Code::cast(obj); | 2153 Code* code = Code::cast(obj); |
| 2142 code_kind_statistics[code->kind()] += code->Size(); | 2154 code_kind_statistics[code->kind()] += code->Size(); |
| 2143 } | 2155 } |
| 2144 } | 2156 } |
| 2145 } | 2157 } |
| 2146 #endif // DEBUG | 2158 #endif // DEBUG |
| 2147 | 2159 |
| 2148 } } // namespace v8::internal | 2160 } } // namespace v8::internal |
| OLD | NEW |