Commit 3ae100c7 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[turbofan] Delete the instruction zone after AssembleCode finished

The instruction sequence consumes a significant amount of memory, so it
should be deallocated as early as possible. This CL separates the zone
which is used by the code generator from the zone which is used by the
instruction selector. Thereby we can delete the instruction selector
zone, which contains the instruction sequence, already after
AssembleCode, and not only after FinalizeCode.

For WebAssembly this means that the instruction sequence gets deleted
on the background tasks already and does not stay alive until the
main threads deletes it.

R=bmeurer@chromium.org, neis@chromium.org
CC=mtrofin@chromium.org

Change-Id: I090a2140ca05ae3bcc66268b0eddb08846fea690
Reviewed-on: https://chromium-review.googlesource.com/566831
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46619}
parent acca8e28
......@@ -35,11 +35,12 @@ class CodeGenerator::JumpTable final : public ZoneObject {
size_t const target_count_;
};
CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
CodeGenerator::CodeGenerator(Zone* codegen_zone, Frame* frame, Linkage* linkage,
InstructionSequence* code, CompilationInfo* info,
base::Optional<OsrHelper> osr_helper,
int start_source_position)
: frame_access_state_(nullptr),
: zone_(codegen_zone),
frame_access_state_(nullptr),
linkage_(linkage),
code_(code),
unwinding_info_writer_(zone()),
......@@ -50,20 +51,20 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
current_source_position_(SourcePosition::Unknown()),
tasm_(info->isolate(), nullptr, 0, CodeObjectRequired::kNo),
resolver_(this),
safepoints_(code->zone()),
handlers_(code->zone()),
deoptimization_exits_(code->zone()),
deoptimization_states_(code->zone()),
deoptimization_literals_(code->zone()),
safepoints_(zone()),
handlers_(zone()),
deoptimization_exits_(zone()),
deoptimization_states_(zone()),
deoptimization_literals_(zone()),
inlined_function_count_(0),
translations_(code->zone()),
translations_(zone()),
last_lazy_deopt_pc_(0),
jump_tables_(nullptr),
ools_(nullptr),
osr_helper_(osr_helper),
osr_pc_offset_(-1),
optimized_out_literal_id_(-1),
source_position_table_builder_(code->zone(),
source_position_table_builder_(zone(),
info->SourcePositionRecordingMode()),
result_(kSuccess) {
for (int i = 0; i < code->InstructionBlockCount(); ++i) {
......@@ -77,7 +78,7 @@ Isolate* CodeGenerator::isolate() const { return info_->isolate(); }
void CodeGenerator::CreateFrameAccessState(Frame* frame) {
FinishFrame(frame);
frame_access_state_ = new (code()->zone()) FrameAccessState(frame);
frame_access_state_ = new (zone()) FrameAccessState(frame);
}
void CodeGenerator::AssembleCode() {
......
......@@ -79,7 +79,7 @@ class DeoptimizationLiteral {
// Generates native code for a sequence of instructions.
class CodeGenerator final : public GapResolver::Assembler {
public:
explicit CodeGenerator(Frame* frame, Linkage* linkage,
explicit CodeGenerator(Zone* codegen_zone, Frame* frame, Linkage* linkage,
InstructionSequence* code, CompilationInfo* info,
base::Optional<OsrHelper> osr_helper,
int start_source_position);
......@@ -109,7 +109,7 @@ class CodeGenerator final : public GapResolver::Assembler {
void RecordSafepoint(ReferenceMap* references, Safepoint::Kind kind,
int arguments, Safepoint::DeoptMode deopt_mode);
Zone* zone() const { return code()->zone(); }
Zone* zone() const { return zone_; }
private:
TurboAssembler* tasm() { return &tasm_; }
......@@ -309,6 +309,7 @@ class CodeGenerator final : public GapResolver::Assembler {
friend class OutOfLineCode;
Zone* zone_;
FrameAccessState* frame_access_state_;
Linkage* const linkage_;
InstructionSequence* const code_;
......
......@@ -97,6 +97,8 @@ class PipelineData {
graph_zone_(graph_zone_scope_.zone()),
instruction_zone_scope_(zone_stats_, ZONE_NAME),
instruction_zone_(instruction_zone_scope_.zone()),
codegen_zone_scope_(zone_stats_, ZONE_NAME),
codegen_zone_(codegen_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {
PhaseScope scope(pipeline_statistics, "init pipeline data");
......@@ -134,6 +136,8 @@ class PipelineData {
jsgraph_(jsgraph),
instruction_zone_scope_(zone_stats_, ZONE_NAME),
instruction_zone_(instruction_zone_scope_.zone()),
codegen_zone_scope_(zone_stats_, ZONE_NAME),
codegen_zone_(codegen_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
protected_instructions_(protected_instructions) {
......@@ -154,6 +158,8 @@ class PipelineData {
schedule_(schedule),
instruction_zone_scope_(zone_stats_, ZONE_NAME),
instruction_zone_(instruction_zone_scope_.zone()),
codegen_zone_scope_(zone_stats_, ZONE_NAME),
codegen_zone_(codegen_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {
is_asm_ = false;
......@@ -169,6 +175,8 @@ class PipelineData {
instruction_zone_scope_(zone_stats_, ZONE_NAME),
instruction_zone_(sequence->zone()),
sequence_(sequence),
codegen_zone_scope_(zone_stats_, ZONE_NAME),
codegen_zone_(codegen_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()) {
is_asm_ =
......@@ -180,6 +188,7 @@ class PipelineData {
code_generator_ = nullptr;
DeleteRegisterAllocationZone();
DeleteInstructionZone();
DeleteCodegenZone();
DeleteGraphZone();
}
......@@ -234,6 +243,7 @@ class PipelineData {
void reset_schedule() { schedule_ = nullptr; }
Zone* instruction_zone() const { return instruction_zone_; }
Zone* codegen_zone() const { return codegen_zone_; }
InstructionSequence* sequence() const { return sequence_; }
Frame* frame() const { return frame_; }
......@@ -279,6 +289,12 @@ class PipelineData {
instruction_zone_scope_.Destroy();
instruction_zone_ = nullptr;
sequence_ = nullptr;
}
void DeleteCodegenZone() {
if (codegen_zone_ == nullptr) return;
codegen_zone_scope_.Destroy();
codegen_zone_ = nullptr;
frame_ = nullptr;
}
......@@ -310,7 +326,7 @@ class PipelineData {
if (descriptor != nullptr) {
fixed_frame_size = descriptor->CalculateFixedFrameSize();
}
frame_ = new (instruction_zone()) Frame(fixed_frame_size);
frame_ = new (codegen_zone()) Frame(fixed_frame_size);
}
void InitializeRegisterAllocationData(const RegisterConfiguration* config,
......@@ -333,7 +349,8 @@ class PipelineData {
void InitializeCodeGenerator(Linkage* linkage) {
DCHECK_NULL(code_generator_);
code_generator_ = new CodeGenerator(frame(), linkage, sequence(), info(),
code_generator_ =
new CodeGenerator(codegen_zone(), frame(), linkage, sequence(), info(),
osr_helper_, start_source_position_);
}
......@@ -386,6 +403,12 @@ class PipelineData {
ZoneStats::Scope instruction_zone_scope_;
Zone* instruction_zone_;
InstructionSequence* sequence_ = nullptr;
// All objects in the following group of fields are allocated in
// codegen_zone_. They are all set to nullptr when the codegen_zone_
// is destroyed.
ZoneStats::Scope codegen_zone_scope_;
Zone* codegen_zone_;
Frame* frame_ = nullptr;
// All objects in the following group of fields are allocated in
......@@ -2026,6 +2049,7 @@ void PipelineImpl::AssembleCode(Linkage* linkage) {
data->BeginPhaseKind("code generation");
data->InitializeCodeGenerator(linkage);
Run<AssembleCodePhase>();
data->DeleteInstructionZone();
}
Handle<Code> PipelineImpl::FinalizeCode() {
......
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