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 #ifndef V8_COMPILER_ZONE_POOL_H_ |
| 6 #define V8_COMPILER_ZONE_POOL_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <vector> |
| 11 |
| 12 #include "src/v8.h" |
| 13 |
| 14 namespace v8 { |
| 15 namespace internal { |
| 16 namespace compiler { |
| 17 |
| 18 class ZonePool FINAL { |
| 19 public: |
| 20 class Scope FINAL { |
| 21 public: |
| 22 explicit Scope(ZonePool* zone_pool) : zone_pool_(zone_pool), zone_(NULL) {} |
| 23 ~Scope() { Destroy(); } |
| 24 |
| 25 Zone* zone() { |
| 26 if (zone_ == NULL) zone_ = zone_pool_->GetEmptyZone(); |
| 27 return zone_; |
| 28 } |
| 29 void Destroy() { |
| 30 if (zone_ != NULL) zone_pool_->ReturnZone(zone_); |
| 31 zone_ = NULL; |
| 32 } |
| 33 |
| 34 private: |
| 35 ZonePool* const zone_pool_; |
| 36 Zone* zone_; |
| 37 DISALLOW_COPY_AND_ASSIGN(Scope); |
| 38 }; |
| 39 |
| 40 class StatsScope FINAL { |
| 41 public: |
| 42 explicit StatsScope(ZonePool* zone_pool); |
| 43 ~StatsScope(); |
| 44 |
| 45 size_t GetMaxAllocatedBytes(); |
| 46 size_t GetCurrentAllocatedBytes(); |
| 47 |
| 48 private: |
| 49 friend class ZonePool; |
| 50 void ZoneReturned(Zone* zone); |
| 51 |
| 52 typedef std::map<Zone*, size_t> InitialValues; |
| 53 |
| 54 ZonePool* const zone_pool_; |
| 55 InitialValues initial_values_; |
| 56 size_t max_allocated_bytes_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(StatsScope); |
| 59 }; |
| 60 |
| 61 explicit ZonePool(Isolate* isolate); |
| 62 ~ZonePool() { DCHECK(used_.empty()); } |
| 63 |
| 64 size_t GetMaxAllocatedBytes(); |
| 65 size_t GetTotalAllocatedBytes(); |
| 66 size_t GetCurrentAllocatedBytes(); |
| 67 |
| 68 private: |
| 69 Zone* GetEmptyZone(); |
| 70 void ReturnZone(Zone* zone); |
| 71 |
| 72 static const size_t kMaxUnusedSize = 3; |
| 73 typedef std::vector<Zone*> Unused; |
| 74 typedef std::vector<Zone*> Used; |
| 75 typedef std::vector<StatsScope*> Stats; |
| 76 |
| 77 Isolate* const isolate_; |
| 78 Unused unused_; |
| 79 Used used_; |
| 80 Stats stats_; |
| 81 size_t max_allocated_bytes_; |
| 82 size_t total_deleted_bytes_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(ZonePool); |
| 85 }; |
| 86 |
| 87 } // namespace compiler |
| 88 } // namespace internal |
| 89 } // namespace v8 |
| 90 |
| 91 #endif |
OLD | NEW |