Commit 568979f4 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Fix memory accounting of explicitly cleared zones

Bug: chromium:889086
Change-Id: Ie5a6a9e27260545469ea62d35b9571c0524f0f92
Reviewed-on: https://chromium-review.googlesource.com/1245427Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56235}
parent e5648b2a
......@@ -36,7 +36,7 @@ namespace internal {
class PreParserZoneScope {
public:
explicit PreParserZoneScope(PreParser* preparser) : preparser_(preparser) {}
~PreParserZoneScope() { preparser_->zone()->DeleteAll(); }
~PreParserZoneScope() { preparser_->zone()->ReleaseMemory(); }
private:
PreParser* preparser_;
......
......@@ -43,7 +43,6 @@ Zone::Zone(AccountingAllocator* allocator, const char* name,
Zone::~Zone() {
allocator_->ZoneDestruction(this);
DeleteAll();
DCHECK_EQ(segment_bytes_allocated_, 0);
......@@ -77,6 +76,12 @@ void* Zone::New(size_t size) {
return reinterpret_cast<void*>(result);
}
void Zone::ReleaseMemory() {
allocator_->ZoneDestruction(this);
DeleteAll();
allocator_->ZoneCreation(this);
}
void Zone::DeleteAll() {
// Traverse the chained list of segments and return them all to the allocator.
for (Segment* current = segment_head_; current;) {
......
......@@ -57,8 +57,9 @@ class V8_EXPORT_PRIVATE Zone final {
// Seals the zone to prevent any further allocation.
void Seal() { sealed_ = true; }
// Deletes all objects and free all memory allocated in the Zone.
void DeleteAll();
// Allows the zone to be safely reused. Releases the memory and fires zone
// destruction and creation events for the accounting allocator.
void ReleaseMemory();
// Returns true if more memory has been allocated in zones than
// the limit allows.
......@@ -73,6 +74,9 @@ class V8_EXPORT_PRIVATE Zone final {
AccountingAllocator* allocator() const { return allocator_; }
private:
// Deletes all objects and free all memory allocated in the Zone.
void DeleteAll();
// All pointers returned from New() are 8-byte aligned.
static const size_t kAlignmentInBytes = 8;
......
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