| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // During scavenge collection this field is used to store allocation watermark | 348 // During scavenge collection this field is used to store allocation watermark |
| 349 // if it is altered during scavenge. | 349 // if it is altered during scavenge. |
| 350 Address mc_first_forwarded; | 350 Address mc_first_forwarded; |
| 351 }; | 351 }; |
| 352 | 352 |
| 353 | 353 |
| 354 // ---------------------------------------------------------------------------- | 354 // ---------------------------------------------------------------------------- |
| 355 // Space is the abstract superclass for all allocation spaces. | 355 // Space is the abstract superclass for all allocation spaces. |
| 356 class Space : public Malloced { | 356 class Space : public Malloced { |
| 357 public: | 357 public: |
| 358 Space(AllocationSpace id, Executability executable) | 358 Space(Heap* heap, AllocationSpace id, Executability executable) |
| 359 : id_(id), executable_(executable) {} | 359 : heap_(heap), id_(id), executable_(executable) {} |
| 360 | 360 |
| 361 virtual ~Space() {} | 361 virtual ~Space() {} |
| 362 | 362 |
| 363 Heap* heap() const { return heap_; } |
| 364 |
| 363 // Does the space need executable memory? | 365 // Does the space need executable memory? |
| 364 Executability executable() { return executable_; } | 366 Executability executable() { return executable_; } |
| 365 | 367 |
| 366 // Identity used in error reporting. | 368 // Identity used in error reporting. |
| 367 AllocationSpace identity() { return id_; } | 369 AllocationSpace identity() { return id_; } |
| 368 | 370 |
| 369 virtual int Size() = 0; | 371 virtual int Size() = 0; |
| 370 | 372 |
| 371 #ifdef ENABLE_HEAP_PROTECTION | 373 #ifdef ENABLE_HEAP_PROTECTION |
| 372 // Protect/unprotect the space by marking it read-only/writable. | 374 // Protect/unprotect the space by marking it read-only/writable. |
| 373 virtual void Protect() = 0; | 375 virtual void Protect() = 0; |
| 374 virtual void Unprotect() = 0; | 376 virtual void Unprotect() = 0; |
| 375 #endif | 377 #endif |
| 376 | 378 |
| 377 #ifdef DEBUG | 379 #ifdef DEBUG |
| 378 virtual void Print() = 0; | 380 virtual void Print() = 0; |
| 379 #endif | 381 #endif |
| 380 | 382 |
| 381 // After calling this we can allocate a certain number of bytes using only | 383 // After calling this we can allocate a certain number of bytes using only |
| 382 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) | 384 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) |
| 383 // without using freelists or causing a GC. This is used by partial | 385 // without using freelists or causing a GC. This is used by partial |
| 384 // snapshots. It returns true of space was reserved or false if a GC is | 386 // snapshots. It returns true of space was reserved or false if a GC is |
| 385 // needed. For paged spaces the space requested must include the space wasted | 387 // needed. For paged spaces the space requested must include the space wasted |
| 386 // at the end of each when allocating linearly. | 388 // at the end of each when allocating linearly. |
| 387 virtual bool ReserveSpace(int bytes) = 0; | 389 virtual bool ReserveSpace(int bytes) = 0; |
| 388 | 390 |
| 389 private: | 391 private: |
| 392 Heap* heap_; |
| 390 AllocationSpace id_; | 393 AllocationSpace id_; |
| 391 Executability executable_; | 394 Executability executable_; |
| 392 }; | 395 }; |
| 393 | 396 |
| 394 | 397 |
| 395 // ---------------------------------------------------------------------------- | 398 // ---------------------------------------------------------------------------- |
| 396 // All heap objects containing executable code (code objects) must be allocated | 399 // All heap objects containing executable code (code objects) must be allocated |
| 397 // from a 2 GB range of memory, so that they can call each other using 32-bit | 400 // from a 2 GB range of memory, so that they can call each other using 32-bit |
| 398 // displacements. This happens automatically on 32-bit platforms, where 32-bit | 401 // displacements. This happens automatically on 32-bit platforms, where 32-bit |
| 399 // displacements cover the entire 4GB virtual address space. On 64-bit | 402 // displacements cover the entire 4GB virtual address space. On 64-bit |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 int capacity_; | 986 int capacity_; |
| 984 int available_; | 987 int available_; |
| 985 int size_; | 988 int size_; |
| 986 int waste_; | 989 int waste_; |
| 987 }; | 990 }; |
| 988 | 991 |
| 989 | 992 |
| 990 class PagedSpace : public Space { | 993 class PagedSpace : public Space { |
| 991 public: | 994 public: |
| 992 // Creates a space with a maximum capacity, and an id. | 995 // Creates a space with a maximum capacity, and an id. |
| 993 PagedSpace(int max_capacity, AllocationSpace id, Executability executable); | 996 PagedSpace(Heap* heap, |
| 997 int max_capacity, |
| 998 AllocationSpace id, |
| 999 Executability executable); |
| 994 | 1000 |
| 995 virtual ~PagedSpace() {} | 1001 virtual ~PagedSpace() {} |
| 996 | 1002 |
| 997 // Set up the space using the given address range of virtual memory (from | 1003 // Set up the space using the given address range of virtual memory (from |
| 998 // the memory allocator's initial chunk) if possible. If the block of | 1004 // the memory allocator's initial chunk) if possible. If the block of |
| 999 // addresses is not big enough to contain a single page-aligned page, a | 1005 // addresses is not big enough to contain a single page-aligned page, a |
| 1000 // fresh chunk will be allocated. | 1006 // fresh chunk will be allocated. |
| 1001 bool Setup(Address start, size_t size); | 1007 bool Setup(Address start, size_t size); |
| 1002 | 1008 |
| 1003 // Returns true if the space has been successfully set up and not | 1009 // Returns true if the space has been successfully set up and not |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 // ----------------------------------------------------------------------------- | 1278 // ----------------------------------------------------------------------------- |
| 1273 // SemiSpace in young generation | 1279 // SemiSpace in young generation |
| 1274 // | 1280 // |
| 1275 // A semispace is a contiguous chunk of memory. The mark-compact collector | 1281 // A semispace is a contiguous chunk of memory. The mark-compact collector |
| 1276 // uses the memory in the from space as a marking stack when tracing live | 1282 // uses the memory in the from space as a marking stack when tracing live |
| 1277 // objects. | 1283 // objects. |
| 1278 | 1284 |
| 1279 class SemiSpace : public Space { | 1285 class SemiSpace : public Space { |
| 1280 public: | 1286 public: |
| 1281 // Constructor. | 1287 // Constructor. |
| 1282 SemiSpace() :Space(NEW_SPACE, NOT_EXECUTABLE) { | 1288 explicit SemiSpace(Heap* heap) : Space(heap, NEW_SPACE, NOT_EXECUTABLE) { |
| 1283 start_ = NULL; | 1289 start_ = NULL; |
| 1284 age_mark_ = NULL; | 1290 age_mark_ = NULL; |
| 1285 } | 1291 } |
| 1286 | 1292 |
| 1287 // Sets up the semispace using the given chunk. | 1293 // Sets up the semispace using the given chunk. |
| 1288 bool Setup(Address start, int initial_capacity, int maximum_capacity); | 1294 bool Setup(Address start, int initial_capacity, int maximum_capacity); |
| 1289 | 1295 |
| 1290 // Tear down the space. Heap memory was not allocated by the space, so it | 1296 // Tear down the space. Heap memory was not allocated by the space, so it |
| 1291 // is not deallocated here. | 1297 // is not deallocated here. |
| 1292 void TearDown(); | 1298 void TearDown(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 | 1445 |
| 1440 // ----------------------------------------------------------------------------- | 1446 // ----------------------------------------------------------------------------- |
| 1441 // The young generation space. | 1447 // The young generation space. |
| 1442 // | 1448 // |
| 1443 // The new space consists of a contiguous pair of semispaces. It simply | 1449 // The new space consists of a contiguous pair of semispaces. It simply |
| 1444 // forwards most functions to the appropriate semispace. | 1450 // forwards most functions to the appropriate semispace. |
| 1445 | 1451 |
| 1446 class NewSpace : public Space { | 1452 class NewSpace : public Space { |
| 1447 public: | 1453 public: |
| 1448 // Constructor. | 1454 // Constructor. |
| 1449 NewSpace() : Space(NEW_SPACE, NOT_EXECUTABLE) {} | 1455 explicit NewSpace(Heap* heap) |
| 1456 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| 1457 to_space_(heap), |
| 1458 from_space_(heap) {} |
| 1450 | 1459 |
| 1451 // Sets up the new space using the given chunk. | 1460 // Sets up the new space using the given chunk. |
| 1452 bool Setup(Address start, int size); | 1461 bool Setup(Address start, int size); |
| 1453 | 1462 |
| 1454 // Tears down the space. Heap memory was not allocated by the space, so it | 1463 // Tears down the space. Heap memory was not allocated by the space, so it |
| 1455 // is not deallocated here. | 1464 // is not deallocated here. |
| 1456 void TearDown(); | 1465 void TearDown(); |
| 1457 | 1466 |
| 1458 // True if the space has been set up but not torn down. | 1467 // True if the space has been set up but not torn down. |
| 1459 bool HasBeenSetup() { | 1468 bool HasBeenSetup() { |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 }; | 1835 }; |
| 1827 | 1836 |
| 1828 | 1837 |
| 1829 // ----------------------------------------------------------------------------- | 1838 // ----------------------------------------------------------------------------- |
| 1830 // Old object space (excluding map objects) | 1839 // Old object space (excluding map objects) |
| 1831 | 1840 |
| 1832 class OldSpace : public PagedSpace { | 1841 class OldSpace : public PagedSpace { |
| 1833 public: | 1842 public: |
| 1834 // Creates an old space object with a given maximum capacity. | 1843 // Creates an old space object with a given maximum capacity. |
| 1835 // The constructor does not allocate pages from OS. | 1844 // The constructor does not allocate pages from OS. |
| 1836 explicit OldSpace(int max_capacity, | 1845 OldSpace(Heap* heap, |
| 1837 AllocationSpace id, | 1846 int max_capacity, |
| 1838 Executability executable) | 1847 AllocationSpace id, |
| 1839 : PagedSpace(max_capacity, id, executable), free_list_(id) { | 1848 Executability executable) |
| 1849 : PagedSpace(heap, max_capacity, id, executable), free_list_(id) { |
| 1840 page_extra_ = 0; | 1850 page_extra_ = 0; |
| 1841 } | 1851 } |
| 1842 | 1852 |
| 1843 // The bytes available on the free list (ie, not above the linear allocation | 1853 // The bytes available on the free list (ie, not above the linear allocation |
| 1844 // pointer). | 1854 // pointer). |
| 1845 int AvailableFree() { return free_list_.available(); } | 1855 int AvailableFree() { return free_list_.available(); } |
| 1846 | 1856 |
| 1847 // The limit of allocation for a page in this space. | 1857 // The limit of allocation for a page in this space. |
| 1848 virtual Address PageAllocationLimit(Page* page) { | 1858 virtual Address PageAllocationLimit(Page* page) { |
| 1849 return page->ObjectAreaEnd(); | 1859 return page->ObjectAreaEnd(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 public: | 1906 public: |
| 1897 TRACK_MEMORY("OldSpace") | 1907 TRACK_MEMORY("OldSpace") |
| 1898 }; | 1908 }; |
| 1899 | 1909 |
| 1900 | 1910 |
| 1901 // ----------------------------------------------------------------------------- | 1911 // ----------------------------------------------------------------------------- |
| 1902 // Old space for objects of a fixed size | 1912 // Old space for objects of a fixed size |
| 1903 | 1913 |
| 1904 class FixedSpace : public PagedSpace { | 1914 class FixedSpace : public PagedSpace { |
| 1905 public: | 1915 public: |
| 1906 FixedSpace(int max_capacity, | 1916 FixedSpace(Heap* heap, |
| 1917 int max_capacity, |
| 1907 AllocationSpace id, | 1918 AllocationSpace id, |
| 1908 int object_size_in_bytes, | 1919 int object_size_in_bytes, |
| 1909 const char* name) | 1920 const char* name) |
| 1910 : PagedSpace(max_capacity, id, NOT_EXECUTABLE), | 1921 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), |
| 1911 object_size_in_bytes_(object_size_in_bytes), | 1922 object_size_in_bytes_(object_size_in_bytes), |
| 1912 name_(name), | 1923 name_(name), |
| 1913 free_list_(id, object_size_in_bytes) { | 1924 free_list_(id, object_size_in_bytes) { |
| 1914 page_extra_ = Page::kObjectAreaSize % object_size_in_bytes; | 1925 page_extra_ = Page::kObjectAreaSize % object_size_in_bytes; |
| 1915 } | 1926 } |
| 1916 | 1927 |
| 1917 // The limit of allocation for a page in this space. | 1928 // The limit of allocation for a page in this space. |
| 1918 virtual Address PageAllocationLimit(Page* page) { | 1929 virtual Address PageAllocationLimit(Page* page) { |
| 1919 return page->ObjectAreaEnd() - page_extra_; | 1930 return page->ObjectAreaEnd() - page_extra_; |
| 1920 } | 1931 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 FixedSizeFreeList free_list_; | 1982 FixedSizeFreeList free_list_; |
| 1972 }; | 1983 }; |
| 1973 | 1984 |
| 1974 | 1985 |
| 1975 // ----------------------------------------------------------------------------- | 1986 // ----------------------------------------------------------------------------- |
| 1976 // Old space for all map objects | 1987 // Old space for all map objects |
| 1977 | 1988 |
| 1978 class MapSpace : public FixedSpace { | 1989 class MapSpace : public FixedSpace { |
| 1979 public: | 1990 public: |
| 1980 // Creates a map space object with a maximum capacity. | 1991 // Creates a map space object with a maximum capacity. |
| 1981 MapSpace(int max_capacity, int max_map_space_pages, AllocationSpace id) | 1992 MapSpace(Heap* heap, |
| 1982 : FixedSpace(max_capacity, id, Map::kSize, "map"), | 1993 int max_capacity, |
| 1994 int max_map_space_pages, |
| 1995 AllocationSpace id) |
| 1996 : FixedSpace(heap, max_capacity, id, Map::kSize, "map"), |
| 1983 max_map_space_pages_(max_map_space_pages) { | 1997 max_map_space_pages_(max_map_space_pages) { |
| 1984 ASSERT(max_map_space_pages < kMaxMapPageIndex); | 1998 ASSERT(max_map_space_pages < kMaxMapPageIndex); |
| 1985 } | 1999 } |
| 1986 | 2000 |
| 1987 // Prepares for a mark-compact GC. | 2001 // Prepares for a mark-compact GC. |
| 1988 virtual void PrepareForMarkCompact(bool will_compact); | 2002 virtual void PrepareForMarkCompact(bool will_compact); |
| 1989 | 2003 |
| 1990 // Given an index, returns the page address. | 2004 // Given an index, returns the page address. |
| 1991 Address PageAddress(int page_index) { return page_addresses_[page_index]; } | 2005 Address PageAddress(int page_index) { return page_addresses_[page_index]; } |
| 1992 | 2006 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 TRACK_MEMORY("MapSpace") | 2090 TRACK_MEMORY("MapSpace") |
| 2077 }; | 2091 }; |
| 2078 | 2092 |
| 2079 | 2093 |
| 2080 // ----------------------------------------------------------------------------- | 2094 // ----------------------------------------------------------------------------- |
| 2081 // Old space for all global object property cell objects | 2095 // Old space for all global object property cell objects |
| 2082 | 2096 |
| 2083 class CellSpace : public FixedSpace { | 2097 class CellSpace : public FixedSpace { |
| 2084 public: | 2098 public: |
| 2085 // Creates a property cell space object with a maximum capacity. | 2099 // Creates a property cell space object with a maximum capacity. |
| 2086 CellSpace(int max_capacity, AllocationSpace id) | 2100 CellSpace(Heap* heap, int max_capacity, AllocationSpace id) |
| 2087 : FixedSpace(max_capacity, id, JSGlobalPropertyCell::kSize, "cell") {} | 2101 : FixedSpace(heap, max_capacity, id, JSGlobalPropertyCell::kSize, "cell") |
| 2102 {} |
| 2088 | 2103 |
| 2089 protected: | 2104 protected: |
| 2090 #ifdef DEBUG | 2105 #ifdef DEBUG |
| 2091 virtual void VerifyObject(HeapObject* obj); | 2106 virtual void VerifyObject(HeapObject* obj); |
| 2092 #endif | 2107 #endif |
| 2093 | 2108 |
| 2094 public: | 2109 public: |
| 2095 TRACK_MEMORY("CellSpace") | 2110 TRACK_MEMORY("CellSpace") |
| 2096 }; | 2111 }; |
| 2097 | 2112 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 // The size of this chunk. | 2166 // The size of this chunk. |
| 2152 size_t size_; | 2167 size_t size_; |
| 2153 | 2168 |
| 2154 public: | 2169 public: |
| 2155 TRACK_MEMORY("LargeObjectChunk") | 2170 TRACK_MEMORY("LargeObjectChunk") |
| 2156 }; | 2171 }; |
| 2157 | 2172 |
| 2158 | 2173 |
| 2159 class LargeObjectSpace : public Space { | 2174 class LargeObjectSpace : public Space { |
| 2160 public: | 2175 public: |
| 2161 explicit LargeObjectSpace(AllocationSpace id); | 2176 LargeObjectSpace(Heap* heap, AllocationSpace id); |
| 2162 virtual ~LargeObjectSpace() {} | 2177 virtual ~LargeObjectSpace() {} |
| 2163 | 2178 |
| 2164 // Initializes internal data structures. | 2179 // Initializes internal data structures. |
| 2165 bool Setup(); | 2180 bool Setup(); |
| 2166 | 2181 |
| 2167 // Releases internal resources, frees objects in this space. | 2182 // Releases internal resources, frees objects in this space. |
| 2168 void TearDown(); | 2183 void TearDown(); |
| 2169 | 2184 |
| 2170 // Allocates a (non-FixedArray, non-Code) large object. | 2185 // Allocates a (non-FixedArray, non-Code) large object. |
| 2171 Object* AllocateRaw(int size_in_bytes); | 2186 Object* AllocateRaw(int size_in_bytes); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2276 } | 2291 } |
| 2277 // Must be small, since an iteration is used for lookup. | 2292 // Must be small, since an iteration is used for lookup. |
| 2278 static const int kMaxComments = 64; | 2293 static const int kMaxComments = 64; |
| 2279 }; | 2294 }; |
| 2280 #endif | 2295 #endif |
| 2281 | 2296 |
| 2282 | 2297 |
| 2283 } } // namespace v8::internal | 2298 } } // namespace v8::internal |
| 2284 | 2299 |
| 2285 #endif // V8_SPACES_H_ | 2300 #endif // V8_SPACES_H_ |
| OLD | NEW |