Commit f62fc2e1 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Allow enabling --local-heaps by default

All tests pass now with --concurrent-allocation and --local-heaps flags
set to true.

Bug: v8:10315
Change-Id: I03a70933aa0db4d9e74933ad2fc4cb81105cb889
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2218061Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68111}
parent 1e0287c1
...@@ -10,7 +10,8 @@ namespace internal { ...@@ -10,7 +10,8 @@ namespace internal {
CombinedHeapObjectIterator::CombinedHeapObjectIterator( CombinedHeapObjectIterator::CombinedHeapObjectIterator(
Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering) Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering)
: heap_iterator_(heap, filtering), : safepoint_scope_(heap),
heap_iterator_(heap, filtering),
ro_heap_iterator_(heap->isolate()->read_only_heap()) {} ro_heap_iterator_(heap->isolate()->read_only_heap()) {}
HeapObject CombinedHeapObjectIterator::Next() { HeapObject CombinedHeapObjectIterator::Next() {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/heap/read-only-heap.h" #include "src/heap/read-only-heap.h"
#include "src/heap/safepoint.h"
#include "src/heap/third-party/heap-api.h" #include "src/heap/third-party/heap-api.h"
#include "src/objects/objects.h" #include "src/objects/objects.h"
...@@ -25,6 +26,7 @@ class V8_EXPORT_PRIVATE CombinedHeapObjectIterator final { ...@@ -25,6 +26,7 @@ class V8_EXPORT_PRIVATE CombinedHeapObjectIterator final {
HeapObject Next(); HeapObject Next();
private: private:
SafepointScope safepoint_scope_;
HeapObjectIterator heap_iterator_; HeapObjectIterator heap_iterator_;
ReadOnlyHeapObjectIterator ro_heap_iterator_; ReadOnlyHeapObjectIterator ro_heap_iterator_;
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <cinttypes> #include <cinttypes>
#include <iomanip> #include <iomanip>
#include <memory>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
...@@ -3240,6 +3241,7 @@ FixedArrayBase Heap::LeftTrimFixedArray(FixedArrayBase object, ...@@ -3240,6 +3241,7 @@ FixedArrayBase Heap::LeftTrimFixedArray(FixedArrayBase object,
if (FLAG_enable_slow_asserts) { if (FLAG_enable_slow_asserts) {
// Make sure the stack or other roots (e.g., Handles) don't contain pointers // Make sure the stack or other roots (e.g., Handles) don't contain pointers
// to the original FixedArray (which is now the filler object). // to the original FixedArray (which is now the filler object).
SafepointScope scope(this);
LeftTrimmerVerifierRootVisitor root_visitor(object); LeftTrimmerVerifierRootVisitor root_visitor(object);
ReadOnlyRoots(this).Iterate(&root_visitor); ReadOnlyRoots(this).Iterate(&root_visitor);
IterateRoots(&root_visitor, {}); IterateRoots(&root_visitor, {});
...@@ -4206,6 +4208,7 @@ class VerifyReadOnlyPointersVisitor : public VerifyPointersVisitor { ...@@ -4206,6 +4208,7 @@ class VerifyReadOnlyPointersVisitor : public VerifyPointersVisitor {
void Heap::Verify() { void Heap::Verify() {
CHECK(HasBeenSetUp()); CHECK(HasBeenSetUp());
SafepointScope safepoint_scope(this);
HandleScope scope(isolate()); HandleScope scope(isolate());
if (FLAG_local_heaps) { if (FLAG_local_heaps) {
...@@ -6046,6 +6049,7 @@ class UnreachableObjectsFilter : public HeapObjectsFilter { ...@@ -6046,6 +6049,7 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
HeapObjectIterator::HeapObjectIterator( HeapObjectIterator::HeapObjectIterator(
Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering) Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering)
: heap_(heap), : heap_(heap),
safepoint_scope_(std::make_unique<SafepointScope>(heap)),
filtering_(filtering), filtering_(filtering),
filter_(nullptr), filter_(nullptr),
space_iterator_(nullptr), space_iterator_(nullptr),
......
...@@ -88,6 +88,7 @@ class Page; ...@@ -88,6 +88,7 @@ class Page;
class PagedSpace; class PagedSpace;
class ReadOnlyHeap; class ReadOnlyHeap;
class RootVisitor; class RootVisitor;
class SafepointScope;
class ScavengeJob; class ScavengeJob;
class Scavenger; class Scavenger;
class ScavengerCollector; class ScavengerCollector;
...@@ -2507,6 +2508,7 @@ class V8_EXPORT_PRIVATE HeapObjectIterator { ...@@ -2507,6 +2508,7 @@ class V8_EXPORT_PRIVATE HeapObjectIterator {
DISALLOW_HEAP_ALLOCATION(no_heap_allocation_) DISALLOW_HEAP_ALLOCATION(no_heap_allocation_)
Heap* heap_; Heap* heap_;
std::unique_ptr<SafepointScope> safepoint_scope_;
HeapObjectsFiltering filtering_; HeapObjectsFiltering filtering_;
HeapObjectsFilter* filter_; HeapObjectsFilter* filter_;
// Space iterator for iterating all the spaces. // Space iterator for iterating all the spaces.
......
...@@ -13,13 +13,16 @@ namespace v8 { ...@@ -13,13 +13,16 @@ namespace v8 {
namespace internal { namespace internal {
GlobalSafepoint::GlobalSafepoint(Heap* heap) GlobalSafepoint::GlobalSafepoint(Heap* heap)
: heap_(heap), local_heaps_head_(nullptr), is_active_(false) {} : heap_(heap), local_heaps_head_(nullptr), active_safepoint_scopes_(0) {}
void GlobalSafepoint::Start() { StopThreads(); } void GlobalSafepoint::Start() { EnterSafepointScope(); }
void GlobalSafepoint::End() { ResumeThreads(); } void GlobalSafepoint::End() { LeaveSafepointScope(); }
void GlobalSafepoint::StopThreads() { void GlobalSafepoint::EnterSafepointScope() {
if (!FLAG_local_heaps) return;
if (++active_safepoint_scopes_ > 1) return;
local_heaps_mutex_.Lock(); local_heaps_mutex_.Lock();
barrier_.Arm(); barrier_.Arm();
...@@ -37,12 +40,13 @@ void GlobalSafepoint::StopThreads() { ...@@ -37,12 +40,13 @@ void GlobalSafepoint::StopThreads() {
current->state_change_.Wait(&current->state_mutex_); current->state_change_.Wait(&current->state_mutex_);
} }
} }
is_active_ = true;
} }
void GlobalSafepoint::ResumeThreads() { void GlobalSafepoint::LeaveSafepointScope() {
is_active_ = false; if (!FLAG_local_heaps) return;
DCHECK_GT(active_safepoint_scopes_, 0);
if (--active_safepoint_scopes_ > 0) return;
for (LocalHeap* current = local_heaps_head_; current; for (LocalHeap* current = local_heaps_head_; current;
current = current->next_) { current = current->next_) {
...@@ -90,12 +94,10 @@ void GlobalSafepoint::Barrier::Wait() { ...@@ -90,12 +94,10 @@ void GlobalSafepoint::Barrier::Wait() {
} }
SafepointScope::SafepointScope(Heap* heap) : safepoint_(heap->safepoint()) { SafepointScope::SafepointScope(Heap* heap) : safepoint_(heap->safepoint()) {
if (FLAG_local_heaps) safepoint_->StopThreads(); safepoint_->EnterSafepointScope();
} }
SafepointScope::~SafepointScope() { SafepointScope::~SafepointScope() { safepoint_->LeaveSafepointScope(); }
if (FLAG_local_heaps) safepoint_->ResumeThreads();
}
void GlobalSafepoint::AddLocalHeap(LocalHeap* local_heap) { void GlobalSafepoint::AddLocalHeap(LocalHeap* local_heap) {
base::MutexGuard guard(&local_heaps_mutex_); base::MutexGuard guard(&local_heaps_mutex_);
......
...@@ -47,7 +47,7 @@ class GlobalSafepoint { ...@@ -47,7 +47,7 @@ class GlobalSafepoint {
void Start(); void Start();
void End(); void End();
bool IsActive() { return is_active_; } bool IsActive() { return active_safepoint_scopes_ > 0; }
private: private:
class Barrier { class Barrier {
...@@ -63,8 +63,8 @@ class GlobalSafepoint { ...@@ -63,8 +63,8 @@ class GlobalSafepoint {
void Wait(); void Wait();
}; };
void StopThreads(); void EnterSafepointScope();
void ResumeThreads(); void LeaveSafepointScope();
void AddLocalHeap(LocalHeap* local_heap); void AddLocalHeap(LocalHeap* local_heap);
void RemoveLocalHeap(LocalHeap* local_heap); void RemoveLocalHeap(LocalHeap* local_heap);
...@@ -75,7 +75,7 @@ class GlobalSafepoint { ...@@ -75,7 +75,7 @@ class GlobalSafepoint {
base::Mutex local_heaps_mutex_; base::Mutex local_heaps_mutex_;
LocalHeap* local_heaps_head_; LocalHeap* local_heaps_head_;
bool is_active_; int active_safepoint_scopes_;
friend class SafepointScope; friend class SafepointScope;
friend class LocalHeap; friend class LocalHeap;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/handles/global-handles.h" #include "src/handles/global-handles.h"
#include "src/heap/combined-heap.h" #include "src/heap/combined-heap.h"
#include "src/heap/safepoint.h"
#include "src/numbers/conversions.h" #include "src/numbers/conversions.h"
#include "src/objects/allocation-site-inl.h" #include "src/objects/allocation-site-inl.h"
#include "src/objects/api-callbacks.h" #include "src/objects/api-callbacks.h"
...@@ -2037,6 +2038,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() { ...@@ -2037,6 +2038,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
GarbageCollectionReason::kHeapProfiler); GarbageCollectionReason::kHeapProfiler);
NullContextForSnapshotScope null_context_scope(Isolate::FromHeap(heap_)); NullContextForSnapshotScope null_context_scope(Isolate::FromHeap(heap_));
SafepointScope scope(heap_);
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
Heap* debug_heap = heap_; Heap* debug_heap = heap_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/heap/incremental-marking.h" #include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact.h" #include "src/heap/mark-compact.h"
#include "src/heap/memory-chunk.h" #include "src/heap/memory-chunk.h"
#include "src/heap/safepoint.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
namespace v8 { namespace v8 {
...@@ -177,6 +178,7 @@ void SimulateIncrementalMarking(i::Heap* heap, bool force_completion) { ...@@ -177,6 +178,7 @@ void SimulateIncrementalMarking(i::Heap* heap, bool force_completion) {
marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
i::StepOrigin::kV8); i::StepOrigin::kV8);
if (marking->IsReadyToOverApproximateWeakClosure()) { if (marking->IsReadyToOverApproximateWeakClosure()) {
SafepointScope scope(heap);
marking->FinalizeIncrementally(); marking->FinalizeIncrementally();
} }
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "include/v8.h" #include "include/v8.h"
#include "src/api/api-inl.h" #include "src/api/api-inl.h"
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/heap/safepoint.h"
#include "src/objects/module.h" #include "src/objects/module.h"
#include "src/objects/objects-inl.h" #include "src/objects/objects-inl.h"
#include "src/objects/script.h" #include "src/objects/script.h"
...@@ -264,7 +265,11 @@ TEST(FinalizeTracingWhenMarking) { ...@@ -264,7 +265,11 @@ TEST(FinalizeTracingWhenMarking) {
CHECK(i_isolate->heap()->incremental_marking()->IsStopped()); CHECK(i_isolate->heap()->incremental_marking()->IsStopped());
i::IncrementalMarking* marking = i_isolate->heap()->incremental_marking(); i::IncrementalMarking* marking = i_isolate->heap()->incremental_marking();
{
SafepointScope scope(i_isolate->heap());
marking->Start(i::GarbageCollectionReason::kTesting); marking->Start(i::GarbageCollectionReason::kTesting);
}
// Sweeping is not runing so we should immediately start marking. // Sweeping is not runing so we should immediately start marking.
CHECK(marking->IsMarking()); CHECK(marking->IsMarking());
tracer.FinalizeTracing(); tracer.FinalizeTracing();
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "src/heap/memory-chunk.h" #include "src/heap/memory-chunk.h"
#include "src/heap/memory-reducer.h" #include "src/heap/memory-reducer.h"
#include "src/heap/remembered-set-inl.h" #include "src/heap/remembered-set-inl.h"
#include "src/heap/safepoint.h"
#include "src/ic/ic.h" #include "src/ic/ic.h"
#include "src/numbers/hash-seed-inl.h" #include "src/numbers/hash-seed-inl.h"
#include "src/objects/elements.h" #include "src/objects/elements.h"
...@@ -5616,6 +5617,7 @@ TEST(Regress598319) { ...@@ -5616,6 +5617,7 @@ TEST(Regress598319) {
i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
StepOrigin::kV8); StepOrigin::kV8);
if (marking->IsReadyToOverApproximateWeakClosure()) { if (marking->IsReadyToOverApproximateWeakClosure()) {
SafepointScope scope(heap);
marking->FinalizeIncrementally(); marking->FinalizeIncrementally();
} }
} }
...@@ -5699,6 +5701,7 @@ TEST(Regress615489) { ...@@ -5699,6 +5701,7 @@ TEST(Regress615489) {
marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
StepOrigin::kV8); StepOrigin::kV8);
if (marking->IsReadyToOverApproximateWeakClosure()) { if (marking->IsReadyToOverApproximateWeakClosure()) {
SafepointScope scope(heap);
marking->FinalizeIncrementally(); marking->FinalizeIncrementally();
} }
} }
...@@ -5761,6 +5764,7 @@ TEST(Regress631969) { ...@@ -5761,6 +5764,7 @@ TEST(Regress631969) {
marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, marking->Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
StepOrigin::kV8); StepOrigin::kV8);
if (marking->IsReadyToOverApproximateWeakClosure()) { if (marking->IsReadyToOverApproximateWeakClosure()) {
SafepointScope scope(heap);
marking->FinalizeIncrementally(); marking->FinalizeIncrementally();
} }
} }
...@@ -6340,6 +6344,7 @@ HEAP_TEST(Regress670675) { ...@@ -6340,6 +6344,7 @@ HEAP_TEST(Regress670675) {
} }
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
if (marking->IsStopped()) { if (marking->IsStopped()) {
SafepointScope scope(heap);
marking->Start(i::GarbageCollectionReason::kTesting); marking->Start(i::GarbageCollectionReason::kTesting);
} }
size_t array_length = 128 * KB; size_t array_length = 128 * KB;
...@@ -6998,6 +7003,7 @@ TEST(Regress978156) { ...@@ -6998,6 +7003,7 @@ TEST(Regress978156) {
// 5. Start incremental marking. // 5. Start incremental marking.
i::IncrementalMarking* marking = heap->incremental_marking(); i::IncrementalMarking* marking = heap->incremental_marking();
if (marking->IsStopped()) { if (marking->IsStopped()) {
SafepointScope scope(heap);
marking->Start(i::GarbageCollectionReason::kTesting); marking->Start(i::GarbageCollectionReason::kTesting);
} }
IncrementalMarking::MarkingState* marking_state = marking->marking_state(); IncrementalMarking::MarkingState* marking_state = marking->marking_state();
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "src/heap/safepoint.h"
#ifdef __linux__ #ifdef __linux__
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -104,7 +106,10 @@ TEST(IncrementalMarkingUsingTasks) { ...@@ -104,7 +106,10 @@ TEST(IncrementalMarkingUsingTasks) {
i::heap::SimulateFullSpace(CcTest::heap()->old_space()); i::heap::SimulateFullSpace(CcTest::heap()->old_space());
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
marking->Stop(); marking->Stop();
{
SafepointScope scope(CcTest::heap());
marking->Start(i::GarbageCollectionReason::kTesting); marking->Start(i::GarbageCollectionReason::kTesting);
}
CHECK(platform.PendingTask()); CHECK(platform.PendingTask());
while (platform.PendingTask()) { while (platform.PendingTask()) {
platform.PerformTask(); platform.PerformTask();
......
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