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

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: 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/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
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
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 if (compile_job_->ExecuteJob() != CompilationJob::SUCCEEDED) {
173 status_ = CompileJobStatus::kFailed;
174 return;
175 }
176
177 status_ = CompileJobStatus::kCompiled;
178 }
179
180 void CompilerDispatcherJob::FinalizeCompilingOnMainThread() {
181 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
182 DCHECK(status() == CompileJobStatus::kCompiled);
183
184 if (!Compiler::FinalizeCompilationJob(compile_job_.release())) {
185 status_ = CompileJobStatus::kFailed;
186 return;
187 }
188
189 status_ = CompileJobStatus::kDone;
190 }
191
140 void CompilerDispatcherJob::ReportErrorsOnMainThread() { 192 void CompilerDispatcherJob::ReportErrorsOnMainThread() {
141 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 193 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
142 DCHECK(status() == CompileJobStatus::kFailed); 194 DCHECK(status() == CompileJobStatus::kFailed);
143 195
144 // Internalizing the parsing result will throw the error. 196 // Internalizing the parsing result will throw the error.
145 InternalizeParsingResult(); 197 InternalizeParsingResult();
146 198
147 status_ = CompileJobStatus::kDone; 199 status_ = CompileJobStatus::kDone;
148 } 200 }
149 201
150 void CompilerDispatcherJob::ResetOnMainThread() { 202 void CompilerDispatcherJob::ResetOnMainThread() {
151 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 203 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
152 204
153 parser_.reset(); 205 parser_.reset();
154 unicode_cache_.reset(); 206 unicode_cache_.reset();
155 character_stream_.reset(); 207 character_stream_.reset();
156 parse_info_.reset(); 208 parse_info_.reset();
209 compile_info_.reset();
157 zone_.reset(); 210 zone_.reset();
158 211
159 if (!source_.is_null()) { 212 if (!source_.is_null()) {
160 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 213 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
161 source_ = Handle<String>::null(); 214 source_ = Handle<String>::null();
162 } 215 }
163 216
164 status_ = CompileJobStatus::kInitial; 217 status_ = CompileJobStatus::kInitial;
165 } 218 }
166 219
167 void CompilerDispatcherJob::InternalizeParsingResult() { 220 void CompilerDispatcherJob::InternalizeParsingResult() {
168 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 221 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
169 DCHECK(status() == CompileJobStatus::kParsed || 222 DCHECK(status() == CompileJobStatus::kParsed ||
170 status() == CompileJobStatus::kFailed); 223 status() == CompileJobStatus::kFailed);
171 224
172 HandleScope scope(isolate_);
173
174 // Create a canonical handle scope before internalizing parsed values if 225 // Create a canonical handle scope before internalizing parsed values if
175 // compiling bytecode. This is required for off-thread bytecode generation. 226 // compiling bytecode. This is required for off-thread bytecode generation.
176 std::unique_ptr<CanonicalHandleScope> canonical; 227 std::unique_ptr<CanonicalHandleScope> canonical;
177 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); 228 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
178 229
179 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 230 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_);
180 Handle<Script> script(Script::cast(shared->script()), isolate_); 231 Handle<Script> script(Script::cast(shared->script()), isolate_);
181 232
182 parse_info_->set_script(script); 233 parse_info_->set_script(script);
183 parse_info_->set_context(handle(function_->context(), isolate_)); 234 parse_info_->set_context(handle(function_->context(), isolate_));
184 235
185 // Do the parsing tasks which need to be done on the main thread. This will 236 // Do the parsing tasks which need to be done on the main thread. This will
186 // also handle parse errors. 237 // also handle parse errors.
187 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); 238 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
188 parser_->HandleSourceURLComments(isolate_, script); 239 parser_->HandleSourceURLComments(isolate_, script);
189 240
190 parse_info_->set_character_stream(nullptr); 241 parse_info_->set_character_stream(nullptr);
191 parse_info_->set_unicode_cache(nullptr); 242 parse_info_->set_unicode_cache(nullptr);
192 parser_.reset(); 243 parser_.reset();
193 unicode_cache_.reset(); 244 unicode_cache_.reset();
194 character_stream_.reset(); 245 character_stream_.reset();
195 } 246 }
196 247
197 } // namespace internal 248 } // namespace internal
198 } // namespace v8 249 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698