Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: src/heap/heap.h

Issue 2801073006: Decouple root visitors from object visitors. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/global-handles.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 class HistogramTimer; 351 class HistogramTimer;
351 class Isolate; 352 class Isolate;
352 class LocalEmbedderHeapTracer; 353 class LocalEmbedderHeapTracer;
353 class MemoryAllocator; 354 class MemoryAllocator;
354 class MemoryReducer; 355 class MemoryReducer;
355 class MinorMarkCompactCollector; 356 class MinorMarkCompactCollector;
356 class ObjectIterator; 357 class ObjectIterator;
357 class ObjectStats; 358 class ObjectStats;
358 class Page; 359 class Page;
359 class PagedSpace; 360 class PagedSpace;
361 class RootVisitor;
360 class Scavenger; 362 class Scavenger;
361 class ScavengeJob; 363 class ScavengeJob;
362 class Space; 364 class Space;
363 class StoreBuffer; 365 class StoreBuffer;
364 class TracePossibleWrapperReporter; 366 class TracePossibleWrapperReporter;
365 class WeakObjectRetainer; 367 class WeakObjectRetainer;
366 368
367 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to); 369 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to);
368 370
369 enum ArrayStorageAllocationMode { 371 enum ArrayStorageAllocationMode {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 810
809 // Used in CreateAllocationSiteStub and the (de)serializer. 811 // Used in CreateAllocationSiteStub and the (de)serializer.
810 Object** allocation_sites_list_address() { return &allocation_sites_list_; } 812 Object** allocation_sites_list_address() { return &allocation_sites_list_; }
811 813
812 void set_encountered_weak_collections(Object* weak_collection) { 814 void set_encountered_weak_collections(Object* weak_collection) {
813 encountered_weak_collections_ = weak_collection; 815 encountered_weak_collections_ = weak_collection;
814 } 816 }
815 Object* encountered_weak_collections() const { 817 Object* encountered_weak_collections() const {
816 return encountered_weak_collections_; 818 return encountered_weak_collections_;
817 } 819 }
818 void VisitEncounteredWeakCollections(ObjectVisitor* visitor) { 820 void IterateEncounteredWeakCollections(RootVisitor* visitor);
819 visitor->VisitPointer(&encountered_weak_collections_);
820 }
821 821
822 void set_encountered_weak_cells(Object* weak_cell) { 822 void set_encountered_weak_cells(Object* weak_cell) {
823 encountered_weak_cells_ = weak_cell; 823 encountered_weak_cells_ = weak_cell;
824 } 824 }
825 Object* encountered_weak_cells() const { return encountered_weak_cells_; } 825 Object* encountered_weak_cells() const { return encountered_weak_cells_; }
826 826
827 void set_encountered_transition_arrays(Object* transition_array) { 827 void set_encountered_transition_arrays(Object* transition_array) {
828 encountered_transition_arrays_ = transition_array; 828 encountered_transition_arrays_ = transition_array;
829 } 829 }
830 Object* encountered_transition_arrays() const { 830 Object* encountered_transition_arrays() const {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 void ReportExternalMemoryPressure(); 1198 void ReportExternalMemoryPressure();
1199 1199
1200 // Invoked when GC was requested via the stack guard. 1200 // Invoked when GC was requested via the stack guard.
1201 void HandleGCRequest(); 1201 void HandleGCRequest();
1202 1202
1203 // =========================================================================== 1203 // ===========================================================================
1204 // Iterators. ================================================================ 1204 // Iterators. ================================================================
1205 // =========================================================================== 1205 // ===========================================================================
1206 1206
1207 // Iterates over all roots in the heap. 1207 // Iterates over all roots in the heap.
1208 void IterateRoots(ObjectVisitor* v, VisitMode mode); 1208 void IterateRoots(RootVisitor* v, VisitMode mode);
1209 // Iterates over all strong roots in the heap. 1209 // Iterates over all strong roots in the heap.
1210 void IterateStrongRoots(ObjectVisitor* v, VisitMode mode); 1210 void IterateStrongRoots(RootVisitor* v, VisitMode mode);
1211 // Iterates over entries in the smi roots list. Only interesting to the 1211 // Iterates over entries in the smi roots list. Only interesting to the
1212 // serializer/deserializer, since GC does not care about smis. 1212 // serializer/deserializer, since GC does not care about smis.
1213 void IterateSmiRoots(ObjectVisitor* v); 1213 void IterateSmiRoots(RootVisitor* v);
1214 // Iterates over all the other roots in the heap. 1214 // Iterates over all the other roots in the heap.
1215 void IterateWeakRoots(ObjectVisitor* v, VisitMode mode); 1215 void IterateWeakRoots(RootVisitor* v, VisitMode mode);
1216 1216
1217 // Iterate pointers of promoted objects. 1217 // Iterate pointers of promoted objects.
1218 void IterateAndScavengePromotedObject(HeapObject* target, int size, 1218 void IterateAndScavengePromotedObject(HeapObject* target, int size,
1219 bool was_marked_black); 1219 bool was_marked_black);
1220 1220
1221 // =========================================================================== 1221 // ===========================================================================
1222 // Store buffer API. ========================================================= 1222 // Store buffer API. =========================================================
1223 // =========================================================================== 1223 // ===========================================================================
1224 1224
1225 // Write barrier support for object[offset] = o; 1225 // Write barrier support for object[offset] = o;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 class PretenuringScope; 1562 class PretenuringScope;
1563 1563
1564 // External strings table is a place where all external strings are 1564 // External strings table is a place where all external strings are
1565 // registered. We need to keep track of such strings to properly 1565 // registered. We need to keep track of such strings to properly
1566 // finalize them. 1566 // finalize them.
1567 class ExternalStringTable { 1567 class ExternalStringTable {
1568 public: 1568 public:
1569 // Registers an external string. 1569 // Registers an external string.
1570 inline void AddString(String* string); 1570 inline void AddString(String* string);
1571 1571
1572 inline void IterateAll(ObjectVisitor* v); 1572 inline void IterateAll(RootVisitor* v);
1573 inline void IterateNewSpaceStrings(ObjectVisitor* v); 1573 inline void IterateNewSpaceStrings(RootVisitor* v);
1574 inline void PromoteAllNewSpaceStrings(); 1574 inline void PromoteAllNewSpaceStrings();
1575 1575
1576 // Restores internal invariant and gets rid of collected strings. Must be 1576 // Restores internal invariant and gets rid of collected strings. Must be
1577 // called after each Iterate*() that modified the strings. 1577 // called after each Iterate*() that modified the strings.
1578 void CleanUpAll(); 1578 void CleanUpAll();
1579 void CleanUpNewSpaceStrings(); 1579 void CleanUpNewSpaceStrings();
1580 1580
1581 // Destroys all allocated memory. 1581 // Destroys all allocated memory.
1582 void TearDown(); 1582 void TearDown();
1583 1583
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 void MinorMarkCompact(); 1846 void MinorMarkCompact();
1847 1847
1848 // Code to be run before and after mark-compact. 1848 // Code to be run before and after mark-compact.
1849 void MarkCompactPrologue(); 1849 void MarkCompactPrologue();
1850 void MarkCompactEpilogue(); 1850 void MarkCompactEpilogue();
1851 1851
1852 // Performs a minor collection in new generation. 1852 // Performs a minor collection in new generation.
1853 void Scavenge(); 1853 void Scavenge();
1854 void EvacuateYoungGeneration(); 1854 void EvacuateYoungGeneration();
1855 1855
1856 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); 1856 Address DoScavenge(Address new_space_front);
1857 1857
1858 void UpdateNewSpaceReferencesInExternalStringTable( 1858 void UpdateNewSpaceReferencesInExternalStringTable(
1859 ExternalStringTableUpdaterCallback updater_func); 1859 ExternalStringTableUpdaterCallback updater_func);
1860 1860
1861 void UpdateReferencesInExternalStringTable( 1861 void UpdateReferencesInExternalStringTable(
1862 ExternalStringTableUpdaterCallback updater_func); 1862 ExternalStringTableUpdaterCallback updater_func);
1863 1863
1864 void ProcessAllWeakReferences(WeakObjectRetainer* retainer); 1864 void ProcessAllWeakReferences(WeakObjectRetainer* retainer);
1865 void ProcessYoungWeakReferences(WeakObjectRetainer* retainer); 1865 void ProcessYoungWeakReferences(WeakObjectRetainer* retainer);
1866 void ProcessNativeContexts(WeakObjectRetainer* retainer); 1866 void ProcessNativeContexts(WeakObjectRetainer* retainer);
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 private: 2480 private:
2481 Heap* heap_; 2481 Heap* heap_;
2482 }; 2482 };
2483 2483
2484 2484
2485 // Visitor class to verify interior pointers in spaces that do not contain 2485 // Visitor class to verify interior pointers in spaces that do not contain
2486 // or care about intergenerational references. All heap object pointers have to 2486 // or care about intergenerational references. All heap object pointers have to
2487 // point into the heap to a location that has a map pointer at its first word. 2487 // point into the heap to a location that has a map pointer at its first word.
2488 // Caveat: Heap::Contains is an approximation because it can return true for 2488 // Caveat: Heap::Contains is an approximation because it can return true for
2489 // objects in a heap space but above the allocation pointer. 2489 // objects in a heap space but above the allocation pointer.
2490 class VerifyPointersVisitor : public ObjectVisitor { 2490 class VerifyPointersVisitor : public ObjectVisitor, public RootVisitor {
2491 public: 2491 public:
2492 inline void VisitPointers(Object** start, Object** end) override; 2492 inline void VisitPointers(Object** start, Object** end) override;
2493 inline void VisitRootPointers(Root root, Object** start,
2494 Object** end) override;
2495
2496 private:
2497 inline void VerifyPointers(Object** start, Object** end);
2493 }; 2498 };
2494 2499
2495 2500
2496 // Verify that all objects are Smis. 2501 // Verify that all objects are Smis.
2497 class VerifySmisVisitor : public ObjectVisitor { 2502 class VerifySmisVisitor : public RootVisitor {
2498 public: 2503 public:
2499 inline void VisitPointers(Object** start, Object** end) override; 2504 inline void VisitRootPointers(Root root, Object** start,
2505 Object** end) override;
2500 }; 2506 };
2501 2507
2502 2508
2503 // Space iterator for iterating over all spaces of the heap. Returns each space 2509 // Space iterator for iterating over all spaces of the heap. Returns each space
2504 // in turn, and null when it is done. 2510 // in turn, and null when it is done.
2505 class AllSpaces BASE_EMBEDDED { 2511 class AllSpaces BASE_EMBEDDED {
2506 public: 2512 public:
2507 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {} 2513 explicit AllSpaces(Heap* heap) : heap_(heap), counter_(FIRST_SPACE) {}
2508 Space* next(); 2514 Space* next();
2509 2515
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 friend class PagedSpace; 2660 friend class PagedSpace;
2655 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); 2661 DISALLOW_COPY_AND_ASSIGN(AllocationObserver);
2656 }; 2662 };
2657 2663
2658 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); 2664 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space);
2659 2665
2660 } // namespace internal 2666 } // namespace internal
2661 } // namespace v8 2667 } // namespace v8
2662 2668
2663 #endif // V8_HEAP_HEAP_H_ 2669 #endif // V8_HEAP_HEAP_H_
OLDNEW
« no previous file with comments | « src/global-handles.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698