Reland "[zone] Keep one page when we Zone::Reset for reuse"
This is a reland of 2418d22a37
Reland fixes:
* Rebase this 2+ year old change 😱
* Unpoison the kept segment before zapping it to make ASAN happy.
* Carefully adjust allocation size tracking fields to compensate for
kept segment.
Original change's description:
> [zone] Keep one page when we Zone::Reset for reuse
>
> Change-Id: I50c6124d3da5b35d4156c066f38d10d2dc966567
> Reviewed-on: https://chromium-review.googlesource.com/c/1349246
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Commit-Queue: Toon Verwaest <verwaest@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#57793}
Change-Id: Iaffde5b38b3d683af081b1878464dd4c66be5af8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3322833
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78348}
This commit is contained in:
parent
3312b952d1
commit
41b174a7f0
@ -1631,7 +1631,7 @@ void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory,
|
||||
// Get the zone, while variables_ is still valid
|
||||
Zone* zone = this->zone();
|
||||
variables_.Invalidate();
|
||||
zone->ReleaseMemory();
|
||||
zone->Reset();
|
||||
}
|
||||
|
||||
if (aborted) {
|
||||
|
@ -197,7 +197,7 @@ class V8_EXPORT_PRIVATE ReusableUnoptimizedCompileState {
|
||||
// Zone pointer in the AstValueFactory.
|
||||
Zone* single_parse_zone() { return &single_parse_zone_; }
|
||||
|
||||
void NotifySingleParseCompleted() { single_parse_zone_.ReleaseMemory(); }
|
||||
void NotifySingleParseCompleted() { single_parse_zone_.Reset(); }
|
||||
|
||||
AstValueFactory* ast_value_factory() const {
|
||||
return ast_value_factory_.get();
|
||||
|
@ -70,9 +70,30 @@ void* Zone::AsanNew(size_t size) {
|
||||
return reinterpret_cast<void*>(result);
|
||||
}
|
||||
|
||||
void Zone::ReleaseMemory() {
|
||||
void Zone::Reset() {
|
||||
if (!segment_head_) return;
|
||||
Segment* keep = segment_head_;
|
||||
segment_head_ = segment_head_->next();
|
||||
if (segment_head_ != nullptr) {
|
||||
// Reset the position to the end of the new head, and uncommit its
|
||||
// allocation size (which will be re-committed in DeleteAll).
|
||||
position_ = segment_head_->end();
|
||||
allocation_size_ -= segment_head_->end() - segment_head_->start();
|
||||
}
|
||||
keep->set_next(nullptr);
|
||||
DeleteAll();
|
||||
allocator_->TraceZoneCreation(this);
|
||||
|
||||
// Un-poison the kept segment content so we can zap and re-use it.
|
||||
ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<void*>(keep->start()),
|
||||
keep->capacity());
|
||||
keep->ZapContents();
|
||||
|
||||
segment_head_ = keep;
|
||||
position_ = keep->start();
|
||||
limit_ = keep->end();
|
||||
DCHECK_EQ(allocation_size(), 0);
|
||||
DCHECK_EQ(segment_bytes_allocated_, keep->total_size());
|
||||
}
|
||||
|
||||
void Zone::DeleteAll() {
|
||||
|
@ -134,9 +134,10 @@ class V8_EXPORT_PRIVATE Zone final {
|
||||
// Seals the zone to prevent any further allocation.
|
||||
void Seal() { sealed_ = true; }
|
||||
|
||||
// Allows the zone to be safely reused. Releases the memory and fires zone
|
||||
// destruction and creation events for the accounting allocator.
|
||||
void ReleaseMemory();
|
||||
// Allows the zone to be safely reused. Releases the memory except for the
|
||||
// last page, and fires zone destruction and creation events for the
|
||||
// accounting allocator.
|
||||
void Reset();
|
||||
|
||||
// Returns true if more memory has been allocated in zones than
|
||||
// the limit allows.
|
||||
|
Loading…
Reference in New Issue
Block a user