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