| 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 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 | 1494 |
| 1495 // Allocate from available bytes (available -> size). | 1495 // Allocate from available bytes (available -> size). |
| 1496 void AllocateBytes(intptr_t size_in_bytes) { | 1496 void AllocateBytes(intptr_t size_in_bytes) { |
| 1497 size_ += size_in_bytes; | 1497 size_ += size_in_bytes; |
| 1498 DCHECK(size_ >= 0); | 1498 DCHECK(size_ >= 0); |
| 1499 } | 1499 } |
| 1500 | 1500 |
| 1501 // Free allocated bytes, making them available (size -> available). | 1501 // Free allocated bytes, making them available (size -> available). |
| 1502 void DeallocateBytes(intptr_t size_in_bytes) { | 1502 void DeallocateBytes(intptr_t size_in_bytes) { |
| 1503 size_ -= size_in_bytes; | 1503 size_ -= size_in_bytes; |
| 1504 DCHECK(size_ >= 0); | 1504 DCHECK_GE(size_, 0); |
| 1505 } | 1505 } |
| 1506 | 1506 |
| 1507 // Merge {other} into {this}. | 1507 // Merge {other} into {this}. |
| 1508 void Merge(const AllocationStats& other) { | 1508 void Merge(const AllocationStats& other) { |
| 1509 capacity_ += other.capacity_; | 1509 capacity_ += other.capacity_; |
| 1510 size_ += other.size_; | 1510 size_ += other.size_; |
| 1511 if (other.max_capacity_ > max_capacity_) { | 1511 if (other.max_capacity_ > max_capacity_) { |
| 1512 max_capacity_ = other.max_capacity_; | 1512 max_capacity_ = other.max_capacity_; |
| 1513 } | 1513 } |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 void DecreaseCapacity(intptr_t size_in_bytes) { | 1516 void DecreaseCapacity(intptr_t size_in_bytes) { |
| 1517 capacity_ -= size_in_bytes; | 1517 capacity_ -= size_in_bytes; |
| 1518 DCHECK_GE(capacity_, 0); | 1518 DCHECK_GE(capacity_, 0); |
| 1519 DCHECK_GE(capacity_, size_); |
| 1519 } | 1520 } |
| 1520 | 1521 |
| 1521 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } | 1522 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } |
| 1522 | 1523 |
| 1523 private: | 1524 private: |
| 1524 // |capacity_|: The number of object-area bytes (i.e., not including page | 1525 // |capacity_|: The number of object-area bytes (i.e., not including page |
| 1525 // bookkeeping structures) currently in the space. | 1526 // bookkeeping structures) currently in the space. |
| 1526 intptr_t capacity_; | 1527 intptr_t capacity_; |
| 1527 | 1528 |
| 1528 // |max_capacity_|: The maximum capacity ever observed. | 1529 // |max_capacity_|: The maximum capacity ever observed. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 // spaces are called medium. | 1624 // spaces are called medium. |
| 1624 // 1048-16383 words: There is a list of spaces this large. It is used for top | 1625 // 1048-16383 words: There is a list of spaces this large. It is used for top |
| 1625 // and limit when the object we need to allocate is 256-2047 words in size. | 1626 // and limit when the object we need to allocate is 256-2047 words in size. |
| 1626 // These spaces are call large. | 1627 // These spaces are call large. |
| 1627 // At least 16384 words. This list is for objects of 2048 words or larger. | 1628 // At least 16384 words. This list is for objects of 2048 words or larger. |
| 1628 // Empty pages are added to this list. These spaces are called huge. | 1629 // Empty pages are added to this list. These spaces are called huge. |
| 1629 class FreeList { | 1630 class FreeList { |
| 1630 public: | 1631 public: |
| 1631 explicit FreeList(PagedSpace* owner); | 1632 explicit FreeList(PagedSpace* owner); |
| 1632 | 1633 |
| 1634 // The method concatenates {other} into {this} and returns the added bytes, |
| 1635 // including waste. |
| 1636 // |
| 1637 // Can be used concurrently. |
| 1633 intptr_t Concatenate(FreeList* other); | 1638 intptr_t Concatenate(FreeList* other); |
| 1634 | 1639 |
| 1635 // Clear the free list. | 1640 // Clear the free list. |
| 1636 void Reset(); | 1641 void Reset(); |
| 1637 | 1642 |
| 1638 void ResetStats() { wasted_bytes_ = 0; } | 1643 void ResetStats() { wasted_bytes_ = 0; } |
| 1639 | 1644 |
| 1640 // Return the number of bytes available on the free list. | 1645 // Return the number of bytes available on the free list. |
| 1641 intptr_t available() { | 1646 intptr_t available() { |
| 1642 return small_list_.available() + medium_list_.available() + | 1647 return small_list_.available() + medium_list_.available() + |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 static void ResetCodeStatistics(Isolate* isolate); | 1953 static void ResetCodeStatistics(Isolate* isolate); |
| 1949 #endif | 1954 #endif |
| 1950 | 1955 |
| 1951 // Evacuation candidates are swept by evacuator. Needs to return a valid | 1956 // Evacuation candidates are swept by evacuator. Needs to return a valid |
| 1952 // result before _and_ after evacuation has finished. | 1957 // result before _and_ after evacuation has finished. |
| 1953 static bool ShouldBeSweptBySweeperThreads(Page* p) { | 1958 static bool ShouldBeSweptBySweeperThreads(Page* p) { |
| 1954 return !p->IsEvacuationCandidate() && | 1959 return !p->IsEvacuationCandidate() && |
| 1955 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); | 1960 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); |
| 1956 } | 1961 } |
| 1957 | 1962 |
| 1958 void IncrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ += by; } | |
| 1959 | |
| 1960 void IncreaseUnsweptFreeBytes(Page* p) { | |
| 1961 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
| 1962 unswept_free_bytes_ += (p->area_size() - p->LiveBytes()); | |
| 1963 } | |
| 1964 | |
| 1965 void DecrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ -= by; } | |
| 1966 | |
| 1967 void DecreaseUnsweptFreeBytes(Page* p) { | |
| 1968 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
| 1969 unswept_free_bytes_ -= (p->area_size() - p->LiveBytes()); | |
| 1970 } | |
| 1971 | |
| 1972 void ResetUnsweptFreeBytes() { unswept_free_bytes_ = 0; } | |
| 1973 | |
| 1974 // This function tries to steal size_in_bytes memory from the sweeper threads | 1963 // This function tries to steal size_in_bytes memory from the sweeper threads |
| 1975 // free-lists. If it does not succeed stealing enough memory, it will wait | 1964 // free-lists. If it does not succeed stealing enough memory, it will wait |
| 1976 // for the sweeper threads to finish sweeping. | 1965 // for the sweeper threads to finish sweeping. |
| 1977 // It returns true when sweeping is completed and false otherwise. | 1966 // It returns true when sweeping is completed and false otherwise. |
| 1978 bool EnsureSweeperProgress(intptr_t size_in_bytes); | 1967 bool EnsureSweeperProgress(intptr_t size_in_bytes); |
| 1979 | 1968 |
| 1980 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } | 1969 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } |
| 1981 | 1970 |
| 1982 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } | 1971 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } |
| 1983 | 1972 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 | 2035 |
| 2047 // The dummy page that anchors the double linked list of pages. | 2036 // The dummy page that anchors the double linked list of pages. |
| 2048 Page anchor_; | 2037 Page anchor_; |
| 2049 | 2038 |
| 2050 // The space's free list. | 2039 // The space's free list. |
| 2051 FreeList free_list_; | 2040 FreeList free_list_; |
| 2052 | 2041 |
| 2053 // Normal allocation information. | 2042 // Normal allocation information. |
| 2054 AllocationInfo allocation_info_; | 2043 AllocationInfo allocation_info_; |
| 2055 | 2044 |
| 2056 // The number of free bytes which could be reclaimed by advancing the | |
| 2057 // concurrent sweeper threads. | |
| 2058 intptr_t unswept_free_bytes_; | |
| 2059 | |
| 2060 // The sweeper threads iterate over the list of pointer and data space pages | 2045 // The sweeper threads iterate over the list of pointer and data space pages |
| 2061 // and sweep these pages concurrently. They will stop sweeping after the | 2046 // and sweep these pages concurrently. They will stop sweeping after the |
| 2062 // end_of_unswept_pages_ page. | 2047 // end_of_unswept_pages_ page. |
| 2063 Page* end_of_unswept_pages_; | 2048 Page* end_of_unswept_pages_; |
| 2064 | 2049 |
| 2065 // Mutex guarding any concurrent access to the space. | 2050 // Mutex guarding any concurrent access to the space. |
| 2066 base::Mutex space_mutex_; | 2051 base::Mutex space_mutex_; |
| 2067 | 2052 |
| 2068 friend class MarkCompactCollector; | 2053 friend class MarkCompactCollector; |
| 2069 friend class PageIterator; | 2054 friend class PageIterator; |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2987 count = 0; | 2972 count = 0; |
| 2988 } | 2973 } |
| 2989 // Must be small, since an iteration is used for lookup. | 2974 // Must be small, since an iteration is used for lookup. |
| 2990 static const int kMaxComments = 64; | 2975 static const int kMaxComments = 64; |
| 2991 }; | 2976 }; |
| 2992 #endif | 2977 #endif |
| 2993 } // namespace internal | 2978 } // namespace internal |
| 2994 } // namespace v8 | 2979 } // namespace v8 |
| 2995 | 2980 |
| 2996 #endif // V8_HEAP_SPACES_H_ | 2981 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |