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