| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
| 6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 intptr_t SizeOfObjects(); | 634 intptr_t SizeOfObjects(); |
| 635 | 635 |
| 636 // Return the starting address and a mask for the new space. And-masking an | 636 // Return the starting address and a mask for the new space. And-masking an |
| 637 // address with the mask will result in the start address of the new space | 637 // address with the mask will result in the start address of the new space |
| 638 // for all addresses in either semispace. | 638 // for all addresses in either semispace. |
| 639 Address NewSpaceStart() { return new_space_.start(); } | 639 Address NewSpaceStart() { return new_space_.start(); } |
| 640 uintptr_t NewSpaceMask() { return new_space_.mask(); } | 640 uintptr_t NewSpaceMask() { return new_space_.mask(); } |
| 641 Address NewSpaceTop() { return new_space_.top(); } | 641 Address NewSpaceTop() { return new_space_.top(); } |
| 642 | 642 |
| 643 NewSpace* new_space() { return &new_space_; } | 643 NewSpace* new_space() { return &new_space_; } |
| 644 OldSpace* old_pointer_space() { return old_pointer_space_; } | 644 OldSpace* old_space() { return old_space_; } |
| 645 OldSpace* old_data_space() { return old_data_space_; } | |
| 646 OldSpace* code_space() { return code_space_; } | 645 OldSpace* code_space() { return code_space_; } |
| 647 MapSpace* map_space() { return map_space_; } | 646 MapSpace* map_space() { return map_space_; } |
| 648 CellSpace* cell_space() { return cell_space_; } | 647 CellSpace* cell_space() { return cell_space_; } |
| 649 LargeObjectSpace* lo_space() { return lo_space_; } | 648 LargeObjectSpace* lo_space() { return lo_space_; } |
| 650 PagedSpace* paged_space(int idx) { | 649 PagedSpace* paged_space(int idx) { |
| 651 switch (idx) { | 650 switch (idx) { |
| 652 case OLD_POINTER_SPACE: | 651 case OLD_SPACE: |
| 653 return old_pointer_space(); | 652 return old_space(); |
| 654 case OLD_DATA_SPACE: | |
| 655 return old_data_space(); | |
| 656 case MAP_SPACE: | 653 case MAP_SPACE: |
| 657 return map_space(); | 654 return map_space(); |
| 658 case CELL_SPACE: | 655 case CELL_SPACE: |
| 659 return cell_space(); | 656 return cell_space(); |
| 660 case CODE_SPACE: | 657 case CODE_SPACE: |
| 661 return code_space(); | 658 return code_space(); |
| 662 case NEW_SPACE: | 659 case NEW_SPACE: |
| 663 case LO_SPACE: | 660 case LO_SPACE: |
| 664 UNREACHABLE(); | 661 UNREACHABLE(); |
| 665 } | 662 } |
| 666 return NULL; | 663 return NULL; |
| 667 } | 664 } |
| 668 | 665 |
| 669 bool always_allocate() { return always_allocate_scope_depth_ != 0; } | 666 bool always_allocate() { return always_allocate_scope_depth_ != 0; } |
| 670 Address always_allocate_scope_depth_address() { | 667 Address always_allocate_scope_depth_address() { |
| 671 return reinterpret_cast<Address>(&always_allocate_scope_depth_); | 668 return reinterpret_cast<Address>(&always_allocate_scope_depth_); |
| 672 } | 669 } |
| 673 | 670 |
| 674 Address* NewSpaceAllocationTopAddress() { | 671 Address* NewSpaceAllocationTopAddress() { |
| 675 return new_space_.allocation_top_address(); | 672 return new_space_.allocation_top_address(); |
| 676 } | 673 } |
| 677 Address* NewSpaceAllocationLimitAddress() { | 674 Address* NewSpaceAllocationLimitAddress() { |
| 678 return new_space_.allocation_limit_address(); | 675 return new_space_.allocation_limit_address(); |
| 679 } | 676 } |
| 680 | 677 |
| 681 Address* OldPointerSpaceAllocationTopAddress() { | 678 Address* OldSpaceAllocationTopAddress() { |
| 682 return old_pointer_space_->allocation_top_address(); | 679 return old_space_->allocation_top_address(); |
| 683 } | 680 } |
| 684 Address* OldPointerSpaceAllocationLimitAddress() { | 681 Address* OldSpaceAllocationLimitAddress() { |
| 685 return old_pointer_space_->allocation_limit_address(); | 682 return old_space_->allocation_limit_address(); |
| 686 } | |
| 687 | |
| 688 Address* OldDataSpaceAllocationTopAddress() { | |
| 689 return old_data_space_->allocation_top_address(); | |
| 690 } | |
| 691 Address* OldDataSpaceAllocationLimitAddress() { | |
| 692 return old_data_space_->allocation_limit_address(); | |
| 693 } | 683 } |
| 694 | 684 |
| 695 // TODO(hpayer): There is still a missmatch between capacity and actual | 685 // TODO(hpayer): There is still a missmatch between capacity and actual |
| 696 // committed memory size. | 686 // committed memory size. |
| 697 bool CanExpandOldGeneration(int size) { | 687 bool CanExpandOldGeneration(int size) { |
| 698 return (CommittedOldGenerationMemory() + size) < MaxOldGenerationSize(); | 688 return (CommittedOldGenerationMemory() + size) < MaxOldGenerationSize(); |
| 699 } | 689 } |
| 700 | 690 |
| 701 // Returns a deep copy of the JavaScript object. | 691 // Returns a deep copy of the JavaScript object. |
| 702 // Properties and elements are copied too. | 692 // Properties and elements are copied too. |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 Address end, | 903 Address end, |
| 914 ObjectSlotCallback callback); | 904 ObjectSlotCallback callback); |
| 915 | 905 |
| 916 // Returns whether the object resides in new space. | 906 // Returns whether the object resides in new space. |
| 917 inline bool InNewSpace(Object* object); | 907 inline bool InNewSpace(Object* object); |
| 918 inline bool InNewSpace(Address address); | 908 inline bool InNewSpace(Address address); |
| 919 inline bool InNewSpacePage(Address address); | 909 inline bool InNewSpacePage(Address address); |
| 920 inline bool InFromSpace(Object* object); | 910 inline bool InFromSpace(Object* object); |
| 921 inline bool InToSpace(Object* object); | 911 inline bool InToSpace(Object* object); |
| 922 | 912 |
| 923 // Returns whether the object resides in old pointer space. | 913 // Returns whether the object resides in old space. |
| 924 inline bool InOldPointerSpace(Address address); | 914 inline bool InOldSpace(Address address); |
| 925 inline bool InOldPointerSpace(Object* object); | 915 inline bool InOldSpace(Object* object); |
| 926 | |
| 927 // Returns whether the object resides in old data space. | |
| 928 inline bool InOldDataSpace(Address address); | |
| 929 inline bool InOldDataSpace(Object* object); | |
| 930 | 916 |
| 931 // Checks whether an address/object in the heap (including auxiliary | 917 // Checks whether an address/object in the heap (including auxiliary |
| 932 // area and unused area). | 918 // area and unused area). |
| 933 bool Contains(Address addr); | 919 bool Contains(Address addr); |
| 934 bool Contains(HeapObject* value); | 920 bool Contains(HeapObject* value); |
| 935 | 921 |
| 936 // Checks whether an address/object in a space. | 922 // Checks whether an address/object in a space. |
| 937 // Currently used by tests, serialization and heap verification only. | 923 // Currently used by tests, serialization and heap verification only. |
| 938 bool InSpace(Address addr, AllocationSpace space); | 924 bool InSpace(Address addr, AllocationSpace space); |
| 939 bool InSpace(HeapObject* value, AllocationSpace space); | 925 bool InSpace(HeapObject* value, AllocationSpace space); |
| 940 | 926 |
| 941 // Finds out which space an object should get promoted to based on its type. | |
| 942 inline OldSpace* TargetSpace(HeapObject* object); | |
| 943 static inline AllocationSpace TargetSpaceId(InstanceType type); | |
| 944 | |
| 945 // Checks whether the given object is allowed to be migrated from it's | 927 // Checks whether the given object is allowed to be migrated from it's |
| 946 // current space into the given destination space. Used for debugging. | 928 // current space into the given destination space. Used for debugging. |
| 947 inline bool AllowedToBeMigrated(HeapObject* object, AllocationSpace dest); | 929 inline bool AllowedToBeMigrated(HeapObject* object, AllocationSpace dest); |
| 948 | 930 |
| 949 // Sets the stub_cache_ (only used when expanding the dictionary). | 931 // Sets the stub_cache_ (only used when expanding the dictionary). |
| 950 void public_set_code_stubs(UnseededNumberDictionary* value) { | 932 void public_set_code_stubs(UnseededNumberDictionary* value) { |
| 951 roots_[kCodeStubsRootIndex] = value; | 933 roots_[kCodeStubsRootIndex] = value; |
| 952 } | 934 } |
| 953 | 935 |
| 954 // Support for computing object sizes for old objects during GCs. Returns | 936 // Support for computing object sizes for old objects during GCs. Returns |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 int always_allocate_scope_depth_; | 1562 int always_allocate_scope_depth_; |
| 1581 | 1563 |
| 1582 // For keeping track of context disposals. | 1564 // For keeping track of context disposals. |
| 1583 int contexts_disposed_; | 1565 int contexts_disposed_; |
| 1584 | 1566 |
| 1585 int global_ic_age_; | 1567 int global_ic_age_; |
| 1586 | 1568 |
| 1587 int scan_on_scavenge_pages_; | 1569 int scan_on_scavenge_pages_; |
| 1588 | 1570 |
| 1589 NewSpace new_space_; | 1571 NewSpace new_space_; |
| 1590 OldSpace* old_pointer_space_; | 1572 OldSpace* old_space_; |
| 1591 OldSpace* old_data_space_; | |
| 1592 OldSpace* code_space_; | 1573 OldSpace* code_space_; |
| 1593 MapSpace* map_space_; | 1574 MapSpace* map_space_; |
| 1594 CellSpace* cell_space_; | 1575 CellSpace* cell_space_; |
| 1595 LargeObjectSpace* lo_space_; | 1576 LargeObjectSpace* lo_space_; |
| 1596 HeapState gc_state_; | 1577 HeapState gc_state_; |
| 1597 int gc_post_processing_depth_; | 1578 int gc_post_processing_depth_; |
| 1598 Address new_space_top_after_last_gc_; | 1579 Address new_space_top_after_last_gc_; |
| 1599 | 1580 |
| 1600 // Returns the amount of external memory registered since last global gc. | 1581 // Returns the amount of external memory registered since last global gc. |
| 1601 int64_t PromotedExternalMemorySize(); | 1582 int64_t PromotedExternalMemorySize(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 // Performs garbage collection | 1757 // Performs garbage collection |
| 1777 // Returns whether there is a chance another major GC could | 1758 // Returns whether there is a chance another major GC could |
| 1778 // collect more garbage. | 1759 // collect more garbage. |
| 1779 bool PerformGarbageCollection( | 1760 bool PerformGarbageCollection( |
| 1780 GarbageCollector collector, | 1761 GarbageCollector collector, |
| 1781 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1762 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
| 1782 | 1763 |
| 1783 inline void UpdateOldSpaceLimits(); | 1764 inline void UpdateOldSpaceLimits(); |
| 1784 | 1765 |
| 1785 // Selects the proper allocation space depending on the given object | 1766 // Selects the proper allocation space depending on the given object |
| 1786 // size, pretenuring decision, and preferred old-space. | 1767 // size and pretenuring decision. |
| 1787 static AllocationSpace SelectSpace(int object_size, | 1768 static AllocationSpace SelectSpace(int object_size, |
| 1788 AllocationSpace preferred_old_space, | |
| 1789 PretenureFlag pretenure) { | 1769 PretenureFlag pretenure) { |
| 1790 DCHECK(preferred_old_space == OLD_POINTER_SPACE || | |
| 1791 preferred_old_space == OLD_DATA_SPACE); | |
| 1792 if (object_size > Page::kMaxRegularHeapObjectSize) return LO_SPACE; | 1770 if (object_size > Page::kMaxRegularHeapObjectSize) return LO_SPACE; |
| 1793 return (pretenure == TENURED) ? preferred_old_space : NEW_SPACE; | 1771 return (pretenure == TENURED) ? OLD_SPACE : NEW_SPACE; |
| 1794 } | 1772 } |
| 1795 | 1773 |
| 1796 HeapObject* DoubleAlignForDeserialization(HeapObject* object, int size); | 1774 HeapObject* DoubleAlignForDeserialization(HeapObject* object, int size); |
| 1797 | 1775 |
| 1798 // Allocate an uninitialized object. The memory is non-executable if the | 1776 // Allocate an uninitialized object. The memory is non-executable if the |
| 1799 // hardware and OS allow. This is the single choke-point for allocations | 1777 // hardware and OS allow. This is the single choke-point for allocations |
| 1800 // performed by the runtime and should not be bypassed (to extend this to | 1778 // performed by the runtime and should not be bypassed (to extend this to |
| 1801 // inlined allocations, use the Heap::DisableInlineAllocation() support). | 1779 // inlined allocations, use the Heap::DisableInlineAllocation() support). |
| 1802 MUST_USE_RESULT inline AllocationResult AllocateRaw( | 1780 MUST_USE_RESULT inline AllocationResult AllocateRaw( |
| 1803 int size_in_bytes, AllocationSpace space, AllocationSpace retry_space); | 1781 int size_in_bytes, AllocationSpace space, AllocationSpace retry_space); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2186 | 2164 |
| 2187 | 2165 |
| 2188 class HeapStats { | 2166 class HeapStats { |
| 2189 public: | 2167 public: |
| 2190 static const int kStartMarker = 0xDECADE00; | 2168 static const int kStartMarker = 0xDECADE00; |
| 2191 static const int kEndMarker = 0xDECADE01; | 2169 static const int kEndMarker = 0xDECADE01; |
| 2192 | 2170 |
| 2193 int* start_marker; // 0 | 2171 int* start_marker; // 0 |
| 2194 int* new_space_size; // 1 | 2172 int* new_space_size; // 1 |
| 2195 int* new_space_capacity; // 2 | 2173 int* new_space_capacity; // 2 |
| 2196 intptr_t* old_pointer_space_size; // 3 | 2174 intptr_t* old_space_size; // 3 |
| 2197 intptr_t* old_pointer_space_capacity; // 4 | 2175 intptr_t* old_space_capacity; // 4 |
| 2198 intptr_t* old_data_space_size; // 5 | 2176 intptr_t* code_space_size; // 5 |
| 2199 intptr_t* old_data_space_capacity; // 6 | 2177 intptr_t* code_space_capacity; // 6 |
| 2200 intptr_t* code_space_size; // 7 | 2178 intptr_t* map_space_size; // 7 |
| 2201 intptr_t* code_space_capacity; // 8 | 2179 intptr_t* map_space_capacity; // 8 |
| 2202 intptr_t* map_space_size; // 9 | 2180 intptr_t* cell_space_size; // 9 |
| 2203 intptr_t* map_space_capacity; // 10 | 2181 intptr_t* cell_space_capacity; // 10 |
| 2204 intptr_t* cell_space_size; // 11 | 2182 intptr_t* lo_space_size; // 11 |
| 2205 intptr_t* cell_space_capacity; // 12 | 2183 int* global_handle_count; // 12 |
| 2206 intptr_t* lo_space_size; // 13 | 2184 int* weak_global_handle_count; // 13 |
| 2207 int* global_handle_count; // 14 | 2185 int* pending_global_handle_count; // 14 |
| 2208 int* weak_global_handle_count; // 15 | 2186 int* near_death_global_handle_count; // 15 |
| 2209 int* pending_global_handle_count; // 16 | 2187 int* free_global_handle_count; // 16 |
| 2210 int* near_death_global_handle_count; // 17 | 2188 intptr_t* memory_allocator_size; // 17 |
| 2211 int* free_global_handle_count; // 18 | 2189 intptr_t* memory_allocator_capacity; // 18 |
| 2212 intptr_t* memory_allocator_size; // 19 | 2190 int* objects_per_type; // 19 |
| 2213 intptr_t* memory_allocator_capacity; // 20 | 2191 int* size_per_type; // 20 |
| 2214 int* objects_per_type; // 21 | 2192 int* os_error; // 21 |
| 2215 int* size_per_type; // 22 | 2193 int* end_marker; // 22 |
| 2216 int* os_error; // 23 | |
| 2217 int* end_marker; // 24 | |
| 2218 }; | 2194 }; |
| 2219 | 2195 |
| 2220 | 2196 |
| 2221 class AlwaysAllocateScope { | 2197 class AlwaysAllocateScope { |
| 2222 public: | 2198 public: |
| 2223 explicit inline AlwaysAllocateScope(Isolate* isolate); | 2199 explicit inline AlwaysAllocateScope(Isolate* isolate); |
| 2224 inline ~AlwaysAllocateScope(); | 2200 inline ~AlwaysAllocateScope(); |
| 2225 | 2201 |
| 2226 private: | 2202 private: |
| 2227 // Implicitly disable artificial allocation failures. | 2203 // Implicitly disable artificial allocation failures. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2266 public: | 2242 public: |
| 2267 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {} | 2243 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {} |
| 2268 Space* next(); | 2244 Space* next(); |
| 2269 | 2245 |
| 2270 private: | 2246 private: |
| 2271 Heap* heap_; | 2247 Heap* heap_; |
| 2272 int counter_; | 2248 int counter_; |
| 2273 }; | 2249 }; |
| 2274 | 2250 |
| 2275 | 2251 |
| 2276 // Space iterator for iterating over all old spaces of the heap: Old pointer | 2252 // Space iterator for iterating over all old spaces of the heap: Old space |
| 2277 // space, old data space and code space. Returns each space in turn, and null | 2253 // and code space. Returns each space in turn, and null when it is done. |
| 2278 // when it is done. | |
| 2279 class OldSpaces BASE_EMBEDDED { | 2254 class OldSpaces BASE_EMBEDDED { |
| 2280 public: | 2255 public: |
| 2281 explicit OldSpaces(Heap* heap) : heap_(heap), counter_(OLD_POINTER_SPACE) {} | 2256 explicit OldSpaces(Heap* heap) : heap_(heap), counter_(OLD_SPACE) {} |
| 2282 OldSpace* next(); | 2257 OldSpace* next(); |
| 2283 | 2258 |
| 2284 private: | 2259 private: |
| 2285 Heap* heap_; | 2260 Heap* heap_; |
| 2286 int counter_; | 2261 int counter_; |
| 2287 }; | 2262 }; |
| 2288 | 2263 |
| 2289 | 2264 |
| 2290 // Space iterator for iterating over all the paged spaces of the heap: Map | 2265 // Space iterator for iterating over all the paged spaces of the heap: Map |
| 2291 // space, old pointer space, old data space, code space and cell space. Returns | 2266 // space, old space, code space and cell space. Returns |
| 2292 // each space in turn, and null when it is done. | 2267 // each space in turn, and null when it is done. |
| 2293 class PagedSpaces BASE_EMBEDDED { | 2268 class PagedSpaces BASE_EMBEDDED { |
| 2294 public: | 2269 public: |
| 2295 explicit PagedSpaces(Heap* heap) : heap_(heap), counter_(OLD_POINTER_SPACE) {} | 2270 explicit PagedSpaces(Heap* heap) : heap_(heap), counter_(OLD_SPACE) {} |
| 2296 PagedSpace* next(); | 2271 PagedSpace* next(); |
| 2297 | 2272 |
| 2298 private: | 2273 private: |
| 2299 Heap* heap_; | 2274 Heap* heap_; |
| 2300 int counter_; | 2275 int counter_; |
| 2301 }; | 2276 }; |
| 2302 | 2277 |
| 2303 | 2278 |
| 2304 // Space iterator for iterating over all spaces of the heap. | 2279 // Space iterator for iterating over all spaces of the heap. |
| 2305 // For each space an object iterator is provided. The deallocation of the | 2280 // For each space an object iterator is provided. The deallocation of the |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2628 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2603 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
| 2629 | 2604 |
| 2630 private: | 2605 private: |
| 2631 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2606 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2632 }; | 2607 }; |
| 2633 #endif // DEBUG | 2608 #endif // DEBUG |
| 2634 } | 2609 } |
| 2635 } // namespace v8::internal | 2610 } // namespace v8::internal |
| 2636 | 2611 |
| 2637 #endif // V8_HEAP_HEAP_H_ | 2612 #endif // V8_HEAP_HEAP_H_ |
| OLD | NEW |