[Jobs API] Rename IsRunning -> IsValid

IsRunning is the v8 equivalent of operator bool, but is confusing
with IsCompleted. IsValid (to match base:: operator bool) should be more
clear.

Change-Id: I2529bea21c7cb7613bd5057c66715fb5ea450396
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2461840
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70625}
This commit is contained in:
Etienne Pierre-doray 2020-10-16 13:53:20 -04:00 committed by Commit Bot
parent 4ad68f1c83
commit 10b847c765
9 changed files with 27 additions and 20 deletions

View File

@ -225,15 +225,19 @@ class JobHandle {
virtual void CancelAndDetach() { Cancel(); }
/**
* Returns true if there's no work pending and no worker running.
* Returns true if there's currently no work pending and no worker running.
*/
virtual bool IsCompleted() = 0;
/**
* Returns true if associated with a Job and other methods may be called.
* Returns false after Join() or Cancel() was called.
* Returns false after Join() or Cancel() was called. This may return true
* even if no workers are running and IsCompleted() returns true
* TODO(etiennep): Deprecate IsRunning in favor of IsValid once implemented by
* all embedders.
*/
virtual bool IsRunning() = 0;
virtual bool IsValid() { return IsRunning(); }
/**
* Returns true if job priority can be changed.

View File

@ -525,13 +525,13 @@ size_t ConcurrentMarking::GetMaxConcurrency(size_t worker_count) {
void ConcurrentMarking::ScheduleTasks() {
DCHECK(FLAG_parallel_marking || FLAG_concurrent_marking);
DCHECK(!heap_->IsTearingDown());
DCHECK(!job_handle_ || !job_handle_->IsRunning());
DCHECK(!job_handle_ || !job_handle_->IsValid());
job_handle_ = V8::GetCurrentPlatform()->PostJob(
TaskPriority::kUserVisible,
std::make_unique<JobTask>(this, heap_->mark_compact_collector()->epoch(),
heap_->is_current_gc_forced()));
DCHECK(job_handle_->IsRunning());
DCHECK(job_handle_->IsValid());
}
void ConcurrentMarking::RescheduleTasksIfNeeded() {
@ -543,7 +543,7 @@ void ConcurrentMarking::RescheduleTasksIfNeeded() {
weak_objects_->discovered_ephemerons.IsGlobalPoolEmpty()) {
return;
}
if (!job_handle_ || !job_handle_->IsRunning())
if (!job_handle_ || !job_handle_->IsValid())
ScheduleTasks();
else
job_handle_->NotifyConcurrencyIncrease();
@ -551,7 +551,7 @@ void ConcurrentMarking::RescheduleTasksIfNeeded() {
bool ConcurrentMarking::Stop(StopRequest stop_request) {
DCHECK(FLAG_parallel_marking || FLAG_concurrent_marking);
if (!job_handle_ || !job_handle_->IsRunning()) return false;
if (!job_handle_ || !job_handle_->IsValid()) return false;
if (stop_request == StopRequest::PREEMPT_TASKS) {
job_handle_->Cancel();
@ -564,11 +564,11 @@ bool ConcurrentMarking::Stop(StopRequest stop_request) {
bool ConcurrentMarking::IsStopped() {
if (!FLAG_concurrent_marking) return true;
return !job_handle_ || !job_handle_->IsRunning();
return !job_handle_ || !job_handle_->IsValid();
}
void ConcurrentMarking::FlushNativeContexts(NativeContextStats* main_stats) {
DCHECK(!job_handle_ || !job_handle_->IsRunning());
DCHECK(!job_handle_ || !job_handle_->IsValid());
for (int i = 1; i <= kMaxTasks; i++) {
main_stats->Merge(task_state_[i].native_context_stats);
task_state_[i].native_context_stats.Clear();
@ -577,7 +577,7 @@ void ConcurrentMarking::FlushNativeContexts(NativeContextStats* main_stats) {
void ConcurrentMarking::FlushMemoryChunkData(
MajorNonAtomicMarkingState* marking_state) {
DCHECK(!job_handle_ || !job_handle_->IsRunning());
DCHECK(!job_handle_ || !job_handle_->IsValid());
for (int i = 1; i <= kMaxTasks; i++) {
MemoryChunkDataMap& memory_chunk_data = task_state_[i].memory_chunk_data;
for (auto& pair : memory_chunk_data) {
@ -600,7 +600,7 @@ void ConcurrentMarking::FlushMemoryChunkData(
}
void ConcurrentMarking::ClearMemoryChunkData(MemoryChunk* chunk) {
DCHECK(!job_handle_ || !job_handle_->IsRunning());
DCHECK(!job_handle_ || !job_handle_->IsValid());
for (int i = 1; i <= kMaxTasks; i++) {
auto it = task_state_[i].memory_chunk_data.find(chunk);
if (it != task_state_[i].memory_chunk_data.end()) {

View File

@ -180,18 +180,18 @@ void ConcurrentMarkerBase::Start() {
}
void ConcurrentMarkerBase::Cancel() {
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsRunning())
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsValid())
concurrent_marking_handle_->Cancel();
}
void ConcurrentMarkerBase::JoinForTesting() {
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsRunning())
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsValid())
concurrent_marking_handle_->Join();
}
ConcurrentMarkerBase::~ConcurrentMarkerBase() {
CHECK_IMPLIES(concurrent_marking_handle_,
!concurrent_marking_handle_->IsRunning());
!concurrent_marking_handle_->IsValid());
}
bool ConcurrentMarkerBase::NotifyIncrementalMutatorStepCompleted() {

View File

@ -504,7 +504,7 @@ class Sweeper::SweeperImpl final {
void FinishIfRunning() {
if (!is_in_progress_) return;
if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsRunning() &&
if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsValid() &&
concurrent_sweeper_handle_->UpdatePriorityEnabled()) {
concurrent_sweeper_handle_->UpdatePriority(
cppgc::TaskPriority::kUserBlocking);
@ -593,7 +593,7 @@ class Sweeper::SweeperImpl final {
void CancelSweepers() {
if (incremental_sweeper_handle_) incremental_sweeper_handle_.Cancel();
if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsRunning())
if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsValid())
concurrent_sweeper_handle_->Cancel();
}

View File

@ -114,7 +114,8 @@ class V8_PLATFORM_EXPORT DefaultJobHandle : public JobHandle {
void Cancel() override;
void CancelAndDetach() override;
bool IsCompleted() override;
bool IsRunning() override { return state_ != nullptr; }
bool IsRunning() override { return IsValid(); }
bool IsValid() override { return state_ != nullptr; }
bool UpdatePriorityEnabled() const override { return true; }

View File

@ -3177,7 +3177,7 @@ void CompilationStateImpl::SchedulePublishCompilationResults(
}
void CompilationStateImpl::ScheduleCompileJobForNewUnits() {
if (current_compile_job_ && current_compile_job_->IsRunning()) {
if (current_compile_job_ && current_compile_job_->IsValid()) {
current_compile_job_->NotifyConcurrencyIncrease();
return;
}

View File

@ -419,7 +419,7 @@ WasmEngine::~WasmEngine() {
compile_job_handles = compile_job_handles_;
}
for (auto& job_handle : compile_job_handles) {
if (job_handle->IsRunning()) job_handle->Cancel();
if (job_handle->IsValid()) job_handle->Cancel();
}
// All AsyncCompileJobs have been canceled.

View File

@ -58,7 +58,7 @@ class MockPlatform final : public TestPlatform {
void ExecuteTasks() {
for (auto* job_handle : job_handles_) {
if (job_handle->IsRunning()) job_handle->Join();
if (job_handle->IsValid()) job_handle->Join();
}
task_runner_->ExecuteTasks();
}
@ -114,6 +114,7 @@ class MockPlatform final : public TestPlatform {
void CancelAndDetach() override { orig_handle_->CancelAndDetach(); }
bool IsCompleted() override { return orig_handle_->IsCompleted(); }
bool IsRunning() override { return orig_handle_->IsRunning(); }
bool IsValid() override { return orig_handle_->IsValid(); }
private:
std::unique_ptr<JobHandle> orig_handle_;

View File

@ -53,7 +53,7 @@ class MockPlatform final : public TestPlatform {
void ExecuteTasks() {
for (auto* job_handle : job_handles_) {
if (job_handle->IsRunning()) job_handle->Join();
if (job_handle->IsValid()) job_handle->Join();
}
task_runner_->ExecuteTasks();
}
@ -126,6 +126,7 @@ class MockPlatform final : public TestPlatform {
void Cancel() override { orig_handle_->Cancel(); }
void CancelAndDetach() override { orig_handle_->CancelAndDetach(); }
bool IsRunning() override { return orig_handle_->IsRunning(); }
bool IsValid() override { return orig_handle_->IsValid(); }
bool IsCompleted() override { return orig_handle_->IsCompleted(); }
private: