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/cpp/var.h" | 10 #include "ppapi/cpp/var.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 for (Args::const_iterator arg(args.begin()); arg != args.end(); ++arg) { | 47 for (Args::const_iterator arg(args.begin()); arg != args.end(); ++arg) { |
48 std::copy(arg->begin(), arg->end(), std::back_inserter(*split_args)); | 48 std::copy(arg->begin(), arg->end(), std::back_inserter(*split_args)); |
49 split_args->push_back('\x00'); | 49 split_args->push_back('\x00'); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false), | 55 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false), |
56 ld_subprocess_active_(false), | 56 ld_subprocess_active_(false), |
| 57 subprocesses_aborted_(false), |
57 done_(false), | 58 done_(false), |
58 compile_time_(0), | 59 compile_time_(0), |
59 obj_files_(NULL), | 60 obj_files_(NULL), |
60 nexe_file_(NULL), | 61 nexe_file_(NULL), |
61 coordinator_error_info_(NULL), | 62 coordinator_error_info_(NULL), |
62 resources_(NULL), | 63 resources_(NULL), |
63 coordinator_(NULL), | 64 coordinator_(NULL), |
64 plugin_(NULL) { | 65 plugin_(NULL) { |
65 NaClXMutexCtor(&subprocess_mu_); | 66 NaClXMutexCtor(&subprocess_mu_); |
66 NaClXMutexCtor(&cond_mu_); | 67 NaClXMutexCtor(&cond_mu_); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ErrorInfo error_info; | 154 ErrorInfo error_info; |
154 SrpcParams params; | 155 SrpcParams params; |
155 std::vector<nacl::DescWrapper*> llc_out_files; | 156 std::vector<nacl::DescWrapper*> llc_out_files; |
156 size_t i; | 157 size_t i; |
157 for (i = 0; i < obj_files_->size(); i++) | 158 for (i = 0; i < obj_files_->size(); i++) |
158 llc_out_files.push_back((*obj_files_)[i]->write_wrapper()); | 159 llc_out_files.push_back((*obj_files_)[i]->write_wrapper()); |
159 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) | 160 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) |
160 llc_out_files.push_back(invalid_desc_wrapper_); | 161 llc_out_files.push_back(invalid_desc_wrapper_); |
161 | 162 |
162 pp::Core* core = pp::Module::Get()->core(); | 163 pp::Core* core = pp::Module::Get()->core(); |
| 164 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); |
| 165 PP_FileHandle llc_file_handle = resources_->TakeLlcFileHandle(); |
| 166 // On success, ownership of llc_file_handle is transferred. |
| 167 NaClSubprocess* llc_subprocess = plugin_->LoadHelperNaClModule( |
| 168 resources_->GetLlcUrl(), llc_file_handle, &error_info); |
| 169 if (llc_subprocess == NULL) { |
| 170 if (llc_file_handle != PP_kInvalidFileHandle) |
| 171 CloseFileHandle(llc_file_handle); |
| 172 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, |
| 173 "Compile process could not be created: " + |
| 174 error_info.message()); |
| 175 return; |
| 176 } |
| 177 core->CallOnMainThread(0, |
| 178 coordinator_->GetUMATimeCallback( |
| 179 "NaCl.Perf.PNaClLoadTime.LoadCompiler", |
| 180 NaClGetTimeOfDayMicroseconds() - llc_start_time), |
| 181 PP_OK); |
| 182 |
163 { | 183 { |
164 nacl::MutexLocker ml(&subprocess_mu_); | 184 nacl::MutexLocker ml(&subprocess_mu_); |
165 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); | 185 // If we received a call to AbortSubprocesses() before we had a chance to |
166 PP_FileHandle llc_file_handle = resources_->TakeLlcFileHandle(); | 186 // set llc_subprocess_, shut down and clean up the subprocess started here. |
167 | 187 if (subprocesses_aborted_) { |
168 // On success, ownership of llc_file_handle is transferred. | 188 llc_subprocess->service_runtime()->Shutdown(); |
169 llc_subprocess_.reset(plugin_->LoadHelperNaClModule( | 189 delete llc_subprocess; |
170 resources_->GetLlcUrl(), llc_file_handle, &error_info)); | |
171 if (llc_subprocess_.get() == NULL) { | |
172 if (llc_file_handle != PP_kInvalidFileHandle) | |
173 CloseFileHandle(llc_file_handle); | |
174 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, | |
175 "Compile process could not be created: " + | |
176 error_info.message()); | |
177 return; | 190 return; |
178 } | 191 } |
179 | 192 llc_subprocess_.reset(llc_subprocess); |
| 193 llc_subprocess = NULL; |
180 llc_subprocess_active_ = true; | 194 llc_subprocess_active_ = true; |
181 core->CallOnMainThread(0, | |
182 coordinator_->GetUMATimeCallback( | |
183 "NaCl.Perf.PNaClLoadTime.LoadCompiler", | |
184 NaClGetTimeOfDayMicroseconds() - llc_start_time), | |
185 PP_OK); | |
186 } | 195 } |
187 | 196 |
188 int64_t compile_start_time = NaClGetTimeOfDayMicroseconds(); | 197 int64_t compile_start_time = NaClGetTimeOfDayMicroseconds(); |
189 bool init_success; | 198 bool init_success; |
190 | 199 |
191 std::vector<char> split_args; | 200 std::vector<char> split_args; |
192 GetLlcCommandLine(plugin_, | 201 GetLlcCommandLine(plugin_, |
193 &split_args, | 202 &split_args, |
194 obj_files_->size(), | 203 obj_files_->size(), |
195 pnacl_options_->opt_level, | 204 pnacl_options_->opt_level, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 PLUGIN_PRINTF(("PnaclTranslateThread::AbortSubprocesses\n")); | 428 PLUGIN_PRINTF(("PnaclTranslateThread::AbortSubprocesses\n")); |
420 NaClXMutexLock(&subprocess_mu_); | 429 NaClXMutexLock(&subprocess_mu_); |
421 if (llc_subprocess_ != NULL && llc_subprocess_active_) { | 430 if (llc_subprocess_ != NULL && llc_subprocess_active_) { |
422 llc_subprocess_->service_runtime()->Shutdown(); | 431 llc_subprocess_->service_runtime()->Shutdown(); |
423 llc_subprocess_active_ = false; | 432 llc_subprocess_active_ = false; |
424 } | 433 } |
425 if (ld_subprocess_ != NULL && ld_subprocess_active_) { | 434 if (ld_subprocess_ != NULL && ld_subprocess_active_) { |
426 ld_subprocess_->service_runtime()->Shutdown(); | 435 ld_subprocess_->service_runtime()->Shutdown(); |
427 ld_subprocess_active_ = false; | 436 ld_subprocess_active_ = false; |
428 } | 437 } |
| 438 subprocesses_aborted_ = true; |
429 NaClXMutexUnlock(&subprocess_mu_); | 439 NaClXMutexUnlock(&subprocess_mu_); |
430 nacl::MutexLocker ml(&cond_mu_); | 440 nacl::MutexLocker ml(&cond_mu_); |
431 done_ = true; | 441 done_ = true; |
432 // Free all buffered bitcode chunks | 442 // Free all buffered bitcode chunks |
433 data_buffers_.clear(); | 443 data_buffers_.clear(); |
434 NaClXCondVarSignal(&buffer_cond_); | 444 NaClXCondVarSignal(&buffer_cond_); |
435 } | 445 } |
436 | 446 |
437 PnaclTranslateThread::~PnaclTranslateThread() { | 447 PnaclTranslateThread::~PnaclTranslateThread() { |
438 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", this)); | 448 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", this)); |
439 AbortSubprocesses(); | 449 AbortSubprocesses(); |
440 if (translate_thread_ != NULL) | 450 if (translate_thread_ != NULL) |
441 NaClThreadJoin(translate_thread_.get()); | 451 NaClThreadJoin(translate_thread_.get()); |
442 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | 452 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
443 NaClCondVarDtor(&buffer_cond_); | 453 NaClCondVarDtor(&buffer_cond_); |
444 NaClMutexDtor(&cond_mu_); | 454 NaClMutexDtor(&cond_mu_); |
445 NaClMutexDtor(&subprocess_mu_); | 455 NaClMutexDtor(&subprocess_mu_); |
446 } | 456 } |
447 | 457 |
448 } // namespace plugin | 458 } // namespace plugin |
OLD | NEW |