diff options
Diffstat (limited to 'chromium/v8/src/heap/array-buffer-sweeper.h')
-rw-r--r-- | chromium/v8/src/heap/array-buffer-sweeper.h | 118 |
1 files changed, 41 insertions, 77 deletions
diff --git a/chromium/v8/src/heap/array-buffer-sweeper.h b/chromium/v8/src/heap/array-buffer-sweeper.h index 6dd7ed97f6c..14360dd67f2 100644 --- a/chromium/v8/src/heap/array-buffer-sweeper.h +++ b/chromium/v8/src/heap/array-buffer-sweeper.h @@ -5,6 +5,9 @@ #ifndef V8_HEAP_ARRAY_BUFFER_SWEEPER_H_ #define V8_HEAP_ARRAY_BUFFER_SWEEPER_H_ +#include <memory> + +#include "src/base/logging.h" #include "src/base/platform/mutex.h" #include "src/objects/js-array-buffer.h" #include "src/tasks/cancelable-task.h" @@ -17,47 +20,38 @@ class Heap; // Singly linked-list of ArrayBufferExtensions that stores head and tail of the // list to allow for concatenation of lists. -struct ArrayBufferList { - ArrayBufferList() : head_(nullptr), tail_(nullptr), bytes_(0) {} - - ArrayBufferExtension* head_; - ArrayBufferExtension* tail_; - size_t bytes_; - - bool IsEmpty() { - DCHECK_IMPLIES(head_, tail_); - return head_ == nullptr; - } - - size_t Bytes() { return bytes_; } - size_t BytesSlow(); - - void Reset() { - head_ = tail_ = nullptr; - bytes_ = 0; - } +struct ArrayBufferList final { + bool IsEmpty() const; + size_t ApproximateBytes() const { return bytes_; } + size_t BytesSlow() const; void Append(ArrayBufferExtension* extension); void Append(ArrayBufferList* list); - V8_EXPORT_PRIVATE bool Contains(ArrayBufferExtension* extension); + V8_EXPORT_PRIVATE bool ContainsSlow(ArrayBufferExtension* extension) const; + + private: + ArrayBufferExtension* head_ = nullptr; + ArrayBufferExtension* tail_ = nullptr; + // Bytes are approximate as they may be subtracted eagerly, while the + // `ArrayBufferExtension` is still in the list. The extension will only be + // dropped on next sweep. + size_t bytes_ = 0; + + friend class ArrayBufferSweeper; }; // The ArrayBufferSweeper iterates and deletes ArrayBufferExtensions // concurrently to the application. -class ArrayBufferSweeper { +class ArrayBufferSweeper final { public: - explicit ArrayBufferSweeper(Heap* heap) - : heap_(heap), - sweeping_in_progress_(false), - freed_bytes_(0), - young_bytes_(0), - old_bytes_(0) {} - ~ArrayBufferSweeper() { ReleaseAll(); } + enum class SweepingType { kYoung, kFull }; + explicit ArrayBufferSweeper(Heap* heap); + ~ArrayBufferSweeper(); + + void RequestSweep(SweepingType sweeping_type); void EnsureFinished(); - void RequestSweepYoung(); - void RequestSweepFull(); // Track the given ArrayBufferExtension for the given JSArrayBuffer. void Append(JSArrayBuffer object, ArrayBufferExtension* extension); @@ -65,70 +59,40 @@ class ArrayBufferSweeper { // Detaches an ArrayBufferExtension from a JSArrayBuffer. void Detach(JSArrayBuffer object, ArrayBufferExtension* extension); - ArrayBufferList young() { return young_; } - ArrayBufferList old() { return old_; } + const ArrayBufferList& young() const { return young_; } + const ArrayBufferList& old() const { return old_; } - size_t YoungBytes(); - size_t OldBytes(); + // Bytes accounted in the young generation. Rebuilt during sweeping. + size_t YoungBytes() const { return young().ApproximateBytes(); } + // Bytes accounted in the old generation. Rebuilt during sweeping. + size_t OldBytes() const { return old().ApproximateBytes(); } private: - enum class SweepingScope { kYoung, kFull }; + struct SweepingJob; enum class SweepingState { kInProgress, kDone }; - struct SweepingJob { - ArrayBufferSweeper* sweeper_; - CancelableTaskManager::Id id_; - std::atomic<SweepingState> state_; - ArrayBufferList young_; - ArrayBufferList old_; - SweepingScope scope_; - - SweepingJob(ArrayBufferSweeper* sweeper, ArrayBufferList young, - ArrayBufferList old, SweepingScope scope) - : sweeper_(sweeper), - id_(0), - state_(SweepingState::kInProgress), - young_(young), - old_(old), - scope_(scope) {} - - void Sweep(); - void SweepYoung(); - void SweepFull(); - ArrayBufferList SweepListFull(ArrayBufferList* list); - }; - - base::Optional<SweepingJob> job_; - - void Merge(); - void MergeBackExtensionsWhenSwept(); - - void UpdateCountersForConcurrentlySweptExtensions(); + bool sweeping_in_progress() const { return job_.get(); } + + // Finishes sweeping if it is already done. + void FinishIfDone(); + + // Increments external memory counters outside of ArrayBufferSweeper. + // Increment may trigger GC. void IncrementExternalMemoryCounters(size_t bytes); void DecrementExternalMemoryCounters(size_t bytes); - void IncrementFreedBytes(size_t bytes); - void RequestSweep(SweepingScope sweeping_task); - void Prepare(SweepingScope sweeping_task); + void Prepare(SweepingType type); + void Finalize(); - ArrayBufferList SweepYoungGen(); - void SweepOldGen(ArrayBufferExtension* extension); - - void ReleaseAll(); void ReleaseAll(ArrayBufferList* extension); Heap* const heap_; - bool sweeping_in_progress_; + std::unique_ptr<SweepingJob> job_; base::Mutex sweeping_mutex_; base::ConditionVariable job_finished_; - std::atomic<size_t> freed_bytes_; - ArrayBufferList young_; ArrayBufferList old_; - - size_t young_bytes_; - size_t old_bytes_; }; } // namespace internal |