summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/heap-controller.h
blob: 717c97a5b8b4b5c73f8c356496dda459ac17d2fd (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
// 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/allocation.h"
#include "src/heap/heap.h"
#include "testing/gtest/include/gtest/gtest_prod.h"  // nogncheck

namespace v8 {
namespace internal {

class HeapController {
 public:
  explicit HeapController(Heap* heap) : heap_(heap) {}

  // Computes the allocation limit to trigger the next full garbage collection.
  V8_EXPORT_PRIVATE size_t CalculateOldGenerationAllocationLimit(
      size_t old_gen_size, size_t max_old_generation_size, double gc_speed,
      double mutator_speed, size_t new_space_capacity,
      Heap::HeapGrowingMode growing_mode);

  size_t MinimumAllocationLimitGrowingStep(Heap::HeapGrowingMode growing_mode);

  // The old space size has to be a multiple of Page::kPageSize.
  // Sizes are in MB.
  static const size_t kMinOldGenerationSize = 128 * Heap::kPointerMultiplier;
  static const size_t kMaxOldGenerationSize = 1024 * Heap::kPointerMultiplier;

 private:
  FRIEND_TEST(HeapController, HeapGrowingFactor);
  FRIEND_TEST(HeapController, MaxHeapGrowingFactor);
  FRIEND_TEST(HeapControllerTest, OldGenerationAllocationLimit);

  V8_EXPORT_PRIVATE static const double kMinHeapGrowingFactor;
  V8_EXPORT_PRIVATE static const double kMaxHeapGrowingFactor;
  V8_EXPORT_PRIVATE static const double kConservativeHeapGrowingFactor;
  V8_EXPORT_PRIVATE static double MaxHeapGrowingFactor(
      size_t max_old_generation_size);
  V8_EXPORT_PRIVATE static double HeapGrowingFactor(double gc_speed,
                                                    double mutator_speed,
                                                    double max_factor);

  static const double kTargetMutatorUtilization;

  Heap* heap_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_HEAP_CONTROLLER_H_