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

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

Issue 2358503002: Change the CompilerDispatcherJob to take a SharedFunctionInfo (Closed)
Patch Set: updates Created 4 years, 3 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
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.h ('k') | src/debug/liveedit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compilation-info.h" 8 #include "src/compilation-info.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/global-handles.h" 10 #include "src/global-handles.h"
11 #include "src/isolate.h" 11 #include "src/isolate.h"
12 #include "src/objects-inl.h" 12 #include "src/objects-inl.h"
13 #include "src/parsing/parse-info.h" 13 #include "src/parsing/parse-info.h"
14 #include "src/parsing/parser.h" 14 #include "src/parsing/parser.h"
15 #include "src/parsing/scanner-character-streams.h" 15 #include "src/parsing/scanner-character-streams.h"
16 #include "src/unicode-cache.h" 16 #include "src/unicode-cache.h"
17 #include "src/zone.h" 17 #include "src/zone.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, 22 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate,
23 Handle<JSFunction> function, 23 Handle<SharedFunctionInfo> shared,
24 size_t max_stack_size) 24 size_t max_stack_size)
25 : isolate_(isolate), 25 : isolate_(isolate),
26 function_(Handle<JSFunction>::cast( 26 shared_(Handle<SharedFunctionInfo>::cast(
27 isolate_->global_handles()->Create(*function))), 27 isolate_->global_handles()->Create(*shared))),
28 max_stack_size_(max_stack_size), 28 max_stack_size_(max_stack_size),
29 can_compile_on_background_thread_(false) { 29 can_compile_on_background_thread_(false) {
30 HandleScope scope(isolate_); 30 HandleScope scope(isolate_);
31 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 31 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_));
32 Handle<Script> script(Script::cast(shared->script()), isolate_); 32 Handle<Script> script(Script::cast(shared_->script()), isolate_);
33 Handle<String> source(String::cast(script->source()), isolate_); 33 Handle<String> source(String::cast(script->source()), isolate_);
34 can_parse_on_background_thread_ = 34 can_parse_on_background_thread_ =
35 source->IsExternalTwoByteString() || source->IsExternalOneByteString(); 35 source->IsExternalTwoByteString() || source->IsExternalOneByteString();
36 } 36 }
37 37
38 CompilerDispatcherJob::~CompilerDispatcherJob() { 38 CompilerDispatcherJob::~CompilerDispatcherJob() {
39 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 39 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
40 DCHECK(status_ == CompileJobStatus::kInitial || 40 DCHECK(status_ == CompileJobStatus::kInitial ||
41 status_ == CompileJobStatus::kDone); 41 status_ == CompileJobStatus::kDone);
42 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); 42 i::GlobalHandles::Destroy(Handle<Object>::cast(shared_).location());
43 } 43 }
44 44
45 void CompilerDispatcherJob::PrepareToParseOnMainThread() { 45 void CompilerDispatcherJob::PrepareToParseOnMainThread() {
46 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 46 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
47 DCHECK(status() == CompileJobStatus::kInitial); 47 DCHECK(status() == CompileJobStatus::kInitial);
48 HandleScope scope(isolate_); 48 HandleScope scope(isolate_);
49 unicode_cache_.reset(new UnicodeCache()); 49 unicode_cache_.reset(new UnicodeCache());
50 zone_.reset(new Zone(isolate_->allocator())); 50 zone_.reset(new Zone(isolate_->allocator()));
51 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 51 Handle<Script> script(Script::cast(shared_->script()), isolate_);
52 Handle<Script> script(Script::cast(shared->script()), isolate_);
53 DCHECK(script->type() != Script::TYPE_NATIVE); 52 DCHECK(script->type() != Script::TYPE_NATIVE);
54 53
55 Handle<String> source(String::cast(script->source()), isolate_); 54 Handle<String> source(String::cast(script->source()), isolate_);
56 if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) { 55 if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) {
57 character_stream_.reset(ScannerStream::For(source, shared->start_position(), 56 character_stream_.reset(ScannerStream::For(
58 shared->end_position())); 57 source, shared_->start_position(), shared_->end_position()));
59 } else { 58 } else {
60 source = String::Flatten(source); 59 source = String::Flatten(source);
61 // Have to globalize the reference here, so it survives between function 60 // Have to globalize the reference here, so it survives between function
62 // calls. 61 // calls.
63 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source)); 62 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source));
64 character_stream_.reset(ScannerStream::For( 63 character_stream_.reset(ScannerStream::For(
65 source_, shared->start_position(), shared->end_position())); 64 source_, shared_->start_position(), shared_->end_position()));
66 } 65 }
67 parse_info_.reset(new ParseInfo(zone_.get())); 66 parse_info_.reset(new ParseInfo(zone_.get()));
68 parse_info_->set_isolate(isolate_); 67 parse_info_->set_isolate(isolate_);
69 parse_info_->set_character_stream(character_stream_.get()); 68 parse_info_->set_character_stream(character_stream_.get());
70 parse_info_->set_lazy(); 69 parse_info_->set_lazy();
71 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); 70 parse_info_->set_hash_seed(isolate_->heap()->HashSeed());
72 parse_info_->set_is_named_expression(shared->is_named_expression()); 71 parse_info_->set_is_named_expression(shared_->is_named_expression());
73 parse_info_->set_calls_eval(shared->scope_info()->CallsEval()); 72 parse_info_->set_compiler_hints(shared_->compiler_hints());
74 parse_info_->set_compiler_hints(shared->compiler_hints()); 73 parse_info_->set_start_position(shared_->start_position());
75 parse_info_->set_start_position(shared->start_position()); 74 parse_info_->set_end_position(shared_->end_position());
76 parse_info_->set_end_position(shared->end_position());
77 parse_info_->set_unicode_cache(unicode_cache_.get()); 75 parse_info_->set_unicode_cache(unicode_cache_.get());
78 parse_info_->set_language_mode(shared->language_mode()); 76 parse_info_->set_language_mode(shared_->language_mode());
79 77
80 parser_.reset(new Parser(parse_info_.get())); 78 parser_.reset(new Parser(parse_info_.get()));
81 parser_->DeserializeScopeChain( 79 Handle<ScopeInfo> outer_scope_info(
82 parse_info_.get(), 80 handle(ScopeInfo::cast(shared_->outer_scope_info())));
83 function_->context()->IsNativeContext() 81 parser_->DeserializeScopeChain(parse_info_.get(),
84 ? MaybeHandle<ScopeInfo>() 82 outer_scope_info->length() > 0
85 : MaybeHandle<ScopeInfo>(function_->context()->scope_info(), 83 ? MaybeHandle<ScopeInfo>(outer_scope_info)
86 isolate_)); 84 : MaybeHandle<ScopeInfo>());
87 85
88 Handle<String> name(String::cast(shared->name())); 86 Handle<String> name(String::cast(shared_->name()));
89 parse_info_->set_function_name( 87 parse_info_->set_function_name(
90 parse_info_->ast_value_factory()->GetString(name)); 88 parse_info_->ast_value_factory()->GetString(name));
91 status_ = CompileJobStatus::kReadyToParse; 89 status_ = CompileJobStatus::kReadyToParse;
92 } 90 }
93 91
94 void CompilerDispatcherJob::Parse() { 92 void CompilerDispatcherJob::Parse() {
95 DCHECK(can_parse_on_background_thread_ || 93 DCHECK(can_parse_on_background_thread_ ||
96 ThreadId::Current().Equals(isolate_->thread_id())); 94 ThreadId::Current().Equals(isolate_->thread_id()));
97 DCHECK(status() == CompileJobStatus::kReadyToParse); 95 DCHECK(status() == CompileJobStatus::kReadyToParse);
98 96
(...skipping 30 matching lines...) Expand all
129 } 127 }
130 128
131 if (parse_info_->literal() == nullptr) { 129 if (parse_info_->literal() == nullptr) {
132 status_ = CompileJobStatus::kFailed; 130 status_ = CompileJobStatus::kFailed;
133 } else { 131 } else {
134 status_ = CompileJobStatus::kReadyToAnalyse; 132 status_ = CompileJobStatus::kReadyToAnalyse;
135 } 133 }
136 134
137 DeferredHandleScope scope(isolate_); 135 DeferredHandleScope scope(isolate_);
138 { 136 {
139 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 137 Handle<Script> script(Script::cast(shared_->script()), isolate_);
140 Handle<Script> script(Script::cast(shared->script()), isolate_);
141 138
142 parse_info_->set_script(script); 139 parse_info_->set_script(script);
143 if (!function_->context()->IsNativeContext()) { 140 Handle<ScopeInfo> outer_scope_info(
144 parse_info_->set_outer_scope_info( 141 handle(ScopeInfo::cast(shared_->outer_scope_info())));
145 handle(function_->context()->scope_info(), isolate_)); 142 if (outer_scope_info->length() > 0) {
143 parse_info_->set_outer_scope_info(outer_scope_info);
146 } 144 }
147 parse_info_->set_shared_info(handle(function_->shared(), isolate_)); 145 parse_info_->set_shared_info(shared_);
148 146
149 { 147 {
150 // Create a canonical handle scope if compiling ignition bytecode. This is 148 // Create a canonical handle scope if compiling ignition bytecode. This is
151 // required by the constant array builder to de-duplicate objects without 149 // required by the constant array builder to de-duplicate objects without
152 // dereferencing handles. 150 // dereferencing handles.
153 std::unique_ptr<CanonicalHandleScope> canonical; 151 std::unique_ptr<CanonicalHandleScope> canonical;
154 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); 152 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
155 153
156 // Do the parsing tasks which need to be done on the main thread. This 154 // Do the parsing tasks which need to be done on the main thread. This
157 // will also handle parse errors. 155 // will also handle parse errors.
158 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); 156 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
159 } 157 }
160 parser_->HandleSourceURLComments(isolate_, script); 158 parser_->HandleSourceURLComments(isolate_, script);
161 159
162 parse_info_->set_character_stream(nullptr); 160 parse_info_->set_character_stream(nullptr);
163 parse_info_->set_unicode_cache(nullptr); 161 parse_info_->set_unicode_cache(nullptr);
164 parser_.reset(); 162 parser_.reset();
165 unicode_cache_.reset(); 163 unicode_cache_.reset();
166 character_stream_.reset(); 164 character_stream_.reset();
167 } 165 }
168 handles_from_parsing_.reset(scope.Detach()); 166 handles_from_parsing_.reset(scope.Detach());
169 167
170 return status_ != CompileJobStatus::kFailed; 168 return status_ != CompileJobStatus::kFailed;
171 } 169 }
172 170
173 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { 171 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() {
174 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 172 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
175 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); 173 DCHECK(status() == CompileJobStatus::kReadyToAnalyse);
176 174
177 compile_info_.reset(new CompilationInfo(parse_info_.get(), function_)); 175 compile_info_.reset(
176 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null()));
178 177
179 DeferredHandleScope scope(isolate_); 178 DeferredHandleScope scope(isolate_);
180 if (Compiler::Analyze(parse_info_.get())) { 179 if (Compiler::Analyze(parse_info_.get())) {
181 compile_job_.reset( 180 compile_job_.reset(
182 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); 181 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get()));
183 } 182 }
184 compile_info_->set_deferred_handles(scope.Detach()); 183 compile_info_->set_deferred_handles(scope.Detach());
185 184
186 if (!compile_job_.get()) { 185 if (!compile_job_.get()) {
187 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); 186 if (!isolate_->has_pending_exception()) isolate_->StackOverflow();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 if (!source_.is_null()) { 249 if (!source_.is_null()) {
251 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 250 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
252 source_ = Handle<String>::null(); 251 source_ = Handle<String>::null();
253 } 252 }
254 253
255 status_ = CompileJobStatus::kInitial; 254 status_ = CompileJobStatus::kInitial;
256 } 255 }
257 256
258 } // namespace internal 257 } // namespace internal
259 } // namespace v8 258 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.h ('k') | src/debug/liveedit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698