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 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 | 1472 |
1473 // Allocate from available bytes (available -> size). | 1473 // Allocate from available bytes (available -> size). |
1474 void AllocateBytes(intptr_t size_in_bytes) { | 1474 void AllocateBytes(intptr_t size_in_bytes) { |
1475 size_ += size_in_bytes; | 1475 size_ += size_in_bytes; |
1476 DCHECK(size_ >= 0); | 1476 DCHECK(size_ >= 0); |
1477 } | 1477 } |
1478 | 1478 |
1479 // Free allocated bytes, making them available (size -> available). | 1479 // Free allocated bytes, making them available (size -> available). |
1480 void DeallocateBytes(intptr_t size_in_bytes) { | 1480 void DeallocateBytes(intptr_t size_in_bytes) { |
1481 size_ -= size_in_bytes; | 1481 size_ -= size_in_bytes; |
1482 DCHECK(size_ >= 0); | 1482 DCHECK_GE(size_, 0); |
1483 } | 1483 } |
1484 | 1484 |
1485 // Merge {other} into {this}. | 1485 // Merge {other} into {this}. |
1486 void Merge(const AllocationStats& other) { | 1486 void Merge(const AllocationStats& other) { |
1487 capacity_ += other.capacity_; | 1487 capacity_ += other.capacity_; |
1488 size_ += other.size_; | 1488 size_ += other.size_; |
1489 if (other.max_capacity_ > max_capacity_) { | 1489 if (other.max_capacity_ > max_capacity_) { |
1490 max_capacity_ = other.max_capacity_; | 1490 max_capacity_ = other.max_capacity_; |
1491 } | 1491 } |
1492 } | 1492 } |
1493 | 1493 |
1494 void DecreaseCapacity(intptr_t size_in_bytes) { | 1494 void DecreaseCapacity(intptr_t size_in_bytes) { |
1495 capacity_ -= size_in_bytes; | 1495 capacity_ -= size_in_bytes; |
1496 DCHECK_GE(capacity_, 0); | 1496 DCHECK_GE(capacity_, 0); |
| 1497 DCHECK_GE(capacity_, size_); |
1497 } | 1498 } |
1498 | 1499 |
1499 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } | 1500 void IncreaseCapacity(intptr_t size_in_bytes) { capacity_ += size_in_bytes; } |
1500 | 1501 |
1501 private: | 1502 private: |
1502 // |capacity_|: The number of object-area bytes (i.e., not including page | 1503 // |capacity_|: The number of object-area bytes (i.e., not including page |
1503 // bookkeeping structures) currently in the space. | 1504 // bookkeeping structures) currently in the space. |
1504 intptr_t capacity_; | 1505 intptr_t capacity_; |
1505 | 1506 |
1506 // |max_capacity_|: The maximum capacity ever observed. | 1507 // |max_capacity_|: The maximum capacity ever observed. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 // spaces are called medium. | 1591 // spaces are called medium. |
1591 // 1048-16383 words: There is a list of spaces this large. It is used for top | 1592 // 1048-16383 words: There is a list of spaces this large. It is used for top |
1592 // and limit when the object we need to allocate is 256-2047 words in size. | 1593 // and limit when the object we need to allocate is 256-2047 words in size. |
1593 // These spaces are call large. | 1594 // These spaces are call large. |
1594 // At least 16384 words. This list is for objects of 2048 words or larger. | 1595 // At least 16384 words. This list is for objects of 2048 words or larger. |
1595 // Empty pages are added to this list. These spaces are called huge. | 1596 // Empty pages are added to this list. These spaces are called huge. |
1596 class FreeList { | 1597 class FreeList { |
1597 public: | 1598 public: |
1598 explicit FreeList(PagedSpace* owner); | 1599 explicit FreeList(PagedSpace* owner); |
1599 | 1600 |
| 1601 // The method concatenates {other} into {this} and returns the added bytes, |
| 1602 // including waste. |
| 1603 // |
| 1604 // Can be used concurrently. |
1600 intptr_t Concatenate(FreeList* other); | 1605 intptr_t Concatenate(FreeList* other); |
1601 | 1606 |
1602 // Clear the free list. | 1607 // Clear the free list. |
1603 void Reset(); | 1608 void Reset(); |
1604 | 1609 |
1605 void ResetStats() { wasted_bytes_ = 0; } | 1610 void ResetStats() { wasted_bytes_ = 0; } |
1606 | 1611 |
1607 // Return the number of bytes available on the free list. | 1612 // Return the number of bytes available on the free list. |
1608 intptr_t available() { | 1613 intptr_t available() { |
1609 return small_list_.available() + medium_list_.available() + | 1614 return small_list_.available() + medium_list_.available() + |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 static void ResetCodeStatistics(Isolate* isolate); | 1920 static void ResetCodeStatistics(Isolate* isolate); |
1916 #endif | 1921 #endif |
1917 | 1922 |
1918 // Evacuation candidates are swept by evacuator. Needs to return a valid | 1923 // Evacuation candidates are swept by evacuator. Needs to return a valid |
1919 // result before _and_ after evacuation has finished. | 1924 // result before _and_ after evacuation has finished. |
1920 static bool ShouldBeSweptBySweeperThreads(Page* p) { | 1925 static bool ShouldBeSweptBySweeperThreads(Page* p) { |
1921 return !p->IsEvacuationCandidate() && | 1926 return !p->IsEvacuationCandidate() && |
1922 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); | 1927 !p->IsFlagSet(Page::RESCAN_ON_EVACUATION) && !p->WasSwept(); |
1923 } | 1928 } |
1924 | 1929 |
1925 void IncrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ += by; } | |
1926 | |
1927 void IncreaseUnsweptFreeBytes(Page* p) { | |
1928 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
1929 unswept_free_bytes_ += (p->area_size() - p->LiveBytes()); | |
1930 } | |
1931 | |
1932 void DecrementUnsweptFreeBytes(intptr_t by) { unswept_free_bytes_ -= by; } | |
1933 | |
1934 void DecreaseUnsweptFreeBytes(Page* p) { | |
1935 DCHECK(ShouldBeSweptBySweeperThreads(p)); | |
1936 unswept_free_bytes_ -= (p->area_size() - p->LiveBytes()); | |
1937 } | |
1938 | |
1939 void ResetUnsweptFreeBytes() { unswept_free_bytes_ = 0; } | |
1940 | |
1941 // This function tries to steal size_in_bytes memory from the sweeper threads | 1930 // This function tries to steal size_in_bytes memory from the sweeper threads |
1942 // free-lists. If it does not succeed stealing enough memory, it will wait | 1931 // free-lists. If it does not succeed stealing enough memory, it will wait |
1943 // for the sweeper threads to finish sweeping. | 1932 // for the sweeper threads to finish sweeping. |
1944 // It returns true when sweeping is completed and false otherwise. | 1933 // It returns true when sweeping is completed and false otherwise. |
1945 bool EnsureSweeperProgress(intptr_t size_in_bytes); | 1934 bool EnsureSweeperProgress(intptr_t size_in_bytes); |
1946 | 1935 |
1947 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } | 1936 void set_end_of_unswept_pages(Page* page) { end_of_unswept_pages_ = page; } |
1948 | 1937 |
1949 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } | 1938 Page* end_of_unswept_pages() { return end_of_unswept_pages_; } |
1950 | 1939 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 | 2002 |
2014 // The dummy page that anchors the double linked list of pages. | 2003 // The dummy page that anchors the double linked list of pages. |
2015 Page anchor_; | 2004 Page anchor_; |
2016 | 2005 |
2017 // The space's free list. | 2006 // The space's free list. |
2018 FreeList free_list_; | 2007 FreeList free_list_; |
2019 | 2008 |
2020 // Normal allocation information. | 2009 // Normal allocation information. |
2021 AllocationInfo allocation_info_; | 2010 AllocationInfo allocation_info_; |
2022 | 2011 |
2023 // The number of free bytes which could be reclaimed by advancing the | |
2024 // concurrent sweeper threads. | |
2025 intptr_t unswept_free_bytes_; | |
2026 | |
2027 // The sweeper threads iterate over the list of pointer and data space pages | 2012 // The sweeper threads iterate over the list of pointer and data space pages |
2028 // and sweep these pages concurrently. They will stop sweeping after the | 2013 // and sweep these pages concurrently. They will stop sweeping after the |
2029 // end_of_unswept_pages_ page. | 2014 // end_of_unswept_pages_ page. |
2030 Page* end_of_unswept_pages_; | 2015 Page* end_of_unswept_pages_; |
2031 | 2016 |
2032 // Mutex guarding any concurrent access to the space. | 2017 // Mutex guarding any concurrent access to the space. |
2033 base::Mutex space_mutex_; | 2018 base::Mutex space_mutex_; |
2034 | 2019 |
2035 friend class MarkCompactCollector; | 2020 friend class MarkCompactCollector; |
2036 friend class PageIterator; | 2021 friend class PageIterator; |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2954 count = 0; | 2939 count = 0; |
2955 } | 2940 } |
2956 // Must be small, since an iteration is used for lookup. | 2941 // Must be small, since an iteration is used for lookup. |
2957 static const int kMaxComments = 64; | 2942 static const int kMaxComments = 64; |
2958 }; | 2943 }; |
2959 #endif | 2944 #endif |
2960 } // namespace internal | 2945 } // namespace internal |
2961 } // namespace v8 | 2946 } // namespace v8 |
2962 | 2947 |
2963 #endif // V8_HEAP_SPACES_H_ | 2948 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |