OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "src/runtime-profiler.h" | 27 #include "src/runtime-profiler.h" |
28 #include "src/scanner-character-streams.h" | 28 #include "src/scanner-character-streams.h" |
29 #include "src/scopeinfo.h" | 29 #include "src/scopeinfo.h" |
30 #include "src/scopes.h" | 30 #include "src/scopes.h" |
31 #include "src/typing.h" | 31 #include "src/typing.h" |
32 #include "src/vm-state-inl.h" | 32 #include "src/vm-state-inl.h" |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 | |
38 std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { | 37 std::ostream& operator<<(std::ostream& os, const SourcePosition& p) { |
39 if (p.IsUnknown()) { | 38 if (p.IsUnknown()) { |
40 return os << "<?>"; | 39 return os << "<?>"; |
41 } else if (FLAG_hydrogen_track_positions) { | 40 } else if (FLAG_hydrogen_track_positions) { |
42 return os << "<" << p.inlining_id() << ":" << p.position() << ">"; | 41 return os << "<" << p.inlining_id() << ":" << p.position() << ">"; |
43 } else { | 42 } else { |
44 return os << "<0:" << p.raw() << ">"; | 43 return os << "<0:" << p.raw() << ">"; |
45 } | 44 } |
46 } | 45 } |
47 | 46 |
48 | 47 |
49 ScriptData::ScriptData(const byte* data, int length) | 48 #define PARSE_INFO_GETTER(type, name) \ |
50 : owns_data_(false), rejected_(false), data_(data), length_(length) { | 49 type CompilationInfo::name() const { \ |
51 if (!IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)) { | 50 CHECK(parse_info()); \ |
52 byte* copy = NewArray<byte>(length); | 51 return parse_info()->name(); \ |
53 DCHECK(IsAligned(reinterpret_cast<intptr_t>(copy), kPointerAlignment)); | |
54 CopyBytes(copy, data, length); | |
55 data_ = copy; | |
56 AcquireDataOwnership(); | |
57 } | 52 } |
53 | |
54 | |
55 #define PARSE_INFO_GETTER_WITH_DEFAULT(type, name, def) \ | |
56 type CompilationInfo::name() const { \ | |
57 return parse_info() ? parse_info()->name() : def; \ | |
58 } | |
59 | |
60 | |
61 PARSE_INFO_GETTER(Handle<Script>, script) | |
62 PARSE_INFO_GETTER(bool, is_eval) | |
63 PARSE_INFO_GETTER(bool, is_native) | |
64 PARSE_INFO_GETTER(bool, is_module) | |
65 PARSE_INFO_GETTER(bool, this_has_uses) | |
66 PARSE_INFO_GETTER(LanguageMode, language_mode) | |
67 PARSE_INFO_GETTER_WITH_DEFAULT(Handle<JSFunction>, closure, | |
68 Handle<JSFunction>::null()) | |
69 PARSE_INFO_GETTER(FunctionLiteral*, function) | |
70 PARSE_INFO_GETTER_WITH_DEFAULT(Scope*, scope, nullptr) | |
71 PARSE_INFO_GETTER(Handle<Context>, context) | |
72 PARSE_INFO_GETTER(Handle<SharedFunctionInfo>, shared_info) | |
73 | |
74 #undef PARSE_INFO_GETTER | |
75 #undef PARSE_INFO_GETTER_WITH_DEFAULT | |
76 | |
77 | |
78 bool CompilationInfo::has_shared_info() const { | |
79 return parse_info_ && !parse_info_->shared_info().is_null(); | |
58 } | 80 } |
59 | 81 |
60 | 82 |
61 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) | 83 CompilationInfo::CompilationInfo(ParseInfo* parse_info) |
62 : flags_(kThisHasUses), | 84 : parse_info_(parse_info), |
63 script_(script), | 85 flags_(0), |
64 source_stream_(NULL), | |
65 osr_ast_id_(BailoutId::None()), | 86 osr_ast_id_(BailoutId::None()), |
66 parameter_count_(0), | 87 parameter_count_(0), |
67 optimization_id_(-1), | 88 optimization_id_(-1), |
68 ast_value_factory_(NULL), | |
69 ast_value_factory_owned_(false), | |
70 aborted_due_to_dependency_change_(false), | 89 aborted_due_to_dependency_change_(false), |
71 osr_expr_stack_height_(0) { | 90 osr_expr_stack_height_(0) { |
72 Initialize(script->GetIsolate(), BASE, zone); | 91 Initialize(parse_info->isolate(), BASE, parse_info->zone()); |
73 } | |
74 | |
75 | |
76 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | |
77 Zone* zone) | |
78 : flags_(kLazy | kThisHasUses), | |
79 shared_info_(shared_info), | |
80 script_(Handle<Script>(Script::cast(shared_info->script()))), | |
81 source_stream_(NULL), | |
82 osr_ast_id_(BailoutId::None()), | |
83 parameter_count_(0), | |
84 optimization_id_(-1), | |
85 ast_value_factory_(NULL), | |
86 ast_value_factory_owned_(false), | |
87 aborted_due_to_dependency_change_(false), | |
88 osr_expr_stack_height_(0) { | |
89 Initialize(script_->GetIsolate(), BASE, zone); | |
90 } | |
91 | |
92 | |
93 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) | |
94 : flags_(kLazy | kThisHasUses), | |
95 closure_(closure), | |
96 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | |
97 script_(Handle<Script>(Script::cast(shared_info_->script()))), | |
98 source_stream_(NULL), | |
99 context_(closure->context()), | |
100 osr_ast_id_(BailoutId::None()), | |
101 parameter_count_(0), | |
102 optimization_id_(-1), | |
103 ast_value_factory_(NULL), | |
104 ast_value_factory_owned_(false), | |
105 aborted_due_to_dependency_change_(false), | |
106 osr_expr_stack_height_(0) { | |
107 Initialize(script_->GetIsolate(), BASE, zone); | |
108 } | 92 } |
109 | 93 |
110 | 94 |
111 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) | 95 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) |
112 : flags_(kLazy | kThisHasUses), | 96 : parse_info_(nullptr), |
113 source_stream_(NULL), | 97 flags_(0), |
114 osr_ast_id_(BailoutId::None()), | 98 osr_ast_id_(BailoutId::None()), |
115 parameter_count_(0), | 99 parameter_count_(0), |
116 optimization_id_(-1), | 100 optimization_id_(-1), |
117 ast_value_factory_(NULL), | |
118 ast_value_factory_owned_(false), | |
119 aborted_due_to_dependency_change_(false), | 101 aborted_due_to_dependency_change_(false), |
120 osr_expr_stack_height_(0) { | 102 osr_expr_stack_height_(0) { |
121 Initialize(isolate, STUB, zone); | 103 Initialize(isolate, STUB, zone); |
122 code_stub_ = stub; | 104 code_stub_ = stub; |
123 } | 105 } |
124 | 106 |
125 | 107 |
126 CompilationInfo::CompilationInfo( | |
127 ScriptCompiler::ExternalSourceStream* stream, | |
128 ScriptCompiler::StreamedSource::Encoding encoding, Isolate* isolate, | |
129 Zone* zone) | |
130 : flags_(kThisHasUses), | |
131 source_stream_(stream), | |
132 source_stream_encoding_(encoding), | |
133 osr_ast_id_(BailoutId::None()), | |
134 parameter_count_(0), | |
135 optimization_id_(-1), | |
136 ast_value_factory_(NULL), | |
137 ast_value_factory_owned_(false), | |
138 aborted_due_to_dependency_change_(false), | |
139 osr_expr_stack_height_(0) { | |
140 Initialize(isolate, BASE, zone); | |
141 } | |
142 | |
143 | |
144 void CompilationInfo::Initialize(Isolate* isolate, | 108 void CompilationInfo::Initialize(Isolate* isolate, |
145 Mode mode, | 109 Mode mode, |
146 Zone* zone) { | 110 Zone* zone) { |
147 isolate_ = isolate; | 111 isolate_ = isolate; |
148 function_ = NULL; | |
149 scope_ = NULL; | |
150 script_scope_ = NULL; | |
151 extension_ = NULL; | |
152 cached_data_ = NULL; | |
153 compile_options_ = ScriptCompiler::kNoCompileOptions; | |
154 zone_ = zone; | 112 zone_ = zone; |
155 deferred_handles_ = NULL; | 113 deferred_handles_ = NULL; |
156 code_stub_ = NULL; | 114 code_stub_ = NULL; |
157 prologue_offset_ = Code::kPrologueOffsetNotSet; | 115 prologue_offset_ = Code::kPrologueOffsetNotSet; |
158 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); | 116 opt_count_ = has_shared_info() ? shared_info()->opt_count() : 0; |
159 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() | 117 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
160 ? new List<OffsetRange>(2) : NULL; | 118 ? new List<OffsetRange>(2) : NULL; |
161 if (FLAG_hydrogen_track_positions) { | 119 if (FLAG_hydrogen_track_positions) { |
162 inlined_function_infos_ = new List<InlinedFunctionInfo>(5); | 120 inlined_function_infos_ = new List<InlinedFunctionInfo>(5); |
163 inlining_id_to_function_id_ = new List<int>(5); | 121 inlining_id_to_function_id_ = new List<int>(5); |
164 } else { | 122 } else { |
165 inlined_function_infos_ = NULL; | 123 inlined_function_infos_ = NULL; |
166 inlining_id_to_function_id_ = NULL; | 124 inlining_id_to_function_id_ = NULL; |
167 } | 125 } |
168 | 126 |
169 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 127 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
170 dependencies_[i] = NULL; | 128 dependencies_[i] = NULL; |
171 } | 129 } |
172 if (mode == STUB) { | 130 if (mode == STUB) { |
173 mode_ = STUB; | 131 mode_ = STUB; |
174 return; | 132 return; |
175 } | 133 } |
176 mode_ = mode; | 134 mode_ = mode; |
177 if (!script_.is_null() && script_->type()->value() == Script::TYPE_NATIVE) { | |
178 MarkAsNative(); | |
179 } | |
180 // Compiling for the snapshot typically results in different code than | 135 // Compiling for the snapshot typically results in different code than |
181 // compiling later on. This means that code recompiled with deoptimization | 136 // compiling later on. This means that code recompiled with deoptimization |
182 // support won't be "equivalent" (as defined by SharedFunctionInfo:: | 137 // support won't be "equivalent" (as defined by SharedFunctionInfo:: |
183 // EnableDeoptimizationSupport), so it will replace the old code and all | 138 // EnableDeoptimizationSupport), so it will replace the old code and all |
184 // its type feedback. To avoid this, always compile functions in the snapshot | 139 // its type feedback. To avoid this, always compile functions in the snapshot |
185 // with deoptimization support. | 140 // with deoptimization support. |
186 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); | 141 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); |
187 | 142 |
188 if (isolate_->debug()->is_active()) MarkAsDebug(); | 143 if (isolate_->debug()->is_active()) MarkAsDebug(); |
189 if (FLAG_context_specialization) MarkAsContextSpecializing(); | 144 if (FLAG_context_specialization) MarkAsContextSpecializing(); |
190 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); | 145 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); |
191 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); | 146 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); |
192 if (FLAG_turbo_types) MarkAsTypingEnabled(); | 147 if (FLAG_turbo_types) MarkAsTypingEnabled(); |
193 | 148 |
194 if (!shared_info_.is_null()) { | |
195 DCHECK(is_sloppy(language_mode())); | |
196 SetLanguageMode(shared_info_->language_mode()); | |
197 } | |
198 bailout_reason_ = kNoReason; | 149 bailout_reason_ = kNoReason; |
199 | 150 |
200 if (!shared_info().is_null() && shared_info()->is_compiled()) { | 151 if (has_shared_info() && shared_info()->is_compiled()) { |
201 // We should initialize the CompilationInfo feedback vector from the | 152 // We should initialize the CompilationInfo feedback vector from the |
202 // passed in shared info, rather than creating a new one. | 153 // passed in shared info, rather than creating a new one. |
203 feedback_vector_ = | 154 feedback_vector_ = |
204 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate); | 155 Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate); |
205 } | 156 } |
206 } | 157 } |
207 | 158 |
208 | 159 |
209 CompilationInfo::~CompilationInfo() { | 160 CompilationInfo::~CompilationInfo() { |
210 if (GetFlag(kDisableFutureOptimization)) { | 161 DisableFutureOptimization(); |
211 shared_info()->DisableOptimization(bailout_reason()); | |
212 } | |
213 delete deferred_handles_; | 162 delete deferred_handles_; |
214 delete no_frame_ranges_; | 163 delete no_frame_ranges_; |
215 delete inlined_function_infos_; | 164 delete inlined_function_infos_; |
216 delete inlining_id_to_function_id_; | 165 delete inlining_id_to_function_id_; |
217 if (ast_value_factory_owned_) delete ast_value_factory_; | |
218 #ifdef DEBUG | 166 #ifdef DEBUG |
219 // Check that no dependent maps have been added or added dependent maps have | 167 // Check that no dependent maps have been added or added dependent maps have |
220 // been rolled back or committed. | 168 // been rolled back or committed. |
221 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 169 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
222 DCHECK(!dependencies_[i]); | 170 DCHECK(!dependencies_[i]); |
223 } | 171 } |
224 #endif // DEBUG | 172 #endif // DEBUG |
225 } | 173 } |
226 | 174 |
227 | 175 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 } else { | 248 } else { |
301 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); | 249 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); |
302 } | 250 } |
303 } | 251 } |
304 | 252 |
305 | 253 |
306 // Primitive functions are unlikely to be picked up by the stack-walking | 254 // Primitive functions are unlikely to be picked up by the stack-walking |
307 // profiler, so they trigger their own optimization when they're called | 255 // profiler, so they trigger their own optimization when they're called |
308 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. | 256 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
309 bool CompilationInfo::ShouldSelfOptimize() { | 257 bool CompilationInfo::ShouldSelfOptimize() { |
310 return FLAG_crankshaft && | 258 return FLAG_crankshaft && !function()->flags()->Contains(kDontSelfOptimize) && |
311 !function()->flags()->Contains(kDontSelfOptimize) && | 259 !function()->dont_optimize() && |
312 !function()->dont_optimize() && | 260 function()->scope()->AllowsLazyCompilation() && |
313 function()->scope()->AllowsLazyCompilation() && | 261 (!has_shared_info() || !shared_info()->optimization_disabled()); |
314 (shared_info().is_null() || !shared_info()->optimization_disabled()); | |
315 } | 262 } |
316 | 263 |
317 | 264 |
318 void CompilationInfo::PrepareForCompilation(Scope* scope) { | |
319 DCHECK(scope_ == NULL); | |
320 scope_ = scope; | |
321 } | |
322 | |
323 | |
324 void CompilationInfo::EnsureFeedbackVector() { | 265 void CompilationInfo::EnsureFeedbackVector() { |
325 if (feedback_vector_.is_null()) { | 266 if (feedback_vector_.is_null()) { |
326 feedback_vector_ = isolate()->factory()->NewTypeFeedbackVector( | 267 feedback_vector_ = isolate()->factory()->NewTypeFeedbackVector( |
327 function()->feedback_vector_spec()); | 268 function()->feedback_vector_spec()); |
328 } | 269 } |
329 } | 270 } |
330 | 271 |
331 | 272 |
332 bool CompilationInfo::is_simple_parameter_list() { | 273 bool CompilationInfo::is_simple_parameter_list() { |
333 return scope_->is_simple_parameter_list(); | 274 return scope()->is_simple_parameter_list(); |
334 } | 275 } |
335 | 276 |
336 | 277 |
337 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | 278 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
338 SourcePosition position) { | 279 SourcePosition position) { |
339 DCHECK(FLAG_hydrogen_track_positions); | 280 DCHECK(FLAG_hydrogen_track_positions); |
340 | 281 |
341 DCHECK(inlined_function_infos_); | 282 DCHECK(inlined_function_infos_); |
342 DCHECK(inlining_id_to_function_id_); | 283 DCHECK(inlining_id_to_function_id_); |
343 int id = 0; | 284 int id = 0; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 if (info()->shared_info()->optimization_disabled()) { | 483 if (info()->shared_info()->optimization_disabled()) { |
543 return AbortOptimization( | 484 return AbortOptimization( |
544 info()->shared_info()->disable_optimization_reason()); | 485 info()->shared_info()->disable_optimization_reason()); |
545 } | 486 } |
546 | 487 |
547 graph_builder_ = (FLAG_hydrogen_track_positions || FLAG_trace_ic) | 488 graph_builder_ = (FLAG_hydrogen_track_positions || FLAG_trace_ic) |
548 ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info()) | 489 ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info()) |
549 : new(info()->zone()) HOptimizedGraphBuilder(info()); | 490 : new(info()->zone()) HOptimizedGraphBuilder(info()); |
550 | 491 |
551 Timer t(this, &time_taken_to_create_graph_); | 492 Timer t(this, &time_taken_to_create_graph_); |
552 info()->set_this_has_uses(false); | 493 // TODO(titzer): ParseInfo::this_has_uses is only used by Crankshaft. Move. |
494 info()->parse_info()->set_this_has_uses(false); | |
553 graph_ = graph_builder_->CreateGraph(); | 495 graph_ = graph_builder_->CreateGraph(); |
554 | 496 |
555 if (isolate()->has_pending_exception()) { | 497 if (isolate()->has_pending_exception()) { |
556 return SetLastStatus(FAILED); | 498 return SetLastStatus(FAILED); |
557 } | 499 } |
558 | 500 |
559 if (graph_ == NULL) return SetLastStatus(BAILED_OUT); | 501 if (graph_ == NULL) return SetLastStatus(BAILED_OUT); |
560 | 502 |
561 if (info()->HasAbortedDueToDependencyChange()) { | 503 if (info()->HasAbortedDueToDependencyChange()) { |
562 // Dependency has changed during graph creation. Let's try again later. | 504 // Dependency has changed during graph creation. Let's try again later. |
(...skipping 29 matching lines...) Expand all Loading... | |
592 | 534 |
593 return SetLastStatus(BAILED_OUT); | 535 return SetLastStatus(BAILED_OUT); |
594 } | 536 } |
595 | 537 |
596 | 538 |
597 OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() { | 539 OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() { |
598 DCHECK(last_status() == SUCCEEDED); | 540 DCHECK(last_status() == SUCCEEDED); |
599 // TODO(turbofan): Currently everything is done in the first phase. | 541 // TODO(turbofan): Currently everything is done in the first phase. |
600 if (!info()->code().is_null()) { | 542 if (!info()->code().is_null()) { |
601 if (FLAG_turbo_deoptimization) { | 543 if (FLAG_turbo_deoptimization) { |
602 info()->context()->native_context()->AddOptimizedCode(*info()->code()); | 544 info()->parse_info()->context()->native_context()->AddOptimizedCode( |
545 *info()->code()); | |
603 } | 546 } |
604 RecordOptimizationStats(); | 547 RecordOptimizationStats(); |
605 return last_status(); | 548 return last_status(); |
606 } | 549 } |
607 | 550 |
608 DCHECK(!info()->HasAbortedDueToDependencyChange()); | 551 DCHECK(!info()->HasAbortedDueToDependencyChange()); |
609 DisallowCodeDependencyChange no_dependency_change; | 552 DisallowCodeDependencyChange no_dependency_change; |
610 DisallowJavascriptExecution no_js(isolate()); | 553 DisallowJavascriptExecution no_js(isolate()); |
611 { // Scope for timer. | 554 { // Scope for timer. |
612 Timer timer(this, &time_taken_to_codegen_); | 555 Timer timer(this, &time_taken_to_codegen_); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 CompilationInfo* info, | 647 CompilationInfo* info, |
705 Handle<SharedFunctionInfo> shared) { | 648 Handle<SharedFunctionInfo> shared) { |
706 // SharedFunctionInfo is passed separately, because if CompilationInfo | 649 // SharedFunctionInfo is passed separately, because if CompilationInfo |
707 // was created using Script object, it will not have it. | 650 // was created using Script object, it will not have it. |
708 | 651 |
709 // Log the code generation. If source information is available include | 652 // Log the code generation. If source information is available include |
710 // script name and line number. Check explicitly whether logging is | 653 // script name and line number. Check explicitly whether logging is |
711 // enabled as finding the line number is not free. | 654 // enabled as finding the line number is not free. |
712 if (info->isolate()->logger()->is_logging_code_events() || | 655 if (info->isolate()->logger()->is_logging_code_events() || |
713 info->isolate()->cpu_profiler()->is_profiling()) { | 656 info->isolate()->cpu_profiler()->is_profiling()) { |
714 Handle<Script> script = info->script(); | 657 Handle<Script> script = info->parse_info()->script(); |
715 Handle<Code> code = info->code(); | 658 Handle<Code> code = info->code(); |
716 if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) { | 659 if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) { |
717 return; | 660 return; |
718 } | 661 } |
719 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; | 662 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
720 int column_num = | 663 int column_num = |
721 Script::GetColumnNumber(script, shared->start_position()) + 1; | 664 Script::GetColumnNumber(script, shared->start_position()) + 1; |
722 String* script_name = script->name()->IsString() | 665 String* script_name = script->name()->IsString() |
723 ? String::cast(script->name()) | 666 ? String::cast(script->name()) |
724 : info->isolate()->heap()->empty_string(); | 667 : info->isolate()->heap()->empty_string(); |
725 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); | 668 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); |
726 PROFILE(info->isolate(), | 669 PROFILE(info->isolate(), |
727 CodeCreateEvent(log_tag, *code, *shared, info, script_name, | 670 CodeCreateEvent(log_tag, *code, *shared, info, script_name, |
728 line_num, column_num)); | 671 line_num, column_num)); |
729 } | 672 } |
730 } | 673 } |
731 | 674 |
732 | 675 |
733 static bool CompileUnoptimizedCode(CompilationInfo* info) { | 676 static bool CompileUnoptimizedCode(CompilationInfo* info) { |
734 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 677 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
735 if (!Compiler::Analyze(info) || !FullCodeGenerator::MakeCode(info)) { | 678 if (!Compiler::Analyze(info->parse_info()) || |
679 !FullCodeGenerator::MakeCode(info)) { | |
736 Isolate* isolate = info->isolate(); | 680 Isolate* isolate = info->isolate(); |
737 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 681 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
738 return false; | 682 return false; |
739 } | 683 } |
740 return true; | 684 return true; |
741 } | 685 } |
742 | 686 |
743 | 687 |
744 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( | 688 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
745 CompilationInfo* info) { | 689 CompilationInfo* info) { |
746 VMState<COMPILER> state(info->isolate()); | 690 VMState<COMPILER> state(info->isolate()); |
747 PostponeInterruptsScope postpone(info->isolate()); | 691 PostponeInterruptsScope postpone(info->isolate()); |
748 | 692 |
749 // Parse and update CompilationInfo with the results. | 693 // Parse and update CompilationInfo with the results. |
750 if (!Parser::ParseStatic(info)) return MaybeHandle<Code>(); | 694 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); |
751 Handle<SharedFunctionInfo> shared = info->shared_info(); | 695 Handle<SharedFunctionInfo> shared = info->shared_info(); |
752 FunctionLiteral* lit = info->function(); | 696 FunctionLiteral* lit = info->function(); |
753 shared->set_language_mode(lit->language_mode()); | 697 shared->set_language_mode(lit->language_mode()); |
754 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 698 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
755 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); | 699 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); |
756 | 700 |
757 // Compile unoptimized code. | 701 // Compile unoptimized code. |
758 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 702 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
759 | 703 |
760 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 704 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 // Do not cache bound functions. | 760 // Do not cache bound functions. |
817 if (shared->bound()) return; | 761 if (shared->bound()) return; |
818 Handle<FixedArray> literals(function->literals()); | 762 Handle<FixedArray> literals(function->literals()); |
819 Handle<Context> native_context(function->context()->native_context()); | 763 Handle<Context> native_context(function->context()->native_context()); |
820 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 764 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
821 literals, info->osr_ast_id()); | 765 literals, info->osr_ast_id()); |
822 } | 766 } |
823 } | 767 } |
824 | 768 |
825 | 769 |
826 static bool Renumber(CompilationInfo* info) { | 770 static bool Renumber(ParseInfo* parse_info) { |
827 if (!AstNumbering::Renumber(info->isolate(), info->zone(), | 771 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
828 info->function())) { | 772 parse_info->function())) { |
829 return false; | 773 return false; |
830 } | 774 } |
831 if (!info->shared_info().is_null()) { | 775 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
832 FunctionLiteral* lit = info->function(); | 776 if (!shared_info.is_null()) { |
833 info->shared_info()->set_ast_node_count(lit->ast_node_count()); | 777 FunctionLiteral* lit = parse_info->function(); |
834 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); | 778 shared_info->set_ast_node_count(lit->ast_node_count()); |
835 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); | 779 MaybeDisableOptimization(shared_info, lit->dont_optimize_reason()); |
780 shared_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | |
836 } | 781 } |
837 return true; | 782 return true; |
838 } | 783 } |
839 | 784 |
840 | 785 |
841 bool Compiler::Analyze(CompilationInfo* info) { | 786 bool Compiler::Analyze(ParseInfo* info) { |
842 DCHECK(info->function() != NULL); | 787 DCHECK(info->function() != NULL); |
843 if (!Rewriter::Rewrite(info)) return false; | 788 if (!Rewriter::Rewrite(info)) return false; |
844 if (!Scope::Analyze(info)) return false; | 789 if (!Scope::Analyze(info)) return false; |
845 if (!Renumber(info)) return false; | 790 if (!Renumber(info)) return false; |
846 DCHECK(info->scope() != NULL); | 791 DCHECK(info->scope() != NULL); |
847 return true; | 792 return true; |
848 } | 793 } |
849 | 794 |
850 | 795 |
851 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { | 796 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
852 if (!Parser::ParseStatic(info)) return false; | 797 if (!Parser::ParseStatic(info)) return false; |
853 return Compiler::Analyze(info); | 798 return Compiler::Analyze(info); |
854 } | 799 } |
855 | 800 |
856 | 801 |
857 static bool GetOptimizedCodeNow(CompilationInfo* info) { | 802 static bool GetOptimizedCodeNow(CompilationInfo* info) { |
858 if (!Compiler::ParseAndAnalyze(info)) return false; | 803 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
859 | 804 |
860 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 805 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
861 | 806 |
862 OptimizedCompileJob job(info); | 807 OptimizedCompileJob job(info); |
863 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || | 808 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || |
864 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || | 809 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || |
865 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { | 810 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { |
866 if (FLAG_trace_opt) { | 811 if (FLAG_trace_opt) { |
867 PrintF("[aborted optimizing "); | 812 PrintF("[aborted optimizing "); |
868 info->closure()->ShortPrint(); | 813 info->closure()->ShortPrint(); |
(...skipping 16 matching lines...) Expand all Loading... | |
885 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 830 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
886 if (FLAG_trace_concurrent_recompilation) { | 831 if (FLAG_trace_concurrent_recompilation) { |
887 PrintF(" ** Compilation queue full, will retry optimizing "); | 832 PrintF(" ** Compilation queue full, will retry optimizing "); |
888 info->closure()->ShortPrint(); | 833 info->closure()->ShortPrint(); |
889 PrintF(" later.\n"); | 834 PrintF(" later.\n"); |
890 } | 835 } |
891 return false; | 836 return false; |
892 } | 837 } |
893 | 838 |
894 CompilationHandleScope handle_scope(info); | 839 CompilationHandleScope handle_scope(info); |
895 if (!Compiler::ParseAndAnalyze(info)) return false; | 840 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
896 info->SaveHandles(); // Copy handles to the compilation handle scope. | 841 |
842 // Reopen handles in the new CompilationHandleScope. | |
843 info->ReopenHandlesInNewHandleScope(); | |
844 info->parse_info()->ReopenHandlesInNewHandleScope(); | |
897 | 845 |
898 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 846 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
899 | 847 |
900 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); | 848 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); |
901 OptimizedCompileJob::Status status = job->CreateGraph(); | 849 OptimizedCompileJob::Status status = job->CreateGraph(); |
902 if (status != OptimizedCompileJob::SUCCEEDED) return false; | 850 if (status != OptimizedCompileJob::SUCCEEDED) return false; |
903 isolate->optimizing_compiler_thread()->QueueForOptimization(job); | 851 isolate->optimizing_compiler_thread()->QueueForOptimization(job); |
904 | 852 |
905 if (FLAG_trace_concurrent_recompilation) { | 853 if (FLAG_trace_concurrent_recompilation) { |
906 PrintF(" ** Queued "); | 854 PrintF(" ** Queued "); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 return true; | 954 return true; |
1007 } | 955 } |
1008 | 956 |
1009 | 957 |
1010 // TODO(turbofan): In the future, unoptimized code with deopt support could | 958 // TODO(turbofan): In the future, unoptimized code with deopt support could |
1011 // be generated lazily once deopt is triggered. | 959 // be generated lazily once deopt is triggered. |
1012 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 960 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
1013 DCHECK(info->function() != NULL); | 961 DCHECK(info->function() != NULL); |
1014 DCHECK(info->scope() != NULL); | 962 DCHECK(info->scope() != NULL); |
1015 if (!info->shared_info()->has_deoptimization_support()) { | 963 if (!info->shared_info()->has_deoptimization_support()) { |
964 // TODO(titzer): just reuse the ParseInfo for the unoptimized compile. | |
1016 Handle<SharedFunctionInfo> shared = info->shared_info(); | 965 Handle<SharedFunctionInfo> shared = info->shared_info(); |
1017 CompilationInfoWithZone unoptimized(shared); | 966 CompilationInfoWithZone unoptimized(shared); |
1018 // Note that we use the same AST that we will use for generating the | 967 // Note that we use the same AST that we will use for generating the |
1019 // optimized code. | 968 // optimized code. |
1020 unoptimized.SetFunction(info->function()); | 969 ParseInfo* parse_info = unoptimized.parse_info(); |
1021 unoptimized.PrepareForCompilation(info->scope()); | 970 parse_info->set_literal(info->function()); |
1022 unoptimized.SetContext(info->context()); | 971 parse_info->set_scope(info->scope()); |
972 parse_info->set_context(info->context()); | |
1023 unoptimized.EnableDeoptimizationSupport(); | 973 unoptimized.EnableDeoptimizationSupport(); |
1024 // If the current code has reloc info for serialization, also include | 974 // If the current code has reloc info for serialization, also include |
1025 // reloc info for serialization for the new code, so that deopt support | 975 // reloc info for serialization for the new code, so that deopt support |
1026 // can be added without losing IC state. | 976 // can be added without losing IC state. |
1027 if (shared->code()->kind() == Code::FUNCTION && | 977 if (shared->code()->kind() == Code::FUNCTION && |
1028 shared->code()->has_reloc_info_for_serialization()) { | 978 shared->code()->has_reloc_info_for_serialization()) { |
1029 unoptimized.PrepareForSerializing(); | 979 unoptimized.PrepareForSerializing(); |
1030 } | 980 } |
1031 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; | 981 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; |
1032 | 982 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 return maybe_new_code; | 1036 return maybe_new_code; |
1087 } | 1037 } |
1088 | 1038 |
1089 | 1039 |
1090 void Compiler::CompileForLiveEdit(Handle<Script> script) { | 1040 void Compiler::CompileForLiveEdit(Handle<Script> script) { |
1091 // TODO(635): support extensions. | 1041 // TODO(635): support extensions. |
1092 CompilationInfoWithZone info(script); | 1042 CompilationInfoWithZone info(script); |
1093 PostponeInterruptsScope postpone(info.isolate()); | 1043 PostponeInterruptsScope postpone(info.isolate()); |
1094 VMState<COMPILER> state(info.isolate()); | 1044 VMState<COMPILER> state(info.isolate()); |
1095 | 1045 |
1096 info.MarkAsGlobal(); | 1046 info.parse_info()->set_global(); |
1097 if (!Parser::ParseStatic(&info)) return; | 1047 if (!Parser::ParseStatic(info.parse_info())) return; |
1098 | 1048 |
1099 LiveEditFunctionTracker tracker(info.isolate(), info.function()); | 1049 LiveEditFunctionTracker tracker(info.isolate(), info.function()); |
1100 if (!CompileUnoptimizedCode(&info)) return; | 1050 if (!CompileUnoptimizedCode(&info)) return; |
1101 if (!info.shared_info().is_null()) { | 1051 if (info.has_shared_info()) { |
1102 Handle<ScopeInfo> scope_info = | 1052 Handle<ScopeInfo> scope_info = |
1103 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1053 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1104 info.shared_info()->set_scope_info(*scope_info); | 1054 info.shared_info()->set_scope_info(*scope_info); |
1105 } | 1055 } |
1106 tracker.RecordRootFunctionInfo(info.code()); | 1056 tracker.RecordRootFunctionInfo(info.code()); |
1107 } | 1057 } |
1108 | 1058 |
1109 | 1059 |
1110 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { | 1060 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
1111 Isolate* isolate = info->isolate(); | 1061 Isolate* isolate = info->isolate(); |
1112 PostponeInterruptsScope postpone(isolate); | 1062 PostponeInterruptsScope postpone(isolate); |
1113 DCHECK(!isolate->native_context().is_null()); | 1063 DCHECK(!isolate->native_context().is_null()); |
1114 Handle<Script> script = info->script(); | 1064 ParseInfo* parse_info = info->parse_info(); |
1065 Handle<Script> script = parse_info->script(); | |
1115 | 1066 |
1116 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 1067 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
1117 FixedArray* array = isolate->native_context()->embedder_data(); | 1068 FixedArray* array = isolate->native_context()->embedder_data(); |
1118 script->set_context_data(array->get(0)); | 1069 script->set_context_data(array->get(0)); |
1119 | 1070 |
1120 isolate->debug()->OnBeforeCompile(script); | 1071 isolate->debug()->OnBeforeCompile(script); |
1121 | 1072 |
1122 DCHECK(info->is_eval() || info->is_global() || info->is_module()); | 1073 DCHECK(parse_info->is_eval() || parse_info->is_global() || |
1074 parse_info->is_module()); | |
1123 | 1075 |
1124 info->MarkAsToplevel(); | 1076 parse_info->set_toplevel(); |
1125 | 1077 |
1126 Handle<SharedFunctionInfo> result; | 1078 Handle<SharedFunctionInfo> result; |
1127 | 1079 |
1128 { VMState<COMPILER> state(info->isolate()); | 1080 { VMState<COMPILER> state(info->isolate()); |
1129 if (info->function() == NULL) { | 1081 if (info->function() == NULL) { |
1130 // Parse the script if needed (if it's already parsed, function() is | 1082 // Parse the script if needed (if it's already parsed, function() is |
1131 // non-NULL). | 1083 // non-NULL). |
1132 bool parse_allow_lazy = | 1084 ScriptCompiler::CompileOptions options = |
1133 (info->compile_options() == ScriptCompiler::kConsumeParserCache || | 1085 info->parse_info()->compile_options(); |
1134 String::cast(script->source())->length() > | 1086 bool parse_allow_lazy = (options == ScriptCompiler::kConsumeParserCache || |
1135 FLAG_min_preparse_length) && | 1087 String::cast(script->source())->length() > |
1136 !Compiler::DebuggerWantsEagerCompilation(info); | 1088 FLAG_min_preparse_length) && |
1089 !Compiler::DebuggerWantsEagerCompilation(isolate); | |
1137 | 1090 |
1091 info->parse_info()->set_allow_lazy_parsing(parse_allow_lazy); | |
1138 if (!parse_allow_lazy && | 1092 if (!parse_allow_lazy && |
1139 (info->compile_options() == ScriptCompiler::kProduceParserCache || | 1093 (options == ScriptCompiler::kProduceParserCache || |
1140 info->compile_options() == ScriptCompiler::kConsumeParserCache)) { | 1094 options == ScriptCompiler::kConsumeParserCache)) { |
1141 // We are going to parse eagerly, but we either 1) have cached data | 1095 // We are going to parse eagerly, but we either 1) have cached data |
1142 // produced by lazy parsing or 2) are asked to generate cached data. | 1096 // produced by lazy parsing or 2) are asked to generate cached data. |
1143 // Eager parsing cannot benefit from cached data, and producing cached | 1097 // Eager parsing cannot benefit from cached data, and producing cached |
1144 // data while parsing eagerly is not implemented. | 1098 // data while parsing eagerly is not implemented. |
1145 info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions); | 1099 info->parse_info()->set_cached_data(nullptr); |
marja
2015/03/09 09:18:07
Nit: you already have parse_info, so s/info->parse
titzer
2015/03/09 13:03:09
Done.
| |
1100 info->parse_info()->set_compile_options( | |
1101 ScriptCompiler::kNoCompileOptions); | |
1146 } | 1102 } |
1147 if (!Parser::ParseStatic(info, parse_allow_lazy)) { | 1103 if (!Parser::ParseStatic(info->parse_info())) { |
1148 return Handle<SharedFunctionInfo>::null(); | 1104 return Handle<SharedFunctionInfo>::null(); |
1149 } | 1105 } |
1150 } | 1106 } |
1151 | 1107 |
1152 FunctionLiteral* lit = info->function(); | 1108 FunctionLiteral* lit = info->function(); |
1153 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | 1109 LiveEditFunctionTracker live_edit_tracker(isolate, lit); |
1154 | 1110 |
1155 // Measure how long it takes to do the compilation; only take the | 1111 // Measure how long it takes to do the compilation; only take the |
1156 // rest of the function into account to avoid overlap with the | 1112 // rest of the function into account to avoid overlap with the |
1157 // parsing statistics. | 1113 // parsing statistics. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 | 1173 |
1218 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1174 CompilationCache* compilation_cache = isolate->compilation_cache(); |
1219 MaybeHandle<SharedFunctionInfo> maybe_shared_info = | 1175 MaybeHandle<SharedFunctionInfo> maybe_shared_info = |
1220 compilation_cache->LookupEval(source, outer_info, context, language_mode, | 1176 compilation_cache->LookupEval(source, outer_info, context, language_mode, |
1221 scope_position); | 1177 scope_position); |
1222 Handle<SharedFunctionInfo> shared_info; | 1178 Handle<SharedFunctionInfo> shared_info; |
1223 | 1179 |
1224 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1180 if (!maybe_shared_info.ToHandle(&shared_info)) { |
1225 Handle<Script> script = isolate->factory()->NewScript(source); | 1181 Handle<Script> script = isolate->factory()->NewScript(source); |
1226 CompilationInfoWithZone info(script); | 1182 CompilationInfoWithZone info(script); |
1227 info.MarkAsEval(); | 1183 ParseInfo* parse_info = info.parse_info(); |
1228 if (context->IsNativeContext()) info.MarkAsGlobal(); | 1184 parse_info->set_eval(); |
1229 info.SetLanguageMode(language_mode); | 1185 if (context->IsNativeContext()) parse_info->set_global(); |
1230 info.SetParseRestriction(restriction); | 1186 parse_info->set_language_mode(language_mode); |
1231 info.SetContext(context); | 1187 parse_info->set_parse_restriction(restriction); |
1188 parse_info->set_context(context); | |
1232 | 1189 |
1233 Debug::RecordEvalCaller(script); | 1190 Debug::RecordEvalCaller(script); |
1234 | 1191 |
1235 shared_info = CompileToplevel(&info); | 1192 shared_info = CompileToplevel(&info); |
1236 | 1193 |
1237 if (shared_info.is_null()) { | 1194 if (shared_info.is_null()) { |
1238 return MaybeHandle<JSFunction>(); | 1195 return MaybeHandle<JSFunction>(); |
1239 } else { | 1196 } else { |
1240 // Explicitly disable optimization for eval code. We're not yet prepared | 1197 // Explicitly disable optimization for eval code. We're not yet prepared |
1241 // to handle eval-code in the optimizing compiler. | 1198 // to handle eval-code in the optimizing compiler. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 if (!script_name.is_null()) { | 1288 if (!script_name.is_null()) { |
1332 script->set_name(*script_name); | 1289 script->set_name(*script_name); |
1333 script->set_line_offset(Smi::FromInt(line_offset)); | 1290 script->set_line_offset(Smi::FromInt(line_offset)); |
1334 script->set_column_offset(Smi::FromInt(column_offset)); | 1291 script->set_column_offset(Smi::FromInt(column_offset)); |
1335 } | 1292 } |
1336 script->set_is_shared_cross_origin(is_shared_cross_origin); | 1293 script->set_is_shared_cross_origin(is_shared_cross_origin); |
1337 script->set_is_embedder_debug_script(is_embedder_debug_script); | 1294 script->set_is_embedder_debug_script(is_embedder_debug_script); |
1338 | 1295 |
1339 // Compile the function and add it to the cache. | 1296 // Compile the function and add it to the cache. |
1340 CompilationInfoWithZone info(script); | 1297 CompilationInfoWithZone info(script); |
1298 ParseInfo* parse_info = info.parse_info(); | |
1341 if (FLAG_harmony_modules && is_module) { | 1299 if (FLAG_harmony_modules && is_module) { |
1342 info.MarkAsModule(); | 1300 parse_info->set_module(); |
1343 } else { | 1301 } else { |
1344 info.MarkAsGlobal(); | 1302 parse_info->set_global(); |
1345 } | 1303 } |
1346 info.SetCachedData(cached_data, compile_options); | 1304 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
1347 info.SetExtension(extension); | 1305 parse_info->set_cached_data(cached_data); |
1348 info.SetContext(context); | 1306 } |
1307 parse_info->set_compile_options(compile_options); | |
1308 parse_info->set_extension(extension); | |
1309 parse_info->set_context(context); | |
1349 if (FLAG_serialize_toplevel && | 1310 if (FLAG_serialize_toplevel && |
1350 compile_options == ScriptCompiler::kProduceCodeCache) { | 1311 compile_options == ScriptCompiler::kProduceCodeCache) { |
1351 info.PrepareForSerializing(); | 1312 info.PrepareForSerializing(); |
1352 } | 1313 } |
1353 | 1314 |
1354 info.SetLanguageMode( | 1315 parse_info->set_language_mode( |
1355 static_cast<LanguageMode>(info.language_mode() | language_mode)); | 1316 static_cast<LanguageMode>(info.language_mode() | language_mode)); |
1356 result = CompileToplevel(&info); | 1317 result = CompileToplevel(&info); |
1357 if (extension == NULL && !result.is_null() && !result->dont_cache()) { | 1318 if (extension == NULL && !result.is_null() && !result->dont_cache()) { |
1358 compilation_cache->PutScript(source, context, language_mode, result); | 1319 compilation_cache->PutScript(source, context, language_mode, result); |
1359 if (FLAG_serialize_toplevel && | 1320 if (FLAG_serialize_toplevel && |
1360 compile_options == ScriptCompiler::kProduceCodeCache) { | 1321 compile_options == ScriptCompiler::kProduceCodeCache) { |
1361 HistogramTimerScope histogram_timer( | 1322 HistogramTimerScope histogram_timer( |
1362 isolate->counters()->compile_serialize()); | 1323 isolate->counters()->compile_serialize()); |
1363 *cached_data = CodeSerializer::Serialize(isolate, result, source); | 1324 *cached_data = CodeSerializer::Serialize(isolate, result, source); |
1364 if (FLAG_profile_deserialization) { | 1325 if (FLAG_profile_deserialization) { |
1365 PrintF("[Compiling and serializing took %0.3f ms]\n", | 1326 PrintF("[Compiling and serializing took %0.3f ms]\n", |
1366 timer.Elapsed().InMillisecondsF()); | 1327 timer.Elapsed().InMillisecondsF()); |
1367 } | 1328 } |
1368 } | 1329 } |
1369 } | 1330 } |
1370 | 1331 |
1371 if (result.is_null()) isolate->ReportPendingMessages(); | 1332 if (result.is_null()) isolate->ReportPendingMessages(); |
1372 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { | 1333 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { |
1373 result->ResetForNewContext(isolate->heap()->global_ic_age()); | 1334 result->ResetForNewContext(isolate->heap()->global_ic_age()); |
1374 } | 1335 } |
1375 return result; | 1336 return result; |
1376 } | 1337 } |
1377 | 1338 |
1378 | 1339 |
1379 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( | 1340 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( |
1380 CompilationInfo* info, int source_length) { | 1341 Handle<Script> script, ParseInfo* parse_info, int source_length) { |
1381 Isolate* isolate = info->isolate(); | 1342 Isolate* isolate = script->GetIsolate(); |
1343 // TODO(titzer): increment the counters in caller. | |
1382 isolate->counters()->total_load_size()->Increment(source_length); | 1344 isolate->counters()->total_load_size()->Increment(source_length); |
1383 isolate->counters()->total_compile_size()->Increment(source_length); | 1345 isolate->counters()->total_compile_size()->Increment(source_length); |
1384 | 1346 |
1385 LanguageMode language_mode = | 1347 LanguageMode language_mode = |
1386 construct_language_mode(FLAG_use_strict, FLAG_use_strong); | 1348 construct_language_mode(FLAG_use_strict, FLAG_use_strong); |
1387 info->SetLanguageMode( | 1349 parse_info->set_language_mode( |
1388 static_cast<LanguageMode>(info->language_mode() | language_mode)); | 1350 static_cast<LanguageMode>(parse_info->language_mode() | language_mode)); |
1389 | 1351 |
1352 CompilationInfo compile_info(parse_info); | |
1390 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the | 1353 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the |
1391 // real code caching lands, streaming needs to be adapted to use it. | 1354 // real code caching lands, streaming needs to be adapted to use it. |
1392 return CompileToplevel(info); | 1355 return CompileToplevel(&compile_info); |
1393 } | 1356 } |
1394 | 1357 |
1395 | 1358 |
1396 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( | 1359 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( |
1397 FunctionLiteral* literal, Handle<Script> script, | 1360 FunctionLiteral* literal, Handle<Script> script, |
1398 CompilationInfo* outer_info) { | 1361 CompilationInfo* outer_info) { |
1399 // Precondition: code has been parsed and scopes have been analyzed. | 1362 // Precondition: code has been parsed and scopes have been analyzed. |
1400 CompilationInfoWithZone info(script); | 1363 CompilationInfoWithZone info(script); |
1401 info.SetFunction(literal); | 1364 ParseInfo* parse_info = info.parse_info(); |
1402 info.PrepareForCompilation(literal->scope()); | 1365 parse_info->set_literal(literal); |
1403 info.SetLanguageMode(literal->scope()->language_mode()); | 1366 parse_info->set_scope(literal->scope()); |
1367 parse_info->set_language_mode(literal->scope()->language_mode()); | |
1404 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1368 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1405 | 1369 |
1406 Isolate* isolate = info.isolate(); | 1370 Isolate* isolate = info.isolate(); |
1407 Factory* factory = isolate->factory(); | 1371 Factory* factory = isolate->factory(); |
1408 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | 1372 LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
1409 // Determine if the function can be lazily compiled. This is necessary to | 1373 // Determine if the function can be lazily compiled. This is necessary to |
1410 // allow some of our builtin JS files to be lazily compiled. These | 1374 // allow some of our builtin JS files to be lazily compiled. These |
1411 // builtins cannot be handled lazily by the parser, since we have to know | 1375 // builtins cannot be handled lazily by the parser, since we have to know |
1412 // if a function uses the special natives syntax, which is something the | 1376 // if a function uses the special natives syntax, which is something the |
1413 // parser records. | 1377 // parser records. |
1414 // If the debugger requests compilation for break points, we cannot be | 1378 // If the debugger requests compilation for break points, we cannot be |
1415 // aggressive about lazy compilation, because it might trigger compilation | 1379 // aggressive about lazy compilation, because it might trigger compilation |
1416 // of functions without an outer context when setting a breakpoint through | 1380 // of functions without an outer context when setting a breakpoint through |
1417 // Debug::FindSharedFunctionInfoInScript. | 1381 // Debug::FindSharedFunctionInfoInScript. |
1418 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1382 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
1419 bool allow_lazy = literal->AllowsLazyCompilation() && | 1383 bool allow_lazy = |
1420 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); | 1384 literal->AllowsLazyCompilation() && |
1385 !DebuggerWantsEagerCompilation(isolate, allow_lazy_without_ctx); | |
1421 | 1386 |
1422 if (outer_info->is_toplevel() && outer_info->will_serialize()) { | 1387 if (outer_info->parse_info()->is_toplevel() && outer_info->will_serialize()) { |
1423 // Make sure that if the toplevel code (possibly to be serialized), | 1388 // Make sure that if the toplevel code (possibly to be serialized), |
1424 // the inner function must be allowed to be compiled lazily. | 1389 // the inner function must be allowed to be compiled lazily. |
1425 // This is necessary to serialize toplevel code without inner functions. | 1390 // This is necessary to serialize toplevel code without inner functions. |
1426 DCHECK(allow_lazy); | 1391 DCHECK(allow_lazy); |
1427 } | 1392 } |
1428 | 1393 |
1429 // Generate code | 1394 // Generate code |
1430 Handle<ScopeInfo> scope_info; | 1395 Handle<ScopeInfo> scope_info; |
1431 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1396 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
1432 Handle<Code> code = isolate->builtins()->CompileLazy(); | 1397 Handle<Code> code = isolate->builtins()->CompileLazy(); |
1433 info.SetCode(code); | 1398 info.SetCode(code); |
1434 // There's no need in theory for a lazy-compiled function to have a type | 1399 // There's no need in theory for a lazy-compiled function to have a type |
1435 // feedback vector, but some parts of the system expect all | 1400 // feedback vector, but some parts of the system expect all |
1436 // SharedFunctionInfo instances to have one. The size of the vector depends | 1401 // SharedFunctionInfo instances to have one. The size of the vector depends |
1437 // on how many feedback-needing nodes are in the tree, and when lazily | 1402 // on how many feedback-needing nodes are in the tree, and when lazily |
1438 // parsing we might not know that, if this function was never parsed before. | 1403 // parsing we might not know that, if this function was never parsed before. |
1439 // In that case the vector will be replaced the next time MakeCode is | 1404 // In that case the vector will be replaced the next time MakeCode is |
1440 // called. | 1405 // called. |
1441 info.EnsureFeedbackVector(); | 1406 info.EnsureFeedbackVector(); |
1442 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1407 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
1443 } else if (Renumber(&info) && FullCodeGenerator::MakeCode(&info)) { | 1408 } else if (Renumber(info.parse_info()) && |
1409 FullCodeGenerator::MakeCode(&info)) { | |
1444 // MakeCode will ensure that the feedback vector is present and | 1410 // MakeCode will ensure that the feedback vector is present and |
1445 // appropriately sized. | 1411 // appropriately sized. |
1446 DCHECK(!info.code().is_null()); | 1412 DCHECK(!info.code().is_null()); |
1447 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1413 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1448 } else { | 1414 } else { |
1449 return Handle<SharedFunctionInfo>::null(); | 1415 return Handle<SharedFunctionInfo>::null(); |
1450 } | 1416 } |
1451 | 1417 |
1452 // Create a shared function info object. | 1418 // Create a shared function info object. |
1453 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1419 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED); | 1528 DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED); |
1563 if (FLAG_trace_opt) { | 1529 if (FLAG_trace_opt) { |
1564 PrintF("[aborted optimizing "); | 1530 PrintF("[aborted optimizing "); |
1565 info->closure()->ShortPrint(); | 1531 info->closure()->ShortPrint(); |
1566 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 1532 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
1567 } | 1533 } |
1568 return Handle<Code>::null(); | 1534 return Handle<Code>::null(); |
1569 } | 1535 } |
1570 | 1536 |
1571 | 1537 |
1572 bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info, | 1538 bool Compiler::DebuggerWantsEagerCompilation(Isolate* isolate, |
1573 bool allow_lazy_without_ctx) { | 1539 bool allow_lazy_without_ctx) { |
1574 if (LiveEditFunctionTracker::IsActive(info->isolate())) return true; | 1540 if (LiveEditFunctionTracker::IsActive(isolate)) return true; |
1575 Debug* debug = info->isolate()->debug(); | 1541 Debug* debug = isolate->debug(); |
1576 bool debugging = debug->is_active() || debug->has_break_points(); | 1542 bool debugging = debug->is_active() || debug->has_break_points(); |
1577 return debugging && !allow_lazy_without_ctx; | 1543 return debugging && !allow_lazy_without_ctx; |
1578 } | 1544 } |
1579 | 1545 |
1580 | 1546 |
1581 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) | 1547 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) |
1582 : name_(name), info_(info) { | 1548 : name_(name), info_(info) { |
1583 if (FLAG_hydrogen_stats) { | 1549 if (FLAG_hydrogen_stats) { |
1584 info_zone_start_allocation_size_ = info->zone()->allocation_size(); | 1550 info_zone_start_allocation_size_ = info->zone()->allocation_size(); |
1585 timer_.Start(); | 1551 timer_.Start(); |
(...skipping 16 matching lines...) Expand all Loading... | |
1602 AllowHandleDereference allow_deref; | 1568 AllowHandleDereference allow_deref; |
1603 bool tracing_on = info()->IsStub() | 1569 bool tracing_on = info()->IsStub() |
1604 ? FLAG_trace_hydrogen_stubs | 1570 ? FLAG_trace_hydrogen_stubs |
1605 : (FLAG_trace_hydrogen && | 1571 : (FLAG_trace_hydrogen && |
1606 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1572 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1607 return (tracing_on && | 1573 return (tracing_on && |
1608 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1574 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1609 } | 1575 } |
1610 | 1576 |
1611 | 1577 |
1578 CompilationInfoWithZone::CompilationInfoWithZone(Handle<Script> script) | |
1579 : CompilationInfo((new ParseInfo(&zone_))->InitializeFromScript(script)) {} | |
1580 | |
1581 CompilationInfoWithZone::CompilationInfoWithZone(Handle<JSFunction> function) | |
1582 : CompilationInfo( | |
1583 (new ParseInfo(&zone_))->InitializeFromJSFunction(function)) {} | |
1584 | |
1585 CompilationInfoWithZone::CompilationInfoWithZone( | |
1586 Handle<SharedFunctionInfo> shared_info) | |
1587 : CompilationInfo((new ParseInfo(&zone_)) | |
1588 ->InitializeFromSharedFunctionInfo(shared_info)) {} | |
1589 | |
1590 CompilationInfoWithZone::~CompilationInfoWithZone() { | |
1591 DisableFutureOptimization(); | |
1592 RollbackDependencies(); | |
1593 if (parse_info_) { | |
marja
2015/03/09 09:18:07
Nit: unnecessary if, since delete 0 is ok.
titzer
2015/03/09 13:03:09
Done.
| |
1594 delete parse_info_; | |
1595 parse_info_ = nullptr; | |
1596 } | |
1597 } | |
1598 | |
1612 #if DEBUG | 1599 #if DEBUG |
1613 void CompilationInfo::PrintAstForTesting() { | 1600 void CompilationInfo::PrintAstForTesting() { |
1614 PrintF("--- Source from AST ---\n%s\n", | 1601 PrintF("--- Source from AST ---\n%s\n", |
1615 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1602 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1616 } | 1603 } |
1617 #endif | 1604 #endif |
1618 } } // namespace v8::internal | 1605 } } // namespace v8::internal |
OLD | NEW |