Line data Source code
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/allocation.h"
10 : #include "src/heap/heap.h"
11 : #include "testing/gtest/include/gtest/gtest_prod.h" // nogncheck
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class V8_EXPORT_PRIVATE MemoryController {
17 : public:
18 : MemoryController(Heap* heap, double min_growing_factor,
19 : double max_growing_factor,
20 : double conservative_growing_factor,
21 : double target_mutator_utilization)
22 : : heap_(heap),
23 : min_growing_factor_(min_growing_factor),
24 : max_growing_factor_(max_growing_factor),
25 : conservative_growing_factor_(conservative_growing_factor),
26 62425 : target_mutator_utilization_(target_mutator_utilization) {}
27 62407 : virtual ~MemoryController() = default;
28 :
29 : // Computes the allocation limit to trigger the next garbage collection.
30 : size_t CalculateAllocationLimit(size_t curr_size, size_t max_size,
31 : double max_factor, double gc_speed,
32 : double mutator_speed,
33 : size_t new_space_capacity,
34 : Heap::HeapGrowingMode growing_mode);
35 :
36 : // Computes the growing step when the limit increases.
37 : size_t MinimumAllocationLimitGrowingStep(Heap::HeapGrowingMode growing_mode);
38 :
39 : protected:
40 : double GrowingFactor(double gc_speed, double mutator_speed,
41 : double max_factor);
42 : virtual const char* ControllerName() = 0;
43 :
44 : Heap* const heap_;
45 : const double min_growing_factor_;
46 : const double max_growing_factor_;
47 : const double conservative_growing_factor_;
48 : const double target_mutator_utilization_;
49 :
50 : FRIEND_TEST(HeapControllerTest, HeapGrowingFactor);
51 : FRIEND_TEST(HeapControllerTest, MaxHeapGrowingFactor);
52 : FRIEND_TEST(HeapControllerTest, MaxOldGenerationSize);
53 : FRIEND_TEST(HeapControllerTest, OldGenerationAllocationLimit);
54 : };
55 :
56 124811 : class V8_EXPORT_PRIVATE HeapController : public MemoryController {
57 : public:
58 : // Sizes are in MB.
59 : static constexpr size_t kMinSize = 128 * Heap::kPointerMultiplier;
60 : static constexpr size_t kMaxSize = 1024 * Heap::kPointerMultiplier;
61 :
62 : explicit HeapController(Heap* heap)
63 62425 : : MemoryController(heap, 1.1, 4.0, 1.3, 0.97) {}
64 : double MaxGrowingFactor(size_t curr_max_size);
65 :
66 : protected:
67 0 : const char* ControllerName() override { return "HeapController"; }
68 : };
69 :
70 : } // namespace internal
71 : } // namespace v8
72 :
73 : #endif // V8_HEAP_HEAP_CONTROLLER_H_
|