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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1714 static FreeListNode* FromAddress(Address address) { | 1714 static FreeListNode* FromAddress(Address address) { |
1715 return reinterpret_cast<FreeListNode*>(HeapObject::FromAddress(address)); | 1715 return reinterpret_cast<FreeListNode*>(HeapObject::FromAddress(address)); |
1716 } | 1716 } |
1717 | 1717 |
1718 static inline bool IsFreeListNode(HeapObject* object); | 1718 static inline bool IsFreeListNode(HeapObject* object); |
1719 | 1719 |
1720 // Set the size in bytes, which can be read with HeapObject::Size(). This | 1720 // Set the size in bytes, which can be read with HeapObject::Size(). This |
1721 // function also writes a map to the first word of the block so that it | 1721 // function also writes a map to the first word of the block so that it |
1722 // looks like a heap object to the garbage collector and heap iteration | 1722 // looks like a heap object to the garbage collector and heap iteration |
1723 // functions. | 1723 // functions. |
1724 void set_size(int size_in_bytes); | 1724 void set_size(Heap* heap, int size_in_bytes); |
1725 | 1725 |
1726 // Accessors for the next field. | 1726 // Accessors for the next field. |
1727 inline Address next(); | 1727 inline Address next(Heap* heap); |
1728 inline void set_next(Address next); | 1728 inline void set_next(Heap* heap, Address next); |
1729 | 1729 |
1730 private: | 1730 private: |
1731 static const int kNextOffset = POINTER_SIZE_ALIGN(ByteArray::kHeaderSize); | 1731 static const int kNextOffset = POINTER_SIZE_ALIGN(ByteArray::kHeaderSize); |
1732 | 1732 |
1733 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListNode); | 1733 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListNode); |
1734 }; | 1734 }; |
1735 | 1735 |
1736 | 1736 |
1737 // The free list for the old space. | 1737 // The free list for the old space. |
1738 class OldSpaceFreeList BASE_EMBEDDED { | 1738 class OldSpaceFreeList BASE_EMBEDDED { |
1739 public: | 1739 public: |
1740 explicit OldSpaceFreeList(AllocationSpace owner); | 1740 explicit OldSpaceFreeList(Heap* heap, AllocationSpace owner); |
Vitaly Repeshko
2011/03/22 13:53:29
"explicit" no longer required.
| |
1741 | 1741 |
1742 // Clear the free list. | 1742 // Clear the free list. |
1743 void Reset(); | 1743 void Reset(); |
1744 | 1744 |
1745 // Return the number of bytes available on the free list. | 1745 // Return the number of bytes available on the free list. |
1746 intptr_t available() { return available_; } | 1746 intptr_t available() { return available_; } |
1747 | 1747 |
1748 // Place a node on the free list. The block of size 'size_in_bytes' | 1748 // Place a node on the free list. The block of size 'size_in_bytes' |
1749 // starting at 'start' is placed on the free list. The return value is the | 1749 // starting at 'start' is placed on the free list. The return value is the |
1750 // number of bytes that have been lost due to internal fragmentation by | 1750 // number of bytes that have been lost due to internal fragmentation by |
1751 // freeing the block. Bookkeeping information will be written to the block, | 1751 // freeing the block. Bookkeeping information will be written to the block, |
1752 // ie, its contents will be destroyed. The start address should be word | 1752 // ie, its contents will be destroyed. The start address should be word |
1753 // aligned, and the size should be a non-zero multiple of the word size. | 1753 // aligned, and the size should be a non-zero multiple of the word size. |
1754 int Free(Address start, int size_in_bytes); | 1754 int Free(Address start, int size_in_bytes); |
1755 | 1755 |
1756 // Allocate a block of size 'size_in_bytes' from the free list. The block | 1756 // Allocate a block of size 'size_in_bytes' from the free list. The block |
1757 // is unitialized. A failure is returned if no block is available. The | 1757 // is unitialized. A failure is returned if no block is available. The |
1758 // number of bytes lost to fragmentation is returned in the output parameter | 1758 // number of bytes lost to fragmentation is returned in the output parameter |
1759 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. | 1759 // 'wasted_bytes'. The size should be a non-zero multiple of the word size. |
1760 MUST_USE_RESULT MaybeObject* Allocate(int size_in_bytes, int* wasted_bytes); | 1760 MUST_USE_RESULT MaybeObject* Allocate(int size_in_bytes, int* wasted_bytes); |
1761 | 1761 |
1762 void MarkNodes(); | 1762 void MarkNodes(); |
1763 | 1763 |
1764 private: | 1764 private: |
1765 // The size range of blocks, in bytes. (Smaller allocations are allowed, but | 1765 // The size range of blocks, in bytes. (Smaller allocations are allowed, but |
1766 // will always result in waste.) | 1766 // will always result in waste.) |
1767 static const int kMinBlockSize = 2 * kPointerSize; | 1767 static const int kMinBlockSize = 2 * kPointerSize; |
1768 static const int kMaxBlockSize = Page::kMaxHeapObjectSize; | 1768 static const int kMaxBlockSize = Page::kMaxHeapObjectSize; |
1769 | 1769 |
1770 Heap* heap_; | |
1771 | |
1770 // The identity of the owning space, for building allocation Failure | 1772 // The identity of the owning space, for building allocation Failure |
1771 // objects. | 1773 // objects. |
1772 AllocationSpace owner_; | 1774 AllocationSpace owner_; |
1773 | 1775 |
1774 // Total available bytes in all blocks on this free list. | 1776 // Total available bytes in all blocks on this free list. |
1775 int available_; | 1777 int available_; |
1776 | 1778 |
1777 // Blocks are put on exact free lists in an array, indexed by size in words. | 1779 // Blocks are put on exact free lists in an array, indexed by size in words. |
1778 // The available sizes are kept in an increasingly ordered list. Entries | 1780 // The available sizes are kept in an increasingly ordered list. Entries |
1779 // corresponding to sizes < kMinBlockSize always have an empty free list | 1781 // corresponding to sizes < kMinBlockSize always have an empty free list |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1834 bool Contains(FreeListNode* node); | 1836 bool Contains(FreeListNode* node); |
1835 #endif | 1837 #endif |
1836 | 1838 |
1837 DISALLOW_COPY_AND_ASSIGN(OldSpaceFreeList); | 1839 DISALLOW_COPY_AND_ASSIGN(OldSpaceFreeList); |
1838 }; | 1840 }; |
1839 | 1841 |
1840 | 1842 |
1841 // The free list for the map space. | 1843 // The free list for the map space. |
1842 class FixedSizeFreeList BASE_EMBEDDED { | 1844 class FixedSizeFreeList BASE_EMBEDDED { |
1843 public: | 1845 public: |
1844 FixedSizeFreeList(AllocationSpace owner, int object_size); | 1846 FixedSizeFreeList(Heap* heap, AllocationSpace owner, int object_size); |
1845 | 1847 |
1846 // Clear the free list. | 1848 // Clear the free list. |
1847 void Reset(); | 1849 void Reset(); |
1848 | 1850 |
1849 // Return the number of bytes available on the free list. | 1851 // Return the number of bytes available on the free list. |
1850 intptr_t available() { return available_; } | 1852 intptr_t available() { return available_; } |
1851 | 1853 |
1852 // Place a node on the free list. The block starting at 'start' (assumed to | 1854 // Place a node on the free list. The block starting at 'start' (assumed to |
1853 // have size object_size_) is placed on the free list. Bookkeeping | 1855 // have size object_size_) is placed on the free list. Bookkeeping |
1854 // information will be written to the block, ie, its contents will be | 1856 // information will be written to the block, ie, its contents will be |
1855 // destroyed. The start address should be word aligned. | 1857 // destroyed. The start address should be word aligned. |
1856 void Free(Address start); | 1858 void Free(Address start); |
1857 | 1859 |
1858 // Allocate a fixed sized block from the free list. The block is unitialized. | 1860 // Allocate a fixed sized block from the free list. The block is unitialized. |
1859 // A failure is returned if no block is available. | 1861 // A failure is returned if no block is available. |
1860 MUST_USE_RESULT MaybeObject* Allocate(); | 1862 MUST_USE_RESULT MaybeObject* Allocate(); |
1861 | 1863 |
1862 void MarkNodes(); | 1864 void MarkNodes(); |
1863 | 1865 |
1864 private: | 1866 private: |
1867 | |
1868 Heap* heap_; | |
1869 | |
1865 // Available bytes on the free list. | 1870 // Available bytes on the free list. |
1866 intptr_t available_; | 1871 intptr_t available_; |
1867 | 1872 |
1868 // The head of the free list. | 1873 // The head of the free list. |
1869 Address head_; | 1874 Address head_; |
1870 | 1875 |
1871 // The tail of the free list. | 1876 // The tail of the free list. |
1872 Address tail_; | 1877 Address tail_; |
1873 | 1878 |
1874 // The identity of the owning space, for building allocation Failure | 1879 // The identity of the owning space, for building allocation Failure |
(...skipping 11 matching lines...) Expand all Loading... | |
1886 // Old object space (excluding map objects) | 1891 // Old object space (excluding map objects) |
1887 | 1892 |
1888 class OldSpace : public PagedSpace { | 1893 class OldSpace : public PagedSpace { |
1889 public: | 1894 public: |
1890 // Creates an old space object with a given maximum capacity. | 1895 // Creates an old space object with a given maximum capacity. |
1891 // The constructor does not allocate pages from OS. | 1896 // The constructor does not allocate pages from OS. |
1892 OldSpace(Heap* heap, | 1897 OldSpace(Heap* heap, |
1893 intptr_t max_capacity, | 1898 intptr_t max_capacity, |
1894 AllocationSpace id, | 1899 AllocationSpace id, |
1895 Executability executable) | 1900 Executability executable) |
1896 : PagedSpace(heap, max_capacity, id, executable), free_list_(id) { | 1901 : PagedSpace(heap, max_capacity, id, executable), |
1902 free_list_(heap, id) { | |
1897 page_extra_ = 0; | 1903 page_extra_ = 0; |
1898 } | 1904 } |
1899 | 1905 |
1900 // The bytes available on the free list (ie, not above the linear allocation | 1906 // The bytes available on the free list (ie, not above the linear allocation |
1901 // pointer). | 1907 // pointer). |
1902 intptr_t AvailableFree() { return free_list_.available(); } | 1908 intptr_t AvailableFree() { return free_list_.available(); } |
1903 | 1909 |
1904 // The limit of allocation for a page in this space. | 1910 // The limit of allocation for a page in this space. |
1905 virtual Address PageAllocationLimit(Page* page) { | 1911 virtual Address PageAllocationLimit(Page* page) { |
1906 return page->ObjectAreaEnd(); | 1912 return page->ObjectAreaEnd(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1963 class FixedSpace : public PagedSpace { | 1969 class FixedSpace : public PagedSpace { |
1964 public: | 1970 public: |
1965 FixedSpace(Heap* heap, | 1971 FixedSpace(Heap* heap, |
1966 intptr_t max_capacity, | 1972 intptr_t max_capacity, |
1967 AllocationSpace id, | 1973 AllocationSpace id, |
1968 int object_size_in_bytes, | 1974 int object_size_in_bytes, |
1969 const char* name) | 1975 const char* name) |
1970 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), | 1976 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), |
1971 object_size_in_bytes_(object_size_in_bytes), | 1977 object_size_in_bytes_(object_size_in_bytes), |
1972 name_(name), | 1978 name_(name), |
1973 free_list_(id, object_size_in_bytes) { | 1979 free_list_(heap, id, object_size_in_bytes) { |
1974 page_extra_ = Page::kObjectAreaSize % object_size_in_bytes; | 1980 page_extra_ = Page::kObjectAreaSize % object_size_in_bytes; |
1975 } | 1981 } |
1976 | 1982 |
1977 // The limit of allocation for a page in this space. | 1983 // The limit of allocation for a page in this space. |
1978 virtual Address PageAllocationLimit(Page* page) { | 1984 virtual Address PageAllocationLimit(Page* page) { |
1979 return page->ObjectAreaEnd() - page_extra_; | 1985 return page->ObjectAreaEnd() - page_extra_; |
1980 } | 1986 } |
1981 | 1987 |
1982 int object_size_in_bytes() { return object_size_in_bytes_; } | 1988 int object_size_in_bytes() { return object_size_in_bytes_; } |
1983 | 1989 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2353 } | 2359 } |
2354 // Must be small, since an iteration is used for lookup. | 2360 // Must be small, since an iteration is used for lookup. |
2355 static const int kMaxComments = 64; | 2361 static const int kMaxComments = 64; |
2356 }; | 2362 }; |
2357 #endif | 2363 #endif |
2358 | 2364 |
2359 | 2365 |
2360 } } // namespace v8::internal | 2366 } } // namespace v8::internal |
2361 | 2367 |
2362 #endif // V8_SPACES_H_ | 2368 #endif // V8_SPACES_H_ |
OLD | NEW |