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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1346 // functions increase or decrease one of the non-capacity stats in | 1346 // functions increase or decrease one of the non-capacity stats in |
1347 // conjunction with capacity, or else they always balance increases and | 1347 // conjunction with capacity, or else they always balance increases and |
1348 // decreases to the non-capacity stats. | 1348 // decreases to the non-capacity stats. |
1349 class AllocationStats BASE_EMBEDDED { | 1349 class AllocationStats BASE_EMBEDDED { |
1350 public: | 1350 public: |
1351 AllocationStats() { Clear(); } | 1351 AllocationStats() { Clear(); } |
1352 | 1352 |
1353 // Zero out all the allocation statistics (i.e., no capacity). | 1353 // Zero out all the allocation statistics (i.e., no capacity). |
1354 void Clear() { | 1354 void Clear() { |
1355 capacity_ = 0; | 1355 capacity_ = 0; |
1356 max_capacity_ = 0; | |
1356 size_ = 0; | 1357 size_ = 0; |
1357 waste_ = 0; | 1358 waste_ = 0; |
1358 } | 1359 } |
1359 | 1360 |
1360 void ClearSizeWaste() { | 1361 void ClearSizeWaste() { |
1361 size_ = capacity_; | 1362 size_ = capacity_; |
1362 waste_ = 0; | 1363 waste_ = 0; |
1363 } | 1364 } |
1364 | 1365 |
1365 // Reset the allocation statistics (i.e., available = capacity with no | 1366 // Reset the allocation statistics (i.e., available = capacity with no |
1366 // wasted or allocated bytes). | 1367 // wasted or allocated bytes). |
1367 void Reset() { | 1368 void Reset() { |
1368 size_ = 0; | 1369 size_ = 0; |
1369 waste_ = 0; | 1370 waste_ = 0; |
1370 } | 1371 } |
1371 | 1372 |
1372 // Accessors for the allocation statistics. | 1373 // Accessors for the allocation statistics. |
1373 intptr_t Capacity() { return capacity_; } | 1374 intptr_t Capacity() { return capacity_; } |
1375 intptr_t MaxCapacity() { return max_capacity_; } | |
1374 intptr_t Size() { return size_; } | 1376 intptr_t Size() { return size_; } |
1375 intptr_t Waste() { return waste_; } | 1377 intptr_t Waste() { return waste_; } |
1376 | 1378 |
1377 // Grow the space by adding available bytes. They are initially marked as | 1379 // Grow the space by adding available bytes. They are initially marked as |
1378 // being in use (part of the size), but will normally be immediately freed, | 1380 // being in use (part of the size), but will normally be immediately freed, |
1379 // putting them on the free list and removing them from size_. | 1381 // putting them on the free list and removing them from size_. |
1380 void ExpandSpace(int size_in_bytes) { | 1382 void ExpandSpace(int size_in_bytes) { |
1381 capacity_ += size_in_bytes; | 1383 capacity_ += size_in_bytes; |
1382 size_ += size_in_bytes; | 1384 size_ += size_in_bytes; |
1385 if (capacity_ > max_capacity_) { | |
1386 max_capacity_ = capacity_; | |
1387 } | |
1383 ASSERT(size_ >= 0); | 1388 ASSERT(size_ >= 0); |
1384 } | 1389 } |
1385 | 1390 |
1386 // Shrink the space by removing available bytes. Since shrinking is done | 1391 // Shrink the space by removing available bytes. Since shrinking is done |
1387 // during sweeping, bytes have been marked as being in use (part of the size) | 1392 // during sweeping, bytes have been marked as being in use (part of the size) |
1388 // and are hereby freed. | 1393 // and are hereby freed. |
1389 void ShrinkSpace(int size_in_bytes) { | 1394 void ShrinkSpace(int size_in_bytes) { |
1390 capacity_ -= size_in_bytes; | 1395 capacity_ -= size_in_bytes; |
1391 size_ -= size_in_bytes; | 1396 size_ -= size_in_bytes; |
1392 ASSERT(size_ >= 0); | 1397 ASSERT(size_ >= 0); |
(...skipping 13 matching lines...) Expand all Loading... | |
1406 | 1411 |
1407 // Waste free bytes (available -> waste). | 1412 // Waste free bytes (available -> waste). |
1408 void WasteBytes(int size_in_bytes) { | 1413 void WasteBytes(int size_in_bytes) { |
1409 size_ -= size_in_bytes; | 1414 size_ -= size_in_bytes; |
1410 waste_ += size_in_bytes; | 1415 waste_ += size_in_bytes; |
1411 ASSERT(size_ >= 0); | 1416 ASSERT(size_ >= 0); |
1412 } | 1417 } |
1413 | 1418 |
1414 private: | 1419 private: |
1415 intptr_t capacity_; | 1420 intptr_t capacity_; |
1421 intptr_t max_capacity_; | |
1416 intptr_t size_; | 1422 intptr_t size_; |
1417 intptr_t waste_; | 1423 intptr_t waste_; |
1418 }; | 1424 }; |
1419 | 1425 |
1420 | 1426 |
1421 // ----------------------------------------------------------------------------- | 1427 // ----------------------------------------------------------------------------- |
1422 // Free lists for old object spaces | 1428 // Free lists for old object spaces |
1423 // | 1429 // |
1424 // Free-list nodes are free blocks in the heap. They look like heap objects | 1430 // Free-list nodes are free blocks in the heap. They look like heap objects |
1425 // (free-list node pointers have the heap object tag, and they have a map like | 1431 // (free-list node pointers have the heap object tag, and they have a map like |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 // Prepares for a mark-compact GC. | 1653 // Prepares for a mark-compact GC. |
1648 virtual void PrepareForMarkCompact(); | 1654 virtual void PrepareForMarkCompact(); |
1649 | 1655 |
1650 // Current capacity without growing (Size() + Available()). | 1656 // Current capacity without growing (Size() + Available()). |
1651 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1657 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
1652 | 1658 |
1653 // Total amount of memory committed for this space. For paged | 1659 // Total amount of memory committed for this space. For paged |
1654 // spaces this equals the capacity. | 1660 // spaces this equals the capacity. |
1655 intptr_t CommittedMemory() { return Capacity(); } | 1661 intptr_t CommittedMemory() { return Capacity(); } |
1656 | 1662 |
1663 // The maximum amount of memory ever committed for this space. | |
1664 intptr_t MaximumCommittedMemory() { return accounting_stats_.MaxCapacity(); } | |
1665 | |
1657 // Approximate amount of physical memory committed for this space. | 1666 // Approximate amount of physical memory committed for this space. |
1658 size_t CommittedPhysicalMemory(); | 1667 size_t CommittedPhysicalMemory(); |
1659 | 1668 |
1660 struct SizeStats { | 1669 struct SizeStats { |
1661 intptr_t Total() { | 1670 intptr_t Total() { |
1662 return small_size_ + medium_size_ + large_size_ + huge_size_; | 1671 return small_size_ + medium_size_ + large_size_ + huge_size_; |
1663 } | 1672 } |
1664 | 1673 |
1665 intptr_t small_size_; | 1674 intptr_t small_size_; |
1666 intptr_t medium_size_; | 1675 intptr_t medium_size_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1747 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | 1756 Page::FromAddress(top) == Page::FromAddress(limit - 1)); |
1748 MemoryChunk::UpdateHighWaterMark(allocation_info_.top); | 1757 MemoryChunk::UpdateHighWaterMark(allocation_info_.top); |
1749 allocation_info_.top = top; | 1758 allocation_info_.top = top; |
1750 allocation_info_.limit = limit; | 1759 allocation_info_.limit = limit; |
1751 } | 1760 } |
1752 | 1761 |
1753 void Allocate(int bytes) { | 1762 void Allocate(int bytes) { |
1754 accounting_stats_.AllocateBytes(bytes); | 1763 accounting_stats_.AllocateBytes(bytes); |
1755 } | 1764 } |
1756 | 1765 |
1757 void IncreaseCapacity(int size) { | 1766 void IncreaseCapacity(int size); |
1758 accounting_stats_.ExpandSpace(size); | |
1759 } | |
1760 | 1767 |
1761 // Releases an unused page and shrinks the space. | 1768 // Releases an unused page and shrinks the space. |
1762 void ReleasePage(Page* page, bool unlink); | 1769 void ReleasePage(Page* page, bool unlink); |
1763 | 1770 |
1764 // The dummy page that anchors the linked list of pages. | 1771 // The dummy page that anchors the linked list of pages. |
1765 Page* anchor() { return &anchor_; } | 1772 Page* anchor() { return &anchor_; } |
1766 | 1773 |
1767 #ifdef VERIFY_HEAP | 1774 #ifdef VERIFY_HEAP |
1768 // Verify integrity of this space. | 1775 // Verify integrity of this space. |
1769 virtual void Verify(ObjectVisitor* visitor); | 1776 virtual void Verify(ObjectVisitor* visitor); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2159 // Returns the maximum capacity of the semi space. | 2166 // Returns the maximum capacity of the semi space. |
2160 int MaximumCapacity() { return maximum_capacity_; } | 2167 int MaximumCapacity() { return maximum_capacity_; } |
2161 | 2168 |
2162 // Returns the initial capacity of the semi space. | 2169 // Returns the initial capacity of the semi space. |
2163 int InitialCapacity() { return initial_capacity_; } | 2170 int InitialCapacity() { return initial_capacity_; } |
2164 | 2171 |
2165 SemiSpaceId id() { return id_; } | 2172 SemiSpaceId id() { return id_; } |
2166 | 2173 |
2167 static void Swap(SemiSpace* from, SemiSpace* to); | 2174 static void Swap(SemiSpace* from, SemiSpace* to); |
2168 | 2175 |
2176 // Returns the maximum amount of memory ever committed by the semi space. | |
2177 size_t MaximumCommittedMemory() { return maximum_committed_; } | |
2178 | |
2169 // Approximate amount of physical memory committed for this space. | 2179 // Approximate amount of physical memory committed for this space. |
2170 size_t CommittedPhysicalMemory(); | 2180 size_t CommittedPhysicalMemory(); |
2171 | 2181 |
2172 private: | 2182 private: |
2173 // Flips the semispace between being from-space and to-space. | 2183 // Flips the semispace between being from-space and to-space. |
2174 // Copies the flags into the masked positions on all pages in the space. | 2184 // Copies the flags into the masked positions on all pages in the space. |
2175 void FlipPages(intptr_t flags, intptr_t flag_mask); | 2185 void FlipPages(intptr_t flags, intptr_t flag_mask); |
2176 | 2186 |
2177 NewSpacePage* anchor() { return &anchor_; } | 2187 NewSpacePage* anchor() { return &anchor_; } |
2178 | 2188 |
2179 // The current and maximum capacity of the space. | 2189 // The current and maximum capacity of the space. |
2180 int capacity_; | 2190 int capacity_; |
2181 int maximum_capacity_; | 2191 int maximum_capacity_; |
2182 int initial_capacity_; | 2192 int initial_capacity_; |
2183 | 2193 |
2194 intptr_t maximum_committed_; | |
2195 | |
2184 // The start address of the space. | 2196 // The start address of the space. |
2185 Address start_; | 2197 Address start_; |
2186 // Used to govern object promotion during mark-compact collection. | 2198 // Used to govern object promotion during mark-compact collection. |
2187 Address age_mark_; | 2199 Address age_mark_; |
2188 | 2200 |
2189 // Masks and comparison values to test for containment in this semispace. | 2201 // Masks and comparison values to test for containment in this semispace. |
2190 uintptr_t address_mask_; | 2202 uintptr_t address_mask_; |
2191 uintptr_t object_mask_; | 2203 uintptr_t object_mask_; |
2192 uintptr_t object_expected_; | 2204 uintptr_t object_expected_; |
2193 | 2205 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2359 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 2371 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
2360 return to_space_.Capacity(); | 2372 return to_space_.Capacity(); |
2361 } | 2373 } |
2362 | 2374 |
2363 // Return the total amount of memory committed for new space. | 2375 // Return the total amount of memory committed for new space. |
2364 intptr_t CommittedMemory() { | 2376 intptr_t CommittedMemory() { |
2365 if (from_space_.is_committed()) return 2 * Capacity(); | 2377 if (from_space_.is_committed()) return 2 * Capacity(); |
2366 return Capacity(); | 2378 return Capacity(); |
2367 } | 2379 } |
2368 | 2380 |
2381 // Return the total amount of memory committed for new space. | |
2382 intptr_t MaximumCommittedMemory() { | |
2383 ASSERT(to_space_.MaximumCommittedMemory() == | |
2384 from_space_.MaximumCommittedMemory()); | |
Benedikt Meurer
2013/10/22 11:44:10
Nit: indentation
rmcilroy
2013/10/23 14:40:23
Done.
| |
2385 return 2 * to_space_.MaximumCommittedMemory(); | |
2386 } | |
2387 | |
2369 // Approximate amount of physical memory committed for this space. | 2388 // Approximate amount of physical memory committed for this space. |
2370 size_t CommittedPhysicalMemory(); | 2389 size_t CommittedPhysicalMemory(); |
2371 | 2390 |
2372 // Return the available bytes without growing. | 2391 // Return the available bytes without growing. |
2373 intptr_t Available() { | 2392 intptr_t Available() { |
2374 return Capacity() - Size(); | 2393 return Capacity() - Size(); |
2375 } | 2394 } |
2376 | 2395 |
2377 // Return the maximum capacity of a semispace. | 2396 // Return the maximum capacity of a semispace. |
2378 int MaximumCapacity() { | 2397 int MaximumCapacity() { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2741 inline intptr_t Available(); | 2760 inline intptr_t Available(); |
2742 | 2761 |
2743 virtual intptr_t Size() { | 2762 virtual intptr_t Size() { |
2744 return size_; | 2763 return size_; |
2745 } | 2764 } |
2746 | 2765 |
2747 virtual intptr_t SizeOfObjects() { | 2766 virtual intptr_t SizeOfObjects() { |
2748 return objects_size_; | 2767 return objects_size_; |
2749 } | 2768 } |
2750 | 2769 |
2770 intptr_t MaximumCommittedMemory() { | |
2771 return maximum_committed_; | |
2772 } | |
2773 | |
2751 intptr_t CommittedMemory() { | 2774 intptr_t CommittedMemory() { |
2752 return Size(); | 2775 return Size(); |
2753 } | 2776 } |
2754 | 2777 |
2755 // Approximate amount of physical memory committed for this space. | 2778 // Approximate amount of physical memory committed for this space. |
2756 size_t CommittedPhysicalMemory(); | 2779 size_t CommittedPhysicalMemory(); |
2757 | 2780 |
2758 int PageCount() { | 2781 int PageCount() { |
2759 return page_count_; | 2782 return page_count_; |
2760 } | 2783 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2792 virtual void Print(); | 2815 virtual void Print(); |
2793 void ReportStatistics(); | 2816 void ReportStatistics(); |
2794 void CollectCodeStatistics(); | 2817 void CollectCodeStatistics(); |
2795 #endif | 2818 #endif |
2796 // Checks whether an address is in the object area in this space. It | 2819 // Checks whether an address is in the object area in this space. It |
2797 // iterates all objects in the space. May be slow. | 2820 // iterates all objects in the space. May be slow. |
2798 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } | 2821 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } |
2799 | 2822 |
2800 private: | 2823 private: |
2801 intptr_t max_capacity_; | 2824 intptr_t max_capacity_; |
2825 intptr_t maximum_committed_; | |
2802 // The head of the linked list of large object chunks. | 2826 // The head of the linked list of large object chunks. |
2803 LargePage* first_page_; | 2827 LargePage* first_page_; |
2804 intptr_t size_; // allocated bytes | 2828 intptr_t size_; // allocated bytes |
2805 int page_count_; // number of chunks | 2829 int page_count_; // number of chunks |
2806 intptr_t objects_size_; // size of objects | 2830 intptr_t objects_size_; // size of objects |
2807 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them | 2831 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them |
2808 HashMap chunk_map_; | 2832 HashMap chunk_map_; |
2809 | 2833 |
2810 friend class LargeObjectIterator; | 2834 friend class LargeObjectIterator; |
2811 | 2835 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2903 } | 2927 } |
2904 // Must be small, since an iteration is used for lookup. | 2928 // Must be small, since an iteration is used for lookup. |
2905 static const int kMaxComments = 64; | 2929 static const int kMaxComments = 64; |
2906 }; | 2930 }; |
2907 #endif | 2931 #endif |
2908 | 2932 |
2909 | 2933 |
2910 } } // namespace v8::internal | 2934 } } // namespace v8::internal |
2911 | 2935 |
2912 #endif // V8_SPACES_H_ | 2936 #endif // V8_SPACES_H_ |
OLD | NEW |