| 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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 virtual intptr_t SizeOfObjects() { return Size(); } | 716 virtual intptr_t SizeOfObjects() { return Size(); } |
| 717 | 717 |
| 718 virtual int RoundSizeDownToObjectAlignment(int size) { | 718 virtual int RoundSizeDownToObjectAlignment(int size) { |
| 719 if (id_ == CODE_SPACE) { | 719 if (id_ == CODE_SPACE) { |
| 720 return RoundDown(size, kCodeAlignment); | 720 return RoundDown(size, kCodeAlignment); |
| 721 } else { | 721 } else { |
| 722 return RoundDown(size, kPointerSize); | 722 return RoundDown(size, kPointerSize); |
| 723 } | 723 } |
| 724 } | 724 } |
| 725 | 725 |
| 726 #ifdef ENABLE_HEAP_PROTECTION | |
| 727 // Protect/unprotect the space by marking it read-only/writable. | |
| 728 virtual void Protect() = 0; | |
| 729 virtual void Unprotect() = 0; | |
| 730 #endif | |
| 731 | |
| 732 #ifdef DEBUG | 726 #ifdef DEBUG |
| 733 virtual void Print() = 0; | 727 virtual void Print() = 0; |
| 734 #endif | 728 #endif |
| 735 | 729 |
| 736 // After calling this we can allocate a certain number of bytes using only | 730 // After calling this we can allocate a certain number of bytes using only |
| 737 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) | 731 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) |
| 738 // without using freelists or causing a GC. This is used by partial | 732 // without using freelists or causing a GC. This is used by partial |
| 739 // snapshots. It returns true of space was reserved or false if a GC is | 733 // snapshots. It returns true of space was reserved or false if a GC is |
| 740 // needed. For paged spaces the space requested must include the space wasted | 734 // needed. For paged spaces the space requested must include the space wasted |
| 741 // at the end of each when allocating linearly. | 735 // at the end of each when allocating linearly. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 } | 859 } |
| 866 | 860 |
| 867 // Returns allocated executable spaces in bytes. | 861 // Returns allocated executable spaces in bytes. |
| 868 intptr_t SizeExecutable() { return size_executable_; } | 862 intptr_t SizeExecutable() { return size_executable_; } |
| 869 | 863 |
| 870 // Returns maximum available bytes that the old space can have. | 864 // Returns maximum available bytes that the old space can have. |
| 871 intptr_t MaxAvailable() { | 865 intptr_t MaxAvailable() { |
| 872 return (Available() / Page::kPageSize) * Page::kObjectAreaSize; | 866 return (Available() / Page::kPageSize) * Page::kObjectAreaSize; |
| 873 } | 867 } |
| 874 | 868 |
| 875 #ifdef ENABLE_HEAP_PROTECTION | |
| 876 // Protect/unprotect a block of memory by marking it read-only/writable. | |
| 877 inline void Protect(Address start, size_t size); | |
| 878 inline void Unprotect(Address start, size_t size, | |
| 879 Executability executable); | |
| 880 | |
| 881 // Protect/unprotect a chunk given a page in the chunk. | |
| 882 inline void ProtectChunkFromPage(Page* page); | |
| 883 inline void UnprotectChunkFromPage(Page* page); | |
| 884 #endif | |
| 885 | |
| 886 #ifdef DEBUG | 869 #ifdef DEBUG |
| 887 // Reports statistic info of the space. | 870 // Reports statistic info of the space. |
| 888 void ReportStatistics(); | 871 void ReportStatistics(); |
| 889 #endif | 872 #endif |
| 890 | 873 |
| 891 MemoryChunk* AllocateChunk(intptr_t body_size, | 874 MemoryChunk* AllocateChunk(intptr_t body_size, |
| 892 Executability executable, | 875 Executability executable, |
| 893 Space* space); | 876 Space* space); |
| 894 | 877 |
| 895 Address AllocateAlignedMemory(const size_t requested, | 878 Address AllocateAlignedMemory(const size_t requested, |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 | 1399 |
| 1417 // Releases half of unused pages. | 1400 // Releases half of unused pages. |
| 1418 void Shrink(); | 1401 void Shrink(); |
| 1419 | 1402 |
| 1420 // Ensures that the capacity is at least 'capacity'. Returns false on failure. | 1403 // Ensures that the capacity is at least 'capacity'. Returns false on failure. |
| 1421 bool EnsureCapacity(int capacity); | 1404 bool EnsureCapacity(int capacity); |
| 1422 | 1405 |
| 1423 // The dummy page that anchors the linked list of pages. | 1406 // The dummy page that anchors the linked list of pages. |
| 1424 Page* anchor() { return &anchor_; } | 1407 Page* anchor() { return &anchor_; } |
| 1425 | 1408 |
| 1426 #ifdef ENABLE_HEAP_PROTECTION | |
| 1427 // Protect/unprotect the space by marking it read-only/writable. | |
| 1428 void Protect(); | |
| 1429 void Unprotect(); | |
| 1430 #endif | |
| 1431 | |
| 1432 #ifdef DEBUG | 1409 #ifdef DEBUG |
| 1433 // Print meta info and objects in this space. | 1410 // Print meta info and objects in this space. |
| 1434 virtual void Print(); | 1411 virtual void Print(); |
| 1435 | 1412 |
| 1436 // Verify integrity of this space. | 1413 // Verify integrity of this space. |
| 1437 virtual void Verify(ObjectVisitor* visitor); | 1414 virtual void Verify(ObjectVisitor* visitor); |
| 1438 | 1415 |
| 1439 // Reports statistics for the space | 1416 // Reports statistics for the space |
| 1440 void ReportStatistics(); | 1417 void ReportStatistics(); |
| 1441 | 1418 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 | 1518 |
| 1542 #ifdef DEBUG | 1519 #ifdef DEBUG |
| 1543 // Returns the number of total pages in this space. | 1520 // Returns the number of total pages in this space. |
| 1544 int CountTotalPages(); | 1521 int CountTotalPages(); |
| 1545 #endif | 1522 #endif |
| 1546 | 1523 |
| 1547 friend class PageIterator; | 1524 friend class PageIterator; |
| 1548 }; | 1525 }; |
| 1549 | 1526 |
| 1550 | 1527 |
| 1551 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 1552 class NumberAndSizeInfo BASE_EMBEDDED { | 1528 class NumberAndSizeInfo BASE_EMBEDDED { |
| 1553 public: | 1529 public: |
| 1554 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 1530 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
| 1555 | 1531 |
| 1556 int number() const { return number_; } | 1532 int number() const { return number_; } |
| 1557 void increment_number(int num) { number_ += num; } | 1533 void increment_number(int num) { number_ += num; } |
| 1558 | 1534 |
| 1559 int bytes() const { return bytes_; } | 1535 int bytes() const { return bytes_; } |
| 1560 void increment_bytes(int size) { bytes_ += size; } | 1536 void increment_bytes(int size) { bytes_ += size; } |
| 1561 | 1537 |
| 1562 void clear() { | 1538 void clear() { |
| 1563 number_ = 0; | 1539 number_ = 0; |
| 1564 bytes_ = 0; | 1540 bytes_ = 0; |
| 1565 } | 1541 } |
| 1566 | 1542 |
| 1567 private: | 1543 private: |
| 1568 int number_; | 1544 int number_; |
| 1569 int bytes_; | 1545 int bytes_; |
| 1570 }; | 1546 }; |
| 1571 | 1547 |
| 1572 | 1548 |
| 1573 // HistogramInfo class for recording a single "bar" of a histogram. This | 1549 // HistogramInfo class for recording a single "bar" of a histogram. This |
| 1574 // class is used for collecting statistics to print to stdout (when compiled | 1550 // class is used for collecting statistics to print to the log file. |
| 1575 // with DEBUG) or to the log file (when compiled with | |
| 1576 // ENABLE_LOGGING_AND_PROFILING). | |
| 1577 class HistogramInfo: public NumberAndSizeInfo { | 1551 class HistogramInfo: public NumberAndSizeInfo { |
| 1578 public: | 1552 public: |
| 1579 HistogramInfo() : NumberAndSizeInfo() {} | 1553 HistogramInfo() : NumberAndSizeInfo() {} |
| 1580 | 1554 |
| 1581 const char* name() { return name_; } | 1555 const char* name() { return name_; } |
| 1582 void set_name(const char* name) { name_ = name; } | 1556 void set_name(const char* name) { name_ = name; } |
| 1583 | 1557 |
| 1584 private: | 1558 private: |
| 1585 const char* name_; | 1559 const char* name_; |
| 1586 }; | 1560 }; |
| 1587 #endif | |
| 1588 | 1561 |
| 1589 | 1562 |
| 1590 enum SemiSpaceId { | 1563 enum SemiSpaceId { |
| 1591 kFromSpace = 0, | 1564 kFromSpace = 0, |
| 1592 kToSpace = 1 | 1565 kToSpace = 1 |
| 1593 }; | 1566 }; |
| 1594 | 1567 |
| 1595 | 1568 |
| 1596 class SemiSpace; | 1569 class SemiSpace; |
| 1597 | 1570 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 return false; | 1754 return false; |
| 1782 } | 1755 } |
| 1783 | 1756 |
| 1784 bool is_committed() { return committed_; } | 1757 bool is_committed() { return committed_; } |
| 1785 bool Commit(); | 1758 bool Commit(); |
| 1786 bool Uncommit(); | 1759 bool Uncommit(); |
| 1787 | 1760 |
| 1788 NewSpacePage* first_page() { return anchor_.next_page(); } | 1761 NewSpacePage* first_page() { return anchor_.next_page(); } |
| 1789 NewSpacePage* current_page() { return current_page_; } | 1762 NewSpacePage* current_page() { return current_page_; } |
| 1790 | 1763 |
| 1791 #ifdef ENABLE_HEAP_PROTECTION | |
| 1792 // Protect/unprotect the space by marking it read-only/writable. | |
| 1793 virtual void Protect() {} | |
| 1794 virtual void Unprotect() {} | |
| 1795 #endif | |
| 1796 | |
| 1797 #ifdef DEBUG | 1764 #ifdef DEBUG |
| 1798 virtual void Print(); | 1765 virtual void Print(); |
| 1799 virtual void Verify(); | 1766 virtual void Verify(); |
| 1800 // Validate a range of of addresses in a SemiSpace. | 1767 // Validate a range of of addresses in a SemiSpace. |
| 1801 // The "from" address must be on a page prior to the "to" address, | 1768 // The "from" address must be on a page prior to the "to" address, |
| 1802 // in the linked page order, or it must be earlier on the same page. | 1769 // in the linked page order, or it must be earlier on the same page. |
| 1803 static void AssertValidRange(Address from, Address to); | 1770 static void AssertValidRange(Address from, Address to); |
| 1804 #else | 1771 #else |
| 1805 // Do nothing. | 1772 // Do nothing. |
| 1806 inline static void AssertValidRange(Address from, Address to) {} | 1773 inline static void AssertValidRange(Address from, Address to) {} |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2116 // if successful. | 2083 // if successful. |
| 2117 bool AddFreshPage(); | 2084 bool AddFreshPage(); |
| 2118 | 2085 |
| 2119 virtual bool ReserveSpace(int bytes); | 2086 virtual bool ReserveSpace(int bytes); |
| 2120 | 2087 |
| 2121 // Resizes a sequential string which must be the most recent thing that was | 2088 // Resizes a sequential string which must be the most recent thing that was |
| 2122 // allocated in new space. | 2089 // allocated in new space. |
| 2123 template <typename StringType> | 2090 template <typename StringType> |
| 2124 inline void ShrinkStringAtAllocationBoundary(String* string, int len); | 2091 inline void ShrinkStringAtAllocationBoundary(String* string, int len); |
| 2125 | 2092 |
| 2126 #ifdef ENABLE_HEAP_PROTECTION | |
| 2127 // Protect/unprotect the space by marking it read-only/writable. | |
| 2128 virtual void Protect(); | |
| 2129 virtual void Unprotect(); | |
| 2130 #endif | |
| 2131 | |
| 2132 #ifdef DEBUG | 2093 #ifdef DEBUG |
| 2133 // Verify the active semispace. | 2094 // Verify the active semispace. |
| 2134 virtual void Verify(); | 2095 virtual void Verify(); |
| 2135 // Print the active semispace. | 2096 // Print the active semispace. |
| 2136 virtual void Print() { to_space_.Print(); } | 2097 virtual void Print() { to_space_.Print(); } |
| 2137 #endif | 2098 #endif |
| 2138 | 2099 |
| 2139 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 2140 // Iterates the active semispace to collect statistics. | 2100 // Iterates the active semispace to collect statistics. |
| 2141 void CollectStatistics(); | 2101 void CollectStatistics(); |
| 2142 // Reports previously collected statistics of the active semispace. | 2102 // Reports previously collected statistics of the active semispace. |
| 2143 void ReportStatistics(); | 2103 void ReportStatistics(); |
| 2144 // Clears previously collected statistics. | 2104 // Clears previously collected statistics. |
| 2145 void ClearHistograms(); | 2105 void ClearHistograms(); |
| 2146 | 2106 |
| 2147 // Record the allocation or promotion of a heap object. Note that we don't | 2107 // Record the allocation or promotion of a heap object. Note that we don't |
| 2148 // record every single allocation, but only those that happen in the | 2108 // record every single allocation, but only those that happen in the |
| 2149 // to space during a scavenge GC. | 2109 // to space during a scavenge GC. |
| 2150 void RecordAllocation(HeapObject* obj); | 2110 void RecordAllocation(HeapObject* obj); |
| 2151 void RecordPromotion(HeapObject* obj); | 2111 void RecordPromotion(HeapObject* obj); |
| 2152 #endif | |
| 2153 | 2112 |
| 2154 // Return whether the operation succeded. | 2113 // Return whether the operation succeded. |
| 2155 bool CommitFromSpaceIfNeeded() { | 2114 bool CommitFromSpaceIfNeeded() { |
| 2156 if (from_space_.is_committed()) return true; | 2115 if (from_space_.is_committed()) return true; |
| 2157 return from_space_.Commit(); | 2116 return from_space_.Commit(); |
| 2158 } | 2117 } |
| 2159 | 2118 |
| 2160 bool UncommitFromSpace() { | 2119 bool UncommitFromSpace() { |
| 2161 if (!from_space_.is_committed()) return true; | 2120 if (!from_space_.is_committed()) return true; |
| 2162 return from_space_.Uncommit(); | 2121 return from_space_.Uncommit(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2191 AllocationInfo allocation_info_; | 2150 AllocationInfo allocation_info_; |
| 2192 | 2151 |
| 2193 // When incremental marking is active we will set allocation_info_.limit | 2152 // When incremental marking is active we will set allocation_info_.limit |
| 2194 // to be lower than actual limit and then will gradually increase it | 2153 // to be lower than actual limit and then will gradually increase it |
| 2195 // in steps to guarantee that we do incremental marking steps even | 2154 // in steps to guarantee that we do incremental marking steps even |
| 2196 // when all allocation is performed from inlined generated code. | 2155 // when all allocation is performed from inlined generated code. |
| 2197 intptr_t inline_allocation_limit_step_; | 2156 intptr_t inline_allocation_limit_step_; |
| 2198 | 2157 |
| 2199 Address top_on_previous_step_; | 2158 Address top_on_previous_step_; |
| 2200 | 2159 |
| 2201 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | |
| 2202 HistogramInfo* allocated_histogram_; | 2160 HistogramInfo* allocated_histogram_; |
| 2203 HistogramInfo* promoted_histogram_; | 2161 HistogramInfo* promoted_histogram_; |
| 2204 #endif | |
| 2205 | 2162 |
| 2206 // Implementation of AllocateRaw. | 2163 // Implementation of AllocateRaw. |
| 2207 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal(int size_in_bytes); | 2164 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal(int size_in_bytes); |
| 2208 | 2165 |
| 2209 friend class SemiSpaceIterator; | 2166 friend class SemiSpaceIterator; |
| 2210 | 2167 |
| 2211 public: | 2168 public: |
| 2212 TRACK_MEMORY("NewSpace") | 2169 TRACK_MEMORY("NewSpace") |
| 2213 }; | 2170 }; |
| 2214 | 2171 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2434 bool Contains(HeapObject* obj); | 2391 bool Contains(HeapObject* obj); |
| 2435 | 2392 |
| 2436 // Checks whether the space is empty. | 2393 // Checks whether the space is empty. |
| 2437 bool IsEmpty() { return first_page_ == NULL; } | 2394 bool IsEmpty() { return first_page_ == NULL; } |
| 2438 | 2395 |
| 2439 // See the comments for ReserveSpace in the Space class. This has to be | 2396 // See the comments for ReserveSpace in the Space class. This has to be |
| 2440 // called after ReserveSpace has been called on the paged spaces, since they | 2397 // called after ReserveSpace has been called on the paged spaces, since they |
| 2441 // may use some memory, leaving less for large objects. | 2398 // may use some memory, leaving less for large objects. |
| 2442 virtual bool ReserveSpace(int bytes); | 2399 virtual bool ReserveSpace(int bytes); |
| 2443 | 2400 |
| 2444 #ifdef ENABLE_HEAP_PROTECTION | |
| 2445 // Protect/unprotect the space by marking it read-only/writable. | |
| 2446 void Protect(); | |
| 2447 void Unprotect(); | |
| 2448 #endif | |
| 2449 | |
| 2450 LargePage* first_page() { return first_page_; } | 2401 LargePage* first_page() { return first_page_; } |
| 2451 | 2402 |
| 2452 #ifdef DEBUG | 2403 #ifdef DEBUG |
| 2453 virtual void Verify(); | 2404 virtual void Verify(); |
| 2454 virtual void Print(); | 2405 virtual void Print(); |
| 2455 void ReportStatistics(); | 2406 void ReportStatistics(); |
| 2456 void CollectCodeStatistics(); | 2407 void CollectCodeStatistics(); |
| 2457 #endif | 2408 #endif |
| 2458 // Checks whether an address is in the object area in this space. It | 2409 // Checks whether an address is in the object area in this space. It |
| 2459 // iterates all objects in the space. May be slow. | 2410 // iterates all objects in the space. May be slow. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2567 } | 2518 } |
| 2568 // Must be small, since an iteration is used for lookup. | 2519 // Must be small, since an iteration is used for lookup. |
| 2569 static const int kMaxComments = 64; | 2520 static const int kMaxComments = 64; |
| 2570 }; | 2521 }; |
| 2571 #endif | 2522 #endif |
| 2572 | 2523 |
| 2573 | 2524 |
| 2574 } } // namespace v8::internal | 2525 } } // namespace v8::internal |
| 2575 | 2526 |
| 2576 #endif // V8_SPACES_H_ | 2527 #endif // V8_SPACES_H_ |
| OLD | NEW |