Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/zone-pool.h" | 5 #include "src/compiler/zone-stats.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace compiler { | 9 namespace compiler { |
| 10 | 10 |
| 11 ZonePool::StatsScope::StatsScope(ZonePool* zone_pool) | 11 ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats) |
| 12 : zone_pool_(zone_pool), | 12 : zone_stats_(zone_stats), |
| 13 total_allocated_bytes_at_start_(zone_pool->GetTotalAllocatedBytes()), | 13 total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()), |
| 14 max_allocated_bytes_(0) { | 14 max_allocated_bytes_(0) { |
| 15 zone_pool_->stats_.push_back(this); | 15 zone_stats_->stats_.push_back(this); |
| 16 for (Zone* zone : zone_pool_->used_) { | 16 for (Zone* zone : zone_stats_->used_) { |
| 17 size_t size = static_cast<size_t>(zone->allocation_size()); | 17 size_t size = static_cast<size_t>(zone->allocation_size()); |
| 18 std::pair<InitialValues::iterator, bool> res = | 18 std::pair<InitialValues::iterator, bool> res = |
| 19 initial_values_.insert(std::make_pair(zone, size)); | 19 initial_values_.insert(std::make_pair(zone, size)); |
| 20 USE(res); | 20 USE(res); |
| 21 DCHECK(res.second); | 21 DCHECK(res.second); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 ZoneStats::StatsScope::~StatsScope() { |
| 26 ZonePool::StatsScope::~StatsScope() { | 26 DCHECK_EQ(zone_stats_->stats_.back(), this); |
| 27 DCHECK_EQ(zone_pool_->stats_.back(), this); | 27 zone_stats_->stats_.pop_back(); |
| 28 zone_pool_->stats_.pop_back(); | |
| 29 } | 28 } |
| 30 | 29 |
| 31 | 30 size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() { |
| 32 size_t ZonePool::StatsScope::GetMaxAllocatedBytes() { | |
| 33 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); | 31 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); |
| 34 } | 32 } |
| 35 | 33 |
| 36 | 34 size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() { |
| 37 size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() { | |
| 38 size_t total = 0; | 35 size_t total = 0; |
| 39 for (Zone* zone : zone_pool_->used_) { | 36 for (Zone* zone : zone_stats_->used_) { |
| 40 total += static_cast<size_t>(zone->allocation_size()); | 37 total += static_cast<size_t>(zone->allocation_size()); |
| 41 // Adjust for initial values. | 38 // Adjust for initial values. |
| 42 InitialValues::iterator it = initial_values_.find(zone); | 39 InitialValues::iterator it = initial_values_.find(zone); |
| 43 if (it != initial_values_.end()) { | 40 if (it != initial_values_.end()) { |
| 44 total -= it->second; | 41 total -= it->second; |
| 45 } | 42 } |
| 46 } | 43 } |
| 47 return total; | 44 return total; |
| 48 } | 45 } |
| 49 | 46 |
| 50 | 47 size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() { |
| 51 size_t ZonePool::StatsScope::GetTotalAllocatedBytes() { | 48 return zone_stats_->GetTotalAllocatedBytes() - |
| 52 return zone_pool_->GetTotalAllocatedBytes() - total_allocated_bytes_at_start_; | 49 total_allocated_bytes_at_start_; |
| 53 } | 50 } |
| 54 | 51 |
| 55 | 52 void ZoneStats::StatsScope::ZoneReturned(Zone* zone) { |
| 56 void ZonePool::StatsScope::ZoneReturned(Zone* zone) { | |
| 57 size_t current_total = GetCurrentAllocatedBytes(); | 53 size_t current_total = GetCurrentAllocatedBytes(); |
| 58 // Update max. | 54 // Update max. |
| 59 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); | 55 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); |
| 60 // Drop zone from initial value map. | 56 // Drop zone from initial value map. |
| 61 InitialValues::iterator it = initial_values_.find(zone); | 57 InitialValues::iterator it = initial_values_.find(zone); |
| 62 if (it != initial_values_.end()) { | 58 if (it != initial_values_.end()) { |
| 63 initial_values_.erase(it); | 59 initial_values_.erase(it); |
| 64 } | 60 } |
| 65 } | 61 } |
| 66 | 62 |
| 67 ZonePool::ZonePool(AccountingAllocator* allocator) | 63 ZoneStats::ZoneStats(AccountingAllocator* allocator) |
| 68 : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {} | 64 : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {} |
| 69 | 65 |
| 70 ZonePool::~ZonePool() { | 66 ZoneStats::~ZoneStats() { |
| 71 DCHECK(used_.empty()); | 67 DCHECK(used_.empty()); |
| 72 DCHECK(stats_.empty()); | 68 DCHECK(stats_.empty()); |
| 73 for (Zone* zone : unused_) { | |
| 74 delete zone; | |
| 75 } | |
| 76 } | 69 } |
| 77 | 70 |
| 78 | 71 size_t ZoneStats::GetMaxAllocatedBytes() { |
| 79 size_t ZonePool::GetMaxAllocatedBytes() { | |
| 80 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); | 72 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); |
| 81 } | 73 } |
| 82 | 74 |
| 83 | 75 size_t ZoneStats::GetCurrentAllocatedBytes() { |
| 84 size_t ZonePool::GetCurrentAllocatedBytes() { | |
| 85 size_t total = 0; | 76 size_t total = 0; |
| 86 for (Zone* zone : used_) { | 77 for (Zone* zone : used_) { |
| 87 total += static_cast<size_t>(zone->allocation_size()); | 78 total += static_cast<size_t>(zone->allocation_size()); |
| 88 } | 79 } |
| 89 return total; | 80 return total; |
| 90 } | 81 } |
| 91 | 82 |
| 92 | 83 size_t ZoneStats::GetTotalAllocatedBytes() { |
| 93 size_t ZonePool::GetTotalAllocatedBytes() { | |
| 94 return total_deleted_bytes_ + GetCurrentAllocatedBytes(); | 84 return total_deleted_bytes_ + GetCurrentAllocatedBytes(); |
| 95 } | 85 } |
| 96 | 86 |
| 97 | 87 Zone* ZoneStats::NewEmptyZone() { |
| 98 Zone* ZonePool::NewEmptyZone() { | 88 Zone* zone = new Zone(allocator_); |
| 99 Zone* zone; | |
| 100 // Grab a zone from pool if possible. | |
| 101 if (!unused_.empty()) { | |
| 102 zone = unused_.back(); | |
| 103 unused_.pop_back(); | |
| 104 } else { | |
| 105 zone = new Zone(allocator_); | |
| 106 } | |
| 107 used_.push_back(zone); | 89 used_.push_back(zone); |
|
Toon Verwaest
2016/09/21 11:31:03
Does it still make sense to call this "used_" rath
| |
| 108 DCHECK_EQ(0u, zone->allocation_size()); | |
| 109 return zone; | 90 return zone; |
| 110 } | 91 } |
| 111 | 92 |
| 112 | 93 void ZoneStats::ReturnZone(Zone* zone) { |
|
Toon Verwaest
2016/09/21 11:31:03
Does it make sense to call this Return, now that t
| |
| 113 void ZonePool::ReturnZone(Zone* zone) { | |
| 114 size_t current_total = GetCurrentAllocatedBytes(); | 94 size_t current_total = GetCurrentAllocatedBytes(); |
| 115 // Update max. | 95 // Update max. |
| 116 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); | 96 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); |
| 117 // Update stats. | 97 // Update stats. |
| 118 for (StatsScope* stat_scope : stats_) { | 98 for (StatsScope* stat_scope : stats_) { |
| 119 stat_scope->ZoneReturned(zone); | 99 stat_scope->ZoneReturned(zone); |
| 120 } | 100 } |
| 121 // Remove from used. | 101 // Remove from used. |
| 122 Used::iterator it = std::find(used_.begin(), used_.end(), zone); | 102 Used::iterator it = std::find(used_.begin(), used_.end(), zone); |
| 123 DCHECK(it != used_.end()); | 103 DCHECK(it != used_.end()); |
| 124 used_.erase(it); | 104 used_.erase(it); |
| 125 total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size()); | 105 total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size()); |
| 126 // Delete zone or clear and stash on unused_. | 106 delete zone; |
| 127 if (unused_.size() >= kMaxUnusedSize) { | |
| 128 delete zone; | |
| 129 } else { | |
| 130 zone->DeleteAll(); | |
| 131 DCHECK_EQ(0u, zone->allocation_size()); | |
| 132 unused_.push_back(zone); | |
| 133 } | |
| 134 } | 107 } |
| 135 | 108 |
| 136 } // namespace compiler | 109 } // namespace compiler |
| 137 } // namespace internal | 110 } // namespace internal |
| 138 } // namespace v8 | 111 } // namespace v8 |
| OLD | NEW |