Commit e770879e authored by Ali Ijaz Sheikh's avatar Ali Ijaz Sheikh Committed by Commit Bot

[heap] Add missing steps for Add/Remove observers

Change-Id: I9935ff4debc623af674e606c006085258b685ced
Reviewed-on: https://chromium-review.googlesource.com/715118Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com>
Cr-Commit-Position: refs/heads/master@{#48513}
parent 469a08f7
......@@ -6372,5 +6372,16 @@ void Heap::CreateObjectStats() {
}
}
void AllocationObserver::AllocationStep(int bytes_allocated,
Address soon_object, size_t size) {
DCHECK_GE(bytes_allocated, 0);
bytes_to_next_step_ -= bytes_allocated;
if (bytes_to_next_step_ <= 0) {
Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object, size);
step_size_ = GetNextStepSize();
bytes_to_next_step_ = step_size_;
}
}
} // namespace internal
} // namespace v8
......@@ -2648,15 +2648,7 @@ class AllocationObserver {
// Called each time the observed space does an allocation step. This may be
// more frequently than the step_size we are monitoring (e.g. when there are
// multiple observers, or when page or space boundary is encountered.)
void AllocationStep(int bytes_allocated, Address soon_object, size_t size) {
bytes_to_next_step_ -= bytes_allocated;
if (bytes_to_next_step_ <= 0) {
Step(static_cast<int>(step_size_ - bytes_to_next_step_), soon_object,
size);
step_size_ = GetNextStepSize();
bytes_to_next_step_ = step_size_;
}
}
void AllocationStep(int bytes_allocated, Address soon_object, size_t size);
protected:
intptr_t step_size() const { return step_size_; }
......
......@@ -103,7 +103,7 @@ void ScavengeJob::ScheduleIdleTaskIfNeeded(Heap* heap, int bytes_allocated) {
void ScavengeJob::ScheduleIdleTask(Heap* heap) {
if (!idle_task_pending_) {
if (!idle_task_pending_ && heap->use_tasks()) {
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap->isolate());
if (V8::GetCurrentPlatform()->IdleTasksEnabled(isolate)) {
idle_task_pending_ = true;
......
......@@ -1696,12 +1696,7 @@ void PagedSpace::EmptyAllocationInfo() {
}
}
if (top_on_previous_step_) {
DCHECK(current_top >= top_on_previous_step_);
AllocationStep(static_cast<int>(current_top - top_on_previous_step_),
nullptr, 0);
top_on_previous_step_ = 0;
}
InlineAllocationStep(current_top, nullptr, nullptr, 0);
SetTopAndLimit(NULL, NULL);
DCHECK_GE(current_limit, current_top);
Free(current_top, current_limit - current_top);
......@@ -2150,6 +2145,30 @@ void NewSpace::StartNextInlineAllocationStep() {
}
}
// TODO(ofrobots): refactor into SpaceWithLinearArea
void NewSpace::AddAllocationObserver(AllocationObserver* observer) {
InlineAllocationStep(top(), top(), nullptr, 0);
Space::AddAllocationObserver(observer);
}
// TODO(ofrobots): refactor into SpaceWithLinearArea
void PagedSpace::AddAllocationObserver(AllocationObserver* observer) {
InlineAllocationStep(top(), top(), nullptr, 0);
Space::AddAllocationObserver(observer);
}
// TODO(ofrobots): refactor into SpaceWithLinearArea
void NewSpace::RemoveAllocationObserver(AllocationObserver* observer) {
InlineAllocationStep(top(), top(), nullptr, 0);
Space::RemoveAllocationObserver(observer);
}
// TODO(ofrobots): refactor into SpaceWithLinearArea
void PagedSpace::RemoveAllocationObserver(AllocationObserver* observer) {
InlineAllocationStep(top(), top(), nullptr, 0);
Space::RemoveAllocationObserver(observer);
}
void NewSpace::PauseAllocationObservers() {
// Do a step to account for memory allocated so far.
InlineAllocationStep(top(), top(), nullptr, 0);
......@@ -2160,10 +2179,7 @@ void NewSpace::PauseAllocationObservers() {
void PagedSpace::PauseAllocationObservers() {
// Do a step to account for memory allocated so far.
if (top_on_previous_step_) {
int bytes_allocated = static_cast<int>(top() - top_on_previous_step_);
AllocationStep(bytes_allocated, nullptr, 0);
}
InlineAllocationStep(top(), nullptr, nullptr, 0);
Space::PauseAllocationObservers();
top_on_previous_step_ = 0;
}
......@@ -2181,13 +2197,21 @@ void PagedSpace::ResumeAllocationObservers() {
StartNextInlineAllocationStep();
}
// TODO(ofrobots): refactor into SpaceWithLinearArea
void PagedSpace::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_);
AllocationStep(bytes_allocated, soon_object, static_cast<int>(size));
top_on_previous_step_ = new_top;
}
}
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 (AllocationObserver* observer : allocation_observers_) {
observer->AllocationStep(bytes_allocated, soon_object, size);
}
AllocationStep(bytes_allocated, soon_object, static_cast<int>(size));
top_on_previous_step_ = new_top;
}
}
......
......@@ -903,9 +903,11 @@ class Space : public Malloced {
// Identity used in error reporting.
AllocationSpace identity() { return id_; }
void AddAllocationObserver(AllocationObserver* observer);
V8_EXPORT_PRIVATE virtual void AddAllocationObserver(
AllocationObserver* observer);
void RemoveAllocationObserver(AllocationObserver* observer);
V8_EXPORT_PRIVATE virtual void RemoveAllocationObserver(
AllocationObserver* observer);
V8_EXPORT_PRIVATE virtual void PauseAllocationObservers();
......@@ -2078,9 +2080,14 @@ class V8_EXPORT_PRIVATE PagedSpace : NON_EXPORTED_BASE(public Space) {
void ResetFreeList() { free_list_.Reset(); }
void AddAllocationObserver(AllocationObserver* observer) override;
void RemoveAllocationObserver(AllocationObserver* observer) override;
void PauseAllocationObservers() override;
void ResumeAllocationObservers() override;
void InlineAllocationStep(Address top, Address new_top, Address soon_object,
size_t size);
// Empty space allocation info, returning unused area to free list.
void EmptyAllocationInfo();
......@@ -2730,6 +2737,8 @@ class NewSpace : public Space {
SemiSpace* active_space() { return &to_space_; }
void AddAllocationObserver(AllocationObserver* observer) override;
void RemoveAllocationObserver(AllocationObserver* observer) override;
void PauseAllocationObservers() override;
void ResumeAllocationObservers() override;
......
......@@ -3137,3 +3137,28 @@ TEST(SamplingHeapProfilerPretenuredInlineAllocations) {
CHECK_GE(count, 9000);
}
TEST(SamplingHeapProfilerLargeInterval) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext env;
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
// Suppress randomness to avoid flakiness in tests.
v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
heap_profiler->StartSamplingHeapProfiler(512 * 1024);
for (int i = 0; i < 8 * 1024; ++i) {
CcTest::i_isolate()->factory()->NewFixedArray(1024);
}
std::unique_ptr<v8::AllocationProfile> profile(
heap_profiler->GetAllocationProfile());
CHECK(profile);
const char* names[] = {"(EXTERNAL)"};
auto node = FindAllocationProfileNode(env->GetIsolate(), *profile,
ArrayVector(names));
CHECK(node);
heap_profiler->StopSamplingHeapProfiler();
}
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