gc-idle-time-handler.h 2.43 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_
#define V8_HEAP_GC_IDLE_TIME_HANDLER_H_

8
#include "src/common/globals.h"
9 10 11 12

namespace v8 {
namespace internal {

13 14 15 16
enum class GCIdleTimeAction : uint8_t {
  kDone,
  kIncrementalStep,
  kFullGC,
17 18
};

19 20 21 22 23 24 25 26 27 28
class GCIdleTimeHeapState {
 public:
  void Print();

  int contexts_disposed;
  double contexts_disposal_rate;
  size_t size_of_objects;
  bool incremental_marking_stopped;
};

29

30 31
// The idle time handler makes decisions about which garbage collection
// operations are executing during IdleNotification.
32
class V8_EXPORT_PRIVATE GCIdleTimeHandler {
33 34 35
 public:
  // If we haven't recorded any incremental marking events yet, we carefully
  // mark with a conservative lower bound for the marking speed.
36 37 38 39
  static const size_t kInitialConservativeMarkingSpeed = 100 * KB;

  // Maximum marking step size returned by EstimateMarkingStepSize.
  static const size_t kMaximumMarkingStepSize = 700 * MB;
40 41 42 43 44

  // We have to make sure that we finish the IdleNotification before
  // idle_time_in_ms. Hence, we conservatively prune our workload estimate.
  static const double kConservativeTimeRatio;

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 50
  static const size_t kMaxHeapSizeForContextDisposalMarkCompact = 100 * MB;

51 52 53
  // If contexts are disposed at a higher rate a full gc is triggered.
  static const double kHighContextDisposalRate;

54
  GCIdleTimeHandler() = default;
55

56 57
  GCIdleTimeAction Compute(double idle_time_in_ms,
                           GCIdleTimeHeapState heap_state);
58

59 60
  bool Enabled();

61 62
  static size_t EstimateMarkingStepSize(double idle_time_in_ms,
                                        double marking_speed_in_bytes_per_ms);
63

64 65
  static double EstimateFinalIncrementalMarkCompactTime(
      size_t size_of_objects, double mark_compact_speed_in_bytes_per_ms);
66

67
  static bool ShouldDoContextDisposalMarkCompact(int context_disposed,
68 69
                                                 double contexts_disposal_rate,
                                                 size_t size_of_objects);
70

71
 private:
72 73 74 75 76 77 78
  DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_GC_IDLE_TIME_HANDLER_H_