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

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

Issue 2632123006: Reland: [Parse] ParseInfo owns the parsing Zone. (Closed)
Patch Set: Rebase Created 3 years, 10 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/compiler/js-inlining.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-dispatcher/compiler-dispatcher-tracer.h" 9 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 CompilerDispatcherTracer* tracer, 88 CompilerDispatcherTracer* tracer,
89 Handle<SharedFunctionInfo> shared, 89 Handle<SharedFunctionInfo> shared,
90 FunctionLiteral* literal, 90 FunctionLiteral* literal,
91 size_t max_stack_size) 91 size_t max_stack_size)
92 : status_(CompileJobStatus::kAnalyzed), 92 : status_(CompileJobStatus::kAnalyzed),
93 isolate_(isolate), 93 isolate_(isolate),
94 tracer_(tracer), 94 tracer_(tracer),
95 shared_(Handle<SharedFunctionInfo>::cast( 95 shared_(Handle<SharedFunctionInfo>::cast(
96 isolate_->global_handles()->Create(*shared))), 96 isolate_->global_handles()->Create(*shared))),
97 max_stack_size_(max_stack_size), 97 max_stack_size_(max_stack_size),
98 zone_(new Zone(isolate->allocator(), ZONE_NAME)), 98 parse_info_(
99 parse_info_(new ParseInfo( 99 new ParseInfo(Handle<Script>(Script::cast(shared->script())))),
100 zone_.get(), Handle<Script>(Script::cast(shared->script())))),
101 compile_info_( 100 compile_info_(
102 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())), 101 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())),
103 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { 102 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) {
104 parse_info_->set_literal(literal); 103 parse_info_->set_literal(literal);
105 parse_info_->set_shared_info(shared); 104 parse_info_->set_shared_info(shared);
106 parse_info_->set_function_literal_id(shared->function_literal_id()); 105 parse_info_->set_function_literal_id(shared->function_literal_id());
107 parse_info_->set_language_mode(literal->scope()->language_mode()); 106 parse_info_->set_language_mode(literal->scope()->language_mode());
108 if (trace_compiler_dispatcher_jobs_) { 107 if (trace_compiler_dispatcher_jobs_) {
109 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); 108 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this));
110 shared_->ShortPrint(); 109 shared_->ShortPrint();
(...skipping 16 matching lines...) Expand all
127 void CompilerDispatcherJob::PrepareToParseOnMainThread() { 126 void CompilerDispatcherJob::PrepareToParseOnMainThread() {
128 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 127 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
129 DCHECK(status() == CompileJobStatus::kInitial); 128 DCHECK(status() == CompileJobStatus::kInitial);
130 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToParse); 129 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToParse);
131 if (trace_compiler_dispatcher_jobs_) { 130 if (trace_compiler_dispatcher_jobs_) {
132 PrintF("CompilerDispatcherJob[%p]: Preparing to parse\n", 131 PrintF("CompilerDispatcherJob[%p]: Preparing to parse\n",
133 static_cast<void*>(this)); 132 static_cast<void*>(this));
134 } 133 }
135 HandleScope scope(isolate_); 134 HandleScope scope(isolate_);
136 unicode_cache_.reset(new UnicodeCache()); 135 unicode_cache_.reset(new UnicodeCache());
137 zone_.reset(new Zone(isolate_->allocator(), ZONE_NAME));
138 Handle<Script> script(Script::cast(shared_->script()), isolate_); 136 Handle<Script> script(Script::cast(shared_->script()), isolate_);
139 DCHECK(script->type() != Script::TYPE_NATIVE); 137 DCHECK(script->type() != Script::TYPE_NATIVE);
140 138
141 Handle<String> source(String::cast(script->source()), isolate_); 139 Handle<String> source(String::cast(script->source()), isolate_);
140 parse_info_.reset(new ParseInfo(isolate_->allocator()));
142 if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) { 141 if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) {
143 character_stream_.reset(ScannerStream::For( 142 character_stream_.reset(ScannerStream::For(
144 source, shared_->start_position(), shared_->end_position())); 143 source, shared_->start_position(), shared_->end_position()));
145 } else { 144 } else {
146 source = String::Flatten(source); 145 source = String::Flatten(source);
147 const void* data; 146 const void* data;
148 int offset = 0; 147 int offset = 0;
149 int length = source->length(); 148 int length = source->length();
150 149
151 // Objects in lo_space don't move, so we can just read the contents from 150 // Objects in lo_space don't move, so we can just read the contents from
(...skipping 10 matching lines...) Expand all
162 content.IsOneByte() 161 content.IsOneByte()
163 ? reinterpret_cast<const void*>(content.ToOneByteVector().start()) 162 ? reinterpret_cast<const void*>(content.ToOneByteVector().start())
164 : reinterpret_cast<const void*>(content.ToUC16Vector().start()); 163 : reinterpret_cast<const void*>(content.ToUC16Vector().start());
165 } else { 164 } else {
166 // Otherwise, create a copy of the part of the string we'll parse in the 165 // Otherwise, create a copy of the part of the string we'll parse in the
167 // zone. 166 // zone.
168 length = (shared_->end_position() - shared_->start_position()); 167 length = (shared_->end_position() - shared_->start_position());
169 offset = shared_->start_position(); 168 offset = shared_->start_position();
170 169
171 int byte_len = length * (source->IsOneByteRepresentation() ? 1 : 2); 170 int byte_len = length * (source->IsOneByteRepresentation() ? 1 : 2);
172 data = zone_->New(byte_len); 171 data = parse_info_->zone()->New(byte_len);
173 172
174 DisallowHeapAllocation no_allocation; 173 DisallowHeapAllocation no_allocation;
175 String::FlatContent content = source->GetFlatContent(); 174 String::FlatContent content = source->GetFlatContent();
176 DCHECK(content.IsFlat()); 175 DCHECK(content.IsFlat());
177 if (content.IsOneByte()) { 176 if (content.IsOneByte()) {
178 MemCopy(const_cast<void*>(data), 177 MemCopy(const_cast<void*>(data),
179 &content.ToOneByteVector().at(shared_->start_position()), 178 &content.ToOneByteVector().at(shared_->start_position()),
180 byte_len); 179 byte_len);
181 } else { 180 } else {
182 MemCopy(const_cast<void*>(data), 181 MemCopy(const_cast<void*>(data),
(...skipping 17 matching lines...) Expand all
200 ->NewExternalStringFromTwoByte(resource) 199 ->NewExternalStringFromTwoByte(resource)
201 .ToHandleChecked(); 200 .ToHandleChecked();
202 } 201 }
203 wrapper_ = 202 wrapper_ =
204 Handle<String>::cast(isolate_->global_handles()->Create(*wrapper)); 203 Handle<String>::cast(isolate_->global_handles()->Create(*wrapper));
205 204
206 character_stream_.reset( 205 character_stream_.reset(
207 ScannerStream::For(wrapper_, shared_->start_position() - offset, 206 ScannerStream::For(wrapper_, shared_->start_position() - offset,
208 shared_->end_position() - offset)); 207 shared_->end_position() - offset));
209 } 208 }
210 parse_info_.reset(new ParseInfo(zone_.get()));
211 parse_info_->set_isolate(isolate_); 209 parse_info_->set_isolate(isolate_);
212 parse_info_->set_character_stream(character_stream_.get()); 210 parse_info_->set_character_stream(character_stream_.get());
213 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); 211 parse_info_->set_hash_seed(isolate_->heap()->HashSeed());
214 parse_info_->set_is_named_expression(shared_->is_named_expression()); 212 parse_info_->set_is_named_expression(shared_->is_named_expression());
215 parse_info_->set_compiler_hints(shared_->compiler_hints()); 213 parse_info_->set_compiler_hints(shared_->compiler_hints());
216 parse_info_->set_start_position(shared_->start_position()); 214 parse_info_->set_start_position(shared_->start_position());
217 parse_info_->set_end_position(shared_->end_position()); 215 parse_info_->set_end_position(shared_->end_position());
218 parse_info_->set_unicode_cache(unicode_cache_.get()); 216 parse_info_->set_unicode_cache(unicode_cache_.get());
219 parse_info_->set_language_mode(shared_->language_mode()); 217 parse_info_->set_language_mode(shared_->language_mode());
220 parse_info_->set_function_literal_id(shared_->function_literal_id()); 218 parse_info_->set_function_literal_id(shared_->function_literal_id());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 static_cast<void*>(this)); 384 static_cast<void*>(this));
387 } 385 }
388 386
389 if (compile_job_->state() == CompilationJob::State::kFailed || 387 if (compile_job_->state() == CompilationJob::State::kFailed ||
390 !Compiler::FinalizeCompilationJob(compile_job_.release())) { 388 !Compiler::FinalizeCompilationJob(compile_job_.release())) {
391 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); 389 if (!isolate_->has_pending_exception()) isolate_->StackOverflow();
392 status_ = CompileJobStatus::kFailed; 390 status_ = CompileJobStatus::kFailed;
393 return false; 391 return false;
394 } 392 }
395 393
396 zone_.reset();
397 compile_job_.reset(); 394 compile_job_.reset();
398 compile_info_.reset(); 395 compile_info_.reset();
399 handles_from_parsing_.reset(); 396 handles_from_parsing_.reset();
400 parse_info_.reset(); 397 parse_info_.reset();
401 398
402 status_ = CompileJobStatus::kDone; 399 status_ = CompileJobStatus::kDone;
403 return true; 400 return true;
404 } 401 }
405 402
406 void CompilerDispatcherJob::ResetOnMainThread() { 403 void CompilerDispatcherJob::ResetOnMainThread() {
407 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 404 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
408 405
409 if (trace_compiler_dispatcher_jobs_) { 406 if (trace_compiler_dispatcher_jobs_) {
410 PrintF("CompilerDispatcherJob[%p]: Resetting\n", static_cast<void*>(this)); 407 PrintF("CompilerDispatcherJob[%p]: Resetting\n", static_cast<void*>(this));
411 } 408 }
412 409
413 compile_job_.reset(); 410 compile_job_.reset();
414 compile_info_.reset(); 411 compile_info_.reset();
415 parser_.reset(); 412 parser_.reset();
416 unicode_cache_.reset(); 413 unicode_cache_.reset();
417 character_stream_.reset(); 414 character_stream_.reset();
418 handles_from_parsing_.reset(); 415 handles_from_parsing_.reset();
419 parse_info_.reset(); 416 parse_info_.reset();
420 zone_.reset();
421 417
422 if (!source_.is_null()) { 418 if (!source_.is_null()) {
423 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 419 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
424 source_ = Handle<String>::null(); 420 source_ = Handle<String>::null();
425 } 421 }
426 if (!wrapper_.is_null()) { 422 if (!wrapper_.is_null()) {
427 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location()); 423 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location());
428 wrapper_ = Handle<String>::null(); 424 wrapper_ = Handle<String>::null();
429 } 425 }
430 426
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 return 0.0; 461 return 0.0;
466 } 462 }
467 463
468 void CompilerDispatcherJob::ShortPrint() { 464 void CompilerDispatcherJob::ShortPrint() {
469 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 465 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
470 shared_->ShortPrint(); 466 shared_->ShortPrint();
471 } 467 }
472 468
473 } // namespace internal 469 } // namespace internal
474 } // namespace v8 470 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.h ('k') | src/compiler/js-inlining.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698