• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, cppgc::Heap::MarkingType,
38               cppgc::Heap::SweepingType);
39   ~HeapGrowing();
40 
41   HeapGrowing(const HeapGrowing&) = delete;
42   HeapGrowing& operator=(const HeapGrowing&) = delete;
43 
44   size_t limit_for_atomic_gc() const;
45   size_t limit_for_incremental_gc() const;
46 
47   void DisableForTesting();
48 
49  private:
50   class HeapGrowingImpl;
51   std::unique_ptr<HeapGrowingImpl> impl_;
52 };
53 
54 }  // namespace internal
55 }  // namespace cppgc
56 
57 #endif  // V8_HEAP_CPPGC_HEAP_GROWING_H_
58