• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_HEAP_HEAP_CONTROLLER_H_
6 #define V8_HEAP_HEAP_CONTROLLER_H_
7 
8 #include <cstddef>
9 #include "src/heap/heap.h"
10 #include "src/utils/allocation.h"
11 #include "testing/gtest/include/gtest/gtest_prod.h"  // nogncheck
12 
13 namespace v8 {
14 namespace internal {
15 
16 struct BaseControllerTrait {
17   static constexpr size_t kMinSize = 128u * Heap::kHeapLimitMultiplier * MB;
18   static constexpr size_t kMaxSize = 1024u * Heap::kHeapLimitMultiplier * MB;
19 
20   static constexpr double kMinGrowingFactor = 1.1;
21   static constexpr double kMaxGrowingFactor = 4.0;
22   static constexpr double kConservativeGrowingFactor = 1.3;
23   static constexpr double kTargetMutatorUtilization = 0.97;
24 };
25 
26 struct V8HeapTrait : public BaseControllerTrait {
27   static const char* kName;
28 };
29 
30 struct GlobalMemoryTrait : public BaseControllerTrait {
31   static const char* kName;
32 };
33 
34 template <typename Trait>
35 class V8_EXPORT_PRIVATE MemoryController : public AllStatic {
36  public:
37   // Computes the growing step when the limit increases.
38   static size_t MinimumAllocationLimitGrowingStep(
39       Heap::HeapGrowingMode growing_mode);
40 
41   static double GrowingFactor(Heap* heap, size_t max_heap_size, double gc_speed,
42                               double mutator_speed);
43 
44   static size_t CalculateAllocationLimit(Heap* heap, size_t current_size,
45                                          size_t min_size, size_t max_size,
46                                          size_t new_space_capacity,
47                                          double factor,
48                                          Heap::HeapGrowingMode growing_mode);
49 
50  private:
51   static double MaxGrowingFactor(size_t max_heap_size);
52   static double DynamicGrowingFactor(double gc_speed, double mutator_speed,
53                                      double max_factor);
54 
55   FRIEND_TEST(MemoryControllerTest, HeapGrowingFactor);
56   FRIEND_TEST(MemoryControllerTest, MaxHeapGrowingFactor);
57 };
58 
59 }  // namespace internal
60 }  // namespace v8
61 
62 #endif  // V8_HEAP_HEAP_CONTROLLER_H_
63