summaryrefslogtreecommitdiff
path: root/chromium/v8/src/zone
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/zone
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/zone')
-rw-r--r--chromium/v8/src/zone/OWNERS1
-rw-r--r--chromium/v8/src/zone/accounting-allocator.h26
-rw-r--r--chromium/v8/src/zone/zone.cc50
-rw-r--r--chromium/v8/src/zone/zone.h12
4 files changed, 58 insertions, 31 deletions
diff --git a/chromium/v8/src/zone/OWNERS b/chromium/v8/src/zone/OWNERS
index e4e653da5ba..04bfcc5ec5a 100644
--- a/chromium/v8/src/zone/OWNERS
+++ b/chromium/v8/src/zone/OWNERS
@@ -1,3 +1,4 @@
clemensb@chromium.org
+ishell@chromium.org
sigurds@chromium.org
verwaest@chromium.org
diff --git a/chromium/v8/src/zone/accounting-allocator.h b/chromium/v8/src/zone/accounting-allocator.h
index 69a649e75ea..bd2590df35d 100644
--- a/chromium/v8/src/zone/accounting-allocator.h
+++ b/chromium/v8/src/zone/accounting-allocator.h
@@ -8,6 +8,7 @@
#include <atomic>
#include "src/base/macros.h"
+#include "src/logging/tracing-flags.h"
namespace v8 {
namespace internal {
@@ -21,11 +22,11 @@ class V8_EXPORT_PRIVATE AccountingAllocator {
virtual ~AccountingAllocator();
// Allocates a new segment. Returns nullptr on failed allocation.
- virtual Segment* AllocateSegment(size_t bytes);
+ Segment* AllocateSegment(size_t bytes);
// Return unneeded segments to either insert them into the pool or release
// them if the pool is already full or memory pressure is high.
- virtual void ReturnSegment(Segment* memory);
+ void ReturnSegment(Segment* memory);
size_t GetCurrentMemoryUsage() const {
return current_memory_usage_.load(std::memory_order_relaxed);
@@ -35,8 +36,25 @@ class V8_EXPORT_PRIVATE AccountingAllocator {
return max_memory_usage_.load(std::memory_order_relaxed);
}
- virtual void ZoneCreation(const Zone* zone) {}
- virtual void ZoneDestruction(const Zone* zone) {}
+ void TraceZoneCreation(const Zone* zone) {
+ if (V8_LIKELY(!TracingFlags::is_zone_stats_enabled())) return;
+ TraceZoneCreationImpl(zone);
+ }
+
+ void TraceZoneDestruction(const Zone* zone) {
+ if (V8_LIKELY(!TracingFlags::is_zone_stats_enabled())) return;
+ TraceZoneDestructionImpl(zone);
+ }
+
+ void TraceAllocateSegment(Segment* segment) {
+ if (V8_LIKELY(!TracingFlags::is_zone_stats_enabled())) return;
+ TraceAllocateSegmentImpl(segment);
+ }
+
+ protected:
+ virtual void TraceZoneCreationImpl(const Zone* zone) {}
+ virtual void TraceZoneDestructionImpl(const Zone* zone) {}
+ virtual void TraceAllocateSegmentImpl(Segment* segment) {}
private:
std::atomic<size_t> current_memory_usage_{0};
diff --git a/chromium/v8/src/zone/zone.cc b/chromium/v8/src/zone/zone.cc
index 81fc9c7d8b3..34882d966ca 100644
--- a/chromium/v8/src/zone/zone.cc
+++ b/chromium/v8/src/zone/zone.cc
@@ -36,11 +36,10 @@ Zone::Zone(AccountingAllocator* allocator, const char* name)
segment_head_(nullptr),
name_(name),
sealed_(false) {
- allocator_->ZoneCreation(this);
+ allocator_->TraceZoneCreation(this);
}
Zone::~Zone() {
- allocator_->ZoneDestruction(this);
DeleteAll();
DCHECK_EQ(segment_bytes_allocated_, 0);
@@ -74,14 +73,23 @@ void* Zone::AsanNew(size_t size) {
}
void Zone::ReleaseMemory() {
- allocator_->ZoneDestruction(this);
DeleteAll();
- allocator_->ZoneCreation(this);
+ allocator_->TraceZoneCreation(this);
}
void Zone::DeleteAll() {
+ Segment* current = segment_head_;
+ if (current) {
+ // Commit the allocation_size_ of segment_head_ and disconnect the segments
+ // list from the zone in order to ensure that tracing accounting allocator
+ // will observe value including memory from the head segment.
+ allocation_size_ = allocation_size();
+ segment_head_ = nullptr;
+ }
+ allocator_->TraceZoneDestruction(this);
+
// Traverse the chained list of segments and return them all to the allocator.
- for (Segment* current = segment_head_; current;) {
+ while (current) {
Segment* next = current->next();
size_t size = current->total_size();
@@ -96,30 +104,14 @@ void Zone::DeleteAll() {
position_ = limit_ = 0;
allocation_size_ = 0;
- segment_head_ = nullptr;
-}
-
-// Creates a new segment, sets its size, and pushes it to the front
-// of the segment chain. Returns the new segment.
-Segment* Zone::NewSegment(size_t requested_size) {
- Segment* result = allocator_->AllocateSegment(requested_size);
- if (!result) return nullptr;
- DCHECK_GE(result->total_size(), requested_size);
- segment_bytes_allocated_ += result->total_size();
- result->set_zone(this);
- result->set_next(segment_head_);
- segment_head_ = result;
- return result;
}
Address Zone::NewExpand(size_t size) {
// Make sure the requested size is already properly aligned and that
// there isn't enough room in the Zone to satisfy the request.
DCHECK_EQ(size, RoundDown(size, kAlignmentInBytes));
- DCHECK(limit_ - position_ < size);
+ DCHECK_LT(limit_ - position_, size);
- // Commit the allocation_size_ of segment_head_ if any.
- allocation_size_ = allocation_size();
// Compute the new segment size. We use a 'high water mark'
// strategy, where we increase the segment size every time we expand
// except that we employ a maximum segment size when we delete. This
@@ -148,12 +140,24 @@ Address Zone::NewExpand(size_t size) {
V8::FatalProcessOutOfMemory(nullptr, "Zone");
return kNullAddress;
}
- Segment* segment = NewSegment(new_size);
+
+ Segment* segment = allocator_->AllocateSegment(new_size);
if (segment == nullptr) {
V8::FatalProcessOutOfMemory(nullptr, "Zone");
return kNullAddress;
}
+ DCHECK_GE(segment->total_size(), new_size);
+ segment_bytes_allocated_ += segment->total_size();
+ segment->set_zone(this);
+ segment->set_next(segment_head_);
+ // Commit the allocation_size_ of segment_head_ if any, in order to ensure
+ // that tracing accounting allocator will observe value including memory
+ // from the previous head segment.
+ allocation_size_ = allocation_size();
+ segment_head_ = segment;
+ allocator_->TraceAllocateSegment(segment);
+
// Recompute 'top' and 'limit' based on the new segment.
Address result = RoundUp(segment->start(), kAlignmentInBytes);
position_ = result + size;
diff --git a/chromium/v8/src/zone/zone.h b/chromium/v8/src/zone/zone.h
index df72864c5a9..6c30af8132a 100644
--- a/chromium/v8/src/zone/zone.h
+++ b/chromium/v8/src/zone/zone.h
@@ -79,13 +79,21 @@ class V8_EXPORT_PRIVATE Zone final {
return segment_bytes_allocated_ > kExcessLimit;
}
+ size_t segment_bytes_allocated() const { return segment_bytes_allocated_; }
+
const char* name() const { return name_; }
+ // Returns precise value of used zone memory, allowed to be called only
+ // from thread owning the zone.
size_t allocation_size() const {
size_t extra = segment_head_ ? position_ - segment_head_->start() : 0;
return allocation_size_ + extra;
}
+ // Returns used zone memory not including the head segment, can be called
+ // from threads not owning the zone.
+ size_t allocation_size_for_tracing() const { return allocation_size_; }
+
AccountingAllocator* allocator() const { return allocator_; }
private:
@@ -118,10 +126,6 @@ class V8_EXPORT_PRIVATE Zone final {
// room in the Zone already.
Address NewExpand(size_t size);
- // Creates a new segment, sets it size, and pushes it to the front
- // of the segment chain. Returns the new segment.
- inline Segment* NewSegment(size_t requested_size);
-
// The free region in the current (front) segment is represented as
// the half-open interval [position, limit). The 'position' variable
// is guaranteed to be aligned as dictated by kAlignment.