• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   kFullGC,
17 };
18 
19 class GCIdleTimeHeapState {
20  public:
21   void Print();
22 
23   int contexts_disposed;
24   double contexts_disposal_rate;
25   size_t size_of_objects;
26   bool incremental_marking_stopped;
27 };
28 
29 
30 // The idle time handler makes decisions about which garbage collection
31 // operations are executing during IdleNotification.
32 class V8_EXPORT_PRIVATE GCIdleTimeHandler {
33  public:
34   // If we haven't recorded any incremental marking events yet, we carefully
35   // mark with a conservative lower bound for the marking speed.
36   static const size_t kInitialConservativeMarkingSpeed = 100 * KB;
37 
38   // Maximum marking step size returned by EstimateMarkingStepSize.
39   static const size_t kMaximumMarkingStepSize = 700 * MB;
40 
41   // We have to make sure that we finish the IdleNotification before
42   // idle_time_in_ms. Hence, we conservatively prune our workload estimate.
43   static const double kConservativeTimeRatio;
44 
45   // This is the maximum scheduled idle time. Note that it can be more than
46   // 16.66 ms when there is currently no rendering going on.
47   static const size_t kMaxScheduledIdleTime = 50;
48 
49   static const size_t kMaxHeapSizeForContextDisposalMarkCompact = 100 * MB;
50 
51   // If contexts are disposed at a higher rate a full gc is triggered.
52   static const double kHighContextDisposalRate;
53 
54   GCIdleTimeHandler() = default;
55 
56   GCIdleTimeAction Compute(double idle_time_in_ms,
57                            GCIdleTimeHeapState heap_state);
58 
59   bool Enabled();
60 
61   static size_t EstimateMarkingStepSize(double idle_time_in_ms,
62                                         double marking_speed_in_bytes_per_ms);
63 
64   static double EstimateFinalIncrementalMarkCompactTime(
65       size_t size_of_objects, double mark_compact_speed_in_bytes_per_ms);
66 
67   static bool ShouldDoContextDisposalMarkCompact(int context_disposed,
68                                                  double contexts_disposal_rate,
69                                                  size_t size_of_objects);
70 
71  private:
72   DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler);
73 };
74 
75 }  // namespace internal
76 }  // namespace v8
77 
78 #endif  // V8_HEAP_GC_IDLE_TIME_HANDLER_H_
79