Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: src/compiler-dispatcher/compiler-dispatcher-job.cc

Issue 2251713002: [Compiler] Add compile to CompilerDispatcherJob. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_compilerdispatcher
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } else { 62 } else {
62 source = String::Flatten(source); 63 source = String::Flatten(source);
63 // Have to globalize the reference here, so it survives between function 64 // Have to globalize the reference here, so it survives between function
64 // calls. 65 // calls.
65 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source)); 66 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source));
66 character_stream_.reset(new GenericStringUtf16CharacterStream( 67 character_stream_.reset(new GenericStringUtf16CharacterStream(
67 source_, shared->start_position(), shared->end_position())); 68 source_, shared->start_position(), shared->end_position()));
68 } 69 }
69 parse_info_.reset(new ParseInfo(zone_.get())); 70 parse_info_.reset(new ParseInfo(zone_.get()));
70 parse_info_->set_isolate(isolate_); 71 parse_info_->set_isolate(isolate_);
72 parse_info_->set_shared_info(shared);
71 parse_info_->set_character_stream(character_stream_.get()); 73 parse_info_->set_character_stream(character_stream_.get());
72 parse_info_->set_lazy(); 74 parse_info_->set_lazy();
73 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); 75 parse_info_->set_hash_seed(isolate_->heap()->HashSeed());
74 parse_info_->set_is_named_expression(shared->is_named_expression()); 76 parse_info_->set_is_named_expression(shared->is_named_expression());
75 parse_info_->set_calls_eval(shared->scope_info()->CallsEval()); 77 parse_info_->set_calls_eval(shared->scope_info()->CallsEval());
76 parse_info_->set_compiler_hints(shared->compiler_hints()); 78 parse_info_->set_compiler_hints(shared->compiler_hints());
77 parse_info_->set_start_position(shared->start_position()); 79 parse_info_->set_start_position(shared->start_position());
78 parse_info_->set_end_position(shared->end_position()); 80 parse_info_->set_end_position(shared->end_position());
79 parse_info_->set_unicode_cache(unicode_cache_.get()); 81 parse_info_->set_unicode_cache(unicode_cache_.get());
80 parse_info_->set_language_mode(shared->language_mode()); 82 parse_info_->set_language_mode(shared->language_mode());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 source_ = Handle<String>::null(); 130 source_ = Handle<String>::null();
129 } 131 }
130 132
131 if (parse_info_->literal() == nullptr) { 133 if (parse_info_->literal() == nullptr) {
132 status_ = CompileJobStatus::kFailed; 134 status_ = CompileJobStatus::kFailed;
133 return; 135 return;
134 } 136 }
135 137
136 InternalizeParsingResult(); 138 InternalizeParsingResult();
137 139
140 status_ = CompileJobStatus::kReadyToAnalyse;
141 }
142
143 void CompilerDispatcherJob::PrepareToCompileOnMainThread() {
jochen (gone - plz use gerrit) 2016/08/23 12:04:26 can you make this return a bool that's false if yo
rmcilroy 2016/08/23 15:55:10 Done.
144 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
145 DCHECK(status() == CompileJobStatus::kReadyToAnalyse);
146
147 compile_info_.reset(new CompilationInfo(parse_info_.get(), function_));
jochen (gone - plz use gerrit) 2016/08/23 12:04:26 mind putting a DeferredHandleScope here and later
rmcilroy 2016/08/23 15:55:10 Done.
148
149 // Create a canonical handle scope before ast numbering if compiling bytecode.
150 // This is required for off-thread bytecode generation.
151 std::unique_ptr<CanonicalHandleScope> canonical;
152 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
153
154 if (!Compiler::Analyze(parse_info_.get())) {
155 status_ = CompileJobStatus::kFailed;
156 return;
157 }
158 compile_job_.reset(
159 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get()));
160 if (!compile_job_.get()) {
161 status_ = CompileJobStatus::kFailed;
162 return;
163 }
164
138 status_ = CompileJobStatus::kReadyToCompile; 165 status_ = CompileJobStatus::kReadyToCompile;
139 } 166 }
140 167
168 void CompilerDispatcherJob::Compile() {
jochen (gone - plz use gerrit) 2016/08/23 12:04:26 same here
rmcilroy 2016/08/23 15:55:10 Change this phase to never fail, and always report
169 DCHECK(status() == CompileJobStatus::kReadyToCompile);
170 DCHECK(compile_job_->can_execute_on_background_thread() ||
171 ThreadId::Current().Equals(isolate_->thread_id()));
172
173 // Disallowing of handle dereference and heap access dealt with in
174 // CompilationJob::ExecuteJob.
175
176 uintptr_t stack_limit =
177 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB;
178 compile_job_->set_stack_limit(stack_limit);
179
180 if (compile_job_->ExecuteJob() != CompilationJob::SUCCEEDED) {
181 status_ = CompileJobStatus::kFailed;
182 return;
183 }
184
185 status_ = CompileJobStatus::kCompiled;
186 }
187
188 void CompilerDispatcherJob::FinalizeCompilingOnMainThread() {
189 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
190 DCHECK(status() == CompileJobStatus::kCompiled);
191
192 if (!Compiler::FinalizeCompilationJob(compile_job_.release())) {
193 status_ = CompileJobStatus::kFailed;
194 return;
195 }
196
197 status_ = CompileJobStatus::kDone;
198 }
199
141 void CompilerDispatcherJob::ReportErrorsOnMainThread() { 200 void CompilerDispatcherJob::ReportErrorsOnMainThread() {
142 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 201 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
143 DCHECK(status() == CompileJobStatus::kFailed); 202 DCHECK(status() == CompileJobStatus::kFailed);
144 203
145 // Internalizing the parsing result will throw the error. 204 // Internalizing the parsing result will throw the error.
146 InternalizeParsingResult(); 205 InternalizeParsingResult();
147 206
148 status_ = CompileJobStatus::kDone; 207 status_ = CompileJobStatus::kDone;
149 } 208 }
150 209
151 void CompilerDispatcherJob::ResetOnMainThread() { 210 void CompilerDispatcherJob::ResetOnMainThread() {
152 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 211 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
153 212
154 parser_.reset(); 213 parser_.reset();
155 unicode_cache_.reset(); 214 unicode_cache_.reset();
156 character_stream_.reset(); 215 character_stream_.reset();
157 parse_info_.reset(); 216 parse_info_.reset();
217 compile_info_.reset();
jochen (gone - plz use gerrit) 2016/08/23 12:04:26 why not also reset the compile_job_?
rmcilroy 2016/08/23 15:55:10 Opps, done (also for new DeferredHandleScope).
158 zone_.reset(); 218 zone_.reset();
159 219
160 if (!source_.is_null()) { 220 if (!source_.is_null()) {
161 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 221 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
162 source_ = Handle<String>::null(); 222 source_ = Handle<String>::null();
163 } 223 }
164 224
165 status_ = CompileJobStatus::kInitial; 225 status_ = CompileJobStatus::kInitial;
166 } 226 }
167 227
168 void CompilerDispatcherJob::InternalizeParsingResult() { 228 void CompilerDispatcherJob::InternalizeParsingResult() {
169 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 229 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
170 DCHECK(status() == CompileJobStatus::kParsed || 230 DCHECK(status() == CompileJobStatus::kParsed ||
171 status() == CompileJobStatus::kFailed); 231 status() == CompileJobStatus::kFailed);
172 232
173 HandleScope scope(isolate_);
174
175 // Create a canonical handle scope before internalizing parsed values if 233 // Create a canonical handle scope before internalizing parsed values if
176 // compiling bytecode. This is required for off-thread bytecode generation. 234 // compiling bytecode. This is required for off-thread bytecode generation.
177 std::unique_ptr<CanonicalHandleScope> canonical; 235 std::unique_ptr<CanonicalHandleScope> canonical;
178 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); 236 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
179 237
180 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 238 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_);
181 Handle<Script> script(Script::cast(shared->script()), isolate_); 239 Handle<Script> script(Script::cast(shared->script()), isolate_);
182 240
183 parse_info_->set_script(script); 241 parse_info_->set_script(script);
184 parse_info_->set_context(handle(function_->context(), isolate_)); 242 parse_info_->set_context(handle(function_->context(), isolate_));
185 243
186 // Do the parsing tasks which need to be done on the main thread. This will 244 // Do the parsing tasks which need to be done on the main thread. This will
187 // also handle parse errors. 245 // also handle parse errors.
188 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); 246 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
189 parser_->HandleSourceURLComments(isolate_, script); 247 parser_->HandleSourceURLComments(isolate_, script);
190 248
191 parse_info_->set_character_stream(nullptr); 249 parse_info_->set_character_stream(nullptr);
192 parse_info_->set_unicode_cache(nullptr); 250 parse_info_->set_unicode_cache(nullptr);
193 parser_.reset(); 251 parser_.reset();
194 unicode_cache_.reset(); 252 unicode_cache_.reset();
195 character_stream_.reset(); 253 character_stream_.reset();
196 } 254 }
197 255
198 } // namespace internal 256 } // namespace internal
199 } // namespace v8 257 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698