| 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 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 // functions increase or decrease one of the non-capacity stats in | 1381 // functions increase or decrease one of the non-capacity stats in |
| 1382 // conjunction with capacity, or else they always balance increases and | 1382 // conjunction with capacity, or else they always balance increases and |
| 1383 // decreases to the non-capacity stats. | 1383 // decreases to the non-capacity stats. |
| 1384 class AllocationStats BASE_EMBEDDED { | 1384 class AllocationStats BASE_EMBEDDED { |
| 1385 public: | 1385 public: |
| 1386 AllocationStats() { Clear(); } | 1386 AllocationStats() { Clear(); } |
| 1387 | 1387 |
| 1388 // Zero out all the allocation statistics (i.e., no capacity). | 1388 // Zero out all the allocation statistics (i.e., no capacity). |
| 1389 void Clear() { | 1389 void Clear() { |
| 1390 capacity_ = 0; | 1390 capacity_ = 0; |
| 1391 max_capacity_ = 0; |
| 1391 size_ = 0; | 1392 size_ = 0; |
| 1392 waste_ = 0; | 1393 waste_ = 0; |
| 1393 } | 1394 } |
| 1394 | 1395 |
| 1395 void ClearSizeWaste() { | 1396 void ClearSizeWaste() { |
| 1396 size_ = capacity_; | 1397 size_ = capacity_; |
| 1397 waste_ = 0; | 1398 waste_ = 0; |
| 1398 } | 1399 } |
| 1399 | 1400 |
| 1400 // Reset the allocation statistics (i.e., available = capacity with no | 1401 // Reset the allocation statistics (i.e., available = capacity with no |
| 1401 // wasted or allocated bytes). | 1402 // wasted or allocated bytes). |
| 1402 void Reset() { | 1403 void Reset() { |
| 1403 size_ = 0; | 1404 size_ = 0; |
| 1404 waste_ = 0; | 1405 waste_ = 0; |
| 1405 } | 1406 } |
| 1406 | 1407 |
| 1407 // Accessors for the allocation statistics. | 1408 // Accessors for the allocation statistics. |
| 1408 intptr_t Capacity() { return capacity_; } | 1409 intptr_t Capacity() { return capacity_; } |
| 1410 intptr_t MaxCapacity() { return max_capacity_; } |
| 1409 intptr_t Size() { return size_; } | 1411 intptr_t Size() { return size_; } |
| 1410 intptr_t Waste() { return waste_; } | 1412 intptr_t Waste() { return waste_; } |
| 1411 | 1413 |
| 1412 // Grow the space by adding available bytes. They are initially marked as | 1414 // Grow the space by adding available bytes. They are initially marked as |
| 1413 // being in use (part of the size), but will normally be immediately freed, | 1415 // being in use (part of the size), but will normally be immediately freed, |
| 1414 // putting them on the free list and removing them from size_. | 1416 // putting them on the free list and removing them from size_. |
| 1415 void ExpandSpace(int size_in_bytes) { | 1417 void ExpandSpace(int size_in_bytes) { |
| 1416 capacity_ += size_in_bytes; | 1418 capacity_ += size_in_bytes; |
| 1417 size_ += size_in_bytes; | 1419 size_ += size_in_bytes; |
| 1420 if (capacity_ > max_capacity_) { |
| 1421 max_capacity_ = capacity_; |
| 1422 } |
| 1418 ASSERT(size_ >= 0); | 1423 ASSERT(size_ >= 0); |
| 1419 } | 1424 } |
| 1420 | 1425 |
| 1421 // Shrink the space by removing available bytes. Since shrinking is done | 1426 // Shrink the space by removing available bytes. Since shrinking is done |
| 1422 // during sweeping, bytes have been marked as being in use (part of the size) | 1427 // during sweeping, bytes have been marked as being in use (part of the size) |
| 1423 // and are hereby freed. | 1428 // and are hereby freed. |
| 1424 void ShrinkSpace(int size_in_bytes) { | 1429 void ShrinkSpace(int size_in_bytes) { |
| 1425 capacity_ -= size_in_bytes; | 1430 capacity_ -= size_in_bytes; |
| 1426 size_ -= size_in_bytes; | 1431 size_ -= size_in_bytes; |
| 1427 ASSERT(size_ >= 0); | 1432 ASSERT(size_ >= 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1441 | 1446 |
| 1442 // Waste free bytes (available -> waste). | 1447 // Waste free bytes (available -> waste). |
| 1443 void WasteBytes(int size_in_bytes) { | 1448 void WasteBytes(int size_in_bytes) { |
| 1444 size_ -= size_in_bytes; | 1449 size_ -= size_in_bytes; |
| 1445 waste_ += size_in_bytes; | 1450 waste_ += size_in_bytes; |
| 1446 ASSERT(size_ >= 0); | 1451 ASSERT(size_ >= 0); |
| 1447 } | 1452 } |
| 1448 | 1453 |
| 1449 private: | 1454 private: |
| 1450 intptr_t capacity_; | 1455 intptr_t capacity_; |
| 1456 intptr_t max_capacity_; |
| 1451 intptr_t size_; | 1457 intptr_t size_; |
| 1452 intptr_t waste_; | 1458 intptr_t waste_; |
| 1453 }; | 1459 }; |
| 1454 | 1460 |
| 1455 | 1461 |
| 1456 // ----------------------------------------------------------------------------- | 1462 // ----------------------------------------------------------------------------- |
| 1457 // Free lists for old object spaces | 1463 // Free lists for old object spaces |
| 1458 // | 1464 // |
| 1459 // Free-list nodes are free blocks in the heap. They look like heap objects | 1465 // Free-list nodes are free blocks in the heap. They look like heap objects |
| 1460 // (free-list node pointers have the heap object tag, and they have a map like | 1466 // (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... |
| 1682 // Prepares for a mark-compact GC. | 1688 // Prepares for a mark-compact GC. |
| 1683 virtual void PrepareForMarkCompact(); | 1689 virtual void PrepareForMarkCompact(); |
| 1684 | 1690 |
| 1685 // Current capacity without growing (Size() + Available()). | 1691 // Current capacity without growing (Size() + Available()). |
| 1686 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1692 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
| 1687 | 1693 |
| 1688 // Total amount of memory committed for this space. For paged | 1694 // Total amount of memory committed for this space. For paged |
| 1689 // spaces this equals the capacity. | 1695 // spaces this equals the capacity. |
| 1690 intptr_t CommittedMemory() { return Capacity(); } | 1696 intptr_t CommittedMemory() { return Capacity(); } |
| 1691 | 1697 |
| 1698 // The maximum amount of memory ever committed for this space. |
| 1699 intptr_t MaximumCommittedMemory() { return accounting_stats_.MaxCapacity(); } |
| 1700 |
| 1692 // Approximate amount of physical memory committed for this space. | 1701 // Approximate amount of physical memory committed for this space. |
| 1693 size_t CommittedPhysicalMemory(); | 1702 size_t CommittedPhysicalMemory(); |
| 1694 | 1703 |
| 1695 struct SizeStats { | 1704 struct SizeStats { |
| 1696 intptr_t Total() { | 1705 intptr_t Total() { |
| 1697 return small_size_ + medium_size_ + large_size_ + huge_size_; | 1706 return small_size_ + medium_size_ + large_size_ + huge_size_; |
| 1698 } | 1707 } |
| 1699 | 1708 |
| 1700 intptr_t small_size_; | 1709 intptr_t small_size_; |
| 1701 intptr_t medium_size_; | 1710 intptr_t medium_size_; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | 1797 Page::FromAddress(top) == Page::FromAddress(limit - 1)); |
| 1789 MemoryChunk::UpdateHighWaterMark(allocation_info_.top()); | 1798 MemoryChunk::UpdateHighWaterMark(allocation_info_.top()); |
| 1790 allocation_info_.set_top(top); | 1799 allocation_info_.set_top(top); |
| 1791 allocation_info_.set_limit(limit); | 1800 allocation_info_.set_limit(limit); |
| 1792 } | 1801 } |
| 1793 | 1802 |
| 1794 void Allocate(int bytes) { | 1803 void Allocate(int bytes) { |
| 1795 accounting_stats_.AllocateBytes(bytes); | 1804 accounting_stats_.AllocateBytes(bytes); |
| 1796 } | 1805 } |
| 1797 | 1806 |
| 1798 void IncreaseCapacity(int size) { | 1807 void IncreaseCapacity(int size); |
| 1799 accounting_stats_.ExpandSpace(size); | |
| 1800 } | |
| 1801 | 1808 |
| 1802 // Releases an unused page and shrinks the space. | 1809 // Releases an unused page and shrinks the space. |
| 1803 void ReleasePage(Page* page, bool unlink); | 1810 void ReleasePage(Page* page, bool unlink); |
| 1804 | 1811 |
| 1805 // The dummy page that anchors the linked list of pages. | 1812 // The dummy page that anchors the linked list of pages. |
| 1806 Page* anchor() { return &anchor_; } | 1813 Page* anchor() { return &anchor_; } |
| 1807 | 1814 |
| 1808 #ifdef VERIFY_HEAP | 1815 #ifdef VERIFY_HEAP |
| 1809 // Verify integrity of this space. | 1816 // Verify integrity of this space. |
| 1810 virtual void Verify(ObjectVisitor* visitor); | 1817 virtual void Verify(ObjectVisitor* visitor); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 // Returns the maximum capacity of the semi space. | 2207 // Returns the maximum capacity of the semi space. |
| 2201 int MaximumCapacity() { return maximum_capacity_; } | 2208 int MaximumCapacity() { return maximum_capacity_; } |
| 2202 | 2209 |
| 2203 // Returns the initial capacity of the semi space. | 2210 // Returns the initial capacity of the semi space. |
| 2204 int InitialCapacity() { return initial_capacity_; } | 2211 int InitialCapacity() { return initial_capacity_; } |
| 2205 | 2212 |
| 2206 SemiSpaceId id() { return id_; } | 2213 SemiSpaceId id() { return id_; } |
| 2207 | 2214 |
| 2208 static void Swap(SemiSpace* from, SemiSpace* to); | 2215 static void Swap(SemiSpace* from, SemiSpace* to); |
| 2209 | 2216 |
| 2217 // Returns the maximum amount of memory ever committed by the semi space. |
| 2218 size_t MaximumCommittedMemory() { return maximum_committed_; } |
| 2219 |
| 2210 // Approximate amount of physical memory committed for this space. | 2220 // Approximate amount of physical memory committed for this space. |
| 2211 size_t CommittedPhysicalMemory(); | 2221 size_t CommittedPhysicalMemory(); |
| 2212 | 2222 |
| 2213 private: | 2223 private: |
| 2214 // Flips the semispace between being from-space and to-space. | 2224 // Flips the semispace between being from-space and to-space. |
| 2215 // Copies the flags into the masked positions on all pages in the space. | 2225 // Copies the flags into the masked positions on all pages in the space. |
| 2216 void FlipPages(intptr_t flags, intptr_t flag_mask); | 2226 void FlipPages(intptr_t flags, intptr_t flag_mask); |
| 2217 | 2227 |
| 2228 // Updates Capacity and MaximumCommitted based on new capacity. |
| 2229 void SetCapacity(int new_capacity); |
| 2230 |
| 2218 NewSpacePage* anchor() { return &anchor_; } | 2231 NewSpacePage* anchor() { return &anchor_; } |
| 2219 | 2232 |
| 2220 // The current and maximum capacity of the space. | 2233 // The current and maximum capacity of the space. |
| 2221 int capacity_; | 2234 int capacity_; |
| 2222 int maximum_capacity_; | 2235 int maximum_capacity_; |
| 2223 int initial_capacity_; | 2236 int initial_capacity_; |
| 2224 | 2237 |
| 2238 intptr_t maximum_committed_; |
| 2239 |
| 2225 // The start address of the space. | 2240 // The start address of the space. |
| 2226 Address start_; | 2241 Address start_; |
| 2227 // Used to govern object promotion during mark-compact collection. | 2242 // Used to govern object promotion during mark-compact collection. |
| 2228 Address age_mark_; | 2243 Address age_mark_; |
| 2229 | 2244 |
| 2230 // Masks and comparison values to test for containment in this semispace. | 2245 // Masks and comparison values to test for containment in this semispace. |
| 2231 uintptr_t address_mask_; | 2246 uintptr_t address_mask_; |
| 2232 uintptr_t object_mask_; | 2247 uintptr_t object_mask_; |
| 2233 uintptr_t object_expected_; | 2248 uintptr_t object_expected_; |
| 2234 | 2249 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 2415 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
| 2401 return to_space_.Capacity(); | 2416 return to_space_.Capacity(); |
| 2402 } | 2417 } |
| 2403 | 2418 |
| 2404 // Return the total amount of memory committed for new space. | 2419 // Return the total amount of memory committed for new space. |
| 2405 intptr_t CommittedMemory() { | 2420 intptr_t CommittedMemory() { |
| 2406 if (from_space_.is_committed()) return 2 * Capacity(); | 2421 if (from_space_.is_committed()) return 2 * Capacity(); |
| 2407 return Capacity(); | 2422 return Capacity(); |
| 2408 } | 2423 } |
| 2409 | 2424 |
| 2425 // Return the total amount of memory committed for new space. |
| 2426 intptr_t MaximumCommittedMemory() { |
| 2427 return to_space_.MaximumCommittedMemory() + |
| 2428 from_space_.MaximumCommittedMemory(); |
| 2429 } |
| 2430 |
| 2410 // Approximate amount of physical memory committed for this space. | 2431 // Approximate amount of physical memory committed for this space. |
| 2411 size_t CommittedPhysicalMemory(); | 2432 size_t CommittedPhysicalMemory(); |
| 2412 | 2433 |
| 2413 // Return the available bytes without growing. | 2434 // Return the available bytes without growing. |
| 2414 intptr_t Available() { | 2435 intptr_t Available() { |
| 2415 return Capacity() - Size(); | 2436 return Capacity() - Size(); |
| 2416 } | 2437 } |
| 2417 | 2438 |
| 2418 // Return the maximum capacity of a semispace. | 2439 // Return the maximum capacity of a semispace. |
| 2419 int MaximumCapacity() { | 2440 int MaximumCapacity() { |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2795 inline intptr_t Available(); | 2816 inline intptr_t Available(); |
| 2796 | 2817 |
| 2797 virtual intptr_t Size() { | 2818 virtual intptr_t Size() { |
| 2798 return size_; | 2819 return size_; |
| 2799 } | 2820 } |
| 2800 | 2821 |
| 2801 virtual intptr_t SizeOfObjects() { | 2822 virtual intptr_t SizeOfObjects() { |
| 2802 return objects_size_; | 2823 return objects_size_; |
| 2803 } | 2824 } |
| 2804 | 2825 |
| 2826 intptr_t MaximumCommittedMemory() { |
| 2827 return maximum_committed_; |
| 2828 } |
| 2829 |
| 2805 intptr_t CommittedMemory() { | 2830 intptr_t CommittedMemory() { |
| 2806 return Size(); | 2831 return Size(); |
| 2807 } | 2832 } |
| 2808 | 2833 |
| 2809 // Approximate amount of physical memory committed for this space. | 2834 // Approximate amount of physical memory committed for this space. |
| 2810 size_t CommittedPhysicalMemory(); | 2835 size_t CommittedPhysicalMemory(); |
| 2811 | 2836 |
| 2812 int PageCount() { | 2837 int PageCount() { |
| 2813 return page_count_; | 2838 return page_count_; |
| 2814 } | 2839 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2846 virtual void Print(); | 2871 virtual void Print(); |
| 2847 void ReportStatistics(); | 2872 void ReportStatistics(); |
| 2848 void CollectCodeStatistics(); | 2873 void CollectCodeStatistics(); |
| 2849 #endif | 2874 #endif |
| 2850 // Checks whether an address is in the object area in this space. It | 2875 // Checks whether an address is in the object area in this space. It |
| 2851 // iterates all objects in the space. May be slow. | 2876 // iterates all objects in the space. May be slow. |
| 2852 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } | 2877 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } |
| 2853 | 2878 |
| 2854 private: | 2879 private: |
| 2855 intptr_t max_capacity_; | 2880 intptr_t max_capacity_; |
| 2881 intptr_t maximum_committed_; |
| 2856 // The head of the linked list of large object chunks. | 2882 // The head of the linked list of large object chunks. |
| 2857 LargePage* first_page_; | 2883 LargePage* first_page_; |
| 2858 intptr_t size_; // allocated bytes | 2884 intptr_t size_; // allocated bytes |
| 2859 int page_count_; // number of chunks | 2885 int page_count_; // number of chunks |
| 2860 intptr_t objects_size_; // size of objects | 2886 intptr_t objects_size_; // size of objects |
| 2861 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them | 2887 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them |
| 2862 HashMap chunk_map_; | 2888 HashMap chunk_map_; |
| 2863 | 2889 |
| 2864 friend class LargeObjectIterator; | 2890 friend class LargeObjectIterator; |
| 2865 | 2891 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 } | 2983 } |
| 2958 // Must be small, since an iteration is used for lookup. | 2984 // Must be small, since an iteration is used for lookup. |
| 2959 static const int kMaxComments = 64; | 2985 static const int kMaxComments = 64; |
| 2960 }; | 2986 }; |
| 2961 #endif | 2987 #endif |
| 2962 | 2988 |
| 2963 | 2989 |
| 2964 } } // namespace v8::internal | 2990 } } // namespace v8::internal |
| 2965 | 2991 |
| 2966 #endif // V8_SPACES_H_ | 2992 #endif // V8_SPACES_H_ |
| OLD | NEW |