Commit 04bc53b5 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Move AllocationObserver into its own file

In preparation for AllocationObserver changes, move AllocationObserver
related code into its own file.

Bug: v8:10315
Change-Id: I65d5a51662ff192c7b05d4229d8ca27f4a53aa3e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2304580Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68924}
parent bac47366
...@@ -2461,6 +2461,8 @@ v8_source_set("v8_base_without_compiler") { ...@@ -2461,6 +2461,8 @@ v8_source_set("v8_base_without_compiler") {
"src/handles/maybe-handles.h", "src/handles/maybe-handles.h",
"src/handles/persistent-handles.cc", "src/handles/persistent-handles.cc",
"src/handles/persistent-handles.h", "src/handles/persistent-handles.h",
"src/heap/allocation-observer.cc",
"src/heap/allocation-observer.h",
"src/heap/allocation-stats.h", "src/heap/allocation-stats.h",
"src/heap/array-buffer-collector.cc", "src/heap/array-buffer-collector.cc",
"src/heap/array-buffer-collector.h", "src/heap/array-buffer-collector.h",
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/heap/allocation-observer.h"
#include "src/heap/heap.h"
#include "src/heap/spaces.h"
namespace v8 {
namespace internal {
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_;
}
DCHECK_GE(bytes_to_next_step_, 0);
}
PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap)
: heap_(heap) {
DCHECK_EQ(heap->gc_state(), Heap::NOT_IN_GC);
for (SpaceIterator it(heap_); it.HasNext();) {
it.Next()->PauseAllocationObservers();
}
}
PauseAllocationObserversScope::~PauseAllocationObserversScope() {
for (SpaceIterator it(heap_); it.HasNext();) {
it.Next()->ResumeAllocationObservers();
}
}
} // namespace internal
} // namespace v8
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_HEAP_ALLOCATION_OBSERVER_H_
#define V8_HEAP_ALLOCATION_OBSERVER_H_
#include "src/common/globals.h"
namespace v8 {
namespace internal {
// -----------------------------------------------------------------------------
// Allows observation of allocations.
class AllocationObserver {
public:
explicit AllocationObserver(intptr_t step_size)
: step_size_(step_size), bytes_to_next_step_(step_size) {
DCHECK_LE(kTaggedSize, step_size);
}
virtual ~AllocationObserver() = default;
// 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);
protected:
intptr_t step_size() const { return step_size_; }
intptr_t bytes_to_next_step() const { return bytes_to_next_step_; }
// Pure virtual method provided by the subclasses that gets called when at
// least step_size bytes have been allocated. soon_object is the address just
// 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;
// Subclasses can override this method to make step size dynamic.
virtual intptr_t GetNextStepSize() { return step_size_; }
intptr_t step_size_;
intptr_t bytes_to_next_step_;
private:
friend class Space;
DISALLOW_COPY_AND_ASSIGN(AllocationObserver);
};
class V8_EXPORT_PRIVATE PauseAllocationObserversScope {
public:
explicit PauseAllocationObserversScope(Heap* heap);
~PauseAllocationObserversScope();
private:
Heap* heap_;
DISALLOW_COPY_AND_ASSIGN(PauseAllocationObserversScope);
};
} // namespace internal
} // namespace v8
#endif // V8_HEAP_ALLOCATION_OBSERVER_H_
...@@ -6534,18 +6534,6 @@ void Heap::CreateObjectStats() { ...@@ -6534,18 +6534,6 @@ 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_;
}
DCHECK_GE(bytes_to_next_step_, 0);
}
Map Heap::GcSafeMapOfCodeSpaceObject(HeapObject object) { Map Heap::GcSafeMapOfCodeSpaceObject(HeapObject object) {
MapWord map_word = object.map_word(); MapWord map_word = object.map_word();
return map_word.IsForwardingAddress() ? map_word.ToForwardingAddress().map() return map_word.IsForwardingAddress() ? map_word.ToForwardingAddress().map()
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "src/builtins/accessors.h" #include "src/builtins/accessors.h"
#include "src/common/assert-scope.h" #include "src/common/assert-scope.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/heap/allocation-observer.h"
#include "src/init/heap-symbols.h" #include "src/init/heap-symbols.h"
#include "src/objects/allocation-site.h" #include "src/objects/allocation-site.h"
#include "src/objects/fixed-array.h" #include "src/objects/fixed-array.h"
...@@ -61,7 +62,6 @@ class NativeContext; ...@@ -61,7 +62,6 @@ class NativeContext;
using v8::MemoryPressureLevel; using v8::MemoryPressureLevel;
class AllocationObserver;
class ArrayBufferCollector; class ArrayBufferCollector;
class ArrayBufferSweeper; class ArrayBufferSweeper;
class BasicMemoryChunk; class BasicMemoryChunk;
...@@ -2528,50 +2528,6 @@ class WeakObjectRetainer { ...@@ -2528,50 +2528,6 @@ class WeakObjectRetainer {
virtual Object RetainAs(Object object) = 0; virtual Object RetainAs(Object object) = 0;
}; };
// -----------------------------------------------------------------------------
// Allows observation of allocations.
class AllocationObserver {
public:
explicit AllocationObserver(intptr_t step_size)
: step_size_(step_size), bytes_to_next_step_(step_size) {
DCHECK_LE(kTaggedSize, step_size);
}
virtual ~AllocationObserver() = default;
// 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);
protected:
intptr_t step_size() const { return step_size_; }
intptr_t bytes_to_next_step() const { return bytes_to_next_step_; }
// Pure virtual method provided by the subclasses that gets called when at
// least step_size bytes have been allocated. soon_object is the address just
// 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;
// Subclasses can override this method to make step size dynamic.
virtual intptr_t GetNextStepSize() { return step_size_; }
intptr_t step_size_;
intptr_t bytes_to_next_step_;
private:
friend class Space;
DISALLOW_COPY_AND_ASSIGN(AllocationObserver);
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Allows observation of heap object allocations. // Allows observation of heap object allocations.
class HeapObjectAllocationTracker { class HeapObjectAllocationTracker {
......
...@@ -45,21 +45,6 @@ namespace internal { ...@@ -45,21 +45,6 @@ namespace internal {
STATIC_ASSERT(kClearedWeakHeapObjectLower32 > 0); STATIC_ASSERT(kClearedWeakHeapObjectLower32 > 0);
STATIC_ASSERT(kClearedWeakHeapObjectLower32 < Page::kHeaderSize); STATIC_ASSERT(kClearedWeakHeapObjectLower32 < Page::kHeaderSize);
PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap)
: heap_(heap) {
DCHECK_EQ(heap->gc_state(), Heap::NOT_IN_GC);
for (SpaceIterator it(heap_); it.HasNext();) {
it.Next()->PauseAllocationObservers();
}
}
PauseAllocationObserversScope::~PauseAllocationObserversScope() {
for (SpaceIterator it(heap_); it.HasNext();) {
it.Next()->ResumeAllocationObservers();
}
}
void Page::AllocateFreeListCategories() { void Page::AllocateFreeListCategories() {
DCHECK_NULL(categories_); DCHECK_NULL(categories_);
categories_ = categories_ =
......
...@@ -549,16 +549,6 @@ class SpaceWithLinearArea : public Space { ...@@ -549,16 +549,6 @@ class SpaceWithLinearArea : public Space {
AllocationOrigin::kNumberOfAllocationOrigins)] = {0}; AllocationOrigin::kNumberOfAllocationOrigins)] = {0};
}; };
class V8_EXPORT_PRIVATE PauseAllocationObserversScope {
public:
explicit PauseAllocationObserversScope(Heap* heap);
~PauseAllocationObserversScope();
private:
Heap* heap_;
DISALLOW_COPY_AND_ASSIGN(PauseAllocationObserversScope);
};
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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