diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc index 33b23323220..d0d878c775d 100644 --- a/runtime/vm/zone.cc +++ b/runtime/vm/zone.cc @@ -320,19 +320,25 @@ char* Zone::VPrint(const char* format, va_list args) { } StackZone::StackZone(ThreadState* thread) +#if defined(DART_USE_ABSL) + // DART_USE_ABSL encodes the use of fibers in the Dart VM for threading. : StackResource(thread), zone_(new Zone()) { +#else + : StackResource(thread), zone_() { +#endif // defined(DART_USE_ABSL) if (FLAG_trace_zones) { OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", reinterpret_cast(this), - reinterpret_cast(zone_)); + reinterpret_cast(GetZone())); } // 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* lzone = GetZone(); + lzone->Link(thread->zone()); + thread->set_zone(lzone); } StackZone::~StackZone() { @@ -340,15 +346,19 @@ StackZone::~StackZone() { // chain of handle blocks we're about the mutate. ASSERT(Thread::Current()->MayAllocateHandles()); - ASSERT(thread()->zone() == zone_); - thread()->set_zone(zone_->previous_); + Zone* lzone = GetZone(); + ASSERT(thread()->zone() == lzone); + thread()->set_zone(lzone->previous_); if (FLAG_trace_zones) { OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", reinterpret_cast(this), - reinterpret_cast(zone_)); + reinterpret_cast(lzone)); } +#if defined(DART_USE_ABSL) + // DART_USE_ABSL encodes the use of fibers in the Dart VM for threading. delete zone_; +#endif // defined(DART_USE_ABSL) } } // namespace dart diff --git a/runtime/vm/zone.h b/runtime/vm/zone.h index a22f953b05d..d5abb3b54c3 100644 --- a/runtime/vm/zone.h +++ b/runtime/vm/zone.h @@ -192,6 +192,8 @@ class StackZone : public StackResource { // Delete all memory associated with the zone. virtual ~StackZone(); + // DART_USE_ABSL encodes the use of fibers in the Dart VM for threading, +#if defined(DART_USE_ABSL) // 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(); } @@ -200,9 +202,34 @@ class StackZone : public StackResource { intptr_t CapacityInBytes() const { return zone_->CapacityInBytes(); } Zone* GetZone() { return zone_; } +#else + // 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(); + } + + // Computes the used space in the zone. + intptr_t CapacityInBytes() const { + return zone_.CapacityInBytes(); + } + + Zone* GetZone() { + return &zone_; + } +#endif // defined(DART_USE_ABSL) private: +#if defined(DART_USE_ABSL) + // When fibers are used we have to make do with a smaller stack size and hence + // the first zone is allocated instead of being a stack resource. Zone* zone_; +#else + // For regular configurations that have larger stack sizes it is ok to + // have the first zone be a stack resource, avoids the overhead of a malloc + // call for every stack zone creation. + Zone zone_; +#endif // defined(DART_USE_ABSL) template friend class GrowableArray;