| 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/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" |
| 11 #include "src/parsing/parser.h" | 11 #include "src/parsing/parser.h" |
| 12 #include "src/parsing/scanner-character-streams.h" | 12 #include "src/parsing/scanner-character-streams.h" |
| 13 #include "src/unicode-cache.h" | 13 #include "src/unicode-cache.h" |
| 14 #include "src/zone.h" | 14 #include "src/zone.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, | 19 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
| 20 Handle<JSFunction> function, | 20 Handle<JSFunction> function, |
| 21 size_t max_stack_size) | 21 size_t max_stack_size) |
| 22 : isolate_(isolate), | 22 : isolate_(isolate), |
| 23 function_(Handle<JSFunction>::cast( | 23 function_(Handle<JSFunction>::cast( |
| 24 isolate_->global_handles()->Create(*function))), | 24 isolate_->global_handles()->Create(*function))), |
| 25 max_stack_size_(max_stack_size) { | 25 max_stack_size_(max_stack_size) { |
| 26 HandleScope scope(isolate_); | 26 HandleScope scope(isolate_); |
| 27 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 27 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
| 28 Handle<Script> script(Script::cast(shared->script()), isolate_); | 28 Handle<Script> script(Script::cast(shared->script()), isolate_); |
| 29 Handle<String> source(String::cast(script->source()), isolate_); | 29 Handle<String> source(String::cast(script->source()), isolate_); |
| 30 if (source->IsExternalTwoByteString()) { | 30 can_parse_on_background_thread_ = |
| 31 can_parse_on_background_thread_ = true; | 31 source->IsExternalTwoByteString() || source->IsExternalOneByteString(); |
| 32 } else if (source->IsExternalOneByteString()) { | |
| 33 can_parse_on_background_thread_ = true; | |
| 34 } else { | |
| 35 can_parse_on_background_thread_ = false; | |
| 36 } | |
| 37 } | 32 } |
| 38 | 33 |
| 39 CompilerDispatcherJob::~CompilerDispatcherJob() { | 34 CompilerDispatcherJob::~CompilerDispatcherJob() { |
| 40 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 35 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 41 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); | 36 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); |
| 42 } | 37 } |
| 43 | 38 |
| 44 void CompilerDispatcherJob::PrepareToParseOnMainThread() { | 39 void CompilerDispatcherJob::PrepareToParseOnMainThread() { |
| 45 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 40 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 46 DCHECK(status() == CompileJobStatus::kInitial); | 41 DCHECK(status() == CompileJobStatus::kInitial); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 can_parse_on_background_thread_ = false; | 59 can_parse_on_background_thread_ = false; |
| 65 character_stream_.reset(new GenericStringUtf16CharacterStream( | 60 character_stream_.reset(new GenericStringUtf16CharacterStream( |
| 66 source, shared->start_position(), shared->end_position())); | 61 source, shared->start_position(), shared->end_position())); |
| 67 } | 62 } |
| 68 parse_info_.reset(new ParseInfo(zone_.get())); | 63 parse_info_.reset(new ParseInfo(zone_.get())); |
| 69 parse_info_->set_isolate(isolate_); | 64 parse_info_->set_isolate(isolate_); |
| 70 parse_info_->set_character_stream(character_stream_.get()); | 65 parse_info_->set_character_stream(character_stream_.get()); |
| 71 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); | 66 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); |
| 72 parse_info_->set_unicode_cache(unicode_cache_.get()); | 67 parse_info_->set_unicode_cache(unicode_cache_.get()); |
| 73 parser_.reset(new Parser(parse_info_.get())); | 68 parser_.reset(new Parser(parse_info_.get())); |
| 74 status_.SetValue(CompileJobStatus::kReadyToParse); | 69 status_ = CompileJobStatus::kReadyToParse; |
| 75 } | 70 } |
| 76 | 71 |
| 77 void CompilerDispatcherJob::Parse() { | 72 void CompilerDispatcherJob::Parse() { |
| 78 DCHECK(can_parse_on_background_thread_ || | 73 DCHECK(can_parse_on_background_thread_ || |
| 79 ThreadId::Current().Equals(isolate_->thread_id())); | 74 ThreadId::Current().Equals(isolate_->thread_id())); |
| 80 DCHECK(status() == CompileJobStatus::kReadyToParse); | 75 DCHECK(status() == CompileJobStatus::kReadyToParse); |
| 81 | 76 |
| 82 DisallowHeapAllocation no_allocation; | 77 DisallowHeapAllocation no_allocation; |
| 83 DisallowHandleAllocation no_handles; | 78 DisallowHandleAllocation no_handles; |
| 84 DisallowHandleDereference no_deref; | 79 DisallowHandleDereference no_deref; |
| 85 | 80 |
| 86 // Nullify the Isolate temporarily so that the parser doesn't accidentally | 81 // Nullify the Isolate temporarily so that the parser doesn't accidentally |
| 87 // use it. | 82 // use it. |
| 88 parse_info_->set_isolate(nullptr); | 83 parse_info_->set_isolate(nullptr); |
| 89 | 84 |
| 90 uintptr_t stack_limit = | 85 uintptr_t stack_limit = |
| 91 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | 86 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; |
| 92 | 87 |
| 93 parser_->set_stack_limit(stack_limit); | 88 parser_->set_stack_limit(stack_limit); |
| 94 parser_->ParseOnBackground(parse_info_.get()); | 89 parser_->ParseOnBackground(parse_info_.get()); |
| 95 | 90 |
| 96 parse_info_->set_isolate(isolate_); | 91 parse_info_->set_isolate(isolate_); |
| 97 | 92 |
| 98 status_.SetValue(CompileJobStatus::kParsed); | 93 status_ = CompileJobStatus::kParsed; |
| 99 } | 94 } |
| 100 | 95 |
| 101 } // namespace internal | 96 } // namespace internal |
| 102 } // namespace v8 | 97 } // namespace v8 |
| OLD | NEW |