Commit ddafe2c4 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[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}
parent 8dfe1855
......@@ -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;
......
......@@ -6837,32 +6837,11 @@ Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
}
void Isolate::CollectAllGarbage(const char* gc_reason) {
void Isolate::ReportExternalAllocationLimitReached() {
i::Heap* heap = reinterpret_cast<i::Isolate*>(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.");
}
......
......@@ -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<size_t>(GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs),
static_cast<size_t>(
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;
......
......@@ -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_;
......
......@@ -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,
......
......@@ -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<size_t>(GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs),
static_cast<size_t>(
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,
......
......@@ -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
......
......@@ -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,
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#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"
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment