v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
marking-progress-tracker.h
Go to the documentation of this file.
1// Copyright 2021 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_MARKING_PROGRESS_TRACKER_H_
6#define V8_HEAP_MARKING_PROGRESS_TRACKER_H_
7
8#include <atomic>
9#include <cstdint>
10
11#include "src/base/logging.h"
12#include "src/common/globals.h"
13
14namespace v8 {
15namespace internal {
16
17// The MarkingProgressTracker allows for keeping track of the bytes processed of
18// a single object. It splits marking of large arrays into chunks so that the
19// work can be shared across multiple concurrent markers. The tracker must be
20// enabled before it's used.
21//
22// Only large objects use the tracker which is stored in their page metadata.
23// These objects are scanned in increments and concurrently and will be kept
24// black while being scanned. Even if the mutator writes to them they will be
25// kept black and a white to grey transition is performed in the value via
26// regular write barrier.
27//
28// The tracker starts as disabled. After enabling (through `Enable()`), it can
29// never be disabled again.
31 public:
32 static constexpr size_t kChunkSize = kMaxRegularHeapObjectSize;
33
34 void Enable(size_t size) {
35 DCHECK(!IsEnabled());
36 overall_chunks_ = (size + kChunkSize - 1) / kChunkSize;
38 }
39
40 bool IsEnabled() const { return overall_chunks_ != 0; }
41
43 const size_t new_chunk =
44 current_chunk_.fetch_add(1, std::memory_order_acq_rel);
45 DCHECK_LT(new_chunk, overall_chunks_);
46 return new_chunk;
47 }
48
49 size_t TotalNumberOfChunks() const { return overall_chunks_; }
50
52 if (IsEnabled()) {
54 }
55 }
56
58 return current_chunk_.load(std::memory_order_relaxed);
59 }
60
61 private:
62 size_t overall_chunks_ = 0;
63 std::atomic<size_t> current_chunk_;
64};
65
66} // namespace internal
67} // namespace v8
68
69#endif // V8_HEAP_MARKING_PROGRESS_TRACKER_H_
constexpr int kMaxRegularHeapObjectSize
Definition globals.h:680
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489