Commit a90f361f authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Speed up Worklist::IsGlobalPoolEmpty check.

This patch makes the check lock-free. When concurrent marking is on,
the main thread checks two marking worklist: bailout and shared.

Often the bailout worklist empty, so the emptiness check is in hot path.

Bug: chromium:694255
TBR: mlippautz@chromium.org
Change-Id: I5c92ea3fb6c5300d653fbd27b536241851231f24
Reviewed-on: https://chromium-review.googlesource.com/602351Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47184}
parent 668d8927
......@@ -8,6 +8,7 @@
#include <cstddef>
#include <vector>
#include "src/base/atomic-utils.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/base/platform/mutex.h"
......@@ -243,22 +244,21 @@ class Worklist {
V8_INLINE void Push(Segment* segment) {
base::LockGuard<base::Mutex> guard(&lock_);
segment->set_next(top_);
top_ = segment;
SetTop(segment);
}
V8_INLINE bool Pop(Segment** segment) {
base::LockGuard<base::Mutex> guard(&lock_);
if (top_ != nullptr) {
*segment = top_;
top_ = top_->next();
SetTop(top_->next());
return true;
}
return false;
}
V8_INLINE bool IsEmpty() {
base::LockGuard<base::Mutex> guard(&lock_);
return top_ == nullptr;
return base::AsAtomicPointer::Relaxed_Load(&top_) == nullptr;
}
void Clear() {
......@@ -269,7 +269,7 @@ class Worklist {
current = current->next();
delete tmp;
}
top_ = nullptr;
SetTop(nullptr);
}
// See Worklist::Update.
......@@ -307,6 +307,9 @@ class Worklist {
}
private:
void SetTop(Segment* segment) {
base::AsAtomicPointer::Relaxed_Store(&top_, segment);
}
base::Mutex lock_;
Segment* top_;
};
......@@ -334,6 +337,7 @@ class Worklist {
}
V8_INLINE bool StealPopSegmentFromGlobal(int task_id) {
if (global_pool_.IsEmpty()) return false;
Segment* new_segment = nullptr;
if (global_pool_.Pop(&new_segment)) {
delete private_pop_segment(task_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment