1 // Copyright 2020 the V8 project 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 V8_HEAP_CPPGC_HEAP_GROWING_H_ 6 #define V8_HEAP_CPPGC_HEAP_GROWING_H_ 7 8 #include "include/cppgc/heap.h" 9 #include "src/base/macros.h" 10 #include "src/heap/cppgc/globals.h" 11 #include "src/heap/cppgc/raw-heap.h" 12 13 namespace cppgc { 14 15 class Platform; 16 17 namespace internal { 18 19 class GarbageCollector; 20 class StatsCollector; 21 22 // Growing strategy that invokes garbage collection using GarbageCollector based 23 // on allocation statistics provided by StatsCollector and ResourceConstraints. 24 // 25 // Implements a fixed-ratio growing strategy with an initial heap size that the 26 // GC can ignore to avoid excessive GCs for smaller heaps. 27 class V8_EXPORT_PRIVATE HeapGrowing final { 28 public: 29 // Constant growing factor for growing the heap limit. 30 static constexpr double kGrowingFactor = 1.5; 31 // For smaller heaps, allow allocating at least LAB in each regular space 32 // before triggering GC again. 33 static constexpr size_t kMinLimitIncrease = 34 kPageSize * RawHeap::kNumberOfRegularSpaces; 35 36 HeapGrowing(GarbageCollector*, StatsCollector*, 37 cppgc::Heap::ResourceConstraints); 38 ~HeapGrowing(); 39 40 HeapGrowing(const HeapGrowing&) = delete; 41 HeapGrowing& operator=(const HeapGrowing&) = delete; 42 43 size_t limit_for_atomic_gc() const; 44 size_t limit_for_incremental_gc() const; 45 46 void DisableForTesting(); 47 48 private: 49 class HeapGrowingImpl; 50 std::unique_ptr<HeapGrowingImpl> impl_; 51 }; 52 53 } // namespace internal 54 } // namespace cppgc 55 56 #endif // V8_HEAP_CPPGC_HEAP_GROWING_H_ 57