Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::CompactorTask Class Reference
Inheritance diagram for dart::CompactorTask:
dart::ThreadPool::Task dart::IntrusiveDListEntry< Task >

Public Member Functions

 CompactorTask (IsolateGroup *isolate_group, GCCompactor *compactor, ThreadBarrier *barrier, RelaxedAtomic< intptr_t > *next_planning_task, RelaxedAtomic< intptr_t > *next_setup_task, RelaxedAtomic< intptr_t > *next_sliding_task, RelaxedAtomic< intptr_t > *next_forwarding_task, intptr_t num_tasks, Partition *partitions, FreeList *freelist)
 
void Run ()
 
void RunEnteredIsolateGroup ()
 
- Public Member Functions inherited from dart::ThreadPool::Task
virtual ~Task ()
 
virtual void Run ()=0
 
- Public Member Functions inherited from dart::IntrusiveDListEntry< Task >
 IntrusiveDListEntry ()
 
 ~IntrusiveDListEntry ()
 

Additional Inherited Members

- Protected Member Functions inherited from dart::ThreadPool::Task
 Task ()
 

Detailed Description

Definition at line 125 of file compactor.cc.

Constructor & Destructor Documentation

◆ CompactorTask()

dart::CompactorTask::CompactorTask ( IsolateGroup isolate_group,
GCCompactor compactor,
ThreadBarrier barrier,
RelaxedAtomic< intptr_t > *  next_planning_task,
RelaxedAtomic< intptr_t > *  next_setup_task,
RelaxedAtomic< intptr_t > *  next_sliding_task,
RelaxedAtomic< intptr_t > *  next_forwarding_task,
intptr_t  num_tasks,
Partition partitions,
FreeList freelist 
)
inline

Definition at line 127 of file compactor.cc.

137 : isolate_group_(isolate_group),
138 compactor_(compactor),
139 barrier_(barrier),
140 next_planning_task_(next_planning_task),
141 next_setup_task_(next_setup_task),
142 next_sliding_task_(next_sliding_task),
143 next_forwarding_task_(next_forwarding_task),
144 num_tasks_(num_tasks),
145 partitions_(partitions),
146 freelist_(freelist),
147 free_page_(nullptr),
148 free_current_(0),
149 free_end_(0) {}

Member Function Documentation

◆ Run()

void dart::CompactorTask::Run ( )
virtual

Implements dart::ThreadPool::Task.

Definition at line 401 of file compactor.cc.

401 {
402 if (!barrier_->TryEnter()) {
403 barrier_->Release();
404 return;
405 }
406
407 bool result =
409 /*bypass_safepoint=*/true);
410 ASSERT(result);
411
413
414 Thread::ExitIsolateGroupAsHelper(/*bypass_safepoint=*/true);
415
416 // This task is done. Notify the original thread.
417 barrier_->Sync();
418 barrier_->Release();
419}
void RunEnteredIsolateGroup()
Definition: compactor.cc:421
@ kCompactorTask
Definition: thread.h:351
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
Definition: thread.cc:499
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
Definition: thread.cc:481
#define ASSERT(E)
GAsyncResult * result

◆ RunEnteredIsolateGroup()

void dart::CompactorTask::RunEnteredIsolateGroup ( )

Definition at line 421 of file compactor.cc.

421 {
422#ifdef SUPPORT_TIMELINE
423 Thread* thread = Thread::Current();
424#endif
425 {
426 isolate_group_->heap()->old_space()->SweepLarge();
427
428 while (true) {
429 intptr_t planning_task = next_planning_task_->fetch_add(1u);
430 if (planning_task >= num_tasks_) break;
431
432 TIMELINE_FUNCTION_GC_DURATION(thread, "Plan");
433 Page* head = partitions_[planning_task].head;
434 free_page_ = head;
435 free_current_ = head->object_start();
436 free_end_ = head->object_end();
437
438 for (Page* page = head; page != nullptr; page = page->next()) {
439 PlanPage(page);
440 }
441 }
442
443 barrier_->Sync();
444
445 if (next_setup_task_->fetch_add(1u) == 0) {
446 compactor_->SetupLargePages();
447 }
448
449 barrier_->Sync();
450
451 while (true) {
452 intptr_t sliding_task = next_sliding_task_->fetch_add(1u);
453 if (sliding_task >= num_tasks_) break;
454
455 TIMELINE_FUNCTION_GC_DURATION(thread, "Slide");
456 Page* head = partitions_[sliding_task].head;
457 free_page_ = head;
458 free_current_ = head->object_start();
459 free_end_ = head->object_end();
460
461 for (Page* page = head; page != nullptr; page = page->next()) {
462 SlidePage(page);
463 }
464
465 // Add any leftover in the last used page to the freelist. This is
466 // required to make the page walkable during forwarding, etc.
467 intptr_t free_remaining = free_end_ - free_current_;
468 if (free_remaining != 0) {
469 freelist_->Free(free_current_, free_remaining);
470 }
471
472 ASSERT(free_page_ != nullptr);
473 partitions_[sliding_task].tail = free_page_; // Last live page.
474
475 {
476 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardLargePages");
477 compactor_->ForwardLargePages();
478 }
479 }
480
481 // Heap: Regular pages already visited during sliding. Code and image pages
482 // have no pointers to forward. Visit large pages and new-space.
483
484 bool more_forwarding_tasks = true;
485 while (more_forwarding_tasks) {
486 intptr_t forwarding_task = next_forwarding_task_->fetch_add(1u);
487 switch (forwarding_task) {
488 case 0: {
489 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardNewSpace");
490 isolate_group_->heap()->new_space()->VisitObjectPointers(compactor_);
491 break;
492 }
493 case 1: {
494 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardRememberedSet");
495 isolate_group_->store_buffer()->VisitObjectPointers(compactor_);
496 break;
497 }
498 case 2: {
499 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardWeakTables");
500 isolate_group_->heap()->ForwardWeakTables(compactor_);
501 break;
502 }
503 case 3: {
504 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardWeakHandles");
505 isolate_group_->VisitWeakPersistentHandles(compactor_);
506 break;
507 }
508#ifndef PRODUCT
509 case 4: {
510 TIMELINE_FUNCTION_GC_DURATION(thread, "ForwardObjectIdRing");
511 isolate_group_->ForEachIsolate(
512 [&](Isolate* isolate) {
513 ObjectIdRing* ring = isolate->object_id_ring();
514 if (ring != nullptr) {
515 ring->VisitPointers(compactor_);
516 }
517 },
518 /*at_safepoint=*/true);
519 break;
520 }
521#endif // !PRODUCT
522 default:
523 more_forwarding_tasks = false;
524 }
525 }
526 }
527}
void VisitObjectPointers(ObjectPointerVisitor *visitor)
void Free(uword addr, intptr_t size)
Definition: freelist.cc:193
Scavenger * new_space()
Definition: heap.h:62
PageSpace * old_space()
Definition: heap.h:63
void ForwardWeakTables(ObjectPointerVisitor *visitor)
Definition: heap.cc:965
StoreBuffer * store_buffer() const
Definition: isolate.h:509
void ForEachIsolate(std::function< void(Isolate *isolate)> function, bool at_safepoint=false)
Definition: isolate.cc:2841
Heap * heap() const
Definition: isolate.h:296
void VisitWeakPersistentHandles(HandleVisitor *visitor)
Definition: isolate.cc:2998
T fetch_add(T arg, std::memory_order order=std::memory_order_relaxed)
Definition: atomic.h:35
void VisitObjectPointers(ObjectPointerVisitor *visitor) const
Definition: scavenger.cc:1775
static Thread * Current()
Definition: thread.h:362
#define TIMELINE_FUNCTION_GC_DURATION(thread, name)
Definition: timeline.h:41

The documentation for this class was generated from the following file: