Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/compiler/zone-pool.h" | |
| 6 | |
| 7 namespace v8 { | |
| 8 namespace internal { | |
| 9 namespace compiler { | |
| 10 | |
| 11 ZonePool::StatsScope::StatsScope(ZonePool* zone_pool) | |
| 12 : zone_pool_(zone_pool), max_allocated_bytes_(0) { | |
| 13 zone_pool_->stats_.push_back(this); | |
| 14 for (auto zone : zone_pool_->used_) { | |
| 15 size_t size = static_cast<size_t>(zone->allocation_size()); | |
| 16 std::pair<InitialValues::iterator, bool> res = | |
| 17 initial_values_.insert(std::make_pair(zone, size)); | |
| 18 USE(res); | |
| 19 DCHECK(res.second); | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 | |
| 24 ZonePool::StatsScope::~StatsScope() { | |
| 25 DCHECK_EQ(zone_pool_->stats_.back(), this); | |
| 26 zone_pool_->stats_.pop_back(); | |
| 27 } | |
| 28 | |
| 29 | |
| 30 size_t ZonePool::StatsScope::GetMaxAllocatedBytes() { | |
| 31 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() { | |
| 36 size_t total = 0; | |
| 37 for (Zone* zone : zone_pool_->used_) { | |
| 38 total += static_cast<size_t>(zone->allocation_size()); | |
| 39 // Adjust for initial values. | |
| 40 InitialValues::iterator it = initial_values_.find(zone); | |
| 41 if (it != initial_values_.end()) { | |
| 42 total -= it->second; | |
| 43 } | |
| 44 } | |
| 45 return total; | |
| 46 } | |
| 47 | |
| 48 | |
| 49 void ZonePool::StatsScope::ZoneReturned(Zone* zone) { | |
| 50 size_t current_total = GetCurrentAllocatedBytes(); | |
| 51 // Update max. | |
| 52 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); | |
| 53 // Drop zone from initial value map. | |
| 54 InitialValues::iterator it = initial_values_.find(zone); | |
| 55 if (it != initial_values_.end()) { | |
| 56 initial_values_.erase(it); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 | |
| 61 ZonePool::ZonePool(Isolate* isolate) | |
| 62 : isolate_(isolate), max_allocated_bytes_(0), total_deleted_bytes_(0) {} | |
| 63 | |
| 64 | |
| 65 size_t ZonePool::GetMaxAllocatedBytes() { | |
| 66 return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); | |
| 67 } | |
| 68 | |
| 69 | |
| 70 size_t ZonePool::GetCurrentAllocatedBytes() { | |
| 71 size_t total = 0; | |
| 72 for (Zone* zone : used_) { | |
| 73 total += static_cast<size_t>(zone->allocation_size()); | |
| 74 } | |
| 75 return total; | |
| 76 } | |
| 77 | |
| 78 | |
| 79 size_t ZonePool::GetTotalAllocatedBytes() { | |
| 80 return total_deleted_bytes_ + GetCurrentAllocatedBytes(); | |
| 81 } | |
| 82 | |
| 83 | |
| 84 Zone* ZonePool::GetEmptyZone() { | |
|
Benedikt Meurer
2014/10/21 10:55:33
This should not be called Get*.
| |
| 85 Zone* zone; | |
| 86 // Grab a zone from pool if possible. | |
| 87 if (!unused_.empty()) { | |
| 88 zone = unused_.back(); | |
| 89 unused_.pop_back(); | |
| 90 } else { | |
| 91 zone = new Zone(isolate_); | |
| 92 } | |
| 93 used_.push_back(zone); | |
| 94 DCHECK_EQ(0, zone->allocation_size()); | |
| 95 return zone; | |
| 96 } | |
| 97 | |
| 98 | |
| 99 void ZonePool::ReturnZone(Zone* zone) { | |
| 100 size_t current_total = GetCurrentAllocatedBytes(); | |
| 101 // Update max. | |
| 102 max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); | |
| 103 // Take from used. | |
| 104 Used::iterator it = std::find(used_.begin(), used_.end(), zone); | |
| 105 DCHECK(it != used_.end()); | |
| 106 used_.erase(it); | |
| 107 total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size()); | |
| 108 // Update stats. | |
| 109 for (auto stat_scope : stats_) { | |
| 110 stat_scope->ZoneReturned(zone); | |
| 111 } | |
| 112 // Delete zone or clear and stash on unused_. | |
| 113 if (unused_.size() >= kMaxUnusedSize) { | |
| 114 delete zone; | |
| 115 } else { | |
| 116 zone->DeleteAll(); | |
| 117 DCHECK_EQ(0, zone->allocation_size()); | |
| 118 unused_.push_back(zone); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace compiler | |
| 123 } // namespace internal | |
| 124 } // namespace v8 | |
| OLD | NEW |