Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: components/nacl/renderer/plugin/pnacl_resources.cc

Issue 1005173006: Add a switch for using PNaCl Subzero and use it for -O0 translation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: separate subzero / llc cache keys Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_resources.h" 5 #include "components/nacl/renderer/plugin/pnacl_resources.h"
6 6
7 #include <vector>
8
9 #include "base/macros.h"
7 #include "components/nacl/renderer/plugin/plugin.h" 10 #include "components/nacl/renderer/plugin/plugin.h"
8 #include "components/nacl/renderer/plugin/utility.h" 11 #include "components/nacl/renderer/plugin/utility.h"
9 #include "native_client/src/include/portability_io.h" 12 #include "native_client/src/include/portability_io.h"
10 #include "native_client/src/shared/platform/nacl_check.h" 13 #include "native_client/src/shared/platform/nacl_check.h"
11 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 14 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
12 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
13 16
14 namespace plugin { 17 namespace plugin {
15 18
16 namespace { 19 namespace {
17 20
18 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; 21 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/";
19 22
20 std::string GetFullUrl(const std::string& partial_url) { 23 std::string GetFullUrl(const std::string& partial_url) {
21 return std::string(kPnaclBaseUrl) + GetNaClInterface()->GetSandboxArch() + 24 return std::string(kPnaclBaseUrl) + GetNaClInterface()->GetSandboxArch() +
22 "/" + partial_url; 25 "/" + partial_url;
23 } 26 }
24 27
25 } // namespace 28 } // namespace
26 29
27 PnaclResources::PnaclResources(Plugin* plugin) 30 PnaclResources::PnaclResources(Plugin* plugin, bool use_subzero)
28 : plugin_(plugin) { 31 : plugin_(plugin), use_subzero_(use_subzero) {
29 llc_file_info_ = kInvalidNaClFileInfo; 32 for (size_t i = 0; i < arraysize(resources_); ++i) {
30 ld_file_info_ = kInvalidNaClFileInfo; 33 resources_[i].file_info = kInvalidNaClFileInfo;
34 }
31 } 35 }
32 36
33 PnaclResources::~PnaclResources() { 37 PnaclResources::~PnaclResources() {
34 if (llc_file_info_.handle != PP_kInvalidFileHandle) 38 for (size_t i = 0; i < arraysize(resources_); ++i) {
35 CloseFileHandle(llc_file_info_.handle); 39 if (resources_[i].file_info.handle != PP_kInvalidFileHandle)
36 if (ld_file_info_.handle != PP_kInvalidFileHandle) 40 CloseFileHandle(resources_[i].file_info.handle);
37 CloseFileHandle(ld_file_info_.handle); 41 }
42 }
43
44 const std::string& PnaclResources::GetUrl(ResourceType type) const {
45 size_t index = static_cast<size_t>(type);
Derek Schuff 2015/03/30 16:39:47 would making ResourceType an enum class avoid the
jvoung (off chromium) 2015/03/30 20:26:40 Doesn't seem to help: http://stackoverflow.com/qu
Derek Schuff 2015/03/30 21:03:12 yeah it's declared in <type_traits>. oh well.
46 if (index < kNumTypes) {
47 return resources_[index].tool_name;
48 }
49 DCHECK(false && "Index out of bounds");
Derek Schuff 2015/03/30 16:39:47 it looks like chrome style is DCHECK(condition) <<
jvoung (off chromium) 2015/03/30 20:26:40 =( Unfortunately this is the NaCl DCHECK macro. I
Derek Schuff 2015/03/30 21:03:12 fun :/
50 // Return a dummy URL.
51 return resources_[kNumTypes].tool_name;
52 }
53
54 PP_NaClFileInfo PnaclResources::TakeFileInfo(ResourceType type) {
55 size_t index = static_cast<size_t>(type);
56 if (index >= kNumTypes) {
57 DCHECK(false && "Index out of bounds");
58 return kInvalidNaClFileInfo;
59 }
60 return resources_[index].file_info;
38 } 61 }
39 62
40 bool PnaclResources::ReadResourceInfo() { 63 bool PnaclResources::ReadResourceInfo() {
41 PP_Var pp_llc_tool_name_var; 64 PP_Var pp_llc_tool_name_var;
42 PP_Var pp_ld_tool_name_var; 65 PP_Var pp_ld_tool_name_var;
66 PP_Var pp_subzero_tool_name_var;
43 if (!plugin_->nacl_interface()->GetPnaclResourceInfo( 67 if (!plugin_->nacl_interface()->GetPnaclResourceInfo(
44 plugin_->pp_instance(), 68 plugin_->pp_instance(), &pp_llc_tool_name_var, &pp_ld_tool_name_var,
45 &pp_llc_tool_name_var, 69 &pp_subzero_tool_name_var)) {
46 &pp_ld_tool_name_var)) {
47 return false; 70 return false;
48 } 71 }
49 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var); 72 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var);
50 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var); 73 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var);
51 llc_tool_name_ = GetFullUrl(llc_tool_name.AsString()); 74 pp::Var subzero_tool_name(pp::PASS_REF, pp_subzero_tool_name_var);
52 ld_tool_name_ = GetFullUrl(ld_tool_name.AsString()); 75 resources_[kLLC].tool_name = GetFullUrl(llc_tool_name.AsString());
76 resources_[kLD].tool_name = GetFullUrl(ld_tool_name.AsString());
77 resources_[kSubzero].tool_name = GetFullUrl(subzero_tool_name.AsString());
53 return true; 78 return true;
54 } 79 }
55 80
56 PP_NaClFileInfo PnaclResources::TakeLlcFileInfo() {
57 PP_NaClFileInfo to_return = llc_file_info_;
58 llc_file_info_ = kInvalidNaClFileInfo;
59 return to_return;
60 }
61
62 PP_NaClFileInfo PnaclResources::TakeLdFileInfo() {
63 PP_NaClFileInfo to_return = ld_file_info_;
64 ld_file_info_ = kInvalidNaClFileInfo;
65 return to_return;
66 }
67 81
68 bool PnaclResources::StartLoad() { 82 bool PnaclResources::StartLoad() {
69 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); 83 PLUGIN_PRINTF(("PnaclResources::StartLoad\n"));
70 84
71 // Do a blocking load of each of the resources. 85 // Do a blocking load of each of the resources.
72 plugin_->nacl_interface()->GetReadExecPnaclFd(llc_tool_name_.c_str(), 86 std::vector<ResourceType> to_load;
73 &llc_file_info_); 87 if (use_subzero_) {
74 plugin_->nacl_interface()->GetReadExecPnaclFd(ld_tool_name_.c_str(), 88 to_load.push_back(kSubzero);
75 &ld_file_info_); 89 } else {
76 return (llc_file_info_.handle != PP_kInvalidFileHandle && 90 to_load.push_back(kLLC);
77 ld_file_info_.handle != PP_kInvalidFileHandle); 91 }
92 to_load.push_back(kLD);
93 bool all_valid = true;
94 for (ResourceType t : to_load) {
95 plugin_->nacl_interface()->GetReadExecPnaclFd(
96 resources_[t].tool_name.c_str(), &resources_[t].file_info);
97 all_valid =
98 all_valid && resources_[t].file_info.handle != PP_kInvalidFileHandle;
99 }
100 return all_valid;
78 } 101 }
79 102
80 } // namespace plugin 103 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698