OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" | 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/checked_cast.h" | 10 #include "native_client/src/include/checked_cast.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", | 193 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
194 static_cast<void*>(plugin), pexe_url.c_str())); | 194 static_cast<void*>(plugin), pexe_url.c_str())); |
195 PnaclCoordinator* coordinator = | 195 PnaclCoordinator* coordinator = |
196 new PnaclCoordinator(plugin, pexe_url, | 196 new PnaclCoordinator(plugin, pexe_url, |
197 pnacl_options, | 197 pnacl_options, |
198 translate_notify_callback); | 198 translate_notify_callback); |
199 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); | 199 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); |
200 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ", | 200 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ", |
201 reinterpret_cast<const void*>(coordinator->manifest_.get()))); | 201 reinterpret_cast<const void*>(coordinator->manifest_.get()))); |
202 | 202 |
203 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); | |
204 coordinator->split_module_count_ = std::min(4, cpus); | |
jvoung (off chromium)
2014/02/14 00:46:49
Maybe clamp to >= 1. Looks like the unittest of im
Derek Schuff
2014/02/14 01:01:51
Done.
| |
205 fprintf(stderr, "processors %d, modules %d\n", cpus, coordinator->split_module _count_); | |
206 | |
203 // First start a network request for the pexe, to tickle the component | 207 // First start a network request for the pexe, to tickle the component |
204 // updater's On-Demand resource throttler, and to get Last-Modified/ETag | 208 // updater's On-Demand resource throttler, and to get Last-Modified/ETag |
205 // cache information. We can cancel the request later if there's | 209 // cache information. We can cancel the request later if there's |
206 // a bitcode->nexe cache hit. | 210 // a bitcode->nexe cache hit. |
207 coordinator->OpenBitcodeStream(); | 211 coordinator->OpenBitcodeStream(); |
208 return coordinator; | 212 return coordinator; |
209 } | 213 } |
210 | 214 |
211 PnaclCoordinator::PnaclCoordinator( | 215 PnaclCoordinator::PnaclCoordinator( |
212 Plugin* plugin, | 216 Plugin* plugin, |
213 const nacl::string& pexe_url, | 217 const nacl::string& pexe_url, |
214 const PnaclOptions& pnacl_options, | 218 const PnaclOptions& pnacl_options, |
215 const pp::CompletionCallback& translate_notify_callback) | 219 const pp::CompletionCallback& translate_notify_callback) |
216 : translate_finish_error_(PP_OK), | 220 : translate_finish_error_(PP_OK), |
217 plugin_(plugin), | 221 plugin_(plugin), |
218 translate_notify_callback_(translate_notify_callback), | 222 translate_notify_callback_(translate_notify_callback), |
219 translation_finished_reported_(false), | 223 translation_finished_reported_(false), |
220 manifest_(new PnaclManifest()), | 224 manifest_(new PnaclManifest()), |
221 pexe_url_(pexe_url), | 225 pexe_url_(pexe_url), |
222 pnacl_options_(pnacl_options), | 226 pnacl_options_(pnacl_options), |
227 num_object_files_opened_(0), | |
jvoung (off chromium)
2014/02/14 00:46:49
Initialize split_module_count_(0) or to 1 in const
Derek Schuff
2014/02/14 01:01:51
Done.
| |
223 is_cache_hit_(PP_FALSE), | 228 is_cache_hit_(PP_FALSE), |
224 error_already_reported_(false), | 229 error_already_reported_(false), |
225 pnacl_init_time_(0), | 230 pnacl_init_time_(0), |
226 pexe_size_(0), | 231 pexe_size_(0), |
227 pexe_bytes_compiled_(0), | 232 pexe_bytes_compiled_(0), |
228 expected_pexe_size_(-1) { | 233 expected_pexe_size_(-1) { |
229 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", | 234 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", |
230 static_cast<void*>(this), static_cast<void*>(plugin))); | 235 static_cast<void*>(this), static_cast<void*>(plugin))); |
231 callback_factory_.Initialize(this); | 236 callback_factory_.Initialize(this); |
232 } | 237 } |
233 | 238 |
234 PnaclCoordinator::~PnaclCoordinator() { | 239 PnaclCoordinator::~PnaclCoordinator() { |
235 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " | 240 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " |
236 "translate_thread=%p\n", | 241 "translate_thread=%p\n", |
237 static_cast<void*>(this), translate_thread_.get())); | 242 static_cast<void*>(this), translate_thread_.get())); |
238 // Stopping the translate thread will cause the translate thread to try to | 243 // Stopping the translate thread will cause the translate thread to try to |
239 // run translation_complete_callback_ on the main thread. This destructor is | 244 // run translation_complete_callback_ on the main thread. This destructor is |
240 // running from the main thread, and by the time it exits, callback_factory_ | 245 // running from the main thread, and by the time it exits, callback_factory_ |
241 // will have been destroyed. This will result in the cancellation of | 246 // will have been destroyed. This will result in the cancellation of |
242 // translation_complete_callback_, so no notification will be delivered. | 247 // translation_complete_callback_, so no notification will be delivered. |
243 if (translate_thread_.get() != NULL) { | 248 if (translate_thread_.get() != NULL) { |
244 translate_thread_->AbortSubprocesses(); | 249 translate_thread_->AbortSubprocesses(); |
245 } | 250 } |
246 if (!translation_finished_reported_) { | 251 if (!translation_finished_reported_) { |
247 plugin_->nacl_interface()->ReportTranslationFinished( | 252 plugin_->nacl_interface()->ReportTranslationFinished( |
248 plugin_->pp_instance(), | 253 plugin_->pp_instance(), |
249 PP_FALSE); | 254 PP_FALSE); |
250 } | 255 } |
256 for (int i = 0; i < num_object_files_opened_; i++) { | |
257 delete obj_files_[i]; | |
258 } | |
251 } | 259 } |
252 | 260 |
253 nacl::DescWrapper* PnaclCoordinator::ReleaseTranslatedFD() { | 261 nacl::DescWrapper* PnaclCoordinator::ReleaseTranslatedFD() { |
254 DCHECK(temp_nexe_file_ != NULL); | 262 DCHECK(temp_nexe_file_ != NULL); |
255 return temp_nexe_file_->release_read_wrapper(); | 263 return temp_nexe_file_->release_read_wrapper(); |
256 } | 264 } |
257 | 265 |
258 void PnaclCoordinator::ReportNonPpapiError(enum PluginErrorCode err_code, | 266 void PnaclCoordinator::ReportNonPpapiError(enum PluginErrorCode err_code, |
259 const nacl::string& message) { | 267 const nacl::string& message) { |
260 error_info_.SetReport(err_code, message); | 268 error_info_.SetReport(err_code, message); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 if (is_cache_hit_ == PP_TRUE) { | 532 if (is_cache_hit_ == PP_TRUE) { |
525 // Cache hit -- no need to stream the rest of the file. | 533 // Cache hit -- no need to stream the rest of the file. |
526 streaming_downloader_.reset(NULL); | 534 streaming_downloader_.reset(NULL); |
527 // Open it for reading as the cached nexe file. | 535 // Open it for reading as the cached nexe file. |
528 pp::CompletionCallback cb = | 536 pp::CompletionCallback cb = |
529 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); | 537 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); |
530 temp_nexe_file_->Open(cb, false); | 538 temp_nexe_file_->Open(cb, false); |
531 } else { | 539 } else { |
532 // Open an object file first so the translator can start writing to it | 540 // Open an object file first so the translator can start writing to it |
533 // during streaming translation. | 541 // during streaming translation. |
534 obj_file_.reset(new TempFile(plugin_)); | 542 for (int i = 0; i < split_module_count_; i++) { |
535 pp::CompletionCallback obj_cb = | 543 obj_files_.push_back(new TempFile(plugin_)); |
536 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); | 544 |
537 obj_file_->Open(obj_cb, true); | 545 pp::CompletionCallback obj_cb = |
546 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); | |
547 obj_files_[i]->Open(obj_cb, true); | |
548 } | |
538 | 549 |
539 // Meanwhile, a miss means we know we need to stream the bitcode, so stream | 550 // Meanwhile, a miss means we know we need to stream the bitcode, so stream |
540 // the rest of it now. (Calling FinishStreaming means that the downloader | 551 // the rest of it now. (Calling FinishStreaming means that the downloader |
541 // will begin handing data to the coordinator, which is safe any time after | 552 // will begin handing data to the coordinator, which is safe any time after |
542 // the translate_thread_ object has been initialized). | 553 // the translate_thread_ object has been initialized). |
543 pp::CompletionCallback finish_cb = callback_factory_.NewCallback( | 554 pp::CompletionCallback finish_cb = callback_factory_.NewCallback( |
544 &PnaclCoordinator::BitcodeStreamDidFinish); | 555 &PnaclCoordinator::BitcodeStreamDidFinish); |
545 streaming_downloader_->FinishStreaming(finish_cb); | 556 streaming_downloader_->FinishStreaming(finish_cb); |
546 } | 557 } |
547 } | 558 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 | 647 |
637 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { | 648 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { |
638 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" | 649 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" |
639 NACL_PRId32 ")\n", pp_error)); | 650 NACL_PRId32 ")\n", pp_error)); |
640 if (pp_error != PP_OK) { | 651 if (pp_error != PP_OK) { |
641 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, | 652 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, |
642 pp_error, | 653 pp_error, |
643 "Failed to open scratch object file."); | 654 "Failed to open scratch object file."); |
644 return; | 655 return; |
645 } | 656 } |
646 // Open the nexe file for connecting ld and sel_ldr. | 657 num_object_files_opened_++; |
647 // Start translation when done with this last step of setup! | 658 if (num_object_files_opened_ == split_module_count_) { |
648 pp::CompletionCallback cb = | 659 // Open the nexe file for connecting ld and sel_ldr. |
649 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); | 660 // Start translation when done with this last step of setup! |
650 temp_nexe_file_->Open(cb, true); | 661 pp::CompletionCallback cb = |
662 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); | |
663 temp_nexe_file_->Open(cb, true); | |
664 } | |
651 } | 665 } |
652 | 666 |
653 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 667 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
654 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 668 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
655 NACL_PRId32 ")\n", pp_error)); | 669 NACL_PRId32 ")\n", pp_error)); |
656 // Invoke llc followed by ld off the main thread. This allows use of | 670 // Invoke llc followed by ld off the main thread. This allows use of |
657 // blocking RPCs that would otherwise block the JavaScript main thread. | 671 // blocking RPCs that would otherwise block the JavaScript main thread. |
658 pp::CompletionCallback report_translate_finished = | 672 pp::CompletionCallback report_translate_finished = |
659 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 673 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
660 | 674 |
661 CHECK(translate_thread_ != NULL); | 675 CHECK(translate_thread_ != NULL); |
662 translate_thread_->RunTranslate(report_translate_finished, | 676 translate_thread_->RunTranslate(report_translate_finished, |
663 manifest_.get(), | 677 manifest_.get(), |
664 obj_file_.get(), | 678 &obj_files_, |
665 temp_nexe_file_.get(), | 679 temp_nexe_file_.get(), |
666 &error_info_, | 680 &error_info_, |
667 resources_.get(), | 681 resources_.get(), |
668 &pnacl_options_, | 682 &pnacl_options_, |
669 this, | 683 this, |
670 plugin_); | 684 plugin_); |
671 } | 685 } |
672 | 686 |
673 } // namespace plugin | 687 } // namespace plugin |
OLD | NEW |