OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 | 1523 |
1524 // Allocate from available bytes (available -> size). | 1524 // Allocate from available bytes (available -> size). |
1525 void AllocateBytes(intptr_t size_in_bytes) { | 1525 void AllocateBytes(intptr_t size_in_bytes) { |
1526 size_ += size_in_bytes; | 1526 size_ += size_in_bytes; |
1527 DCHECK(size_ >= 0); | 1527 DCHECK(size_ >= 0); |
1528 } | 1528 } |
1529 | 1529 |
1530 // Free allocated bytes, making them available (size -> available). | 1530 // Free allocated bytes, making them available (size -> available). |
1531 void DeallocateBytes(intptr_t size_in_bytes) { | 1531 void DeallocateBytes(intptr_t size_in_bytes) { |
1532 size_ -= size_in_bytes; | 1532 size_ -= size_in_bytes; |
1533 DCHECK(size_ >= 0); | 1533 DCHECK_GE(size_, 0); |
1534 } | 1534 } |
1535 | 1535 |
1536 // Merge {other} into {this}. | 1536 // Merge {other} into {this}. |
1537 void Merge(const AllocationStats& other) { | 1537 void Merge(const AllocationStats& other) { |
1538 capacity_ += other.capacity_; | 1538 capacity_ += other.capacity_; |
1539 size_ += other.size_; | 1539 size_ += other.size_; |
1540 if (other.max_capacity_ > max_capacity_) { | 1540 if (other.max_capacity_ > max_capacity_) { |
1541 max_capacity_ = other.max_capacity_; | 1541 max_capacity_ = other.max_capacity_; |
1542 } | 1542 } |
1543 } | 1543 } |
1544 | 1544 |
1545 void DecreaseCapacity(intptr_t size_in_bytes) { | 1545 void DecreaseCapacity(intptr_t size_in_bytes) { |
1546 capacity_ -= size_in_bytes; | 1546 capacity_ -= size_in_bytes; |
1547 DCHECK_GE(capacity_, 0); | 1547 DCHECK_GE(capacity_, 0); |
| 1548 DCHECK_GE(capacity_, size_); |
1548 } | 1549 } |
1549 | 1550 |
1550 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } | 1551 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } |
1551 | 1552 |
1552 private: | 1553 private: |
1553 // |capacity_|: The number of object-area bytes (i.e., not including page | 1554 // |capacity_|: The number of object-area bytes (i.e., not including page |
1554 // bookkeeping structures) currently in the space. | 1555 // bookkeeping structures) currently in the space. |
1555 intptr_t capacity_; | 1556 intptr_t capacity_; |
1556 | 1557 |
1557 // |max_capacity_|: The maximum capacity ever observed. | 1558 // |max_capacity_|: The maximum capacity ever observed. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 // spaces are called medium. | 1653 // spaces are called medium. |
1653 // 1048-16383 words: There is a list of spaces this large. It is used for top | 1654 // 1048-16383 words: There is a list of spaces this large. It is used for top |
1654 // and limit when the object we need to allocate is 256-2047 words in size. | 1655 // and limit when the object we need to allocate is 256-2047 words in size. |
1655 // These spaces are call large. | 1656 // These spaces are call large. |
1656 // At least 16384 words. This list is for objects of 2048 words or larger. | 1657 // At least 16384 words. This list is for objects of 2048 words or larger. |
1657 // Empty pages are added to this list. These spaces are called huge. | 1658 // Empty pages are added to this list. These spaces are called huge. |
1658 class FreeList { | 1659 class FreeList { |
1659 public: | 1660 public: |
1660 explicit FreeList(PagedSpace* owner); | 1661 explicit FreeList(PagedSpace* owner); |
1661 | 1662 |
| 1663 // The method concatenates {other} into {this} and returns the added bytes, |
| 1664 // including waste. |
| 1665 // |
| 1666 // Can be used concurrently. |
1662 intptr_t Concatenate(FreeList* other); | 1667 intptr_t Concatenate(FreeList* other); |
1663 | 1668 |
1664 // Clear the free list. | 1669 // Clear the free list. |
1665 void Reset(); | 1670 void Reset(); |
1666 | 1671 |
1667 void ResetStats() { wasted_bytes_ = 0; } | 1672 void ResetStats() { wasted_bytes_ = 0; } |
1668 | 1673 |
1669 // Return the number of bytes available on the free list. | 1674 // Return the number of bytes available on the free list. |
1670 intptr_t available() { | 1675 intptr_t available() { |
1671 return small_list_.available() + medium_list_.available() + | 1676 return small_list_.available() + medium_list_.available() + |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 static void ResetCodeStatistics(Isolate* isolate); | 1975 static void ResetCodeStatistics(Isolate* isolate); |
1971 #endif | 1976 #endif |
1972 | 1977 |
1973 // Evacuation candidates are swept by evacuator. Needs to return a valid | 1978 // Evacuation candidates are swept by evacuator. Needs to return a valid |
1974 // result before _and_ after evacuation has finished. | 1979 // result before _and_ after evacuation has finished. |
1975 static bool ShouldBeSweptBySweeperThreads(Page* p) { | 1980 static bool ShouldBeSweptBySweeperThreads(Page* p) { |
1976 return !p->IsEvacuationCandidate() && | 1981 return !p->IsEvacuationCandidate() && |
1977 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); | 1982 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); |
1978 } | 1983 } |
1979 | 1984 |
1980 void IncrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ += by; } | |
1981 | |
1982 void IncreaseUnsweptFreeBytes(Page* p) { | |
1983 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
1984 unswept_free_bytes_ += (p->area_size() - p->LiveBytes()); | |
1985 } | |
1986 | |
1987 void DecrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ -= by; } | |
1988 | |
1989 void DecreaseUnsweptFreeBytes(Page* p) { | |
1990 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
1991 unswept_free_bytes_ -= (p->area_size() - p->LiveBytes()); | |
1992 } | |
1993 | |
1994 void ResetUnsweptFreeBytes() { unswept_free_bytes_ = 0; } | |
1995 | |
1996 // This function tries to steal size_in_bytes memory from the sweeper threads | 1985 // This function tries to steal size_in_bytes memory from the sweeper threads |
1997 // free-lists. If it does not succeed stealing enough memory, it will wait | 1986 // free-lists. If it does not succeed stealing enough memory, it will wait |
1998 // for the sweeper threads to finish sweeping. | 1987 // for the sweeper threads to finish sweeping. |
1999 // It returns true when sweeping is completed and false otherwise. | 1988 // It returns true when sweeping is completed and false otherwise. |
2000 bool EnsureSweeperProgress(intptr_t size_in_bytes); | 1989 bool EnsureSweeperProgress(intptr_t size_in_bytes); |
2001 | 1990 |
2002 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } | 1991 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } |
2003 | 1992 |
2004 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } | 1993 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } |
2005 | 1994 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 | 2057 |
2069 // The dummy page that anchors the double linked list of pages. | 2058 // The dummy page that anchors the double linked list of pages. |
2070 Page anchor_; | 2059 Page anchor_; |
2071 | 2060 |
2072 // The space's free list. | 2061 // The space's free list. |
2073 FreeList free_list_; | 2062 FreeList free_list_; |
2074 | 2063 |
2075 // Normal allocation information. | 2064 // Normal allocation information. |
2076 AllocationInfo allocation_info_; | 2065 AllocationInfo allocation_info_; |
2077 | 2066 |
2078 // The number of free bytes which could be reclaimed by advancing the | |
2079 // concurrent sweeper threads. | |
2080 intptr_t unswept_free_bytes_; | |
2081 | |
2082 // The sweeper threads iterate over the list of pointer and data space pages | 2067 // The sweeper threads iterate over the list of pointer and data space pages |
2083 // and sweep these pages concurrently. They will stop sweeping after the | 2068 // and sweep these pages concurrently. They will stop sweeping after the |
2084 // end_of_unswept_pages_ page. | 2069 // end_of_unswept_pages_ page. |
2085 Page* end_of_unswept_pages_; | 2070 Page* end_of_unswept_pages_; |
2086 | 2071 |
2087 // Mutex guarding any concurrent access to the space. | 2072 // Mutex guarding any concurrent access to the space. |
2088 base::Mutex space_mutex_; | 2073 base::Mutex space_mutex_; |
2089 | 2074 |
2090 friend class MarkCompactCollector; | 2075 friend class MarkCompactCollector; |
2091 friend class PageIterator; | 2076 friend class PageIterator; |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2993 count = 0; | 2978 count = 0; |
2994 } | 2979 } |
2995 // Must be small, since an iteration is used for lookup. | 2980 // Must be small, since an iteration is used for lookup. |
2996 static const int kMaxComments = 64; | 2981 static const int kMaxComments = 64; |
2997 }; | 2982 }; |
2998 #endif | 2983 #endif |
2999 } // namespace internal | 2984 } // namespace internal |
3000 } // namespace v8 | 2985 } // namespace v8 |
3001 | 2986 |
3002 #endif // V8_HEAP_SPACES_H_ | 2987 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |