OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/compiler-dispatcher/compiler-dispatcher-job.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
6 | 6 |
7 #include "src/assert-scope.h" | 7 #include "src/assert-scope.h" |
8 #include "src/global-handles.h" | 8 #include "src/global-handles.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 } else { | 60 } else { |
61 source = String::Flatten(source); | 61 source = String::Flatten(source); |
62 // Have to globalize the reference here, so it survives between function | 62 // Have to globalize the reference here, so it survives between function |
63 // calls. | 63 // calls. |
64 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source)); | 64 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source)); |
65 character_stream_.reset(new GenericStringUtf16CharacterStream( | 65 character_stream_.reset(new GenericStringUtf16CharacterStream( |
66 source_, shared->start_position(), shared->end_position())); | 66 source_, shared->start_position(), shared->end_position())); |
67 } | 67 } |
68 parse_info_.reset(new ParseInfo(zone_.get())); | 68 parse_info_.reset(new ParseInfo(zone_.get())); |
69 parse_info_->set_isolate(isolate_); | 69 parse_info_->set_isolate(isolate_); |
70 parse_info_->set_shared_info(shared); | |
70 parse_info_->set_character_stream(character_stream_.get()); | 71 parse_info_->set_character_stream(character_stream_.get()); |
71 parse_info_->set_lazy(); | 72 parse_info_->set_lazy(); |
72 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); | 73 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); |
73 parse_info_->set_is_named_expression(shared->is_named_expression()); | 74 parse_info_->set_is_named_expression(shared->is_named_expression()); |
74 parse_info_->set_calls_eval(shared->scope_info()->CallsEval()); | 75 parse_info_->set_calls_eval(shared->scope_info()->CallsEval()); |
75 parse_info_->set_compiler_hints(shared->compiler_hints()); | 76 parse_info_->set_compiler_hints(shared->compiler_hints()); |
76 parse_info_->set_start_position(shared->start_position()); | 77 parse_info_->set_start_position(shared->start_position()); |
77 parse_info_->set_end_position(shared->end_position()); | 78 parse_info_->set_end_position(shared->end_position()); |
78 parse_info_->set_unicode_cache(unicode_cache_.get()); | 79 parse_info_->set_unicode_cache(unicode_cache_.get()); |
79 parse_info_->set_language_mode(shared->language_mode()); | 80 parse_info_->set_language_mode(shared->language_mode()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 source_ = Handle<String>::null(); | 128 source_ = Handle<String>::null(); |
128 } | 129 } |
129 | 130 |
130 if (parse_info_->literal() == nullptr) { | 131 if (parse_info_->literal() == nullptr) { |
131 status_ = CompileJobStatus::kFailed; | 132 status_ = CompileJobStatus::kFailed; |
132 return; | 133 return; |
133 } | 134 } |
134 | 135 |
135 InternalizeParsingResult(); | 136 InternalizeParsingResult(); |
136 | 137 |
138 status_ = CompileJobStatus::kReadyToAnalyse; | |
139 } | |
140 | |
141 void CompilerDispatcherJob::PrepareToCompileOnMainThread() { | |
142 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
143 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); | |
144 | |
145 compile_info_.reset(new CompilationInfo(parse_info_.get(), function_)); | |
146 | |
147 // Create a canonical handle scope before ast numbering if compiling bytecode. | |
148 // This is required for off-thread bytecode generation. | |
149 std::unique_ptr<CanonicalHandleScope> canonical; | |
150 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | |
151 | |
152 if (!Compiler::Analyze(parse_info_.get())) { | |
153 status_ = CompileJobStatus::kFailed; | |
154 return; | |
155 } | |
156 compile_job_.reset( | |
157 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); | |
158 if (!compile_job_.get()) { | |
159 status_ = CompileJobStatus::kFailed; | |
160 return; | |
161 } | |
162 | |
137 status_ = CompileJobStatus::kReadyToCompile; | 163 status_ = CompileJobStatus::kReadyToCompile; |
138 } | 164 } |
139 | 165 |
166 void CompilerDispatcherJob::Compile() { | |
167 DCHECK(status() == CompileJobStatus::kReadyToCompile); | |
168 DisallowHeapAllocation no_allocation; | |
169 DisallowHandleAllocation no_handles; | |
170 DisallowHandleDereference no_deref; | |
171 | |
172 uintptr_t stack_limit = | |
173 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | |
174 compile_job_->set_stack_limit(stack_limit); | |
175 | |
176 if (compile_job_->ExecuteJob() != CompilationJob::SUCCEEDED) { | |
177 status_ = CompileJobStatus::kFailed; | |
178 return; | |
179 } | |
180 | |
181 status_ = CompileJobStatus::kCompiled; | |
182 } | |
183 | |
184 void CompilerDispatcherJob::FinalizeCompilingOnMainThread() { | |
185 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
186 DCHECK(status() == CompileJobStatus::kCompiled); | |
187 | |
188 if (!Compiler::FinalizeCompilationJob(compile_job_.release())) { | |
189 status_ = CompileJobStatus::kFailed; | |
190 return; | |
191 } | |
192 | |
193 status_ = CompileJobStatus::kDone; | |
194 } | |
195 | |
140 void CompilerDispatcherJob::ReportErrorsOnMainThread() { | 196 void CompilerDispatcherJob::ReportErrorsOnMainThread() { |
141 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 197 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
142 DCHECK(status() == CompileJobStatus::kFailed); | 198 DCHECK(status() == CompileJobStatus::kFailed); |
143 | 199 |
144 // Internalizing the parsing result will throw the error. | 200 // Internalizing the parsing result will throw the error. |
145 InternalizeParsingResult(); | 201 InternalizeParsingResult(); |
146 | 202 |
147 status_ = CompileJobStatus::kDone; | 203 status_ = CompileJobStatus::kDone; |
148 } | 204 } |
149 | 205 |
150 void CompilerDispatcherJob::ResetOnMainThread() { | 206 void CompilerDispatcherJob::ResetOnMainThread() { |
151 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 207 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
152 | 208 |
153 parser_.reset(); | 209 parser_.reset(); |
154 unicode_cache_.reset(); | 210 unicode_cache_.reset(); |
155 character_stream_.reset(); | 211 character_stream_.reset(); |
156 parse_info_.reset(); | 212 parse_info_.reset(); |
213 compile_info_.reset(); | |
157 zone_.reset(); | 214 zone_.reset(); |
158 | 215 |
159 if (!source_.is_null()) { | 216 if (!source_.is_null()) { |
160 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 217 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
161 source_ = Handle<String>::null(); | 218 source_ = Handle<String>::null(); |
162 } | 219 } |
163 | 220 |
164 status_ = CompileJobStatus::kInitial; | 221 status_ = CompileJobStatus::kInitial; |
165 } | 222 } |
166 | 223 |
167 void CompilerDispatcherJob::InternalizeParsingResult() { | 224 void CompilerDispatcherJob::InternalizeParsingResult() { |
168 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 225 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
169 DCHECK(status() == CompileJobStatus::kParsed || | 226 DCHECK(status() == CompileJobStatus::kParsed || |
170 status() == CompileJobStatus::kFailed); | 227 status() == CompileJobStatus::kFailed); |
171 | 228 |
172 HandleScope scope(isolate_); | |
rmcilroy
2016/08/22 13:27:08
I've removed this HandleScope because the handles
| |
173 | |
174 // Create a canonical handle scope before internalizing parsed values if | 229 // Create a canonical handle scope before internalizing parsed values if |
175 // compiling bytecode. This is required for off-thread bytecode generation. | 230 // compiling bytecode. This is required for off-thread bytecode generation. |
176 std::unique_ptr<CanonicalHandleScope> canonical; | 231 std::unique_ptr<CanonicalHandleScope> canonical; |
177 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | 232 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); |
178 | 233 |
179 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 234 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
180 Handle<Script> script(Script::cast(shared->script()), isolate_); | 235 Handle<Script> script(Script::cast(shared->script()), isolate_); |
181 | 236 |
182 parse_info_->set_script(script); | 237 parse_info_->set_script(script); |
183 parse_info_->set_context(handle(function_->context(), isolate_)); | 238 parse_info_->set_context(handle(function_->context(), isolate_)); |
184 | 239 |
185 // Do the parsing tasks which need to be done on the main thread. This will | 240 // Do the parsing tasks which need to be done on the main thread. This will |
186 // also handle parse errors. | 241 // also handle parse errors. |
187 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | 242 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); |
188 parser_->HandleSourceURLComments(isolate_, script); | 243 parser_->HandleSourceURLComments(isolate_, script); |
189 | 244 |
190 parse_info_->set_character_stream(nullptr); | 245 parse_info_->set_character_stream(nullptr); |
191 parse_info_->set_unicode_cache(nullptr); | 246 parse_info_->set_unicode_cache(nullptr); |
192 parser_.reset(); | 247 parser_.reset(); |
193 unicode_cache_.reset(); | 248 unicode_cache_.reset(); |
194 character_stream_.reset(); | 249 character_stream_.reset(); |
195 } | 250 } |
196 | 251 |
197 } // namespace internal | 252 } // namespace internal |
198 } // namespace v8 | 253 } // namespace v8 |
OLD | NEW |