From 6e1f628f19c1ed0ccd2b12a86d09a78ad34767bb Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Thu, 23 May 2019 19:10:46 +0000 Subject: [PATCH] Outline the StackZone's Zone Bug: https://github.com/dart-lang/sdk/issues/36100 Change-Id: I17cdf438c19fcc66ceb09c23348654eb752dd3cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103560 Commit-Queue: Liam Appelbe Reviewed-by: Martin Kustermann --- runtime/vm/zone.cc | 17 ++++++++++------- runtime/vm/zone.h | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc index 595871ada1c..cdb8ba424da 100644 --- a/runtime/vm/zone.cc +++ b/runtime/vm/zone.cc @@ -331,19 +331,20 @@ char* Zone::VPrint(const char* format, va_list args) { return OS::VSCreate(this, format, args); } -StackZone::StackZone(ThreadState* thread) : StackResource(thread), zone_() { +StackZone::StackZone(ThreadState* thread) + : StackResource(thread), zone_(new Zone()) { if (FLAG_trace_zones) { OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", reinterpret_cast(this), - reinterpret_cast(&zone_)); + reinterpret_cast(zone_)); } // This thread must be preventing safepoints or the GC could be visiting the // chain of handle blocks we're about the mutate. ASSERT(Thread::Current()->MayAllocateHandles()); - zone_.Link(thread->zone()); - thread->set_zone(&zone_); + zone_->Link(thread->zone()); + thread->set_zone(zone_); } StackZone::~StackZone() { @@ -351,13 +352,15 @@ StackZone::~StackZone() { // chain of handle blocks we're about the mutate. ASSERT(Thread::Current()->MayAllocateHandles()); - ASSERT(thread()->zone() == &zone_); - thread()->set_zone(zone_.previous_); + ASSERT(thread()->zone() == zone_); + thread()->set_zone(zone_->previous_); if (FLAG_trace_zones) { OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", reinterpret_cast(this), - reinterpret_cast(&zone_)); + reinterpret_cast(zone_)); } + + delete zone_; } } // namespace dart diff --git a/runtime/vm/zone.h b/runtime/vm/zone.h index b4aba7f7f05..88e1ef99d7f 100644 --- a/runtime/vm/zone.h +++ b/runtime/vm/zone.h @@ -177,19 +177,19 @@ class StackZone : public StackResource { explicit StackZone(ThreadState* thread); // Delete all memory associated with the zone. - ~StackZone(); + virtual ~StackZone(); // Compute the total size of this zone. This includes wasted space that is // due to internal fragmentation in the segments. - uintptr_t SizeInBytes() const { return zone_.SizeInBytes(); } + uintptr_t SizeInBytes() const { return zone_->SizeInBytes(); } // Computes the used space in the zone. - intptr_t CapacityInBytes() const { return zone_.CapacityInBytes(); } + intptr_t CapacityInBytes() const { return zone_->CapacityInBytes(); } - Zone* GetZone() { return &zone_; } + Zone* GetZone() { return zone_; } private: - Zone zone_; + Zone* zone_; template friend class GrowableArray;