v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
zone-stats.h
Go to the documentation of this file.
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_STATS_H_
6#define V8_COMPILER_ZONE_STATS_H_
7
8#include <map>
9#include <vector>
10
11#include "src/zone/zone.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
18 public:
19 class V8_NODISCARD Scope final {
20 public:
21 explicit Scope(ZoneStats* zone_stats, const char* zone_name,
22 bool support_zone_compression = false)
23 : zone_name_(zone_name),
24 zone_stats_(zone_stats),
25 zone_(nullptr),
26 support_zone_compression_(support_zone_compression) {}
27 ~Scope() { Destroy(); }
28
29 Scope(const Scope&) = delete;
31 : zone_name_(other.zone_name_),
32 zone_stats_(other.zone_stats_),
33 zone_(nullptr),
34 support_zone_compression_(other.support_zone_compression_) {
35 std::swap(zone_, other.zone_);
36 }
37 Scope& operator=(const Scope&) = delete;
39 Destroy();
40 zone_name_ = other.zone_name_;
41 zone_stats_ = other.zone_stats_;
42 support_zone_compression_ = other.support_zone_compression_;
44 std::swap(zone_, other.zone_);
45 return *this;
46 }
47
49 if (zone_ == nullptr)
50 zone_ =
51 zone_stats_->NewEmptyZone(zone_name_, support_zone_compression_);
52 return zone_;
53 }
54 void Destroy() {
55 if (zone_ != nullptr) zone_stats_->ReturnZone(zone_);
56 zone_ = nullptr;
57 }
58
59 ZoneStats* zone_stats() const { return zone_stats_; }
60
61 private:
62 const char* zone_name_;
66 };
67
69 public:
70 explicit StatsScope(ZoneStats* zone_stats);
72 StatsScope(const StatsScope&) = delete;
73 StatsScope& operator=(const StatsScope&) = delete;
74
75 size_t GetMaxAllocatedBytes();
76 size_t GetCurrentAllocatedBytes();
77 size_t GetTotalAllocatedBytes();
78
79 private:
80 friend class ZoneStats;
81 void ZoneReturned(Zone* zone);
82
83 using InitialValues = std::map<Zone*, size_t>;
84
89 };
90
91 explicit ZoneStats(AccountingAllocator* allocator);
92 ~ZoneStats();
93 ZoneStats(const ZoneStats&) = delete;
94 ZoneStats& operator=(const ZoneStats&) = delete;
95
96 size_t GetMaxAllocatedBytes() const;
97 size_t GetTotalAllocatedBytes() const;
98 size_t GetCurrentAllocatedBytes() const;
99
100 private:
101 Zone* NewEmptyZone(const char* zone_name, bool support_zone_compression);
102 void ReturnZone(Zone* zone);
103
104 static const size_t kMaxUnusedSize = 3;
105 using Zones = std::vector<Zone*>;
106 using Stats = std::vector<StatsScope*>;
107
113};
114
115} // namespace compiler
116} // namespace internal
117} // namespace v8
118
119#endif // V8_COMPILER_ZONE_STATS_H_
Scope & operator=(Scope &&other) V8_NOEXCEPT
Definition zone-stats.h:38
Scope(ZoneStats *zone_stats, const char *zone_name, bool support_zone_compression=false)
Definition zone-stats.h:21
Scope(Scope &&other) V8_NOEXCEPT
Definition zone-stats.h:30
Scope & operator=(const Scope &)=delete
std::map< Zone *, size_t > InitialValues
Definition zone-stats.h:83
StatsScope & operator=(const StatsScope &)=delete
std::vector< StatsScope * > Stats
Definition zone-stats.h:106
std::vector< Zone * > Zones
Definition zone-stats.h:105
ZoneStats & operator=(const ZoneStats &)=delete
ZoneStats(const ZoneStats &)=delete
AccountingAllocator * allocator_
Definition zone-stats.h:112
Zone * zone_
#define V8_NOEXCEPT
#define DCHECK_NULL(val)
Definition logging.h:491
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_NODISCARD
Definition v8config.h:693