Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: src/compiler/zone-pool.cc

Issue 665893006: [turbofan] add ZonePool to correctly track compiler phase memory usage (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/zone-pool.h ('k') | src/zone.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/zone-pool.cc
diff --git a/src/compiler/zone-pool.cc b/src/compiler/zone-pool.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8276023522962e01762e0dd6e85b8ac0469391ab
--- /dev/null
+++ b/src/compiler/zone-pool.cc
@@ -0,0 +1,133 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/compiler/zone-pool.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+ZonePool::StatsScope::StatsScope(ZonePool* zone_pool)
+ : zone_pool_(zone_pool), max_allocated_bytes_(0) {
+ zone_pool_->stats_.push_back(this);
+ for (auto zone : zone_pool_->used_) {
+ size_t size = static_cast<size_t>(zone->allocation_size());
+ std::pair<InitialValues::iterator, bool> res =
+ initial_values_.insert(std::make_pair(zone, size));
+ USE(res);
+ DCHECK(res.second);
+ }
+}
+
+
+ZonePool::StatsScope::~StatsScope() {
+ DCHECK_EQ(zone_pool_->stats_.back(), this);
+ zone_pool_->stats_.pop_back();
+}
+
+
+size_t ZonePool::StatsScope::GetMaxAllocatedBytes() {
+ return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
+}
+
+
+size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() {
+ size_t total = 0;
+ for (Zone* zone : zone_pool_->used_) {
+ total += static_cast<size_t>(zone->allocation_size());
+ // Adjust for initial values.
+ InitialValues::iterator it = initial_values_.find(zone);
+ if (it != initial_values_.end()) {
+ total -= it->second;
+ }
+ }
+ return total;
+}
+
+
+void ZonePool::StatsScope::ZoneReturned(Zone* zone) {
+ size_t current_total = GetCurrentAllocatedBytes();
+ // Update max.
+ max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
+ // Drop zone from initial value map.
+ InitialValues::iterator it = initial_values_.find(zone);
+ if (it != initial_values_.end()) {
+ initial_values_.erase(it);
+ }
+}
+
+
+ZonePool::ZonePool(Isolate* isolate)
+ : isolate_(isolate), max_allocated_bytes_(0), total_deleted_bytes_(0) {}
+
+
+ZonePool::~ZonePool() {
+ DCHECK(used_.empty());
+ DCHECK(stats_.empty());
+ for (Zone* zone : unused_) {
+ delete zone;
+ }
+}
+
+
+size_t ZonePool::GetMaxAllocatedBytes() {
+ return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
+}
+
+
+size_t ZonePool::GetCurrentAllocatedBytes() {
+ size_t total = 0;
+ for (Zone* zone : used_) {
+ total += static_cast<size_t>(zone->allocation_size());
+ }
+ return total;
+}
+
+
+size_t ZonePool::GetTotalAllocatedBytes() {
+ return total_deleted_bytes_ + GetCurrentAllocatedBytes();
+}
+
+
+Zone* ZonePool::NewEmptyZone() {
+ Zone* zone;
+ // Grab a zone from pool if possible.
+ if (!unused_.empty()) {
+ zone = unused_.back();
+ unused_.pop_back();
+ } else {
+ zone = new Zone(isolate_);
+ }
+ used_.push_back(zone);
+ DCHECK_EQ(0, zone->allocation_size());
+ return zone;
+}
+
+
+void ZonePool::ReturnZone(Zone* zone) {
+ size_t current_total = GetCurrentAllocatedBytes();
+ // Update max.
+ max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
+ // Update stats.
+ for (auto stat_scope : stats_) {
+ stat_scope->ZoneReturned(zone);
+ }
+ // Remove from used.
+ Used::iterator it = std::find(used_.begin(), used_.end(), zone);
+ DCHECK(it != used_.end());
+ used_.erase(it);
+ total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size());
+ // Delete zone or clear and stash on unused_.
+ if (unused_.size() >= kMaxUnusedSize) {
+ delete zone;
+ } else {
+ zone->DeleteAll();
+ DCHECK_EQ(0, zone->allocation_size());
+ unused_.push_back(zone);
+ }
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/compiler/zone-pool.h ('k') | src/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698