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 { ...@@ -36,7 +36,7 @@ namespace internal {
class PreParserZoneScope { class PreParserZoneScope {
public: public:
explicit PreParserZoneScope(PreParser* preparser) : preparser_(preparser) {} explicit PreParserZoneScope(PreParser* preparser) : preparser_(preparser) {}
~PreParserZoneScope() { preparser_->zone()->DeleteAll(); } ~PreParserZoneScope() { preparser_->zone()->ReleaseMemory(); }
private: private:
PreParser* preparser_; PreParser* preparser_;
......
...@@ -43,7 +43,6 @@ Zone::Zone(AccountingAllocator* allocator, const char* name, ...@@ -43,7 +43,6 @@ Zone::Zone(AccountingAllocator* allocator, const char* name,
Zone::~Zone() { Zone::~Zone() {
allocator_->ZoneDestruction(this); allocator_->ZoneDestruction(this);
DeleteAll(); DeleteAll();
DCHECK_EQ(segment_bytes_allocated_, 0); DCHECK_EQ(segment_bytes_allocated_, 0);
...@@ -77,6 +76,12 @@ void* Zone::New(size_t size) { ...@@ -77,6 +76,12 @@ void* Zone::New(size_t size) {
return reinterpret_cast<void*>(result); return reinterpret_cast<void*>(result);
} }
void Zone::ReleaseMemory() {
allocator_->ZoneDestruction(this);
DeleteAll();
allocator_->ZoneCreation(this);
}
void Zone::DeleteAll() { void Zone::DeleteAll() {
// Traverse the chained list of segments and return them all to the allocator. // Traverse the chained list of segments and return them all to the allocator.
for (Segment* current = segment_head_; current;) { for (Segment* current = segment_head_; current;) {
......
...@@ -57,8 +57,9 @@ class V8_EXPORT_PRIVATE Zone final { ...@@ -57,8 +57,9 @@ class V8_EXPORT_PRIVATE Zone final {
// Seals the zone to prevent any further allocation. // Seals the zone to prevent any further allocation.
void Seal() { sealed_ = true; } void Seal() { sealed_ = true; }
// Deletes all objects and free all memory allocated in the Zone. // Allows the zone to be safely reused. Releases the memory and fires zone
void DeleteAll(); // destruction and creation events for the accounting allocator.
void ReleaseMemory();
// Returns true if more memory has been allocated in zones than // Returns true if more memory has been allocated in zones than
// the limit allows. // the limit allows.
...@@ -73,6 +74,9 @@ class V8_EXPORT_PRIVATE Zone final { ...@@ -73,6 +74,9 @@ class V8_EXPORT_PRIVATE Zone final {
AccountingAllocator* allocator() const { return allocator_; } AccountingAllocator* allocator() const { return allocator_; }
private: private:
// Deletes all objects and free all memory allocated in the Zone.
void DeleteAll();
// All pointers returned from New() are 8-byte aligned. // All pointers returned from New() are 8-byte aligned.
static const size_t kAlignmentInBytes = 8; 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