| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 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 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 accounting_stats_.AllocateBytes(size_in_bytes); | 1766 accounting_stats_.AllocateBytes(size_in_bytes); |
| 1767 | 1767 |
| 1768 HeapObject* obj = HeapObject::cast(result); | 1768 HeapObject* obj = HeapObject::cast(result); |
| 1769 Page* p = Page::FromAddress(obj->address()); | 1769 Page* p = Page::FromAddress(obj->address()); |
| 1770 | 1770 |
| 1771 if (obj->address() >= p->AllocationWatermark()) { | 1771 if (obj->address() >= p->AllocationWatermark()) { |
| 1772 // There should be no hole between the allocation watermark | 1772 // There should be no hole between the allocation watermark |
| 1773 // and allocated object address. | 1773 // and allocated object address. |
| 1774 // Memory above the allocation watermark was not swept and | 1774 // Memory above the allocation watermark was not swept and |
| 1775 // might contain garbage pointers to new space. | 1775 // might contain garbage pointers to new space. |
| 1776 ASSERT(obj->address() == p->AllocationWatermark()); | 1776 if (obj->address() != p->AllocationWatermark()) { |
| 1777 // TODO(gc) this is waste of time. we should enable linear allocation |
| 1778 // at least from above watermark |
| 1779 HeapObject* filler = |
| 1780 HeapObject::FromAddress(p->AllocationWatermark()); |
| 1781 while (filler->address() < obj->address()) { |
| 1782 Address next_filler = filler->address() + filler->Size(); |
| 1783 if (filler->Size() > ByteArray::kHeaderSize) { |
| 1784 for (Address slot = filler->address() + ByteArray::kHeaderSize; |
| 1785 slot < next_filler; |
| 1786 slot += kPointerSize) { |
| 1787 Memory::Address_at(slot) = 0; |
| 1788 } |
| 1789 } |
| 1790 filler = HeapObject::FromAddress(next_filler); |
| 1791 } |
| 1792 } |
| 1777 p->SetAllocationWatermark(obj->address() + size_in_bytes); | 1793 p->SetAllocationWatermark(obj->address() + size_in_bytes); |
| 1778 } | 1794 } |
| 1779 | 1795 |
| 1780 return obj; | 1796 return obj; |
| 1781 } | 1797 } |
| 1782 } | 1798 } |
| 1783 | 1799 |
| 1784 // Free list allocation failed and there is no next page. Fail if we have | 1800 // Free list allocation failed and there is no next page. Fail if we have |
| 1785 // hit the old generation size limit that should cause a garbage | 1801 // hit the old generation size limit that should cause a garbage |
| 1786 // collection. | 1802 // collection. |
| 1787 if (!Heap::always_allocate() && Heap::OldGenerationAllocationLimitReached()) { | 1803 if (!Heap::always_allocate() && Heap::OldGenerationAllocationLimitReached()) { |
| 1788 return NULL; | 1804 return NULL; |
| 1789 } | 1805 } |
| 1790 | 1806 |
| 1791 // Try to expand the space and allocate in the new next page. | 1807 // Try to expand the space and allocate in the new next page. |
| 1792 ASSERT(!current_page->next_page()->is_valid()); | 1808 ASSERT(!current_page->next_page()->is_valid()); |
| 1793 if (Expand()) { | 1809 if (Expand()) { |
| 1794 return AllocateInNextPage(current_page, size_in_bytes); | 1810 return AllocateInNextPage(current_page, size_in_bytes); |
| 1795 } | 1811 } |
| 1796 | 1812 |
| 1797 // Finally, fail. | 1813 // Finally, fail. |
| 1798 return NULL; | 1814 return NULL; |
| 1799 } | 1815 } |
| 1800 | 1816 |
| 1801 | 1817 |
| 1802 void OldSpace::PutRestOfCurrentPageOnFreeList(Page* current_page) { | 1818 void OldSpace::PutRestOfCurrentPageOnFreeList(Page* current_page) { |
| 1803 current_page->SetAllocationWatermark(allocation_info_.top); | 1819 current_page->SetAllocationWatermark(allocation_info_.top); |
| 1804 int free_size = | 1820 int free_size = |
| 1805 static_cast<int>(current_page->ObjectAreaEnd() - allocation_info_.top); | 1821 static_cast<int>(current_page->ObjectAreaEnd() - allocation_info_.top); |
| 1806 if (free_size > 0) { | 1822 if (free_size > 0) AddToFreeList(allocation_info_.top, free_size); |
| 1807 int wasted_bytes = free_list_.Free(allocation_info_.top, free_size); | |
| 1808 accounting_stats_.WasteBytes(wasted_bytes); | |
| 1809 } | |
| 1810 } | 1823 } |
| 1811 | 1824 |
| 1812 | 1825 |
| 1813 void FixedSpace::PutRestOfCurrentPageOnFreeList(Page* current_page) { | 1826 void FixedSpace::PutRestOfCurrentPageOnFreeList(Page* current_page) { |
| 1814 current_page->SetAllocationWatermark(allocation_info_.top); | 1827 current_page->SetAllocationWatermark(allocation_info_.top); |
| 1815 int free_size = | 1828 int free_size = |
| 1816 static_cast<int>(current_page->ObjectAreaEnd() - allocation_info_.top); | 1829 static_cast<int>(current_page->ObjectAreaEnd() - allocation_info_.top); |
| 1817 // In the fixed space free list all the free list items have the right size. | 1830 // In the fixed space free list all the free list items have the right size. |
| 1818 // We use up the rest of the page while preserving this invariant. | 1831 // We use up the rest of the page while preserving this invariant. |
| 1819 while (free_size >= object_size_in_bytes_) { | 1832 while (free_size >= object_size_in_bytes_) { |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2460 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 2473 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
| 2461 if (obj->IsCode()) { | 2474 if (obj->IsCode()) { |
| 2462 Code* code = Code::cast(obj); | 2475 Code* code = Code::cast(obj); |
| 2463 code_kind_statistics[code->kind()] += code->Size(); | 2476 code_kind_statistics[code->kind()] += code->Size(); |
| 2464 } | 2477 } |
| 2465 } | 2478 } |
| 2466 } | 2479 } |
| 2467 #endif // DEBUG | 2480 #endif // DEBUG |
| 2468 | 2481 |
| 2469 } } // namespace v8::internal | 2482 } } // namespace v8::internal |
| OLD | NEW |