24 if (
head_ ==
nullptr) {
32 const size_t accounting_length = [&] {
34 return extension->SetOld().accounting_length();
36 return extension->SetYoung().accounting_length();
40 bytes_ += accounting_length;
42 return accounting_length;
48 if (
head_ ==
nullptr) {
52 }
else if (list.
head_) {
66 current = current->
next()) {
76 sum += current->accounting_length();
77 current = current->next();
86 return head_ ==
nullptr;
210 ? GCTracer::Scope::MINOR_MS_SWEEP
211 : GCTracer::Scope::MINOR_MS_BACKGROUND_SWEEPING
213 ? GCTracer::Scope::MC_SWEEP
214 : GCTracer::Scope::MC_BACKGROUND_SWEEPING;
219 const bool finished =
222 if (!finished)
return;
228 ? GCTracer::Scope::YOUNG_ARRAY_BUFFER_SWEEP
229 : GCTracer::Scope::BACKGROUND_YOUNG_ARRAY_BUFFER_SWEEP
231 ? GCTracer::Scope::FULL_ARRAY_BUFFER_SWEEP
232 : GCTracer::Scope::BACKGROUND_FULL_ARRAY_BUFFER_SWEEP;
248 heap, *this,
std::move(young),
std::move(old), type,
249 treat_all_young_as_promoted, trace_id))) {}
292 ? GCTracer::Scope::MINOR_MS_FINISH_SWEEP_ARRAY_BUFFERS
293 : GCTracer::Scope::SCAVENGER_SWEEP_ARRAY_BUFFERS
294 : GCTracer::Scope::MC_FINISH_SWEEP_ARRAY_BUFFERS;
298 Prepare(type, treat_all_young_as_promoted, trace_id);
302 v8_flags.concurrent_array_buffer_sweeping &&
304 state_->StartBackgroundSweeping();
318 state_ = std::make_unique<SweepingState>(
320 type, treat_all_young_as_promoted, trace_id);
324 state_ = std::make_unique<SweepingState>(
326 treat_all_young_as_promoted, trace_id);
355 size_t bytes =
extension->accounting_length();
376 extension->UpdateAccountingLength(delta);
397 previous_value.
age());
423 if (bytes == 0)
return;
431 if (bytes == 0)
return;
439#ifdef V8_COMPRESS_POINTERS
440 extension->ZapExternalPointerTableEntry();
475 static constexpr size_t kYieldCheckInterval = 256;
477 "kYieldCheckInterval must be power of 2");
482 size_t freed_bytes = 0;
483 size_t accounted_bytes = 0;
484 size_t swept_extensions = 0;
488 if ((swept_extensions++ & (kYieldCheckInterval - 1)) == 0) {
493 if (!current->IsMarked()) {
494 freed_bytes += current->accounting_length();
498 accounted_bytes += new_old.
Append(current);
504 state_.freed_bytes_ += freed_bytes;
506 state_.young_bytes_accounted_ += (freed_bytes + accounted_bytes);
508 state_.old_bytes_accounted_ += (freed_bytes + accounted_bytes);
517 static constexpr size_t kYieldCheckInterval = 256;
519 "kYieldCheckInterval must be power of 2");
526 size_t freed_bytes = 0;
527 size_t accounted_bytes = 0;
528 size_t swept_extensions = 0;
532 if ((swept_extensions++ & (kYieldCheckInterval - 1)) == 0) {
537 if (!current->IsYoungMarked()) {
538 const size_t bytes = current->accounting_length();
540 if (bytes) freed_bytes += bytes;
543 current->IsYoungPromoted()) {
544 current->YoungUnmark();
545 accounted_bytes += new_old.
Append(current);
547 current->YoungUnmark();
548 accounted_bytes += new_young.
Append(current);
555 state_.freed_bytes_ += freed_bytes;
559 state_.young_bytes_accounted_ += (freed_bytes + accounted_bytes);
567 return reinterpret_cast<uint64_t
>(
this) ^
void Decrease(Isolate *isolate, size_t size)
void Increase(Isolate *isolate, size_t size)
virtual bool ShouldYield()=0
virtual bool IsJoiningThread() const =0
ArrayBufferExtension * next() const
void set_next(ArrayBufferExtension *extension)
AccountingState ClearAccountingLength()
SweepingJob & operator=(const SweepingJob &)=delete
bool SweepYoung(JobDelegate *delegate)
Sweeper::LocalSweeper local_sweeper_
void Sweep(JobDelegate *delegate)
void Run(JobDelegate *delegate) final
bool SweepFull(JobDelegate *delegate)
~SweepingJob() override=default
bool SweepListFull(JobDelegate *delegate, ArrayBufferList &list, ArrayBufferExtension::Age age)
SweepingJob(const SweepingJob &)=delete
const TreatAllYoungAsPromoted treat_all_young_as_promoted_
size_t GetMaxConcurrency(size_t worker_count) const override
SweepingJob(Heap *heap, SweepingState &state, ArrayBufferList young, ArrayBufferList old, SweepingType type, TreatAllYoungAsPromoted treat_all_young_as_promoted, uint64_t trace_id)
std::unique_ptr< JobHandle > job_handle_
const uint64_t initial_young_bytes_
SweepingState(Heap *heap, ArrayBufferList young, ArrayBufferList old, SweepingType type, TreatAllYoungAsPromoted treat_all_young_as_promoted, uint64_t trace_id)
uint64_t young_bytes_accounted_
uint64_t old_bytes_accounted_
void StartBackgroundSweeping()
const uint64_t initial_old_bytes_
void MergeTo(ArrayBufferSweeper *sweeper)
std::atomic< Status > status_
ArrayBufferList new_young_
static void FinalizeAndDelete(ArrayBufferExtension *extension)
V8_NO_UNIQUE_ADDRESS ExternalMemoryAccounter external_memory_accounter_
int64_t young_bytes_adjustment_while_sweeping_
std::unique_ptr< SweepingState > state_
void DecrementExternalMemoryCounters(size_t bytes)
ArrayBufferSweeper(Heap *heap)
void Detach(ArrayBufferExtension *extension)
void RequestSweep(SweepingType sweeping_type, TreatAllYoungAsPromoted treat_all_young_as_promoted)
void Resize(ArrayBufferExtension *extension, int64_t delta)
bool sweeping_in_progress() const
int64_t old_bytes_adjustment_while_sweeping_
void UpdateApproximateBytes(int64_t delta, ArrayBufferExtension::Age age)
void Append(ArrayBufferExtension *extension)
uint64_t GetTraceIdForFlowEvent(GCTracer::Scope::ScopeId scope_id) const
void IncrementExternalMemoryCounters(size_t bytes)
void Prepare(SweepingType type, TreatAllYoungAsPromoted treat_all_young_as_promoted, uint64_t trace_id)
void ReleaseAll(ArrayBufferList *extension)
V8_INLINE CollectionEpoch CurrentEpoch(Scope::ScopeId id) const
bool IsTearingDown() const
void IncrementExternalBackingStoreBytes(ExternalBackingStoreType type, size_t amount)
void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type, size_t amount)
uint64_t backing_store_bytes() const
bool ShouldUseBackgroundThreads() const
Isolate * isolate() const
bool ShouldReduceMemory() const
bool ContributeAndWaitForPromotedPagesIteration(JobDelegate *delegate)
uint64_t GetTraceIdForFlowEvent(GCTracer::Scope::ScopeId scope_id) const
bool IsIteratingPromotedPages() const
#define TRACE_GC_EPOCH_WITH_FLOW(tracer, scope_id, thread_kind, bind_id, flow_flags)
#define TRACE_GC_WITH_FLOW(tracer, scope_id, bind_id, flow_flags)
#define TRACE_GC_NOTE(note)
constexpr bool IsPowerOfTwo(T value)
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK_LE(v1, v2)
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
size_t accounting_length() const
ArrayBufferExtension * head_
ArrayBufferExtension::Age age_
V8_EXPORT_PRIVATE bool ContainsSlow(ArrayBufferExtension *extension) const
size_t Append(ArrayBufferExtension *extension)
size_t ApproximateBytes() const
ArrayBufferExtension * tail_
#define TRACE_EVENT_FLAG_FLOW_OUT
#define TRACE_EVENT_FLAG_FLOW_IN