From d856e058ea764fade95fdf76530c741079bd63e1 Mon Sep 17 00:00:00 2001 From: asiva Date: Thu, 5 May 2022 23:20:25 +0000 Subject: [PATCH] [VM/Runtime] Inline first zone in a StackZone when we are not using fibers. TEST=ci Change-Id: I1308b2450d77ac83c89208acb7d18ad1be5bdcbf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243856 Reviewed-by: Ryan Macnak Commit-Queue: Siva Annamalai --- runtime/vm/zone.cc | 22 ++++++++++++++++------ runtime/vm/zone.h | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) 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;