| 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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | 112 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; |
| 113 | 113 |
| 114 parser_->set_stack_limit(stack_limit); | 114 parser_->set_stack_limit(stack_limit); |
| 115 parser_->ParseOnBackground(parse_info_.get()); | 115 parser_->ParseOnBackground(parse_info_.get()); |
| 116 | 116 |
| 117 parse_info_->set_isolate(isolate_); | 117 parse_info_->set_isolate(isolate_); |
| 118 | 118 |
| 119 status_ = CompileJobStatus::kParsed; | 119 status_ = CompileJobStatus::kParsed; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void CompilerDispatcherJob::FinalizeParsingOnMainThread() { | 122 bool CompilerDispatcherJob::FinalizeParsingOnMainThread() { |
| 123 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 123 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 124 DCHECK(status() == CompileJobStatus::kParsed); | 124 DCHECK(status() == CompileJobStatus::kParsed); |
| 125 | 125 |
| 126 if (!source_.is_null()) { | 126 if (!source_.is_null()) { |
| 127 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 127 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
| 128 source_ = Handle<String>::null(); | 128 source_ = Handle<String>::null(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (parse_info_->literal() == nullptr) { | 131 if (parse_info_->literal() == nullptr) { |
| 132 status_ = CompileJobStatus::kFailed; | 132 status_ = CompileJobStatus::kFailed; |
| 133 return; | 133 } else { |
| 134 status_ = CompileJobStatus::kReadyToCompile; |
| 134 } | 135 } |
| 135 | 136 |
| 136 InternalizeParsingResult(); | 137 DeferredHandleScope scope(isolate_); |
| 138 { |
| 139 // Create a canonical handle scope before internalizing parsed values if |
| 140 // compiling bytecode. This is required for off-thread bytecode generation. |
| 141 std::unique_ptr<CanonicalHandleScope> canonical; |
| 142 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); |
| 137 | 143 |
| 138 status_ = CompileJobStatus::kReadyToCompile; | 144 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
| 139 } | 145 Handle<Script> script(Script::cast(shared->script()), isolate_); |
| 140 | 146 |
| 141 void CompilerDispatcherJob::ReportErrorsOnMainThread() { | 147 parse_info_->set_script(script); |
| 142 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 148 parse_info_->set_context(handle(function_->context(), isolate_)); |
| 143 DCHECK(status() == CompileJobStatus::kFailed); | |
| 144 | 149 |
| 145 // Internalizing the parsing result will throw the error. | 150 // Do the parsing tasks which need to be done on the main thread. This will |
| 146 InternalizeParsingResult(); | 151 // also handle parse errors. |
| 152 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); |
| 153 parser_->HandleSourceURLComments(isolate_, script); |
| 147 | 154 |
| 148 status_ = CompileJobStatus::kDone; | 155 parse_info_->set_character_stream(nullptr); |
| 156 parse_info_->set_unicode_cache(nullptr); |
| 157 parser_.reset(); |
| 158 unicode_cache_.reset(); |
| 159 character_stream_.reset(); |
| 160 } |
| 161 handles_from_parsing_.reset(scope.Detach()); |
| 162 |
| 163 return status_ != CompileJobStatus::kFailed; |
| 149 } | 164 } |
| 150 | 165 |
| 151 void CompilerDispatcherJob::ResetOnMainThread() { | 166 void CompilerDispatcherJob::ResetOnMainThread() { |
| 152 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 167 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 153 | 168 |
| 154 parser_.reset(); | 169 parser_.reset(); |
| 155 unicode_cache_.reset(); | 170 unicode_cache_.reset(); |
| 156 character_stream_.reset(); | 171 character_stream_.reset(); |
| 157 parse_info_.reset(); | 172 parse_info_.reset(); |
| 158 zone_.reset(); | 173 zone_.reset(); |
| 174 handles_from_parsing_.reset(); |
| 159 | 175 |
| 160 if (!source_.is_null()) { | 176 if (!source_.is_null()) { |
| 161 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 177 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
| 162 source_ = Handle<String>::null(); | 178 source_ = Handle<String>::null(); |
| 163 } | 179 } |
| 164 | 180 |
| 165 status_ = CompileJobStatus::kInitial; | 181 status_ = CompileJobStatus::kInitial; |
| 166 } | 182 } |
| 167 | 183 |
| 168 void CompilerDispatcherJob::InternalizeParsingResult() { | |
| 169 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
| 170 DCHECK(status() == CompileJobStatus::kParsed || | |
| 171 status() == CompileJobStatus::kFailed); | |
| 172 | |
| 173 HandleScope scope(isolate_); | |
| 174 | |
| 175 // Create a canonical handle scope before internalizing parsed values if | |
| 176 // compiling bytecode. This is required for off-thread bytecode generation. | |
| 177 std::unique_ptr<CanonicalHandleScope> canonical; | |
| 178 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); | |
| 179 | |
| 180 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | |
| 181 Handle<Script> script(Script::cast(shared->script()), isolate_); | |
| 182 | |
| 183 parse_info_->set_script(script); | |
| 184 parse_info_->set_context(handle(function_->context(), isolate_)); | |
| 185 | |
| 186 // Do the parsing tasks which need to be done on the main thread. This will | |
| 187 // also handle parse errors. | |
| 188 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | |
| 189 parser_->HandleSourceURLComments(isolate_, script); | |
| 190 | |
| 191 parse_info_->set_character_stream(nullptr); | |
| 192 parse_info_->set_unicode_cache(nullptr); | |
| 193 parser_.reset(); | |
| 194 unicode_cache_.reset(); | |
| 195 character_stream_.reset(); | |
| 196 } | |
| 197 | |
| 198 } // namespace internal | 184 } // namespace internal |
| 199 } // namespace v8 | 185 } // namespace v8 |
| OLD | NEW |