[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 <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
asiva 2022-05-05 23:20:25 +00:00 committed by Commit Bot
parent df21baa407
commit d856e058ea
2 changed files with 43 additions and 6 deletions

View file

@ -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<intptr_t>(this),
reinterpret_cast<intptr_t>(zone_));
reinterpret_cast<intptr_t>(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<intptr_t>(this),
reinterpret_cast<intptr_t>(zone_));
reinterpret_cast<intptr_t>(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

View file

@ -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 <typename T>
friend class GrowableArray;