Revert of Replaced different means of zone pooling/reusing by one zone segment pool (patchset #3 id:120001 of https://codereview.chromium.org/2348303002/ )

Reason for revert:
Blocks Roll https://codereview.chromium.org/2366733002/

Original issue's description:
> Replaced different means of zone pooling/reusing by one zone segment pool
>
> BUG=v8:5409
>
> Committed: https://crrev.com/a124feb0760896c8be61de08004a08c3bc9b4b3f
> Cr-Commit-Position: refs/heads/master@{#39633}

TBR=mstarzinger@chromium.org,verwaest@chromium.org,heimbuef@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5409

Review-Url: https://codereview.chromium.org/2360403003
Cr-Commit-Position: refs/heads/master@{#39651}
This commit is contained in:
hablich 2016-09-22 23:02:24 -07:00 committed by Commit bot
parent 55e55489b7
commit b88a848faf
20 changed files with 209 additions and 153 deletions

View File

@ -1174,8 +1174,8 @@ v8_source_set("v8_base") {
"src/compiler/wasm-compiler.cc",
"src/compiler/wasm-compiler.h",
"src/compiler/wasm-linkage.cc",
"src/compiler/zone-stats.cc",
"src/compiler/zone-stats.h",
"src/compiler/zone-pool.cc",
"src/compiler/zone-pool.h",
"src/context-measure.cc",
"src/context-measure.h",
"src/contexts-inl.h",

View File

@ -317,7 +317,7 @@ void MoveOptimizer::OptimizeMerge(InstructionBlock* block) {
if (!op->IsConstant() && !op->IsImmediate()) return;
}
}
// TODO(dcarney): pass a ZoneStats down for this?
// TODO(dcarney): pass a ZonePool down for this?
MoveMap move_map(local_zone());
size_t correct_counts = 0;
// Accumulate set of shared moves.

View File

@ -6,7 +6,7 @@
#include "src/compilation-info.h"
#include "src/compiler/pipeline-statistics.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
#include "src/isolate.h"
namespace v8 {
@ -16,13 +16,13 @@ namespace compiler {
void PipelineStatistics::CommonStats::Begin(
PipelineStatistics* pipeline_stats) {
DCHECK(!scope_);
scope_.reset(new ZoneStats::StatsScope(pipeline_stats->zone_stats_));
scope_.reset(new ZonePool::StatsScope(pipeline_stats->zone_pool_));
timer_.Start();
outer_zone_initial_size_ = pipeline_stats->OuterZoneSize();
allocated_bytes_at_start_ =
outer_zone_initial_size_ -
pipeline_stats->total_stats_.outer_zone_initial_size_ +
pipeline_stats->zone_stats_->GetCurrentAllocatedBytes();
pipeline_stats->zone_pool_->GetCurrentAllocatedBytes();
}
@ -43,11 +43,12 @@ void PipelineStatistics::CommonStats::End(
timer_.Stop();
}
PipelineStatistics::PipelineStatistics(CompilationInfo* info,
ZoneStats* zone_stats)
ZonePool* zone_pool)
: isolate_(info->isolate()),
outer_zone_(info->zone()),
zone_stats_(zone_stats),
zone_pool_(zone_pool),
compilation_stats_(isolate_->GetTurboStatistics()),
source_size_(0),
phase_kind_name_(nullptr),

View File

@ -10,7 +10,7 @@
#include "src/base/platform/elapsed-timer.h"
#include "src/compilation-statistics.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
namespace v8 {
namespace internal {
@ -20,7 +20,7 @@ class PhaseScope;
class PipelineStatistics : public Malloced {
public:
PipelineStatistics(CompilationInfo* info, ZoneStats* zone_stats);
PipelineStatistics(CompilationInfo* info, ZonePool* zone_pool);
~PipelineStatistics();
void BeginPhaseKind(const char* phase_kind_name);
@ -39,7 +39,7 @@ class PipelineStatistics : public Malloced {
void End(PipelineStatistics* pipeline_stats,
CompilationStatistics::BasicStats* diff);
std::unique_ptr<ZoneStats::StatsScope> scope_;
std::unique_ptr<ZonePool::StatsScope> scope_;
base::ElapsedTimer timer_;
size_t outer_zone_initial_size_;
size_t allocated_bytes_at_start_;
@ -57,7 +57,7 @@ class PipelineStatistics : public Malloced {
Isolate* isolate_;
Zone* outer_zone_;
ZoneStats* zone_stats_;
ZonePool* zone_pool_;
CompilationStatistics* compilation_stats_;
std::string function_name_;

View File

@ -69,7 +69,7 @@
#include "src/compiler/typer.h"
#include "src/compiler/value-numbering-reducer.h"
#include "src/compiler/verifier.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
#include "src/isolate-inl.h"
#include "src/ostreams.h"
#include "src/parsing/parse-info.h"
@ -84,19 +84,19 @@ namespace compiler {
class PipelineData {
public:
// For main entry point.
PipelineData(ZoneStats* zone_stats, CompilationInfo* info,
PipelineData(ZonePool* zone_pool, CompilationInfo* info,
PipelineStatistics* pipeline_statistics)
: isolate_(info->isolate()),
info_(info),
debug_name_(info_->GetDebugName()),
outer_zone_(info_->zone()),
zone_stats_(zone_stats),
zone_pool_(zone_pool),
pipeline_statistics_(pipeline_statistics),
graph_zone_scope_(zone_stats_),
graph_zone_scope_(zone_pool_),
graph_zone_(graph_zone_scope_.zone()),
instruction_zone_scope_(zone_stats_),
instruction_zone_scope_(zone_pool_),
instruction_zone_(instruction_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_),
register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {
PhaseScope scope(pipeline_statistics, "init pipeline data");
graph_ = new (graph_zone_) Graph(graph_zone_);
@ -113,48 +113,48 @@ class PipelineData {
}
// For WASM compile entry point.
PipelineData(ZoneStats* zone_stats, CompilationInfo* info, Graph* graph,
PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph,
SourcePositionTable* source_positions)
: isolate_(info->isolate()),
info_(info),
debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats),
graph_zone_scope_(zone_stats_),
zone_pool_(zone_pool),
graph_zone_scope_(zone_pool_),
graph_(graph),
source_positions_(source_positions),
instruction_zone_scope_(zone_stats_),
instruction_zone_scope_(zone_pool_),
instruction_zone_(instruction_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_),
register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
// For machine graph testing entry point.
PipelineData(ZoneStats* zone_stats, CompilationInfo* info, Graph* graph,
PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph,
Schedule* schedule)
: isolate_(info->isolate()),
info_(info),
debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats),
graph_zone_scope_(zone_stats_),
zone_pool_(zone_pool),
graph_zone_scope_(zone_pool_),
graph_(graph),
source_positions_(new (info->zone()) SourcePositionTable(graph_)),
schedule_(schedule),
instruction_zone_scope_(zone_stats_),
instruction_zone_scope_(zone_pool_),
instruction_zone_(instruction_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_),
register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
// For register allocation testing entry point.
PipelineData(ZoneStats* zone_stats, CompilationInfo* info,
PipelineData(ZonePool* zone_pool, CompilationInfo* info,
InstructionSequence* sequence)
: isolate_(info->isolate()),
info_(info),
debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats),
graph_zone_scope_(zone_stats_),
instruction_zone_scope_(zone_stats_),
zone_pool_(zone_pool),
graph_zone_scope_(zone_pool_),
instruction_zone_scope_(zone_pool_),
instruction_zone_(sequence->zone()),
sequence_(sequence),
register_allocation_zone_scope_(zone_stats_),
register_allocation_zone_scope_(zone_pool_),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {}
~PipelineData() {
@ -165,7 +165,7 @@ class PipelineData {
Isolate* isolate() const { return isolate_; }
CompilationInfo* info() const { return info_; }
ZoneStats* zone_stats() const { return zone_stats_; }
ZonePool* zone_pool() const { return zone_pool_; }
PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; }
bool compilation_failed() const { return compilation_failed_; }
void set_compilation_failed() { compilation_failed_ = true; }
@ -312,14 +312,14 @@ class PipelineData {
CompilationInfo* const info_;
std::unique_ptr<char[]> debug_name_;
Zone* outer_zone_ = nullptr;
ZoneStats* const zone_stats_;
ZonePool* const zone_pool_;
PipelineStatistics* pipeline_statistics_ = nullptr;
bool compilation_failed_ = false;
Handle<Code> code_ = Handle<Code>::null();
// All objects in the following group of fields are allocated in graph_zone_.
// They are all set to nullptr when the graph_zone_ is destroyed.
ZoneStats::Scope graph_zone_scope_;
ZonePool::Scope graph_zone_scope_;
Zone* graph_zone_ = nullptr;
Graph* graph_ = nullptr;
SourcePositionTable* source_positions_ = nullptr;
@ -336,7 +336,7 @@ class PipelineData {
// instruction_zone_. They are all set to nullptr when the instruction_zone_
// is
// destroyed.
ZoneStats::Scope instruction_zone_scope_;
ZonePool::Scope instruction_zone_scope_;
Zone* instruction_zone_;
InstructionSequence* sequence_ = nullptr;
Frame* frame_ = nullptr;
@ -344,7 +344,7 @@ class PipelineData {
// All objects in the following group of fields are allocated in
// register_allocation_zone_. They are all set to nullptr when the zone is
// destroyed.
ZoneStats::Scope register_allocation_zone_scope_;
ZonePool::Scope register_allocation_zone_scope_;
Zone* register_allocation_zone_;
RegisterAllocationData* register_allocation_data_ = nullptr;
@ -517,21 +517,21 @@ class PipelineRunScope {
: phase_scope_(
phase_name == nullptr ? nullptr : data->pipeline_statistics(),
phase_name),
zone_scope_(data->zone_stats()) {}
zone_scope_(data->zone_pool()) {}
Zone* zone() { return zone_scope_.zone(); }
private:
PhaseScope phase_scope_;
ZoneStats::Scope zone_scope_;
ZonePool::Scope zone_scope_;
};
PipelineStatistics* CreatePipelineStatistics(CompilationInfo* info,
ZoneStats* zone_stats) {
ZonePool* zone_pool) {
PipelineStatistics* pipeline_statistics = nullptr;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics = new PipelineStatistics(info, zone_stats);
pipeline_statistics = new PipelineStatistics(info, zone_pool);
pipeline_statistics->BeginPhaseKind("initializing");
}
@ -568,11 +568,11 @@ class PipelineCompilationJob final : public CompilationJob {
// to the CompilationJob constructor, but it is not dereferenced there.
: CompilationJob(isolate, &info_, "TurboFan"),
zone_(isolate->allocator()),
zone_stats_(isolate->allocator()),
zone_pool_(isolate->allocator()),
parse_info_(&zone_, function),
info_(&parse_info_, function),
pipeline_statistics_(CreatePipelineStatistics(info(), &zone_stats_)),
data_(&zone_stats_, info(), pipeline_statistics_.get()),
pipeline_statistics_(CreatePipelineStatistics(info(), &zone_pool_)),
data_(&zone_pool_, info(), pipeline_statistics_.get()),
pipeline_(&data_),
linkage_(nullptr) {}
@ -583,7 +583,7 @@ class PipelineCompilationJob final : public CompilationJob {
private:
Zone zone_;
ZoneStats zone_stats_;
ZonePool zone_pool_;
ParseInfo parse_info_;
CompilationInfo info_;
std::unique_ptr<PipelineStatistics> pipeline_statistics_;
@ -669,8 +669,8 @@ class PipelineWasmCompilationJob final : public CompilationJob {
SourcePositionTable* source_positions)
: CompilationJob(info->isolate(), info, "TurboFan",
State::kReadyToExecute),
zone_stats_(info->isolate()->allocator()),
data_(&zone_stats_, info, graph, source_positions),
zone_pool_(info->isolate()->allocator()),
data_(&zone_pool_, info, graph, source_positions),
pipeline_(&data_),
linkage_(descriptor) {}
@ -680,7 +680,7 @@ class PipelineWasmCompilationJob final : public CompilationJob {
Status FinalizeJobImpl() final;
private:
ZoneStats zone_stats_;
ZonePool zone_pool_;
PipelineData data_;
PipelineImpl pipeline_;
Linkage linkage_;
@ -1642,11 +1642,11 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate,
CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags);
// Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(isolate->allocator());
PipelineData data(&zone_stats, &info, graph, schedule);
ZonePool zone_pool(isolate->allocator());
PipelineData data(&zone_pool, &info, graph, schedule);
std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(new PipelineStatistics(&info, &zone_stats));
pipeline_statistics.reset(new PipelineStatistics(&info, &zone_pool));
pipeline_statistics->BeginPhaseKind("stub codegen");
}
@ -1668,10 +1668,10 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate,
// static
Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info) {
ZoneStats zone_stats(info->isolate()->allocator());
ZonePool zone_pool(info->isolate()->allocator());
std::unique_ptr<PipelineStatistics> pipeline_statistics(
CreatePipelineStatistics(info, &zone_stats));
PipelineData data(&zone_stats, info, pipeline_statistics.get());
CreatePipelineStatistics(info, &zone_pool));
PipelineData data(&zone_pool, info, pipeline_statistics.get());
PipelineImpl pipeline(&data);
Linkage linkage(Linkage::ComputeIncoming(data.instruction_zone(), info));
@ -1696,11 +1696,11 @@ Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info,
Graph* graph,
Schedule* schedule) {
// Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(info->isolate()->allocator());
PipelineData data(&zone_stats, info, graph, schedule);
ZonePool zone_pool(info->isolate()->allocator());
PipelineData data(&zone_pool, info, graph, schedule);
std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(new PipelineStatistics(info, &zone_stats));
pipeline_statistics.reset(new PipelineStatistics(info, &zone_pool));
pipeline_statistics->BeginPhaseKind("test codegen");
}
@ -1735,8 +1735,8 @@ bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
bool run_verifier) {
CompilationInfo info(ArrayVector("testing"), sequence->isolate(),
sequence->zone(), Code::ComputeFlags(Code::STUB));
ZoneStats zone_stats(sequence->isolate()->allocator());
PipelineData data(&zone_stats, &info, sequence);
ZonePool zone_pool(sequence->isolate()->allocator());
PipelineData data(&zone_pool, &info, sequence);
PipelineImpl pipeline(&data);
pipeline.data_->InitializeFrameData(nullptr);
pipeline.AllocateRegisters(config, nullptr, run_verifier);

View File

@ -9,7 +9,7 @@
#include "src/compiler/node.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/schedule.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
#include "src/zone/zone-containers.h"
namespace v8 {

View File

@ -25,7 +25,7 @@
#include "src/compiler/node-matchers.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/source-position.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
#include "src/code-factory.h"
#include "src/code-stubs.h"

View File

@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
namespace v8 {
namespace internal {
namespace compiler {
ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
: zone_stats_(zone_stats),
total_allocated_bytes_at_start_(zone_stats->GetTotalAllocatedBytes()),
ZonePool::StatsScope::StatsScope(ZonePool* zone_pool)
: zone_pool_(zone_pool),
total_allocated_bytes_at_start_(zone_pool->GetTotalAllocatedBytes()),
max_allocated_bytes_(0) {
zone_stats_->stats_.push_back(this);
for (Zone* zone : zone_stats_->zones_) {
zone_pool_->stats_.push_back(this);
for (Zone* zone : zone_pool_->used_) {
size_t size = static_cast<size_t>(zone->allocation_size());
std::pair<InitialValues::iterator, bool> res =
initial_values_.insert(std::make_pair(zone, size));
@ -22,18 +22,21 @@ ZoneStats::StatsScope::StatsScope(ZoneStats* zone_stats)
}
}
ZoneStats::StatsScope::~StatsScope() {
DCHECK_EQ(zone_stats_->stats_.back(), this);
zone_stats_->stats_.pop_back();
ZonePool::StatsScope::~StatsScope() {
DCHECK_EQ(zone_pool_->stats_.back(), this);
zone_pool_->stats_.pop_back();
}
size_t ZoneStats::StatsScope::GetMaxAllocatedBytes() {
size_t ZonePool::StatsScope::GetMaxAllocatedBytes() {
return std::max(max_allocated_bytes_, GetCurrentAllocatedBytes());
}
size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
size_t ZonePool::StatsScope::GetCurrentAllocatedBytes() {
size_t total = 0;
for (Zone* zone : zone_stats_->zones_) {
for (Zone* zone : zone_pool_->used_) {
total += static_cast<size_t>(zone->allocation_size());
// Adjust for initial values.
InitialValues::iterator it = initial_values_.find(zone);
@ -44,12 +47,13 @@ size_t ZoneStats::StatsScope::GetCurrentAllocatedBytes() {
return total;
}
size_t ZoneStats::StatsScope::GetTotalAllocatedBytes() {
return zone_stats_->GetTotalAllocatedBytes() -
total_allocated_bytes_at_start_;
size_t ZonePool::StatsScope::GetTotalAllocatedBytes() {
return zone_pool_->GetTotalAllocatedBytes() - total_allocated_bytes_at_start_;
}
void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
void ZonePool::StatsScope::ZoneReturned(Zone* zone) {
size_t current_total = GetCurrentAllocatedBytes();
// Update max.
max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
@ -60,37 +64,53 @@ void ZoneStats::StatsScope::ZoneReturned(Zone* zone) {
}
}
ZoneStats::ZoneStats(AccountingAllocator* allocator)
ZonePool::ZonePool(AccountingAllocator* allocator)
: max_allocated_bytes_(0), total_deleted_bytes_(0), allocator_(allocator) {}
ZoneStats::~ZoneStats() {
DCHECK(zones_.empty());
ZonePool::~ZonePool() {
DCHECK(used_.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());
}
size_t ZoneStats::GetCurrentAllocatedBytes() {
size_t ZonePool::GetCurrentAllocatedBytes() {
size_t total = 0;
for (Zone* zone : zones_) {
for (Zone* zone : used_) {
total += static_cast<size_t>(zone->allocation_size());
}
return total;
}
size_t ZoneStats::GetTotalAllocatedBytes() {
size_t ZonePool::GetTotalAllocatedBytes() {
return total_deleted_bytes_ + GetCurrentAllocatedBytes();
}
Zone* ZoneStats::NewEmptyZone() {
Zone* zone = new Zone(allocator_);
zones_.push_back(zone);
Zone* ZonePool::NewEmptyZone() {
Zone* 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;
}
void ZoneStats::ReturnZone(Zone* zone) {
void ZonePool::ReturnZone(Zone* zone) {
size_t current_total = GetCurrentAllocatedBytes();
// Update max.
max_allocated_bytes_ = std::max(max_allocated_bytes_, current_total);
@ -99,11 +119,18 @@ void ZoneStats::ReturnZone(Zone* zone) {
stat_scope->ZoneReturned(zone);
}
// Remove from used.
Zones::iterator it = std::find(zones_.begin(), zones_.end(), zone);
DCHECK(it != zones_.end());
zones_.erase(it);
Used::iterator it = std::find(used_.begin(), used_.end(), zone);
DCHECK(it != used_.end());
used_.erase(it);
total_deleted_bytes_ += static_cast<size_t>(zone->allocation_size());
// Delete zone or clear and stash on unused_.
if (unused_.size() >= kMaxUnusedSize) {
delete zone;
} else {
zone->DeleteAll();
DCHECK_EQ(0u, zone->allocation_size());
unused_.push_back(zone);
}
}
} // namespace compiler

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_ZONE_STATS_H_
#define V8_COMPILER_ZONE_STATS_H_
#ifndef V8_COMPILER_ZONE_POOL_H_
#define V8_COMPILER_ZONE_POOL_H_
#include <map>
#include <set>
@ -15,32 +15,32 @@ namespace v8 {
namespace internal {
namespace compiler {
class ZoneStats final {
class ZonePool final {
public:
class Scope final {
public:
explicit Scope(ZoneStats* zone_stats)
: zone_stats_(zone_stats), zone_(nullptr) {}
explicit Scope(ZonePool* zone_pool)
: zone_pool_(zone_pool), zone_(nullptr) {}
~Scope() { Destroy(); }
Zone* zone() {
if (zone_ == nullptr) zone_ = zone_stats_->NewEmptyZone();
if (zone_ == nullptr) zone_ = zone_pool_->NewEmptyZone();
return zone_;
}
void Destroy() {
if (zone_ != nullptr) zone_stats_->ReturnZone(zone_);
if (zone_ != nullptr) zone_pool_->ReturnZone(zone_);
zone_ = nullptr;
}
private:
ZoneStats* const zone_stats_;
ZonePool* const zone_pool_;
Zone* zone_;
DISALLOW_COPY_AND_ASSIGN(Scope);
};
class StatsScope final {
public:
explicit StatsScope(ZoneStats* zone_stats);
explicit StatsScope(ZonePool* zone_pool);
~StatsScope();
size_t GetMaxAllocatedBytes();
@ -48,12 +48,12 @@ class ZoneStats final {
size_t GetTotalAllocatedBytes();
private:
friend class ZoneStats;
friend class ZonePool;
void ZoneReturned(Zone* zone);
typedef std::map<Zone*, size_t> InitialValues;
ZoneStats* const zone_stats_;
ZonePool* const zone_pool_;
InitialValues initial_values_;
size_t total_allocated_bytes_at_start_;
size_t max_allocated_bytes_;
@ -61,8 +61,8 @@ class ZoneStats final {
DISALLOW_COPY_AND_ASSIGN(StatsScope);
};
explicit ZoneStats(AccountingAllocator* allocator);
~ZoneStats();
explicit ZonePool(AccountingAllocator* allocator);
~ZonePool();
size_t GetMaxAllocatedBytes();
size_t GetTotalAllocatedBytes();
@ -73,20 +73,22 @@ class ZoneStats final {
void ReturnZone(Zone* zone);
static const size_t kMaxUnusedSize = 3;
typedef std::vector<Zone*> Zones;
typedef std::vector<Zone*> Unused;
typedef std::vector<Zone*> Used;
typedef std::vector<StatsScope*> Stats;
Zones zones_;
Unused unused_;
Used used_;
Stats stats_;
size_t max_allocated_bytes_;
size_t total_deleted_bytes_;
AccountingAllocator* allocator_;
DISALLOW_COPY_AND_ASSIGN(ZoneStats);
DISALLOW_COPY_AND_ASSIGN(ZonePool);
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_ZONE_STATS_H_
#endif

View File

@ -1972,6 +1972,7 @@ Isolate::Isolate(bool enable_serializer)
allocator_(FLAG_trace_gc_object_stats
? new VerboseAccountingAllocator(&heap_, 256 * KB)
: new AccountingAllocator()),
runtime_zone_(new Zone(allocator_)),
inner_pointer_to_code_cache_(NULL),
global_handles_(NULL),
eternal_handles_(NULL),
@ -2244,6 +2245,9 @@ Isolate::~Isolate() {
delete cancelable_task_manager_;
cancelable_task_manager_ = nullptr;
delete runtime_zone_;
runtime_zone_ = nullptr;
delete allocator_;
allocator_ = nullptr;

View File

@ -885,6 +885,7 @@ class Isolate {
DCHECK(handle_scope_implementer_);
return handle_scope_implementer_;
}
Zone* runtime_zone() { return runtime_zone_; }
UnicodeCache* unicode_cache() {
return unicode_cache_;
@ -1330,6 +1331,7 @@ class Isolate {
HandleScopeImplementer* handle_scope_implementer_;
UnicodeCache* unicode_cache_;
AccountingAllocator* allocator_;
Zone* runtime_zone_;
InnerPointerToCodeCache* inner_pointer_to_code_cache_;
GlobalHandles* global_handles_;
EternalHandles* eternal_handles_;

View File

@ -393,8 +393,8 @@ MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
DCHECK(subject->IsFlat());
DCHECK(replacement->IsFlat());
Zone zone(isolate->allocator());
ZoneList<int> indices(8, &zone);
ZoneScope zone_scope(isolate->runtime_zone());
ZoneList<int> indices(8, zone_scope.zone());
DCHECK_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag());
String* pattern =
String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
@ -403,7 +403,7 @@ MUST_USE_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
int replacement_len = replacement->length();
FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff,
&zone);
zone_scope.zone());
int matches = indices.length();
if (matches == 0) return *subject;
@ -474,8 +474,8 @@ MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithString(
int subject_length = subject->length();
// CompiledReplacement uses zone allocation.
Zone zone(isolate->allocator());
CompiledReplacement compiled_replacement(&zone);
ZoneScope zone_scope(isolate->runtime_zone());
CompiledReplacement compiled_replacement(zone_scope.zone());
bool simple_replace =
compiled_replacement.Compile(replacement, capture_count, subject_length);
@ -711,17 +711,17 @@ RUNTIME_FUNCTION(Runtime_StringSplit) {
static const int kMaxInitialListCapacity = 16;
Zone zone(isolate->allocator());
ZoneScope zone_scope(isolate->runtime_zone());
// Find (up to limit) indices of separator and end-of-string in subject
int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit);
ZoneList<int> indices(initial_capacity, &zone);
ZoneList<int> indices(initial_capacity, zone_scope.zone());
FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit,
&zone);
zone_scope.zone());
if (static_cast<uint32_t>(indices.length()) < limit) {
indices.Add(subject_length, &zone);
indices.Add(subject_length, zone_scope.zone());
}
// The list indices now contains the end of each part to create.

View File

@ -181,14 +181,14 @@ RUNTIME_FUNCTION(Runtime_StringMatch) {
int capture_count = regexp->CaptureCount();
Zone zone(isolate->allocator());
ZoneList<int> offsets(8, &zone);
ZoneScope zone_scope(isolate->runtime_zone());
ZoneList<int> offsets(8, zone_scope.zone());
while (true) {
int32_t* match = global_cache.FetchNext();
if (match == NULL) break;
offsets.Add(match[0], &zone); // start
offsets.Add(match[1], &zone); // end
offsets.Add(match[0], zone_scope.zone()); // start
offsets.Add(match[1], zone_scope.zone()); // end
}
if (global_cache.HasException()) return isolate->heap()->exception();

View File

@ -738,8 +738,8 @@
'compiler/wasm-compiler.cc',
'compiler/wasm-compiler.h',
'compiler/wasm-linkage.cc',
'compiler/zone-stats.cc',
'compiler/zone-stats.h',
'compiler/zone-pool.cc',
'compiler/zone-pool.h',
'compiler-dispatcher/compiler-dispatcher-job.cc',
'compiler-dispatcher/compiler-dispatcher-job.h',
'compiler-dispatcher/optimizing-compile-dispatcher.cc',

View File

@ -105,7 +105,9 @@ void Zone::DeleteAll() {
}
position_ = limit_ = 0;
allocation_size_ = 0;
// Update the head segment to be the kept segment (if any).
segment_head_ = nullptr;
}

View File

@ -44,6 +44,9 @@ class Zone final {
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
// the limit allows.
bool excess_allocation() const {
@ -74,9 +77,6 @@ class Zone final {
// Report zone excess when allocation exceeds this limit.
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.
size_t allocation_size_;
@ -125,6 +125,19 @@ class ZoneObject {
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
// structures to allocate themselves and their elements in the Zone.
class ZoneAllocationPolicy final {

View File

@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include "src/base/utils/random-number-generator.h"
@ -19,7 +20,8 @@
#include "src/compiler/node.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/wasm-compiler.h"
#include "src/compiler/zone-stats.h"
#include "src/compiler/zone-pool.h"
#include "src/wasm/ast-decoder.h"
#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h"

View File

@ -82,7 +82,7 @@ v8_executable("unittests") {
"compiler/typed-optimization-unittest.cc",
"compiler/typer-unittest.cc",
"compiler/value-numbering-reducer-unittest.cc",
"compiler/zone-stats-unittest.cc",
"compiler/zone-pool-unittest.cc",
"counters-unittest.cc",
"eh-frame-iterator-unittest.cc",
"eh-frame-writer-unittest.cc",

View File

@ -2,28 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/zone-stats.h"
#include "src/base/utils/random-number-generator.h"
#include "src/compiler/zone-pool.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
class ZoneStatsTest : public TestWithIsolate {
class ZonePoolTest : public TestWithIsolate {
public:
ZoneStatsTest() : zone_stats_(&allocator_) {}
ZonePoolTest() : zone_pool_(&allocator_) {}
protected:
ZoneStats* zone_stats() { return &zone_stats_; }
ZonePool* zone_pool() { return &zone_pool_; }
void ExpectForPool(size_t current, size_t max, size_t total) {
ASSERT_EQ(current, zone_stats()->GetCurrentAllocatedBytes());
ASSERT_EQ(max, zone_stats()->GetMaxAllocatedBytes());
ASSERT_EQ(total, zone_stats()->GetTotalAllocatedBytes());
ASSERT_EQ(current, zone_pool()->GetCurrentAllocatedBytes());
ASSERT_EQ(max, zone_pool()->GetMaxAllocatedBytes());
ASSERT_EQ(total, zone_pool()->GetTotalAllocatedBytes());
}
void Expect(ZoneStats::StatsScope* stats, size_t current, size_t max,
void Expect(ZonePool::StatsScope* stats, size_t current, size_t max,
size_t total) {
ASSERT_EQ(current, stats->GetCurrentAllocatedBytes());
ASSERT_EQ(max, stats->GetMaxAllocatedBytes());
@ -39,39 +39,41 @@ class ZoneStatsTest : public TestWithIsolate {
private:
v8::internal::AccountingAllocator allocator_;
ZoneStats zone_stats_;
ZonePool zone_pool_;
base::RandomNumberGenerator rng;
};
TEST_F(ZoneStatsTest, Empty) {
TEST_F(ZonePoolTest, Empty) {
ExpectForPool(0, 0, 0);
{
ZoneStats::StatsScope stats(zone_stats());
ZonePool::StatsScope stats(zone_pool());
Expect(&stats, 0, 0, 0);
}
ExpectForPool(0, 0, 0);
{
ZoneStats::Scope scope(zone_stats());
ZonePool::Scope scope(zone_pool());
scope.zone();
}
ExpectForPool(0, 0, 0);
}
TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) {
TEST_F(ZonePoolTest, MultipleZonesWithDeletion) {
static const size_t kArraySize = 10;
ZoneStats::Scope* scopes[kArraySize];
ZonePool::Scope* scopes[kArraySize];
// Initialize.
size_t before_stats = 0;
for (size_t i = 0; i < kArraySize; ++i) {
scopes[i] = new ZoneStats::Scope(zone_stats());
scopes[i] = new ZonePool::Scope(zone_pool());
before_stats += Allocate(scopes[i]->zone()); // Add some stuff.
}
ExpectForPool(before_stats, before_stats, before_stats);
ZoneStats::StatsScope stats(zone_stats());
ZonePool::StatsScope stats(zone_pool());
size_t before_deletion = 0;
for (size_t i = 0; i < kArraySize; ++i) {
@ -85,7 +87,7 @@ TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) {
// Delete the scopes and create new ones.
for (size_t i = 0; i < kArraySize; ++i) {
delete scopes[i];
scopes[i] = new ZoneStats::Scope(zone_stats());
scopes[i] = new ZonePool::Scope(zone_pool());
}
Expect(&stats, 0, before_deletion, before_deletion);
@ -114,13 +116,14 @@ TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) {
before_stats + before_deletion + after_deletion);
}
TEST_F(ZoneStatsTest, SimpleAllocationLoop) {
TEST_F(ZonePoolTest, SimpleAllocationLoop) {
int runs = 20;
size_t total_allocated = 0;
size_t max_loop_allocation = 0;
ZoneStats::StatsScope outer_stats(zone_stats());
ZonePool::StatsScope outer_stats(zone_pool());
{
ZoneStats::Scope outer_scope(zone_stats());
ZonePool::Scope outer_scope(zone_pool());
size_t outer_allocated = 0;
for (int i = 0; i < runs; ++i) {
{
@ -128,10 +131,10 @@ TEST_F(ZoneStatsTest, SimpleAllocationLoop) {
outer_allocated += bytes;
total_allocated += bytes;
}
ZoneStats::StatsScope inner_stats(zone_stats());
ZonePool::StatsScope inner_stats(zone_pool());
size_t allocated = 0;
{
ZoneStats::Scope inner_scope(zone_stats());
ZonePool::Scope inner_scope(zone_pool());
for (int j = 0; j < 20; ++j) {
size_t bytes = Allocate(inner_scope.zone());
allocated += bytes;

View File

@ -79,7 +79,7 @@
'compiler/typed-optimization-unittest.cc',
'compiler/typer-unittest.cc',
'compiler/value-numbering-reducer-unittest.cc',
'compiler/zone-stats-unittest.cc',
'compiler/zone-pool-unittest.cc',
'compiler-dispatcher/compiler-dispatcher-job-unittest.cc',
'counters-unittest.cc',
'eh-frame-iterator-unittest.cc',