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 <liama@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc
index 595871a..cdb8ba4 100644
--- a/runtime/vm/zone.cc
+++ b/runtime/vm/zone.cc
@@ -331,19 +331,20 @@
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<intptr_t>(this),
- reinterpret_cast<intptr_t>(&zone_));
+ reinterpret_cast<intptr_t>(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 @@
// 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<intptr_t>(this),
- reinterpret_cast<intptr_t>(&zone_));
+ reinterpret_cast<intptr_t>(zone_));
}
+
+ delete zone_;
}
} // namespace dart
diff --git a/runtime/vm/zone.h b/runtime/vm/zone.h
index b4aba7f..88e1ef9 100644
--- a/runtime/vm/zone.h
+++ b/runtime/vm/zone.h
@@ -177,19 +177,19 @@
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 <typename T>
friend class GrowableArray;