From: mstarzinger Date: Tue, 29 Sep 2015 16:59:01 +0000 (-0700) Subject: [heap] No leakage of incremental-marking.h outside of heap. X-Git-Tag: upstream/4.7.83~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddafe2c4940ae20a7c925047d27b54be234cada4;p=platform%2Fupstream%2Fv8.git [heap] No leakage of incremental-marking.h outside of heap. This prevents the internal incremental-marking.h to be usable outisde of the "heap" directory. The logic inside that component is only useful within the GC and is now properly encapsulated. R=hpayer@chromium.org Review URL: https://codereview.chromium.org/1374203002 Cr-Commit-Position: refs/heads/master@{#31010} --- diff --git a/include/v8.h b/include/v8.h index e19daee15..395354341 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5919,7 +5919,7 @@ class V8_EXPORT Isolate { void SetObjectGroupId(internal::Object** object, UniqueId id); void SetReferenceFromGroup(UniqueId id, internal::Object** object); void SetReference(internal::Object** parent, internal::Object** child); - void CollectAllGarbage(const char* gc_reason); + void ReportExternalAllocationLimitReached(); }; class V8_EXPORT StartupData { @@ -8170,7 +8170,7 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( if (change_in_bytes > 0 && amount - *amount_of_external_allocated_memory_at_last_global_gc > I::kExternalAllocationLimit) { - CollectAllGarbage("external memory allocation limit reached."); + ReportExternalAllocationLimitReached(); } *amount_of_external_allocated_memory = amount; return *amount_of_external_allocated_memory; diff --git a/src/api.cc b/src/api.cc index 0b99743a9..dbe7670b4 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6837,32 +6837,11 @@ Local v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) { } -void Isolate::CollectAllGarbage(const char* gc_reason) { +void Isolate::ReportExternalAllocationLimitReached() { i::Heap* heap = reinterpret_cast(this)->heap(); DCHECK_EQ(heap->gc_state(), i::Heap::NOT_IN_GC); - if (heap->incremental_marking()->IsStopped()) { - if (heap->incremental_marking()->CanBeActivated()) { - heap->StartIncrementalMarking( - i::Heap::kNoGCFlags, - kGCCallbackFlagSynchronousPhantomCallbackProcessing, gc_reason); - } else { - heap->CollectAllGarbage( - i::Heap::kNoGCFlags, gc_reason, - kGCCallbackFlagSynchronousPhantomCallbackProcessing); - } - } else { - // Incremental marking is turned on an has already been started. - - // TODO(mlippautz): Compute the time slice for incremental marking based on - // memory pressure. - double deadline = heap->MonotonicallyIncreasingTimeInMs() + - i::FLAG_external_allocation_limit_incremental_time; - heap->AdvanceIncrementalMarking( - 0, deadline, i::IncrementalMarking::StepActions( - i::IncrementalMarking::GC_VIA_STACK_GUARD, - i::IncrementalMarking::FORCE_MARKING, - i::IncrementalMarking::FORCE_COMPLETION)); - } + heap->ReportExternalMemoryPressure( + "external memory allocation limit reached."); } diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 83a1cb16a..2b072f302 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -124,7 +124,7 @@ Heap::Heap() scavenge_collector_(nullptr), mark_compact_collector_(nullptr), store_buffer_(this), - incremental_marking_(this), + incremental_marking_(nullptr), gc_idle_time_handler_(nullptr), memory_reducer_(nullptr), object_stats_(nullptr), @@ -865,6 +865,32 @@ void Heap::CollectAllAvailableGarbage(const char* gc_reason) { } +void Heap::ReportExternalMemoryPressure(const char* gc_reason) { + if (incremental_marking()->IsStopped()) { + if (incremental_marking()->CanBeActivated()) { + StartIncrementalMarking( + i::Heap::kNoGCFlags, + kGCCallbackFlagSynchronousPhantomCallbackProcessing, gc_reason); + } else { + CollectAllGarbage(i::Heap::kNoGCFlags, gc_reason, + kGCCallbackFlagSynchronousPhantomCallbackProcessing); + } + } else { + // Incremental marking is turned on an has already been started. + + // TODO(mlippautz): Compute the time slice for incremental marking based on + // memory pressure. + double deadline = MonotonicallyIncreasingTimeInMs() + + FLAG_external_allocation_limit_incremental_time; + incremental_marking()->AdvanceIncrementalMarking( + 0, deadline, + IncrementalMarking::StepActions(IncrementalMarking::GC_VIA_STACK_GUARD, + IncrementalMarking::FORCE_MARKING, + IncrementalMarking::FORCE_COMPLETION)); + } +} + + void Heap::EnsureFillerObjectAtTop() { // There may be an allocation memento behind every object in new space. // If we evacuate a not full new space or if we are on the last page of @@ -4058,32 +4084,6 @@ GCIdleTimeHeapState Heap::ComputeHeapState() { } -double Heap::AdvanceIncrementalMarking( - intptr_t step_size_in_bytes, double deadline_in_ms, - IncrementalMarking::StepActions step_actions) { - DCHECK(!incremental_marking()->IsStopped()); - - if (step_size_in_bytes == 0) { - step_size_in_bytes = GCIdleTimeHandler::EstimateMarkingStepSize( - static_cast(GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs), - static_cast( - tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond())); - } - - double remaining_time_in_ms = 0.0; - do { - incremental_marking()->Step( - step_size_in_bytes, step_actions.completion_action, - step_actions.force_marking, step_actions.force_completion); - remaining_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs(); - } while (remaining_time_in_ms >= - 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && - !incremental_marking()->IsComplete() && - !mark_compact_collector()->marking_deque()->IsEmpty()); - return remaining_time_in_ms; -} - - bool Heap::PerformIdleTimeAction(GCIdleTimeAction action, GCIdleTimeHeapState heap_state, double deadline_in_ms) { @@ -4981,6 +4981,9 @@ bool Heap::SetUp() { if (!isolate_->memory_allocator()->SetUp(MaxReserved(), MaxExecutableSize())) return false; + // Initialize incremental marking. + incremental_marking_ = new IncrementalMarking(this); + // Set up new space. if (!new_space_.SetUp(reserved_semispace_size_, max_semi_space_size_)) { return false; @@ -5160,6 +5163,9 @@ void Heap::TearDown() { mark_compact_collector_ = nullptr; } + delete incremental_marking_; + incremental_marking_ = nullptr; + delete gc_idle_time_handler_; gc_idle_time_handler_ = nullptr; diff --git a/src/heap/heap.h b/src/heap/heap.h index 410b6499b..0e427de1c 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -14,8 +14,7 @@ #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" +// TODO(mstarzinger): Two more includes to kill! #include "src/heap/spaces.h" #include "src/heap/store-buffer.h" #include "src/list.h" @@ -1215,6 +1214,10 @@ class Heap { // Last hope GC, should try to squeeze as much as possible. void CollectAllAvailableGarbage(const char* gc_reason = NULL); + // Reports and external memory pressure event, either performs a major GC or + // completes incremental marking in order to free external resources. + void ReportExternalMemoryPressure(const char* gc_reason = NULL); + // Invoked when GC was requested via the stack guard. void HandleGCRequest(); @@ -1267,20 +1270,11 @@ class Heap { GCCallbackFlags::kNoGCCallbackFlags, const char* reason = nullptr); - // Performs incremental marking steps of step_size_in_bytes as long as - // deadline_ins_ms is not reached. step_size_in_bytes can be 0 to compute - // an estimate increment. Returns the remaining time that cannot be used - // for incremental marking anymore because a single step would exceed the - // deadline. - double AdvanceIncrementalMarking( - intptr_t step_size_in_bytes, double deadline_in_ms, - IncrementalMarking::StepActions step_actions); - void FinalizeIncrementalMarkingIfComplete(const char* comment); bool TryFinalizeIdleIncrementalMarking(double idle_time_in_ms); - IncrementalMarking* incremental_marking() { return &incremental_marking_; } + IncrementalMarking* incremental_marking() { return incremental_marking_; } // =========================================================================== // External string table API. ================================================ @@ -2270,7 +2264,7 @@ class Heap { StoreBuffer store_buffer_; - IncrementalMarking incremental_marking_; + IncrementalMarking* incremental_marking_; GCIdleTimeHandler* gc_idle_time_handler_; diff --git a/src/heap/incremental-marking-job.cc b/src/heap/incremental-marking-job.cc index 308d1b9a2..43e8b7628 100644 --- a/src/heap/incremental-marking-job.cc +++ b/src/heap/incremental-marking-job.cc @@ -77,8 +77,9 @@ IncrementalMarkingJob::IdleTask::Progress IncrementalMarkingJob::IdleTask::Step( } return kMoreWork; } - const double remaining_idle_time_in_ms = heap->AdvanceIncrementalMarking( - 0, deadline_in_ms, IncrementalMarking::IdleStepActions()); + const double remaining_idle_time_in_ms = + incremental_marking->AdvanceIncrementalMarking( + 0, deadline_in_ms, IncrementalMarking::IdleStepActions()); if (remaining_idle_time_in_ms > 0.0) { heap->TryFinalizeIdleIncrementalMarking(remaining_idle_time_in_ms); } @@ -115,7 +116,7 @@ void IncrementalMarkingJob::DelayedTask::Step(Heap* heap) { const int kIncrementalMarkingDelayMs = 50; double deadline = heap->MonotonicallyIncreasingTimeInMs() + kIncrementalMarkingDelayMs; - heap->AdvanceIncrementalMarking( + heap->incremental_marking()->AdvanceIncrementalMarking( 0, deadline, i::IncrementalMarking::StepActions( i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, i::IncrementalMarking::FORCE_MARKING, diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 39ee846f3..cbc26516b 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -7,6 +7,7 @@ #include "src/code-stubs.h" #include "src/compilation-cache.h" #include "src/conversions.h" +#include "src/heap/gc-idle-time-handler.h" #include "src/heap/gc-tracer.h" #include "src/heap/mark-compact-inl.h" #include "src/heap/objects-visiting.h" @@ -815,6 +816,34 @@ void IncrementalMarking::Epilogue() { } +double IncrementalMarking::AdvanceIncrementalMarking( + intptr_t step_size_in_bytes, double deadline_in_ms, + IncrementalMarking::StepActions step_actions) { + DCHECK(!IsStopped()); + + if (step_size_in_bytes == 0) { + step_size_in_bytes = GCIdleTimeHandler::EstimateMarkingStepSize( + static_cast(GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs), + static_cast( + heap() + ->tracer() + ->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond())); + } + + double remaining_time_in_ms = 0.0; + do { + Step(step_size_in_bytes, step_actions.completion_action, + step_actions.force_marking, step_actions.force_completion); + remaining_time_in_ms = + deadline_in_ms - heap()->MonotonicallyIncreasingTimeInMs(); + } while (remaining_time_in_ms >= + 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && + !IsComplete() && + !heap()->mark_compact_collector()->marking_deque()->IsEmpty()); + return remaining_time_in_ms; +} + + void IncrementalMarking::OldSpaceStep(intptr_t allocated) { if (IsStopped() && ShouldActivateEvenWithoutIdleNotification()) { heap()->StartIncrementalMarking(Heap::kNoGCFlags, kNoGCCallbackFlags, diff --git a/src/heap/incremental-marking.h b/src/heap/incremental-marking.h index fb6e5cf6a..010392875 100644 --- a/src/heap/incremental-marking.h +++ b/src/heap/incremental-marking.h @@ -103,6 +103,15 @@ class IncrementalMarking { void Epilogue(); + // Performs incremental marking steps of step_size_in_bytes as long as + // deadline_ins_ms is not reached. step_size_in_bytes can be 0 to compute + // an estimate increment. Returns the remaining time that cannot be used + // for incremental marking anymore because a single step would exceed the + // deadline. + double AdvanceIncrementalMarking(intptr_t step_size_in_bytes, + double deadline_in_ms, + StepActions step_actions); + // It's hard to know how much work the incremental marker should do to make // progress in the face of the mutator creating new work for it. We start // of at a moderate rate of work and gradually increase the speed of the diff --git a/src/heap/memory-reducer.cc b/src/heap/memory-reducer.cc index 115e376f2..45d6bd3d7 100644 --- a/src/heap/memory-reducer.cc +++ b/src/heap/memory-reducer.cc @@ -67,7 +67,7 @@ void MemoryReducer::NotifyTimer(const Event& event) { const int kIncrementalMarkingDelayMs = 500; double deadline = heap()->MonotonicallyIncreasingTimeInMs() + kIncrementalMarkingDelayMs; - heap()->AdvanceIncrementalMarking( + heap()->incremental_marking()->AdvanceIncrementalMarking( 0, deadline, i::IncrementalMarking::StepActions( i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, i::IncrementalMarking::FORCE_MARKING, diff --git a/src/heap/store-buffer.cc b/src/heap/store-buffer.cc index 1c673dacc..2ed9deccf 100644 --- a/src/heap/store-buffer.cc +++ b/src/heap/store-buffer.cc @@ -7,6 +7,7 @@ #include #include "src/counters.h" +#include "src/heap/incremental-marking.h" #include "src/heap/store-buffer-inl.h" #include "src/isolate.h" #include "src/objects-inl.h" diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 6eee9ffbc..add16ad9c 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -4596,8 +4596,8 @@ TEST(LargeObjectSlotRecording) { // Start incremental marking to active write barrier. SimulateIncrementalMarking(heap, false); - heap->AdvanceIncrementalMarking(10000000, 10000000, - IncrementalMarking::IdleStepActions()); + heap->incremental_marking()->AdvanceIncrementalMarking( + 10000000, 10000000, IncrementalMarking::IdleStepActions()); // Create references from the large object to the object on the evacuation // candidate.