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 "components/nacl/renderer/plugin/pnacl_coordinator.h" | 5 #include "components/nacl/renderer/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 const pp::CompletionCallback& translate_notify_callback) { | 94 const pp::CompletionCallback& translate_notify_callback) { |
95 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", | 95 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
96 static_cast<void*>(plugin), pexe_url.c_str())); | 96 static_cast<void*>(plugin), pexe_url.c_str())); |
97 PnaclCoordinator* coordinator = | 97 PnaclCoordinator* coordinator = |
98 new PnaclCoordinator(plugin, pexe_url, | 98 new PnaclCoordinator(plugin, pexe_url, |
99 pnacl_options, | 99 pnacl_options, |
100 translate_notify_callback); | 100 translate_notify_callback); |
101 | 101 |
102 GetNaClInterface()->SetPNaClStartTime(plugin->pp_instance()); | 102 GetNaClInterface()->SetPNaClStartTime(plugin->pp_instance()); |
103 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); | 103 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); |
104 coordinator->split_module_count_ = std::min(4, std::max(1, cpus)); | 104 coordinator->num_threads_ = std::min(4, std::max(1, cpus)); |
105 | 105 if (pnacl_options.use_subzero) { |
| 106 coordinator->split_module_count_ = 1; |
| 107 } else { |
| 108 coordinator->split_module_count_ = coordinator->num_threads_; |
| 109 } |
106 // First start a network request for the pexe, to tickle the component | 110 // First start a network request for the pexe, to tickle the component |
107 // updater's On-Demand resource throttler, and to get Last-Modified/ETag | 111 // updater's On-Demand resource throttler, and to get Last-Modified/ETag |
108 // cache information. We can cancel the request later if there's | 112 // cache information. We can cancel the request later if there's |
109 // a bitcode->nexe cache hit. | 113 // a bitcode->nexe cache hit. |
110 coordinator->OpenBitcodeStream(); | 114 coordinator->OpenBitcodeStream(); |
111 return coordinator; | 115 return coordinator; |
112 } | 116 } |
113 | 117 |
114 PnaclCoordinator::PnaclCoordinator( | 118 PnaclCoordinator::PnaclCoordinator( |
115 Plugin* plugin, | 119 Plugin* plugin, |
116 const std::string& pexe_url, | 120 const std::string& pexe_url, |
117 const PP_PNaClOptions& pnacl_options, | 121 const PP_PNaClOptions& pnacl_options, |
118 const pp::CompletionCallback& translate_notify_callback) | 122 const pp::CompletionCallback& translate_notify_callback) |
119 : translate_finish_error_(PP_OK), | 123 : translate_finish_error_(PP_OK), |
120 plugin_(plugin), | 124 plugin_(plugin), |
121 translate_notify_callback_(translate_notify_callback), | 125 translate_notify_callback_(translate_notify_callback), |
122 translation_finished_reported_(false), | 126 translation_finished_reported_(false), |
123 pexe_url_(pexe_url), | 127 pexe_url_(pexe_url), |
124 pnacl_options_(pnacl_options), | 128 pnacl_options_(pnacl_options), |
125 architecture_attributes_(GetArchitectureAttributes(plugin)), | 129 architecture_attributes_(GetArchitectureAttributes(plugin)), |
126 split_module_count_(1), | 130 split_module_count_(0), |
127 error_already_reported_(false), | 131 num_threads_(0), |
128 pexe_size_(0), | 132 error_already_reported_(false), |
129 pexe_bytes_compiled_(0), | 133 pexe_size_(0), |
130 expected_pexe_size_(-1) { | 134 pexe_bytes_compiled_(0), |
| 135 expected_pexe_size_(-1) { |
131 callback_factory_.Initialize(this); | 136 callback_factory_.Initialize(this); |
132 } | 137 } |
133 | 138 |
134 PnaclCoordinator::~PnaclCoordinator() { | 139 PnaclCoordinator::~PnaclCoordinator() { |
135 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " | 140 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " |
136 "translate_thread=%p\n", | 141 "translate_thread=%p\n", |
137 static_cast<void*>(this), translate_thread_.get())); | 142 static_cast<void*>(this), translate_thread_.get())); |
138 // Stopping the translate thread will cause the translate thread to try to | 143 // Stopping the translate thread will cause the translate thread to try to |
139 // run translation_complete_callback_ on the main thread. This destructor is | 144 // run translation_complete_callback_ on the main thread. This destructor is |
140 // running from the main thread, and by the time it exits, callback_factory_ | 145 // running from the main thread, and by the time it exits, callback_factory_ |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 312 } |
308 | 313 |
309 void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size, | 314 void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size, |
310 PP_FileHandle nexe_handle) { | 315 PP_FileHandle nexe_handle) { |
311 // IMPORTANT: Make sure that PnaclResources::StartLoad() is only | 316 // IMPORTANT: Make sure that PnaclResources::StartLoad() is only |
312 // called after you receive a response to a request for a .pexe file. | 317 // called after you receive a response to a request for a .pexe file. |
313 // | 318 // |
314 // The component updater's resource throttles + OnDemand update/install | 319 // The component updater's resource throttles + OnDemand update/install |
315 // should block the URL request until the compiler is present. Now we | 320 // should block the URL request until the compiler is present. Now we |
316 // can load the resources (e.g. llc and ld nexes). | 321 // can load the resources (e.g. llc and ld nexes). |
317 resources_.reset(new PnaclResources(plugin_)); | 322 resources_.reset(new PnaclResources(plugin_, pnacl_options_.use_subzero)); |
318 CHECK(resources_ != NULL); | 323 CHECK(resources_ != NULL); |
319 | 324 |
320 // The first step of loading resources: read the resource info file. | 325 // The first step of loading resources: read the resource info file. |
321 if (!resources_->ReadResourceInfo()) { | 326 if (!resources_->ReadResourceInfo()) { |
322 ExitWithError(); | 327 ExitWithError(); |
323 return; | 328 return; |
324 } | 329 } |
325 | 330 |
326 // Second step of loading resources: call StartLoad to load pnacl-llc | 331 // Second step of loading resources: call StartLoad to load pnacl-llc |
327 // and pnacl-ld, based on the filenames found in the resource info file. | 332 // and pnacl-ld, based on the filenames found in the resource info file. |
328 if (!resources_->StartLoad()) { | 333 if (!resources_->StartLoad()) { |
329 ReportNonPpapiError( | 334 ReportNonPpapiError( |
330 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 335 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
331 std::string("The Portable Native Client (pnacl) component is not " | 336 std::string("The Portable Native Client (pnacl) component is not " |
332 "installed. Please consult chrome://components for more " | 337 "installed. Please consult chrome://components for more " |
333 "information.")); | 338 "information.")); |
334 return; | 339 return; |
335 } | 340 } |
336 | 341 |
337 expected_pexe_size_ = expected_pexe_size; | 342 expected_pexe_size_ = expected_pexe_size; |
338 | 343 |
339 for (int i = 0; i < split_module_count_; i++) { | 344 for (size_t i = 0; i < split_module_count_; i++) { |
340 PP_FileHandle obj_handle = | 345 PP_FileHandle obj_handle = |
341 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance()); | 346 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance()); |
342 nacl::scoped_ptr<TempFile> temp_file(new TempFile(plugin_, obj_handle)); | 347 nacl::scoped_ptr<TempFile> temp_file(new TempFile(plugin_, obj_handle)); |
343 int32_t pp_error = temp_file->Open(true); | 348 int32_t pp_error = temp_file->Open(true); |
344 if (pp_error != PP_OK) { | 349 if (pp_error != PP_OK) { |
345 ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, | 350 ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, |
346 pp_error, | 351 pp_error, |
347 "Failed to open scratch object file."); | 352 "Failed to open scratch object file."); |
348 return; | 353 return; |
349 } else { | 354 } else { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 439 |
435 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 440 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
436 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 441 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
437 NACL_PRId32 ")\n", pp_error)); | 442 NACL_PRId32 ")\n", pp_error)); |
438 // Invoke llc followed by ld off the main thread. This allows use of | 443 // Invoke llc followed by ld off the main thread. This allows use of |
439 // blocking RPCs that would otherwise block the JavaScript main thread. | 444 // blocking RPCs that would otherwise block the JavaScript main thread. |
440 pp::CompletionCallback report_translate_finished = | 445 pp::CompletionCallback report_translate_finished = |
441 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 446 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
442 | 447 |
443 CHECK(translate_thread_ != NULL); | 448 CHECK(translate_thread_ != NULL); |
444 translate_thread_->RunTranslate(report_translate_finished, | 449 translate_thread_->RunTranslate(report_translate_finished, &obj_files_, |
445 &obj_files_, | 450 num_threads_, temp_nexe_file_.get(), |
446 temp_nexe_file_.get(), | 451 invalid_desc_wrapper_.get(), &error_info_, |
447 invalid_desc_wrapper_.get(), | 452 resources_.get(), &pnacl_options_, |
448 &error_info_, | 453 architecture_attributes_, this, plugin_); |
449 resources_.get(), | |
450 &pnacl_options_, | |
451 architecture_attributes_, | |
452 this, | |
453 plugin_); | |
454 } | 454 } |
455 | 455 |
456 } // namespace plugin | 456 } // namespace plugin |
OLD | NEW |