Chromium Code Reviews| 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/compiler.h" | |
| 8 #include "src/global-handles.h" | 9 #include "src/global-handles.h" |
| 9 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| 10 #include "src/objects-inl.h" | 11 #include "src/objects-inl.h" |
| 11 #include "src/parsing/parse-info.h" | 12 #include "src/parsing/parse-info.h" |
| 12 #include "src/parsing/parser.h" | 13 #include "src/parsing/parser.h" |
| 13 #include "src/parsing/scanner-character-streams.h" | 14 #include "src/parsing/scanner-character-streams.h" |
| 14 #include "src/unicode-cache.h" | 15 #include "src/unicode-cache.h" |
| 15 #include "src/zone.h" | 16 #include "src/zone.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 DCHECK(status() == CompileJobStatus::kParsed); | 125 DCHECK(status() == CompileJobStatus::kParsed); |
| 125 | 126 |
| 126 if (!source_.is_null()) { | 127 if (!source_.is_null()) { |
| 127 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 128 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
| 128 source_ = Handle<String>::null(); | 129 source_ = Handle<String>::null(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 if (parse_info_->literal() == nullptr) { | 132 if (parse_info_->literal() == nullptr) { |
| 132 status_ = CompileJobStatus::kFailed; | 133 status_ = CompileJobStatus::kFailed; |
| 133 } else { | 134 } else { |
| 134 status_ = CompileJobStatus::kReadyToCompile; | 135 status_ = CompileJobStatus::kReadyToAnalyse; |
| 135 } | 136 } |
| 136 | 137 |
| 137 DeferredHandleScope scope(isolate_); | 138 DeferredHandleScope scope(isolate_); |
| 138 { | 139 { |
| 139 // Create a canonical handle scope before internalizing parsed values if | 140 // Create a canonical handle scope before internalizing parsed values if |
| 140 // compiling bytecode. This is required for off-thread bytecode generation. | 141 // compiling bytecode. This is required for off-thread bytecode generation. |
| 141 std::unique_ptr<CanonicalHandleScope> canonical; | 142 std::unique_ptr<CanonicalHandleScope> canonical; |
| 142 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | 143 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); |
| 143 | 144 |
| 144 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 145 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
| 145 Handle<Script> script(Script::cast(shared->script()), isolate_); | 146 Handle<Script> script(Script::cast(shared->script()), isolate_); |
| 146 | 147 |
| 147 parse_info_->set_script(script); | 148 parse_info_->set_script(script); |
| 148 parse_info_->set_context(handle(function_->context(), isolate_)); | 149 parse_info_->set_context(handle(function_->context(), isolate_)); |
| 150 parse_info_->set_shared_info(handle(function_->shared(), isolate_)); | |
| 149 | 151 |
| 150 // Do the parsing tasks which need to be done on the main thread. This will | 152 // Do the parsing tasks which need to be done on the main thread. This will |
| 151 // also handle parse errors. | 153 // also handle parse errors. |
| 152 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | 154 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); |
| 153 parser_->HandleSourceURLComments(isolate_, script); | 155 parser_->HandleSourceURLComments(isolate_, script); |
| 154 | 156 |
| 155 parse_info_->set_character_stream(nullptr); | 157 parse_info_->set_character_stream(nullptr); |
| 156 parse_info_->set_unicode_cache(nullptr); | 158 parse_info_->set_unicode_cache(nullptr); |
| 157 parser_.reset(); | 159 parser_.reset(); |
| 158 unicode_cache_.reset(); | 160 unicode_cache_.reset(); |
| 159 character_stream_.reset(); | 161 character_stream_.reset(); |
| 160 } | 162 } |
| 161 handles_from_parsing_.reset(scope.Detach()); | 163 handles_from_parsing_.reset(scope.Detach()); |
| 162 | 164 |
| 163 return status_ != CompileJobStatus::kFailed; | 165 return status_ != CompileJobStatus::kFailed; |
| 164 } | 166 } |
| 165 | 167 |
| 168 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { | |
| 169 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
| 170 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); | |
| 171 | |
| 172 compile_info_.reset(new CompilationInfo(parse_info_.get(), function_)); | |
| 173 | |
| 174 DeferredHandleScope scope(isolate_); | |
| 175 { | |
| 176 // Create a canonical handle scope before ast numbering if compiling | |
| 177 // bytecode. This is required for off-thread bytecode generation. | |
| 178 std::unique_ptr<CanonicalHandleScope> canonical; | |
| 179 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | |
| 180 | |
| 181 if (Compiler::Analyze(parse_info_.get())) { | |
| 182 compile_job_.reset( | |
| 183 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); | |
| 184 } | |
| 185 } | |
| 186 handles_from_analysing_.reset(scope.Detach()); | |
|
jochen (gone - plz use gerrit)
2016/08/23 16:06:22
why not just compile_info_->set_deferred_handles(s
rmcilroy
2016/08/23 16:58:29
Works for me. Done.
| |
| 187 | |
| 188 if (!compile_job_.get()) { | |
| 189 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | |
| 190 status_ = CompileJobStatus::kFailed; | |
| 191 return false; | |
| 192 } | |
| 193 | |
| 194 status_ = CompileJobStatus::kReadyToCompile; | |
| 195 return true; | |
| 196 } | |
| 197 | |
| 198 void CompilerDispatcherJob::Compile() { | |
| 199 DCHECK(status() == CompileJobStatus::kReadyToCompile); | |
| 200 DCHECK(compile_job_->can_execute_on_background_thread() || | |
| 201 ThreadId::Current().Equals(isolate_->thread_id())); | |
| 202 | |
| 203 // Disallowing of handle dereference and heap access dealt with in | |
| 204 // CompilationJob::ExecuteJob. | |
| 205 | |
| 206 uintptr_t stack_limit = | |
| 207 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | |
| 208 compile_job_->set_stack_limit(stack_limit); | |
| 209 | |
| 210 CompilationJob::Status status = compile_job_->ExecuteJob(); | |
| 211 USE(status); | |
| 212 | |
| 213 // Always transition to kCompiled - errors will be reported by | |
| 214 // FinalizeCompilingOnMainThread. | |
| 215 status_ = CompileJobStatus::kCompiled; | |
| 216 } | |
| 217 | |
| 218 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() { | |
| 219 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
| 220 DCHECK(status() == CompileJobStatus::kCompiled); | |
| 221 | |
| 222 if (compile_job_->state() == CompilationJob::State::kFailed || | |
| 223 !Compiler::FinalizeCompilationJob(compile_job_.release())) { | |
| 224 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | |
| 225 status_ = CompileJobStatus::kFailed; | |
| 226 return false; | |
| 227 } | |
| 228 | |
| 229 zone_.reset(); | |
| 230 parse_info_.reset(); | |
| 231 compile_info_.reset(); | |
| 232 compile_job_.reset(); | |
| 233 handles_from_parsing_.reset(); | |
| 234 handles_from_analysing_.reset(); | |
| 235 | |
| 236 status_ = CompileJobStatus::kDone; | |
| 237 return true; | |
| 238 } | |
| 239 | |
| 166 void CompilerDispatcherJob::ResetOnMainThread() { | 240 void CompilerDispatcherJob::ResetOnMainThread() { |
| 167 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 241 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 168 | 242 |
| 169 parser_.reset(); | 243 parser_.reset(); |
| 170 unicode_cache_.reset(); | 244 unicode_cache_.reset(); |
| 171 character_stream_.reset(); | 245 character_stream_.reset(); |
| 172 parse_info_.reset(); | 246 parse_info_.reset(); |
| 173 zone_.reset(); | 247 zone_.reset(); |
| 174 handles_from_parsing_.reset(); | 248 handles_from_parsing_.reset(); |
| 249 compile_info_.reset(); | |
| 250 compile_job_.reset(); | |
| 251 handles_from_analysing_.reset(); | |
| 175 | 252 |
| 176 if (!source_.is_null()) { | 253 if (!source_.is_null()) { |
| 177 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 254 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
| 178 source_ = Handle<String>::null(); | 255 source_ = Handle<String>::null(); |
| 179 } | 256 } |
| 180 | 257 |
| 181 status_ = CompileJobStatus::kInitial; | 258 status_ = CompileJobStatus::kInitial; |
| 182 } | 259 } |
| 183 | 260 |
| 184 } // namespace internal | 261 } // namespace internal |
| 185 } // namespace v8 | 262 } // namespace v8 |
| OLD | NEW |