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 // 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 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1519 | 1519 |
| 1520 // Clear the free list. | 1520 // Clear the free list. |
| 1521 void Reset(); | 1521 void Reset(); |
| 1522 | 1522 |
| 1523 // Return the number of bytes available on the free list. | 1523 // Return the number of bytes available on the free list. |
| 1524 intptr_t available() { | 1524 intptr_t available() { |
| 1525 return small_list_.available() + medium_list_.available() + | 1525 return small_list_.available() + medium_list_.available() + |
| 1526 large_list_.available() + huge_list_.available(); | 1526 large_list_.available() + huge_list_.available(); |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 enum AllocationStrategy { | |
| 1530 BEST_FIT, | |
| 1531 WORST_FIT | |
| 1532 }; | |
| 1533 | |
| 1529 // Place a node on the free list. The block of size 'size_in_bytes' | 1534 // Place a node on the free list. The block of size 'size_in_bytes' |
| 1530 // starting at 'start' is placed on the free list. The return value is the | 1535 // starting at 'start' is placed on the free list. The return value is the |
| 1531 // number of bytes that have been lost due to internal fragmentation by | 1536 // number of bytes that have been lost due to internal fragmentation by |
| 1532 // freeing the block. Bookkeeping information will be written to the block, | 1537 // freeing the block. Bookkeeping information will be written to the block, |
| 1533 // i.e., its contents will be destroyed. The start address should be word | 1538 // i.e., its contents will be destroyed. The start address should be word |
| 1534 // aligned, and the size should be a non-zero multiple of the word size. | 1539 // aligned, and the size should be a non-zero multiple of the word size. |
| 1535 int Free(Address start, int size_in_bytes); | 1540 int Free(Address start, int size_in_bytes); |
| 1536 | 1541 |
| 1537 // Allocate a block of size 'size_in_bytes' from the free list. The block | 1542 // Allocate a block of size 'size_in_bytes' from the free list. The block |
| 1538 // is unitialized. A failure is returned if no block is available. The | 1543 // is unitialized. A failure is returned if no block is available. The |
| 1539 // number of bytes lost to fragmentation is returned in the output parameter | 1544 // number of bytes lost to fragmentation is returned in the output parameter |
| 1540 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. | 1545 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. |
| 1546 template<AllocationStrategy strategy> | |
| 1541 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); | 1547 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); |
| 1542 | 1548 |
| 1543 #ifdef DEBUG | 1549 #ifdef DEBUG |
| 1544 void Zap(); | 1550 void Zap(); |
| 1545 intptr_t SumFreeLists(); | 1551 intptr_t SumFreeLists(); |
| 1546 bool IsVeryLong(); | 1552 bool IsVeryLong(); |
| 1547 #endif | 1553 #endif |
| 1548 | 1554 |
| 1549 // Used after booting the VM. | 1555 // Used after booting the VM. |
| 1550 void RepairLists(Heap* heap); | 1556 void RepairLists(Heap* heap); |
| 1551 | 1557 |
| 1552 intptr_t EvictFreeListItems(Page* p); | 1558 intptr_t EvictFreeListItems(Page* p); |
| 1553 | 1559 |
| 1554 FreeListCategory* small_list() { return &small_list_; } | 1560 FreeListCategory* small_list() { return &small_list_; } |
| 1555 FreeListCategory* medium_list() { return &medium_list_; } | 1561 FreeListCategory* medium_list() { return &medium_list_; } |
| 1556 FreeListCategory* large_list() { return &large_list_; } | 1562 FreeListCategory* large_list() { return &large_list_; } |
| 1557 FreeListCategory* huge_list() { return &huge_list_; } | 1563 FreeListCategory* huge_list() { return &huge_list_; } |
| 1558 | 1564 |
| 1559 private: | 1565 private: |
| 1560 // The size range of blocks, in bytes. | 1566 // The size range of blocks, in bytes. |
| 1561 static const int kMinBlockSize = 3 * kPointerSize; | 1567 static const int kMinBlockSize = 3 * kPointerSize; |
| 1562 static const int kMaxBlockSize = Page::kMaxNonCodeHeapObjectSize; | 1568 static const int kMaxBlockSize = Page::kMaxNonCodeHeapObjectSize; |
| 1563 | 1569 |
| 1564 FreeListNode* FindNodeFor(int size_in_bytes, int* node_size); | 1570 FreeListNode* FindNodeInHugeList(int size_in_bytes, int* node_size); |
| 1571 | |
| 1572 // Finds a node in the free-list using the best-fit allocation strategy. | |
| 1573 FreeListNode* FindNodeForBestFit(int size_in_bytes, int* node_size); | |
| 1574 | |
| 1575 // Finds a node in the free-list using the worst-fit allocation strategy | |
| 1576 // and it ignores the smalles category. | |
|
Michael Starzinger
2013/04/16 13:29:27
nit: s/smalles/smallest/
Hannes Payer (out of office)
2013/04/16 13:41:04
Done.
| |
| 1577 FreeListNode* FindNodeForWorstFit(int size_in_bytes, int* node_size); | |
| 1565 | 1578 |
| 1566 PagedSpace* owner_; | 1579 PagedSpace* owner_; |
| 1567 Heap* heap_; | 1580 Heap* heap_; |
| 1568 | 1581 |
| 1569 static const int kSmallListMin = 0x20 * kPointerSize; | 1582 static const int kSmallListMin = 0x20 * kPointerSize; |
| 1570 static const int kSmallListMax = 0xff * kPointerSize; | 1583 static const int kSmallListMax = 0xff * kPointerSize; |
| 1571 static const int kMediumListMax = 0x7ff * kPointerSize; | 1584 static const int kMediumListMax = 0x7ff * kPointerSize; |
| 1572 static const int kLargeListMax = 0x3fff * kPointerSize; | 1585 static const int kLargeListMax = 0x3fff * kPointerSize; |
| 1573 static const int kSmallAllocationMax = kSmallListMin - kPointerSize; | 1586 static const int kSmallAllocationMax = kSmallListMin - kPointerSize; |
| 1574 static const int kMediumAllocationMax = kSmallListMax; | 1587 static const int kMediumAllocationMax = kSmallListMax; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1685 // Returns the allocation pointer in this space. | 1698 // Returns the allocation pointer in this space. |
| 1686 Address top() { return allocation_info_.top; } | 1699 Address top() { return allocation_info_.top; } |
| 1687 Address limit() { return allocation_info_.limit; } | 1700 Address limit() { return allocation_info_.limit; } |
| 1688 | 1701 |
| 1689 // The allocation top and limit addresses. | 1702 // The allocation top and limit addresses. |
| 1690 Address* allocation_top_address() { return &allocation_info_.top; } | 1703 Address* allocation_top_address() { return &allocation_info_.top; } |
| 1691 Address* allocation_limit_address() { return &allocation_info_.limit; } | 1704 Address* allocation_limit_address() { return &allocation_info_.limit; } |
| 1692 | 1705 |
| 1693 // Allocate the requested number of bytes in the space if possible, return a | 1706 // Allocate the requested number of bytes in the space if possible, return a |
| 1694 // failure object if not. | 1707 // failure object if not. |
| 1708 template<FreeList::AllocationStrategy strategy> | |
| 1695 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes); | 1709 MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes); |
| 1696 | 1710 |
| 1697 virtual bool ReserveSpace(int bytes); | 1711 virtual bool ReserveSpace(int bytes); |
| 1698 | 1712 |
| 1699 // Give a block of memory to the space's free list. It might be added to | 1713 // Give a block of memory to the space's free list. It might be added to |
| 1700 // the free list or accounted as waste. | 1714 // the free list or accounted as waste. |
| 1701 // If add_to_freelist is false then just accounting stats are updated and | 1715 // If add_to_freelist is false then just accounting stats are updated and |
| 1702 // no attempt to add area to free list is made. | 1716 // no attempt to add area to free list is made. |
| 1703 int Free(Address start, int size_in_bytes) { | 1717 int Free(Address start, int size_in_bytes) { |
| 1704 int wasted = free_list_.Free(start, size_in_bytes); | 1718 int wasted = free_list_.Free(start, size_in_bytes); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1862 // Expands the space by allocating a fixed number of pages. Returns false if | 1876 // Expands the space by allocating a fixed number of pages. Returns false if |
| 1863 // it cannot allocate requested number of pages from OS, or if the hard heap | 1877 // it cannot allocate requested number of pages from OS, or if the hard heap |
| 1864 // size limit has been hit. | 1878 // size limit has been hit. |
| 1865 bool Expand(); | 1879 bool Expand(); |
| 1866 | 1880 |
| 1867 // Generic fast case allocation function that tries linear allocation at the | 1881 // Generic fast case allocation function that tries linear allocation at the |
| 1868 // address denoted by top in allocation_info_. | 1882 // address denoted by top in allocation_info_. |
| 1869 inline HeapObject* AllocateLinearly(int size_in_bytes); | 1883 inline HeapObject* AllocateLinearly(int size_in_bytes); |
| 1870 | 1884 |
| 1871 // Slow path of AllocateRaw. This function is space-dependent. | 1885 // Slow path of AllocateRaw. This function is space-dependent. |
| 1872 MUST_USE_RESULT virtual HeapObject* SlowAllocateRaw(int size_in_bytes); | 1886 template<FreeList::AllocationStrategy strategy> |
| 1887 MUST_USE_RESULT HeapObject* SlowAllocateRaw(int size_in_bytes); | |
| 1873 | 1888 |
| 1874 friend class PageIterator; | 1889 friend class PageIterator; |
| 1875 friend class SweeperThread; | 1890 friend class SweeperThread; |
| 1876 }; | 1891 }; |
| 1877 | 1892 |
| 1878 | 1893 |
| 1879 class NumberAndSizeInfo BASE_EMBEDDED { | 1894 class NumberAndSizeInfo BASE_EMBEDDED { |
| 1880 public: | 1895 public: |
| 1881 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 1896 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
| 1882 | 1897 |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2845 } | 2860 } |
| 2846 // Must be small, since an iteration is used for lookup. | 2861 // Must be small, since an iteration is used for lookup. |
| 2847 static const int kMaxComments = 64; | 2862 static const int kMaxComments = 64; |
| 2848 }; | 2863 }; |
| 2849 #endif | 2864 #endif |
| 2850 | 2865 |
| 2851 | 2866 |
| 2852 } } // namespace v8::internal | 2867 } } // namespace v8::internal |
| 2853 | 2868 |
| 2854 #endif // V8_SPACES_H_ | 2869 #endif // V8_SPACES_H_ |
| OLD | NEW |