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_translate_thread.h" | 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 return str; | 33 return str; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false), | 38 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false), |
39 ld_subprocess_active_(false), | 39 ld_subprocess_active_(false), |
40 done_(false), | 40 done_(false), |
41 compile_time_(0), | 41 compile_time_(0), |
42 manifest_(NULL), | 42 manifest_id_(0), |
43 obj_files_(NULL), | 43 obj_files_(NULL), |
44 nexe_file_(NULL), | 44 nexe_file_(NULL), |
45 coordinator_error_info_(NULL), | 45 coordinator_error_info_(NULL), |
46 resources_(NULL), | 46 resources_(NULL), |
47 coordinator_(NULL), | 47 coordinator_(NULL), |
48 plugin_(NULL) { | 48 plugin_(NULL) { |
49 NaClXMutexCtor(&subprocess_mu_); | 49 NaClXMutexCtor(&subprocess_mu_); |
50 NaClXMutexCtor(&cond_mu_); | 50 NaClXMutexCtor(&cond_mu_); |
51 NaClXCondVarCtor(&buffer_cond_); | 51 NaClXCondVarCtor(&buffer_cond_); |
52 } | 52 } |
53 | 53 |
54 void PnaclTranslateThread::RunTranslate( | 54 void PnaclTranslateThread::RunTranslate( |
55 const pp::CompletionCallback& finish_callback, | 55 const pp::CompletionCallback& finish_callback, |
56 const Manifest* manifest, | 56 int32_t manifest_id, |
57 const std::vector<TempFile*>* obj_files, | 57 const std::vector<TempFile*>* obj_files, |
58 TempFile* nexe_file, | 58 TempFile* nexe_file, |
59 nacl::DescWrapper* invalid_desc_wrapper, | 59 nacl::DescWrapper* invalid_desc_wrapper, |
60 ErrorInfo* error_info, | 60 ErrorInfo* error_info, |
61 PnaclResources* resources, | 61 PnaclResources* resources, |
62 PP_PNaClOptions* pnacl_options, | 62 PP_PNaClOptions* pnacl_options, |
63 PnaclCoordinator* coordinator, | 63 PnaclCoordinator* coordinator, |
64 Plugin* plugin) { | 64 Plugin* plugin) { |
65 PLUGIN_PRINTF(("PnaclStreamingTranslateThread::RunTranslate)\n")); | 65 PLUGIN_PRINTF(("PnaclStreamingTranslateThread::RunTranslate)\n")); |
66 manifest_ = manifest; | 66 manifest_id_ = manifest_id; |
67 obj_files_ = obj_files; | 67 obj_files_ = obj_files; |
68 nexe_file_ = nexe_file; | 68 nexe_file_ = nexe_file; |
69 invalid_desc_wrapper_ = invalid_desc_wrapper; | 69 invalid_desc_wrapper_ = invalid_desc_wrapper; |
70 coordinator_error_info_ = error_info; | 70 coordinator_error_info_ = error_info; |
71 resources_ = resources; | 71 resources_ = resources; |
72 pnacl_options_ = pnacl_options; | 72 pnacl_options_ = pnacl_options; |
73 coordinator_ = coordinator; | 73 coordinator_ = coordinator; |
74 plugin_ = plugin; | 74 plugin_ = plugin; |
75 | 75 |
76 // Invoke llc followed by ld off the main thread. This allows use of | 76 // Invoke llc followed by ld off the main thread. This allows use of |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 NaClXCondVarSignal(&buffer_cond_); | 123 NaClXCondVarSignal(&buffer_cond_); |
124 NaClXMutexUnlock(&cond_mu_); | 124 NaClXMutexUnlock(&cond_mu_); |
125 | 125 |
126 // Ensure the buffer we send back to the coordinator is the expected size | 126 // Ensure the buffer we send back to the coordinator is the expected size |
127 bytes->resize(buffer_size); | 127 bytes->resize(buffer_size); |
128 } | 128 } |
129 | 129 |
130 NaClSubprocess* PnaclTranslateThread::StartSubprocess( | 130 NaClSubprocess* PnaclTranslateThread::StartSubprocess( |
131 const nacl::string& url_for_nexe, | 131 const nacl::string& url_for_nexe, |
132 const Manifest* manifest, | 132 int32_t manifest_id, |
133 ErrorInfo* error_info) { | 133 ErrorInfo* error_info) { |
134 PLUGIN_PRINTF(("PnaclTranslateThread::StartSubprocess (url_for_nexe=%s)\n", | 134 PLUGIN_PRINTF(("PnaclTranslateThread::StartSubprocess (url_for_nexe=%s)\n", |
135 url_for_nexe.c_str())); | 135 url_for_nexe.c_str())); |
136 nacl::DescWrapper* wrapper = resources_->WrapperForUrl(url_for_nexe); | 136 nacl::DescWrapper* wrapper = resources_->WrapperForUrl(url_for_nexe); |
137 // Supply a URL for the translator components, different from the app URL, | 137 // Supply a URL for the translator components, different from the app URL, |
138 // so that NaCl GDB can filter-out the translator processes (and not debug | 138 // so that NaCl GDB can filter-out the translator processes (and not debug |
139 // the translator itself). Must have a full URL with schema, otherwise the | 139 // the translator itself). Must have a full URL with schema, otherwise the |
140 // string gets silently dropped by GURL. | 140 // string gets silently dropped by GURL. |
141 nacl::string full_url = resources_->GetFullUrl( | 141 nacl::string full_url = resources_->GetFullUrl( |
142 url_for_nexe, plugin_->nacl_interface()->GetSandboxArch()); | 142 url_for_nexe, plugin_->nacl_interface()->GetSandboxArch()); |
143 nacl::scoped_ptr<NaClSubprocess> subprocess( | 143 nacl::scoped_ptr<NaClSubprocess> subprocess(plugin_->LoadHelperNaClModule( |
144 plugin_->LoadHelperNaClModule(full_url, wrapper, manifest, error_info)); | 144 full_url, wrapper, manifest_id, error_info)); |
145 if (subprocess.get() == NULL) { | 145 if (subprocess.get() == NULL) { |
146 PLUGIN_PRINTF(( | 146 PLUGIN_PRINTF(( |
147 "PnaclTranslateThread::StartSubprocess: subprocess creation failed\n")); | 147 "PnaclTranslateThread::StartSubprocess: subprocess creation failed\n")); |
148 return NULL; | 148 return NULL; |
149 } | 149 } |
150 return subprocess.release(); | 150 return subprocess.release(); |
151 } | 151 } |
152 | 152 |
153 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { | 153 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { |
154 PnaclTranslateThread* translator = | 154 PnaclTranslateThread* translator = |
(...skipping 11 matching lines...) Expand all Loading... |
166 } | 166 } |
167 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) { | 167 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) { |
168 llc_out_files.push_back(invalid_desc_wrapper_); | 168 llc_out_files.push_back(invalid_desc_wrapper_); |
169 } | 169 } |
170 | 170 |
171 pp::Core* core = pp::Module::Get()->core(); | 171 pp::Core* core = pp::Module::Get()->core(); |
172 { | 172 { |
173 nacl::MutexLocker ml(&subprocess_mu_); | 173 nacl::MutexLocker ml(&subprocess_mu_); |
174 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); | 174 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); |
175 llc_subprocess_.reset( | 175 llc_subprocess_.reset( |
176 StartSubprocess(resources_->GetLlcUrl(), manifest_, &error_info)); | 176 StartSubprocess(resources_->GetLlcUrl(), manifest_id_, &error_info)); |
177 if (llc_subprocess_ == NULL) { | 177 if (llc_subprocess_ == NULL) { |
178 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, | 178 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, |
179 "Compile process could not be created: " + | 179 "Compile process could not be created: " + |
180 error_info.message()); | 180 error_info.message()); |
181 return; | 181 return; |
182 } | 182 } |
183 llc_subprocess_active_ = true; | 183 llc_subprocess_active_ = true; |
184 core->CallOnMainThread(0, | 184 core->CallOnMainThread(0, |
185 coordinator_->GetUMATimeCallback( | 185 coordinator_->GetUMATimeCallback( |
186 "NaCl.Perf.PNaClLoadTime.LoadCompiler", | 186 "NaCl.Perf.PNaClLoadTime.LoadCompiler", |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 ld_in_files.push_back(invalid_desc_wrapper_); | 343 ld_in_files.push_back(invalid_desc_wrapper_); |
344 } | 344 } |
345 | 345 |
346 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); | 346 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); |
347 pp::Core* core = pp::Module::Get()->core(); | 347 pp::Core* core = pp::Module::Get()->core(); |
348 { | 348 { |
349 // Create LD process | 349 // Create LD process |
350 nacl::MutexLocker ml(&subprocess_mu_); | 350 nacl::MutexLocker ml(&subprocess_mu_); |
351 int64_t ld_start_time = NaClGetTimeOfDayMicroseconds(); | 351 int64_t ld_start_time = NaClGetTimeOfDayMicroseconds(); |
352 ld_subprocess_.reset( | 352 ld_subprocess_.reset( |
353 StartSubprocess(resources_->GetLdUrl(), manifest_, &error_info)); | 353 StartSubprocess(resources_->GetLdUrl(), manifest_id_, &error_info)); |
354 if (ld_subprocess_ == NULL) { | 354 if (ld_subprocess_ == NULL) { |
355 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, | 355 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, |
356 "Link process could not be created: " + | 356 "Link process could not be created: " + |
357 error_info.message()); | 357 error_info.message()); |
358 return false; | 358 return false; |
359 } | 359 } |
360 ld_subprocess_active_ = true; | 360 ld_subprocess_active_ = true; |
361 core->CallOnMainThread(0, | 361 core->CallOnMainThread(0, |
362 coordinator_->GetUMATimeCallback( | 362 coordinator_->GetUMATimeCallback( |
363 "NaCl.Perf.PNaClLoadTime.LoadLinker", | 363 "NaCl.Perf.PNaClLoadTime.LoadLinker", |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 AbortSubprocesses(); | 452 AbortSubprocesses(); |
453 if (translate_thread_ != NULL) | 453 if (translate_thread_ != NULL) |
454 NaClThreadJoin(translate_thread_.get()); | 454 NaClThreadJoin(translate_thread_.get()); |
455 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | 455 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
456 NaClCondVarDtor(&buffer_cond_); | 456 NaClCondVarDtor(&buffer_cond_); |
457 NaClMutexDtor(&cond_mu_); | 457 NaClMutexDtor(&cond_mu_); |
458 NaClMutexDtor(&subprocess_mu_); | 458 NaClMutexDtor(&subprocess_mu_); |
459 } | 459 } |
460 | 460 |
461 } // namespace plugin | 461 } // namespace plugin |
OLD | NEW |