v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
array-buffer-sweeper.h
Go to the documentation of this file.
1// Copyright 2020 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_ARRAY_BUFFER_SWEEPER_H_
6#define V8_HEAP_ARRAY_BUFFER_SWEEPER_H_
7
8#include <memory>
9
11#include "include/v8config.h"
12#include "src/api/api.h"
13#include "src/base/logging.h"
14#include "src/heap/sweeper.h"
17
18namespace v8 {
19namespace internal {
20
21class ArrayBufferExtension;
22class Heap;
23
24// Singly linked-list of ArrayBufferExtensions that stores head and tail of the
25// list to allow for concatenation of lists.
26struct ArrayBufferList final {
28
29 explicit ArrayBufferList(Age age) : age_(age) {}
30
31 bool IsEmpty() const;
32 size_t ApproximateBytes() const { return bytes_; }
33 size_t BytesSlow() const;
34
36 void Append(ArrayBufferList& list);
37
39
40 private:
43 // Bytes are approximate as they may be subtracted eagerly, while the
44 // `ArrayBufferExtension` is still in the list. The extension will only be
45 // dropped on next sweep.
46 size_t bytes_ = 0;
48
49 friend class ArrayBufferSweeper;
50};
51
52// The ArrayBufferSweeper iterates and deletes ArrayBufferExtensions
53// concurrently to the application.
54class ArrayBufferSweeper final {
55 public:
56 enum class SweepingType { kYoung, kFull };
58
59 explicit ArrayBufferSweeper(Heap* heap);
61
62 void RequestSweep(SweepingType sweeping_type,
63 TreatAllYoungAsPromoted treat_all_young_as_promoted);
64 void EnsureFinished();
65
66 // Track the given ArrayBufferExtension.
68
69 void Resize(ArrayBufferExtension* extension, int64_t delta);
70
71 // Detaches an ArrayBufferExtension.
73
74 const ArrayBufferList& young() const { return young_; }
75 const ArrayBufferList& old() const { return old_; }
76
77 // Bytes accounted in the young generation. Rebuilt during sweeping.
78 size_t YoungBytes() const { return young().ApproximateBytes(); }
79 // Bytes accounted in the old generation. Rebuilt during sweeping.
80 size_t OldBytes() const { return old().ApproximateBytes(); }
81
82 bool sweeping_in_progress() const { return state_.get(); }
83
84 uint64_t GetTraceIdForFlowEvent(GCTracer::Scope::ScopeId scope_id) const;
85
86 private:
87 class SweepingState;
88
89 // Finishes sweeping if it is already done.
90 void FinishIfDone();
91 void Finish();
92
94
95 // Increments external memory counters outside of ArrayBufferSweeper.
96 // Increment may trigger GC.
97 void IncrementExternalMemoryCounters(size_t bytes);
98 void DecrementExternalMemoryCounters(size_t bytes);
99
100 void Prepare(SweepingType type,
101 TreatAllYoungAsPromoted treat_all_young_as_promoted,
102 uint64_t trace_id);
103 void Finalize();
104
106
108
109 Heap* const heap_;
110 std::unique_ptr<SweepingState> state_;
111 ArrayBufferList young_{ArrayBufferList::Age::kYoung};
112 ArrayBufferList old_{ArrayBufferList::Age::kOld};
113 // Track accounting bytes adjustment during sweeping including freeing, and
114 // resizing. Adjustment are applied to the accounted bytes when sweeping
115 // finishes.
119};
120
121} // namespace internal
122} // namespace v8
123
124#endif // V8_HEAP_ARRAY_BUFFER_SWEEPER_H_
static void FinalizeAndDelete(ArrayBufferExtension *extension)
V8_NO_UNIQUE_ADDRESS ExternalMemoryAccounter external_memory_accounter_
const ArrayBufferList & young() const
std::unique_ptr< SweepingState > state_
void Detach(ArrayBufferExtension *extension)
void RequestSweep(SweepingType sweeping_type, TreatAllYoungAsPromoted treat_all_young_as_promoted)
const ArrayBufferList & old() const
void Resize(ArrayBufferExtension *extension, int64_t delta)
void UpdateApproximateBytes(int64_t delta, ArrayBufferExtension::Age age)
void Append(ArrayBufferExtension *extension)
uint64_t GetTraceIdForFlowEvent(GCTracer::Scope::ScopeId scope_id) const
void Prepare(SweepingType type, TreatAllYoungAsPromoted treat_all_young_as_promoted, uint64_t trace_id)
void ReleaseAll(ArrayBufferList *extension)
std::string extension
#define V8_EXPORT_PRIVATE
Definition macros.h:460
ArrayBufferExtension::Age age_
V8_EXPORT_PRIVATE bool ContainsSlow(ArrayBufferExtension *extension) const
size_t Append(ArrayBufferExtension *extension)
#define V8_NO_UNIQUE_ADDRESS
Definition v8config.h:722