Commit adcd4a69 authored by Michal Majewski's avatar Michal Majewski Committed by Commit Bot

Function to add allocation observers to all spaces.

Bug: v8:6972
Change-Id: I3f5f2d5ebba3eaddd9e5390b7f299cdbc192ba6e
Reviewed-on: https://chromium-review.googlesource.com/801714Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michał Majewski <majeski@google.com>
Cr-Commit-Position: refs/heads/master@{#49823}
parent 77021584
......@@ -712,6 +712,34 @@ void Heap::MergeAllocationSitePretenuringFeedback(
}
}
void Heap::AddAllocationObserversToAllSpaces(
AllocationObserver* observer, AllocationObserver* new_space_observer) {
DCHECK(observer && new_space_observer);
for (SpaceIterator it(this); it.has_next();) {
Space* space = it.next();
if (space == new_space()) {
space->AddAllocationObserver(new_space_observer);
} else {
space->AddAllocationObserver(observer);
}
}
}
void Heap::RemoveAllocationObserversFromAllSpaces(
AllocationObserver* observer, AllocationObserver* new_space_observer) {
DCHECK(observer && new_space_observer);
for (SpaceIterator it(this); it.has_next();) {
Space* space = it.next();
if (space == new_space()) {
space->RemoveAllocationObserver(new_space_observer);
} else {
space->RemoveAllocationObserver(observer);
}
}
}
class Heap::SkipStoreBufferScope {
public:
explicit SkipStoreBufferScope(StoreBuffer* store_buffer)
......
......@@ -1571,6 +1571,19 @@ class Heap {
void MergeAllocationSitePretenuringFeedback(
const PretenuringFeedbackMap& local_pretenuring_feedback);
// ===========================================================================
// Allocation tracking. ======================================================
// ===========================================================================
// Adds {new_space_observer} to new space and {observer} to any other space.
void AddAllocationObserversToAllSpaces(
AllocationObserver* observer, AllocationObserver* new_space_observer);
// Removes {new_space_observer} from new space and {observer} from any other
// space.
void RemoveAllocationObserversFromAllSpaces(
AllocationObserver* observer, AllocationObserver* new_space_observer);
// ===========================================================================
// Retaining path tracking. ==================================================
// ===========================================================================
......
......@@ -364,16 +364,8 @@ void IncrementalMarking::Start(GarbageCollectionReason gc_reason) {
SetState(SWEEPING);
}
SpaceIterator it(heap_);
while (it.has_next()) {
Space* space = it.next();
if (space == heap_->new_space()) {
space->AddAllocationObserver(&new_generation_observer_);
} else {
space->AddAllocationObserver(&old_generation_observer_);
}
}
heap_->AddAllocationObserversToAllSpaces(&old_generation_observer_,
&new_generation_observer_);
incremental_marking_job()->Start(heap_);
}
......
......@@ -66,24 +66,15 @@ SamplingHeapProfiler::SamplingHeapProfiler(
rate_(rate),
flags_(flags) {
CHECK_GT(rate_, 0u);
heap->new_space()->AddAllocationObserver(new_space_observer_.get());
AllSpaces spaces(heap);
for (Space* space = spaces.next(); space != nullptr; space = spaces.next()) {
if (space != heap->new_space()) {
space->AddAllocationObserver(other_spaces_observer_.get());
}
}
heap_->AddAllocationObserversToAllSpaces(other_spaces_observer_.get(),
new_space_observer_.get());
}
SamplingHeapProfiler::~SamplingHeapProfiler() {
heap_->new_space()->RemoveAllocationObserver(new_space_observer_.get());
AllSpaces spaces(heap_);
for (Space* space = spaces.next(); space != nullptr; space = spaces.next()) {
if (space != heap_->new_space()) {
space->RemoveAllocationObserver(other_spaces_observer_.get());
}
}
heap_->RemoveAllocationObserversFromAllSpaces(other_spaces_observer_.get(),
new_space_observer_.get());
for (auto sample : samples_) {
delete sample;
......
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