14template <
typename Trait>
16 Heap*
heap,
size_t max_heap_size, std::optional<double> gc_speed,
17 double mutator_speed, Heap::HeapGrowingMode growing_mode) {
18 const double max_factor = MaxGrowingFactor(max_heap_size);
19 double factor = DynamicGrowingFactor(gc_speed, mutator_speed, max_factor);
20 switch (growing_mode) {
21 case Heap::HeapGrowingMode::kConservative:
22 case Heap::HeapGrowingMode::kSlow:
23 factor = std::min({factor, Trait::kConservativeGrowingFactor});
25 case Heap::HeapGrowingMode::kMinimal:
26 factor = Trait::kMinGrowingFactor;
28 case Heap::HeapGrowingMode::kDefault:
31 if (
v8_flags.heap_growing_percent > 0) {
32 factor = 1.0 +
v8_flags.heap_growing_percent / 100.0;
36 "[%s] factor %.1f based on mu=%.3f, speed_ratio=%.f "
37 "(gc=%.f, mutator=%.f)\n",
38 Trait::kName, factor, Trait::kTargetMutatorUtilization,
39 gc_speed.value_or(0) / mutator_speed, gc_speed.value_or(0),
45template <
typename Trait>
47 constexpr double kMinSmallFactor = 1.3;
48 constexpr double kMaxSmallFactor = 2.0;
49 constexpr double kHighFactor = 4.0;
53 if (max_heap_size >= Trait::kMaxSize) {
57 size_t max_size = std::max({max_heap_size, Trait::kMinSize});
63 double factor = kMinSmallFactor + (kMaxSmallFactor - kMinSmallFactor) *
64 (max_size - Trait::kMinSize) /
65 (Trait::kMaxSize - Trait::kMinSize);
108template <
typename Trait>
110 std::optional<double> gc_speed,
double mutator_speed,
double max_factor) {
111 DCHECK_LE(Trait::kMinGrowingFactor, max_factor);
112 DCHECK_GE(Trait::kMaxGrowingFactor, max_factor);
113 if (!gc_speed || mutator_speed == 0)
return max_factor;
115 const double speed_ratio = *gc_speed / mutator_speed;
117 const double a = speed_ratio * (1 - Trait::kTargetMutatorUtilization);
118 const double b = speed_ratio * (1 - Trait::kTargetMutatorUtilization) -
119 Trait::kTargetMutatorUtilization;
122 double factor = (a < b * max_factor) ? a / b : max_factor;
124 factor = std::max({factor, Trait::kMinGrowingFactor});
128template <
typename Trait>
130 Heap::HeapGrowingMode growing_mode) {
131 const size_t kRegularAllocationLimitGrowingStep = 8;
132 const size_t kLowMemoryAllocationLimitGrowingStep = 2;
134 return limit * (growing_mode == Heap::HeapGrowingMode::kConservative
135 ? kLowMemoryAllocationLimitGrowingStep
136 : kRegularAllocationLimitGrowingStep);
139template <
typename Trait>
141 Heap*
heap,
size_t current_size, uint64_t limit,
size_t min_size,
142 size_t max_size,
size_t new_space_capacity,
143 Heap::HeapGrowingMode growing_mode) {
145 limit = std::max(limit,
static_cast<uint64_t
>(current_size) +
146 MinimumAllocationLimitGrowingStep(growing_mode)) +
148 const uint64_t halfway_to_the_max =
149 (
static_cast<uint64_t
>(current_size) + max_size) / 2;
150 const uint64_t limit_or_halfway =
151 std::min<uint64_t>(limit, halfway_to_the_max);
153 static_cast<size_t>(std::max<uint64_t>(limit_or_halfway, min_size));
156 "[%s] Limit: old size: %zu KB, new limit: %zu KB\n", Trait::kName,
157 current_size / KB,
result / KB);
static Isolate * FromHeap(const Heap *heap)
static double GrowingFactor(Heap *heap, size_t max_heap_size, std::optional< double > gc_speed, double mutator_speed, Heap::HeapGrowingMode growing_mode)
static double DynamicGrowingFactor(std::optional< double > gc_speed, double mutator_speed, double max_factor)
static size_t MinimumAllocationLimitGrowingStep(Heap::HeapGrowingMode growing_mode)
static size_t BoundAllocationLimit(Heap *heap, size_t current_size, uint64_t limit, size_t min_size, size_t max_size, size_t new_space_capacity, Heap::HeapGrowingMode growing_mode)
static double MaxGrowingFactor(size_t max_heap_size)
static const int kPageSize
ZoneVector< RpoNumber > & result
V8_EXPORT_PRIVATE FlagValues v8_flags
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage * MB
#define DCHECK_LE(v1, v2)
#define CHECK_LT(lhs, rhs)
#define DCHECK_GE(v1, v2)
#define DCHECK_LT(v1, v2)
#define V8_EXPORT_PRIVATE
#define V8_UNLIKELY(condition)