Commit fc840361 authored by heimbuef's avatar heimbuef Committed by Commit bot

Replaced different means of zone pooling/reusing by one zone segment pool

BUG=v8:5409

Committed: https://crrev.com/a124feb0760896c8be61de08004a08c3bc9b4b3f
Review-Url: https://codereview.chromium.org/2348303002
Cr-Original-Commit-Position: refs/heads/master@{#39633}
Cr-Commit-Position: refs/heads/master@{#40048}
parent c9b908a0
...@@ -1177,8 +1177,8 @@ v8_source_set("v8_base") { ...@@ -1177,8 +1177,8 @@ v8_source_set("v8_base") {
"src/compiler/wasm-compiler.cc", "src/compiler/wasm-compiler.cc",
"src/compiler/wasm-compiler.h", "src/compiler/wasm-compiler.h",
"src/compiler/wasm-linkage.cc", "src/compiler/wasm-linkage.cc",
"src/compiler/zone-pool.cc", "src/compiler/zone-stats.cc",
"src/compiler/zone-pool.h", "src/compiler/zone-stats.h",
"src/context-measure.cc", "src/context-measure.cc",
"src/context-measure.h", "src/context-measure.h",
"src/contexts-inl.h", "src/contexts-inl.h",
......
...@@ -317,7 +317,7 @@ void MoveOptimizer::OptimizeMerge(InstructionBlock* block) { ...@@ -317,7 +317,7 @@ void MoveOptimizer::OptimizeMerge(InstructionBlock* block) {
if (!op->IsConstant() && !op->IsImmediate()) return; if (!op->IsConstant() && !op->IsImmediate()) return;
} }
} }
// TODO(dcarney): pass a ZonePool down for this? // TODO(dcarney): pass a ZoneStats down for this?
MoveMap move_map(local_zone()); MoveMap move_map(local_zone());
size_t correct_counts = 0; size_t correct_counts = 0;
// Accumulate set of shared moves. // Accumulate set of shared moves.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "src/compilation-info.h" #include "src/compilation-info.h"
#include "src/compiler/pipeline-statistics.h" #include "src/compiler/pipeline-statistics.h"
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
#include "src/isolate.h" #include "src/isolate.h"
namespace v8 { namespace v8 {
...@@ -16,13 +16,13 @@ namespace compiler { ...@@ -16,13 +16,13 @@ namespace compiler {
void PipelineStatistics::CommonStats::Begin( void PipelineStatistics::CommonStats::Begin(
PipelineStatistics* pipeline_stats) { PipelineStatistics* pipeline_stats) {
DCHECK(!scope_); DCHECK(!scope_);
scope_.reset(new ZonePool::StatsScope(pipeline_stats->zone_pool_)); scope_.reset(new ZoneStats::StatsScope(pipeline_stats->zone_stats_));
timer_.Start(); timer_.Start();
outer_zone_initial_size_ = pipeline_stats->OuterZoneSize(); outer_zone_initial_size_ = pipeline_stats->OuterZoneSize();
allocated_bytes_at_start_ = allocated_bytes_at_start_ =
outer_zone_initial_size_ - outer_zone_initial_size_ -
pipeline_stats->total_stats_.outer_zone_initial_size_ + pipeline_stats->total_stats_.outer_zone_initial_size_ +
pipeline_stats->zone_pool_->GetCurrentAllocatedBytes(); pipeline_stats->zone_stats_->GetCurrentAllocatedBytes();
} }
...@@ -43,12 +43,11 @@ void PipelineStatistics::CommonStats::End( ...@@ -43,12 +43,11 @@ void PipelineStatistics::CommonStats::End(
timer_.Stop(); timer_.Stop();
} }
PipelineStatistics::PipelineStatistics(CompilationInfo* info, PipelineStatistics::PipelineStatistics(CompilationInfo* info,
ZonePool* zone_pool) ZoneStats* zone_stats)
: isolate_(info->isolate()), : isolate_(info->isolate()),
outer_zone_(info->zone()), outer_zone_(info->zone()),
zone_pool_(zone_pool), zone_stats_(zone_stats),
compilation_stats_(isolate_->GetTurboStatistics()), compilation_stats_(isolate_->GetTurboStatistics()),
source_size_(0), source_size_(0),
phase_kind_name_(nullptr), phase_kind_name_(nullptr),
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "src/base/platform/elapsed-timer.h" #include "src/base/platform/elapsed-timer.h"
#include "src/compilation-statistics.h" #include "src/compilation-statistics.h"
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -20,7 +20,7 @@ class PhaseScope; ...@@ -20,7 +20,7 @@ class PhaseScope;
class PipelineStatistics : public Malloced { class PipelineStatistics : public Malloced {
public: public:
PipelineStatistics(CompilationInfo* info, ZonePool* zone_pool); PipelineStatistics(CompilationInfo* info, ZoneStats* zone_stats);
~PipelineStatistics(); ~PipelineStatistics();
void BeginPhaseKind(const char* phase_kind_name); void BeginPhaseKind(const char* phase_kind_name);
...@@ -39,7 +39,7 @@ class PipelineStatistics : public Malloced { ...@@ -39,7 +39,7 @@ class PipelineStatistics : public Malloced {
void End(PipelineStatistics* pipeline_stats, void End(PipelineStatistics* pipeline_stats,
CompilationStatistics::BasicStats* diff); CompilationStatistics::BasicStats* diff);
std::unique_ptr<ZonePool::StatsScope> scope_; std::unique_ptr<ZoneStats::StatsScope> scope_;
base::ElapsedTimer timer_; base::ElapsedTimer timer_;
size_t outer_zone_initial_size_; size_t outer_zone_initial_size_;
size_t allocated_bytes_at_start_; size_t allocated_bytes_at_start_;
...@@ -57,7 +57,7 @@ class PipelineStatistics : public Malloced { ...@@ -57,7 +57,7 @@ class PipelineStatistics : public Malloced {
Isolate* isolate_; Isolate* isolate_;
Zone* outer_zone_; Zone* outer_zone_;
ZonePool* zone_pool_; ZoneStats* zone_stats_;
CompilationStatistics* compilation_stats_; CompilationStatistics* compilation_stats_;
std::string function_name_; std::string function_name_;
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/opcodes.h" #include "src/compiler/opcodes.h"
#include "src/compiler/schedule.h" #include "src/compiler/schedule.h"
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
namespace v8 { namespace v8 {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/source-position.h" #include "src/compiler/source-position.h"
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/code-stubs.h" #include "src/code-stubs.h"
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
ZonePool::StatsScope::StatsScope(ZonePool* zone_pool) ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
: zone_pool_(zone_pool), : zone_stats_(zone_stats),
total_allocated_bytes_at_start_(zone_pool->GetTotalAllocatedBytes()), total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()),
max_allocated_bytes_(0) { max_allocated_bytes_(0) {
zone_pool_->stats_.push_back(this); zone_stats_->stats_.push_back(this);
for (Zone* zone : zone_pool_->used_) { for (Zone* zone : zone_stats_->zones_) {
size_t size = static_cast<size_t>(zone->allocation_size()); size_t size = static_cast<size_t>(zone->allocation_size());
std::pair<InitialValues::iterator, bool> res = std::pair<InitialValues::iterator, bool> res =
initial_values_.insert(std::make_pair(zone, size)); initial_values_.insert(std::make_pair(zone, size));
...@@ -22,21 +22,18 @@ ZonePool::StatsScope::StatsScope(ZonePool* zone_pool) ...@@ -22,21 +22,18 @@ ZonePool::StatsScope::StatsScope(ZonePool* zone_pool)
} }
} }
ZoneStats::StatsScope::~StatsScope() {
ZonePool::StatsScope::~StatsScope() { DCHECK_EQ(zone_stats_->stats_.back(), this);
DCHECK_EQ(zone_pool_->stats_.back(), this); zone_stats_->stats_.pop_back();
zone_pool_->stats_.pop_back();
} }
size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() {
size_t ZonePool::StatsScope::GetMaxAllocatedBytes() {
return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
} }
size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() {
size_t total = 0; size_t total = 0;
for (Zone* zone : zone_pool_->used_) { for (Zone* zone : zone_stats_->zones_) {
total += static_cast<size_t>(zone->allocation_size()); total += static_cast<size_t>(zone->allocation_size());
// Adjust for initial values. // Adjust for initial values.
InitialValues::iterator it = initial_values_.find(zone); InitialValues::iterator it = initial_values_.find(zone);
...@@ -47,13 +44,12 @@ size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() { ...@@ -47,13 +44,12 @@ size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() {
return total; return total;
} }
size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() {
size_t ZonePool::StatsScope::GetTotalAllocatedBytes() { return zone_stats_->GetTotalAllocatedBytes() -
return zone_pool_->GetTotalAllocatedBytes() - total_allocated_bytes_at_start_; total_allocated_bytes_at_start_;
} }
void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
void ZonePool::StatsScope::ZoneReturned(Zone* zone) {
size_t current_total = GetCurrentAllocatedBytes(); size_t current_total = GetCurrentAllocatedBytes();
// Update max. // Update max.
max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
...@@ -64,53 +60,37 @@ void ZonePool::StatsScope::ZoneReturned(Zone* zone) { ...@@ -64,53 +60,37 @@ void ZonePool::StatsScope::ZoneReturned(Zone* zone) {
} }
} }
ZonePool::ZonePool(AccountingAllocator* allocator) ZoneStats::ZoneStats(AccountingAllocator* allocator)
: max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {} : max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {}
ZonePool::~ZonePool() { ZoneStats::~ZoneStats() {
DCHECK(used_.empty()); DCHECK(zones_.empty());
DCHECK(stats_.empty()); DCHECK(stats_.empty());
for (Zone* zone : unused_) {
delete zone;
}
} }
size_t ZoneStats::GetMaxAllocatedBytes() {
size_t ZonePool::GetMaxAllocatedBytes() {
return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes()); return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
} }
size_t ZoneStats::GetCurrentAllocatedBytes() {
size_t ZonePool::GetCurrentAllocatedBytes() {
size_t total = 0; size_t total = 0;
for (Zone* zone : used_) { for (Zone* zone : zones_) {
total += static_cast<size_t>(zone->allocation_size()); total += static_cast<size_t>(zone->allocation_size());
} }
return total; return total;
} }
size_t ZoneStats::GetTotalAllocatedBytes() {
size_t ZonePool::GetTotalAllocatedBytes() {
return total_deleted_bytes_ + GetCurrentAllocatedBytes(); return total_deleted_bytes_ + GetCurrentAllocatedBytes();
} }
Zone* ZoneStats::NewEmptyZone() {
Zone* ZonePool::NewEmptyZone() { Zone* zone = new Zone(allocator_);
Zone* zone; zones_.push_back(zone);
// Grab a zone from pool if possible.
if (!unused_.empty()) {
zone = unused_.back();
unused_.pop_back();
} else {
zone = new Zone(allocator_);
}
used_.push_back(zone);
DCHECK_EQ(0u, zone->allocation_size());
return zone; return zone;
} }
void ZoneStats::ReturnZone(Zone* zone) {
void ZonePool::ReturnZone(Zone* zone) {
size_t current_total = GetCurrentAllocatedBytes(); size_t current_total = GetCurrentAllocatedBytes();
// Update max. // Update max.
max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total); max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
...@@ -119,18 +99,11 @@ void ZonePool::ReturnZone(Zone* zone) { ...@@ -119,18 +99,11 @@ void ZonePool::ReturnZone(Zone* zone) {
stat_scope->ZoneReturned(zone); stat_scope->ZoneReturned(zone);
} }
// Remove from used. // Remove from used.
Used::iterator it = std::find(used_.begin(), used_.end(), zone); Zones::iterator it = std::find(zones_.begin(), zones_.end(), zone);
DCHECK(it != used_.end()); DCHECK(it != zones_.end());
used_.erase(it); zones_.erase(it);
total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size()); total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size());
// Delete zone or clear and stash on unused_. delete zone;
if (unused_.size() >= kMaxUnusedSize) {
delete zone;
} else {
zone->DeleteAll();
DCHECK_EQ(0u, zone->allocation_size());
unused_.push_back(zone);
}
} }
} // namespace compiler } // namespace compiler
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef V8_COMPILER_ZONE_POOL_H_ #ifndef V8_COMPILER_ZONE_STATS_H_
#define V8_COMPILER_ZONE_POOL_H_ #define V8_COMPILER_ZONE_STATS_H_
#include <map> #include <map>
#include <set> #include <set>
...@@ -15,32 +15,32 @@ namespace v8 { ...@@ -15,32 +15,32 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class ZonePool final { class ZoneStats final {
public: public:
class Scope final { class Scope final {
public: public:
explicit Scope(ZonePool* zone_pool) explicit Scope(ZoneStats* zone_stats)
: zone_pool_(zone_pool), zone_(nullptr) {} : zone_stats_(zone_stats), zone_(nullptr) {}
~Scope() { Destroy(); } ~Scope() { Destroy(); }
Zone* zone() { Zone* zone() {
if (zone_ == nullptr) zone_ = zone_pool_->NewEmptyZone(); if (zone_ == nullptr) zone_ = zone_stats_->NewEmptyZone();
return zone_; return zone_;
} }
void Destroy() { void Destroy() {
if (zone_ != nullptr) zone_pool_->ReturnZone(zone_); if (zone_ != nullptr) zone_stats_->ReturnZone(zone_);
zone_ = nullptr; zone_ = nullptr;
} }
private: private:
ZonePool* const zone_pool_; ZoneStats* const zone_stats_;
Zone* zone_; Zone* zone_;
DISALLOW_COPY_AND_ASSIGN(Scope); DISALLOW_COPY_AND_ASSIGN(Scope);
}; };
class StatsScope final { class StatsScope final {
public: public:
explicit StatsScope(ZonePool* zone_pool); explicit StatsScope(ZoneStats* zone_stats);
~StatsScope(); ~StatsScope();
size_t GetMaxAllocatedBytes(); size_t GetMaxAllocatedBytes();
...@@ -48,12 +48,12 @@ class ZonePool final { ...@@ -48,12 +48,12 @@ class ZonePool final {
size_t GetTotalAllocatedBytes(); size_t GetTotalAllocatedBytes();
private: private:
friend class ZonePool; friend class ZoneStats;
void ZoneReturned(Zone* zone); void ZoneReturned(Zone* zone);
typedef std::map<Zone*, size_t> InitialValues; typedef std::map<Zone*, size_t> InitialValues;
ZonePool* const zone_pool_; ZoneStats* const zone_stats_;
InitialValues initial_values_; InitialValues initial_values_;
size_t total_allocated_bytes_at_start_; size_t total_allocated_bytes_at_start_;
size_t max_allocated_bytes_; size_t max_allocated_bytes_;
...@@ -61,8 +61,8 @@ class ZonePool final { ...@@ -61,8 +61,8 @@ class ZonePool final {
DISALLOW_COPY_AND_ASSIGN(StatsScope); DISALLOW_COPY_AND_ASSIGN(StatsScope);
}; };
explicit ZonePool(AccountingAllocator* allocator); explicit ZoneStats(AccountingAllocator* allocator);
~ZonePool(); ~ZoneStats();
size_t GetMaxAllocatedBytes(); size_t GetMaxAllocatedBytes();
size_t GetTotalAllocatedBytes(); size_t GetTotalAllocatedBytes();
...@@ -73,22 +73,20 @@ class ZonePool final { ...@@ -73,22 +73,20 @@ class ZonePool final {
void ReturnZone(Zone* zone); void ReturnZone(Zone* zone);
static const size_t kMaxUnusedSize = 3; static const size_t kMaxUnusedSize = 3;
typedef std::vector<Zone*> Unused; typedef std::vector<Zone*> Zones;
typedef std::vector<Zone*> Used;
typedef std::vector<StatsScope*> Stats; typedef std::vector<StatsScope*> Stats;
Unused unused_; Zones zones_;
Used used_;
Stats stats_; Stats stats_;
size_t max_allocated_bytes_; size_t max_allocated_bytes_;
size_t total_deleted_bytes_; size_t total_deleted_bytes_;
AccountingAllocator* allocator_; AccountingAllocator* allocator_;
DISALLOW_COPY_AND_ASSIGN(ZonePool); DISALLOW_COPY_AND_ASSIGN(ZoneStats);
}; };
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
#endif #endif // V8_COMPILER_ZONE_STATS_H_
...@@ -741,8 +741,8 @@ ...@@ -741,8 +741,8 @@
'compiler/wasm-compiler.cc', 'compiler/wasm-compiler.cc',
'compiler/wasm-compiler.h', 'compiler/wasm-compiler.h',
'compiler/wasm-linkage.cc', 'compiler/wasm-linkage.cc',
'compiler/zone-pool.cc', 'compiler/zone-stats.cc',
'compiler/zone-pool.h', 'compiler/zone-stats.h',
'compiler-dispatcher/compiler-dispatcher-job.cc', 'compiler-dispatcher/compiler-dispatcher-job.cc',
'compiler-dispatcher/compiler-dispatcher-job.h', 'compiler-dispatcher/compiler-dispatcher-job.h',
'compiler-dispatcher/optimizing-compile-dispatcher.cc', 'compiler-dispatcher/optimizing-compile-dispatcher.cc',
......
...@@ -105,9 +105,7 @@ void Zone::DeleteAll() { ...@@ -105,9 +105,7 @@ void Zone::DeleteAll() {
} }
position_ = limit_ = 0; position_ = limit_ = 0;
allocation_size_ = 0; allocation_size_ = 0;
// Update the head segment to be the kept segment (if any).
segment_head_ = nullptr; segment_head_ = nullptr;
} }
......
...@@ -44,9 +44,6 @@ class V8_EXPORT_PRIVATE Zone final { ...@@ -44,9 +44,6 @@ class V8_EXPORT_PRIVATE Zone final {
return static_cast<T*>(New(length * sizeof(T))); return static_cast<T*>(New(length * sizeof(T)));
} }
// Deletes all objects and free all memory allocated in the Zone.
void DeleteAll();
// Returns true if more memory has been allocated in zones than // Returns true if more memory has been allocated in zones than
// the limit allows. // the limit allows.
bool excess_allocation() const { bool excess_allocation() const {
...@@ -78,6 +75,9 @@ class V8_EXPORT_PRIVATE Zone final { ...@@ -78,6 +75,9 @@ class V8_EXPORT_PRIVATE Zone final {
// Report zone excess when allocation exceeds this limit. // Report zone excess when allocation exceeds this limit.
static const size_t kExcessLimit = 256 * MB; static const size_t kExcessLimit = 256 * MB;
// Deletes all objects and free all memory allocated in the Zone.
void DeleteAll();
// The number of bytes allocated in this zone so far. // The number of bytes allocated in this zone so far.
size_t allocation_size_; size_t allocation_size_;
...@@ -126,19 +126,6 @@ class ZoneObject { ...@@ -126,19 +126,6 @@ class ZoneObject {
void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
}; };
// The ZoneScope is used to automatically call DeleteAll() on a
// Zone when the ZoneScope is destroyed (i.e. goes out of scope)
class ZoneScope final {
public:
explicit ZoneScope(Zone* zone) : zone_(zone) {}
~ZoneScope() { zone_->DeleteAll(); }
Zone* zone() const { return zone_; }
private:
Zone* zone_;
};
// The ZoneAllocationPolicy is used to specialize generic data // The ZoneAllocationPolicy is used to specialize generic data
// structures to allocate themselves and their elements in the Zone. // structures to allocate themselves and their elements in the Zone.
class ZoneAllocationPolicy final { class ZoneAllocationPolicy final {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <memory> #include <memory>
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
...@@ -20,8 +19,7 @@ ...@@ -20,8 +19,7 @@
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/wasm-compiler.h" #include "src/compiler/wasm-compiler.h"
#include "src/compiler/zone-pool.h" #include "src/compiler/zone-stats.h"
#include "src/wasm/ast-decoder.h" #include "src/wasm/ast-decoder.h"
#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h" #include "src/wasm/wasm-js.h"
......
...@@ -82,7 +82,7 @@ v8_executable("unittests") { ...@@ -82,7 +82,7 @@ v8_executable("unittests") {
"compiler/typed-optimization-unittest.cc", "compiler/typed-optimization-unittest.cc",
"compiler/typer-unittest.cc", "compiler/typer-unittest.cc",
"compiler/value-numbering-reducer-unittest.cc", "compiler/value-numbering-reducer-unittest.cc",
"compiler/zone-pool-unittest.cc", "compiler/zone-stats-unittest.cc",
"counters-unittest.cc", "counters-unittest.cc",
"eh-frame-iterator-unittest.cc", "eh-frame-iterator-unittest.cc",
"eh-frame-writer-unittest.cc", "eh-frame-writer-unittest.cc",
......
...@@ -2,28 +2,28 @@ ...@@ -2,28 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/zone-stats.h"
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
#include "src/compiler/zone-pool.h"
#include "test/unittests/test-utils.h" #include "test/unittests/test-utils.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class ZonePoolTest : public TestWithIsolate { class ZoneStatsTest : public TestWithIsolate {
public: public:
ZonePoolTest() : zone_pool_(&allocator_) {} ZoneStatsTest() : zone_stats_(&allocator_) {}
protected: protected:
ZonePool* zone_pool() { return &zone_pool_; } ZoneStats* zone_stats() { return &zone_stats_; }
void ExpectForPool(size_t current, size_t max, size_t total) { void ExpectForPool(size_t current, size_t max, size_t total) {
ASSERT_EQ(current, zone_pool()->GetCurrentAllocatedBytes()); ASSERT_EQ(current, zone_stats()->GetCurrentAllocatedBytes());
ASSERT_EQ(max, zone_pool()->GetMaxAllocatedBytes()); ASSERT_EQ(max, zone_stats()->GetMaxAllocatedBytes());
ASSERT_EQ(total, zone_pool()->GetTotalAllocatedBytes()); ASSERT_EQ(total, zone_stats()->GetTotalAllocatedBytes());
} }
void Expect(ZonePool::StatsScope* stats, size_t current, size_t max, void Expect(ZoneStats::StatsScope* stats, size_t current, size_t max,
size_t total) { size_t total) {
ASSERT_EQ(current, stats->GetCurrentAllocatedBytes()); ASSERT_EQ(current, stats->GetCurrentAllocatedBytes());
ASSERT_EQ(max, stats->GetMaxAllocatedBytes()); ASSERT_EQ(max, stats->GetMaxAllocatedBytes());
...@@ -39,41 +39,39 @@ class ZonePoolTest : public TestWithIsolate { ...@@ -39,41 +39,39 @@ class ZonePoolTest : public TestWithIsolate {
private: private:
v8::internal::AccountingAllocator allocator_; v8::internal::AccountingAllocator allocator_;
ZonePool zone_pool_; ZoneStats zone_stats_;
base::RandomNumberGenerator rng; base::RandomNumberGenerator rng;
}; };
TEST_F(ZoneStatsTest, Empty) {
TEST_F(ZonePoolTest, Empty) {
ExpectForPool(0, 0, 0); ExpectForPool(0, 0, 0);
{ {
ZonePool::StatsScope stats(zone_pool()); ZoneStats::StatsScope stats(zone_stats());
Expect(&stats, 0, 0, 0); Expect(&stats, 0, 0, 0);
} }
ExpectForPool(0, 0, 0); ExpectForPool(0, 0, 0);
{ {
ZonePool::Scope scope(zone_pool()); ZoneStats::Scope scope(zone_stats());
scope.zone(); scope.zone();
} }
ExpectForPool(0, 0, 0); ExpectForPool(0, 0, 0);
} }
TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) {
TEST_F(ZonePoolTest, MultipleZonesWithDeletion) {
static const size_t kArraySize = 10; static const size_t kArraySize = 10;
ZonePool::Scope* scopes[kArraySize]; ZoneStats::Scope* scopes[kArraySize];
// Initialize. // Initialize.
size_t before_stats = 0; size_t before_stats = 0;
for (size_t i = 0; i < kArraySize; ++i) { for (size_t i = 0; i < kArraySize; ++i) {
scopes[i] = new ZonePool::Scope(zone_pool()); scopes[i] = new ZoneStats::Scope(zone_stats());
before_stats += Allocate(scopes[i]->zone()); // Add some stuff. before_stats += Allocate(scopes[i]->zone()); // Add some stuff.
} }
ExpectForPool(before_stats, before_stats, before_stats); ExpectForPool(before_stats, before_stats, before_stats);
ZonePool::StatsScope stats(zone_pool()); ZoneStats::StatsScope stats(zone_stats());
size_t before_deletion = 0; size_t before_deletion = 0;
for (size_t i = 0; i < kArraySize; ++i) { for (size_t i = 0; i < kArraySize; ++i) {
...@@ -87,7 +85,7 @@ TEST_F(ZonePoolTest, MultipleZonesWithDeletion) { ...@@ -87,7 +85,7 @@ TEST_F(ZonePoolTest, MultipleZonesWithDeletion) {
// Delete the scopes and create new ones. // Delete the scopes and create new ones.
for (size_t i = 0; i < kArraySize; ++i) { for (size_t i = 0; i < kArraySize; ++i) {
delete scopes[i]; delete scopes[i];
scopes[i] = new ZonePool::Scope(zone_pool()); scopes[i] = new ZoneStats::Scope(zone_stats());
} }
Expect(&stats, 0, before_deletion, before_deletion); Expect(&stats, 0, before_deletion, before_deletion);
...@@ -116,14 +114,13 @@ TEST_F(ZonePoolTest, MultipleZonesWithDeletion) { ...@@ -116,14 +114,13 @@ TEST_F(ZonePoolTest, MultipleZonesWithDeletion) {
before_stats + before_deletion + after_deletion); before_stats + before_deletion + after_deletion);
} }
TEST_F(ZoneStatsTest, SimpleAllocationLoop) {
TEST_F(ZonePoolTest, SimpleAllocationLoop) {
int runs = 20; int runs = 20;
size_t total_allocated = 0; size_t total_allocated = 0;
size_t max_loop_allocation = 0; size_t max_loop_allocation = 0;
ZonePool::StatsScope outer_stats(zone_pool()); ZoneStats::StatsScope outer_stats(zone_stats());
{ {
ZonePool::Scope outer_scope(zone_pool()); ZoneStats::Scope outer_scope(zone_stats());
size_t outer_allocated = 0; size_t outer_allocated = 0;
for (int i = 0; i < runs; ++i) { for (int i = 0; i < runs; ++i) {
{ {
...@@ -131,10 +128,10 @@ TEST_F(ZonePoolTest, SimpleAllocationLoop) { ...@@ -131,10 +128,10 @@ TEST_F(ZonePoolTest, SimpleAllocationLoop) {
outer_allocated += bytes; outer_allocated += bytes;
total_allocated += bytes; total_allocated += bytes;
} }
ZonePool::StatsScope inner_stats(zone_pool()); ZoneStats::StatsScope inner_stats(zone_stats());
size_t allocated = 0; size_t allocated = 0;
{ {
ZonePool::Scope inner_scope(zone_pool()); ZoneStats::Scope inner_scope(zone_stats());
for (int j = 0; j < 20; ++j) { for (int j = 0; j < 20; ++j) {
size_t bytes = Allocate(inner_scope.zone()); size_t bytes = Allocate(inner_scope.zone());
allocated += bytes; allocated += bytes;
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
'compiler/typed-optimization-unittest.cc', 'compiler/typed-optimization-unittest.cc',
'compiler/typer-unittest.cc', 'compiler/typer-unittest.cc',
'compiler/value-numbering-reducer-unittest.cc', 'compiler/value-numbering-reducer-unittest.cc',
'compiler/zone-pool-unittest.cc', 'compiler/zone-stats-unittest.cc',
'compiler-dispatcher/compiler-dispatcher-job-unittest.cc', 'compiler-dispatcher/compiler-dispatcher-job-unittest.cc',
'counters-unittest.cc', 'counters-unittest.cc',
'eh-frame-iterator-unittest.cc', 'eh-frame-iterator-unittest.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment