Commit cce601ba authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

[heap] Split off changes for concurrently processing TracedReference

Trivial changes from https://crrev.com/c/3571887.

Bug: v8:12600
Change-Id: I0a6f36d32f72a6c3817a4390645ccf5a690c5580
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3579161Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79885}
parent 04b8124b
......@@ -161,6 +161,7 @@ class V8_EXPORT CppHeap {
class JSVisitor : public cppgc::Visitor {
public:
explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
~JSVisitor() override = default;
void Trace(const TracedReferenceBase& ref) {
if (ref.IsEmptyThreadSafe()) return;
......
......@@ -203,9 +203,12 @@ void ConcurrentMarkerBase::Start() {
std::make_unique<ConcurrentMarkingTask>(*this));
}
void ConcurrentMarkerBase::Cancel() {
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsValid())
concurrent_marking_handle_->Cancel();
bool ConcurrentMarkerBase::Cancel() {
if (!concurrent_marking_handle_ || !concurrent_marking_handle_->IsValid())
return false;
concurrent_marking_handle_->Cancel();
return true;
}
void ConcurrentMarkerBase::JoinForTesting() {
......
......@@ -24,7 +24,8 @@ class V8_EXPORT_PRIVATE ConcurrentMarkerBase {
ConcurrentMarkerBase& operator=(const ConcurrentMarkerBase&) = delete;
void Start();
void Cancel();
// Returns whether the job has been cancelled.
bool Cancel();
void JoinForTesting();
......
......@@ -218,7 +218,6 @@ void MarkerBase::StartMarking() {
MarkingConfig::MarkingType::kIncrementalAndConcurrent) {
mutator_marking_state_.Publish();
concurrent_marker_->Start();
concurrent_marking_active_ = true;
}
incremental_marking_allocation_observer_ =
std::make_unique<IncrementalMarkingAllocationObserver>(*this);
......@@ -262,11 +261,10 @@ void MarkerBase::EnterAtomicPause(MarkingConfig::StackState stack_state) {
MarkingConfig::MarkingType::kIncrementalAndConcurrent) {
// Start parallel marking.
mutator_marking_state_.Publish();
if (concurrent_marking_active_) {
if (concurrent_marker_->IsActive()) {
concurrent_marker_->NotifyIncrementalMutatorStepCompleted();
} else {
concurrent_marker_->Start();
concurrent_marking_active_ = true;
}
}
}
......@@ -433,11 +431,9 @@ void MarkerBase::AdvanceMarkingOnAllocation() {
bool MarkerBase::CancelConcurrentMarkingIfNeeded() {
if (config_.marking_type != MarkingConfig::MarkingType::kAtomic ||
!concurrent_marking_active_)
!concurrent_marker_->Cancel())
return false;
concurrent_marker_->Cancel();
concurrent_marking_active_ = false;
// Concurrent markers may have pushed some "leftover" in-construction objects
// after flushing in EnterAtomicPause.
HandleNotFullyConstructedObjects();
......
......@@ -183,7 +183,6 @@ class V8_EXPORT_PRIVATE MarkerBase {
IncrementalMarkingSchedule schedule_;
std::unique_ptr<ConcurrentMarkerBase> concurrent_marker_{nullptr};
bool concurrent_marking_active_ = false;
bool main_marking_disabled_for_testing_{false};
bool visited_cross_thread_persistents_in_atomic_pause_{false};
......
......@@ -609,7 +609,7 @@ void MarkCompactCollector::StartMarking() {
if (FLAG_verify_heap) {
VerifyMarkbitsAreClean();
}
#endif
#endif // VERIFY_HEAP
}
void MarkCompactCollector::CollectGarbage() {
......@@ -976,16 +976,21 @@ void MarkCompactCollector::Prepare() {
DCHECK(!sweeping_in_progress());
if (!heap()->incremental_marking()->IsMarking()) {
const auto embedder_flags = heap_->flags_for_embedder_tracer();
{
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_EMBEDDER_PROLOGUE);
auto embedder_flags = heap_->flags_for_embedder_tracer();
// PrepareForTrace should be called before visitor initialization in
// StartMarking.
heap_->local_embedder_heap_tracer()->PrepareForTrace(embedder_flags);
heap_->local_embedder_heap_tracer()->TracePrologue(embedder_flags);
}
StartCompaction(StartCompactionMode::kAtomic);
StartMarking();
{
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_EMBEDDER_PROLOGUE);
// TracePrologue immediately starts marking which requires V8 worklists to
// be set up.
heap_->local_embedder_heap_tracer()->TracePrologue(embedder_flags);
}
}
heap_->FreeLinearAllocationAreas();
......
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