Chromium Code Reviews| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 298 |
| 299 // Identity used in error reporting. | 299 // Identity used in error reporting. |
| 300 AllocationSpace identity() { return id_; } | 300 AllocationSpace identity() { return id_; } |
| 301 | 301 |
| 302 virtual int Size() = 0; | 302 virtual int Size() = 0; |
| 303 | 303 |
| 304 #ifdef DEBUG | 304 #ifdef DEBUG |
| 305 virtual void Print() = 0; | 305 virtual void Print() = 0; |
| 306 #endif | 306 #endif |
| 307 | 307 |
| 308 // After calling this we can allocate a certain number of bytes using only | |
| 309 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) | |
| 310 // without using freelists or causing a GC. This is used by partial | |
| 311 // snapshots. It returns true of space was reserved or false if a GC is | |
|
Mads Ager (chromium)
2010/01/12 14:17:49
of space -> if space
| |
| 312 // needed. | |
| 313 virtual bool ReserveSpace(int bytes) = 0; | |
| 314 | |
| 308 private: | 315 private: |
| 309 AllocationSpace id_; | 316 AllocationSpace id_; |
| 310 Executability executable_; | 317 Executability executable_; |
| 311 }; | 318 }; |
| 312 | 319 |
| 313 | 320 |
| 314 // ---------------------------------------------------------------------------- | 321 // ---------------------------------------------------------------------------- |
| 315 // All heap objects containing executable code (code objects) must be allocated | 322 // All heap objects containing executable code (code objects) must be allocated |
| 316 // from a 2 GB range of memory, so that they can call each other using 32-bit | 323 // from a 2 GB range of memory, so that they can call each other using 32-bit |
| 317 // displacements. This happens automatically on 32-bit platforms, where 32-bit | 324 // displacements. This happens automatically on 32-bit platforms, where 32-bit |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 Address top() { return allocation_info_.top; } | 887 Address top() { return allocation_info_.top; } |
| 881 | 888 |
| 882 // Allocate the requested number of bytes in the space if possible, return a | 889 // Allocate the requested number of bytes in the space if possible, return a |
| 883 // failure object if not. | 890 // failure object if not. |
| 884 inline Object* AllocateRaw(int size_in_bytes); | 891 inline Object* AllocateRaw(int size_in_bytes); |
| 885 | 892 |
| 886 // Allocate the requested number of bytes for relocation during mark-compact | 893 // Allocate the requested number of bytes for relocation during mark-compact |
| 887 // collection. | 894 // collection. |
| 888 inline Object* MCAllocateRaw(int size_in_bytes); | 895 inline Object* MCAllocateRaw(int size_in_bytes); |
| 889 | 896 |
| 897 virtual bool ReserveSpace(int bytes); | |
| 898 | |
| 899 // Used by ReserveSpace. | |
| 900 virtual void PutRestOfCurrentPageOnFreeList(Page* current_page) = 0; | |
| 890 | 901 |
| 891 // --------------------------------------------------------------------------- | 902 // --------------------------------------------------------------------------- |
| 892 // Mark-compact collection support functions | 903 // Mark-compact collection support functions |
| 893 | 904 |
| 894 // Set the relocation point to the beginning of the space. | 905 // Set the relocation point to the beginning of the space. |
| 895 void MCResetRelocationInfo(); | 906 void MCResetRelocationInfo(); |
| 896 | 907 |
| 897 // Writes relocation info to the top page. | 908 // Writes relocation info to the top page. |
| 898 void MCWriteRelocationInfoToPage() { | 909 void MCWriteRelocationInfoToPage() { |
| 899 TopPageOf(mc_forwarding_info_)->mc_relocation_top = mc_forwarding_info_.top; | 910 TopPageOf(mc_forwarding_info_)->mc_relocation_top = mc_forwarding_info_.top; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 // semispace (not necessarily below the allocation pointer). | 1119 // semispace (not necessarily below the allocation pointer). |
| 1109 bool Contains(Object* o) { | 1120 bool Contains(Object* o) { |
| 1110 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; | 1121 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; |
| 1111 } | 1122 } |
| 1112 | 1123 |
| 1113 // The offset of an address from the beginning of the space. | 1124 // The offset of an address from the beginning of the space. |
| 1114 int SpaceOffsetForAddress(Address addr) { | 1125 int SpaceOffsetForAddress(Address addr) { |
| 1115 return static_cast<int>(addr - low()); | 1126 return static_cast<int>(addr - low()); |
| 1116 } | 1127 } |
| 1117 | 1128 |
| 1118 // If we don't have this here then SemiSpace will be abstract. However | 1129 // If we don't have these here then SemiSpace will be abstract. However |
| 1119 // it should never be called. | 1130 // they should never be called. |
| 1120 virtual int Size() { | 1131 virtual int Size() { |
| 1121 UNREACHABLE(); | 1132 UNREACHABLE(); |
| 1122 return 0; | 1133 return 0; |
| 1123 } | 1134 } |
| 1124 | 1135 |
| 1136 virtual bool ReserveSpace(int bytes) { | |
| 1137 UNREACHABLE(); | |
| 1138 return false; | |
| 1139 } | |
| 1140 | |
| 1125 bool is_committed() { return committed_; } | 1141 bool is_committed() { return committed_; } |
| 1126 bool Commit(); | 1142 bool Commit(); |
| 1127 bool Uncommit(); | 1143 bool Uncommit(); |
| 1128 | 1144 |
| 1129 #ifdef DEBUG | 1145 #ifdef DEBUG |
| 1130 virtual void Print(); | 1146 virtual void Print(); |
| 1131 virtual void Verify(); | 1147 virtual void Verify(); |
| 1132 #endif | 1148 #endif |
| 1133 | 1149 |
| 1134 // Returns the current capacity of the semi space. | 1150 // Returns the current capacity of the semi space. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 | 1354 |
| 1339 // True if the object is a heap object in the address range of the | 1355 // True if the object is a heap object in the address range of the |
| 1340 // respective semispace (not necessarily below the allocation pointer of the | 1356 // respective semispace (not necessarily below the allocation pointer of the |
| 1341 // semispace). | 1357 // semispace). |
| 1342 bool ToSpaceContains(Object* o) { return to_space_.Contains(o); } | 1358 bool ToSpaceContains(Object* o) { return to_space_.Contains(o); } |
| 1343 bool FromSpaceContains(Object* o) { return from_space_.Contains(o); } | 1359 bool FromSpaceContains(Object* o) { return from_space_.Contains(o); } |
| 1344 | 1360 |
| 1345 bool ToSpaceContains(Address a) { return to_space_.Contains(a); } | 1361 bool ToSpaceContains(Address a) { return to_space_.Contains(a); } |
| 1346 bool FromSpaceContains(Address a) { return from_space_.Contains(a); } | 1362 bool FromSpaceContains(Address a) { return from_space_.Contains(a); } |
| 1347 | 1363 |
| 1364 virtual bool ReserveSpace(int bytes); | |
| 1365 | |
| 1348 #ifdef ENABLE_HEAP_PROTECTION | 1366 #ifdef ENABLE_HEAP_PROTECTION |
| 1349 // Protect/unprotect the space by marking it read-only/writable. | 1367 // Protect/unprotect the space by marking it read-only/writable. |
| 1350 virtual void Protect(); | 1368 virtual void Protect(); |
| 1351 virtual void Unprotect(); | 1369 virtual void Unprotect(); |
| 1352 #endif | 1370 #endif |
| 1353 | 1371 |
| 1354 #ifdef DEBUG | 1372 #ifdef DEBUG |
| 1355 // Verify the active semispace. | 1373 // Verify the active semispace. |
| 1356 virtual void Verify(); | 1374 virtual void Verify(); |
| 1357 // Print the active semispace. | 1375 // Print the active semispace. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 } | 1642 } |
| 1625 | 1643 |
| 1626 // Prepare for full garbage collection. Resets the relocation pointer and | 1644 // Prepare for full garbage collection. Resets the relocation pointer and |
| 1627 // clears the free list. | 1645 // clears the free list. |
| 1628 virtual void PrepareForMarkCompact(bool will_compact); | 1646 virtual void PrepareForMarkCompact(bool will_compact); |
| 1629 | 1647 |
| 1630 // Updates the allocation pointer to the relocation top after a mark-compact | 1648 // Updates the allocation pointer to the relocation top after a mark-compact |
| 1631 // collection. | 1649 // collection. |
| 1632 virtual void MCCommitRelocationInfo(); | 1650 virtual void MCCommitRelocationInfo(); |
| 1633 | 1651 |
| 1652 virtual void PutRestOfCurrentPageOnFreeList(Page* current_page); | |
| 1653 | |
| 1634 #ifdef DEBUG | 1654 #ifdef DEBUG |
| 1635 // Reports statistics for the space | 1655 // Reports statistics for the space |
| 1636 void ReportStatistics(); | 1656 void ReportStatistics(); |
| 1637 // Dump the remembered sets in the space to stdout. | 1657 // Dump the remembered sets in the space to stdout. |
| 1638 void PrintRSet(); | 1658 void PrintRSet(); |
| 1639 #endif | 1659 #endif |
| 1640 | 1660 |
| 1641 protected: | 1661 protected: |
| 1642 // Virtual function in the superclass. Slow path of AllocateRaw. | 1662 // Virtual function in the superclass. Slow path of AllocateRaw. |
| 1643 HeapObject* SlowAllocateRaw(int size_in_bytes); | 1663 HeapObject* SlowAllocateRaw(int size_in_bytes); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1685 accounting_stats_.DeallocateBytes(object_size_in_bytes_); | 1705 accounting_stats_.DeallocateBytes(object_size_in_bytes_); |
| 1686 } | 1706 } |
| 1687 | 1707 |
| 1688 // Prepares for a mark-compact GC. | 1708 // Prepares for a mark-compact GC. |
| 1689 virtual void PrepareForMarkCompact(bool will_compact); | 1709 virtual void PrepareForMarkCompact(bool will_compact); |
| 1690 | 1710 |
| 1691 // Updates the allocation pointer to the relocation top after a mark-compact | 1711 // Updates the allocation pointer to the relocation top after a mark-compact |
| 1692 // collection. | 1712 // collection. |
| 1693 virtual void MCCommitRelocationInfo(); | 1713 virtual void MCCommitRelocationInfo(); |
| 1694 | 1714 |
| 1715 virtual void PutRestOfCurrentPageOnFreeList(Page* current_page); | |
| 1716 | |
| 1695 #ifdef DEBUG | 1717 #ifdef DEBUG |
| 1696 // Reports statistic info of the space | 1718 // Reports statistic info of the space |
| 1697 void ReportStatistics(); | 1719 void ReportStatistics(); |
| 1698 | 1720 |
| 1699 // Dump the remembered sets in the space to stdout. | 1721 // Dump the remembered sets in the space to stdout. |
| 1700 void PrintRSet(); | 1722 void PrintRSet(); |
| 1701 #endif | 1723 #endif |
| 1702 | 1724 |
| 1703 protected: | 1725 protected: |
| 1704 // Virtual function in the superclass. Slow path of AllocateRaw. | 1726 // Virtual function in the superclass. Slow path of AllocateRaw. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1892 | 1914 |
| 1893 // Frees unmarked objects. | 1915 // Frees unmarked objects. |
| 1894 void FreeUnmarkedObjects(); | 1916 void FreeUnmarkedObjects(); |
| 1895 | 1917 |
| 1896 // Checks whether a heap object is in this space; O(1). | 1918 // Checks whether a heap object is in this space; O(1). |
| 1897 bool Contains(HeapObject* obj); | 1919 bool Contains(HeapObject* obj); |
| 1898 | 1920 |
| 1899 // Checks whether the space is empty. | 1921 // Checks whether the space is empty. |
| 1900 bool IsEmpty() { return first_chunk_ == NULL; } | 1922 bool IsEmpty() { return first_chunk_ == NULL; } |
| 1901 | 1923 |
| 1924 // See the comments for ReserveSpace in the Space class. This has to be | |
| 1925 // called after ReserveSpace has been called on the paged spaces, since they | |
| 1926 // may use some memory, leaving less for large objects. | |
| 1927 virtual bool ReserveSpace(int bytes); | |
| 1928 | |
| 1902 #ifdef ENABLE_HEAP_PROTECTION | 1929 #ifdef ENABLE_HEAP_PROTECTION |
| 1903 // Protect/unprotect the space by marking it read-only/writable. | 1930 // Protect/unprotect the space by marking it read-only/writable. |
| 1904 void Protect(); | 1931 void Protect(); |
| 1905 void Unprotect(); | 1932 void Unprotect(); |
| 1906 #endif | 1933 #endif |
| 1907 | 1934 |
| 1908 #ifdef DEBUG | 1935 #ifdef DEBUG |
| 1909 virtual void Verify(); | 1936 virtual void Verify(); |
| 1910 virtual void Print(); | 1937 virtual void Print(); |
| 1911 void ReportStatistics(); | 1938 void ReportStatistics(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1955 | 1982 |
| 1956 private: | 1983 private: |
| 1957 LargeObjectChunk* current_; | 1984 LargeObjectChunk* current_; |
| 1958 HeapObjectCallback size_func_; | 1985 HeapObjectCallback size_func_; |
| 1959 }; | 1986 }; |
| 1960 | 1987 |
| 1961 | 1988 |
| 1962 } } // namespace v8::internal | 1989 } } // namespace v8::internal |
| 1963 | 1990 |
| 1964 #endif // V8_SPACES_H_ | 1991 #endif // V8_SPACES_H_ |
| OLD | NEW |