From 4f55b83012247148e7040771bdcfccaea352201a Mon Sep 17 00:00:00 2001 From: mstarzinger Date: Mon, 28 Sep 2015 01:04:11 -0700 Subject: [PATCH] [heap] No leakage of mark-compact.h outside of heap. R=hpayer@chromium.org Review URL: https://codereview.chromium.org/1366183003 Cr-Commit-Position: refs/heads/master@{#30961} --- src/heap/heap.cc | 37 ++++++++++++++++++++++--------------- src/heap/heap.h | 8 +++++--- src/heap/incremental-marking-inl.h | 1 + src/heap/incremental-marking.cc | 2 +- src/heap/incremental-marking.h | 9 ++++++--- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 396ba4f..302368f 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -123,7 +123,7 @@ Heap::Heap() last_idle_notification_time_(0.0), last_gc_time_(0.0), scavenge_collector_(nullptr), - mark_compact_collector_(this), + mark_compact_collector_(nullptr), store_buffer_(this), incremental_marking_(this), gc_idle_time_handler_(nullptr), @@ -916,7 +916,8 @@ bool Heap::CollectGarbage(GarbageCollector collector, const char* gc_reason, incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, IncrementalMarking::NO_GC_VIA_STACK_GUARD); if (!incremental_marking()->IsComplete() && - !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { + !mark_compact_collector()->marking_deque_.IsEmpty() && + !FLAG_gc_global) { if (FLAG_trace_incremental_marking) { PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); } @@ -1257,8 +1258,8 @@ bool Heap::PerformGarbageCollection( // We finished a marking cycle. We can uncommit the marking deque until // we start marking again. - mark_compact_collector_.marking_deque()->Uninitialize(); - mark_compact_collector_.EnsureMarkingDequeIsCommitted( + mark_compact_collector()->marking_deque()->Uninitialize(); + mark_compact_collector()->EnsureMarkingDequeIsCommitted( MarkCompactCollector::kMinMarkingDequeSize); } @@ -1352,13 +1353,13 @@ void Heap::MarkCompact() { uint64_t size_of_objects_before_gc = SizeOfObjects(); - mark_compact_collector_.Prepare(); + mark_compact_collector()->Prepare(); ms_count_++; MarkCompactPrologue(); - mark_compact_collector_.CollectGarbage(); + mark_compact_collector()->CollectGarbage(); LOG(isolate_, ResourceEvent("markcompact", "end")); @@ -4064,10 +4065,10 @@ void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { if (FLAG_overapproximate_weak_closure && incremental_marking()->IsMarking() && (incremental_marking()->IsReadyToOverApproximateWeakClosure() || (!incremental_marking()->weak_closure_was_overapproximated() && - mark_compact_collector_.marking_deque()->IsEmpty()))) { + mark_compact_collector()->marking_deque()->IsEmpty()))) { OverApproximateWeakClosure(comment); } else if (incremental_marking()->IsComplete() || - (mark_compact_collector_.marking_deque()->IsEmpty())) { + (mark_compact_collector()->marking_deque()->IsEmpty())) { CollectAllGarbage(current_gc_flags_, comment); } } @@ -4081,14 +4082,14 @@ bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { if (FLAG_overapproximate_weak_closure && (incremental_marking()->IsReadyToOverApproximateWeakClosure() || (!incremental_marking()->weak_closure_was_overapproximated() && - mark_compact_collector_.marking_deque()->IsEmpty() && + mark_compact_collector()->marking_deque()->IsEmpty() && gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( static_cast(idle_time_in_ms))))) { OverApproximateWeakClosure( "Idle notification: overapproximate weak closure"); return true; } else if (incremental_marking()->IsComplete() || - (mark_compact_collector_.marking_deque()->IsEmpty() && + (mark_compact_collector()->marking_deque()->IsEmpty() && gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( static_cast(idle_time_in_ms), size_of_objects, final_incremental_mark_compact_speed_in_bytes_per_ms))) { @@ -4133,7 +4134,7 @@ double Heap::AdvanceIncrementalMarking( } while (remaining_time_in_ms >= 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && !incremental_marking()->IsComplete() && - !mark_compact_collector_.marking_deque()->IsEmpty()); + !mark_compact_collector()->marking_deque()->IsEmpty()); return remaining_time_in_ms; } @@ -4437,9 +4438,9 @@ void Heap::Verify() { lo_space_->Verify(); - mark_compact_collector_.VerifyWeakEmbeddedObjectsInCode(); + mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode(); if (FLAG_omit_map_checks_for_leaf_maps) { - mark_compact_collector_.VerifyOmittedMapChecks(); + mark_compact_collector()->VerifyOmittedMapChecks(); } } #endif @@ -5086,6 +5087,8 @@ bool Heap::SetUp() { scavenge_collector_ = new Scavenger(this); + mark_compact_collector_ = new MarkCompactCollector(this); + gc_idle_time_handler_ = new GCIdleTimeHandler(); memory_reducer_ = new MemoryReducer(this); @@ -5206,6 +5209,12 @@ void Heap::TearDown() { delete scavenge_collector_; scavenge_collector_ = nullptr; + if (mark_compact_collector_ != nullptr) { + mark_compact_collector_->TearDown(); + delete mark_compact_collector_; + mark_compact_collector_ = nullptr; + } + delete gc_idle_time_handler_; gc_idle_time_handler_ = nullptr; @@ -5230,8 +5239,6 @@ void Heap::TearDown() { external_string_table_.TearDown(); - mark_compact_collector()->TearDown(); - delete tracer_; tracer_ = nullptr; diff --git a/src/heap/heap.h b/src/heap/heap.h index 5d01e2a..10d2746 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -8,12 +8,14 @@ #include #include +// Clients of this interface shouldn't depend on lots of heap internals. +// Do not include anything from src/heap here! #include "src/allocation.h" #include "src/assert-scope.h" #include "src/atomic-utils.h" #include "src/globals.h" +// TODO(mstarzinger): Three more includes to kill! #include "src/heap/incremental-marking.h" -#include "src/heap/mark-compact.h" #include "src/heap/spaces.h" #include "src/heap/store-buffer.h" #include "src/list.h" @@ -1097,7 +1099,7 @@ class Heap { inline Isolate* isolate(); MarkCompactCollector* mark_compact_collector() { - return &mark_compact_collector_; + return mark_compact_collector_; } // =========================================================================== @@ -2266,7 +2268,7 @@ class Heap { Scavenger* scavenge_collector_; - MarkCompactCollector mark_compact_collector_; + MarkCompactCollector* mark_compact_collector_; StoreBuffer store_buffer_; diff --git a/src/heap/incremental-marking-inl.h b/src/heap/incremental-marking-inl.h index fabf59d..5988426 100644 --- a/src/heap/incremental-marking-inl.h +++ b/src/heap/incremental-marking-inl.h @@ -6,6 +6,7 @@ #define V8_HEAP_INCREMENTAL_MARKING_INL_H_ #include "src/heap/incremental-marking.h" +#include "src/heap/mark-compact.h" namespace v8 { namespace internal { diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 4b2fbc0..51b91ba 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -305,7 +305,7 @@ void IncrementalMarking::SetOldSpacePageFlags(MemoryChunk* chunk, } -void IncrementalMarking::SetNewSpacePageFlags(NewSpacePage* chunk, +void IncrementalMarking::SetNewSpacePageFlags(MemoryChunk* chunk, bool is_marking) { chunk->SetFlag(MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING); if (is_marking) { diff --git a/src/heap/incremental-marking.h b/src/heap/incremental-marking.h index e0b449a..fb6e5cf 100644 --- a/src/heap/incremental-marking.h +++ b/src/heap/incremental-marking.h @@ -8,12 +8,15 @@ #include "src/cancelable-task.h" #include "src/execution.h" #include "src/heap/incremental-marking-job.h" -#include "src/heap/mark-compact.h" #include "src/objects.h" namespace v8 { namespace internal { +// Forward declarations. +class MarkBit; +class PagedSpace; + class IncrementalMarking { public: enum State { STOPPED, SWEEPING, MARKING, COMPLETE }; @@ -172,7 +175,7 @@ class IncrementalMarking { SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting()); } - inline void SetNewSpacePageFlags(NewSpacePage* chunk) { + inline void SetNewSpacePageFlags(MemoryChunk* chunk) { SetNewSpacePageFlags(chunk, IsMarking()); } @@ -222,7 +225,7 @@ class IncrementalMarking { static void SetOldSpacePageFlags(MemoryChunk* chunk, bool is_marking, bool is_compacting); - static void SetNewSpacePageFlags(NewSpacePage* chunk, bool is_marking); + static void SetNewSpacePageFlags(MemoryChunk* chunk, bool is_marking); INLINE(void ProcessMarkingDeque()); -- 2.7.4