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 #include <map> | 9 #include <map> |
10 | 10 |
11 // Clients of this interface shouldn't depend on lots of heap internals. | 11 // Clients of this interface shouldn't depend on lots of heap internals. |
12 // Do not include anything from src/heap here! | 12 // Do not include anything from src/heap here! |
13 #include "include/v8.h" | 13 #include "include/v8.h" |
14 #include "src/allocation.h" | 14 #include "src/allocation.h" |
15 #include "src/assert-scope.h" | 15 #include "src/assert-scope.h" |
16 #include "src/base/atomic-utils.h" | 16 #include "src/base/atomic-utils.h" |
17 #include "src/debug/debug-interface.h" | 17 #include "src/debug/debug-interface.h" |
18 #include "src/globals.h" | 18 #include "src/globals.h" |
19 #include "src/heap-symbols.h" | 19 #include "src/heap-symbols.h" |
20 #include "src/list.h" | 20 #include "src/list.h" |
21 #include "src/objects.h" | 21 #include "src/objects.h" |
22 #include "src/objects/hash-table.h" | 22 #include "src/objects/hash-table.h" |
23 #include "src/objects/string-table.h" | 23 #include "src/objects/string-table.h" |
| 24 #include "src/visitors.h" |
24 | 25 |
25 namespace v8 { | 26 namespace v8 { |
26 namespace internal { | 27 namespace internal { |
27 | 28 |
28 using v8::MemoryPressureLevel; | 29 using v8::MemoryPressureLevel; |
29 | 30 |
30 // Defines all the roots in Heap. | 31 // Defines all the roots in Heap. |
31 #define STRONG_ROOT_LIST(V) \ | 32 #define STRONG_ROOT_LIST(V) \ |
32 /* Cluster the most popular ones in a few cache lines here at the top. */ \ | 33 /* Cluster the most popular ones in a few cache lines here at the top. */ \ |
33 /* The first 32 entries are most often used in the startup snapshot and */ \ | 34 /* The first 32 entries are most often used in the startup snapshot and */ \ |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 class HistogramTimer; | 326 class HistogramTimer; |
326 class Isolate; | 327 class Isolate; |
327 class LocalEmbedderHeapTracer; | 328 class LocalEmbedderHeapTracer; |
328 class MemoryAllocator; | 329 class MemoryAllocator; |
329 class MemoryReducer; | 330 class MemoryReducer; |
330 class MinorMarkCompactCollector; | 331 class MinorMarkCompactCollector; |
331 class ObjectIterator; | 332 class ObjectIterator; |
332 class ObjectStats; | 333 class ObjectStats; |
333 class Page; | 334 class Page; |
334 class PagedSpace; | 335 class PagedSpace; |
| 336 class RootVisitor; |
335 class Scavenger; | 337 class Scavenger; |
336 class ScavengeJob; | 338 class ScavengeJob; |
337 class Space; | 339 class Space; |
338 class StoreBuffer; | 340 class StoreBuffer; |
339 class TracePossibleWrapperReporter; | 341 class TracePossibleWrapperReporter; |
340 class WeakObjectRetainer; | 342 class WeakObjectRetainer; |
341 | 343 |
342 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to); | 344 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to); |
343 | 345 |
344 enum ArrayStorageAllocationMode { | 346 enum ArrayStorageAllocationMode { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 | 785 |
784 // Used in CreateAllocationSiteStub and the (de)serializer. | 786 // Used in CreateAllocationSiteStub and the (de)serializer. |
785 Object** allocation_sites_list_address() { return &allocation_sites_list_; } | 787 Object** allocation_sites_list_address() { return &allocation_sites_list_; } |
786 | 788 |
787 void set_encountered_weak_collections(Object* weak_collection) { | 789 void set_encountered_weak_collections(Object* weak_collection) { |
788 encountered_weak_collections_ = weak_collection; | 790 encountered_weak_collections_ = weak_collection; |
789 } | 791 } |
790 Object* encountered_weak_collections() const { | 792 Object* encountered_weak_collections() const { |
791 return encountered_weak_collections_; | 793 return encountered_weak_collections_; |
792 } | 794 } |
793 void VisitEncounteredWeakCollections(ObjectVisitor* visitor) { | 795 void IterateEncounteredWeakCollections(RootVisitor* visitor); |
794 visitor->VisitPointer(&encountered_weak_collections_); | |
795 } | |
796 | 796 |
797 void set_encountered_weak_cells(Object* weak_cell) { | 797 void set_encountered_weak_cells(Object* weak_cell) { |
798 encountered_weak_cells_ = weak_cell; | 798 encountered_weak_cells_ = weak_cell; |
799 } | 799 } |
800 Object* encountered_weak_cells() const { return encountered_weak_cells_; } | 800 Object* encountered_weak_cells() const { return encountered_weak_cells_; } |
801 | 801 |
802 void set_encountered_transition_arrays(Object* transition_array) { | 802 void set_encountered_transition_arrays(Object* transition_array) { |
803 encountered_transition_arrays_ = transition_array; | 803 encountered_transition_arrays_ = transition_array; |
804 } | 804 } |
805 Object* encountered_transition_arrays() const { | 805 Object* encountered_transition_arrays() const { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 void ReportExternalMemoryPressure(); | 1173 void ReportExternalMemoryPressure(); |
1174 | 1174 |
1175 // Invoked when GC was requested via the stack guard. | 1175 // Invoked when GC was requested via the stack guard. |
1176 void HandleGCRequest(); | 1176 void HandleGCRequest(); |
1177 | 1177 |
1178 // =========================================================================== | 1178 // =========================================================================== |
1179 // Iterators. ================================================================ | 1179 // Iterators. ================================================================ |
1180 // =========================================================================== | 1180 // =========================================================================== |
1181 | 1181 |
1182 // Iterates over all roots in the heap. | 1182 // Iterates over all roots in the heap. |
1183 void IterateRoots(ObjectVisitor* v, VisitMode mode); | 1183 void IterateRoots(RootVisitor* v, VisitMode mode); |
1184 // Iterates over all strong roots in the heap. | 1184 // Iterates over all strong roots in the heap. |
1185 void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); | 1185 void IterateStrongRoots(RootVisitor* v, VisitMode mode); |
1186 // Iterates over entries in the smi roots list. Only interesting to the | 1186 // Iterates over entries in the smi roots list. Only interesting to the |
1187 // serializer/deserializer, since GC does not care about smis. | 1187 // serializer/deserializer, since GC does not care about smis. |
1188 void IterateSmiRoots(ObjectVisitor* v); | 1188 void IterateSmiRoots(RootVisitor* v); |
1189 // Iterates over all the other roots in the heap. | 1189 // Iterates over all the other roots in the heap. |
1190 void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); | 1190 void IterateWeakRoots(RootVisitor* v, VisitMode mode); |
1191 | 1191 |
1192 // Iterate pointers of promoted objects. | 1192 // Iterate pointers of promoted objects. |
1193 void IterateAndScavengePromotedObject(HeapObject* target, int size, | 1193 void IterateAndScavengePromotedObject(HeapObject* target, int size, |
1194 bool was_marked_black); | 1194 bool was_marked_black); |
1195 | 1195 |
1196 // =========================================================================== | 1196 // =========================================================================== |
1197 // Store buffer API. ========================================================= | 1197 // Store buffer API. ========================================================= |
1198 // =========================================================================== | 1198 // =========================================================================== |
1199 | 1199 |
1200 // Write barrier support for object[offset] = o; | 1200 // Write barrier support for object[offset] = o; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 class PretenuringScope; | 1531 class PretenuringScope; |
1532 | 1532 |
1533 // External strings table is a place where all external strings are | 1533 // External strings table is a place where all external strings are |
1534 // registered. We need to keep track of such strings to properly | 1534 // registered. We need to keep track of such strings to properly |
1535 // finalize them. | 1535 // finalize them. |
1536 class ExternalStringTable { | 1536 class ExternalStringTable { |
1537 public: | 1537 public: |
1538 // Registers an external string. | 1538 // Registers an external string. |
1539 inline void AddString(String* string); | 1539 inline void AddString(String* string); |
1540 | 1540 |
1541 inline void IterateAll(ObjectVisitor* v); | 1541 inline void IterateAll(RootVisitor* v); |
1542 inline void IterateNewSpaceStrings(ObjectVisitor* v); | 1542 inline void IterateNewSpaceStrings(RootVisitor* v); |
1543 inline void PromoteAllNewSpaceStrings(); | 1543 inline void PromoteAllNewSpaceStrings(); |
1544 | 1544 |
1545 // Restores internal invariant and gets rid of collected strings. Must be | 1545 // Restores internal invariant and gets rid of collected strings. Must be |
1546 // called after each Iterate*() that modified the strings. | 1546 // called after each Iterate*() that modified the strings. |
1547 void CleanUpAll(); | 1547 void CleanUpAll(); |
1548 void CleanUpNewSpaceStrings(); | 1548 void CleanUpNewSpaceStrings(); |
1549 | 1549 |
1550 // Destroys all allocated memory. | 1550 // Destroys all allocated memory. |
1551 void TearDown(); | 1551 void TearDown(); |
1552 | 1552 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 void MinorMarkCompact(); | 1815 void MinorMarkCompact(); |
1816 | 1816 |
1817 // Code to be run before and after mark-compact. | 1817 // Code to be run before and after mark-compact. |
1818 void MarkCompactPrologue(); | 1818 void MarkCompactPrologue(); |
1819 void MarkCompactEpilogue(); | 1819 void MarkCompactEpilogue(); |
1820 | 1820 |
1821 // Performs a minor collection in new generation. | 1821 // Performs a minor collection in new generation. |
1822 void Scavenge(); | 1822 void Scavenge(); |
1823 void EvacuateYoungGeneration(); | 1823 void EvacuateYoungGeneration(); |
1824 | 1824 |
1825 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); | 1825 Address DoScavenge(Address new_space_front); |
1826 | 1826 |
1827 void UpdateNewSpaceReferencesInExternalStringTable( | 1827 void UpdateNewSpaceReferencesInExternalStringTable( |
1828 ExternalStringTableUpdaterCallback updater_func); | 1828 ExternalStringTableUpdaterCallback updater_func); |
1829 | 1829 |
1830 void UpdateReferencesInExternalStringTable( | 1830 void UpdateReferencesInExternalStringTable( |
1831 ExternalStringTableUpdaterCallback updater_func); | 1831 ExternalStringTableUpdaterCallback updater_func); |
1832 | 1832 |
1833 void ProcessAllWeakReferences(WeakObjectRetainer* retainer); | 1833 void ProcessAllWeakReferences(WeakObjectRetainer* retainer); |
1834 void ProcessYoungWeakReferences(WeakObjectRetainer* retainer); | 1834 void ProcessYoungWeakReferences(WeakObjectRetainer* retainer); |
1835 void ProcessNativeContexts(WeakObjectRetainer* retainer); | 1835 void ProcessNativeContexts(WeakObjectRetainer* retainer); |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2449 private: | 2449 private: |
2450 Heap* heap_; | 2450 Heap* heap_; |
2451 }; | 2451 }; |
2452 | 2452 |
2453 | 2453 |
2454 // Visitor class to verify interior pointers in spaces that do not contain | 2454 // Visitor class to verify interior pointers in spaces that do not contain |
2455 // or care about intergenerational references. All heap object pointers have to | 2455 // or care about intergenerational references. All heap object pointers have to |
2456 // point into the heap to a location that has a map pointer at its first word. | 2456 // point into the heap to a location that has a map pointer at its first word. |
2457 // Caveat: Heap::Contains is an approximation because it can return true for | 2457 // Caveat: Heap::Contains is an approximation because it can return true for |
2458 // objects in a heap space but above the allocation pointer. | 2458 // objects in a heap space but above the allocation pointer. |
2459 class VerifyPointersVisitor : public ObjectVisitor { | 2459 class VerifyPointersVisitor : public ObjectVisitor, public RootVisitor { |
2460 public: | 2460 public: |
2461 inline void VisitPointers(Object** start, Object** end) override; | 2461 inline void VisitPointers(Object** start, Object** end) override; |
| 2462 inline void VisitRootPointers(Root root, Object** start, |
| 2463 Object** end) override; |
| 2464 |
| 2465 private: |
| 2466 inline void VerifyPointers(Object** start, Object** end); |
2462 }; | 2467 }; |
2463 | 2468 |
2464 | 2469 |
2465 // Verify that all objects are Smis. | 2470 // Verify that all objects are Smis. |
2466 class VerifySmisVisitor : public ObjectVisitor { | 2471 class VerifySmisVisitor : public RootVisitor { |
2467 public: | 2472 public: |
2468 inline void VisitPointers(Object** start, Object** end) override; | 2473 inline void VisitRootPointers(Root root, Object** start, |
| 2474 Object** end) override; |
2469 }; | 2475 }; |
2470 | 2476 |
2471 | 2477 |
2472 // Space iterator for iterating over all spaces of the heap. Returns each space | 2478 // Space iterator for iterating over all spaces of the heap. Returns each space |
2473 // in turn, and null when it is done. | 2479 // in turn, and null when it is done. |
2474 class AllSpaces BASE_EMBEDDED { | 2480 class AllSpaces BASE_EMBEDDED { |
2475 public: | 2481 public: |
2476 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {} | 2482 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {} |
2477 Space* next(); | 2483 Space* next(); |
2478 | 2484 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2621 friend class LargeObjectSpace; | 2627 friend class LargeObjectSpace; |
2622 friend class NewSpace; | 2628 friend class NewSpace; |
2623 friend class PagedSpace; | 2629 friend class PagedSpace; |
2624 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); | 2630 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); |
2625 }; | 2631 }; |
2626 | 2632 |
2627 } // namespace internal | 2633 } // namespace internal |
2628 } // namespace v8 | 2634 } // namespace v8 |
2629 | 2635 |
2630 #endif // V8_HEAP_HEAP_H_ | 2636 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |