aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/heap-controller.h
blob: d4a3534cd7d734a6108f0670fa99feda26fe42e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_HEAP_CONTROLLER_H_
#define V8_HEAP_HEAP_CONTROLLER_H_

#include <cstddef>
#include "src/heap/heap.h"
#include "src/utils/allocation.h"
#include "testing/gtest/include/gtest/gtest_prod.h"  // nogncheck

namespace v8 {
namespace internal {

struct BaseControllerTrait {
  static constexpr size_t kMinSize = 128u * Heap::kPointerMultiplier * MB;
  static constexpr size_t kMaxSize = 1024u * Heap::kPointerMultiplier * MB;

  static constexpr double kMinGrowingFactor = 1.1;
  static constexpr double kMaxGrowingFactor = 4.0;
  static constexpr double kConservativeGrowingFactor = 1.3;
  static constexpr double kTargetMutatorUtilization = 0.97;
};

struct V8HeapTrait : public BaseControllerTrait {
  static const char* kName;
};

struct GlobalMemoryTrait : public BaseControllerTrait {
  static const char* kName;
};

template <typename Trait>
class V8_EXPORT_PRIVATE MemoryController : public AllStatic {
 public:
  // Computes the growing step when the limit increases.
  static size_t MinimumAllocationLimitGrowingStep(
      Heap::HeapGrowingMode growing_mode);

  static double GrowingFactor(Heap* heap, size_t max_heap_size, double gc_speed,
                              double mutator_speed);

  static size_t CalculateAllocationLimit(Heap* heap, size_t current_size,
                                         size_t min_size, size_t max_size,
                                         size_t new_space_capacity,
                                         double factor,
                                         Heap::HeapGrowingMode growing_mode);

 private:
  static double MaxGrowingFactor(size_t max_heap_size);
  static double DynamicGrowingFactor(double gc_speed, double mutator_speed,
                                     double max_factor);

  FRIEND_TEST(MemoryControllerTest, HeapGrowingFactor);
  FRIEND_TEST(MemoryControllerTest, MaxHeapGrowingFactor);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_HEAP_CONTROLLER_H_