1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_ 7 8 // BlinkGC.h is a file that defines common things used by Blink GC. 9 10 #include "third_party/blink/renderer/platform/platform_export.h" 11 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" 12 13 #define PRINT_HEAP_STATS 0 // Enable this macro to print heap stats to stderr. 14 15 namespace blink { 16 17 class WeakCallbackInfo; 18 class MarkingVisitor; 19 class Visitor; 20 21 using Address = uint8_t*; 22 using ConstAddress = const uint8_t*; 23 24 using FinalizationCallback = void (*)(void*); 25 using VisitorCallback = void (*)(Visitor*, const void*); 26 using MarkingVisitorCallback = void (*)(MarkingVisitor*, const void*); 27 using TraceCallback = VisitorCallback; 28 using WeakCallback = void (*)(const WeakCallbackInfo&, const void*); 29 using EphemeronCallback = VisitorCallback; 30 31 // Simple alias to avoid heap compaction type signatures turning into 32 // a sea of generic |void*|s. 33 using MovableReference = const void*; 34 35 // Heap compaction supports registering callbacks that are to be invoked 36 // when an object is moved during compaction. This is to support internal 37 // location fixups that need to happen as a result. 38 // 39 // i.e., when the object residing at |from| is moved to |to| by the compaction 40 // pass, invoke the callback to adjust any internal references that now need 41 // to be |to|-relative. 42 using MovingObjectCallback = void (*)(MovableReference from, 43 MovableReference to, 44 size_t); 45 46 // List of all arenas. Includes typed arenas as well. 47 #define FOR_EACH_ARENA(H) \ 48 H(NormalPage1) \ 49 H(NormalPage2) \ 50 H(NormalPage3) \ 51 H(NormalPage4) \ 52 H(Vector) \ 53 H(HashTable) \ 54 H(Node) \ 55 H(CSSValue) \ 56 H(LargeObject) 57 58 class PLATFORM_EXPORT WorklistTaskId { 59 public: 60 static constexpr int MutatorThread = 0; 61 static constexpr int ConcurrentThreadBase = 1; 62 }; 63 64 class PLATFORM_EXPORT BlinkGC final { 65 STATIC_ONLY(BlinkGC); 66 67 public: 68 // CollectionType represents generational collection. kMinor collects objects 69 // in the young generation (i.e. allocated since the previous collection 70 // cycle, since we use sticky bits), kMajor collects the entire heap. 71 enum class CollectionType { kMinor, kMajor }; 72 73 // When garbage collecting we need to know whether or not there 74 // can be pointers to Blink GC managed objects on the stack for 75 // each thread. When threads reach a safe point they record 76 // whether or not they have pointers on the stack. 77 enum StackState { kNoHeapPointersOnStack, kHeapPointersOnStack }; 78 79 enum MarkingType { 80 // The marking completes synchronously. 81 kAtomicMarking, 82 // The marking task is split and executed in chunks (either on the mutator 83 // thread or concurrently). 84 kIncrementalAndConcurrentMarking 85 }; 86 87 enum SweepingType { 88 // The sweeping task is split into chunks and scheduled lazily and 89 // concurrently. 90 kConcurrentAndLazySweeping, 91 // The sweeping task executes synchronously right after marking. 92 kEagerSweeping, 93 }; 94 95 // Commented out reasons have been used in the past but are not used any 96 // longer. We keep them here as the corresponding UMA histograms cannot be 97 // changed. 98 enum class GCReason { 99 // kIdleGC = 0, 100 kPreciseGC = 1, 101 kConservativeGC = 2, 102 kForcedGCForTesting = 3, 103 kMemoryPressureGC = 4, 104 // kPageNavigationGC = 5, 105 kThreadTerminationGC = 6, 106 // kTesting = 7, 107 // kIncrementalIdleGC = 8, 108 kIncrementalV8FollowupGC = 9, 109 kUnifiedHeapGC = 10, 110 kUnifiedHeapForMemoryReductionGC = 11, 111 kMaxValue = kUnifiedHeapForMemoryReductionGC, 112 }; 113 114 #define DeclareArenaIndex(name) k##name##ArenaIndex, 115 enum ArenaIndices { 116 FOR_EACH_ARENA(DeclareArenaIndex) 117 // Values used for iteration of heap segments. 118 kNumberOfArenas, 119 }; 120 #undef DeclareArenaIndex 121 122 enum V8GCType { 123 kV8MinorGC, 124 kV8MajorGC, 125 }; 126 127 // Sentinel used to mark not-fully-constructed during mixins. 128 static constexpr void* kNotFullyConstructedObject = nullptr; 129 130 static const char* ToString(GCReason); 131 static const char* ToString(MarkingType); 132 static const char* ToString(StackState); 133 static const char* ToString(SweepingType); 134 static const char* ToString(ArenaIndices); 135 }; 136 137 } // namespace blink 138 139 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_ 140