cppgc: Sweeper: Get task runner only when scheduling sweeping

Platform::GetForegroundTaskRunner() can only be used after attaching
an Isolate in V8. Work around that problem by getting the runner only
when needed.

Bug: chromium:1056170
Change-Id: If15ec691e7f5cf11be8b7a3bc18827246ac083d6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2674009
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72527}
This commit is contained in:
Michael Lippautz 2021-02-04 13:48:34 +01:00 committed by Commit Bot
parent 8aadf7c5cb
commit 117f9b051c

View File

@ -526,8 +526,7 @@ class Sweeper::SweeperImpl final {
: heap_(heap),
stats_collector_(stats_collector),
space_states_(heap->size()),
platform_(platform),
foreground_task_runner_(platform_->GetForegroundTaskRunner()) {}
platform_(platform) {}
~SweeperImpl() { CancelSweepers(); }
@ -730,12 +729,11 @@ class Sweeper::SweeperImpl final {
void ScheduleIncrementalSweeping() {
DCHECK(platform_);
if (!foreground_task_runner_ ||
!foreground_task_runner_->IdleTasksEnabled())
return;
auto runner = platform_->GetForegroundTaskRunner();
if (!runner || !runner->IdleTasksEnabled()) return;
incremental_sweeper_handle_ =
IncrementalSweepTask::Post(this, foreground_task_runner_.get());
IncrementalSweepTask::Post(this, runner.get());
}
void ScheduleConcurrentSweeping() {
@ -763,7 +761,6 @@ class Sweeper::SweeperImpl final {
StatsCollector* stats_collector_;
SpaceStates space_states_;
cppgc::Platform* platform_;
std::shared_ptr<cppgc::TaskRunner> foreground_task_runner_;
IncrementalSweepTask::Handle incremental_sweeper_handle_;
std::unique_ptr<cppgc::JobHandle> concurrent_sweeper_handle_;
// Indicates whether the sweeping phase is in progress.