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;