Commit e7560013 authored by ofrobots's avatar ofrobots Committed by Commit bot

[heap] report allocated object to the inline-allocation-observers

Makes it possible for the the inline allocation observers to be sample the
actual object allocation on which the notification triggers.

R=hpayer@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1460063006

Cr-Commit-Position: refs/heads/master@{#32209}
parent 912314be
...@@ -57,7 +57,7 @@ class IdleScavengeObserver : public InlineAllocationObserver { ...@@ -57,7 +57,7 @@ class IdleScavengeObserver : public InlineAllocationObserver {
IdleScavengeObserver(Heap& heap, intptr_t step_size) IdleScavengeObserver(Heap& heap, intptr_t step_size)
: InlineAllocationObserver(step_size), heap_(heap) {} : InlineAllocationObserver(step_size), heap_(heap) {}
virtual void Step(int bytes_allocated) { void Step(int bytes_allocated, Address, size_t) override {
heap_.ScheduleIdleScavengeIfNeeded(bytes_allocated); heap_.ScheduleIdleScavengeIfNeeded(bytes_allocated);
} }
......
...@@ -221,7 +221,7 @@ class IncrementalMarking { ...@@ -221,7 +221,7 @@ class IncrementalMarking {
: InlineAllocationObserver(step_size), : InlineAllocationObserver(step_size),
incremental_marking_(incremental_marking) {} incremental_marking_(incremental_marking) {}
virtual void Step(int bytes_allocated) { void Step(int bytes_allocated, Address, size_t) override {
incremental_marking_.Step(bytes_allocated, incremental_marking_.Step(bytes_allocated,
IncrementalMarking::GC_VIA_STACK_GUARD); IncrementalMarking::GC_VIA_STACK_GUARD);
} }
......
...@@ -1499,7 +1499,7 @@ void NewSpace::ResetAllocationInfo() { ...@@ -1499,7 +1499,7 @@ void NewSpace::ResetAllocationInfo() {
while (it.has_next()) { while (it.has_next()) {
Bitmap::Clear(it.next()); Bitmap::Clear(it.next());
} }
InlineAllocationStep(old_top, allocation_info_.top()); InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0);
} }
...@@ -1579,7 +1579,7 @@ bool NewSpace::EnsureAllocation(int size_in_bytes, ...@@ -1579,7 +1579,7 @@ bool NewSpace::EnsureAllocation(int size_in_bytes,
return false; return false;
} }
InlineAllocationStep(old_top, allocation_info_.top()); InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0);
old_top = allocation_info_.top(); old_top = allocation_info_.top();
high = to_space_.page_high(); high = to_space_.page_high();
...@@ -1595,7 +1595,8 @@ bool NewSpace::EnsureAllocation(int size_in_bytes, ...@@ -1595,7 +1595,8 @@ bool NewSpace::EnsureAllocation(int size_in_bytes,
// or because idle scavenge job wants to get a chance to post a task. // or because idle scavenge job wants to get a chance to post a task.
// Set the new limit accordingly. // Set the new limit accordingly.
Address new_top = old_top + aligned_size_in_bytes; Address new_top = old_top + aligned_size_in_bytes;
InlineAllocationStep(new_top, new_top); Address soon_object = old_top + filler_size;
InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes);
UpdateInlineAllocationLimit(aligned_size_in_bytes); UpdateInlineAllocationLimit(aligned_size_in_bytes);
} }
return true; return true;
...@@ -1640,7 +1641,7 @@ void NewSpace::RemoveInlineAllocationObserver( ...@@ -1640,7 +1641,7 @@ void NewSpace::RemoveInlineAllocationObserver(
void NewSpace::PauseInlineAllocationObservers() { void NewSpace::PauseInlineAllocationObservers() {
// Do a step to account for memory allocated so far. // Do a step to account for memory allocated so far.
InlineAllocationStep(top(), top()); InlineAllocationStep(top(), top(), nullptr, 0);
inline_allocation_observers_paused_ = true; inline_allocation_observers_paused_ = true;
top_on_previous_step_ = 0; top_on_previous_step_ = 0;
UpdateInlineAllocationLimit(0); UpdateInlineAllocationLimit(0);
...@@ -1654,11 +1655,13 @@ void NewSpace::ResumeInlineAllocationObservers() { ...@@ -1654,11 +1655,13 @@ void NewSpace::ResumeInlineAllocationObservers() {
} }
void NewSpace::InlineAllocationStep(Address top, Address new_top) { void NewSpace::InlineAllocationStep(Address top, Address new_top,
Address soon_object, size_t size) {
if (top_on_previous_step_) { if (top_on_previous_step_) {
int bytes_allocated = static_cast<int>(top - 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) { for (int i = 0; i < inline_allocation_observers_.length(); ++i) {
inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated); inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated,
soon_object, size);
} }
top_on_previous_step_ = new_top; top_on_previous_step_ = new_top;
} }
......
...@@ -2523,16 +2523,28 @@ class InlineAllocationObserver { ...@@ -2523,16 +2523,28 @@ class InlineAllocationObserver {
intptr_t bytes_to_next_step() const { return bytes_to_next_step_; } intptr_t bytes_to_next_step() const { return bytes_to_next_step_; }
// Pure virtual method provided by the subclasses that gets called when at // Pure virtual method provided by the subclasses that gets called when at
// least step_size bytes have been allocated. // least step_size bytes have been allocated. soon_object is the address just
virtual void Step(int bytes_allocated) = 0; // allocated (but not yet initialized.) size is the size of the object as
// requested (i.e. w/o the alignment fillers). Some complexities to be aware
// of:
// 1) soon_object will be nullptr in cases where we end up observing an
// allocation that happens to be a filler space (e.g. page boundaries.)
// 2) size is the requested size at the time of allocation. Right-trimming
// may change the object size dynamically.
// 3) soon_object may actually be the first object in an allocation-folding
// group. In such a case size is the size of the group rather than the
// first object.
virtual void Step(int bytes_allocated, Address soon_object, size_t size) = 0;
// Called each time the new space does an inline allocation step. This may be // Called each time the new space does an inline allocation step. This may be
// more frequently than the step_size we are monitoring (e.g. when there are // more frequently than the step_size we are monitoring (e.g. when there are
// multiple observers, or when page or space boundary is encountered.) // multiple observers, or when page or space boundary is encountered.)
void InlineAllocationStep(int bytes_allocated) { void InlineAllocationStep(int bytes_allocated, Address soon_object,
size_t size) {
bytes_to_next_step_ -= bytes_allocated; bytes_to_next_step_ -= bytes_allocated;
if (bytes_to_next_step_ <= 0) { if (bytes_to_next_step_ <= 0) {
Step(static_cast<int>(step_size_ - bytes_to_next_step_)); Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object,
size);
bytes_to_next_step_ = step_size_; bytes_to_next_step_ = step_size_;
} }
} }
...@@ -2863,7 +2875,8 @@ class NewSpace : public Space { ...@@ -2863,7 +2875,8 @@ class NewSpace : public Space {
// allocated since the last step.) new_top is the address of the bump pointer // allocated since the last step.) new_top is the address of the bump pointer
// where the next byte is going to be allocated from. top and new_top may be // where the next byte is going to be allocated from. top and new_top may be
// different when we cross a page boundary or reset the space. // different when we cross a page boundary or reset the space.
void InlineAllocationStep(Address top, Address new_top); void InlineAllocationStep(Address top, Address new_top, Address soon_object,
size_t size);
intptr_t GetNextInlineAllocationStepSize(); intptr_t GetNextInlineAllocationStepSize();
void StartNextInlineAllocationStep(); void StartNextInlineAllocationStep();
......
...@@ -804,7 +804,7 @@ class Observer : public InlineAllocationObserver { ...@@ -804,7 +804,7 @@ class Observer : public InlineAllocationObserver {
explicit Observer(intptr_t step_size) explicit Observer(intptr_t step_size)
: InlineAllocationObserver(step_size), count_(0) {} : InlineAllocationObserver(step_size), count_(0) {}
virtual void Step(int bytes_allocated) { count_++; } void Step(int bytes_allocated, Address, size_t) override { count_++; }
int count() const { return count_; } int count() const { return count_; }
......
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