| 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 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 inline void set_prev_page(NewSpacePage* page) { | 1522 inline void set_prev_page(NewSpacePage* page) { |
| 1523 set_prev_chunk(page); | 1523 set_prev_chunk(page); |
| 1524 } | 1524 } |
| 1525 | 1525 |
| 1526 SemiSpace* semi_space() { | 1526 SemiSpace* semi_space() { |
| 1527 return reinterpret_cast<SemiSpace*>(owner()); | 1527 return reinterpret_cast<SemiSpace*>(owner()); |
| 1528 } | 1528 } |
| 1529 | 1529 |
| 1530 bool is_anchor() { return !this->InNewSpace(); } | 1530 bool is_anchor() { return !this->InNewSpace(); } |
| 1531 | 1531 |
| 1532 static bool IsAtStart(Address addr) { |
| 1533 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) |
| 1534 == kObjectStartOffset; |
| 1535 } |
| 1536 |
| 1537 static bool IsAtEnd(Address addr) { |
| 1538 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) == 0; |
| 1539 } |
| 1540 |
| 1532 // Finds the NewSpacePage containg the given address. | 1541 // Finds the NewSpacePage containg the given address. |
| 1533 static inline NewSpacePage* FromAddress(Address address_in_page) { | 1542 static inline NewSpacePage* FromAddress(Address address_in_page) { |
| 1534 Address page_start = | 1543 Address page_start = |
| 1535 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & | 1544 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & |
| 1536 ~Page::kPageAlignmentMask); | 1545 ~Page::kPageAlignmentMask); |
| 1537 NewSpacePage* page = reinterpret_cast<NewSpacePage*>(page_start); | 1546 NewSpacePage* page = reinterpret_cast<NewSpacePage*>(page_start); |
| 1538 ASSERT(page->InNewSpace()); | 1547 ASSERT(page->InNewSpace()); |
| 1539 return page; | 1548 return page; |
| 1540 } | 1549 } |
| 1541 | 1550 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 return anchor_.prev_page()->body_limit(); | 1635 return anchor_.prev_page()->body_limit(); |
| 1627 } | 1636 } |
| 1628 | 1637 |
| 1629 // Returns one past the end address of the current page of the space. | 1638 // Returns one past the end address of the current page of the space. |
| 1630 Address page_high() { | 1639 Address page_high() { |
| 1631 return current_page_->body_limit(); | 1640 return current_page_->body_limit(); |
| 1632 } | 1641 } |
| 1633 | 1642 |
| 1634 bool AdvancePage() { | 1643 bool AdvancePage() { |
| 1635 NewSpacePage* next_page = current_page_->next_page(); | 1644 NewSpacePage* next_page = current_page_->next_page(); |
| 1636 if (next_page == &anchor_) return false; | 1645 if (next_page == anchor()) return false; |
| 1637 current_page_ = next_page; | 1646 current_page_ = next_page; |
| 1638 return true; | 1647 return true; |
| 1639 } | 1648 } |
| 1640 | 1649 |
| 1641 // Resets the space to using the first page. | 1650 // Resets the space to using the first page. |
| 1642 void Reset(); | 1651 void Reset(); |
| 1643 | 1652 |
| 1644 // Age mark accessors. | 1653 // Age mark accessors. |
| 1645 Address age_mark() { return age_mark_; } | 1654 Address age_mark() { return age_mark_; } |
| 1646 void set_age_mark(Address mark); | 1655 void set_age_mark(Address mark); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1666 | 1675 |
| 1667 #ifdef ENABLE_HEAP_PROTECTION | 1676 #ifdef ENABLE_HEAP_PROTECTION |
| 1668 // Protect/unprotect the space by marking it read-only/writable. | 1677 // Protect/unprotect the space by marking it read-only/writable. |
| 1669 virtual void Protect() {} | 1678 virtual void Protect() {} |
| 1670 virtual void Unprotect() {} | 1679 virtual void Unprotect() {} |
| 1671 #endif | 1680 #endif |
| 1672 | 1681 |
| 1673 #ifdef DEBUG | 1682 #ifdef DEBUG |
| 1674 virtual void Print(); | 1683 virtual void Print(); |
| 1675 virtual void Verify(); | 1684 virtual void Verify(); |
| 1676 static void ValidateRange(Address from, Address to); | 1685 // Validate a range of of addresses in a SemiSpace. |
| 1686 // The "from" address must be on a page prior to the "to" address, |
| 1687 // in the linked page order, or it must be earlier on the same page. |
| 1688 static void AssertValidRange(Address from, Address to); |
| 1689 #else |
| 1690 // Do nothing. |
| 1691 inline static void AssertValidRange(Address from, Address to) {} |
| 1677 #endif | 1692 #endif |
| 1678 | 1693 |
| 1679 // Returns the current capacity of the semi space. | 1694 // Returns the current capacity of the semi space. |
| 1680 int Capacity() { return capacity_; } | 1695 int Capacity() { return capacity_; } |
| 1681 | 1696 |
| 1682 // Returns the maximum capacity of the semi space. | 1697 // Returns the maximum capacity of the semi space. |
| 1683 int MaximumCapacity() { return maximum_capacity_; } | 1698 int MaximumCapacity() { return maximum_capacity_; } |
| 1684 | 1699 |
| 1685 // Returns the initial capacity of the semi space. | 1700 // Returns the initial capacity of the semi space. |
| 1686 int InitialCapacity() { return initial_capacity_; } | 1701 int InitialCapacity() { return initial_capacity_; } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 // Iterate over all of allocated to-space, with a custome size function. | 1755 // Iterate over all of allocated to-space, with a custome size function. |
| 1741 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); | 1756 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); |
| 1742 // Iterate over part of allocated to-space, from start to the end | 1757 // Iterate over part of allocated to-space, from start to the end |
| 1743 // of allocation. | 1758 // of allocation. |
| 1744 SemiSpaceIterator(NewSpace* space, Address start); | 1759 SemiSpaceIterator(NewSpace* space, Address start); |
| 1745 // Iterate from one address to another in the same semi-space. | 1760 // Iterate from one address to another in the same semi-space. |
| 1746 SemiSpaceIterator(Address from, Address to); | 1761 SemiSpaceIterator(Address from, Address to); |
| 1747 | 1762 |
| 1748 HeapObject* Next() { | 1763 HeapObject* Next() { |
| 1749 if (current_ == limit_) return NULL; | 1764 if (current_ == limit_) return NULL; |
| 1750 if (current_ == current_page_limit_) { | 1765 if (NewSpacePage::IsAtEnd(current_)) { |
| 1751 NewSpacePage* page = NewSpacePage::FromAddress(current_ - 1); | 1766 NewSpacePage* page = NewSpacePage::FromLimit(current_); |
| 1752 page = page->next_page(); | 1767 page = page->next_page(); |
| 1753 ASSERT(!page->is_anchor()); | 1768 ASSERT(!page->is_anchor()); |
| 1754 current_ = page->body(); | 1769 current_ = page->body(); |
| 1755 if (current_ == limit_) return NULL; | 1770 if (current_ == limit_) return NULL; |
| 1756 } | 1771 } |
| 1757 | 1772 |
| 1758 HeapObject* object = HeapObject::FromAddress(current_); | 1773 HeapObject* object = HeapObject::FromAddress(current_); |
| 1759 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); | 1774 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); |
| 1760 | 1775 |
| 1761 current_ += size; | 1776 current_ += size; |
| 1762 return object; | 1777 return object; |
| 1763 } | 1778 } |
| 1764 | 1779 |
| 1765 // Implementation of the ObjectIterator functions. | 1780 // Implementation of the ObjectIterator functions. |
| 1766 virtual HeapObject* next_object() { return Next(); } | 1781 virtual HeapObject* next_object() { return Next(); } |
| 1767 | 1782 |
| 1768 private: | 1783 private: |
| 1769 void Initialize(Address start, | 1784 void Initialize(Address start, |
| 1770 Address end, | 1785 Address end, |
| 1771 HeapObjectCallback size_func); | 1786 HeapObjectCallback size_func); |
| 1772 | 1787 |
| 1773 // The current iteration point. | 1788 // The current iteration point. |
| 1774 Address current_; | 1789 Address current_; |
| 1775 // The end of the current page. | |
| 1776 Address current_page_limit_; | |
| 1777 // The end of iteration. | 1790 // The end of iteration. |
| 1778 Address limit_; | 1791 Address limit_; |
| 1779 // The callback function. | 1792 // The callback function. |
| 1780 HeapObjectCallback size_func_; | 1793 HeapObjectCallback size_func_; |
| 1781 }; | 1794 }; |
| 1782 | 1795 |
| 1783 | 1796 |
| 1784 // ----------------------------------------------------------------------------- | 1797 // ----------------------------------------------------------------------------- |
| 1785 // A PageIterator iterates the pages in a semi-space. | 1798 // A PageIterator iterates the pages in a semi-space. |
| 1786 class NewSpacePageIterator BASE_EMBEDDED { | 1799 class NewSpacePageIterator BASE_EMBEDDED { |
| 1787 public: | 1800 public: |
| 1801 // Make an iterator that runs over all pages in to-space. |
| 1802 explicit inline NewSpacePageIterator(NewSpace* space); |
| 1803 |
| 1788 // Make an iterator that runs over all pages in the given semispace, | 1804 // Make an iterator that runs over all pages in the given semispace, |
| 1789 // even those not used in allocation. | 1805 // even those not used in allocation. |
| 1790 explicit inline NewSpacePageIterator(SemiSpace* space); | 1806 explicit inline NewSpacePageIterator(SemiSpace* space); |
| 1807 |
| 1791 // Make iterator that iterates from the page containing start | 1808 // Make iterator that iterates from the page containing start |
| 1792 // to the page that contains limit in the same semispace. | 1809 // to the page that contains limit in the same semispace. |
| 1793 inline NewSpacePageIterator(Address start, Address limit); | 1810 inline NewSpacePageIterator(Address start, Address limit); |
| 1794 | 1811 |
| 1795 inline bool has_next(); | 1812 inline bool has_next(); |
| 1796 inline NewSpacePage* next(); | 1813 inline NewSpacePage* next(); |
| 1797 | 1814 |
| 1798 private: | 1815 private: |
| 1799 NewSpacePage* prev_page_; // Previous page returned. | 1816 NewSpacePage* prev_page_; // Previous page returned. |
| 1800 // Next page that will be returned. Cached here so that we can use this | 1817 // Next page that will be returned. Cached here so that we can use this |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 Address* allocation_limit_address() { return &allocation_info_.limit; } | 1957 Address* allocation_limit_address() { return &allocation_info_.limit; } |
| 1941 | 1958 |
| 1942 MUST_USE_RESULT MaybeObject* AllocateRaw(int size_in_bytes) { | 1959 MUST_USE_RESULT MaybeObject* AllocateRaw(int size_in_bytes) { |
| 1943 return AllocateRawInternal(size_in_bytes); | 1960 return AllocateRawInternal(size_in_bytes); |
| 1944 } | 1961 } |
| 1945 | 1962 |
| 1946 // Reset the allocation pointer to the beginning of the active semispace. | 1963 // Reset the allocation pointer to the beginning of the active semispace. |
| 1947 void ResetAllocationInfo(); | 1964 void ResetAllocationInfo(); |
| 1948 | 1965 |
| 1949 void LowerInlineAllocationLimit(intptr_t step) { | 1966 void LowerInlineAllocationLimit(intptr_t step) { |
| 1950 inline_alloction_limit_step_ = step; | 1967 inline_allocation_limit_step_ = step; |
| 1951 if (step == 0) { | 1968 if (step == 0) { |
| 1952 allocation_info_.limit = to_space_.page_high(); | 1969 allocation_info_.limit = to_space_.page_high(); |
| 1953 } else { | 1970 } else { |
| 1954 allocation_info_.limit = Min( | 1971 allocation_info_.limit = Min( |
| 1955 allocation_info_.top + inline_alloction_limit_step_, | 1972 allocation_info_.top + inline_allocation_limit_step_, |
| 1956 allocation_info_.limit); | 1973 allocation_info_.limit); |
| 1957 } | 1974 } |
| 1958 top_on_previous_step_ = allocation_info_.top; | 1975 top_on_previous_step_ = allocation_info_.top; |
| 1959 } | 1976 } |
| 1960 | 1977 |
| 1961 // Get the extent of the inactive semispace (for use as a marking stack, | 1978 // Get the extent of the inactive semispace (for use as a marking stack, |
| 1962 // or to zap it). | 1979 // or to zap it). |
| 1963 Address FromSpacePageLow() { return from_space_.page_low(); } | 1980 Address FromSpacePageLow() { return from_space_.page_low(); } |
| 1964 Address FromSpaceLow() { return from_space_.space_low(); } | 1981 Address FromSpaceLow() { return from_space_.space_low(); } |
| 1965 Address FromSpaceHigh() { return from_space_.space_high(); } | 1982 Address FromSpaceHigh() { return from_space_.space_high(); } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 bool CommitFromSpaceIfNeeded() { | 2055 bool CommitFromSpaceIfNeeded() { |
| 2039 if (from_space_.is_committed()) return true; | 2056 if (from_space_.is_committed()) return true; |
| 2040 return from_space_.Commit(); | 2057 return from_space_.Commit(); |
| 2041 } | 2058 } |
| 2042 | 2059 |
| 2043 bool UncommitFromSpace() { | 2060 bool UncommitFromSpace() { |
| 2044 if (!from_space_.is_committed()) return true; | 2061 if (!from_space_.is_committed()) return true; |
| 2045 return from_space_.Uncommit(); | 2062 return from_space_.Uncommit(); |
| 2046 } | 2063 } |
| 2047 | 2064 |
| 2048 inline intptr_t inline_alloction_limit_step() { | 2065 inline intptr_t inline_allocation_limit_step() { |
| 2049 return inline_alloction_limit_step_; | 2066 return inline_allocation_limit_step_; |
| 2050 } | 2067 } |
| 2051 | 2068 |
| 2052 NewSpacePage* ActivePage() { | 2069 SemiSpace* active_space() { return &to_space_; } |
| 2053 return to_space_.current_page(); | |
| 2054 } | |
| 2055 | |
| 2056 NewSpacePage* InactivePage() { | |
| 2057 return from_space_.current_page(); | |
| 2058 } | |
| 2059 | 2070 |
| 2060 private: | 2071 private: |
| 2061 // Update allocation info to match the current to-space page. | 2072 // Update allocation info to match the current to-space page. |
| 2062 void UpdateAllocationInfo(); | 2073 void UpdateAllocationInfo(); |
| 2063 | 2074 |
| 2064 Address chunk_base_; | 2075 Address chunk_base_; |
| 2065 uintptr_t chunk_size_; | 2076 uintptr_t chunk_size_; |
| 2066 | 2077 |
| 2067 // The semispaces. | 2078 // The semispaces. |
| 2068 SemiSpace to_space_; | 2079 SemiSpace to_space_; |
| 2069 SemiSpace from_space_; | 2080 SemiSpace from_space_; |
| 2070 | 2081 |
| 2071 // Start address and bit mask for containment testing. | 2082 // Start address and bit mask for containment testing. |
| 2072 Address start_; | 2083 Address start_; |
| 2073 uintptr_t address_mask_; | 2084 uintptr_t address_mask_; |
| 2074 uintptr_t object_mask_; | 2085 uintptr_t object_mask_; |
| 2075 uintptr_t object_expected_; | 2086 uintptr_t object_expected_; |
| 2076 | 2087 |
| 2077 // Allocation pointer and limit for normal allocation and allocation during | 2088 // Allocation pointer and limit for normal allocation and allocation during |
| 2078 // mark-compact collection. | 2089 // mark-compact collection. |
| 2079 AllocationInfo allocation_info_; | 2090 AllocationInfo allocation_info_; |
| 2080 | 2091 |
| 2081 // When incremental marking is active we will set allocation_info_.limit | 2092 // When incremental marking is active we will set allocation_info_.limit |
| 2082 // to be lower than actual limit and then will gradually increase it | 2093 // to be lower than actual limit and then will gradually increase it |
| 2083 // in steps to guarantee that we do incremental marking steps even | 2094 // in steps to guarantee that we do incremental marking steps even |
| 2084 // when all allocation is performed from inlined generated code. | 2095 // when all allocation is performed from inlined generated code. |
| 2085 intptr_t inline_alloction_limit_step_; | 2096 intptr_t inline_allocation_limit_step_; |
| 2086 | 2097 |
| 2087 Address top_on_previous_step_; | 2098 Address top_on_previous_step_; |
| 2088 | 2099 |
| 2089 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | 2100 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
| 2090 HistogramInfo* allocated_histogram_; | 2101 HistogramInfo* allocated_histogram_; |
| 2091 HistogramInfo* promoted_histogram_; | 2102 HistogramInfo* promoted_histogram_; |
| 2092 #endif | 2103 #endif |
| 2093 | 2104 |
| 2094 // Implementation of AllocateRaw. | 2105 // Implementation of AllocateRaw. |
| 2095 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal(int size_in_bytes); | 2106 MUST_USE_RESULT inline MaybeObject* AllocateRawInternal(int size_in_bytes); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2462 } | 2473 } |
| 2463 // Must be small, since an iteration is used for lookup. | 2474 // Must be small, since an iteration is used for lookup. |
| 2464 static const int kMaxComments = 64; | 2475 static const int kMaxComments = 64; |
| 2465 }; | 2476 }; |
| 2466 #endif | 2477 #endif |
| 2467 | 2478 |
| 2468 | 2479 |
| 2469 } } // namespace v8::internal | 2480 } } // namespace v8::internal |
| 2470 | 2481 |
| 2471 #endif // V8_SPACES_H_ | 2482 #endif // V8_SPACES_H_ |
| OLD | NEW |