diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 11:40:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 12:42:11 +0000 |
commit | 5d87695f37678f96492b258bbab36486c59866b4 (patch) | |
tree | be9783bbaf04fb930c4d74ca9c00b5e7954c8bc6 /chromium/third_party/blink/renderer/platform/heap | |
parent | 6c11fb357ec39bf087b8b632e2b1e375aef1b38b (diff) | |
download | qtwebengine-chromium-5d87695f37678f96492b258bbab36486c59866b4.tar.gz |
BASELINE: Update Chromium to 75.0.3770.56
Change-Id: I86d2007fd27a45d5797eee06f4c9369b8b50ac4f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/heap')
43 files changed, 796 insertions, 1434 deletions
diff --git a/chromium/third_party/blink/renderer/platform/heap/BUILD.gn b/chromium/third_party/blink/renderer/platform/heap/BUILD.gn index ed62cd53746..31f54f42777 100644 --- a/chromium/third_party/blink/renderer/platform/heap/BUILD.gn +++ b/chromium/third_party/blink/renderer/platform/heap/BUILD.gn @@ -8,12 +8,6 @@ import("//testing/test.gni") import("//third_party/blink/renderer/platform/platform.gni") declare_args() { - # Build Blink with incremental marking infrastructure for Oilpan. - # - # To turn on incremental marking also use - # --enable-blink-features=HeapIncrementalMarking - enable_blink_heap_incremental_marking = true - # Enables heap verification. enable_blink_heap_verification = false } @@ -22,10 +16,7 @@ buildflag_header("blink_heap_buildflags") { header = "heap_buildflags.h" header_dir = "third_party/blink/renderer/platform/heap" - flags = [ - "BLINK_HEAP_INCREMENTAL_MARKING=$enable_blink_heap_incremental_marking", - "BLINK_HEAP_VERIFICATION=$enable_blink_heap_verification", - ] + flags = [ "BLINK_HEAP_VERIFICATION=$enable_blink_heap_verification" ] } blink_platform_sources("heap") { @@ -71,8 +62,6 @@ blink_platform_sources("heap") { "self_keep_alive.h", "sparse_heap_bitmap.cc", "sparse_heap_bitmap.h", - "stack_frame_depth.cc", - "stack_frame_depth.h", "thread_state.cc", "thread_state.h", "thread_state_scopes.h", diff --git a/chromium/third_party/blink/renderer/platform/heap/asm/BUILD.gn b/chromium/third_party/blink/renderer/platform/heap/asm/BUILD.gn index 6c87950f41a..a2fab32b3c1 100644 --- a/chromium/third_party/blink/renderer/platform/heap/asm/BUILD.gn +++ b/chromium/third_party/blink/renderer/platform/heap/asm/BUILD.gn @@ -46,6 +46,10 @@ if (current_cpu == "x86" || current_cpu == "x64") { sources = [ "SaveRegisters_mips64.S", ] + } else if (current_cpu == "ppc64") { + sources = [ + "SaveRegisters_ppc64.S", + ] } if (current_cpu == "arm") { diff --git a/chromium/third_party/blink/renderer/platform/heap/asm/SaveRegisters_ppc64.S b/chromium/third_party/blink/renderer/platform/heap/asm/SaveRegisters_ppc64.S new file mode 100644 index 00000000000..14c8abaa668 --- /dev/null +++ b/chromium/third_party/blink/renderer/platform/heap/asm/SaveRegisters_ppc64.S @@ -0,0 +1,54 @@ +/* + * typedef void (*PushAllRegistersCallback)(SafePointBarrier*, ThreadState*, intptr_t*); + * extern "C" void PushAllRegisters(SafePointBarrier*, ThreadState*, PushAllRegistersCallback) + */ + +.type PushAllRegisters, %function +.global PushAllRegisters +.hidden PushAllRegisters +PushAllRegisters: + // Push all callee-saves registers to get them + // on the stack for conservative stack scanning. + // Reserve space for callee-saved registers and minimal stack frame. + mflr 0 + std 0,16(1) + stdu 1,-176(1) // 3218*8 = min stack non-volatile registers + + // Save the callee-saved register + std 31,168(1) + std 30,160(1) + std 29,152(1) + std 28,144(1) + std 27,136(1) + std 26,128(1) + std 25,120(1) + std 24,112(1) + std 23,104(1) + std 22,96(1) + std 21,88(1) + std 20,80(1) + std 19,72(1) + std 18,64(1) + std 17,56(1) + std 16,48(1) + std 15,40(1) + std 14,32(1) + // Note: the callee-saved floating point registers do not need to be + // copied to the stack, because fp registers never hold heap pointers + // and so do not need to be kept visible to the garbage collector. + // Pass the two first arguments untouched in r3 and r4 and the + // stack pointer to the callback. + std 2, 24(1) + mtctr 5 + mr 12, 5 + mr 5, 1 + bctrl + ld 2, 24(1) + + // Adjust stack, restore return address and return. + // Note: the copied registers do not need to be reloaded here, + // because they were preserved by the called routine. + addi 1,1,176 + ld 0,16(1) + mtlr 0 + blr diff --git a/chromium/third_party/blink/renderer/platform/heap/blink_gc.h b/chromium/third_party/blink/renderer/platform/heap/blink_gc.h index d6663b55f9f..f1cda113b4a 100644 --- a/chromium/third_party/blink/renderer/platform/heap/blink_gc.h +++ b/chromium/third_party/blink/renderer/platform/heap/blink_gc.h @@ -85,16 +85,19 @@ class PLATFORM_EXPORT BlinkGC final { kEagerSweeping, }; + // Commented out reasons have been used in the past but are not used any + // longer. We keep them here as the corresponding UMA histograms cannot be + // changed. enum class GCReason { - kIdleGC = 0, + // kIdleGC = 0, kPreciseGC = 1, kConservativeGC = 2, - kForcedGC = 3, + kForcedGCForTesting = 3, kMemoryPressureGC = 4, kPageNavigationGC = 5, kThreadTerminationGC = 6, - kTesting = 7, - kIncrementalIdleGC = 8, + // kTesting = 7, + // kIncrementalIdleGC = 8, kIncrementalV8FollowupGC = 9, kUnifiedHeapGC = 10, kMaxValue = kUnifiedHeapGC, diff --git a/chromium/third_party/blink/renderer/platform/heap/blink_gc_memory_dump_provider.cc b/chromium/third_party/blink/renderer/platform/heap/blink_gc_memory_dump_provider.cc index deae8e957e9..e8ef8c4eb2b 100644 --- a/chromium/third_party/blink/renderer/platform/heap/blink_gc_memory_dump_provider.cc +++ b/chromium/third_party/blink/renderer/platform/heap/blink_gc_memory_dump_provider.cc @@ -52,7 +52,7 @@ bool BlinkGCMemoryDumpProvider::OnMemoryDump( if (level_of_detail == MemoryDumpLevelOfDetail::DETAILED) { ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kTakeSnapshot, - BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGCForTesting); } DumpMemoryTotals(memory_dump); diff --git a/chromium/third_party/blink/renderer/platform/heap/heap.cc b/chromium/third_party/blink/renderer/platform/heap/heap.cc index 3b62f5c1559..0d356a94df2 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap.cc @@ -177,12 +177,8 @@ void ThreadHeap::DecommitCallbackStacks() { NotFullyConstructedItem item; while (not_fully_constructed_worklist_->Pop(WorklistTaskId::MainThread, &item)) { - BasePage* const page = PageFromObject(item); - HeapObjectHeader* const header = - page->IsLargeObjectPage() - ? static_cast<LargeObjectPage*>(page)->ObjectHeader() - : static_cast<NormalPage*>(page)->FindHeaderFromAddress( - reinterpret_cast<Address>(const_cast<void*>(item))); + HeapObjectHeader* const header = HeapObjectHeader::FromInnerAddress( + reinterpret_cast<Address>(const_cast<void*>(item))); DCHECK(header->IsMarked()); } #else @@ -194,7 +190,7 @@ void ThreadHeap::DecommitCallbackStacks() { HeapCompact* ThreadHeap::Compaction() { if (!compaction_) - compaction_ = HeapCompact::Create(this); + compaction_ = std::make_unique<HeapCompact>(this); return compaction_.get(); } @@ -517,8 +513,7 @@ void ThreadHeap::TakeSnapshot(SnapshotType type) { // gcInfoIndex. ThreadState::GCSnapshotInfo info(GCInfoTable::Get().GcInfoIndex() + 1); String thread_dump_name = - String::Format("blink_gc/thread_%lu", - static_cast<unsigned long>(thread_state_->ThreadId())); + String("blink_gc/thread_") + String::Number(thread_state_->ThreadId()); const String heaps_dump_name = thread_dump_name + "/heaps"; const String classes_dump_name = thread_dump_name + "/classes"; @@ -612,12 +607,8 @@ void ThreadHeap::WriteBarrier(void* value) { // '-1' is used to indicate deleted values. DCHECK_NE(value, reinterpret_cast<void*>(-1)); - BasePage* const page = PageFromObject(value); - HeapObjectHeader* const header = - page->IsLargeObjectPage() - ? static_cast<LargeObjectPage*>(page)->ObjectHeader() - : static_cast<NormalPage*>(page)->FindHeaderFromAddress( - reinterpret_cast<Address>(const_cast<void*>(value))); + HeapObjectHeader* const header = HeapObjectHeader::FromInnerAddress( + reinterpret_cast<Address>(const_cast<void*>(value))); if (header->IsMarked()) return; diff --git a/chromium/third_party/blink/renderer/platform/heap/heap.h b/chromium/third_party/blink/renderer/platform/heap/heap.h index bba0cf1db4d..0741595ef9d 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap.h +++ b/chromium/third_party/blink/renderer/platform/heap/heap.h @@ -39,7 +39,6 @@ #include "third_party/blink/renderer/platform/heap/gc_info.h" #include "third_party/blink/renderer/platform/heap/heap_page.h" #include "third_party/blink/renderer/platform/heap/process_heap.h" -#include "third_party/blink/renderer/platform/heap/stack_frame_depth.h" #include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/visitor.h" #include "third_party/blink/renderer/platform/heap/worklist.h" @@ -201,8 +200,6 @@ class PLATFORM_EXPORT ThreadHeap { return IsHeapObjectAlive(member.Get()); } - StackFrameDepth& GetStackFrameDepth() { return stack_frame_depth_; } - MarkingWorklist* GetMarkingWorklist() const { return marking_worklist_.get(); } @@ -474,7 +471,6 @@ class PLATFORM_EXPORT ThreadHeap { // No duplicates allowed for ephemeron callbacks. Hence, we use a hashmap // with the key being the HashTable. WTF::HashMap<void*, EphemeronCallback> ephemeron_callbacks_; - StackFrameDepth stack_frame_depth_; std::unique_ptr<HeapCompact> compaction_; diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_allocator.h b/chromium/third_party/blink/renderer/platform/heap/heap_allocator.h index 89b5dbf8e5e..04159a8e166 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_allocator.h +++ b/chromium/third_party/blink/renderer/platform/heap/heap_allocator.h @@ -6,7 +6,6 @@ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_ALLOCATOR_H_ #include "build/build_config.h" -#include "third_party/blink/renderer/platform/bindings/script_wrappable_marking_visitor.h" #include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap_buildflags.h" #include "third_party/blink/renderer/platform/heap/marking_visitor.h" @@ -138,9 +137,8 @@ class PLATFORM_EXPORT HeapAllocator { } template <typename T> - static void BackingWriteBarrier(TraceWrapperMember<T>* address, size_t size) { + static void BackingWriteBarrier(Member<T>* address, size_t size) { MarkingVisitor::WriteBarrier(address); - ScriptWrappableMarkingVisitor::WriteBarrier(address, size); } template <typename T> @@ -215,7 +213,6 @@ class PLATFORM_EXPORT HeapAllocator { template <typename T, typename Traits> static void NotifyNewObject(T* object) { -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) if (!ThreadState::IsAnyIncrementalMarking()) return; // The object may have been in-place constructed as part of a large object. @@ -226,10 +223,6 @@ class PLATFORM_EXPORT HeapAllocator { // are discovered by the marker. ThreadState::NoAllocationScope no_allocation_scope(thread_state); DCHECK(thread_state->CurrentVisitor()); - // This check ensures that the visitor will not eagerly recurse into - // children but rather push all blink::GarbageCollected objects and only - // eagerly trace non-managed objects. - DCHECK(!thread_state->Heap().GetStackFrameDepth().IsEnabled()); // No weak handling for write barriers. Modifying weakly reachable objects // strongifies them for the current cycle. DCHECK(!Traits::kCanHaveDeletedValue || !Traits::IsDeletedValue(*object)); @@ -238,12 +231,10 @@ class PLATFORM_EXPORT HeapAllocator { ->CurrentVisitor(), *object); } -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) } template <typename T, typename Traits> static void NotifyNewObjects(T* array, size_t len) { -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) if (!ThreadState::IsAnyIncrementalMarking()) return; // The object may have been in-place constructed as part of a large object. @@ -253,7 +244,6 @@ class PLATFORM_EXPORT HeapAllocator { // See |NotifyNewObject| for details. ThreadState::NoAllocationScope no_allocation_scope(thread_state); DCHECK(thread_state->CurrentVisitor()); - DCHECK(!thread_state->Heap().GetStackFrameDepth().IsEnabled()); // No weak handling for write barriers. Modifying weakly reachable objects // strongifies them for the current cycle. while (len-- > 0) { @@ -266,7 +256,6 @@ class PLATFORM_EXPORT HeapAllocator { array++; } } -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) } template <typename T> @@ -728,18 +717,6 @@ struct VectorTraits<blink::SameThreadCheckedMember<T>> }; template <typename T> -struct VectorTraits<blink::TraceWrapperMember<T>> - : VectorTraitsBase<blink::TraceWrapperMember<T>> { - STATIC_ONLY(VectorTraits); - static const bool kNeedsDestruction = false; - static const bool kCanInitializeWithMemset = true; - static const bool kCanClearUnusedSlotsWithMemset = true; - static const bool kCanMoveWithMemcpy = true; - static const bool kCanCopyWithMemcpy = true; - static const bool kCanSwapUsingCopyOrMove = true; -}; - -template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBase<blink::WeakMember<T>> { STATIC_ONLY(VectorTraits); @@ -875,39 +852,6 @@ struct HashTraits<blink::SameThreadCheckedMember<T>> }; template <typename T> -struct HashTraits<blink::TraceWrapperMember<T>> - : SimpleClassHashTraits<blink::TraceWrapperMember<T>> { - STATIC_ONLY(HashTraits); - // FIXME: Implement proper const'ness for iterator types. Requires support - // in the marking Visitor. - using PeekInType = T*; - using IteratorGetType = blink::TraceWrapperMember<T>*; - using IteratorConstGetType = const blink::TraceWrapperMember<T>*; - using IteratorReferenceType = blink::TraceWrapperMember<T>&; - using IteratorConstReferenceType = const blink::TraceWrapperMember<T>&; - static IteratorReferenceType GetToReferenceConversion(IteratorGetType x) { - return *x; - } - static IteratorConstReferenceType GetToReferenceConstConversion( - IteratorConstGetType x) { - return *x; - } - - using PeekOutType = T*; - - template <typename U> - static void Store(const U& value, blink::TraceWrapperMember<T>& storage) { - storage = value; - } - - static PeekOutType Peek(const blink::TraceWrapperMember<T>& value) { - return value; - } - - static blink::TraceWrapperMember<T> EmptyValue() { return nullptr; } -}; - -template <typename T> struct HashTraits<blink::WeakMember<T>> : SimpleClassHashTraits<blink::WeakMember<T>> { STATIC_ONLY(HashTraits); diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_compact.cc b/chromium/third_party/blink/renderer/platform/heap/heap_compact.cc index ee869a27bce..8766f7f517d 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_compact.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_compact.cc @@ -32,10 +32,7 @@ class HeapCompact::MovableObjectFixups final { USING_FAST_MALLOC(HeapCompact::MovableObjectFixups); public: - static std::unique_ptr<MovableObjectFixups> Create(ThreadHeap* heap) { - return base::WrapUnique(new MovableObjectFixups(heap)); - } - + explicit MovableObjectFixups(ThreadHeap* heap) : heap_(heap) {} ~MovableObjectFixups() = default; // For the arenas being compacted, record all pages belonging to them. @@ -50,14 +47,14 @@ class HeapCompact::MovableObjectFixups final { auto it = interior_fixups_.find(slot); // Ephemeron fixpoint iterations may cause repeated registrations. if (UNLIKELY(it != interior_fixups_.end())) { - DCHECK(!it->value); + DCHECK(!it->second); return; } - interior_fixups_.insert(slot, nullptr); + interior_fixups_.insert({slot, nullptr}); LOG_HEAP_COMPACTION() << "Interior slot: " << slot; Address slot_address = reinterpret_cast<Address>(slot); if (!interiors_) { - interiors_ = SparseHeapBitmap::Create(slot_address); + interiors_ = std::make_unique<SparseHeapBitmap>(slot_address); return; } interiors_->Add(slot_address); @@ -82,7 +79,7 @@ class HeapCompact::MovableObjectFixups final { return; #if DCHECK_IS_ON() auto it = fixups_.find(reference); - DCHECK(it == fixups_.end() || it->value == slot); + DCHECK(it == fixups_.end() || it->second == slot); #endif // TODO: when updateHeapResidency() becomes more discriminating about @@ -90,7 +87,7 @@ class HeapCompact::MovableObjectFixups final { // isCompactingArena() would be appropriate here, leaving early if // |refPage|'s arena isn't in the set. - fixups_.insert(reference, slot); + fixups_.insert({reference, slot}); // Note: |slot| will reside outside the Oilpan heap if it is a // PersistentHeapCollectionBase. Hence pageFromObject() cannot be @@ -155,17 +152,17 @@ class HeapCompact::MovableObjectFixups final { continue; // If |slot|'s mapping is set, then the slot has been adjusted already. - if (it->value) + if (it->second) continue; Address fixup = to + offset; LOG_HEAP_COMPACTION() << "Range interior fixup: " << (from + offset) - << " " << it->value << " " << fixup; + << " " << it->second << " " << fixup; // Fill in the relocated location of the original slot at |slot|. // when the backing store corresponding to |slot| is eventually // moved/compacted, it'll update |to + offset| with a pointer to the // moved backing store. - interior_fixups_.Set(slot, fixup); + interior_fixups_[slot] = fixup; // If the |slot|'s content is pointing into the region [from, from + size) // we are dealing with an interior pointer that does not point to a valid @@ -207,13 +204,13 @@ class HeapCompact::MovableObjectFixups final { // If the object is referenced by a slot that is contained on a compacted // area itself, check whether it can be updated already. - MovableReference* slot = reinterpret_cast<MovableReference*>(it->value); + MovableReference* slot = reinterpret_cast<MovableReference*>(it->second); auto interior = interior_fixups_.find(slot); if (interior != interior_fixups_.end()) { MovableReference* slot_location = - reinterpret_cast<MovableReference*>(interior->value); + reinterpret_cast<MovableReference*>(interior->second); if (!slot_location) { - interior_fixups_.Set(slot, to); + interior_fixups_[slot] = to; slot_type = kInteriorSlotPreMove; } else { LOG_HEAP_COMPACTION() @@ -245,7 +242,7 @@ class HeapCompact::MovableObjectFixups final { // Execute potential fixup callbacks. MovableReference* callback_slot = - reinterpret_cast<MovableReference*>(it->value); + reinterpret_cast<MovableReference*>(it->second); auto callback = fixup_callbacks_.find(callback_slot); if (UNLIKELY(callback != fixup_callbacks_.end())) { size = HeapObjectHeader::FromPayload(to)->PayloadSize(); @@ -272,8 +269,6 @@ class HeapCompact::MovableObjectFixups final { #endif private: - MovableObjectFixups(ThreadHeap* heap) : heap_(heap) {} - void VerifyUpdatedSlot(MovableReference* slot); ThreadHeap* heap_; @@ -284,7 +279,7 @@ class HeapCompact::MovableObjectFixups final { // updated. // // (TODO: consider in-place updating schemes.) - HashMap<MovableReference, MovableReference*> fixups_; + std::unordered_map<MovableReference, MovableReference*> fixups_; // Map from movable reference to callbacks that need to be invoked // when the object moves. @@ -292,7 +287,7 @@ class HeapCompact::MovableObjectFixups final { fixup_callbacks_; // Slot => relocated slot/final location. - HashMap<MovableReference*, Address> interior_fixups_; + std::unordered_map<MovableReference*, Address> interior_fixups_; // All pages that are being compacted. The set keeps references to // BasePage instances. The void* type was selected to allow to check @@ -353,7 +348,7 @@ HeapCompact::~HeapCompact() = default; HeapCompact::MovableObjectFixups& HeapCompact::Fixups() { if (!fixups_) - fixups_ = MovableObjectFixups::Create(heap_); + fixups_ = std::make_unique<MovableObjectFixups>(heap_); return *fixups_; } @@ -379,14 +374,12 @@ bool HeapCompact::ShouldCompact(ThreadHeap* heap, if (stack_state == BlinkGC::kHeapPointersOnStack) return false; - if (reason == BlinkGC::GCReason::kTesting) { + if (reason == BlinkGC::GCReason::kForcedGCForTesting) { UpdateHeapResidency(); return force_compaction_gc_; } - if (reason != BlinkGC::GCReason::kIdleGC && - reason != BlinkGC::GCReason::kPreciseGC && - reason != BlinkGC::GCReason::kForcedGC) + if (reason != BlinkGC::GCReason::kPreciseGC) return false; // TODO(keishi): crbug.com/918064 Heap compaction for incremental marking @@ -435,6 +428,8 @@ void HeapCompact::RemoveSlot(MovableReference* slot) { } void HeapCompact::RegisterMovingObjectReference(MovableReference* slot) { + CHECK(heap_->LookupPageForAddress(reinterpret_cast<Address>(slot))); + if (!do_compact_) return; @@ -444,6 +439,8 @@ void HeapCompact::RegisterMovingObjectReference(MovableReference* slot) { void HeapCompact::RegisterMovingObjectCallback(MovableReference* slot, MovingObjectCallback callback, void* callback_data) { + DCHECK(heap_->LookupPageForAddress(reinterpret_cast<Address>(slot))); + if (!do_compact_) return; diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_compact.h b/chromium/third_party/blink/renderer/platform/heap/heap_compact.h index ec0ef448537..c8c31992284 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_compact.h +++ b/chromium/third_party/blink/renderer/platform/heap/heap_compact.h @@ -49,10 +49,7 @@ class PLATFORM_EXPORT HeapCompact final { friend class incremental_marking_test::IncrementalMarkingTestDriver; public: - static std::unique_ptr<HeapCompact> Create(ThreadHeap* heap) { - return base::WrapUnique(new HeapCompact(heap)); - } - + explicit HeapCompact(ThreadHeap*); ~HeapCompact(); // Remove slot from traced_slots_ when a registered slot is destructed by @@ -146,8 +143,6 @@ class PLATFORM_EXPORT HeapCompact final { private: class MovableObjectFixups; - explicit HeapCompact(ThreadHeap*); - // Sample the amount of fragmentation and heap memory currently residing // on the freelists of the arenas we're able to compact. The computed // numbers will be subsequently used to determine if a heap compaction diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_compact_test.cc b/chromium/third_party/blink/renderer/platform/heap/heap_compact_test.cc index 8fa82528fe3..462218af38e 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_compact_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_compact_test.cc @@ -101,7 +101,7 @@ static const size_t kUnitPointer = 0x1u TEST(HeapCompactTest, SparseBitmapBasic) { Address base = reinterpret_cast<Address>(0x10000u); - std::unique_ptr<SparseHeapBitmap> bitmap = SparseHeapBitmap::Create(base); + auto bitmap = std::make_unique<SparseHeapBitmap>(base); size_t double_chunk = 2 * kChunkRange; @@ -134,7 +134,7 @@ TEST(HeapCompactTest, SparseBitmapBasic) { TEST(HeapCompactTest, SparseBitmapBuild) { Address base = reinterpret_cast<Address>(0x10000u); - std::unique_ptr<SparseHeapBitmap> bitmap = SparseHeapBitmap::Create(base); + auto bitmap = std::make_unique<SparseHeapBitmap>(base); size_t double_chunk = 2 * kChunkRange; @@ -195,7 +195,7 @@ TEST(HeapCompactTest, SparseBitmapBuild) { TEST(HeapCompactTest, SparseBitmapLeftExtension) { Address base = reinterpret_cast<Address>(0x10000u); - std::unique_ptr<SparseHeapBitmap> bitmap = SparseHeapBitmap::Create(base); + auto bitmap = std::make_unique<SparseHeapBitmap>(base); SparseHeapBitmap* start = bitmap->HasRange(base, 1); EXPECT_TRUE(start); @@ -211,7 +211,7 @@ TEST(HeapCompactTest, SparseBitmapLeftExtension) { bitmap->HasRange(base - 2 * kUnitPointer, 1)); // Reset. - bitmap = SparseHeapBitmap::Create(base); + bitmap = std::make_unique<SparseHeapBitmap>(base); // If attempting same as above, but the Address |A| is outside the // chunk size of a node, a new SparseHeapBitmap node needs to be @@ -220,7 +220,7 @@ TEST(HeapCompactTest, SparseBitmapLeftExtension) { EXPECT_NE(bitmap->HasRange(base, 1), bitmap->HasRange(base - 2 * kUnitPointer, 1)); - bitmap = SparseHeapBitmap::Create(base); + bitmap = std::make_unique<SparseHeapBitmap>(base); bitmap->Add(base - kChunkRange + kUnitPointer); // This address is just inside the horizon and shouldn't create a new chunk. EXPECT_EQ(bitmap->HasRange(base, 1), diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_page.cc b/chromium/third_party/blink/renderer/platform/heap/heap_page.cc index 96537e05a49..d120b441daa 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_page.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_page.cc @@ -136,9 +136,8 @@ void BaseArena::TakeSnapshot(const String& dump_base_name, size_t page_count = 0; BasePage::HeapSnapshotInfo heap_info; for (BasePage* page = first_unswept_page_; page; page = page->Next()) { - String dump_name = dump_base_name + - String::Format("/pages/page_%lu", - static_cast<unsigned long>(page_count++)); + String dump_name = + dump_base_name + String::Format("/pages/page_%zu", page_count++); base::trace_event::MemoryAllocatorDump* page_dump = BlinkGCMemoryDumpProvider::Instance() ->CreateMemoryAllocatorDumpForCurrentGC(dump_name); @@ -1237,8 +1236,7 @@ bool FreeList::TakeSnapshot(const String& dump_base_name) { } String dump_name = - dump_base_name + String::Format("/buckets/bucket_%lu", - static_cast<unsigned long>(1 << i)); + dump_base_name + "/buckets/bucket_" + String::Number(1 << i); base::trace_event::MemoryAllocatorDump* bucket_dump = BlinkGCMemoryDumpProvider::Instance() ->CreateMemoryAllocatorDumpForCurrentGC(dump_name); @@ -1581,11 +1579,6 @@ void NormalPage::VerifyObjectStartBitmapIsConsistentWithPayload() { } void NormalPage::VerifyMarking() { - DCHECK(!ArenaForNormalPage() - ->GetThreadState() - ->Heap() - .GetStackFrameDepth() - .IsSafeToRecurse()); DCHECK(!ArenaForNormalPage()->CurrentAllocationPoint()); MarkingVerifier verifier(ArenaForNormalPage()->GetThreadState()); for (Address header_address = Payload(); header_address < PayloadEnd();) { diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_page.h b/chromium/third_party/blink/renderer/platform/heap/heap_page.h index ce0d28da481..31f162fbc46 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_page.h +++ b/chromium/third_party/blink/renderer/platform/heap/heap_page.h @@ -67,11 +67,12 @@ constexpr size_t kBlinkPageBaseMask = ~kBlinkPageOffsetMask; constexpr size_t kBlinkPagesPerRegion = 10; // TODO(nya): Replace this with something like #if ENABLE_NACL. -#if 0 +#if defined(ARCH_CPU_PPC64) // NaCl's system page size is 64 KiB. This causes a problem in Oilpan's heap // layout because Oilpan allocates two guard pages for each Blink page (whose // size is kBlinkPageSize = 2^17 = 128 KiB). So we don't use guard pages in // NaCl. +// The same issue holds for ppc64 systems, which use a 64k page size. constexpr size_t kBlinkGuardPageSize = 0; #else constexpr size_t kBlinkGuardPageSize = base::kSystemPageSize; @@ -198,6 +199,7 @@ class PLATFORM_EXPORT HeapObjectHeader { static const uint32_t kZappedMagicForbidden = 0x2c2c2c2c; static HeapObjectHeader* FromPayload(const void*); + static HeapObjectHeader* FromInnerAddress(const void*); // Checks sanity of the header given a payload pointer. static void CheckFromPayload(const void*); @@ -902,6 +904,15 @@ inline HeapObjectHeader* HeapObjectHeader::FromPayload(const void* payload) { return header; } +inline HeapObjectHeader* HeapObjectHeader::FromInnerAddress( + const void* address) { + BasePage* const page = PageFromObject(address); + return page->IsLargeObjectPage() + ? static_cast<LargeObjectPage*>(page)->ObjectHeader() + : static_cast<NormalPage*>(page)->FindHeaderFromAddress( + reinterpret_cast<Address>(const_cast<void*>(address))); +} + inline void HeapObjectHeader::CheckFromPayload(const void* payload) { (void)FromPayload(payload); } diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector.h b/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector.h index 15ff884ea06..494615fd8be 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector.h +++ b/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector.h @@ -45,6 +45,8 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { kMarkProcessWorklist, kMarkNotFullyConstructedObjects, kMarkWeakProcessing, + kUnifiedMarkingAtomicPrologue, + kUnifiedMarkingStep, kVisitCrossThreadPersistents, kVisitDOMWrappers, kVisitPersistentRoots, @@ -87,6 +89,10 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { return "BlinkGC.MarkProcessWorklist"; case Id::kMarkWeakProcessing: return "BlinkGC.MarkWeakProcessing"; + case kUnifiedMarkingAtomicPrologue: + return "BlinkGC.UnifiedMarkingAtomicPrologue"; + case kUnifiedMarkingStep: + return "BlinkGC.UnifiedMarkingStep"; case Id::kVisitCrossThreadPersistents: return "BlinkGC.VisitCrossThreadPersistents"; case Id::kVisitDOMWrappers: diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector_test.cc b/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector_test.cc index a80200ec60f..f92147bf57f 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_stats_collector_test.cc @@ -14,7 +14,7 @@ namespace blink { TEST(ThreadHeapStatsCollectorTest, InitialEmpty) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); for (int i = 0; i < ThreadHeapStatsCollector::kNumScopeIds; i++) { EXPECT_EQ(TimeDelta(), stats_collector.current().scope_data[i]); } @@ -24,7 +24,7 @@ TEST(ThreadHeapStatsCollectorTest, InitialEmpty) { TEST(ThreadHeapStatsCollectorTest, IncreaseScopeTime) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kIncrementalMarkingStep, TimeDelta::FromMilliseconds(1)); @@ -37,7 +37,7 @@ TEST(ThreadHeapStatsCollectorTest, IncreaseScopeTime) { TEST(ThreadHeapStatsCollectorTest, StopMovesCurrentToPrevious) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kIncrementalMarkingStep, TimeDelta::FromMilliseconds(1)); @@ -50,7 +50,7 @@ TEST(ThreadHeapStatsCollectorTest, StopMovesCurrentToPrevious) { TEST(ThreadHeapStatsCollectorTest, StopResetsCurrent) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kIncrementalMarkingStep, TimeDelta::FromMilliseconds(1)); @@ -64,7 +64,7 @@ TEST(ThreadHeapStatsCollectorTest, StopResetsCurrent) { TEST(ThreadHeapStatsCollectorTest, StartStop) { ThreadHeapStatsCollector stats_collector; EXPECT_FALSE(stats_collector.is_started()); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); EXPECT_TRUE(stats_collector.is_started()); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); @@ -79,16 +79,17 @@ TEST(ThreadHeapStatsCollectorTest, ScopeToString) { TEST(ThreadHeapStatsCollectorTest, UpdateReason) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); - stats_collector.UpdateReason(BlinkGC::GCReason::kForcedGC); + stats_collector.UpdateReason(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifySweepingCompleted(); - EXPECT_EQ(BlinkGC::GCReason::kForcedGC, stats_collector.previous().reason); + EXPECT_EQ(BlinkGC::GCReason::kForcedGCForTesting, + stats_collector.previous().reason); } TEST(ThreadHeapStatsCollectorTest, InitialEstimatedObjectSizeInBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(0u, stats_collector.object_size_in_bytes()); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); @@ -96,7 +97,7 @@ TEST(ThreadHeapStatsCollectorTest, InitialEstimatedObjectSizeInBytes) { TEST(ThreadHeapStatsCollectorTest, EstimatedObjectSizeInBytesNoMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseAllocatedObjectSize(512); EXPECT_EQ(512u, stats_collector.object_size_in_bytes()); stats_collector.NotifyMarkingCompleted(); @@ -105,11 +106,11 @@ TEST(ThreadHeapStatsCollectorTest, EstimatedObjectSizeInBytesNoMarkedBytes) { TEST(ThreadHeapStatsCollectorTest, EstimatedObjectSizeInBytesWithMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseAllocatedObjectSize(512); EXPECT_EQ(640u, stats_collector.object_size_in_bytes()); @@ -119,11 +120,11 @@ TEST(ThreadHeapStatsCollectorTest, EstimatedObjectSizeInBytesWithMarkedBytes) { TEST(ThreadHeapStatsCollectorTest, EstimatedObjectSizeInBytesDoNotCountCurrentlyMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); // Currently marked bytes should not account to the estimated object size. @@ -136,7 +137,7 @@ TEST(ThreadHeapStatsCollectorTest, PreInitializedEstimatedMarkingTime) { // Checks that a marking time estimate can be retrieved before the first // garbage collection triggers. ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); EXPECT_LT(0u, stats_collector.estimated_marking_time_in_seconds()); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); @@ -144,13 +145,13 @@ TEST(ThreadHeapStatsCollectorTest, PreInitializedEstimatedMarkingTime) { TEST(ThreadHeapStatsCollectorTest, EstimatedMarkingTime1) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kAtomicPhaseMarking, TimeDelta::FromSeconds(1)); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(1024); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); EXPECT_DOUBLE_EQ(1.0, stats_collector.estimated_marking_time_in_seconds()); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); @@ -158,13 +159,13 @@ TEST(ThreadHeapStatsCollectorTest, EstimatedMarkingTime1) { TEST(ThreadHeapStatsCollectorTest, EstimatedMarkingTime2) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kAtomicPhaseMarking, TimeDelta::FromSeconds(1)); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(1024); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseAllocatedObjectSize(512); EXPECT_DOUBLE_EQ(1.5, stats_collector.estimated_marking_time_in_seconds()); stats_collector.NotifyMarkingCompleted(); @@ -174,7 +175,7 @@ TEST(ThreadHeapStatsCollectorTest, EstimatedMarkingTime2) { TEST(ThreadHeapStatsCollectorTest, AllocatedSpaceInBytesInitialZero) { ThreadHeapStatsCollector stats_collector; EXPECT_EQ(0u, stats_collector.allocated_space_bytes()); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(0u, stats_collector.allocated_space_bytes()); stats_collector.NotifyMarkingCompleted(); EXPECT_EQ(0u, stats_collector.allocated_space_bytes()); @@ -201,7 +202,7 @@ TEST(ThreadHeapStatsCollectorTest, AllocatedSpaceInBytesDecrease) { TEST(ThreadHeapStatsCollectorTest, EventPrevGCMarkedObjectSize) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(1024); stats_collector.NotifySweepingCompleted(); @@ -210,7 +211,7 @@ TEST(ThreadHeapStatsCollectorTest, EventPrevGCMarkedObjectSize) { TEST(ThreadHeapStatsCollectorTest, EventMarkingTimeInMsFromIncrementalGC) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kIncrementalMarkingStartMarking, TimeDelta::FromMilliseconds(7)); @@ -231,7 +232,7 @@ TEST(ThreadHeapStatsCollectorTest, EventMarkingTimeInMsFromIncrementalGC) { TEST(ThreadHeapStatsCollectorTest, EventMarkingTimeInMsFromFullGC) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kAtomicPhaseMarking, TimeDelta::FromMilliseconds(11)); @@ -242,7 +243,7 @@ TEST(ThreadHeapStatsCollectorTest, EventMarkingTimeInMsFromFullGC) { TEST(ThreadHeapStatsCollectorTest, EventMarkingTimePerByteInS) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseMarkedObjectSize(1000); stats_collector.IncreaseScopeTime( ThreadHeapStatsCollector::kAtomicPhaseMarking, TimeDelta::FromSeconds(1)); @@ -254,7 +255,7 @@ TEST(ThreadHeapStatsCollectorTest, EventMarkingTimePerByteInS) { TEST(ThreadHeapStatsCollectorTest, EventSweepingTimeInMs) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseScopeTime(ThreadHeapStatsCollector::kLazySweepInIdle, TimeDelta::FromMilliseconds(1)); stats_collector.IncreaseScopeTime(ThreadHeapStatsCollector::kLazySweepInIdle, @@ -274,7 +275,7 @@ TEST(ThreadHeapStatsCollectorTest, EventSweepingTimeInMs) { TEST(ThreadHeapStatsCollectorTest, EventCompactionFreedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseCompactionFreedSize(512); stats_collector.NotifySweepingCompleted(); @@ -283,7 +284,7 @@ TEST(ThreadHeapStatsCollectorTest, EventCompactionFreedBytes) { TEST(ThreadHeapStatsCollectorTest, EventCompactionFreedPages) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseCompactionFreedPages(3); stats_collector.NotifySweepingCompleted(); @@ -292,7 +293,7 @@ TEST(ThreadHeapStatsCollectorTest, EventCompactionFreedPages) { TEST(ThreadHeapStatsCollectorTest, EventInitialEstimatedLiveObjectRate) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); EXPECT_DOUBLE_EQ(0.0, stats_collector.previous().live_object_rate); @@ -301,11 +302,11 @@ TEST(ThreadHeapStatsCollectorTest, EventInitialEstimatedLiveObjectRate) { TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateSameMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); @@ -315,11 +316,11 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateHalfMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(256); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); @@ -328,11 +329,11 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateNoMarkedBytes) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(256); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifySweepingCompleted(); EXPECT_DOUBLE_EQ(0.0, stats_collector.previous().live_object_rate); } @@ -340,12 +341,12 @@ TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateNoMarkedBytes) { TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateWithAllocatedBytes1) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); stats_collector.IncreaseAllocatedObjectSize(128); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); @@ -355,11 +356,11 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateWithAllocatedBytes2) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); stats_collector.IncreaseAllocatedObjectSize(128); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); @@ -369,7 +370,7 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateWithAllocatedBytes3) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); EXPECT_DOUBLE_EQ(0, stats_collector.previous().live_object_rate); @@ -378,11 +379,11 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventEstimatedLiveObjectRateWithAllocatedBytes4) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseMarkedObjectSize(128); stats_collector.NotifySweepingCompleted(); - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.NotifyMarkingCompleted(); stats_collector.NotifySweepingCompleted(); EXPECT_DOUBLE_EQ(0, stats_collector.previous().live_object_rate); @@ -390,7 +391,7 @@ TEST(ThreadHeapStatsCollectorTest, TEST(ThreadHeapStatsCollectorTest, EventAllocatedSpaceBeforeSweeping1) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseAllocatedSpace(1024); stats_collector.NotifyMarkingCompleted(); stats_collector.IncreaseAllocatedSpace(2048); @@ -402,7 +403,7 @@ TEST(ThreadHeapStatsCollectorTest, EventAllocatedSpaceBeforeSweeping1) { TEST(ThreadHeapStatsCollectorTest, EventAllocatedSpaceBeforeSweeping2) { ThreadHeapStatsCollector stats_collector; - stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kTesting); + stats_collector.NotifyMarkingStarted(BlinkGC::GCReason::kForcedGCForTesting); stats_collector.IncreaseAllocatedSpace(1024); stats_collector.NotifyMarkingCompleted(); stats_collector.DecreaseAllocatedSpace(1024); diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_test.cc b/chromium/third_party/blink/renderer/platform/heap/heap_test.cc index ab281cb2dc8..422a25d1b77 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_test.cc @@ -50,7 +50,6 @@ #include "third_party/blink/renderer/platform/heap/heap_test_utilities.h" #include "third_party/blink/renderer/platform/heap/marking_visitor.h" #include "third_party/blink/renderer/platform/heap/self_keep_alive.h" -#include "third_party/blink/renderer/platform/heap/stack_frame_depth.h" #include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/visitor.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" @@ -66,10 +65,6 @@ namespace { class IntWrapper : public GarbageCollectedFinalized<IntWrapper> { public: - static IntWrapper* Create(int x) { - return MakeGarbageCollected<IntWrapper>(x); - } - virtual ~IntWrapper() { destructor_calls_.fetch_add(1, std::memory_order_relaxed); } @@ -382,7 +377,7 @@ class TestGCScope : public TestGCCollectGarbageScope { : TestGCCollectGarbageScope(state), atomic_pause_scope_(ThreadState::Current()) { ThreadState::Current()->Heap().stats_collector()->NotifyMarkingStarted( - BlinkGC::GCReason::kTesting); + BlinkGC::GCReason::kForcedGCForTesting); ThreadState::Current()->AtomicPausePrologue(state, BlinkGC::kAtomicMarking, BlinkGC::GCReason::kPreciseGC); } @@ -398,7 +393,6 @@ class TestGCScope : public TestGCCollectGarbageScope { class SimpleObject : public GarbageCollected<SimpleObject> { public: - static SimpleObject* Create() { return MakeGarbageCollected<SimpleObject>(); } SimpleObject() = default; void Trace(blink::Visitor* visitor) {} char GetPayload(int i) { return payload[i]; } @@ -417,10 +411,6 @@ class SimpleObject : public GarbageCollected<SimpleObject> { class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass> { public: - static HeapTestSuperClass* Create() { - return MakeGarbageCollected<HeapTestSuperClass>(); - } - HeapTestSuperClass() = default; virtual ~HeapTestSuperClass() { ++destructor_calls_; } @@ -440,10 +430,6 @@ static const size_t kClassMagic = 0xABCDDBCA; class HeapTestSubClass : public HeapTestOtherSuperClass, public HeapTestSuperClass { public: - static HeapTestSubClass* Create() { - return MakeGarbageCollected<HeapTestSubClass>(); - } - HeapTestSubClass() : magic_(kClassMagic) {} ~HeapTestSubClass() override { EXPECT_EQ(kClassMagic, magic_); @@ -576,7 +562,7 @@ class ThreadedHeapTester : public ThreadedTesterBase { std::unique_ptr<GlobalIntWrapperPersistent> CreateGlobalPersistent( int value) { return std::make_unique<GlobalIntWrapperPersistent>( - IntWrapper::Create(value)); + MakeGarbageCollected<IntWrapper>(value)); } void AddGlobalPersistent() { @@ -599,7 +585,7 @@ class ThreadedHeapTester : public ThreadedTesterBase { CreateGlobalPersistent(0x0ed0cabb); for (int i = 0; i < kNumberOfAllocations; i++) { - wrapper = IntWrapper::Create(0x0bbac0de); + wrapper = MakeGarbageCollected<IntWrapper>(0x0bbac0de); if (!(i % 10)) { global_persistent = CreateGlobalPersistent(0x0ed0cabb); } @@ -640,7 +626,8 @@ class ThreadedWeaknessTester : public ThreadedTesterBase { HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>>(); for (int i = 0; i < kNumberOfAllocations; i++) { - weak_map->insert(static_cast<unsigned>(i), IntWrapper::Create(0)); + weak_map->insert(static_cast<unsigned>(i), + MakeGarbageCollected<IntWrapper>(0)); test::YieldCurrentThread(); } @@ -689,7 +676,7 @@ class ThreadPersistentHeapTester : public ThreadedTesterBase { explicit RefCountedChain(int count) { if (count > 0) { --count; - persistent_chain_ = PersistentChain::Create(count); + persistent_chain_ = MakeGarbageCollected<PersistentChain>(count); } } @@ -698,10 +685,6 @@ class ThreadPersistentHeapTester : public ThreadedTesterBase { class PersistentChain : public GarbageCollectedFinalized<PersistentChain> { public: - static PersistentChain* Create(int count) { - return MakeGarbageCollected<PersistentChain>(count); - } - explicit PersistentChain(int count) { ref_counted_chain_ = base::AdoptRef(RefCountedChain::Create(count)); } @@ -713,7 +696,7 @@ class ThreadPersistentHeapTester : public ThreadedTesterBase { }; void RunThread() override { - PersistentChain::Create(100); + MakeGarbageCollected<PersistentChain>(100); // Upon thread detach, GCs will run until all persistents have been // released. We verify that the draining of persistents proceeds @@ -733,8 +716,6 @@ void CheckWithSlack(T expected, T actual, int slack) { class TraceCounter : public GarbageCollectedFinalized<TraceCounter> { public: - static TraceCounter* Create() { return MakeGarbageCollected<TraceCounter>(); } - TraceCounter() : trace_count_(0) {} void Trace(blink::Visitor* visitor) { trace_count_++; } @@ -746,7 +727,7 @@ class TraceCounter : public GarbageCollectedFinalized<TraceCounter> { TEST(HeapTest, IsHeapObjectAliveForConstPointer) { // See http://crbug.com/661363. - SimpleObject* object = SimpleObject::Create(); + auto* object = MakeGarbageCollected<SimpleObject>(); HeapObjectHeader* header = HeapObjectHeader::FromPayload(object); header->Mark(); EXPECT_TRUE(ThreadHeap::IsHeapObjectAlive(object)); @@ -756,11 +737,7 @@ TEST(HeapTest, IsHeapObjectAliveForConstPointer) { class ClassWithMember : public GarbageCollected<ClassWithMember> { public: - static ClassWithMember* Create() { - return MakeGarbageCollected<ClassWithMember>(); - } - - ClassWithMember() : trace_counter_(TraceCounter::Create()) {} + ClassWithMember() : trace_counter_(MakeGarbageCollected<TraceCounter>()) {} void Trace(blink::Visitor* visitor) { visitor->Trace(trace_counter_); @@ -774,10 +751,6 @@ class ClassWithMember : public GarbageCollected<ClassWithMember> { class SimpleFinalizedObject : public GarbageCollectedFinalized<SimpleFinalizedObject> { public: - static SimpleFinalizedObject* Create() { - return MakeGarbageCollected<SimpleFinalizedObject>(); - } - SimpleFinalizedObject() = default; ~SimpleFinalizedObject() { ++destructor_calls_; } @@ -820,8 +793,6 @@ class IntNode : public GarbageCollected<IntNode> { class Bar : public GarbageCollectedFinalized<Bar> { public: - static Bar* Create() { return MakeGarbageCollected<Bar>(); } - Bar() : magic_(kMagic) { live_++; } void FinalizeGarbageCollectedObject() { @@ -843,8 +814,6 @@ unsigned Bar::live_ = 0; class Baz : public GarbageCollected<Baz> { public: - static Baz* Create(Bar* bar) { return MakeGarbageCollected<Baz>(bar); } - explicit Baz(Bar* bar) : bar_(bar) {} void Trace(blink::Visitor* visitor) { visitor->Trace(bar_); } @@ -860,10 +829,6 @@ class Baz : public GarbageCollected<Baz> { class Foo : public Bar { public: - static Foo* Create(Bar* bar) { return MakeGarbageCollected<Foo>(bar); } - - static Foo* Create(Foo* foo) { return MakeGarbageCollected<Foo>(foo); } - Foo(Bar* bar) : Bar(), bar_(bar), points_to_foo_(false) {} Foo(Foo* foo) : Bar(), bar_(foo), points_to_foo_(true) {} @@ -882,11 +847,9 @@ class Foo : public Bar { class Bars : public Bar { public: - static Bars* Create() { return MakeGarbageCollected<Bars>(); } - Bars() : width_(0) { for (unsigned i = 0; i < kWidth; i++) { - bars_[i] = Bar::Create(); + bars_[i] = MakeGarbageCollected<Bar>(); width_++; } } @@ -907,12 +870,10 @@ class Bars : public Bar { class ConstructorAllocation : public GarbageCollected<ConstructorAllocation> { public: - static ConstructorAllocation* Create() { - return MakeGarbageCollected<ConstructorAllocation>(); + ConstructorAllocation() { + int_wrapper_ = MakeGarbageCollected<IntWrapper>(42); } - ConstructorAllocation() { int_wrapper_ = IntWrapper::Create(42); } - void Trace(blink::Visitor* visitor) { visitor->Trace(int_wrapper_); } private: @@ -921,11 +882,9 @@ class ConstructorAllocation : public GarbageCollected<ConstructorAllocation> { class LargeHeapObject : public GarbageCollectedFinalized<LargeHeapObject> { public: - LargeHeapObject() { int_wrapper_ = IntWrapper::Create(23); } + LargeHeapObject() { int_wrapper_ = MakeGarbageCollected<IntWrapper>(23); } ~LargeHeapObject() { destructor_calls_++; } - static LargeHeapObject* Create() { - return MakeGarbageCollected<LargeHeapObject>(); - } + char Get(size_t i) { return data_[i]; } void Set(size_t i, char c) { data_[i] = c; } size_t length() { return kLength; } @@ -954,10 +913,6 @@ int LargeHeapObject::destructor_calls_ = 0; class RefCountedAndGarbageCollected : public GarbageCollectedFinalized<RefCountedAndGarbageCollected> { public: - static RefCountedAndGarbageCollected* Create() { - return MakeGarbageCollected<RefCountedAndGarbageCollected>(); - } - RefCountedAndGarbageCollected() : ref_count_(0) {} ~RefCountedAndGarbageCollected() { ++destructor_calls_; } @@ -993,10 +948,6 @@ class RefCountedAndGarbageCollected2 : public HeapTestOtherSuperClass, public GarbageCollectedFinalized<RefCountedAndGarbageCollected2> { public: - static RefCountedAndGarbageCollected2* Create() { - return MakeGarbageCollected<RefCountedAndGarbageCollected2>(); - } - RefCountedAndGarbageCollected2() : ref_count_(0) {} ~RefCountedAndGarbageCollected2() { ++destructor_calls_; } @@ -1030,10 +981,6 @@ int RefCountedAndGarbageCollected2::destructor_calls_ = 0; class Weak : public Bar { public: - static Weak* Create(Bar* strong, Bar* weak) { - return MakeGarbageCollected<Weak>(strong, weak); - } - Weak(Bar* strong_bar, Bar* weak_bar) : Bar(), strong_bar_(strong_bar), weak_bar_(weak_bar) {} @@ -1057,10 +1004,6 @@ class Weak : public Bar { class WithWeakMember : public Bar { public: - static WithWeakMember* Create(Bar* strong, Bar* weak) { - return MakeGarbageCollected<WithWeakMember>(strong, weak); - } - WithWeakMember(Bar* strong_bar, Bar* weak_bar) : Bar(), strong_bar_(strong_bar), weak_bar_(weak_bar) {} @@ -1081,9 +1024,6 @@ class Observable : public GarbageCollectedFinalized<Observable> { USING_PRE_FINALIZER(Observable, WillFinalize); public: - static Observable* Create(Bar* bar) { - return MakeGarbageCollected<Observable>(bar); - } explicit Observable(Bar* bar) : bar_(bar), was_destructed_(false) {} ~Observable() { was_destructed_ = true; } void Trace(blink::Visitor* visitor) { visitor->Trace(bar_); } @@ -1109,9 +1049,6 @@ class ObservableWithPreFinalizer USING_PRE_FINALIZER(ObservableWithPreFinalizer, Dispose); public: - static ObservableWithPreFinalizer* Create() { - return MakeGarbageCollected<ObservableWithPreFinalizer>(); - } ObservableWithPreFinalizer() : was_destructed_(false) {} ~ObservableWithPreFinalizer() { was_destructed_ = true; } void Trace(blink::Visitor* visitor) {} @@ -1135,9 +1072,6 @@ class PreFinalizerBase : public GarbageCollectedFinalized<PreFinalizerBase> { USING_PRE_FINALIZER(PreFinalizerBase, Dispose); public: - static PreFinalizerBase* Create() { - return MakeGarbageCollected<PreFinalizerBase>(); - } PreFinalizerBase() : was_destructed_(false) {} virtual ~PreFinalizerBase() { was_destructed_ = true; } virtual void Trace(blink::Visitor* visitor) {} @@ -1177,9 +1111,6 @@ class PreFinalizerSubClass : public PreFinalizerBase, public PreFinalizerMixin { USING_PRE_FINALIZER(PreFinalizerSubClass, Dispose); public: - static PreFinalizerSubClass* Create() { - return MakeGarbageCollected<PreFinalizerSubClass>(); - } PreFinalizerSubClass() : was_destructed_(false) {} ~PreFinalizerSubClass() override { was_destructed_ = true; } void Trace(blink::Visitor* visitor) override {} @@ -1198,10 +1129,6 @@ class PreFinalizerSubClass : public PreFinalizerBase, public PreFinalizerMixin { template <typename T> class FinalizationObserver : public GarbageCollected<FinalizationObserver<T>> { public: - static FinalizationObserver* Create(T* data) { - return MakeGarbageCollected<FinalizationObserver>(data); - } - FinalizationObserver(T* data) : data_(data), did_call_will_finalize_(false) {} bool DidCallWillFinalize() const { return did_call_will_finalize_; } @@ -1278,8 +1205,6 @@ class SuperClass; class PointsBack : public GarbageCollectedFinalized<PointsBack> { public: - static PointsBack* Create() { return MakeGarbageCollected<PointsBack>(); } - PointsBack() : back_pointer_(nullptr) { ++alive_count_; } ~PointsBack() { --alive_count_; } @@ -1301,10 +1226,6 @@ int PointsBack::alive_count_ = 0; class SuperClass : public GarbageCollectedFinalized<SuperClass> { public: - static SuperClass* Create(PointsBack* points_back) { - return MakeGarbageCollected<SuperClass>(points_back); - } - explicit SuperClass(PointsBack* points_back) : points_back_(points_back) { points_back_->SetBackPointer(this); ++alive_count_; @@ -1344,10 +1265,6 @@ int SubData::alive_count_ = 0; class SubClass : public SuperClass { public: - static SubClass* Create(PointsBack* points_back) { - return MakeGarbageCollected<SubClass>(points_back); - } - explicit SubClass(PointsBack* points_back) : SuperClass(points_back), data_(MakeGarbageCollected<SubData>()) { ++alive_count_; @@ -1381,8 +1298,6 @@ class UseMixin : public SimpleObject, public Mixin { USING_GARBAGE_COLLECTED_MIXIN(UseMixin); public: - static UseMixin* Create() { return MakeGarbageCollected<UseMixin>(); } - UseMixin() { // Verify that WTF::IsGarbageCollectedType<> works as expected for mixins. static_assert(WTF::IsGarbageCollectedType<UseMixin>::value, @@ -1404,7 +1319,7 @@ class VectorObject { DISALLOW_NEW(); public: - VectorObject() { value_ = SimpleFinalizedObject::Create(); } + VectorObject() { value_ = MakeGarbageCollected<SimpleFinalizedObject>(); } void Trace(blink::Visitor* visitor) { visitor->Trace(value_); } @@ -1418,7 +1333,9 @@ class VectorObjectNoTrace { DISALLOW_NEW(); public: - VectorObjectNoTrace() { value_ = SimpleFinalizedObject::Create(); } + VectorObjectNoTrace() { + value_ = MakeGarbageCollected<SimpleFinalizedObject>(); + } private: Member<SimpleFinalizedObject> value_; @@ -1491,11 +1408,11 @@ class FinalizationAllocator ~FinalizationAllocator() { for (int i = 0; i < 10; ++i) - *wrapper_ = IntWrapper::Create(42); + *wrapper_ = MakeGarbageCollected<IntWrapper>(42); for (int i = 0; i < 512; ++i) MakeGarbageCollected<OneKiloByteObject>(); for (int i = 0; i < 32; ++i) - LargeHeapObject::Create(); + MakeGarbageCollected<LargeHeapObject>(); } void Trace(blink::Visitor* visitor) {} @@ -1514,11 +1431,11 @@ class PreFinalizationAllocator void Dispose() { for (int i = 0; i < 10; ++i) - *wrapper_ = IntWrapper::Create(42); + *wrapper_ = MakeGarbageCollected<IntWrapper>(42); for (int i = 0; i < 512; ++i) MakeGarbageCollected<OneKiloByteObject>(); for (int i = 0; i < 32; ++i) - LargeHeapObject::Create(); + MakeGarbageCollected<LargeHeapObject>(); } void Trace(blink::Visitor* visitor) {} @@ -1656,7 +1573,7 @@ TEST(HeapTest, Transition) { { RefCountedAndGarbageCollected::destructor_calls_ = 0; Persistent<RefCountedAndGarbageCollected> ref_counted = - RefCountedAndGarbageCollected::Create(); + MakeGarbageCollected<RefCountedAndGarbageCollected>(); PreciselyCollectGarbage(); EXPECT_EQ(0, RefCountedAndGarbageCollected::destructor_calls_); } @@ -1664,10 +1581,11 @@ TEST(HeapTest, Transition) { EXPECT_EQ(1, RefCountedAndGarbageCollected::destructor_calls_); RefCountedAndGarbageCollected::destructor_calls_ = 0; - Persistent<PointsBack> points_back1 = PointsBack::Create(); - Persistent<PointsBack> points_back2 = PointsBack::Create(); - Persistent<SuperClass> super_class = SuperClass::Create(points_back1); - Persistent<SubClass> sub_class = SubClass::Create(points_back2); + Persistent<PointsBack> points_back1 = MakeGarbageCollected<PointsBack>(); + Persistent<PointsBack> points_back2 = MakeGarbageCollected<PointsBack>(); + Persistent<SuperClass> super_class = + MakeGarbageCollected<SuperClass>(points_back1); + Persistent<SubClass> sub_class = MakeGarbageCollected<SubClass>(points_back2); EXPECT_EQ(2, PointsBack::alive_count_); EXPECT_EQ(2, SuperClass::alive_count_); EXPECT_EQ(1, SubClass::alive_count_); @@ -1890,13 +1808,14 @@ TEST(HeapTest, SimpleAllocation) { } TEST(HeapTest, SimplePersistent) { - Persistent<TraceCounter> trace_counter = TraceCounter::Create(); + Persistent<TraceCounter> trace_counter = MakeGarbageCollected<TraceCounter>(); EXPECT_EQ(0, trace_counter->TraceCount()); PreciselyCollectGarbage(); int saved_trace_count = trace_counter->TraceCount(); EXPECT_LT(0, saved_trace_count); - Persistent<ClassWithMember> class_with_member = ClassWithMember::Create(); + Persistent<ClassWithMember> class_with_member = + MakeGarbageCollected<ClassWithMember>(); EXPECT_EQ(0, class_with_member->TraceCount()); PreciselyCollectGarbage(); EXPECT_LT(0, class_with_member->TraceCount()); @@ -1908,7 +1827,7 @@ TEST(HeapTest, SimpleFinalization) { { SimpleFinalizedObject::destructor_calls_ = 0; Persistent<SimpleFinalizedObject> finalized = - SimpleFinalizedObject::Create(); + MakeGarbageCollected<SimpleFinalizedObject>(); EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); PreciselyCollectGarbage(); EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); @@ -1954,13 +1873,13 @@ TEST(HeapTest, LazySweepingPages) { SimpleFinalizedObject::destructor_calls_ = 0; EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); for (int i = 0; i < 1000; i++) - SimpleFinalizedObject::Create(); + MakeGarbageCollected<SimpleFinalizedObject>(); ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); for (int i = 0; i < 10000; i++) - SimpleFinalizedObject::Create(); + MakeGarbageCollected<SimpleFinalizedObject>(); EXPECT_EQ(1000, SimpleFinalizedObject::destructor_calls_); PreciselyCollectGarbage(); EXPECT_EQ(11000, SimpleFinalizedObject::destructor_calls_); @@ -1970,7 +1889,7 @@ TEST(HeapTest, LazySweepingLargeObjectPages) { ClearOutOldGarbage(); // Create free lists that can be reused for IntWrappers created in - // LargeHeapObject::create(). + // MakeGarbageCollected<LargeHeapObject>(). Persistent<IntWrapper> p1 = MakeGarbageCollected<IntWrapper>(1); for (int i = 0; i < 100; i++) { MakeGarbageCollected<IntWrapper>(i); @@ -1982,21 +1901,21 @@ TEST(HeapTest, LazySweepingLargeObjectPages) { LargeHeapObject::destructor_calls_ = 0; EXPECT_EQ(0, LargeHeapObject::destructor_calls_); for (int i = 0; i < 10; i++) - LargeHeapObject::Create(); + MakeGarbageCollected<LargeHeapObject>(); ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(0, LargeHeapObject::destructor_calls_); for (int i = 0; i < 10; i++) { - LargeHeapObject::Create(); + MakeGarbageCollected<LargeHeapObject>(); EXPECT_EQ(i + 1, LargeHeapObject::destructor_calls_); } - LargeHeapObject::Create(); - LargeHeapObject::Create(); + MakeGarbageCollected<LargeHeapObject>(); + MakeGarbageCollected<LargeHeapObject>(); EXPECT_EQ(10, LargeHeapObject::destructor_calls_); ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(10, LargeHeapObject::destructor_calls_); PreciselyCollectGarbage(); EXPECT_EQ(22, LargeHeapObject::destructor_calls_); @@ -2016,10 +1935,6 @@ class SimpleFinalizedEagerObjectBase class SimpleFinalizedEagerObject : public SimpleFinalizedEagerObjectBase { public: - static SimpleFinalizedEagerObject* Create() { - return MakeGarbageCollected<SimpleFinalizedEagerObject>(); - } - SimpleFinalizedEagerObject() = default; ~SimpleFinalizedEagerObject() override { ++destructor_calls_; } @@ -2036,10 +1951,6 @@ class SimpleFinalizedObjectInstanceOfTemplate final : public GarbageCollectedFinalized<SimpleFinalizedObjectInstanceOfTemplate>, public ParameterizedButEmpty<SimpleFinalizedObjectInstanceOfTemplate> { public: - static SimpleFinalizedObjectInstanceOfTemplate* Create() { - return MakeGarbageCollected<SimpleFinalizedObjectInstanceOfTemplate>(); - } - SimpleFinalizedObjectInstanceOfTemplate() = default; ~SimpleFinalizedObjectInstanceOfTemplate() { ++destructor_calls_; } @@ -2060,14 +1971,14 @@ TEST(HeapTest, EagerlySweepingPages) { EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); EXPECT_EQ(0, SimpleFinalizedEagerObject::destructor_calls_); for (int i = 0; i < 1000; i++) - SimpleFinalizedObject::Create(); + MakeGarbageCollected<SimpleFinalizedObject>(); for (int i = 0; i < 100; i++) - SimpleFinalizedEagerObject::Create(); + MakeGarbageCollected<SimpleFinalizedEagerObject>(); for (int i = 0; i < 100; i++) - SimpleFinalizedObjectInstanceOfTemplate::Create(); + MakeGarbageCollected<SimpleFinalizedObjectInstanceOfTemplate>(); ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kLazySweeping, BlinkGC::GCReason::kForcedGCForTesting); EXPECT_EQ(0, SimpleFinalizedObject::destructor_calls_); EXPECT_EQ(100, SimpleFinalizedEagerObject::destructor_calls_); EXPECT_EQ(100, SimpleFinalizedObjectInstanceOfTemplate::destructor_calls_); @@ -2077,9 +1988,9 @@ TEST(HeapTest, Finalization) { { HeapTestSubClass::destructor_calls_ = 0; HeapTestSuperClass::destructor_calls_ = 0; - HeapTestSubClass* t1 = HeapTestSubClass::Create(); - HeapTestSubClass* t2 = HeapTestSubClass::Create(); - HeapTestSuperClass* t3 = HeapTestSuperClass::Create(); + auto* t1 = MakeGarbageCollected<HeapTestSubClass>(); + auto* t2 = MakeGarbageCollected<HeapTestSubClass>(); + auto* t3 = MakeGarbageCollected<HeapTestSuperClass>(); // FIXME(oilpan): Ignore unused variables. (void)t1; (void)t2; @@ -2098,7 +2009,8 @@ TEST(HeapTest, Finalization) { TEST(HeapTest, TypedArenaSanity) { // We use TraceCounter for allocating an object on the general heap. - Persistent<TraceCounter> general_heap_object = TraceCounter::Create(); + Persistent<TraceCounter> general_heap_object = + MakeGarbageCollected<TraceCounter>(); Persistent<IntNode> typed_heap_object = IntNode::Create(0); EXPECT_NE(PageFromObject(general_heap_object.Get()), PageFromObject(typed_heap_object.Get())); @@ -2122,10 +2034,10 @@ TEST(HeapTest, Members) { Persistent<Baz> h1; Persistent<Baz> h2; { - h1 = Baz::Create(Bar::Create()); + h1 = MakeGarbageCollected<Baz>(MakeGarbageCollected<Bar>()); PreciselyCollectGarbage(); EXPECT_EQ(1u, Bar::live_); - h2 = Baz::Create(Bar::Create()); + h2 = MakeGarbageCollected<Baz>(MakeGarbageCollected<Bar>()); PreciselyCollectGarbage(); EXPECT_EQ(2u, Bar::live_); } @@ -2143,13 +2055,13 @@ TEST(HeapTest, MarkTest) { ClearOutOldGarbage(); { Bar::live_ = 0; - Persistent<Bar> bar = Bar::Create(); + Persistent<Bar> bar = MakeGarbageCollected<Bar>(); #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(bar)); #endif EXPECT_EQ(1u, Bar::live_); { - Foo* foo = Foo::Create(bar); + auto* foo = MakeGarbageCollected<Foo>(bar); #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(foo)); #endif @@ -2172,17 +2084,17 @@ TEST(HeapTest, DeepTest) { const unsigned kDepth = 100000; Bar::live_ = 0; { - Bar* bar = Bar::Create(); + auto* bar = MakeGarbageCollected<Bar>(); #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(bar)); #endif - Foo* foo = Foo::Create(bar); + auto* foo = MakeGarbageCollected<Foo>(bar); #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(foo)); #endif EXPECT_EQ(2u, Bar::live_); for (unsigned i = 0; i < kDepth; i++) { - Foo* foo2 = Foo::Create(foo); + auto* foo2 = MakeGarbageCollected<Foo>(foo); foo = foo2; #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(foo)); @@ -2201,7 +2113,7 @@ TEST(HeapTest, WideTest) { ClearOutOldGarbage(); Bar::live_ = 0; { - Bars* bars = Bars::Create(); + auto* bars = MakeGarbageCollected<Bars>(); unsigned width = Bars::kWidth; EXPECT_EQ(width + 1, Bar::live_); ConservativelyCollectGarbage(); @@ -2240,8 +2152,8 @@ TEST(HeapTest, HashMapOfMembers) { // If the additions below cause garbage collections, these // pointers should be found by conservative stack scanning. - IntWrapper* one(IntWrapper::Create(1)); - IntWrapper* another_one(IntWrapper::Create(1)); + auto* one(MakeGarbageCollected<IntWrapper>(1)); + auto* another_one(MakeGarbageCollected<IntWrapper>(1)); map->insert(one, one); @@ -2281,8 +2193,8 @@ TEST(HeapTest, HashMapOfMembers) { IntWrapper* dozen = nullptr; for (int i = 1; i < 1000; i++) { // 999 iterations. - IntWrapper* i_wrapper(IntWrapper::Create(i)); - IntWrapper* i_squared(IntWrapper::Create(i * i)); + auto* i_wrapper(MakeGarbageCollected<IntWrapper>(i)); + auto* i_squared(MakeGarbageCollected<IntWrapper>(i * i)); map->insert(i_wrapper, i_squared); if (i == 12) dozen = i_wrapper; @@ -2312,7 +2224,7 @@ TEST(HeapTest, NestedAllocation) { size_t initial_object_payload_size = heap.ObjectPayloadSizeForTesting(); { Persistent<ConstructorAllocation> constructor_allocation = - ConstructorAllocation::Create(); + MakeGarbageCollected<ConstructorAllocation>(); } ClearOutOldGarbage(); size_t after_free = heap.ObjectPayloadSizeForTesting(); @@ -2330,7 +2242,8 @@ TEST(HeapTest, LargeHeapObjects) { { int slack = 8; // LargeHeapObject points to an IntWrapper that is also allocated. - Persistent<LargeHeapObject> object = LargeHeapObject::Create(); + Persistent<LargeHeapObject> object = + MakeGarbageCollected<LargeHeapObject>(); #if DCHECK_IS_ON() DCHECK(ThreadState::Current()->Heap().FindPageFromAddress(object)); DCHECK(ThreadState::Current()->Heap().FindPageFromAddress( @@ -2366,7 +2279,7 @@ TEST(HeapTest, LargeHeapObjects) { EXPECT_EQ(0, IntWrapper::destructor_calls_); EXPECT_EQ(0, LargeHeapObject::destructor_calls_); for (int i = 0; i < 10; i++) - object = LargeHeapObject::Create(); + object = MakeGarbageCollected<LargeHeapObject>(); } ClearOutOldGarbage(); EXPECT_EQ(after_allocation, @@ -2425,7 +2338,6 @@ typedef std::pair<int, WeakMember<IntWrapper>> PairUnwrappedWeak; class Container : public GarbageCollected<Container> { public: - static Container* Create() { return MakeGarbageCollected<Container>(); } HeapHashMap<Member<IntWrapper>, Member<IntWrapper>> map; HeapHashSet<Member<IntWrapper>> set; HeapHashSet<Member<IntWrapper>> set2; @@ -2457,7 +2369,7 @@ struct NeedsTracingTrait { }; TEST(HeapTest, HeapVectorFilledWithValue) { - IntWrapper* val = IntWrapper::Create(1); + auto* val = MakeGarbageCollected<IntWrapper>(1); HeapVector<Member<IntWrapper>> vector(10, val); EXPECT_EQ(10u, vector.size()); for (wtf_size_t i = 0; i < vector.size(); i++) @@ -2465,12 +2377,12 @@ TEST(HeapTest, HeapVectorFilledWithValue) { } TEST(HeapTest, HeapVectorWithInlineCapacity) { - IntWrapper* one = IntWrapper::Create(1); - IntWrapper* two = IntWrapper::Create(2); - IntWrapper* three = IntWrapper::Create(3); - IntWrapper* four = IntWrapper::Create(4); - IntWrapper* five = IntWrapper::Create(5); - IntWrapper* six = IntWrapper::Create(6); + auto* one = MakeGarbageCollected<IntWrapper>(1); + auto* two = MakeGarbageCollected<IntWrapper>(2); + auto* three = MakeGarbageCollected<IntWrapper>(3); + auto* four = MakeGarbageCollected<IntWrapper>(4); + auto* five = MakeGarbageCollected<IntWrapper>(5); + auto* six = MakeGarbageCollected<IntWrapper>(6); { HeapVector<Member<IntWrapper>, 2> vector; vector.push_back(one); @@ -2593,7 +2505,7 @@ TEST(HeapTest, HeapVectorOnStackLargeObjectPageSized) { sizeof(Container::ValueType); vector.ReserveCapacity(size); for (unsigned i = 0; i < size; ++i) - vector.push_back(IntWrapper::Create(i)); + vector.push_back(MakeGarbageCollected<IntWrapper>(i)); ConservativelyCollectGarbage(); } @@ -2649,35 +2561,35 @@ TEST(HeapTest, HeapCollectionTypes) { Persistent<DequeWU> deque_wu2 = MakeGarbageCollected<DequeWU>(); Persistent<DequeUW> deque_uw = MakeGarbageCollected<DequeUW>(); Persistent<DequeUW> deque_uw2 = MakeGarbageCollected<DequeUW>(); - Persistent<Container> container = Container::Create(); + Persistent<Container> container = MakeGarbageCollected<Container>(); ClearOutOldGarbage(); { - Persistent<IntWrapper> one(IntWrapper::Create(1)); - Persistent<IntWrapper> two(IntWrapper::Create(2)); - Persistent<IntWrapper> one_b(IntWrapper::Create(1)); - Persistent<IntWrapper> two_b(IntWrapper::Create(2)); - Persistent<IntWrapper> one_c(IntWrapper::Create(1)); - Persistent<IntWrapper> one_d(IntWrapper::Create(1)); - Persistent<IntWrapper> one_e(IntWrapper::Create(1)); - Persistent<IntWrapper> one_f(IntWrapper::Create(1)); + Persistent<IntWrapper> one(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> two(MakeGarbageCollected<IntWrapper>(2)); + Persistent<IntWrapper> one_b(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> two_b(MakeGarbageCollected<IntWrapper>(2)); + Persistent<IntWrapper> one_c(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> one_d(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> one_e(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> one_f(MakeGarbageCollected<IntWrapper>(1)); { - IntWrapper* three_b(IntWrapper::Create(3)); - IntWrapper* three_c(IntWrapper::Create(3)); - IntWrapper* three_d(IntWrapper::Create(3)); - IntWrapper* three_e(IntWrapper::Create(3)); - IntWrapper* three_f(IntWrapper::Create(3)); - IntWrapper* three(IntWrapper::Create(3)); - IntWrapper* four_b(IntWrapper::Create(4)); - IntWrapper* four_c(IntWrapper::Create(4)); - IntWrapper* four_d(IntWrapper::Create(4)); - IntWrapper* four_e(IntWrapper::Create(4)); - IntWrapper* four_f(IntWrapper::Create(4)); - IntWrapper* four(IntWrapper::Create(4)); - IntWrapper* five_c(IntWrapper::Create(5)); - IntWrapper* five_d(IntWrapper::Create(5)); - IntWrapper* five_e(IntWrapper::Create(5)); - IntWrapper* five_f(IntWrapper::Create(5)); + auto* three_b(MakeGarbageCollected<IntWrapper>(3)); + auto* three_c(MakeGarbageCollected<IntWrapper>(3)); + auto* three_d(MakeGarbageCollected<IntWrapper>(3)); + auto* three_e(MakeGarbageCollected<IntWrapper>(3)); + auto* three_f(MakeGarbageCollected<IntWrapper>(3)); + auto* three(MakeGarbageCollected<IntWrapper>(3)); + auto* four_b(MakeGarbageCollected<IntWrapper>(4)); + auto* four_c(MakeGarbageCollected<IntWrapper>(4)); + auto* four_d(MakeGarbageCollected<IntWrapper>(4)); + auto* four_e(MakeGarbageCollected<IntWrapper>(4)); + auto* four_f(MakeGarbageCollected<IntWrapper>(4)); + auto* four(MakeGarbageCollected<IntWrapper>(4)); + auto* five_c(MakeGarbageCollected<IntWrapper>(5)); + auto* five_d(MakeGarbageCollected<IntWrapper>(5)); + auto* five_e(MakeGarbageCollected<IntWrapper>(5)); + auto* five_f(MakeGarbageCollected<IntWrapper>(5)); // Member Collections. member_member2->insert(one, two); @@ -2915,12 +2827,12 @@ TEST(HeapTest, PersistentVector) { typedef Vector<Persistent<IntWrapper>> PersistentVector; - Persistent<IntWrapper> one(IntWrapper::Create(1)); - Persistent<IntWrapper> two(IntWrapper::Create(2)); - Persistent<IntWrapper> three(IntWrapper::Create(3)); - Persistent<IntWrapper> four(IntWrapper::Create(4)); - Persistent<IntWrapper> five(IntWrapper::Create(5)); - Persistent<IntWrapper> six(IntWrapper::Create(6)); + Persistent<IntWrapper> one(MakeGarbageCollected<IntWrapper>(1)); + Persistent<IntWrapper> two(MakeGarbageCollected<IntWrapper>(2)); + Persistent<IntWrapper> three(MakeGarbageCollected<IntWrapper>(3)); + Persistent<IntWrapper> four(MakeGarbageCollected<IntWrapper>(4)); + Persistent<IntWrapper> five(MakeGarbageCollected<IntWrapper>(5)); + Persistent<IntWrapper> six(MakeGarbageCollected<IntWrapper>(6)); { PersistentVector vector; vector.push_back(one); @@ -2981,12 +2893,12 @@ TEST(HeapTest, CrossThreadPersistentVector) { typedef Vector<CrossThreadPersistent<IntWrapper>> CrossThreadPersistentVector; - CrossThreadPersistent<IntWrapper> one(IntWrapper::Create(1)); - CrossThreadPersistent<IntWrapper> two(IntWrapper::Create(2)); - CrossThreadPersistent<IntWrapper> three(IntWrapper::Create(3)); - CrossThreadPersistent<IntWrapper> four(IntWrapper::Create(4)); - CrossThreadPersistent<IntWrapper> five(IntWrapper::Create(5)); - CrossThreadPersistent<IntWrapper> six(IntWrapper::Create(6)); + CrossThreadPersistent<IntWrapper> one(MakeGarbageCollected<IntWrapper>(1)); + CrossThreadPersistent<IntWrapper> two(MakeGarbageCollected<IntWrapper>(2)); + CrossThreadPersistent<IntWrapper> three(MakeGarbageCollected<IntWrapper>(3)); + CrossThreadPersistent<IntWrapper> four(MakeGarbageCollected<IntWrapper>(4)); + CrossThreadPersistent<IntWrapper> five(MakeGarbageCollected<IntWrapper>(5)); + CrossThreadPersistent<IntWrapper> six(MakeGarbageCollected<IntWrapper>(6)); { CrossThreadPersistentVector vector; vector.push_back(one); @@ -3047,14 +2959,14 @@ TEST(HeapTest, PersistentSet) { typedef HashSet<Persistent<IntWrapper>> PersistentSet; - IntWrapper* one_raw = IntWrapper::Create(1); + auto* one_raw = MakeGarbageCollected<IntWrapper>(1); Persistent<IntWrapper> one(one_raw); Persistent<IntWrapper> one2(one_raw); - Persistent<IntWrapper> two(IntWrapper::Create(2)); - Persistent<IntWrapper> three(IntWrapper::Create(3)); - Persistent<IntWrapper> four(IntWrapper::Create(4)); - Persistent<IntWrapper> five(IntWrapper::Create(5)); - Persistent<IntWrapper> six(IntWrapper::Create(6)); + Persistent<IntWrapper> two(MakeGarbageCollected<IntWrapper>(2)); + Persistent<IntWrapper> three(MakeGarbageCollected<IntWrapper>(3)); + Persistent<IntWrapper> four(MakeGarbageCollected<IntWrapper>(4)); + Persistent<IntWrapper> five(MakeGarbageCollected<IntWrapper>(5)); + Persistent<IntWrapper> six(MakeGarbageCollected<IntWrapper>(6)); { PersistentSet set; set.insert(one); @@ -3098,14 +3010,14 @@ TEST(HeapTest, CrossThreadPersistentSet) { typedef HashSet<CrossThreadPersistent<IntWrapper>> CrossThreadPersistentSet; - IntWrapper* one_raw = IntWrapper::Create(1); + auto* one_raw = MakeGarbageCollected<IntWrapper>(1); CrossThreadPersistent<IntWrapper> one(one_raw); CrossThreadPersistent<IntWrapper> one2(one_raw); - CrossThreadPersistent<IntWrapper> two(IntWrapper::Create(2)); - CrossThreadPersistent<IntWrapper> three(IntWrapper::Create(3)); - CrossThreadPersistent<IntWrapper> four(IntWrapper::Create(4)); - CrossThreadPersistent<IntWrapper> five(IntWrapper::Create(5)); - CrossThreadPersistent<IntWrapper> six(IntWrapper::Create(6)); + CrossThreadPersistent<IntWrapper> two(MakeGarbageCollected<IntWrapper>(2)); + CrossThreadPersistent<IntWrapper> three(MakeGarbageCollected<IntWrapper>(3)); + CrossThreadPersistent<IntWrapper> four(MakeGarbageCollected<IntWrapper>(4)); + CrossThreadPersistent<IntWrapper> five(MakeGarbageCollected<IntWrapper>(5)); + CrossThreadPersistent<IntWrapper> six(MakeGarbageCollected<IntWrapper>(6)); { CrossThreadPersistentSet set; set.insert(one); @@ -3150,8 +3062,8 @@ class NonTrivialObject final { public: NonTrivialObject() = default; explicit NonTrivialObject(int num) { - deque_.push_back(IntWrapper::Create(num)); - vector_.push_back(IntWrapper::Create(num)); + deque_.push_back(MakeGarbageCollected<IntWrapper>(num)); + vector_.push_back(MakeGarbageCollected<IntWrapper>(num)); } void Trace(blink::Visitor* visitor) { visitor->Trace(deque_); @@ -3216,21 +3128,21 @@ TEST(HeapTest, HeapWeakCollectionSimple) { Persistent<WeakSet> weak_set = MakeGarbageCollected<WeakSet>(); Persistent<WeakCountedSet> weak_counted_set = new WeakCountedSet(); - Persistent<IntWrapper> two = IntWrapper::Create(2); + Persistent<IntWrapper> two = MakeGarbageCollected<IntWrapper>(2); - keep_numbers_alive->push_back(IntWrapper::Create(103)); - keep_numbers_alive->push_back(IntWrapper::Create(10)); + keep_numbers_alive->push_back(MakeGarbageCollected<IntWrapper>(103)); + keep_numbers_alive->push_back(MakeGarbageCollected<IntWrapper>(10)); { - weak_strong->insert(IntWrapper::Create(1), two); - strong_weak->insert(two, IntWrapper::Create(1)); - weak_weak->insert(two, IntWrapper::Create(42)); - weak_weak->insert(IntWrapper::Create(42), two); - weak_set->insert(IntWrapper::Create(0)); + weak_strong->insert(MakeGarbageCollected<IntWrapper>(1), two); + strong_weak->insert(two, MakeGarbageCollected<IntWrapper>(1)); + weak_weak->insert(two, MakeGarbageCollected<IntWrapper>(42)); + weak_weak->insert(MakeGarbageCollected<IntWrapper>(42), two); + weak_set->insert(MakeGarbageCollected<IntWrapper>(0)); weak_set->insert(two); weak_set->insert(keep_numbers_alive->at(0)); weak_set->insert(keep_numbers_alive->at(1)); - weak_counted_set->insert(IntWrapper::Create(0)); + weak_counted_set->insert(MakeGarbageCollected<IntWrapper>(0)); weak_counted_set->insert(two); weak_counted_set->insert(two); weak_counted_set->insert(two); @@ -3270,17 +3182,17 @@ void OrderedSetHelper(bool strong) { const Set& const_set = *set1.Get(); - keep_numbers_alive->push_back(IntWrapper::Create(2)); - keep_numbers_alive->push_back(IntWrapper::Create(103)); - keep_numbers_alive->push_back(IntWrapper::Create(10)); + keep_numbers_alive->push_back(MakeGarbageCollected<IntWrapper>(2)); + keep_numbers_alive->push_back(MakeGarbageCollected<IntWrapper>(103)); + keep_numbers_alive->push_back(MakeGarbageCollected<IntWrapper>(10)); - set1->insert(IntWrapper::Create(0)); + set1->insert(MakeGarbageCollected<IntWrapper>(0)); set1->insert(keep_numbers_alive->at(0)); set1->insert(keep_numbers_alive->at(1)); set1->insert(keep_numbers_alive->at(2)); set2->clear(); - set2->insert(IntWrapper::Create(42)); + set2->insert(MakeGarbageCollected<IntWrapper>(42)); set2->clear(); EXPECT_EQ(4u, set1->size()); @@ -3418,7 +3330,7 @@ static void HeapMapDestructorHelper(bool clear_maps) { Persistent<Map> map(MakeGarbageCollected<Map>()); Persistent<RefMap> ref_map(MakeGarbageCollected<RefMap>()); - Persistent<IntWrapper> luck(IntWrapper::Create(103)); + Persistent<IntWrapper> luck(MakeGarbageCollected<IntWrapper>(103)); int base_line, ref_base_line; @@ -3429,11 +3341,13 @@ static void HeapMapDestructorHelper(bool clear_maps) { PreciselyCollectGarbage(); PreciselyCollectGarbage(); - stack_map.insert(IntWrapper::Create(42), ThingWithDestructor(1729)); + stack_map.insert(MakeGarbageCollected<IntWrapper>(42), + ThingWithDestructor(1729)); stack_map.insert(luck, ThingWithDestructor(8128)); - stack_ref_map.insert(IntWrapper::Create(42), - RefCountedAndGarbageCollected::Create()); - stack_ref_map.insert(luck, RefCountedAndGarbageCollected::Create()); + stack_ref_map.insert(MakeGarbageCollected<IntWrapper>(42), + MakeGarbageCollected<RefCountedAndGarbageCollected>()); + stack_ref_map.insert(luck, + MakeGarbageCollected<RefCountedAndGarbageCollected>()); base_line = ThingWithDestructor::live_things_with_destructor_; ref_base_line = RefCountedAndGarbageCollected::destructor_calls_; @@ -3454,11 +3368,11 @@ static void HeapMapDestructorHelper(bool clear_maps) { // Now use maps kept alive with persistents. Here we don't expect any // destructors to be called before there have been GCs. - map->insert(IntWrapper::Create(42), ThingWithDestructor(1729)); + map->insert(MakeGarbageCollected<IntWrapper>(42), ThingWithDestructor(1729)); map->insert(luck, ThingWithDestructor(8128)); - ref_map->insert(IntWrapper::Create(42), - RefCountedAndGarbageCollected::Create()); - ref_map->insert(luck, RefCountedAndGarbageCollected::Create()); + ref_map->insert(MakeGarbageCollected<IntWrapper>(42), + MakeGarbageCollected<RefCountedAndGarbageCollected>()); + ref_map->insert(luck, MakeGarbageCollected<RefCountedAndGarbageCollected>()); base_line = ThingWithDestructor::live_things_with_destructor_; ref_base_line = RefCountedAndGarbageCollected::destructor_calls_; @@ -3580,15 +3494,19 @@ void WeakPairsHelper() { Persistent<WUSet> weak_unwrapped = MakeGarbageCollected<WUSet>(); Persistent<UWSet> unwrapped_weak = MakeGarbageCollected<UWSet>(); - Persistent<IntWrapper> two = IntWrapper::Create(2); + Persistent<IntWrapper> two = MakeGarbageCollected<IntWrapper>(2); - weak_strong->insert(PairWeakStrong(IntWrapper::Create(1), &*two)); + weak_strong->insert( + PairWeakStrong(MakeGarbageCollected<IntWrapper>(1), &*two)); weak_strong->insert(PairWeakStrong(&*two, &*two)); - strong_weak->insert(PairStrongWeak(&*two, IntWrapper::Create(1))); + strong_weak->insert( + PairStrongWeak(&*two, MakeGarbageCollected<IntWrapper>(1))); strong_weak->insert(PairStrongWeak(&*two, &*two)); - weak_unwrapped->insert(PairWeakUnwrapped(IntWrapper::Create(1), 2)); + weak_unwrapped->insert( + PairWeakUnwrapped(MakeGarbageCollected<IntWrapper>(1), 2)); weak_unwrapped->insert(PairWeakUnwrapped(&*two, 2)); - unwrapped_weak->insert(PairUnwrappedWeak(2, IntWrapper::Create(1))); + unwrapped_weak->insert( + PairUnwrappedWeak(2, MakeGarbageCollected<IntWrapper>(1))); unwrapped_weak->insert(PairUnwrappedWeak(2, &*two)); CheckPairSets<WSSet, SWSet, WUSet, UWSet>( @@ -3672,8 +3590,8 @@ TEST(HeapTest, HeapWeakCollectionTypes) { Persistent<HeapVector<Member<IntWrapper>>> keep_numbers_alive = MakeGarbageCollected<HeapVector<Member<IntWrapper>>>(); for (int i = 0; i < 128; i += 2) { - IntWrapper* wrapped = IntWrapper::Create(i); - IntWrapper* wrapped2 = IntWrapper::Create(i + 1); + auto* wrapped = MakeGarbageCollected<IntWrapper>(i); + auto* wrapped2 = MakeGarbageCollected<IntWrapper>(i + 1); keep_numbers_alive->push_back(wrapped); keep_numbers_alive->push_back(wrapped2); weak_strong->insert(wrapped, wrapped2); @@ -3797,7 +3715,7 @@ TEST(HeapTest, HeapWeakCollectionTypes) { } if (add_afterwards) { for (int i = 1000; i < 1100; i++) { - IntWrapper* wrapped = IntWrapper::Create(i); + auto* wrapped = MakeGarbageCollected<IntWrapper>(i); keep_numbers_alive->push_back(wrapped); weak_strong->insert(wrapped, wrapped); strong_weak->insert(wrapped, wrapped); @@ -3890,9 +3808,9 @@ TEST(HeapTest, RefCountedGarbageCollected) { Persistent<RefCountedAndGarbageCollected> persistent; { Persistent<RefCountedAndGarbageCollected> ref_ptr1 = - RefCountedAndGarbageCollected::Create(); + MakeGarbageCollected<RefCountedAndGarbageCollected>(); Persistent<RefCountedAndGarbageCollected> ref_ptr2 = - RefCountedAndGarbageCollected::Create(); + MakeGarbageCollected<RefCountedAndGarbageCollected>(); PreciselyCollectGarbage(); EXPECT_EQ(0, RefCountedAndGarbageCollected::destructor_calls_); persistent = ref_ptr1.Get(); @@ -3918,16 +3836,16 @@ TEST(HeapTest, WeakMembers) { ClearOutOldGarbage(); Bar::live_ = 0; { - Persistent<Bar> h1 = Bar::Create(); + Persistent<Bar> h1 = MakeGarbageCollected<Bar>(); Persistent<Weak> h4; Persistent<WithWeakMember> h5; PreciselyCollectGarbage(); ASSERT_EQ(1u, Bar::live_); // h1 is live. { - Bar* h2 = Bar::Create(); - Bar* h3 = Bar::Create(); - h4 = Weak::Create(h2, h3); - h5 = WithWeakMember::Create(h2, h3); + auto* h2 = MakeGarbageCollected<Bar>(); + auto* h3 = MakeGarbageCollected<Bar>(); + h4 = MakeGarbageCollected<Weak>(h2, h3); + h5 = MakeGarbageCollected<WithWeakMember>(h2, h3); ConservativelyCollectGarbage(); EXPECT_EQ(5u, Bar::live_); // The on-stack pointer keeps h3 alive. EXPECT_FALSE(h3->HasBeenFinalized()); @@ -3957,9 +3875,9 @@ TEST(HeapTest, WeakMembers) { TEST(HeapTest, FinalizationObserver) { Persistent<FinalizationObserver<Observable>> o; { - Observable* foo = Observable::Create(Bar::Create()); + auto* foo = MakeGarbageCollected<Observable>(MakeGarbageCollected<Bar>()); // |o| observes |foo|. - o = FinalizationObserver<Observable>::Create(foo); + o = MakeGarbageCollected<FinalizationObserver<Observable>>(foo); } // FinalizationObserver doesn't have a strong reference to |foo|. So |foo| // and its member will be collected. @@ -3968,7 +3886,7 @@ TEST(HeapTest, FinalizationObserver) { EXPECT_TRUE(o->DidCallWillFinalize()); FinalizationObserverWithHashMap::did_call_will_finalize_ = false; - Observable* foo = Observable::Create(Bar::Create()); + auto* foo = MakeGarbageCollected<Observable>(MakeGarbageCollected<Bar>()); FinalizationObserverWithHashMap::ObserverMap& map = FinalizationObserverWithHashMap::Observe(*foo); EXPECT_EQ(1u, map.size()); @@ -3985,14 +3903,14 @@ TEST(HeapTest, FinalizationObserver) { TEST(HeapTest, PreFinalizer) { Observable::will_finalize_was_called_ = false; - { Observable::Create(Bar::Create()); } + { MakeGarbageCollected<Observable>(MakeGarbageCollected<Bar>()); } PreciselyCollectGarbage(); EXPECT_TRUE(Observable::will_finalize_was_called_); } TEST(HeapTest, PreFinalizerUnregistersItself) { ObservableWithPreFinalizer::dispose_was_called_ = false; - ObservableWithPreFinalizer::Create(); + MakeGarbageCollected<ObservableWithPreFinalizer>(); PreciselyCollectGarbage(); EXPECT_TRUE(ObservableWithPreFinalizer::dispose_was_called_); // Don't crash, and assertions don't fail. @@ -4002,7 +3920,7 @@ TEST(HeapTest, NestedPreFinalizer) { g_dispose_was_called_for_pre_finalizer_base = false; g_dispose_was_called_for_pre_finalizer_sub_class = false; g_dispose_was_called_for_pre_finalizer_mixin = false; - PreFinalizerSubClass::Create(); + MakeGarbageCollected<PreFinalizerSubClass>(); PreciselyCollectGarbage(); EXPECT_TRUE(g_dispose_was_called_for_pre_finalizer_base); EXPECT_TRUE(g_dispose_was_called_for_pre_finalizer_sub_class); @@ -4011,8 +3929,8 @@ TEST(HeapTest, NestedPreFinalizer) { } TEST(HeapTest, Comparisons) { - Persistent<Bar> bar_persistent = Bar::Create(); - Persistent<Foo> foo_persistent = Foo::Create(bar_persistent); + Persistent<Bar> bar_persistent = MakeGarbageCollected<Bar>(); + Persistent<Foo> foo_persistent = MakeGarbageCollected<Foo>(bar_persistent); EXPECT_TRUE(bar_persistent != foo_persistent); bar_persistent = foo_persistent; EXPECT_TRUE(bar_persistent == foo_persistent); @@ -4042,13 +3960,13 @@ TEST(HeapTest, CheckAndMarkPointer) { Vector<Address> object_addresses; Vector<Address> end_addresses; for (int i = 0; i < 10; i++) { - SimpleObject* object = SimpleObject::Create(); + auto* object = MakeGarbageCollected<SimpleObject>(); Address object_address = reinterpret_cast<Address>(object); object_addresses.push_back(object_address); end_addresses.push_back(object_address + sizeof(SimpleObject) - 1); } Address large_object_address = - reinterpret_cast<Address>(LargeHeapObject::Create()); + reinterpret_cast<Address>(MakeGarbageCollected<LargeHeapObject>()); Address large_object_end_address = large_object_address + sizeof(LargeHeapObject) - 1; @@ -4056,6 +3974,10 @@ TEST(HeapTest, CheckAndMarkPointer) { TestGCScope scope(BlinkGC::kHeapPointersOnStack); MarkingVisitor visitor(ThreadState::Current(), MarkingVisitor::kGlobalMarking); + // Record marking speed as counter generation requires valid marking timings + // for heaps >1MB. + ThreadHeapStatsCollector::Scope stats_scope( + heap.stats_collector(), ThreadHeapStatsCollector::kAtomicPhaseMarking); heap.address_cache()->EnableLookup(); heap.address_cache()->Flush(); @@ -4084,6 +4006,10 @@ TEST(HeapTest, CheckAndMarkPointer) { TestGCScope scope(BlinkGC::kHeapPointersOnStack); MarkingVisitor visitor(ThreadState::Current(), MarkingVisitor::kGlobalMarking); + // Record marking speed as counter generation requires valid marking timings + // for heaps >1MB. + ThreadHeapStatsCollector::Scope stats_scope( + heap.stats_collector(), ThreadHeapStatsCollector::kAtomicPhaseMarking); heap.address_cache()->EnableLookup(); heap.address_cache()->Flush(); @@ -4129,10 +4055,10 @@ TEST(HeapTest, CollectionNesting) { HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); EXPECT_EQ(0u, map2->at(key).size()); - it->value.push_back(IntWrapper::Create(42)); + it->value.push_back(MakeGarbageCollected<IntWrapper>(42)); EXPECT_EQ(1u, map->at(key).size()); - it2->value.push_back(IntWrapper::Create(42)); + it2->value.push_back(MakeGarbageCollected<IntWrapper>(42)); EXPECT_EQ(1u, map2->at(key).size()); Persistent<HeapHashMap<void*, IntVector>> keep_alive(map); @@ -4157,7 +4083,7 @@ TEST(HeapTest, CollectionNesting) { TEST(HeapTest, GarbageCollectedMixin) { ClearOutOldGarbage(); - Persistent<UseMixin> usemixin = UseMixin::Create(); + Persistent<UseMixin> usemixin = MakeGarbageCollected<UseMixin>(); EXPECT_EQ(0, UseMixin::trace_count_); PreciselyCollectGarbage(); EXPECT_EQ(1, UseMixin::trace_count_); @@ -4169,7 +4095,7 @@ TEST(HeapTest, GarbageCollectedMixin) { Persistent<HeapHashSet<WeakMember<Mixin>>> weak_map = MakeGarbageCollected<HeapHashSet<WeakMember<Mixin>>>(); - weak_map->insert(UseMixin::Create()); + weak_map->insert(MakeGarbageCollected<UseMixin>()); PreciselyCollectGarbage(); EXPECT_EQ(0u, weak_map->size()); } @@ -4187,7 +4113,7 @@ TEST(HeapTest, CollectionNesting2) { HeapHashMap<void*, IntSet>::iterator it = map->find(key); EXPECT_EQ(0u, map->at(key).size()); - it->value.insert(IntWrapper::Create(42)); + it->value.insert(MakeGarbageCollected<IntWrapper>(42)); EXPECT_EQ(1u, map->at(key).size()); Persistent<HeapHashMap<void*, IntSet>> keep_alive(map); @@ -4212,8 +4138,8 @@ TEST(HeapTest, CollectionNesting3) { EXPECT_EQ(0u, it->size()); EXPECT_EQ(0u, it2->size()); - it->push_back(IntWrapper::Create(42)); - it2->push_back(IntWrapper::Create(42)); + it->push_back(MakeGarbageCollected<IntWrapper>(42)); + it2->push_back(MakeGarbageCollected<IntWrapper>(42)); EXPECT_EQ(1u, it->size()); EXPECT_EQ(1u, it2->size()); @@ -4482,7 +4408,7 @@ TEST(HeapTest, HeapLinkedStack) { const wtf_size_t kStackSize = 10; for (wtf_size_t i = 0; i < kStackSize; i++) - stack->Push(TerminatedArrayItem(IntWrapper::Create(i))); + stack->Push(TerminatedArrayItem(MakeGarbageCollected<IntWrapper>(i))); ConservativelyCollectGarbage(); EXPECT_EQ(0, IntWrapper::destructor_calls_); @@ -4620,7 +4546,8 @@ TEST(HeapTest, DestructorsCalled) { HeapHashMap<Member<IntWrapper>, std::unique_ptr<SimpleClassWithDestructor>> map; SimpleClassWithDestructor* has_destructor = new SimpleClassWithDestructor(); - map.insert(IntWrapper::Create(1), base::WrapUnique(has_destructor)); + map.insert(MakeGarbageCollected<IntWrapper>(1), + base::WrapUnique(has_destructor)); SimpleClassWithDestructor::was_destructed_ = false; map.clear(); EXPECT_TRUE(SimpleClassWithDestructor::was_destructed_); @@ -4628,7 +4555,7 @@ TEST(HeapTest, DestructorsCalled) { class MixinA : public GarbageCollectedMixin { public: - MixinA() : obj_(IntWrapper::Create(100)) {} + MixinA() : obj_(MakeGarbageCollected<IntWrapper>(100)) {} void Trace(blink::Visitor* visitor) override { trace_count_++; visitor->Trace(obj_); @@ -4643,7 +4570,7 @@ int MixinA::trace_count_ = 0; class MixinB : public GarbageCollectedMixin { public: - MixinB() : obj_(IntWrapper::Create(101)) {} + MixinB() : obj_(MakeGarbageCollected<IntWrapper>(101)) {} void Trace(blink::Visitor* visitor) override { visitor->Trace(obj_); } Member<IntWrapper> obj_; }; @@ -4654,7 +4581,7 @@ class MultipleMixins : public GarbageCollected<MultipleMixins>, USING_GARBAGE_COLLECTED_MIXIN(MultipleMixins); public: - MultipleMixins() : obj_(IntWrapper::Create(102)) {} + MultipleMixins() : obj_(MakeGarbageCollected<IntWrapper>(102)) {} void Trace(blink::Visitor* visitor) override { visitor->Trace(obj_); MixinA::Trace(visitor); @@ -4665,7 +4592,7 @@ class MultipleMixins : public GarbageCollected<MultipleMixins>, class DerivedMultipleMixins : public MultipleMixins { public: - DerivedMultipleMixins() : obj_(IntWrapper::Create(103)) {} + DerivedMultipleMixins() : obj_(MakeGarbageCollected<IntWrapper>(103)) {} void Trace(blink::Visitor* visitor) override { trace_called_++; @@ -4785,17 +4712,17 @@ TEST(HeapTest, NeedsAdjustPointer) { template <typename Set> void SetWithCustomWeaknessHandling() { typedef typename Set::iterator Iterator; - Persistent<IntWrapper> living_int(IntWrapper::Create(42)); + Persistent<IntWrapper> living_int(MakeGarbageCollected<IntWrapper>(42)); Persistent<Set> set1(MakeGarbageCollected<Set>()); { Set set2; Set* set3 = MakeGarbageCollected<Set>(); - set2.insert( - PairWithWeakHandling(IntWrapper::Create(0), IntWrapper::Create(1))); - set3->insert( - PairWithWeakHandling(IntWrapper::Create(2), IntWrapper::Create(3))); - set1->insert( - PairWithWeakHandling(IntWrapper::Create(4), IntWrapper::Create(5))); + set2.insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(0), + MakeGarbageCollected<IntWrapper>(1))); + set3->insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(2), + MakeGarbageCollected<IntWrapper>(3))); + set1->insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(4), + MakeGarbageCollected<IntWrapper>(5))); ConservativelyCollectGarbage(); // The first set is pointed to from a persistent, so it's referenced, but // the weak processing may have taken place. @@ -4819,12 +4746,14 @@ void SetWithCustomWeaknessHandling() { } PreciselyCollectGarbage(); EXPECT_EQ(0u, set1->size()); - set1->insert(PairWithWeakHandling(IntWrapper::Create(103), living_int)); + set1->insert( + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(103), living_int)); // This one gets zapped at GC time because nothing holds the 103 alive. - set1->insert(PairWithWeakHandling(living_int, IntWrapper::Create(103))); + set1->insert( + PairWithWeakHandling(living_int, MakeGarbageCollected<IntWrapper>(103))); set1->insert(PairWithWeakHandling( - IntWrapper::Create(103), - IntWrapper::Create(103))); // This one gets zapped too. + MakeGarbageCollected<IntWrapper>(103), + MakeGarbageCollected<IntWrapper>(103))); // This one gets zapped too. set1->insert(PairWithWeakHandling(living_int, living_int)); // This one is identical to the previous and doesn't add anything. set1->insert(PairWithWeakHandling(living_int, living_int)); @@ -4851,19 +4780,19 @@ TEST(HeapTest, MapWithCustomWeaknessHandling) { OffHeapInt::destructor_calls_ = 0; Persistent<Map> map1(MakeGarbageCollected<Map>()); - Persistent<IntWrapper> living_int(IntWrapper::Create(42)); + Persistent<IntWrapper> living_int(MakeGarbageCollected<IntWrapper>(42)); { Map map2; Map* map3 = MakeGarbageCollected<Map>(); - map2.insert( - PairWithWeakHandling(IntWrapper::Create(0), IntWrapper::Create(1)), - OffHeapInt::Create(1001)); - map3->insert( - PairWithWeakHandling(IntWrapper::Create(2), IntWrapper::Create(3)), - OffHeapInt::Create(1002)); - map1->insert( - PairWithWeakHandling(IntWrapper::Create(4), IntWrapper::Create(5)), - OffHeapInt::Create(1003)); + map2.insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(0), + MakeGarbageCollected<IntWrapper>(1)), + OffHeapInt::Create(1001)); + map3->insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(2), + MakeGarbageCollected<IntWrapper>(3)), + OffHeapInt::Create(1002)); + map1->insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(4), + MakeGarbageCollected<IntWrapper>(5)), + OffHeapInt::Create(1003)); EXPECT_EQ(0, OffHeapInt::destructor_calls_); ConservativelyCollectGarbage(); @@ -4897,14 +4826,16 @@ TEST(HeapTest, MapWithCustomWeaknessHandling) { OffHeapInt::destructor_calls_ = 0; - map1->insert(PairWithWeakHandling(IntWrapper::Create(103), living_int), - OffHeapInt::Create(2000)); - map1->insert(PairWithWeakHandling(living_int, IntWrapper::Create(103)), - OffHeapInt::Create(2001)); // This one gets zapped at GC time - // because nothing holds the 103 alive. map1->insert( - PairWithWeakHandling(IntWrapper::Create(103), IntWrapper::Create(103)), - OffHeapInt::Create(2002)); // This one gets zapped too. + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(103), living_int), + OffHeapInt::Create(2000)); + map1->insert( + PairWithWeakHandling(living_int, MakeGarbageCollected<IntWrapper>(103)), + OffHeapInt::Create(2001)); // This one gets zapped at GC time + // because nothing holds the 103 alive. + map1->insert(PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(103), + MakeGarbageCollected<IntWrapper>(103)), + OffHeapInt::Create(2002)); // This one gets zapped too. scoped_refptr<OffHeapInt> dupe_int(OffHeapInt::Create(2003)); map1->insert(PairWithWeakHandling(living_int, living_int), dupe_int); map1->insert( @@ -4933,20 +4864,20 @@ TEST(HeapTest, MapWithCustomWeaknessHandling2) { OffHeapInt::destructor_calls_ = 0; Persistent<Map> map1(MakeGarbageCollected<Map>()); - Persistent<IntWrapper> living_int(IntWrapper::Create(42)); + Persistent<IntWrapper> living_int(MakeGarbageCollected<IntWrapper>(42)); { Map map2; Map* map3 = MakeGarbageCollected<Map>(); - map2.insert( - OffHeapInt::Create(1001), - PairWithWeakHandling(IntWrapper::Create(0), IntWrapper::Create(1))); - map3->insert( - OffHeapInt::Create(1002), - PairWithWeakHandling(IntWrapper::Create(2), IntWrapper::Create(3))); - map1->insert( - OffHeapInt::Create(1003), - PairWithWeakHandling(IntWrapper::Create(4), IntWrapper::Create(5))); + map2.insert(OffHeapInt::Create(1001), + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(0), + MakeGarbageCollected<IntWrapper>(1))); + map3->insert(OffHeapInt::Create(1002), + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(2), + MakeGarbageCollected<IntWrapper>(3))); + map1->insert(OffHeapInt::Create(1003), + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(4), + MakeGarbageCollected<IntWrapper>(5))); EXPECT_EQ(0, OffHeapInt::destructor_calls_); ConservativelyCollectGarbage(); @@ -4980,15 +4911,17 @@ TEST(HeapTest, MapWithCustomWeaknessHandling2) { OffHeapInt::destructor_calls_ = 0; - map1->insert(OffHeapInt::Create(2000), - PairWithWeakHandling(IntWrapper::Create(103), living_int)); + map1->insert( + OffHeapInt::Create(2000), + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(103), living_int)); // This one gets zapped at GC time because nothing holds the 103 alive. - map1->insert(OffHeapInt::Create(2001), - PairWithWeakHandling(living_int, IntWrapper::Create(103))); + map1->insert( + OffHeapInt::Create(2001), + PairWithWeakHandling(living_int, MakeGarbageCollected<IntWrapper>(103))); map1->insert(OffHeapInt::Create(2002), - PairWithWeakHandling( - IntWrapper::Create(103), - IntWrapper::Create(103))); // This one gets zapped too. + PairWithWeakHandling(MakeGarbageCollected<IntWrapper>(103), + MakeGarbageCollected<IntWrapper>( + 103))); // This one gets zapped too. scoped_refptr<OffHeapInt> dupe_int(OffHeapInt::Create(2003)); map1->insert(dupe_int, PairWithWeakHandling(living_int, living_int)); // This one is identical to the previous and doesn't add anything. @@ -5012,7 +4945,7 @@ static void AddElementsToWeakMap( HeapHashMap<int, WeakMember<IntWrapper>>* map) { // Key cannot be zero in hashmap. for (int i = 1; i < 11; i++) - map->insert(i, IntWrapper::Create(i)); + map->insert(i, MakeGarbageCollected<IntWrapper>(i)); } // crbug.com/402426 @@ -5024,13 +4957,13 @@ TEST(HeapTest, RegressNullIsStrongified) { HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = map->insert(800, nullptr); ConservativelyCollectGarbage(); - result.stored_value->value = IntWrapper::Create(42); + result.stored_value->value = MakeGarbageCollected<IntWrapper>(42); } TEST(HeapTest, Bind) { base::OnceClosure closure = WTF::Bind(static_cast<void (Bar::*)(Visitor*)>(&Bar::Trace), - WrapPersistent(Bar::Create()), nullptr); + WrapPersistent(MakeGarbageCollected<Bar>()), nullptr); // OffHeapInt* should not make Persistent. base::OnceClosure closure2 = WTF::Bind(&OffHeapInt::VoidFunction, OffHeapInt::Create(1)); @@ -5039,7 +4972,7 @@ TEST(HeapTest, Bind) { EXPECT_EQ(1u, Bar::live_); UseMixin::trace_count_ = 0; - Mixin* mixin = UseMixin::Create(); + auto* mixin = MakeGarbageCollected<UseMixin>(); base::OnceClosure mixin_closure = WTF::Bind(static_cast<void (Mixin::*)(Visitor*)>(&Mixin::Trace), WrapPersistent(mixin), nullptr); @@ -5103,7 +5036,7 @@ TEST(HeapTest, RemoveEmptySets) { ClearOutOldGarbage(); OffHeapInt::destructor_calls_ = 0; - Persistent<IntWrapper> living_int(IntWrapper::Create(42)); + Persistent<IntWrapper> living_int(MakeGarbageCollected<IntWrapper>(42)); typedef scoped_refptr<OffHeapInt> Key; typedef HeapHashMap<Key, WeakSet, WTF::DefaultHash<Key>::Hash, @@ -5113,7 +5046,8 @@ TEST(HeapTest, RemoveEmptySets) { map->insert(OffHeapInt::Create(1), WeakSet()); { WeakSet& set = map->begin()->value; - set.insert(IntWrapper::Create(103)); // Weak set can't hold this long. + set.insert(MakeGarbageCollected<IntWrapper>( + 103)); // Weak set can't hold this long. set.insert(living_int); // This prevents the set from being emptied. EXPECT_EQ(2u, set.size()); } @@ -5143,10 +5077,10 @@ TEST(HeapTest, EphemeronsInEphemerons) { for (int keep_outer_alive = 0; keep_outer_alive <= 1; keep_outer_alive++) { for (int keep_inner_alive = 0; keep_inner_alive <= 1; keep_inner_alive++) { Persistent<OuterMap> outer = MakeGarbageCollected<OuterMap>(); - Persistent<IntWrapper> one = IntWrapper::Create(1); - Persistent<IntWrapper> two = IntWrapper::Create(2); + Persistent<IntWrapper> one = MakeGarbageCollected<IntWrapper>(1); + Persistent<IntWrapper> two = MakeGarbageCollected<IntWrapper>(2); outer->insert(one, InnerMap()); - outer->begin()->value.insert(two, IntWrapper::Create(3)); + outer->begin()->value.insert(two, MakeGarbageCollected<IntWrapper>(3)); EXPECT_EQ(1u, outer->at(one).size()); if (!keep_outer_alive) one.Clear(); @@ -5166,13 +5100,13 @@ TEST(HeapTest, EphemeronsInEphemerons) { EXPECT_EQ(0u, outer->size()); } outer->clear(); - Persistent<IntWrapper> deep = IntWrapper::Create(42); - Persistent<IntWrapper> home = IntWrapper::Create(103); - Persistent<IntWrapper> composite = IntWrapper::Create(91); + Persistent<IntWrapper> deep = MakeGarbageCollected<IntWrapper>(42); + Persistent<IntWrapper> home = MakeGarbageCollected<IntWrapper>(103); + Persistent<IntWrapper> composite = MakeGarbageCollected<IntWrapper>(91); Persistent<HeapVector<Member<IntWrapper>>> keep_alive = MakeGarbageCollected<HeapVector<Member<IntWrapper>>>(); for (int i = 0; i < 10000; i++) { - IntWrapper* value = IntWrapper::Create(i); + auto* value = MakeGarbageCollected<IntWrapper>(i); keep_alive->push_back(value); OuterMap::AddResult new_entry = outer->insert(value, InnerMap()); new_entry.stored_value->value.insert(deep, home); @@ -5207,8 +5141,8 @@ class EphemeronWrapper : public GarbageCollected<EphemeronWrapper> { }; TEST(HeapTest, EphemeronsPointToEphemerons) { - Persistent<IntWrapper> key = IntWrapper::Create(42); - Persistent<IntWrapper> key2 = IntWrapper::Create(103); + Persistent<IntWrapper> key = MakeGarbageCollected<IntWrapper>(42); + Persistent<IntWrapper> key2 = MakeGarbageCollected<IntWrapper>(103); Persistent<EphemeronWrapper> chain; for (int i = 0; i < 100; i++) { @@ -5218,7 +5152,7 @@ TEST(HeapTest, EphemeronsPointToEphemerons) { chain->GetMap().insert(key2, old_head); else chain->GetMap().insert(key, old_head); - chain->GetMap().insert(IntWrapper::Create(103), + chain->GetMap().insert(MakeGarbageCollected<IntWrapper>(103), MakeGarbageCollected<EphemeronWrapper>()); } @@ -5264,10 +5198,10 @@ TEST(HeapTest, Ephemeron) { Persistent<Set> set = MakeGarbageCollected<Set>(); - Persistent<IntWrapper> wp1 = IntWrapper::Create(1); - Persistent<IntWrapper> wp2 = IntWrapper::Create(2); - Persistent<IntWrapper> pw1 = IntWrapper::Create(3); - Persistent<IntWrapper> pw2 = IntWrapper::Create(4); + Persistent<IntWrapper> wp1 = MakeGarbageCollected<IntWrapper>(1); + Persistent<IntWrapper> wp2 = MakeGarbageCollected<IntWrapper>(2); + Persistent<IntWrapper> pw1 = MakeGarbageCollected<IntWrapper>(3); + Persistent<IntWrapper> pw2 = MakeGarbageCollected<IntWrapper>(4); weak_pair_map->insert(wp1, PairWithWeakHandling(wp1, wp1)); weak_pair_map->insert(wp2, PairWithWeakHandling(wp1, wp1)); @@ -5346,9 +5280,9 @@ class Link1 : public GarbageCollected<Link1> { TEST(HeapTest, IndirectStrongToWeak) { typedef HeapHashMap<WeakMember<IntWrapper>, Member<Link1>> Map; Persistent<Map> map = MakeGarbageCollected<Map>(); - Persistent<IntWrapper> dead_object = - IntWrapper::Create(100); // Named for "Drowning by Numbers" (1988). - Persistent<IntWrapper> life_object = IntWrapper::Create(42); + Persistent<IntWrapper> dead_object = MakeGarbageCollected<IntWrapper>( + 100); // Named for "Drowning by Numbers" (1988). + Persistent<IntWrapper> life_object = MakeGarbageCollected<IntWrapper>(42); map->insert(dead_object, MakeGarbageCollected<Link1>(dead_object)); map->insert(life_object, MakeGarbageCollected<Link1>(life_object)); EXPECT_EQ(2u, map->size()); @@ -5374,12 +5308,9 @@ template <typename T> class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester<T>> { public: - static TraceIfNeededTester<T>* Create() { - return new TraceIfNeededTester<T>(); - } - static TraceIfNeededTester<T>* Create(const T& obj) { - return new TraceIfNeededTester<T>(obj); - } + TraceIfNeededTester() = default; + explicit TraceIfNeededTester(const T& obj) : obj_(obj) {} + void Trace(blink::Visitor* visitor) { TraceIfNeeded<T>::Trace(visitor, obj_); } @@ -5387,8 +5318,6 @@ class TraceIfNeededTester ~TraceIfNeededTester() = default; private: - TraceIfNeededTester() = default; - explicit TraceIfNeededTester(const T& obj) : obj_(obj) {} T obj_; }; @@ -5396,7 +5325,7 @@ class PartObject { DISALLOW_NEW(); public: - PartObject() : obj_(SimpleObject::Create()) {} + PartObject() : obj_(MakeGarbageCollected<SimpleObject>()) {} void Trace(blink::Visitor* visitor) { visitor->Trace(obj_); } private: @@ -5547,7 +5476,7 @@ TEST(HeapTest, AllocationInSuperConstructorArgument) { AllocInSuperConstructorArgument* object = MakeGarbageCollected<AllocInSuperConstructorArgument>(); EXPECT_TRUE(object); - ThreadState::Current()->CollectAllGarbage(); + ThreadState::Current()->CollectAllGarbageForTesting(); } class NonNodeAllocatingNodeInDestructor @@ -5623,7 +5552,7 @@ TEST(HeapTest, DequeExpand) { // deque's buffer. int i = 0; for (; i < 60; ++i) - deque->push_back(IntWrapper::Create(i)); + deque->push_back(MakeGarbageCollected<IntWrapper>(i)); EXPECT_EQ(60u, deque->size()); i = 0; @@ -5647,7 +5576,7 @@ TEST(HeapTest, DequeExpand) { // Append even more, eventually causing an expansion of the underlying // buffer once the end index wraps around and reaches the start index. for (i = 0; i < 70; ++i) - deque->push_back(IntWrapper::Create(60 + i)); + deque->push_back(MakeGarbageCollected<IntWrapper>(60 + i)); // Verify that the final buffer expansion copied the start and end segments // of the old buffer to both ends of the expanded buffer, along with @@ -5789,54 +5718,6 @@ TEST(HeapTest, HeapVectorPartObjects) { EXPECT_EQ(14u, vector1.size()); } -namespace { - -enum GrowthDirection { - kGrowsTowardsHigher, - kGrowsTowardsLower, -}; - -NOINLINE NO_SANITIZE_ADDRESS NO_SANITIZE_HWADDRESS GrowthDirection -StackGrowthDirection() { - // Disable ASan, otherwise its stack checking (use-after-return) will - // confuse the direction check. Similarly, HWASan will store a random value in - // the top byte of the address of each stack variable, causing the direction - // check to return the wrong answer half of the time. - static char* previous = nullptr; - char dummy; - if (!previous) { - previous = &dummy; - GrowthDirection result = StackGrowthDirection(); - previous = nullptr; - return result; - } - DCHECK_NE(&dummy, previous); - return &dummy < previous ? kGrowsTowardsLower : kGrowsTowardsHigher; -} - -} // namespace - -TEST(HeapTest, StackGrowthDirection) { - // The implementation of marking probes stack usage as it runs, - // and has a builtin assumption that the stack grows towards - // lower addresses. - EXPECT_EQ(kGrowsTowardsLower, StackGrowthDirection()); -} - -TEST(HeapTest, StackFrameDepthDisabledByDefault) { - StackFrameDepth depth; - // Only allow recursion after explicitly enabling the stack limit. - EXPECT_FALSE(depth.IsSafeToRecurse()); -} - -TEST(HeapTest, StackFrameDepthEnable) { - StackFrameDepth depth; - StackFrameDepthScope scope(&depth); - // The scope may fail to enable recursion when the stack is close to the - // limit. In all other cases we should be able to safely recurse. - EXPECT_TRUE(depth.IsSafeToRecurse() || !depth.IsEnabled()); -} - class TestMixinAllocationA : public GarbageCollected<TestMixinAllocationA>, public GarbageCollectedMixin { USING_GARBAGE_COLLECTED_MIXIN(TestMixinAllocationA); @@ -5891,7 +5772,7 @@ class ObjectWithLargeAmountsOfAllocationInConstructor { // mixin base. DCHECK(ThreadState::Current()->IsGCForbidden()); for (size_t i = 0; i < number_of_large_objects_to_allocate; i++) { - LargeHeapObject* large_object = LargeHeapObject::Create(); + auto* large_object = MakeGarbageCollected<LargeHeapObject>(); EXPECT_TRUE(large_object); EXPECT_EQ(0, member->TraceCount()); } @@ -5962,10 +5843,6 @@ class ThreadedClearOnShutdownTester::HeapObject final : public GarbageCollectedFinalized< ThreadedClearOnShutdownTester::HeapObject> { public: - static HeapObject* Create(bool test_destructor) { - return MakeGarbageCollected<HeapObject>(test_destructor); - } - explicit HeapObject(bool test_destructor) : test_destructor_(test_destructor) {} ~HeapObject() { @@ -5980,7 +5857,7 @@ class ThreadedClearOnShutdownTester::HeapObject final // object. Done while terminating the test thread, so // verify that this brings about the release of the // persistent also. - GetHeapObjectSet().insert(Create(false)); + GetHeapObjectSet().insert(MakeGarbageCollected<HeapObject>(false)); } void Trace(blink::Visitor* visitor) {} @@ -6016,7 +5893,7 @@ ThreadedClearOnShutdownTester::GetHeapObjectSet() { void ThreadedClearOnShutdownTester::RunWhileAttached() { EXPECT_EQ(42, ThreadSpecificIntWrapper().Value()); // Creates a thread-specific singleton to a weakly held object. - GetWeakHeapObjectSet().insert(HeapObject::Create(true)); + GetWeakHeapObjectSet().insert(MakeGarbageCollected<HeapObject>(true)); } } // namespace @@ -6028,10 +5905,6 @@ TEST(HeapTest, TestClearOnShutdown) { // Verify that WeakMember<const T> compiles and behaves as expected. class WithWeakConstObject final : public GarbageCollected<WithWeakConstObject> { public: - static WithWeakConstObject* Create(const IntWrapper* int_wrapper) { - return MakeGarbageCollected<WithWeakConstObject>(int_wrapper); - } - WithWeakConstObject(const IntWrapper* int_wrapper) : wrapper_(int_wrapper) {} void Trace(blink::Visitor* visitor) { visitor->Trace(wrapper_); } @@ -6045,8 +5918,8 @@ class WithWeakConstObject final : public GarbageCollected<WithWeakConstObject> { TEST(HeapTest, TestWeakConstObject) { Persistent<WithWeakConstObject> weak_wrapper; { - const IntWrapper* wrapper = IntWrapper::Create(42); - weak_wrapper = WithWeakConstObject::Create(wrapper); + const auto* wrapper = MakeGarbageCollected<IntWrapper>(42); + weak_wrapper = MakeGarbageCollected<WithWeakConstObject>(wrapper); ConservativelyCollectGarbage(); EXPECT_EQ(wrapper, weak_wrapper->Value()); // Stub out any stack reference. @@ -6119,7 +5992,7 @@ TEST(HeapTest, HeapHashMapCallsDestructor) { for (int i = 1; i <= 100; ++i) { KeyWithCopyingMoveConstructor key(i, string); - map.insert(key, IntWrapper::Create(i)); + map.insert(key, MakeGarbageCollected<IntWrapper>(i)); } EXPECT_FALSE(string.Impl()->HasOneRef()); @@ -6133,9 +6006,6 @@ class DoublyLinkedListNodeImpl public DoublyLinkedListNode<DoublyLinkedListNodeImpl> { public: DoublyLinkedListNodeImpl() = default; - static DoublyLinkedListNodeImpl* Create() { - return MakeGarbageCollected<DoublyLinkedListNodeImpl>(); - } static int destructor_calls_; ~DoublyLinkedListNodeImpl() { ++destructor_calls_; } @@ -6157,9 +6027,6 @@ template <typename T> class HeapDoublyLinkedListContainer : public GarbageCollected<HeapDoublyLinkedListContainer<T>> { public: - static HeapDoublyLinkedListContainer<T>* Create() { - return MakeGarbageCollected<HeapDoublyLinkedListContainer<T>>(); - } HeapDoublyLinkedListContainer<T>() = default; HeapDoublyLinkedList<T> list_; void Trace(Visitor* visitor) { visitor->Trace(list_); } @@ -6167,12 +6034,12 @@ class HeapDoublyLinkedListContainer TEST(HeapTest, HeapDoublyLinkedList) { Persistent<HeapDoublyLinkedListContainer<DoublyLinkedListNodeImpl>> - container = - HeapDoublyLinkedListContainer<DoublyLinkedListNodeImpl>::Create(); + container = MakeGarbageCollected< + HeapDoublyLinkedListContainer<DoublyLinkedListNodeImpl>>(); DoublyLinkedListNodeImpl::destructor_calls_ = 0; - container->list_.Append(DoublyLinkedListNodeImpl::Create()); - container->list_.Append(DoublyLinkedListNodeImpl::Create()); + container->list_.Append(MakeGarbageCollected<DoublyLinkedListNodeImpl>()); + container->list_.Append(MakeGarbageCollected<DoublyLinkedListNodeImpl>()); PreciselyCollectGarbage(); EXPECT_EQ(DoublyLinkedListNodeImpl::destructor_calls_, 0); @@ -6293,12 +6160,8 @@ TEST(HeapTest, GarbageCollectedInConstruction) { TEST(HeapTest, GarbageCollectedMixinInConstruction) { using O = ObjectWithMixinWithCallbackBeforeInitializer<IntWrapper>; MakeGarbageCollected<O>(base::BindOnce([](O::Mixin* thiz) { - BasePage* const page = PageFromObject(thiz); - HeapObjectHeader* const header = - page->IsLargeObjectPage() - ? static_cast<LargeObjectPage*>(page)->ObjectHeader() - : static_cast<NormalPage*>(page)->FindHeaderFromAddress( - reinterpret_cast<Address>(thiz)); + const HeapObjectHeader* const header = + HeapObjectHeader::FromInnerAddress(reinterpret_cast<Address>(thiz)); CHECK(header->IsInConstruction()); })); } diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_test_utilities.cc b/chromium/third_party/blink/renderer/platform/heap/heap_test_utilities.cc index 1d01f7b8856..2fb98c3fc24 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_test_utilities.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_test_utilities.cc @@ -13,13 +13,13 @@ namespace blink { void PreciselyCollectGarbage() { ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGCForTesting); } void ConservativelyCollectGarbage(BlinkGC::SweepingType sweeping_type) { - ThreadState::Current()->CollectGarbage(BlinkGC::kHeapPointersOnStack, - BlinkGC::kAtomicMarking, sweeping_type, - BlinkGC::GCReason::kForcedGC); + ThreadState::Current()->CollectGarbage( + BlinkGC::kHeapPointersOnStack, BlinkGC::kAtomicMarking, sweeping_type, + BlinkGC::GCReason::kForcedGCForTesting); } // Do several GCs to make sure that later GCs don't free up old memory from diff --git a/chromium/third_party/blink/renderer/platform/heap/heap_thread_test.cc b/chromium/third_party/blink/renderer/platform/heap/heap_thread_test.cc index f5d687b6337..989478ea3ab 100644 --- a/chromium/third_party/blink/renderer/platform/heap/heap_thread_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/heap_thread_test.cc @@ -7,10 +7,12 @@ #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap_test_utilities.h" #include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h" +#include "third_party/blink/renderer/platform/wtf/allocator.h" namespace blink { namespace heap_thread_test { @@ -68,6 +70,8 @@ class Object : public GarbageCollected<Object> { }; class AlternatingThreadTester { + STACK_ALLOCATED(); + public: void Test() { MutexLocker locker(ActiveThreadMutex()); @@ -206,10 +210,6 @@ TEST(HeapDeathTest, MarkingSameThreadCheck) { class DestructorLockingObject : public GarbageCollectedFinalized<DestructorLockingObject> { public: - static DestructorLockingObject* Create() { - return MakeGarbageCollected<DestructorLockingObject>(); - } - DestructorLockingObject() = default; virtual ~DestructorLockingObject() { ++destructor_calls_; } @@ -248,13 +248,13 @@ class CrossThreadWeakPersistentTester : public AlternatingThreadTester { void WorkerThreadMain() override { // Step 2: Create an object and store the pointer. - object_ = DestructorLockingObject::Create(); + object_ = MakeGarbageCollected<DestructorLockingObject>(); SwitchToMainThread(); // Step 4: Run a GC. ThreadState::Current()->CollectGarbage( BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGC); + BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGCForTesting); SwitchToMainThread(); } diff --git a/chromium/third_party/blink/renderer/platform/heap/incremental_marking_test.cc b/chromium/third_party/blink/renderer/platform/heap/incremental_marking_test.cc index bfafd73102d..767cab62509 100644 --- a/chromium/third_party/blink/renderer/platform/heap/incremental_marking_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/incremental_marking_test.cc @@ -18,9 +18,7 @@ #include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/trace_traits.h" #include "third_party/blink/renderer/platform/heap/visitor.h" - -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) - +#include "third_party/blink/renderer/platform/wtf/allocator.h" namespace blink { namespace incremental_marking_test { @@ -72,7 +70,6 @@ class BackingVisitor : public Visitor { void* callback_data) final {} void RegisterWeakCallback(void* closure, WeakCallback) final {} void Visit(const TraceWrapperV8Reference<v8::Value>&) final {} - void VisitWithWrappers(void*, TraceDescriptor) final {} private: std::vector<void*>* objects_; @@ -80,6 +77,8 @@ class BackingVisitor : public Visitor { // Base class for initializing worklists. class IncrementalMarkingScopeBase { + DISALLOW_NEW(); + public: explicit IncrementalMarkingScopeBase(ThreadState* thread_state) : thread_state_(thread_state), heap_(thread_state_->Heap()) { @@ -112,8 +111,8 @@ class IncrementalMarkingScope : public IncrementalMarkingScopeBase { EXPECT_TRUE(marking_worklist_->IsGlobalEmpty()); EXPECT_TRUE(not_fully_constructed_worklist_->IsGlobalEmpty()); thread_state->EnableIncrementalMarkingBarrier(); - thread_state->current_gc_data_.visitor = - MarkingVisitor::Create(thread_state, MarkingVisitor::kGlobalMarking); + thread_state->current_gc_data_.visitor = std::make_unique<MarkingVisitor>( + thread_state, MarkingVisitor::kGlobalMarking); } ~IncrementalMarkingScope() { @@ -222,11 +221,6 @@ class ExpectNoWriteBarrierFires : public IncrementalMarkingScope { class Object : public GarbageCollected<Object> { public: - static Object* Create() { return MakeGarbageCollected<Object>(); } - static Object* Create(Object* next) { - return MakeGarbageCollected<Object>(next); - } - Object() : next_(nullptr) {} explicit Object(Object* next) : next_(next) {} @@ -257,13 +251,8 @@ TEST(IncrementalMarkingTest, EnableDisableBarrier) { EXPECT_FALSE(ThreadState::Current()->IsIncrementalMarking()); } -TEST(IncrementalMarkingTest, StackFrameDepthDisabled) { - IncrementalMarkingScope scope(ThreadState::Current()); - EXPECT_FALSE(scope.heap().GetStackFrameDepth().IsSafeToRecurse()); -} - TEST(IncrementalMarkingTest, ManualWriteBarrierTriggersWhenMarkingIsOn) { - Object* object = Object::Create(); + auto* object = MakeGarbageCollected<Object>(); { ExpectWriteBarrierFires scope(ThreadState::Current(), {object}); EXPECT_FALSE(object->IsMarked()); @@ -273,7 +262,7 @@ TEST(IncrementalMarkingTest, ManualWriteBarrierTriggersWhenMarkingIsOn) { } TEST(IncrementalMarkingTest, ManualWriteBarrierBailoutWhenMarkingIsOff) { - Object* object = Object::Create(); + auto* object = MakeGarbageCollected<Object>(); EXPECT_FALSE(object->IsMarked()); MarkingVisitor::WriteBarrier(object); EXPECT_FALSE(object->IsMarked()); @@ -284,8 +273,8 @@ TEST(IncrementalMarkingTest, ManualWriteBarrierBailoutWhenMarkingIsOff) { // ============================================================================= TEST(IncrementalMarkingTest, MemberSetUnmarkedObject) { - Object* parent = Object::Create(); - Object* child = Object::Create(); + auto* parent = MakeGarbageCollected<Object>(); + auto* child = MakeGarbageCollected<Object>(); { ExpectWriteBarrierFires scope(ThreadState::Current(), {child}); EXPECT_FALSE(child->IsMarked()); @@ -295,8 +284,8 @@ TEST(IncrementalMarkingTest, MemberSetUnmarkedObject) { } TEST(IncrementalMarkingTest, MemberSetMarkedObjectNoBarrier) { - Object* parent = Object::Create(); - Object* child = Object::Create(); + auto* parent = MakeGarbageCollected<Object>(); + auto* child = MakeGarbageCollected<Object>(); HeapObjectHeader::FromPayload(child)->Mark(); { ExpectNoWriteBarrierFires scope(ThreadState::Current(), {child}); @@ -305,12 +294,12 @@ TEST(IncrementalMarkingTest, MemberSetMarkedObjectNoBarrier) { } TEST(IncrementalMarkingTest, MemberInitializingStoreNoBarrier) { - Object* object1 = Object::Create(); + auto* object1 = MakeGarbageCollected<Object>(); HeapObjectHeader* object1_header = HeapObjectHeader::FromPayload(object1); { IncrementalMarkingScope scope(ThreadState::Current()); EXPECT_FALSE(object1_header->IsMarked()); - Object* object2 = Object::Create(object1); + auto* object2 = MakeGarbageCollected<Object>(object1); HeapObjectHeader* object2_header = HeapObjectHeader::FromPayload(object2); EXPECT_FALSE(object1_header->IsMarked()); EXPECT_FALSE(object2_header->IsMarked()); @@ -318,7 +307,7 @@ TEST(IncrementalMarkingTest, MemberInitializingStoreNoBarrier) { } TEST(IncrementalMarkingTest, MemberReferenceAssignMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Member<Object> m1; Member<Object>& m2 = m1; Member<Object> m3(obj); @@ -353,7 +342,7 @@ TEST(IncrementalMarkingTest, MemberHashTraitConstructDeletedValueNoBarrier) { } TEST(IncrementalMarkingTest, MemberHashTraitIsDeletedValueNoBarrier) { - Member<Object> m1(Object::Create()); + Member<Object> m1(MakeGarbageCollected<Object>()); { ExpectNoWriteBarrierFires scope(ThreadState::Current(), {}); EXPECT_FALSE(HashTraits<Member<Object>>::IsDeletedValue(m1)); @@ -390,8 +379,6 @@ class Child : public GarbageCollected<Child>, USING_GARBAGE_COLLECTED_MIXIN(Child); public: - static Child* Create() { return MakeGarbageCollected<Child>(); } - Child() : ClassWithVirtual(), Mixin() {} ~Child() override {} @@ -403,10 +390,6 @@ class Child : public GarbageCollected<Child>, class ParentWithMixinPointer : public GarbageCollected<ParentWithMixinPointer> { public: - static ParentWithMixinPointer* Create() { - return MakeGarbageCollected<ParentWithMixinPointer>(); - } - ParentWithMixinPointer() : mixin_(nullptr) {} void set_mixin(Mixin* mixin) { mixin_ = mixin; } @@ -420,8 +403,9 @@ class ParentWithMixinPointer : public GarbageCollected<ParentWithMixinPointer> { } // namespace TEST(IncrementalMarkingTest, WriteBarrierOnUnmarkedMixinApplication) { - ParentWithMixinPointer* parent = ParentWithMixinPointer::Create(); - Child* child = Child::Create(); + ParentWithMixinPointer* parent = + MakeGarbageCollected<ParentWithMixinPointer>(); + auto* child = MakeGarbageCollected<Child>(); Mixin* mixin = static_cast<Mixin*>(child); EXPECT_NE(static_cast<void*>(child), static_cast<void*>(mixin)); { @@ -431,8 +415,9 @@ TEST(IncrementalMarkingTest, WriteBarrierOnUnmarkedMixinApplication) { } TEST(IncrementalMarkingTest, NoWriteBarrierOnMarkedMixinApplication) { - ParentWithMixinPointer* parent = ParentWithMixinPointer::Create(); - Child* child = Child::Create(); + ParentWithMixinPointer* parent = + MakeGarbageCollected<ParentWithMixinPointer>(); + auto* child = MakeGarbageCollected<Child>(); HeapObjectHeader::FromPayload(child)->Mark(); Mixin* mixin = static_cast<Mixin*>(child); EXPECT_NE(static_cast<void*>(child), static_cast<void*>(mixin)); @@ -485,7 +470,7 @@ class NonGarbageCollectedContainerRoot { } // namespace TEST(IncrementalMarkingTest, HeapVectorPushBackMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -494,7 +479,7 @@ TEST(IncrementalMarkingTest, HeapVectorPushBackMember) { } TEST(IncrementalMarkingTest, HeapVectorPushBackNonGCedContainer) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<NonGarbageCollectedContainer> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -503,8 +488,8 @@ TEST(IncrementalMarkingTest, HeapVectorPushBackNonGCedContainer) { } TEST(IncrementalMarkingTest, HeapVectorPushBackStdPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<std::pair<Member<Object>, Member<Object>>> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj1, obj2}); @@ -513,7 +498,7 @@ TEST(IncrementalMarkingTest, HeapVectorPushBackStdPair) { } TEST(IncrementalMarkingTest, HeapVectorEmplaceBackMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -522,7 +507,7 @@ TEST(IncrementalMarkingTest, HeapVectorEmplaceBackMember) { } TEST(IncrementalMarkingTest, HeapVectorEmplaceBackNonGCedContainer) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<NonGarbageCollectedContainer> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -531,8 +516,8 @@ TEST(IncrementalMarkingTest, HeapVectorEmplaceBackNonGCedContainer) { } TEST(IncrementalMarkingTest, HeapVectorEmplaceBackStdPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<std::pair<Member<Object>, Member<Object>>> vec; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj1, obj2}); @@ -541,7 +526,7 @@ TEST(IncrementalMarkingTest, HeapVectorEmplaceBackStdPair) { } TEST(IncrementalMarkingTest, HeapVectorCopyMember) { - Object* object = Object::Create(); + auto* object = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec1; vec1.push_back(object); { @@ -551,7 +536,7 @@ TEST(IncrementalMarkingTest, HeapVectorCopyMember) { } TEST(IncrementalMarkingTest, HeapVectorCopyNonGCedContainer) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<NonGarbageCollectedContainer> vec1; vec1.emplace_back(obj, 1); { @@ -561,8 +546,8 @@ TEST(IncrementalMarkingTest, HeapVectorCopyNonGCedContainer) { } TEST(IncrementalMarkingTest, HeapVectorCopyStdPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<std::pair<Member<Object>, Member<Object>>> vec1; vec1.emplace_back(obj1, obj2); { @@ -572,7 +557,7 @@ TEST(IncrementalMarkingTest, HeapVectorCopyStdPair) { } TEST(IncrementalMarkingTest, HeapVectorMoveMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec1; vec1.push_back(obj); { @@ -582,7 +567,7 @@ TEST(IncrementalMarkingTest, HeapVectorMoveMember) { } TEST(IncrementalMarkingTest, HeapVectorMoveNonGCedContainer) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapVector<NonGarbageCollectedContainer> vec1; vec1.emplace_back(obj, 1); { @@ -592,8 +577,8 @@ TEST(IncrementalMarkingTest, HeapVectorMoveNonGCedContainer) { } TEST(IncrementalMarkingTest, HeapVectorMoveStdPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<std::pair<Member<Object>, Member<Object>>> vec1; vec1.emplace_back(obj1, obj2); { @@ -603,8 +588,8 @@ TEST(IncrementalMarkingTest, HeapVectorMoveStdPair) { } TEST(IncrementalMarkingTest, HeapVectorSwapMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec1; vec1.push_back(obj1); HeapVector<Member<Object>> vec2; @@ -616,8 +601,8 @@ TEST(IncrementalMarkingTest, HeapVectorSwapMember) { } TEST(IncrementalMarkingTest, HeapVectorSwapNonGCedContainer) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<NonGarbageCollectedContainer> vec1; vec1.emplace_back(obj1, 1); HeapVector<NonGarbageCollectedContainer> vec2; @@ -629,8 +614,8 @@ TEST(IncrementalMarkingTest, HeapVectorSwapNonGCedContainer) { } TEST(IncrementalMarkingTest, HeapVectorSwapStdPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<std::pair<Member<Object>, Member<Object>>> vec1; vec1.emplace_back(obj1, nullptr); HeapVector<std::pair<Member<Object>, Member<Object>>> vec2; @@ -642,8 +627,8 @@ TEST(IncrementalMarkingTest, HeapVectorSwapStdPair) { } TEST(IncrementalMarkingTest, HeapVectorSubscriptOperator) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapVector<Member<Object>> vec; vec.push_back(obj1); { @@ -657,9 +642,9 @@ TEST(IncrementalMarkingTest, HeapVectorSubscriptOperator) { } TEST(IncrementalMarkingTest, HeapVectorEagerTracingStopsAtMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); obj1->set_next(obj3); HeapVector<NonGarbageCollectedContainerRoot> vec; { @@ -699,7 +684,7 @@ class ObjectNode : public GarbageCollected<ObjectNode>, } // namespace TEST(IncrementalMarkingTest, HeapDoublyLinkedListPush) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); ObjectNode* obj_node = MakeGarbageCollected<ObjectNode>(obj); HeapDoublyLinkedList<ObjectNode> list; { @@ -711,7 +696,7 @@ TEST(IncrementalMarkingTest, HeapDoublyLinkedListPush) { } TEST(IncrementalMarkingTest, HeapDoublyLinkedListAppend) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); ObjectNode* obj_node = MakeGarbageCollected<ObjectNode>(obj); HeapDoublyLinkedList<ObjectNode> list; { @@ -727,7 +712,7 @@ TEST(IncrementalMarkingTest, HeapDoublyLinkedListAppend) { // ============================================================================= TEST(IncrementalMarkingTest, HeapDequePushBackMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -736,7 +721,7 @@ TEST(IncrementalMarkingTest, HeapDequePushBackMember) { } TEST(IncrementalMarkingTest, HeapDequePushFrontMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -745,7 +730,7 @@ TEST(IncrementalMarkingTest, HeapDequePushFrontMember) { } TEST(IncrementalMarkingTest, HeapDequeEmplaceBackMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -754,7 +739,7 @@ TEST(IncrementalMarkingTest, HeapDequeEmplaceBackMember) { } TEST(IncrementalMarkingTest, HeapDequeEmplaceFrontMember) { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -763,7 +748,7 @@ TEST(IncrementalMarkingTest, HeapDequeEmplaceFrontMember) { } TEST(IncrementalMarkingTest, HeapDequeCopyMember) { - Object* object = Object::Create(); + auto* object = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq1; deq1.push_back(object); { @@ -773,7 +758,7 @@ TEST(IncrementalMarkingTest, HeapDequeCopyMember) { } TEST(IncrementalMarkingTest, HeapDequeMoveMember) { - Object* object = Object::Create(); + auto* object = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq1; deq1.push_back(object); { @@ -783,8 +768,8 @@ TEST(IncrementalMarkingTest, HeapDequeMoveMember) { } TEST(IncrementalMarkingTest, HeapDequeSwapMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapDeque<Member<Object>> deq1; deq1.push_back(obj1); HeapDeque<Member<Object>> deq2; @@ -803,7 +788,7 @@ namespace { template <typename Container> void Insert() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -813,7 +798,7 @@ void Insert() { template <typename Container> void InsertNoBarrier() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container; { ExpectNoWriteBarrierFires scope(ThreadState::Current(), {obj}); @@ -823,7 +808,7 @@ void InsertNoBarrier() { template <typename Container> void Copy() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container1; container1.insert(obj); { @@ -836,7 +821,7 @@ void Copy() { template <typename Container> void CopyNoBarrier() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container1; container1.insert(obj); { @@ -849,7 +834,7 @@ void CopyNoBarrier() { template <typename Container> void Move() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container1; Container container2; container1.insert(obj); @@ -861,7 +846,7 @@ void Move() { template <typename Container> void MoveNoBarrier() { - Object* obj = Object::Create(); + auto* obj = MakeGarbageCollected<Object>(); Container container1; container1.insert(obj); { @@ -872,8 +857,8 @@ void MoveNoBarrier() { template <typename Container> void Swap() { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); Container container1; container1.insert(obj1); Container container2; @@ -886,8 +871,8 @@ void Swap() { template <typename Container> void SwapNoBarrier() { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); Container container1; container1.insert(obj1); Container container2; @@ -1017,8 +1002,8 @@ namespace blink { namespace incremental_marking_test { TEST(IncrementalMarkingTest, HeapHashSetStrongWeakPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashSet<StrongWeakPair> set; { // Both, the weak and the strong field, are hit by the write barrier. @@ -1028,8 +1013,8 @@ TEST(IncrementalMarkingTest, HeapHashSetStrongWeakPair) { } TEST(IncrementalMarkingTest, HeapLinkedHashSetStrongWeakPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapLinkedHashSet<StrongWeakPair> set; { // Both, the weak and the strong field, are hit by the write barrier. @@ -1081,8 +1066,8 @@ TEST(IncrementalMarkingTest, HeapHashCountedSetInsert) { TEST(IncrementalMarkingTest, HeapHashCountedSetSwap) { // HeapHashCountedSet is not move constructible so we cannot use std::swap. { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashCountedSet<Member<Object>> container1; container1.insert(obj1); HeapHashCountedSet<Member<Object>> container2; @@ -1093,8 +1078,8 @@ TEST(IncrementalMarkingTest, HeapHashCountedSetSwap) { } } { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashCountedSet<WeakMember<Object>> container1; container1.insert(obj1); HeapHashCountedSet<WeakMember<Object>> container2; @@ -1112,8 +1097,8 @@ TEST(IncrementalMarkingTest, HeapHashCountedSetSwap) { // ============================================================================= TEST(IncrementalMarkingTest, HeapHashMapInsertMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj1, obj2}); @@ -1122,8 +1107,8 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertMember) { } TEST(IncrementalMarkingTest, HeapHashMapInsertWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, WeakMember<Object>> map; { // Weak references are strongified for the current cycle. @@ -1133,8 +1118,8 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapInsertMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, WeakMember<Object>> map; { // Weak references are strongified for the current cycle. @@ -1144,8 +1129,8 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapInsertWeakMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, Member<Object>> map; { // Weak references are strongified for the current cycle. @@ -1155,8 +1140,8 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertWeakMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapSetMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; { ExpectWriteBarrierFires scope(ThreadState::Current(), {obj1, obj2}); @@ -1165,9 +1150,9 @@ TEST(IncrementalMarkingTest, HeapHashMapSetMember) { } TEST(IncrementalMarkingTest, HeapHashMapSetMemberUpdateValue) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; map.insert(obj1, obj2); { @@ -1181,9 +1166,9 @@ TEST(IncrementalMarkingTest, HeapHashMapSetMemberUpdateValue) { } TEST(IncrementalMarkingTest, HeapHashMapIteratorChangeKey) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; map.insert(obj1, obj2); { @@ -1195,9 +1180,9 @@ TEST(IncrementalMarkingTest, HeapHashMapIteratorChangeKey) { } TEST(IncrementalMarkingTest, HeapHashMapIteratorChangeValue) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; map.insert(obj1, obj2); { @@ -1209,8 +1194,8 @@ TEST(IncrementalMarkingTest, HeapHashMapIteratorChangeValue) { } TEST(IncrementalMarkingTest, HeapHashMapCopyMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map1; map1.insert(obj1, obj2); { @@ -1223,8 +1208,8 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapCopyWeakMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); { @@ -1238,8 +1223,8 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyWeakMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapCopyMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); { @@ -1253,8 +1238,8 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapCopyWeakMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, Member<Object>> map1; map1.insert(obj1, obj2); { @@ -1268,8 +1253,8 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyWeakMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapMoveMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map1; map1.insert(obj1, obj2); { @@ -1279,8 +1264,8 @@ TEST(IncrementalMarkingTest, HeapHashMapMoveMember) { } TEST(IncrementalMarkingTest, HeapHashMapMoveWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); { @@ -1291,8 +1276,8 @@ TEST(IncrementalMarkingTest, HeapHashMapMoveWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapMoveMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); { @@ -1303,8 +1288,8 @@ TEST(IncrementalMarkingTest, HeapHashMapMoveMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapMoveWeakMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, Member<Object>> map1; map1.insert(obj1, obj2); { @@ -1315,10 +1300,10 @@ TEST(IncrementalMarkingTest, HeapHashMapMoveWeakMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapSwapMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); - Object* obj4 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); + auto* obj4 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map1; map1.insert(obj1, obj2); HeapHashMap<Member<Object>, Member<Object>> map2; @@ -1331,10 +1316,10 @@ TEST(IncrementalMarkingTest, HeapHashMapSwapMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapSwapWeakMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); - Object* obj4 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); + auto* obj4 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); HeapHashMap<WeakMember<Object>, WeakMember<Object>> map2; @@ -1348,10 +1333,10 @@ TEST(IncrementalMarkingTest, HeapHashMapSwapWeakMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapSwapMemberWeakMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); - Object* obj4 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); + auto* obj4 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, WeakMember<Object>> map1; map1.insert(obj1, obj2); HeapHashMap<Member<Object>, WeakMember<Object>> map2; @@ -1365,10 +1350,10 @@ TEST(IncrementalMarkingTest, HeapHashMapSwapMemberWeakMember) { } TEST(IncrementalMarkingTest, HeapHashMapSwapWeakMemberMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); - Object* obj4 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); + auto* obj4 = MakeGarbageCollected<Object>(); HeapHashMap<WeakMember<Object>, Member<Object>> map1; map1.insert(obj1, obj2); HeapHashMap<WeakMember<Object>, Member<Object>> map2; @@ -1382,9 +1367,9 @@ TEST(IncrementalMarkingTest, HeapHashMapSwapWeakMemberMember) { } TEST(IncrementalMarkingTest, HeapHashMapInsertStrongWeakPairMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); HeapHashMap<StrongWeakPair, Member<Object>> map; { // Tests that the write barrier also fires for entities such as @@ -1395,9 +1380,9 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertStrongWeakPairMember) { } TEST(IncrementalMarkingTest, HeapHashMapInsertMemberStrongWeakPair) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); - Object* obj3 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); + auto* obj3 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, StrongWeakPair> map; { // Tests that the write barrier also fires for entities such as @@ -1408,8 +1393,8 @@ TEST(IncrementalMarkingTest, HeapHashMapInsertMemberStrongWeakPair) { } TEST(IncrementalMarkingTest, HeapHashMapCopyKeysToVectorMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; map.insert(obj1, obj2); HeapVector<Member<Object>> vec; @@ -1422,8 +1407,8 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyKeysToVectorMember) { } TEST(IncrementalMarkingTest, HeapHashMapCopyValuesToVectorMember) { - Object* obj1 = Object::Create(); - Object* obj2 = Object::Create(); + auto* obj1 = MakeGarbageCollected<Object>(); + auto* obj2 = MakeGarbageCollected<Object>(); HeapHashMap<Member<Object>, Member<Object>> map; map.insert(obj1, obj2); HeapVector<Member<Object>> vec; @@ -1441,7 +1426,7 @@ TEST(IncrementalMarkingTest, HeapHashMapCopyValuesToVectorMember) { TEST(IncrementalMarkingTest, DISABLED_WeakHashMapPromptlyFreeDisabled) { ThreadState* state = ThreadState::Current(); state->SetGCState(ThreadState::kIncrementalMarkingStepScheduled); - Persistent<Object> obj1 = Object::Create(); + Persistent<Object> obj1 = MakeGarbageCollected<Object>(); NormalPageArena* arena = static_cast<NormalPageArena*>( ThreadState::Current()->Heap().Arena(BlinkGC::kHashTableArenaIndex)); CHECK(arena); @@ -1559,7 +1544,8 @@ class IncrementalMarkingTestDriver { } void Start() { - thread_state_->IncrementalMarkingStart(BlinkGC::GCReason::kTesting); + thread_state_->IncrementalMarkingStart( + BlinkGC::GCReason::kForcedGCForTesting); } bool SingleStep(BlinkGC::StackState stack_state = @@ -1614,7 +1600,7 @@ TEST(IncrementalMarkingTest, DropBackingStore) { using WeakStore = HeapHashCountedSet<WeakMember<Object>>; Persistent<WeakStore> persistent(new WeakStore); - persistent->insert(Object::Create()); + persistent->insert(MakeGarbageCollected<Object>()); IncrementalMarkingTestDriver driver(ThreadState::Current()); driver.Start(); driver.FinishSteps(); @@ -1635,8 +1621,8 @@ TEST(IncrementalMarkingTest, WeakCallbackDoesNotReviveDeletedValue) { // structure. The values for .second are chosen to be non-null as they // would otherwise count as empty and be skipped during iteration after the // first part died. - persistent->insert({Object::Create(), 1}); - persistent->insert({Object::Create(), 2}); + persistent->insert({MakeGarbageCollected<Object>(), 1}); + persistent->insert({MakeGarbageCollected<Object>(), 2}); IncrementalMarkingTestDriver driver(ThreadState::Current()); driver.Start(); // The backing is not treated as weak backing and thus eagerly processed, @@ -1670,11 +1656,11 @@ TEST(IncrementalMarkingTest, NoBackingFreeDuringIncrementalMarking) { // would trigger the write barrier, mitigating the bug where a backing store // is promptly freed. for (size_t i = 0; i < 8; i++) { - persistent->insert({Object::Create(), i}); + persistent->insert({MakeGarbageCollected<Object>(), i}); } IncrementalMarkingTestDriver driver(ThreadState::Current()); driver.Start(); - persistent->insert({Object::Create(), 8}); + persistent->insert({MakeGarbageCollected<Object>(), 8}); // Is not allowed to free the backing store as the previous insert may have // registered a slot. persistent->clear(); @@ -1686,7 +1672,7 @@ TEST(IncrementalMarkingTest, DropReferenceWithHeapCompaction) { using Store = HeapHashCountedSet<Member<Object>>; Persistent<Store> persistent(new Store()); - persistent->insert(Object::Create()); + persistent->insert(MakeGarbageCollected<Object>()); IncrementalMarkingTestDriver driver(ThreadState::Current()); HeapCompact::ScheduleCompactionGCForTesting(true); driver.Start(); @@ -1705,7 +1691,7 @@ TEST(IncrementalMarkingTest, HasInlineCapacityCollectionWithHeapCompaction) { IncrementalMarkingTestDriver driver(ThreadState::Current()); HeapCompact::ScheduleCompactionGCForTesting(true); - persistent->push_back(Object::Create()); + persistent->push_back(MakeGarbageCollected<Object>()); driver.Start(); driver.FinishGC(); @@ -1728,7 +1714,7 @@ TEST(IncrementalMarkingTest, WeakHashMapHeapCompaction) { HeapCompact::ScheduleCompactionGCForTesting(true); driver.Start(); driver.FinishSteps(); - persistent->insert(Object::Create()); + persistent->insert(MakeGarbageCollected<Object>()); driver.FinishGC(); // Weak callback should register the slot. @@ -1738,7 +1724,7 @@ TEST(IncrementalMarkingTest, WeakHashMapHeapCompaction) { TEST(IncrementalMarkingTest, ConservativeGCWhileCompactionScheduled) { using Store = HeapVector<Member<Object>>; Persistent<Store> persistent(MakeGarbageCollected<Store>()); - persistent->push_back(Object::Create()); + persistent->push_back(MakeGarbageCollected<Object>()); IncrementalMarkingTestDriver driver(ThreadState::Current()); HeapCompact::ScheduleCompactionGCForTesting(true); @@ -1777,7 +1763,7 @@ TEST(IncrementalMarkingTest, WeakMember) { IncrementalMarkingTestDriver driver(ThreadState::Current()); driver.Start(); driver.FinishSteps(); - persistent->set_object(Object::Create()); + persistent->set_object(MakeGarbageCollected<Object>()); driver.FinishGC(); ConservativelyCollectGarbage(); } @@ -1878,5 +1864,3 @@ TEST(IncrementalMarkingTest, StepDuringMixinObjectConstruction) { } // namespace incremental_marking_test } // namespace blink - -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) diff --git a/chromium/third_party/blink/renderer/platform/heap/marking_verifier.h b/chromium/third_party/blink/renderer/platform/heap/marking_verifier.h index 8a5bc5c330c..f4095b95be7 100644 --- a/chromium/third_party/blink/renderer/platform/heap/marking_verifier.h +++ b/chromium/third_party/blink/renderer/platform/heap/marking_verifier.h @@ -33,16 +33,14 @@ class MarkingVerifier final : public Visitor { } void Visit(void* object, TraceDescriptor desc) final { - CHECK(object); - VerifyChild(desc.base_object_payload); + VerifyChild(object, desc.base_object_payload); } void VisitWeak(void* object, void** object_slot, TraceDescriptor desc, WeakCallback callback) final { - CHECK(object); - VerifyChild(desc.base_object_payload); + VerifyChild(object, desc.base_object_payload); } // Unused overrides. @@ -57,20 +55,18 @@ class MarkingVerifier final : public Visitor { } void RegisterWeakCallback(void*, WeakCallback) final {} void Visit(const TraceWrapperV8Reference<v8::Value>&) final {} - void VisitWithWrappers(void*, TraceDescriptor) final {} private: - void VerifyChild(void* base_object_payload) { - // The following check ensures that an object is currently not under - // construction. All verifier runs are assumed to be run outside of mixin - // construction. Consequently, the following cases can lead to a failing - // check: - // 1. The garbage collector ignoring no-GC scopes for mixin construction. - // 2. Missing macro USING_GARBAGE_COLLECTED_MIXIN for users of - // GarbageCollectedMixin. - CHECK(base_object_payload); - HeapObjectHeader* child_header = - HeapObjectHeader::FromPayload(base_object_payload); + void VerifyChild(void* object, void* base_object_payload) { + CHECK(object); + // Verification may check objects that are currently under construction and + // would require vtable access to figure out their headers. A nullptr in + // |base_object_payload| indicates that a mixin object is in construction + // and the vtable cannot be used to get to the object header. + const HeapObjectHeader* const child_header = + (base_object_payload) + ? HeapObjectHeader::FromPayload(base_object_payload) + : HeapObjectHeader::FromInnerAddress(object); // These checks ensure that any children reachable from marked parents are // also marked. If you hit these checks then marking is in an inconsistent // state meaning that there are unmarked objects reachable from marked diff --git a/chromium/third_party/blink/renderer/platform/heap/marking_visitor.cc b/chromium/third_party/blink/renderer/platform/heap/marking_visitor.cc index 25feea2c96f..b51f0c48df1 100644 --- a/chromium/third_party/blink/renderer/platform/heap/marking_visitor.cc +++ b/chromium/third_party/blink/renderer/platform/heap/marking_visitor.cc @@ -17,11 +17,6 @@ ALWAYS_INLINE bool IsHashTableDeleteValue(const void* value) { } // namespace -std::unique_ptr<MarkingVisitor> MarkingVisitor::Create(ThreadState* state, - MarkingMode mode) { - return std::make_unique<MarkingVisitor>(state, mode); -} - MarkingVisitor::MarkingVisitor(ThreadState* state, MarkingMode marking_mode) : Visitor(state), marking_worklist_(Heap().GetMarkingWorklist(), @@ -40,11 +35,7 @@ MarkingVisitor::MarkingVisitor(ThreadState* state, MarkingMode marking_mode) MarkingVisitor::~MarkingVisitor() = default; void MarkingVisitor::DynamicallyMarkAddress(Address address) { - BasePage* const page = PageFromObject(address); - HeapObjectHeader* const header = - page->IsLargeObjectPage() - ? static_cast<LargeObjectPage*>(page)->ObjectHeader() - : static_cast<NormalPage*>(page)->FindHeaderFromAddress(address); + HeapObjectHeader* const header = HeapObjectHeader::FromInnerAddress(address); DCHECK(header); DCHECK(!header->IsInConstruction()); const GCInfo* gc_info = @@ -146,10 +137,6 @@ void MarkingVisitor::TraceMarkedBackingStoreSlow(void* value) { HeapObjectHeader* header = HeapObjectHeader::FromPayload(value); CHECK(header->IsMarked()); DCHECK(thread_state->CurrentVisitor()); - // This check ensures that the visitor will not eagerly recurse into children - // but rather push all blink::GarbageCollected objects and only eagerly trace - // non-managed objects. - DCHECK(!thread_state->Heap().GetStackFrameDepth().IsEnabled()); // No weak handling for write barriers. Modifying weakly reachable objects // strongifies them for the current cycle. GCInfoTable::Get() diff --git a/chromium/third_party/blink/renderer/platform/heap/marking_visitor.h b/chromium/third_party/blink/renderer/platform/heap/marking_visitor.h index d7251a65bc2..ca797f63892 100644 --- a/chromium/third_party/blink/renderer/platform/heap/marking_visitor.h +++ b/chromium/third_party/blink/renderer/platform/heap/marking_visitor.h @@ -33,8 +33,6 @@ class PLATFORM_EXPORT MarkingVisitor : public Visitor { kGlobalMarkingWithCompaction, }; - static std::unique_ptr<MarkingVisitor> Create(ThreadState*, MarkingMode); - // Write barrier that adds |value| to the set of marked objects. The barrier // bails out if marking is off or the object is not yet marked. ALWAYS_INLINE static void WriteBarrier(void* value); @@ -82,10 +80,6 @@ class PLATFORM_EXPORT MarkingVisitor : public Visitor { desc.callback); } - void VisitWithWrappers(void*, TraceDescriptor) final { - // Ignore as the object is also passed to Visit(void*, TraceDescriptor). - } - void VisitWeak(void* object, void** object_slot, TraceDescriptor desc, @@ -180,25 +174,21 @@ inline void MarkingVisitor::MarkHeader(HeapObjectHeader* header, } ALWAYS_INLINE void MarkingVisitor::WriteBarrier(void* value) { -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) if (!ThreadState::IsAnyIncrementalMarking()) return; // Avoid any further checks and dispatch to a call at this point. Aggressive // inlining otherwise pollutes the regular execution paths. WriteBarrierSlow(value); -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) } ALWAYS_INLINE void MarkingVisitor::TraceMarkedBackingStore(void* value) { -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) if (!ThreadState::IsAnyIncrementalMarking()) return; // Avoid any further checks and dispatch to a call at this point. Aggressive // inlining otherwise pollutes the regular execution paths. TraceMarkedBackingStoreSlow(value); -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) } } // namespace blink diff --git a/chromium/third_party/blink/renderer/platform/heap/member.h b/chromium/third_party/blink/renderer/platform/heap/member.h index acca8c067e3..6c746355504 100644 --- a/chromium/third_party/blink/renderer/platform/heap/member.h +++ b/chromium/third_party/blink/renderer/platform/heap/member.h @@ -22,8 +22,6 @@ namespace blink { template <typename T> class Persistent; -template <typename T> -class TraceWrapperMember; enum class TracenessMemberConfiguration { kTraced, @@ -213,10 +211,8 @@ class MemberBase { static constexpr intptr_t kHashTableDeletedRawValue = -1; ALWAYS_INLINE void WriteBarrier() const { -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) MarkingVisitor::WriteBarrier( const_cast<typename std::remove_const<T>::type*>(this->raw_)); -#endif // BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) } void CheckPointer() { @@ -553,12 +549,6 @@ struct DefaultHash<blink::SameThreadCheckedMember<T>> { }; template <typename T> -struct DefaultHash<blink::TraceWrapperMember<T>> { - STATIC_ONLY(DefaultHash); - using Hash = MemberHash<T>; -}; - -template <typename T> struct IsTraceable<blink::Member<T>> { STATIC_ONLY(IsTraceable); static const bool value = true; @@ -582,12 +572,6 @@ struct IsTraceable<blink::SameThreadCheckedMember<T>> { static const bool value = true; }; -template <typename T> -struct IsTraceable<blink::TraceWrapperMember<T>> { - STATIC_ONLY(IsTraceable); - static const bool value = true; -}; - template <typename T, typename Traits, typename Allocator> class ConstructTraits<blink::Member<T>, Traits, Allocator> { STATIC_ONLY(ConstructTraits); diff --git a/chromium/third_party/blink/renderer/platform/heap/name_trait_test.cc b/chromium/third_party/blink/renderer/platform/heap/name_trait_test.cc index 44fb5e32ef6..d83ab7012fc 100644 --- a/chromium/third_party/blink/renderer/platform/heap/name_trait_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/name_trait_test.cc @@ -6,20 +6,21 @@ #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/renderer/platform/bindings/name_client.h" #include "third_party/blink/renderer/platform/heap/name_traits.h" namespace blink { namespace { -class ClassWithoutName { +class ClassWithoutName final { public: ClassWithoutName() = default; }; -class ClassWithName : public NameClient { +class ClassWithName final : public NameClient { public: - ClassWithName(const char* name) : name_(name) {} + explicit ClassWithName(const char* name) : name_(name) {} const char* NameInHeapSnapshot() const final { return name_; } @@ -30,15 +31,28 @@ class ClassWithName : public NameClient { } // namespace TEST(NameTraitTest, InternalNamesHiddenInOfficialBuild) { + // Use a test instead of static_assert to allow local builds but block + // enabling the feature accidentally through the waterfall. + // + // Do not include such type information in official builds to + // (a) safe binary size on string literals, and + // (b) avoid exposing internal types until it has been clarified whether + // exposing internals in DevTools is fine. #if defined(OFFICIAL_BUILD) - EXPECT_TRUE(NameTrait<ClassWithoutName>::HideInternalName()); + EXPECT_TRUE(NameClient::HideInternalName()); #endif } +TEST(NameTraitTest, InternalNamesHiddenWhenFlagIsTurnedOff) { +#if !BUILDFLAG(RAW_HEAP_SNAPSHOTS) + EXPECT_TRUE(NameClient::HideInternalName()); +#endif // BUILDFLAG(RAW_HEAP_SNAPSHOTS) +} + TEST(NameTraitTest, DefaultName) { ClassWithoutName no_name; const char* name = NameTrait<ClassWithoutName>::GetName(&no_name).value; - if (NameTrait<ClassWithoutName>::HideInternalName()) { + if (NameClient::HideInternalName()) { EXPECT_EQ(0, strcmp(name, "InternalNode")); } else { EXPECT_NE(nullptr, strstr(name, "ClassWithoutName")); diff --git a/chromium/third_party/blink/renderer/platform/heap/name_traits.h b/chromium/third_party/blink/renderer/platform/heap/name_traits.h index c994d5e00a7..eda1cc15dde 100644 --- a/chromium/third_party/blink/renderer/platform/heap/name_traits.h +++ b/chromium/third_party/blink/renderer/platform/heap/name_traits.h @@ -24,14 +24,6 @@ class NameTrait { STATIC_ONLY(NameTrait); public: - static constexpr bool HideInternalName() { -#if defined(OFFICIAL_BUILD) || !(defined(COMPILER_GCC) || defined(__clang__)) - return true; -#else - return false; -#endif - } - static HeapObjectName GetName(const void* obj) { return GetNameFor(static_cast<const T*>(obj)); } @@ -42,17 +34,10 @@ class NameTrait { } static HeapObjectName GetNameFor(...) { - // For non-official builds construct the name of a type from a compiler - // intrinsic. - // - // Do not include such type information in official builds to - // (a) safe binary size on string literals, and - // (b) avoid exposing internal types until a proper DevTools frontend - // implementation is present. -#if defined(OFFICIAL_BUILD) || !(defined(COMPILER_GCC) || defined(__clang__)) - return {"InternalNode", true}; -#else - DCHECK(!HideInternalName()); + if (NameClient::HideInternalName()) + return {"InternalNode", true}; + + DCHECK(!NameClient::HideInternalName()); static const char* leaky_class_name = nullptr; if (leaky_class_name) return {leaky_class_name, false}; @@ -67,7 +52,6 @@ class NameTrait { const std::string name = raw.substr(start_pos, len).c_str(); leaky_class_name = strcpy(new char[name.length() + 1], name.c_str()); return {leaky_class_name, false}; -#endif } }; diff --git a/chromium/third_party/blink/renderer/platform/heap/object_start_bitmap_test.cc b/chromium/third_party/blink/renderer/platform/heap/object_start_bitmap_test.cc index b9a8dc8350a..0fc37528bee 100644 --- a/chromium/third_party/blink/renderer/platform/heap/object_start_bitmap_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/object_start_bitmap_test.cc @@ -5,6 +5,7 @@ #include "third_party/blink/renderer/platform/heap/heap_page.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/renderer/platform/wtf/allocator.h" namespace blink { @@ -19,6 +20,8 @@ bool IsEmpty(const ObjectStartBitmap& bitmap) { // Abstraction for objects that hides ObjectStartBitmap::kGranularity and // the base address as getting either of it wrong will result in failed DCHECKs. class Object { + STACK_ALLOCATED(); + public: static Address kBaseOffset; diff --git a/chromium/third_party/blink/renderer/platform/heap/page_memory.h b/chromium/third_party/blink/renderer/platform/heap/page_memory.h index aca70268b44..0780971f793 100644 --- a/chromium/third_party/blink/renderer/platform/heap/page_memory.h +++ b/chromium/third_party/blink/renderer/platform/heap/page_memory.h @@ -10,7 +10,6 @@ #include "third_party/blink/renderer/platform/heap/heap_page.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" -#include "third_party/blink/renderer/platform/wtf/compiler.h" namespace blink { diff --git a/chromium/third_party/blink/renderer/platform/heap/persistent_node.h b/chromium/third_party/blink/renderer/platform/heap/persistent_node.h index 51df614a1f6..50c6f4fff74 100644 --- a/chromium/third_party/blink/renderer/platform/heap/persistent_node.h +++ b/chromium/third_party/blink/renderer/platform/heap/persistent_node.h @@ -109,6 +109,8 @@ struct PersistentNodeSlots final { template <ThreadAffinity affinity, WeaknessPersistentConfiguration weakness_configuration> class PersistentNodePtr { + STACK_ALLOCATED(); + public: PersistentNode* Get() const { return ptr_; } bool IsInitialized() const { return ptr_; } @@ -128,6 +130,8 @@ class PersistentNodePtr { // but can be polled to see whether it is initialized without the mutex. template <WeaknessPersistentConfiguration weakness_configuration> class CrossThreadPersistentNodePtr { + STACK_ALLOCATED(); + public: PersistentNode* Get() const { #if DCHECK_IS_ON() diff --git a/chromium/third_party/blink/renderer/platform/heap/run_all_tests.cc b/chromium/third_party/blink/renderer/platform/heap/run_all_tests.cc index ea68f22d0c2..47429a84ecd 100644 --- a/chromium/third_party/blink/renderer/platform/heap/run_all_tests.cc +++ b/chromium/third_party/blink/renderer/platform/heap/run_all_tests.cc @@ -43,11 +43,10 @@ class BlinkTestSuite : public base::TestSuite { void Initialize() override { base::TestSuite::Initialize(); content::SetUpBlinkTestEnvironment(); - blink::ThreadState::Current()->RegisterTraceDOMWrappers(nullptr, nullptr, - nullptr, nullptr); + blink::ThreadState::Current()->RegisterTraceDOMWrappers(nullptr, nullptr); } void Shutdown() override { - blink::ThreadState::Current()->CollectAllGarbage(); + blink::ThreadState::Current()->CollectAllGarbageForTesting(); content::TearDownBlinkTestEnvironment(); base::TestSuite::Shutdown(); } diff --git a/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.cc b/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.cc index 04793f31d5f..b9ae01d062a 100644 --- a/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.cc +++ b/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.cc @@ -62,7 +62,7 @@ void SparseHeapBitmap::Add(Address address) { // encompass. if (address >= MaxEnd()) { if (!right_) { - right_ = SparseHeapBitmap::Create(address); + right_ = std::make_unique<SparseHeapBitmap>(address); return; } right_->Add(address); @@ -71,7 +71,7 @@ void SparseHeapBitmap::Add(Address address) { // Same on the other side. if (address < MinStart()) { if (!left_) { - left_ = SparseHeapBitmap::Create(address); + left_ = std::make_unique<SparseHeapBitmap>(address); return; } left_->Add(address); diff --git a/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h b/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h index 70654e74e4e..f16c2ca1253 100644 --- a/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h +++ b/chromium/third_party/blink/renderer/platform/heap/sparse_heap_bitmap.h @@ -40,10 +40,14 @@ namespace blink { // class PLATFORM_EXPORT SparseHeapBitmap { public: - static std::unique_ptr<SparseHeapBitmap> Create(Address base) { - return base::WrapUnique(new SparseHeapBitmap(base)); + explicit SparseHeapBitmap(Address base) : base_(base), size_(1) { + DCHECK(!(reinterpret_cast<uintptr_t>(base_) & kPointerAlignmentMask)); + static_assert(kPointerAlignmentMask <= kAllocationMask, + "address shift exceeds heap pointer alignment"); + // For now, only recognize 8 and 4. + static_assert(alignof(void*) == 8 || alignof(void*) == 4, + "unsupported pointer alignment"); } - ~SparseHeapBitmap() = default; // Return the sparse bitmap subtree that at least covers the @@ -81,15 +85,6 @@ class PLATFORM_EXPORT SparseHeapBitmap { size_t IntervalCount() const; private: - explicit SparseHeapBitmap(Address base) : base_(base), size_(1) { - DCHECK(!(reinterpret_cast<uintptr_t>(base_) & kPointerAlignmentMask)); - static_assert(kPointerAlignmentMask <= kAllocationMask, - "address shift exceeds heap pointer alignment"); - // For now, only recognize 8 and 4. - static_assert(alignof(void*) == 8 || alignof(void*) == 4, - "unsupported pointer alignment"); - } - Address Base() const { return base_; } size_t size() const { return size_; } Address end() const { return Base() + (size_ - 1); } diff --git a/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.cc b/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.cc deleted file mode 100644 index 93ba8e28ecb..00000000000 --- a/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "third_party/blink/renderer/platform/heap/stack_frame_depth.h" - -#include "third_party/blink/public/platform/platform.h" -#include "third_party/blink/renderer/platform/wtf/stack_util.h" - -#if defined(OS_WIN) -#include <stddef.h> -#include <windows.h> -#include <winnt.h> -#elif defined(__GLIBC__) -extern "C" void* __libc_stack_end; // NOLINT -#endif - -namespace blink { - -static const char* g_avoid_optimization = nullptr; - -// NOINLINE ensures that |dummy| array on configureLimit() is not optimized -// away, and the stack frame base register is adjusted |kSafeStackFrameSize|. -NOINLINE static uintptr_t CurrentStackFrameBaseOnCallee(const char* dummy) { - g_avoid_optimization = dummy; - return StackFrameDepth::CurrentStackFrame(); -} - -uintptr_t StackFrameDepth::GetFallbackStackLimit() { - // Allocate an |kSafeStackFrameSize|-sized object on stack and query - // stack frame base after it. - char dummy[kSafeStackFrameSize]; - - // Check that the stack frame can be used. - dummy[sizeof(dummy) - 1] = 0; - return CurrentStackFrameBaseOnCallee(dummy); -} - -void StackFrameDepth::EnableStackLimit() { - // All supported platforms will currently return a non-zero estimate, - // except if ASan is enabled. - size_t stack_size = WTF::GetUnderestimatedStackSize(); - if (!stack_size) { - stack_frame_limit_ = GetFallbackStackLimit(); - return; - } - - // Adjust the following when running out of stack space in between turns of - // checking |IsSafeToRecurse()|. The required room size depends on the actions - // performed between turns and how well compiler optimizations apply. - static const int kStackRoomSize = 4096; - - Address stack_base = reinterpret_cast<Address>(WTF::GetStackStart()); - CHECK_GT(stack_size, static_cast<const size_t>(kStackRoomSize)); - size_t stack_room = stack_size - kStackRoomSize; - CHECK_GT(stack_base, reinterpret_cast<Address>(stack_room)); - stack_frame_limit_ = reinterpret_cast<uintptr_t>(stack_base - stack_room); - - // If current stack use is already exceeding estimated limit, mark as - // disabled. - if (!IsSafeToRecurse()) - DisableStackLimit(); -} - -} // namespace blink diff --git a/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.h b/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.h deleted file mode 100644 index 853db1148c3..00000000000 --- a/chromium/third_party/blink/renderer/platform/heap/stack_frame_depth.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_STACK_FRAME_DEPTH_H_ -#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_STACK_FRAME_DEPTH_H_ - -#include <stdint.h> -#include <cstddef> -#include "base/macros.h" -#include "build/build_config.h" -#include "third_party/blink/renderer/platform/platform_export.h" -#include "third_party/blink/renderer/platform/wtf/allocator.h" -#include "third_party/blink/renderer/platform/wtf/assertions.h" - -namespace blink { - -// StackFrameDepth keeps track of current call stack frame depth. -// It is specifically used to control stack usage while tracing -// the object graph during a GC. -// -// Use isSafeToRecurse() to determine if it is safe to consume -// more stack by invoking another recursive call. -class PLATFORM_EXPORT StackFrameDepth final { - DISALLOW_NEW(); - - public: - StackFrameDepth() : stack_frame_limit_(kMinimumStackLimit) {} - bool IsSafeToRecurse() { - // Asssume that the stack grows towards lower addresses, which - // all the ABIs currently supported do. - // - // A unit test checks that the assumption holds for a target - // (HeapTest.StackGrowthDirection.) - return CurrentStackFrame() > stack_frame_limit_; - } - - void EnableStackLimit(); - void DisableStackLimit() { stack_frame_limit_ = kMinimumStackLimit; } - - bool IsEnabled() { return stack_frame_limit_ != kMinimumStackLimit; } - bool IsAcceptableStackUse() { -#if defined(ADDRESS_SANITIZER) - // ASan adds extra stack usage leading to too noisy asserts. - return true; -#else - return !IsEnabled() || IsSafeToRecurse(); -#endif - } - -#if defined(COMPILER_MSVC) -// Ignore C4172: returning address of local variable or temporary: dummy. This -// warning suppression has to go outside of the function to take effect. -#pragma warning(push) -#pragma warning(disable : 4172) -#endif - static uintptr_t CurrentStackFrame(const char* dummy = nullptr) { -#if defined(COMPILER_GCC) - return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); -#elif defined(COMPILER_MSVC) - return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); -#else -#error "Stack frame pointer estimation not supported on this platform." - return 0; -#endif - } -#if defined(COMPILER_MSVC) -#pragma warning(pop) -#endif - - private: - // The maximum depth of eager, unrolled trace() calls that is - // considered safe and allowed for targets with an unknown - // thread stack size. - static const int kSafeStackFrameSize = 32 * 1024; - - // The stack pointer is assumed to grow towards lower addresses; - // |kMinimumStackLimit| then being the limit that a stack - // pointer will always exceed. - static const uintptr_t kMinimumStackLimit = ~uintptr_t{0}; - - static uintptr_t GetFallbackStackLimit(); - - // The (pointer-valued) stack limit. - uintptr_t stack_frame_limit_; -}; - -class StackFrameDepthScope { - STACK_ALLOCATED(); - DISALLOW_COPY_AND_ASSIGN(StackFrameDepthScope); - - public: - explicit StackFrameDepthScope(StackFrameDepth* depth) : depth_(depth) { - depth_->EnableStackLimit(); - // Enabled unless under stack pressure. - DCHECK(depth_->IsSafeToRecurse() || !depth_->IsEnabled()); - } - - ~StackFrameDepthScope() { depth_->DisableStackLimit(); } - - private: - StackFrameDepth* depth_; -}; - -} // namespace blink - -#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_STACK_FRAME_DEPTH_H_ diff --git a/chromium/third_party/blink/renderer/platform/heap/thread_state.cc b/chromium/third_party/blink/renderer/platform/heap/thread_state.cc index c5afac70bdf..8b4b01704b4 100644 --- a/chromium/third_party/blink/renderer/platform/heap/thread_state.cc +++ b/chromium/third_party/blink/renderer/platform/heap/thread_state.cc @@ -101,24 +101,18 @@ constexpr size_t kMaxTerminationGCLoops = 20; const char* GcReasonString(BlinkGC::GCReason reason) { switch (reason) { - case BlinkGC::GCReason::kIdleGC: - return "IdleGC"; case BlinkGC::GCReason::kPreciseGC: return "PreciseGC"; case BlinkGC::GCReason::kConservativeGC: return "ConservativeGC"; - case BlinkGC::GCReason::kForcedGC: - return "ForcedGC"; + case BlinkGC::GCReason::kForcedGCForTesting: + return "ForcedGCForTesting"; case BlinkGC::GCReason::kMemoryPressureGC: return "MemoryPressureGC"; case BlinkGC::GCReason::kPageNavigationGC: return "PageNavigationGC"; case BlinkGC::GCReason::kThreadTerminationGC: return "ThreadTerminationGC"; - case BlinkGC::GCReason::kTesting: - return "TestingGC"; - case BlinkGC::GCReason::kIncrementalIdleGC: - return "IncrementalIdleGC"; case BlinkGC::GCReason::kIncrementalV8FollowupGC: return "IncrementalV8FollowupGC"; case BlinkGC::GCReason::kUnifiedHeapGC: @@ -175,11 +169,7 @@ ThreadState::ThreadState() end_of_stack_(reinterpret_cast<intptr_t*>(WTF::GetStackStart())), gc_state_(kNoGCScheduled), gc_phase_(GCPhase::kNone), - reason_for_scheduled_gc_(BlinkGC::GCReason::kMaxValue), - isolate_(nullptr), - trace_dom_wrappers_(nullptr), - invalidate_dead_objects_in_wrappers_marking_deque_(nullptr), - perform_cleanup_(nullptr), + reason_for_scheduled_gc_(BlinkGC::GCReason::kForcedGCForTesting), #if defined(ADDRESS_SANITIZER) asan_fake_stack_(__asan_get_current_fake_stack()), #endif @@ -190,13 +180,12 @@ ThreadState::ThreadState() DCHECK(CheckThread()); DCHECK(!**thread_specific_); **thread_specific_ = this; - heap_ = std::make_unique<ThreadHeap>(this); } -// Implementation for WebRAILModeObserver -void ThreadState::OnRAILModeChanged(v8::RAILMode new_mode) { - should_optimize_for_load_time_ = new_mode == v8::RAILMode::PERFORMANCE_LOAD; +// Implementation for RAILModeObserver +void ThreadState::OnRAILModeChanged(RAILMode new_mode) { + should_optimize_for_load_time_ = new_mode == RAILMode::kLoad; // When switching RAIL mode to load we try to avoid incremental marking as // the write barrier cost is noticeable on throughput and garbage // accumulated during loading is likely to be alive during that phase. The @@ -475,13 +464,6 @@ bool ThreadState::JudgeGCThreshold(size_t allocated_object_size_threshold, PartitionAllocGrowingRate() >= heap_growing_rate_threshold; } -bool ThreadState::ShouldScheduleIdleGC() { - if (GetGCState() != kNoGCScheduled) - return false; - return JudgeGCThreshold(kDefaultAllocatedObjectSizeThreshold, 1024 * 1024, - 1.5); -} - bool ThreadState::ShouldScheduleV8FollowupGC() { return JudgeGCThreshold(kDefaultAllocatedObjectSizeThreshold, 32 * 1024 * 1024, 1.5); @@ -522,19 +504,10 @@ void ThreadState::ScheduleV8FollowupGCIfNeeded(BlinkGC::V8GCType gc_type) { if (gc_type == BlinkGC::kV8MajorGC) { // In case of unified heap garbage collections a V8 major GC also collects // the Blink heap. - if (RuntimeEnabledFeatures::HeapUnifiedGarbageCollectionEnabled()) - return; - - // This CompleteSweep() will do nothing in common cases since we've - // called CompleteSweep() before V8 starts minor/major GCs. - // TODO(ulan): Try removing this for Major V8 GC too. - CompleteSweep(); - DCHECK(!IsSweepingInProgress()); - DCHECK(!SweepForbidden()); + return; } - if ((gc_type == BlinkGC::kV8MajorGC && ShouldForceMemoryPressureGC()) || - ShouldScheduleV8FollowupGC()) { + if (ShouldScheduleV8FollowupGC()) { // When we want to optimize for load time, we should prioritize throughput // over latency and not do incremental marking. if (RuntimeEnabledFeatures::HeapIncrementalMarkingEnabled() && @@ -548,10 +521,6 @@ void ThreadState::ScheduleV8FollowupGCIfNeeded(BlinkGC::V8GCType gc_type) { << "ScheduleV8FollowupGCIfNeeded: Scheduled precise GC"; SchedulePreciseGC(); } - } else if (gc_type == BlinkGC::kV8MajorGC && ShouldScheduleIdleGC()) { - VLOG(2) << "[state:" << this << "] " - << "ScheduleV8FollowupGCIfNeeded: Scheduled idle GC"; - ScheduleIdleGC(); } } @@ -610,10 +579,10 @@ void ThreadState::SchedulePageNavigationGC() { SetGCState(kPageNavigationGCScheduled); } -void ThreadState::ScheduleFullGC() { +void ThreadState::ScheduleForcedGCForTesting() { DCHECK(CheckThread()); CompleteSweep(); - SetGCState(kFullGCScheduled); + SetGCState(kForcedGCForTestingScheduled); } void ThreadState::ScheduleGCIfNeeded() { @@ -663,22 +632,13 @@ void ThreadState::ScheduleGCIfNeeded() { } } - if (ShouldScheduleIdleGC()) { - VLOG(2) << "[state:" << this << "] " - << "ScheduleGCIfNeeded: Scheduled idle GC"; - ScheduleIdleGC(); - return; - } - -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) if (GetGCState() == kNoGCScheduled && RuntimeEnabledFeatures::HeapIncrementalMarkingStressEnabled()) { VLOG(2) << "[state:" << this << "] " << "ScheduleGCIfNeeded: Scheduled incremental marking for testing"; - IncrementalMarkingStart(BlinkGC::GCReason::kTesting); + IncrementalMarkingStart(BlinkGC::GCReason::kForcedGCForTesting); return; } -#endif } ThreadState* ThreadState::FromObject(const void* object) { @@ -689,39 +649,6 @@ ThreadState* ThreadState::FromObject(const void* object) { return page->Arena()->GetThreadState(); } -void ThreadState::PerformIdleGC(TimeTicks deadline) { - DCHECK(CheckThread()); - - if (GetGCState() != kIdleGCScheduled) - return; - - if (IsGCForbidden()) { - // If GC is forbidden at this point, try again. - RescheduleIdleGC(); - return; - } - - TimeDelta estimated_marking_time = - heap_->stats_collector()->estimated_marking_time(); - if ((deadline - CurrentTimeTicks()) <= estimated_marking_time && - !ThreadScheduler::Current()->CanExceedIdleDeadlineIfRequired()) { - // If marking is estimated to take longer than the deadline and we can't - // exceed the deadline, then reschedule for the next idle period. - RescheduleIdleGC(); - return; - } - -#if BUILDFLAG(BLINK_HEAP_INCREMENTAL_MARKING) - if (RuntimeEnabledFeatures::HeapIncrementalMarkingEnabled()) { - IncrementalMarkingStart(BlinkGC::GCReason::kIncrementalIdleGC); - return; - } -#endif - - CollectGarbage(BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kLazySweeping, BlinkGC::GCReason::kIdleGC); -} - void ThreadState::PerformIdleLazySweep(TimeTicks deadline) { DCHECK(CheckThread()); @@ -766,23 +693,6 @@ void ThreadState::ScheduleIncrementalMarkingFinalize() { SetGCState(kIncrementalMarkingFinalizeScheduled); } -void ThreadState::ScheduleIdleGC() { - // Idle GC has the lowest priority so do not schedule if a GC is already - // scheduled or if marking is in progress. - if (GetGCState() != kNoGCScheduled) - return; - CompleteSweep(); - SetGCState(kIdleGCScheduled); - ThreadScheduler::Current()->PostNonNestableIdleTask( - FROM_HERE, WTF::Bind(&ThreadState::PerformIdleGC, WTF::Unretained(this))); -} - -void ThreadState::RescheduleIdleGC() { - DCHECK_EQ(kIdleGCScheduled, GetGCState()); - SetGCState(kNoGCScheduled); - ScheduleIdleGC(); -} - void ThreadState::ScheduleIdleLazySweep() { ThreadScheduler::Current()->PostIdleTask( FROM_HERE, @@ -797,9 +707,9 @@ void ThreadState::SchedulePreciseGC() { void ThreadState::ScheduleIncrementalGC(BlinkGC::GCReason reason) { DCHECK(CheckThread()); - // Schedule an incremental GC only when no GC is scheduled or an idle GC is - // scheduled. Otherwise, already scheduled GCs should be prioritized. - if (GetGCState() == kNoGCScheduled || GetGCState() == kIdleGCScheduled) { + // Schedule an incremental GC only when no GC is scheduled. Otherwise, already + // scheduled GCs should be prioritized. + if (GetGCState() == kNoGCScheduled) { CompleteSweep(); reason_for_scheduled_gc_ = reason; SetGCState(kIncrementalGCScheduled); @@ -816,9 +726,8 @@ namespace { void UnexpectedGCState(ThreadState::GCState gc_state) { switch (gc_state) { UNEXPECTED_GCSTATE(kNoGCScheduled); - UNEXPECTED_GCSTATE(kIdleGCScheduled); UNEXPECTED_GCSTATE(kPreciseGCScheduled); - UNEXPECTED_GCSTATE(kFullGCScheduled); + UNEXPECTED_GCSTATE(kForcedGCForTestingScheduled); UNEXPECTED_GCSTATE(kIncrementalMarkingStepPaused); UNEXPECTED_GCSTATE(kIncrementalMarkingStepScheduled); UNEXPECTED_GCSTATE(kIncrementalMarkingFinalizeScheduled); @@ -840,8 +749,8 @@ void ThreadState::SetGCState(GCState gc_state) { case kNoGCScheduled: DCHECK(CheckThread()); VERIFY_STATE_TRANSITION( - gc_state_ == kNoGCScheduled || gc_state_ == kIdleGCScheduled || - gc_state_ == kPreciseGCScheduled || gc_state_ == kFullGCScheduled || + gc_state_ == kNoGCScheduled || gc_state_ == kPreciseGCScheduled || + gc_state_ == kForcedGCForTestingScheduled || gc_state_ == kPageNavigationGCScheduled || gc_state_ == kIncrementalMarkingStepPaused || gc_state_ == kIncrementalMarkingStepScheduled || @@ -852,39 +761,32 @@ void ThreadState::SetGCState(GCState gc_state) { DCHECK(CheckThread()); VERIFY_STATE_TRANSITION(gc_state_ == kNoGCScheduled || gc_state_ == kIncrementalMarkingStepScheduled || - gc_state_ == kIdleGCScheduled || gc_state_ == kIncrementalGCScheduled); break; case kIncrementalMarkingFinalizeScheduled: DCHECK(CheckThread()); VERIFY_STATE_TRANSITION(gc_state_ == kIncrementalMarkingStepScheduled); break; - case kFullGCScheduled: + case kForcedGCForTestingScheduled: case kPageNavigationGCScheduled: case kPreciseGCScheduled: DCHECK(CheckThread()); DCHECK(!IsSweepingInProgress()); - VERIFY_STATE_TRANSITION( - gc_state_ == kNoGCScheduled || gc_state_ == kIdleGCScheduled || - gc_state_ == kIncrementalMarkingStepPaused || - gc_state_ == kIncrementalMarkingStepScheduled || - gc_state_ == kIncrementalMarkingFinalizeScheduled || - gc_state_ == kPreciseGCScheduled || gc_state_ == kFullGCScheduled || - gc_state_ == kPageNavigationGCScheduled || - gc_state_ == kIncrementalGCScheduled); - break; - case kIdleGCScheduled: - DCHECK(CheckThread()); - DCHECK(!IsMarkingInProgress()); - DCHECK(!IsSweepingInProgress()); - VERIFY_STATE_TRANSITION(gc_state_ == kNoGCScheduled); + VERIFY_STATE_TRANSITION(gc_state_ == kNoGCScheduled || + gc_state_ == kIncrementalMarkingStepPaused || + gc_state_ == kIncrementalMarkingStepScheduled || + gc_state_ == + kIncrementalMarkingFinalizeScheduled || + gc_state_ == kPreciseGCScheduled || + gc_state_ == kForcedGCForTestingScheduled || + gc_state_ == kPageNavigationGCScheduled || + gc_state_ == kIncrementalGCScheduled); break; case kIncrementalGCScheduled: DCHECK(CheckThread()); DCHECK(!IsMarkingInProgress()); DCHECK(!IsSweepingInProgress()); - VERIFY_STATE_TRANSITION(gc_state_ == kNoGCScheduled || - gc_state_ == kIdleGCScheduled); + VERIFY_STATE_TRANSITION(gc_state_ == kNoGCScheduled); break; case kIncrementalMarkingStepPaused: DCHECK(CheckThread()); @@ -929,8 +831,8 @@ void ThreadState::RunScheduledGC(BlinkGC::StackState stack_state) { return; switch (GetGCState()) { - case kFullGCScheduled: - CollectAllGarbage(); + case kForcedGCForTestingScheduled: + CollectAllGarbageForTesting(); break; case kPreciseGCScheduled: CollectGarbage(BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, @@ -941,9 +843,6 @@ void ThreadState::RunScheduledGC(BlinkGC::StackState stack_state) { BlinkGC::kEagerSweeping, BlinkGC::GCReason::kPageNavigationGC); break; - case kIdleGCScheduled: - // Idle time GC will be scheduled by Blink Scheduler. - break; case kIncrementalMarkingStepScheduled: IncrementalMarkingStep(stack_state); break; @@ -1052,7 +951,8 @@ void ThreadState::CompleteSweep() { SweepForbiddenScope scope(this); ThreadHeapStatsCollector::EnabledScope stats_scope( Heap().stats_collector(), ThreadHeapStatsCollector::kCompleteSweep, - "forced", current_gc_data_.reason == BlinkGC::GCReason::kForcedGC); + "forced", + current_gc_data_.reason == BlinkGC::GCReason::kForcedGCForTesting); Heap().CompleteSweep(); if (!was_in_atomic_pause) LeaveAtomicPause(); @@ -1138,12 +1038,40 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) { event.scope_data[ThreadHeapStatsCollector::kLazySweepOnAllocation]; UMA_HISTOGRAM_TIMES("BlinkGC.TimeForGCCycle", cycle_duration); - UMA_HISTOGRAM_TIMES("BlinkGC.TimeForNestedInV8", event.gc_nested_in_v8_); + const WTF::TimeDelta incremental_marking_duration = + event.scope_data + [ThreadHeapStatsCollector::kIncrementalMarkingStartMarking] + + event.scope_data[ThreadHeapStatsCollector::kIncrementalMarkingStep]; + UMA_HISTOGRAM_TIMES("BlinkGC.TimeForIncrementalMarking", + incremental_marking_duration); - // TODO(mlippautz): Update name of this histogram. - UMA_HISTOGRAM_TIMES( - "BlinkGC.CollectGarbage", - event.scope_data[ThreadHeapStatsCollector::kAtomicPhaseMarking]); + const WTF::TimeDelta marking_duration = + event.scope_data + [ThreadHeapStatsCollector::kIncrementalMarkingStartMarking] + + event.scope_data[ThreadHeapStatsCollector::kIncrementalMarkingStep] + + event.scope_data[ThreadHeapStatsCollector::kAtomicPhaseMarking]; + UMA_HISTOGRAM_TIMES("BlinkGC.TimeForMarking", marking_duration); + + constexpr size_t kMinObjectSizeForReportingThroughput = 1024 * 1024; + if (WTF::TimeTicks::IsHighResolution() && + (event.object_size_in_bytes_before_sweeping > + kMinObjectSizeForReportingThroughput)) { + DCHECK_GT(marking_duration.InMillisecondsF(), 0.0); + // For marking throughput computation all marking steps, independent of + // whether they are triggered from V8 or Blink, are relevant. + const WTF::TimeDelta blink_marking_duration = + marking_duration + + event.scope_data + [ThreadHeapStatsCollector::kUnifiedMarkingAtomicPrologue] + + event.scope_data[ThreadHeapStatsCollector::kUnifiedMarkingStep]; + const int main_thread_marking_throughput_mb_per_s = static_cast<int>( + static_cast<double>(event.object_size_in_bytes_before_sweeping) / + blink_marking_duration.InMillisecondsF() * 1000 / 1024 / 1024); + UMA_HISTOGRAM_COUNTS_100000("BlinkGC.MainThreadMarkingThroughput", + main_thread_marking_throughput_mb_per_s); + } + + UMA_HISTOGRAM_TIMES("BlinkGC.TimeForNestedInV8", event.gc_nested_in_v8_); UMA_HISTOGRAM_TIMES( "BlinkGC.AtomicPhaseMarking", @@ -1231,15 +1159,13 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) { break; \ } - COUNT_BY_GC_REASON(IdleGC) + // COUNT_BY_GC_REASON(IdleGC) COUNT_BY_GC_REASON(PreciseGC) COUNT_BY_GC_REASON(ConservativeGC) - COUNT_BY_GC_REASON(ForcedGC) + COUNT_BY_GC_REASON(ForcedGCForTesting) COUNT_BY_GC_REASON(MemoryPressureGC) COUNT_BY_GC_REASON(PageNavigationGC) COUNT_BY_GC_REASON(ThreadTerminationGC) - COUNT_BY_GC_REASON(Testing) - COUNT_BY_GC_REASON(IncrementalIdleGC) COUNT_BY_GC_REASON(IncrementalV8FollowupGC) COUNT_BY_GC_REASON(UnifiedHeapGC) @@ -1280,8 +1206,6 @@ void ThreadState::PostSweep() { DCHECK(CheckThread()); SetGCPhase(GCPhase::kNone); - if (GetGCState() == kIdleGCScheduled) - ScheduleIdleGC(); gc_age_++; @@ -1418,9 +1342,6 @@ void ThreadState::InvokePreFinalizers() { // static AtomicEntryFlag ThreadState::incremental_marking_flag_; -// static -AtomicEntryFlag ThreadState::wrapper_tracing_flag_; - void ThreadState::EnableIncrementalMarkingBarrier() { CHECK(!IsIncrementalMarking()); incremental_marking_flag_.Enter(); @@ -1433,18 +1354,6 @@ void ThreadState::DisableIncrementalMarkingBarrier() { SetIncrementalMarking(false); } -void ThreadState::EnableWrapperTracingBarrier() { - CHECK(!IsWrapperTracing()); - wrapper_tracing_flag_.Enter(); - SetWrapperTracing(true); -} - -void ThreadState::DisableWrapperTracingBarrier() { - CHECK(IsWrapperTracing()); - wrapper_tracing_flag_.Exit(); - SetWrapperTracing(false); -} - void ThreadState::IncrementalMarkingStart(BlinkGC::GCReason reason) { VLOG(2) << "[state:" << this << "] " << "IncrementalMarking: Start"; @@ -1560,7 +1469,8 @@ void ThreadState::CollectGarbage(BlinkGC::StackState stack_state, // mentioned below. In this case we will follow up with a regular full // garbage collection. const bool should_do_full_gc = - !was_incremental_marking || reason == BlinkGC::GCReason::kForcedGC || + !was_incremental_marking || + reason == BlinkGC::GCReason::kForcedGCForTesting || reason == BlinkGC::GCReason::kMemoryPressureGC || reason == BlinkGC::GCReason::kThreadTerminationGC; if (should_do_full_gc) { @@ -1583,15 +1493,12 @@ void ThreadState::CollectGarbage(BlinkGC::StackState stack_state, } switch (reason) { - COUNT_BY_GC_REASON(IdleGC) COUNT_BY_GC_REASON(PreciseGC) COUNT_BY_GC_REASON(ConservativeGC) - COUNT_BY_GC_REASON(ForcedGC) + COUNT_BY_GC_REASON(ForcedGCForTesting) COUNT_BY_GC_REASON(MemoryPressureGC) COUNT_BY_GC_REASON(PageNavigationGC) COUNT_BY_GC_REASON(ThreadTerminationGC) - COUNT_BY_GC_REASON(Testing) - COUNT_BY_GC_REASON(IncrementalIdleGC) COUNT_BY_GC_REASON(IncrementalV8FollowupGC) COUNT_BY_GC_REASON(UnifiedHeapGC) } @@ -1651,7 +1558,7 @@ void ThreadState::RunAtomicPause(BlinkGC::StackState stack_state, { ThreadHeapStatsCollector::DevToolsScope stats1( Heap().stats_collector(), ThreadHeapStatsCollector::kAtomicPhase, - "forced", reason == BlinkGC::GCReason::kForcedGC); + "forced", reason == BlinkGC::GCReason::kForcedGCForTesting); { AtomicPauseScope atomic_pause_scope(this); ThreadHeapStatsCollector::EnabledScope stats2( @@ -1699,10 +1606,10 @@ void ThreadState::MarkPhasePrologue(BlinkGC::StackState stack_state, current_gc_data_.reason = reason; current_gc_data_.visitor = IsUnifiedGCMarkingInProgress() - ? UnifiedHeapMarkingVisitor::Create( + ? std::make_unique<UnifiedHeapMarkingVisitor>( this, GetMarkingMode(should_compact, take_snapshot), GetIsolate()) - : MarkingVisitor::Create( + : std::make_unique<MarkingVisitor>( this, GetMarkingMode(should_compact, take_snapshot)); current_gc_data_.stack_state = stack_state; current_gc_data_.marking_type = marking_type; @@ -1734,9 +1641,6 @@ void ThreadState::AtomicPausePrologue(BlinkGC::StackState stack_state, if (marking_type == BlinkGC::kTakeSnapshot) BlinkGCMemoryDumpProvider::Instance()->ClearProcessDumpForCurrentGC(); - if (isolate_ && perform_cleanup_) - perform_cleanup_(isolate_); - if (stack_state == BlinkGC::kNoHeapPointersOnStack) { Heap().FlushNotFullyConstructedObjects(); } @@ -1747,10 +1651,6 @@ void ThreadState::AtomicPausePrologue(BlinkGC::StackState stack_state, } void ThreadState::MarkPhaseVisitRoots() { - // StackFrameDepth should be disabled to avoid eagerly tracing into the object - // graph when just visiting roots. - DCHECK(!Heap().GetStackFrameDepth().IsEnabled()); - Visitor* visitor = current_gc_data_.visitor.get(); VisitPersistents(visitor); @@ -1780,7 +1680,6 @@ void ThreadState::MarkPhaseVisitRoots() { } bool ThreadState::MarkPhaseAdvanceMarking(TimeTicks deadline) { - StackFrameDepthScope stack_depth_scope(&Heap().GetStackFrameDepth()); return Heap().AdvanceMarking( reinterpret_cast<MarkingVisitor*>(current_gc_data_.visitor.get()), deadline); @@ -1822,9 +1721,6 @@ void ThreadState::MarkPhaseEpilogue(BlinkGC::MarkingType marking_type) { Heap().stats_collector()->NotifyMarkingCompleted(); WTF::Partitions::ReportMemoryUsageHistogram(); - if (invalidate_dead_objects_in_wrappers_marking_deque_) - invalidate_dead_objects_in_wrappers_marking_deque_(isolate_); - DEFINE_THREAD_SAFE_STATIC_LOCAL( CustomCountHistogram, total_object_space_histogram, ("BlinkGC.TotalObjectSpace", 0, 4 * 1024 * 1024, 50)); @@ -1846,12 +1742,13 @@ void ThreadState::VerifyMarking(BlinkGC::MarkingType marking_type) { Heap().VerifyMarking(); } -void ThreadState::CollectAllGarbage() { +void ThreadState::CollectAllGarbageForTesting(BlinkGC::StackState stack_state) { // We need to run multiple GCs to collect a chain of persistent handles. size_t previous_live_objects = 0; for (int i = 0; i < 5; ++i) { - CollectGarbage(BlinkGC::kNoHeapPointersOnStack, BlinkGC::kAtomicMarking, - BlinkGC::kEagerSweeping, BlinkGC::GCReason::kForcedGC); + CollectGarbage(stack_state, BlinkGC::kAtomicMarking, + BlinkGC::kEagerSweeping, + BlinkGC::GCReason::kForcedGCForTesting); const size_t live_objects = Heap().stats_collector()->previous().marked_bytes; if (live_objects == previous_live_objects) diff --git a/chromium/third_party/blink/renderer/platform/heap/thread_state.h b/chromium/third_party/blink/renderer/platform/heap/thread_state.h index afe8b4983ce..4c91b5db8e6 100644 --- a/chromium/third_party/blink/renderer/platform/heap/thread_state.h +++ b/chromium/third_party/blink/renderer/platform/heap/thread_state.h @@ -34,12 +34,12 @@ #include <memory> #include "base/macros.h" -#include "third_party/blink/public/platform/scheduler/web_rail_mode_observer.h" #include "third_party/blink/renderer/platform/bindings/script_forbidden_scope.h" #include "third_party/blink/renderer/platform/heap/atomic_entry_flag.h" #include "third_party/blink/renderer/platform/heap/blink_gc.h" #include "third_party/blink/renderer/platform/heap/threading_traits.h" #include "third_party/blink/renderer/platform/platform_export.h" +#include "third_party/blink/renderer/platform/scheduler/public/rail_mode_observer.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h" @@ -139,20 +139,18 @@ class PLATFORM_EXPORT BlinkGCObserver { ThreadState* thread_state_; }; -class PLATFORM_EXPORT ThreadState final - : private scheduler::WebRAILModeObserver { +class PLATFORM_EXPORT ThreadState final : private RAILModeObserver { USING_FAST_MALLOC(ThreadState); public: // See setGCState() for possible state transitions. enum GCState { kNoGCScheduled, - kIdleGCScheduled, kIncrementalMarkingStepPaused, kIncrementalMarkingStepScheduled, kIncrementalMarkingFinalizeScheduled, kPreciseGCScheduled, - kFullGCScheduled, + kForcedGCForTestingScheduled, kPageNavigationGCScheduled, kIncrementalGCScheduled, }; @@ -186,15 +184,6 @@ class PLATFORM_EXPORT ThreadState final return incremental_marking_flag_.MightBeEntered(); } - // Returns true if some thread (possibly the current thread) may be doing - // wrapper tracing. If false is returned, the *current* thread is definitely - // not doing wrapper tracing. See atomic_entry_flag.h for details. - // - // For an exact check, use ThreadState::IsWrapperTracing. - static bool IsAnyWrapperTracing() { - return wrapper_tracing_flag_.MightBeEntered(); - } - static void AttachMainThread(); // Associate ThreadState object with the current thread. After this @@ -229,17 +218,15 @@ class PLATFORM_EXPORT ThreadState final // in the dangling pointer situation. void RunTerminationGC(); - void PerformIdleGC(TimeTicks deadline); void PerformIdleLazySweep(TimeTicks deadline); - void ScheduleIdleGC(); void ScheduleIdleLazySweep(); void SchedulePreciseGC(); void ScheduleIncrementalGC(BlinkGC::GCReason); void ScheduleV8FollowupGCIfNeeded(BlinkGC::V8GCType); void SchedulePageNavigationGCIfNeeded(float estimated_removal_ratio); void SchedulePageNavigationGC(); - void ScheduleFullGC(); + void ScheduleForcedGCForTesting(); void ScheduleGCIfNeeded(); void PostIdleGCTask(); void WillStartV8GC(BlinkGC::V8GCType); @@ -253,9 +240,6 @@ class PLATFORM_EXPORT ThreadState final current_gc_data_.reason == BlinkGC::GCReason::kUnifiedHeapGC; } - void EnableWrapperTracingBarrier(); - void DisableWrapperTracingBarrier(); - // Incremental GC. void ScheduleIncrementalMarkingStep(); void ScheduleIncrementalMarkingFinalize(); @@ -318,9 +302,6 @@ class PLATFORM_EXPORT ThreadState final return in_atomic_pause() && IsSweepingInProgress(); } - bool IsWrapperTracing() const { return wrapper_tracing_; } - void SetWrapperTracing(bool value) { wrapper_tracing_ = value; } - bool IsIncrementalMarking() const { return incremental_marking_; } void SetIncrementalMarking(bool value) { incremental_marking_ = value; } @@ -372,17 +353,12 @@ class PLATFORM_EXPORT ThreadState final Vector<size_t> dead_size; }; - void RegisterTraceDOMWrappers( - v8::Isolate* isolate, - void (*trace_dom_wrappers)(v8::Isolate*, Visitor*), - void (*invalidate_dead_objects_in_wrappers_marking_deque)(v8::Isolate*), - void (*perform_cleanup)(v8::Isolate*)) { + void RegisterTraceDOMWrappers(v8::Isolate* isolate, + void (*trace_dom_wrappers)(v8::Isolate*, + Visitor*)) { isolate_ = isolate; DCHECK(!isolate_ || trace_dom_wrappers); trace_dom_wrappers_ = trace_dom_wrappers; - invalidate_dead_objects_in_wrappers_marking_deque_ = - invalidate_dead_objects_in_wrappers_marking_deque; - perform_cleanup_ = perform_cleanup; } void FreePersistentNode(PersistentRegion*, PersistentNode*); @@ -399,11 +375,16 @@ class PLATFORM_EXPORT ThreadState final v8::Isolate* GetIsolate() const { return isolate_; } + // Use CollectAllGarbageForTesting below for testing! void CollectGarbage(BlinkGC::StackState, BlinkGC::MarkingType, BlinkGC::SweepingType, BlinkGC::GCReason); - void CollectAllGarbage(); + + // Forced garbage collection for testing. + void CollectAllGarbageForTesting( + BlinkGC::StackState stack_state = + BlinkGC::StackState::kNoHeapPointersOnStack); // Register the pre-finalizer for the |self| object. The class T must have // USING_PRE_FINALIZER(). @@ -441,16 +422,13 @@ class PLATFORM_EXPORT ThreadState final MarkingVisitor* CurrentVisitor() { return current_gc_data_.visitor.get(); } - // Implementation for WebRAILModeObserver - void OnRAILModeChanged(v8::RAILMode new_mode) override; + // Implementation for RAILModeObserver + void OnRAILModeChanged(RAILMode new_mode) override; private: // Stores whether some ThreadState is currently in incremental marking. static AtomicEntryFlag incremental_marking_flag_; - // Same semantic as |incremental_marking_flag_|. - static AtomicEntryFlag wrapper_tracing_flag_; - static WTF::ThreadSpecific<ThreadState*>* thread_specific_; // We can't create a static member of type ThreadState here because it will @@ -498,15 +476,14 @@ class PLATFORM_EXPORT ThreadState final bool ShouldVerifyMarking() const; - // shouldScheduleIdleGC and shouldForceConservativeGC - // implement the heuristics that are used to determine when to collect + // ShouldForceConservativeGC + // implements the heuristics that are used to determine when to collect // garbage. // If shouldForceConservativeGC returns true, we force the garbage // collection immediately. Otherwise, if should*GC returns true, we // record that we should garbage collect the next time we return // to the event loop. If both return false, we don't need to // collect garbage at this point. - bool ShouldScheduleIdleGC(); bool ShouldForceConservativeGC(); bool ShouldScheduleIncrementalMarking(); // V8 minor or major GC is likely to drop a lot of references to objects @@ -518,8 +495,6 @@ class PLATFORM_EXPORT ThreadState final // longer necessary due to the navigation. bool ShouldSchedulePageNavigationGC(float estimated_removal_ratio); - void RescheduleIdleGC(); - // Internal helpers to handle memory pressure conditions. // Returns true if memory use is in a near-OOM state @@ -568,7 +543,6 @@ class PLATFORM_EXPORT ThreadState final bool object_resurrection_forbidden_ = false; bool in_atomic_pause_ = false; bool sweep_forbidden_ = false; - bool wrapper_tracing_ = false; bool incremental_marking_ = false; bool should_optimize_for_load_time_ = false; size_t no_allocation_count_ = 0; @@ -589,10 +563,8 @@ class PLATFORM_EXPORT ThreadState final // for an object, by processing the ordered_pre_finalizers_ back-to-front. LinkedHashSet<PreFinalizer> ordered_pre_finalizers_; - v8::Isolate* isolate_; - void (*trace_dom_wrappers_)(v8::Isolate*, Visitor*); - void (*invalidate_dead_objects_in_wrappers_marking_deque_)(v8::Isolate*); - void (*perform_cleanup_)(v8::Isolate*); + v8::Isolate* isolate_ = nullptr; + void (*trace_dom_wrappers_)(v8::Isolate*, Visitor*) = nullptr; #if defined(ADDRESS_SANITIZER) void* asan_fake_stack_; diff --git a/chromium/third_party/blink/renderer/platform/heap/thread_state_scheduling_test.cc b/chromium/third_party/blink/renderer/platform/heap/thread_state_scheduling_test.cc index e1119d56c4d..1cb35b56625 100644 --- a/chromium/third_party/blink/renderer/platform/heap/thread_state_scheduling_test.cc +++ b/chromium/third_party/blink/renderer/platform/heap/thread_state_scheduling_test.cc @@ -25,23 +25,16 @@ class ThreadStateSchedulingTest : public testing::Test { EXPECT_FALSE(state_->IsSweepingInProgress()); } - void StartIncrementalMarkingForIdleGC() { + void StartIncrementalMarking() { RuntimeEnabledFeatures::SetHeapIncrementalMarkingEnabled(true); EXPECT_EQ(ThreadState::kNoGCScheduled, state_->GetGCState()); - state_->ScheduleIdleGC(); - RunIdleGCTask(); + state_->ScheduleIncrementalGC(BlinkGC::GCReason::kForcedGCForTesting); + state_->RunScheduledGC(BlinkGC::kNoHeapPointersOnStack); EXPECT_EQ(ThreadState::kIncrementalMarkingStepScheduled, state_->GetGCState()); EXPECT_TRUE(state_->IsMarkingInProgress()); } - void RunIdleGCTask() { - // Simulate running idle GC task, instead of actually running the posted - // task. - EXPECT_EQ(ThreadState::kIdleGCScheduled, state_->GetGCState()); - state_->PerformIdleGC(TimeTicks::Max()); - } - void StartLazySweepingForPreciseGC() { EXPECT_EQ(ThreadState::kNoGCScheduled, state_->GetGCState()); state_->SchedulePreciseGC(); @@ -66,20 +59,6 @@ class ThreadStateSchedulingTest : public testing::Test { RuntimeEnabledFeatures::Backup features_backup_; }; -TEST_F(ThreadStateSchedulingTest, ScheduleIdleGCAgain) { - ThreadStateSchedulingTest* test = this; - - EXPECT_EQ(ThreadState::kNoGCScheduled, test->state()->GetGCState()); - test->state()->ScheduleIdleGC(); - EXPECT_EQ(ThreadState::kIdleGCScheduled, test->state()->GetGCState()); - - // Calling ScheduleIdleGC() while an idle GC is scheduled will do nothing. - test->state()->ScheduleIdleGC(); - - EXPECT_EQ(ThreadState::kIdleGCScheduled, test->state()->GetGCState()); - EXPECT_EQ(0, test->GCCount()); -} - TEST_F(ThreadStateSchedulingTest, ScheduleIncrementalV8FollowupGCAgain) { ThreadStateSchedulingTest* test = this; @@ -97,35 +76,6 @@ TEST_F(ThreadStateSchedulingTest, ScheduleIncrementalV8FollowupGCAgain) { EXPECT_EQ(0, test->GCCount()); } -TEST_F(ThreadStateSchedulingTest, ScheduleIdleGCWhileIncrementalMarking) { - ThreadStateSchedulingTest* test = this; - - test->StartIncrementalMarkingForIdleGC(); - - EXPECT_TRUE(test->state()->IsMarkingInProgress()); - EXPECT_EQ(ThreadState::kIncrementalMarkingStepScheduled, - test->state()->GetGCState()); - - // Calling ScheduleIdleGC() while an idle GC is scheduled should do nothing. - test->state()->ScheduleIdleGC(); - - EXPECT_TRUE(test->state()->IsMarkingInProgress()); - EXPECT_EQ(ThreadState::kIncrementalMarkingStepScheduled, - test->state()->GetGCState()); -} - -TEST_F(ThreadStateSchedulingTest, ScheduleIdleGCWhileLazySweeping) { - ThreadStateSchedulingTest* test = this; - - test->StartLazySweepingForPreciseGC(); - - test->state()->ScheduleIdleGC(); - - // Scheduling an idle GC should finish lazy sweeping. - EXPECT_FALSE(test->state()->IsSweepingInProgress()); - EXPECT_EQ(ThreadState::kIdleGCScheduled, test->state()->GetGCState()); -} - TEST_F(ThreadStateSchedulingTest, SchedulePreciseGCWhileLazySweeping) { ThreadStateSchedulingTest* test = this; @@ -154,11 +104,8 @@ TEST_F(ThreadStateSchedulingTest, TEST_F(ThreadStateSchedulingTest, SchedulePreciseGCWhileIncrementalMarking) { ThreadStateSchedulingTest* test = this; - - test->StartIncrementalMarkingForIdleGC(); - + test->StartIncrementalMarking(); test->state()->SchedulePreciseGC(); - // Scheduling a precise GC should cancel incremental marking tasks. EXPECT_EQ(ThreadState::kPreciseGCScheduled, test->state()->GetGCState()); @@ -177,30 +124,15 @@ TEST_F(ThreadStateSchedulingTest, SchedulePreciseGCWhileIncrementalMarking) { TEST_F(ThreadStateSchedulingTest, ScheduleIncrementalV8FollowupGCWhileIncrementalMarking) { ThreadStateSchedulingTest* test = this; - - test->StartIncrementalMarkingForIdleGC(); - + test->StartIncrementalMarking(); test->state()->ScheduleIncrementalGC( BlinkGC::GCReason::kIncrementalV8FollowupGC); - - // Scheduling a precise GC should not cancel incremental marking tasks. + // Scheduling another incremental GC should not cancel incremental marking + // tasks. EXPECT_EQ(ThreadState::kIncrementalMarkingStepScheduled, test->state()->GetGCState()); } -TEST_F(ThreadStateSchedulingTest, ScheduleIdleGCWhileGCForbidden) { - ThreadStateSchedulingTest* test = this; - - test->state()->ScheduleIdleGC(); - EXPECT_EQ(ThreadState::kIdleGCScheduled, test->state()->GetGCState()); - - ThreadState::GCForbiddenScope gc_forbidden_scope(test->state()); - test->RunIdleGCTask(); - - // Starting an idle GC while GC is forbidden should reschedule it. - EXPECT_EQ(ThreadState::kIdleGCScheduled, test->state()->GetGCState()); -} - TEST_F(ThreadStateSchedulingTest, ScheduleIncrementalV8FollowupGCWhileGCForbidden) { ThreadStateSchedulingTest* test = this; diff --git a/chromium/third_party/blink/renderer/platform/heap/threading_traits.h b/chromium/third_party/blink/renderer/platform/heap/threading_traits.h index 036118b18b6..832b212b5a2 100644 --- a/chromium/third_party/blink/renderer/platform/heap/threading_traits.h +++ b/chromium/third_party/blink/renderer/platform/heap/threading_traits.h @@ -18,8 +18,6 @@ namespace blink { template <typename T> class SameThreadCheckedMember; -template <typename T> -class TraceWrapperMember; // ThreadAffinity indicates which threads objects can be used on. We // distinguish between objects that can be used on the main thread @@ -92,12 +90,6 @@ struct ThreadingTrait<SameThreadCheckedMember<T>> { }; template <typename T> -struct ThreadingTrait<TraceWrapperMember<T>> { - STATIC_ONLY(ThreadingTrait); - static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity; -}; - -template <typename T> struct ThreadingTrait<WeakMember<T>> { STATIC_ONLY(ThreadingTrait); static const ThreadAffinity kAffinity = ThreadingTrait<T>::kAffinity; diff --git a/chromium/third_party/blink/renderer/platform/heap/trace_traits.h b/chromium/third_party/blink/renderer/platform/heap/trace_traits.h index b362f77b17e..b5e315e3b3e 100644 --- a/chromium/third_party/blink/renderer/platform/heap/trace_traits.h +++ b/chromium/third_party/blink/renderer/platform/heap/trace_traits.h @@ -6,10 +6,8 @@ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_TRACE_TRAITS_H_ #include "base/optional.h" -#include "third_party/blink/renderer/platform/bindings/script_wrappable_visitor.h" #include "third_party/blink/renderer/platform/heap/gc_info.h" #include "third_party/blink/renderer/platform/heap/heap.h" -#include "third_party/blink/renderer/platform/heap/stack_frame_depth.h" #include "third_party/blink/renderer/platform/heap/visitor.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" diff --git a/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.cc b/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.cc index 158d3f8eca5..acb4999607d 100644 --- a/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.cc +++ b/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.cc @@ -55,9 +55,14 @@ void UnifiedHeapController::EnterFinalPause(EmbedderStackState stack_state) { ThreadHeapStatsCollector::kAtomicPhase); thread_state_->EnterAtomicPause(); thread_state_->EnterGCForbiddenScope(); - thread_state_->AtomicPauseMarkPrologue(ToBlinkGCStackState(stack_state), - BlinkGC::kIncrementalMarking, - BlinkGC::GCReason::kUnifiedHeapGC); + { + ThreadHeapStatsCollector::Scope mark_prologue_scope( + thread_state_->Heap().stats_collector(), + ThreadHeapStatsCollector::kUnifiedMarkingAtomicPrologue); + thread_state_->AtomicPauseMarkPrologue(ToBlinkGCStackState(stack_state), + BlinkGC::kIncrementalMarking, + BlinkGC::GCReason::kUnifiedHeapGC); + } } void UnifiedHeapController::TraceEpilogue() { @@ -108,6 +113,9 @@ void UnifiedHeapController::RegisterV8References( bool UnifiedHeapController::AdvanceTracing(double deadline_in_ms) { VLOG(2) << "UnifiedHeapController::AdvanceTracing"; + ThreadHeapStatsCollector::Scope advance_tracing_scope( + thread_state_->Heap().stats_collector(), + ThreadHeapStatsCollector::kUnifiedMarkingStep); if (!thread_state_->in_atomic_pause()) { // V8 calls into embedder tracing from its own marking to ensure @@ -136,14 +144,6 @@ bool UnifiedHeapController::IsRootForNonTracingGCInternal( class_id != WrapperTypeInfo::kObjectClassId) return true; - const bool collect_non_node_wrappers = - RuntimeEnabledFeatures::HeapCollectLiveNonNodeWrappersEnabled(); - - if (!collect_non_node_wrappers && - class_id == WrapperTypeInfo::kObjectClassId) { - return true; - } - const v8::TracedGlobal<v8::Object>& traced = handle.As<v8::Object>(); if (ToWrapperTypeInfo(traced)->IsActiveScriptWrappable() && ToScriptWrappable(traced)->HasPendingActivity()) { diff --git a/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.h b/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.h index 410acf31859..e22350968e8 100644 --- a/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.h +++ b/chromium/third_party/blink/renderer/platform/heap/unified_heap_controller.h @@ -33,11 +33,6 @@ class PLATFORM_EXPORT UnifiedHeapController final DISALLOW_IMPLICIT_CONSTRUCTORS(UnifiedHeapController); public: - // Temporarily expose that logic to allow reuse by - // ScriptWrappableMarkingVisitor. - static bool IsRootForNonTracingGCInternal( - const v8::TracedGlobal<v8::Value>& handle); - explicit UnifiedHeapController(ThreadState*); // v8::EmbedderHeapTracer implementation. @@ -52,6 +47,9 @@ class PLATFORM_EXPORT UnifiedHeapController final ThreadState* thread_state() const { return thread_state_; } private: + static bool IsRootForNonTracingGCInternal( + const v8::TracedGlobal<v8::Value>& handle); + ThreadState* const thread_state_; // Returns whether the Blink heap has been fully processed. diff --git a/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.cc b/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.cc index 2340a92fef5..fada1f99107 100644 --- a/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.cc +++ b/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.cc @@ -11,16 +11,6 @@ namespace blink { -std::unique_ptr<UnifiedHeapMarkingVisitor> UnifiedHeapMarkingVisitor::Create( - ThreadState* thread_state, - MarkingMode mode, - v8::Isolate* isolate) { - DCHECK(thread_state); - DCHECK(isolate); - return std::unique_ptr<UnifiedHeapMarkingVisitor>( - new UnifiedHeapMarkingVisitor(thread_state, mode, isolate)); -} - UnifiedHeapMarkingVisitor::UnifiedHeapMarkingVisitor(ThreadState* thread_state, MarkingMode mode, v8::Isolate* isolate) diff --git a/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h b/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h index f14c87294dd..17c4b85afdd 100644 --- a/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h +++ b/chromium/third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h @@ -21,9 +21,8 @@ struct WrapperTypeInfo; // methods that allow for announcing reachable objects to V8. class PLATFORM_EXPORT UnifiedHeapMarkingVisitor final : public MarkingVisitor { public: - static std::unique_ptr<UnifiedHeapMarkingVisitor> Create(ThreadState*, - MarkingMode, - v8::Isolate*); + UnifiedHeapMarkingVisitor(ThreadState*, MarkingMode, v8::Isolate*); + // Write barriers for annotating a write during incremental marking. static void WriteBarrier(const TraceWrapperV8Reference<v8::Value>&); static void WriteBarrier(v8::Isolate*, const WrapperTypeInfo*, void*); @@ -34,8 +33,6 @@ class PLATFORM_EXPORT UnifiedHeapMarkingVisitor final : public MarkingVisitor { void Visit(const TraceWrapperV8Reference<v8::Value>&) final; private: - UnifiedHeapMarkingVisitor(ThreadState*, MarkingMode, v8::Isolate*); - v8::Isolate* const isolate_; v8::EmbedderHeapTracer* const controller_; diff --git a/chromium/third_party/blink/renderer/platform/heap/visitor.h b/chromium/third_party/blink/renderer/platform/heap/visitor.h index 68ef1812d5c..fd95a7ce5f7 100644 --- a/chromium/third_party/blink/renderer/platform/heap/visitor.h +++ b/chromium/third_party/blink/renderer/platform/heap/visitor.h @@ -55,8 +55,6 @@ class Visitor; template <typename T> class SameThreadCheckedMember; template <typename T> -class TraceWrapperMember; -template <typename T> class TraceWrapperV8Reference; // The TraceMethodDelegate is used to convert a trace method for type T to a @@ -205,29 +203,6 @@ class PLATFORM_EXPORT Visitor { // Cross-component tracing interface. - template <typename T> - void Trace(const TraceWrapperMember<T>& t) { - DCHECK(!t.IsHashTableDeletedValue()); - TraceWithWrappers(t.Get()); - } - - template <typename T> - void TraceWithWrappers(T* t) { - static_assert(sizeof(T), "T must be fully defined"); - static_assert(IsGarbageCollectedType<T>::value, - "T needs to be a garbage collected object"); - if (!t) - return; - - // Dispatch two both, the TraceDescritpor and the TraceWrapperDescriptor, - // versions of the visitor. This way the wrapper-tracing world can ignore - // the TraceDescriptor versions. - Visit(const_cast<void*>(reinterpret_cast<const void*>(t)), - TraceDescriptorFor(t)); - VisitWithWrappers(const_cast<void*>(reinterpret_cast<const void*>(t)), - TraceDescriptorFor(t)); - } - template <typename V8Type> void Trace(const TraceWrapperV8Reference<V8Type>& v8reference) { Visit(v8reference.template Cast<v8::Value>()); @@ -237,9 +212,6 @@ class PLATFORM_EXPORT Visitor { // Visits an object through a strong reference. virtual void Visit(void*, TraceDescriptor) = 0; - // Subgraph of objects that are interested in wrappers. Note that the same - // object is also passed to Visit(void*, TraceDescriptor). - virtual void VisitWithWrappers(void*, TraceDescriptor) = 0; // Visits an object through a weak reference. virtual void VisitWeak(void*, void**, TraceDescriptor, WeakCallback) = 0; |