summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/heap/blink_gc.h
blob: ade274516726ea1ab65de5f1c3f20750a8b975fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2015 The Chromium 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_

// BlinkGC.h is a file that defines common things used by Blink GC.

#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

#define PRINT_HEAP_STATS 0  // Enable this macro to print heap stats to stderr.

namespace blink {

class LivenessBroker;
class MarkingVisitor;
class Visitor;

using Address = uint8_t*;
using ConstAddress = const uint8_t*;

using VisitorCallback = void (*)(Visitor*, const void*);
using MarkingVisitorCallback = void (*)(MarkingVisitor*, const void*);
using TraceCallback = VisitorCallback;
using WeakCallback = void (*)(const LivenessBroker&, const void*);
using EphemeronCallback = VisitorCallback;

// Simple alias to avoid heap compaction type signatures turning into
// a sea of generic |void*|s.
using MovableReference = const void*;

// Heap compaction supports registering callbacks that are to be invoked
// when an object is moved during compaction. This is to support internal
// location fixups that need to happen as a result.
//
// i.e., when the object residing at |from| is moved to |to| by the compaction
// pass, invoke the callback to adjust any internal references that now need
// to be |to|-relative.
using MovingObjectCallback = void (*)(MovableReference from,
                                      MovableReference to,
                                      size_t);

// List of all arenas. Includes typed arenas as well.
#define FOR_EACH_ARENA(H) \
  H(NormalPage1)          \
  H(NormalPage2)          \
  H(NormalPage3)          \
  H(NormalPage4)          \
  H(Vector)               \
  H(HashTable)            \
  H(Node)                 \
  H(CSSValue)             \
  H(LargeObject)

class PLATFORM_EXPORT WorklistTaskId {
 public:
  static constexpr int MutatorThread = 0;
  static constexpr int ConcurrentThreadBase = 1;
};

class PLATFORM_EXPORT BlinkGC final {
  STATIC_ONLY(BlinkGC);

 public:
  // CollectionType represents generational collection. kMinor collects objects
  // in the young generation (i.e. allocated since the previous collection
  // cycle, since we use sticky bits), kMajor collects the entire heap.
  enum class CollectionType { kMinor, kMajor };

  // When garbage collecting we need to know whether or not there
  // can be pointers to Blink GC managed objects on the stack for
  // each thread. When threads reach a safe point they record
  // whether or not they have pointers on the stack.
  enum StackState { kNoHeapPointersOnStack, kHeapPointersOnStack };

  enum MarkingType {
    // The marking completes synchronously.
    kAtomicMarking,
    // The marking task is split and executed in chunks (either on the mutator
    // thread or concurrently).
    kIncrementalAndConcurrentMarking
  };

  enum SweepingType {
    // The sweeping task is split into chunks and scheduled lazily and
    // concurrently.
    kConcurrentAndLazySweeping,
    // The sweeping task executes synchronously right after marking.
    kEagerSweeping,
  };

  // Commented out reasons have been used in the past but are not used any
  // longer. We keep them here as the corresponding UMA histograms cannot be
  // changed.
  enum class GCReason {
    // kIdleGC = 0
    // kPreciseGC = 1
    // kConservativeGC = 2
    kForcedGCForTesting = 3,
    // kMemoryPressureGC = 4
    // kPageNavigationGC = 5
    kThreadTerminationGC = 6,
    // kTesting = 7
    // kIncrementalIdleGC = 8
    // kIncrementalV8FollowupGC = 9
    kUnifiedHeapGC = 10,
    kUnifiedHeapForMemoryReductionGC = 11,
    kUnifiedHeapForcedForTestingGC = 12,
    // Used by UMA_HISTOGRAM_ENUMERATION macro.
    kMaxValue = kUnifiedHeapForcedForTestingGC,
  };

#define DeclareArenaIndex(name) k##name##ArenaIndex,
  enum ArenaIndices {
    FOR_EACH_ARENA(DeclareArenaIndex)
    // Values used for iteration of heap segments.
    kNumberOfArenas,
  };
#undef DeclareArenaIndex

  enum V8GCType {
    kV8MinorGC,
    kV8MajorGC,
  };

  // Sentinel used to mark not-fully-constructed during mixins.
  static constexpr void* kNotFullyConstructedObject = nullptr;

  static const char* ToString(GCReason);
  static const char* ToString(MarkingType);
  static const char* ToString(StackState);
  static const char* ToString(SweepingType);
  static const char* ToString(ArenaIndices);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_BLINK_GC_H_