From e396f538d0f549fb82ce24c7780139a7c4df9954 Mon Sep 17 00:00:00 2001 From: svenpanne Date: Thu, 19 Mar 2015 05:39:43 -0700 Subject: [PATCH] Some CompilationInfo-related cleanup. Use a delegating constructor for CompilationInfo, reducing duplicated code. Simplified handling of InlinedFunctionInfos on the way: When we start compiling, we have bigger things to worry about than a default vector. Reduced the usage of a SharedFunctionInfo for compiling, this is a slighty strange concept. Review URL: https://codereview.chromium.org/1018853004 Cr-Commit-Position: refs/heads/master@{#27299} --- src/compiler.cc | 118 +++++++++++++---------------------- src/compiler.h | 19 +++--- src/hydrogen.cc | 9 +-- src/parser.h | 3 +- src/runtime/runtime-debug.cc | 2 +- 5 files changed, 58 insertions(+), 93 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index f3584d5017..96edf2d3b9 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/v8.h" - #include "src/compiler.h" +#include + #include "src/ast-numbering.h" #include "src/bootstrapper.h" #include "src/codegen.h" @@ -81,57 +81,8 @@ bool CompilationInfo::has_shared_info() const { CompilationInfo::CompilationInfo(ParseInfo* parse_info) - : parse_info_(parse_info), - flags_(0), - osr_ast_id_(BailoutId::None()), - parameter_count_(0), - optimization_id_(-1), - aborted_due_to_dependency_change_(false), - osr_expr_stack_height_(0) { - Initialize(parse_info->isolate(), BASE, parse_info->zone()); -} - - -CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) - : parse_info_(nullptr), - flags_(0), - osr_ast_id_(BailoutId::None()), - parameter_count_(0), - optimization_id_(-1), - aborted_due_to_dependency_change_(false), - osr_expr_stack_height_(0) { - Initialize(isolate, STUB, zone); - code_stub_ = stub; -} - - -void CompilationInfo::Initialize(Isolate* isolate, - Mode mode, - Zone* zone) { - isolate_ = isolate; - zone_ = zone; - deferred_handles_ = NULL; - code_stub_ = NULL; - prologue_offset_ = Code::kPrologueOffsetNotSet; - opt_count_ = has_shared_info() ? shared_info()->opt_count() : 0; - no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() - ? new List(2) : NULL; - if (FLAG_hydrogen_track_positions) { - inlined_function_infos_ = new std::vector(); - track_positions_ = true; - } else { - inlined_function_infos_ = NULL; - track_positions_ = false; - } - - for (int i = 0; i < DependentCode::kGroupCount; i++) { - dependencies_[i] = NULL; - } - if (mode == STUB) { - mode_ = STUB; - return; - } - mode_ = mode; + : CompilationInfo(parse_info, nullptr, BASE, parse_info->isolate(), + parse_info->zone()) { // Compiling for the snapshot typically results in different code than // compiling later on. This means that code recompiled with deoptimization // support won't be "equivalent" (as defined by SharedFunctionInfo:: @@ -147,22 +98,48 @@ void CompilationInfo::Initialize(Isolate* isolate, if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); if (FLAG_turbo_types) MarkAsTypingEnabled(); - bailout_reason_ = kNoReason; - if (has_shared_info() && shared_info()->is_compiled()) { // We should initialize the CompilationInfo feedback vector from the // passed in shared info, rather than creating a new one. - feedback_vector_ = - Handle(shared_info()->feedback_vector(), isolate); + feedback_vector_ = Handle( + shared_info()->feedback_vector(), parse_info->isolate()); } } +CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) + : CompilationInfo(nullptr, stub, STUB, isolate, zone) {} + + +CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, + Mode mode, Isolate* isolate, Zone* zone) + : parse_info_(parse_info), + isolate_(isolate), + flags_(0), + code_stub_(code_stub), + mode_(mode), + osr_ast_id_(BailoutId::None()), + zone_(zone), + deferred_handles_(nullptr), + bailout_reason_(kNoReason), + prologue_offset_(Code::kPrologueOffsetNotSet), + no_frame_ranges_(isolate->cpu_profiler()->is_profiling() + ? new List(2) + : nullptr), + track_positions_(FLAG_hydrogen_track_positions), + opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), + parameter_count_(0), + optimization_id_(-1), + aborted_due_to_dependency_change_(false), + osr_expr_stack_height_(0) { + std::fill_n(dependencies_, DependentCode::kGroupCount, nullptr); +} + + CompilationInfo::~CompilationInfo() { DisableFutureOptimization(); delete deferred_handles_; delete no_frame_ranges_; - delete inlined_function_infos_; #ifdef DEBUG // Check that no dependent maps have been added or added dependent maps have // been rolled back or committed. @@ -267,9 +244,8 @@ int CompilationInfo::TraceInlinedFunction(Handle shared, SourcePosition position, int parent_id) { DCHECK(track_positions_); - DCHECK(inlined_function_infos_); - int inline_id = static_cast(inlined_function_infos_->size()); + int inline_id = static_cast(inlined_function_infos_.size()); InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId, shared->start_position()); if (!shared->script()->IsUndefined()) { @@ -296,7 +272,7 @@ int CompilationInfo::TraceInlinedFunction(Handle shared, } } - inlined_function_infos_->push_back(info); + inlined_function_infos_.push_back(info); if (FLAG_hydrogen_track_positions && inline_id != 0) { CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); @@ -312,9 +288,8 @@ int CompilationInfo::TraceInlinedFunction(Handle shared, void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { if (!track_positions_ || IsStub()) return; - DCHECK_LT(static_cast(inlining_id), inlined_function_infos_->size()); - inlined_function_infos_->at(inlining_id) - .deopt_pc_offsets.push_back(pc_offset); + DCHECK_LT(static_cast(inlining_id), inlined_function_infos_.size()); + inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); } @@ -926,7 +901,9 @@ MaybeHandle Compiler::GetUnoptimizedCode( DCHECK(!shared->GetIsolate()->has_pending_exception()); DCHECK(!shared->is_compiled()); - CompilationInfoWithZone info(shared); + Zone zone; + ParseInfo parse_info(&zone, shared); + CompilationInfo info(&parse_info); return GetUnoptimizedCodeCommon(&info); } @@ -953,10 +930,10 @@ bool Compiler::EnsureCompiled(Handle function, bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { DCHECK(info->function() != NULL); DCHECK(info->scope() != NULL); - if (!info->shared_info()->has_deoptimization_support()) { + Handle shared = info->shared_info(); + if (!shared->has_deoptimization_support()) { // TODO(titzer): just reuse the ParseInfo for the unoptimized compile. - Handle shared = info->shared_info(); - CompilationInfoWithZone unoptimized(shared); + CompilationInfoWithZone unoptimized(info->closure()); // Note that we use the same AST that we will use for generating the // optimized code. ParseInfo* parse_info = unoptimized.parse_info(); @@ -1581,11 +1558,6 @@ CompilationInfoWithZone::CompilationInfoWithZone(Handle function) : CompilationInfo(new ParseInfo(&zone_, function)) {} -CompilationInfoWithZone::CompilationInfoWithZone( - Handle shared_info) - : CompilationInfo(new ParseInfo(&zone_, shared_info)) {} - - CompilationInfoWithZone::~CompilationInfoWithZone() { DisableFutureOptimization(); RollbackDependencies(); diff --git a/src/compiler.h b/src/compiler.h index 56bbf3778d..e585626647 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -346,13 +346,8 @@ class CompilationInfo { return result; } - std::vector* inlined_function_infos() { - return inlined_function_infos_; - } - std::vector* ReleaseInlinedFunctionInfos() { - std::vector* tmp = inlined_function_infos_; - inlined_function_infos_ = NULL; - return tmp; + int start_position_for(uint32_t inlining_id) { + return inlined_function_infos_.at(inlining_id).start_position; } void LogDeoptCallPosition(int pc_offset, int inlining_id); @@ -405,8 +400,6 @@ class CompilationInfo { } private: - Isolate* isolate_; - // Compilation mode. // BASE is generated by the full codegen, optionally prepared for bailouts. // OPTIMIZE is optimized code generated by the Hydrogen-based backend. @@ -419,7 +412,10 @@ class CompilationInfo { STUB }; - void Initialize(Isolate* isolate, Mode mode, Zone* zone); + CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, Mode mode, + Isolate* isolate, Zone* zone); + + Isolate* isolate_; void SetMode(Mode mode) { mode_ = mode; @@ -464,7 +460,7 @@ class CompilationInfo { int prologue_offset_; List* no_frame_ranges_; - std::vector* inlined_function_infos_; + std::vector inlined_function_infos_; bool track_positions_; // A copy of shared_info()->opt_count() to avoid handle deref @@ -493,7 +489,6 @@ class CompilationInfo { class CompilationInfoWithZone: public CompilationInfo { public: explicit CompilationInfoWithZone(Handle