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: MemoryController(Heap * heap,double min_growing_factor,double max_growing_factor,double conservative_growing_factor,double target_mutator_utilization,size_t min_size,size_t max_size)18 MemoryController(Heap* heap, double min_growing_factor, 19 double max_growing_factor, 20 double conservative_growing_factor, 21 double target_mutator_utilization, size_t min_size, 22 size_t max_size) 23 : heap_(heap), 24 kMinGrowingFactor(min_growing_factor), 25 kMaxGrowingFactor(max_growing_factor), 26 kConservativeGrowingFactor(conservative_growing_factor), 27 kTargetMutatorUtilization(target_mutator_utilization), 28 kMinSize(min_size), 29 kMaxSize(max_size) {} ~MemoryController()30 virtual ~MemoryController() {} 31 32 // Computes the allocation limit to trigger the next garbage collection. 33 size_t CalculateAllocationLimit(size_t curr_size, size_t max_size, 34 double gc_speed, double mutator_speed, 35 size_t new_space_capacity, 36 Heap::HeapGrowingMode growing_mode); 37 38 // Computes the growing step when the limit increases. 39 size_t MinimumAllocationLimitGrowingStep(Heap::HeapGrowingMode growing_mode); 40 41 protected: 42 double GrowingFactor(double gc_speed, double mutator_speed, 43 double max_factor); 44 double MaxGrowingFactor(size_t curr_max_size); 45 virtual const char* ControllerName() = 0; 46 47 Heap* const heap_; 48 49 const double kMinGrowingFactor; 50 const double kMaxGrowingFactor; 51 const double kConservativeGrowingFactor; 52 const double kTargetMutatorUtilization; 53 // Sizes are in MB. 54 const size_t kMinSize; 55 const size_t kMaxSize; 56 57 FRIEND_TEST(HeapControllerTest, HeapGrowingFactor); 58 FRIEND_TEST(HeapControllerTest, MaxHeapGrowingFactor); 59 FRIEND_TEST(HeapControllerTest, MaxOldGenerationSize); 60 FRIEND_TEST(HeapControllerTest, OldGenerationAllocationLimit); 61 }; 62 63 class HeapController : public MemoryController { 64 public: HeapController(Heap * heap)65 explicit HeapController(Heap* heap) 66 : MemoryController(heap, 1.1, 4.0, 1.3, 0.97, kMinHeapSize, 67 kMaxHeapSize) {} 68 69 // Sizes are in MB. 70 static const size_t kMinHeapSize = 128 * Heap::kPointerMultiplier; 71 static const size_t kMaxHeapSize = 1024 * Heap::kPointerMultiplier; 72 73 protected: ControllerName()74 const char* ControllerName() { return "HeapController"; } 75 }; 76 77 } // namespace internal 78 } // namespace v8 79 80 #endif // V8_HEAP_HEAP_CONTROLLER_H_ 81