Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Unified Diff: src/heap/spaces.cc

Issue 1625753002: Allocation sampling for paged/lo spaces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: "Rebase" Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/heap/spaces.cc
diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc
index 31354cc17cea8ce7e0635e5ff97590d19b6b57bb..a8f098cfee8fab797188484b1f0cf65ea13d2b32 100644
--- a/src/heap/spaces.cc
+++ b/src/heap/spaces.cc
@@ -70,6 +70,22 @@ bool HeapObjectIterator::AdvanceToNextPage() {
return true;
}
+PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap)
+ : heap_(heap) {
+ heap_->new_space()->PauseAllocationObservers();
Hannes Payer (out of office) 2016/02/08 10:13:48 Use the AllSpaces iterator.
mattloring 2016/02/09 20:20:04 Done.
+ heap_->old_space()->PauseAllocationObservers();
+ heap_->code_space()->PauseAllocationObservers();
+ heap_->map_space()->PauseAllocationObservers();
+ heap_->lo_space()->PauseAllocationObservers();
+}
+
+PauseAllocationObserversScope::~PauseAllocationObserversScope() {
Hannes Payer (out of office) 2016/02/08 10:13:48 Use the AllSpaces iterator.
mattloring 2016/02/09 20:20:04 Done.
+ heap_->new_space()->ResumeAllocationObservers();
+ heap_->old_space()->ResumeAllocationObservers();
+ heap_->code_space()->ResumeAllocationObservers();
+ heap_->map_space()->ResumeAllocationObservers();
+ heap_->lo_space()->ResumeAllocationObservers();
+}
// -----------------------------------------------------------------------------
// CodeRange
@@ -948,6 +964,14 @@ STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) ==
STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) ==
ObjectSpace::kObjectSpaceMapSpace);
+void Space::AllocationStep(Address soon_object, int size) {
+ if (!allocation_observers_paused_) {
+ for (int i = 0; i < allocation_observers_->length(); ++i) {
+ AllocationObserver* o = (*allocation_observers_)[i];
+ o->AllocationStep(size, soon_object, size);
+ }
+ }
+}
PagedSpace::PagedSpace(Heap* heap, AllocationSpace space,
Executability executable)
@@ -1509,8 +1533,7 @@ void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) {
Address high = to_space_.page_high();
Address new_top = allocation_info_.top() + size_in_bytes;
allocation_info_.set_limit(Min(new_top, high));
- } else if (inline_allocation_observers_paused_ ||
- top_on_previous_step_ == 0) {
+ } else if (allocation_observers_paused_ || top_on_previous_step_ == 0) {
// Normal limit is the end of the current page.
allocation_info_.set_limit(to_space_.page_high());
} else {
@@ -1591,9 +1614,9 @@ bool NewSpace::EnsureAllocation(int size_in_bytes,
void NewSpace::StartNextInlineAllocationStep() {
- if (!inline_allocation_observers_paused_) {
+ if (!allocation_observers_paused_) {
top_on_previous_step_ =
- inline_allocation_observers_.length() ? allocation_info_.top() : 0;
+ allocation_observers_->length() ? allocation_info_.top() : 0;
UpdateInlineAllocationLimit(0);
}
}
@@ -1601,44 +1624,36 @@ void NewSpace::StartNextInlineAllocationStep() {
intptr_t NewSpace::GetNextInlineAllocationStepSize() {
intptr_t next_step = 0;
- for (int i = 0; i < inline_allocation_observers_.length(); ++i) {
- InlineAllocationObserver* o = inline_allocation_observers_[i];
+ for (int i = 0; i < allocation_observers_->length(); ++i) {
+ AllocationObserver* o = (*allocation_observers_)[i];
next_step = next_step ? Min(next_step, o->bytes_to_next_step())
: o->bytes_to_next_step();
}
- DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0);
+ DCHECK(allocation_observers_->length() == 0 || next_step != 0);
return next_step;
}
-
-void NewSpace::AddInlineAllocationObserver(InlineAllocationObserver* observer) {
- inline_allocation_observers_.Add(observer);
+void NewSpace::AddAllocationObserver(AllocationObserver* observer) {
+ Space::AddAllocationObserver(observer);
StartNextInlineAllocationStep();
}
-
-void NewSpace::RemoveInlineAllocationObserver(
- InlineAllocationObserver* observer) {
- bool removed = inline_allocation_observers_.RemoveElement(observer);
- // Only used in assertion. Suppress unused variable warning.
- static_cast<void>(removed);
- DCHECK(removed);
+void NewSpace::RemoveAllocationObserver(AllocationObserver* observer) {
+ Space::RemoveAllocationObserver(observer);
StartNextInlineAllocationStep();
}
-
-void NewSpace::PauseInlineAllocationObservers() {
+void NewSpace::PauseAllocationObservers() {
// Do a step to account for memory allocated so far.
InlineAllocationStep(top(), top(), nullptr, 0);
- inline_allocation_observers_paused_ = true;
+ Space::PauseAllocationObservers();
top_on_previous_step_ = 0;
UpdateInlineAllocationLimit(0);
}
-
-void NewSpace::ResumeInlineAllocationObservers() {
+void NewSpace::ResumeAllocationObservers() {
DCHECK(top_on_previous_step_ == 0);
- inline_allocation_observers_paused_ = false;
+ Space::ResumeAllocationObservers();
StartNextInlineAllocationStep();
}
@@ -1647,9 +1662,9 @@ void NewSpace::InlineAllocationStep(Address top, Address new_top,
Address soon_object, size_t size) {
if (top_on_previous_step_) {
int bytes_allocated = static_cast<int>(top - top_on_previous_step_);
- for (int i = 0; i < inline_allocation_observers_.length(); ++i) {
- inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated,
- soon_object, size);
+ for (int i = 0; i < allocation_observers_->length(); ++i) {
+ (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object,
+ size);
}
top_on_previous_step_ = new_top;
}
@@ -2550,6 +2565,7 @@ HeapObject* FreeList::Allocate(int size_in_bytes) {
int new_node_size = 0;
FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size);
if (new_node == nullptr) return nullptr;
+ owner_->AllocationStep(new_node->address(), size_in_bytes);
int bytes_left = new_node_size - size_in_bytes;
DCHECK(bytes_left >= 0);
@@ -3061,6 +3077,7 @@ AllocationResult LargeObjectSpace::AllocateRaw(int object_size,
}
heap()->incremental_marking()->OldSpaceStep(object_size);
+ AllocationStep(object->address(), object_size);
return object;
}

Powered by Google App Engine
This is Rietveld 408576698