1 // Copyright 2014 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_GC_IDLE_TIME_HANDLER_H_ 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ 7 8 #include "src/common/globals.h" 9 10 namespace v8 { 11 namespace internal { 12 13 enum class GCIdleTimeAction : uint8_t { 14 kDone, 15 kIncrementalStep, 16 }; 17 18 class GCIdleTimeHeapState { 19 public: 20 void Print(); 21 22 size_t size_of_objects; 23 bool incremental_marking_stopped; 24 }; 25 26 27 // The idle time handler makes decisions about which garbage collection 28 // operations are executing during IdleNotification. 29 class V8_EXPORT_PRIVATE GCIdleTimeHandler { 30 public: 31 // If we haven't recorded any incremental marking events yet, we carefully 32 // mark with a conservative lower bound for the marking speed. 33 static const size_t kInitialConservativeMarkingSpeed = 100 * KB; 34 35 // Maximum marking step size returned by EstimateMarkingStepSize. 36 static const size_t kMaximumMarkingStepSize = 700 * MB; 37 38 // We have to make sure that we finish the IdleNotification before 39 // idle_time_in_ms. Hence, we conservatively prune our workload estimate. 40 static const double kConservativeTimeRatio; 41 42 // This is the maximum scheduled idle time. Note that it can be more than 43 // 16.66 ms when there is currently no rendering going on. 44 static const size_t kMaxScheduledIdleTime = 50; 45 46 GCIdleTimeHandler() = default; 47 GCIdleTimeHandler(const GCIdleTimeHandler&) = delete; 48 GCIdleTimeHandler& operator=(const GCIdleTimeHandler&) = delete; 49 50 GCIdleTimeAction Compute(double idle_time_in_ms, 51 GCIdleTimeHeapState heap_state); 52 53 bool Enabled(); 54 55 static size_t EstimateMarkingStepSize(double idle_time_in_ms, 56 double marking_speed_in_bytes_per_ms); 57 58 static double EstimateFinalIncrementalMarkCompactTime( 59 size_t size_of_objects, double mark_compact_speed_in_bytes_per_ms); 60 }; 61 62 } // namespace internal 63 } // namespace v8 64 65 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ 66