Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "class_linker.h" |
| 10 | #include "class_loader.h" |
| 11 | #include "compiler.h" |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 12 | #include "file.h" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 13 | #include "image_writer.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 14 | #include "oat_writer.h" |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 15 | #include "os.h" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 16 | #include "runtime.h" |
| 17 | #include "stringpiece.h" |
| 18 | |
| 19 | namespace art { |
| 20 | |
| 21 | static void usage() { |
| 22 | fprintf(stderr, |
| 23 | "Usage: dex2oat [options]...\n" |
| 24 | "\n"); |
| 25 | fprintf(stderr, |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 26 | " --dex-file=<dex-file>: specifies a .dex file to compile. At least one .dex\n" |
| 27 | " file must be specified. \n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 28 | " Example: --dex-file=/system/framework/core.jar\n" |
| 29 | "\n"); |
| 30 | fprintf(stderr, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 31 | " --image=<file.art>: specifies the required output image filename.\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 32 | " Example: --image=/data/art-cache/boot.art\n" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 33 | "\n"); |
| 34 | // TODO: remove this by inferring from --image |
| 35 | fprintf(stderr, |
| 36 | " --oat=<file.oat>: specifies the required oat filename.\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 37 | " Example: --image=/data/art-cache/boot.oat\n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 38 | "\n"); |
| 39 | fprintf(stderr, |
| 40 | " --base=<hex-address>: specifies the base address when creating a boot image.\n" |
| 41 | " Example: --base=0x50000000\n" |
| 42 | "\n"); |
| 43 | fprintf(stderr, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 44 | " --boot-image=<file.art>: provide the image file for the boot class path.\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 45 | " Example: --boot-image=/data/art-cache/boot.art\n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 46 | "\n"); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 47 | fprintf(stderr, |
| 48 | " --method may be used to limit compilation to a subset of methods.\n" |
| 49 | " Example: --method=Ljava/lang/Object;<init>()V\n" |
| 50 | "\n"); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 51 | fprintf(stderr, |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 52 | " --host-prefix may be used to translate host paths to target paths during\n" |
| 53 | " cross compilation.\n" |
| 54 | " Example: --host-prefix=out/target/product/crespo\n" |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 55 | "\n"); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 56 | fprintf(stderr, |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 57 | " --runtime-arg <argument>: used to specify various arguments for the runtime,\n" |
| 58 | " such as initial heap size, maximum heap size, and verbose output.\n" |
| 59 | " Use a separate --runtime-arg switch for each argument.\n" |
| 60 | " Example: --runtime-arg -Xms256m\n" |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 61 | "\n"); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 62 | exit(EXIT_FAILURE); |
| 63 | } |
| 64 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 65 | int dex2oat(int argc, char** argv) { |
| 66 | // Skip over argv[0]. |
| 67 | argv++; |
| 68 | argc--; |
| 69 | |
| 70 | if (argc == 0) { |
| 71 | fprintf(stderr, "no arguments specified\n"); |
| 72 | usage(); |
| 73 | } |
| 74 | |
| 75 | std::vector<const char*> dex_filenames; |
| 76 | std::vector<const char*> method_names; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 77 | std::string oat_filename; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 78 | const char* image_filename = NULL; |
| 79 | std::string boot_image_option; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 80 | uintptr_t image_base = 0; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 81 | std::string host_prefix; |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 82 | std::vector<const char*> runtime_args; |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 83 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 84 | for (int i = 0; i < argc; i++) { |
| 85 | const StringPiece option(argv[i]); |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 86 | if (false) { |
| 87 | LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i]; |
| 88 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 89 | if (option.starts_with("--dex-file=")) { |
| 90 | dex_filenames.push_back(option.substr(strlen("--dex-file=")).data()); |
| 91 | } else if (option.starts_with("--method=")) { |
| 92 | method_names.push_back(option.substr(strlen("--method=")).data()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 93 | } else if (option.starts_with("--oat=")) { |
| 94 | oat_filename = option.substr(strlen("--oat=")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 95 | } else if (option.starts_with("--image=")) { |
| 96 | image_filename = option.substr(strlen("--image=")).data(); |
| 97 | } else if (option.starts_with("--base=")) { |
| 98 | const char* image_base_str = option.substr(strlen("--base=")).data(); |
| 99 | char* end; |
| 100 | image_base = strtoul(image_base_str, &end, 16); |
| 101 | if (end == image_base_str || *end != '\0') { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 102 | fprintf(stderr, "Failed to parse hexadecimal value for option %s\n", option.data()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 103 | usage(); |
| 104 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 105 | } else if (option.starts_with("--boot-image=")) { |
| 106 | const char* boot_image_filename = option.substr(strlen("--boot-image=")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 107 | boot_image_option.clear(); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 108 | boot_image_option += "-Ximage:"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 109 | boot_image_option += boot_image_filename; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 110 | } else if (option.starts_with("--host-prefix=")) { |
| 111 | host_prefix = option.substr(strlen("--host-prefix=")).data(); |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 112 | } else if (option == "--runtime-arg") { |
| 113 | if (++i >= argc) { |
| 114 | fprintf(stderr, "Missing required argument for --runtime-arg\n"); |
| 115 | usage(); |
| 116 | } |
| 117 | runtime_args.push_back(argv[i]); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 118 | } else { |
| 119 | fprintf(stderr, "unknown argument %s\n", option.data()); |
| 120 | usage(); |
| 121 | } |
| 122 | } |
| 123 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 124 | if (oat_filename == NULL) { |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 125 | fprintf(stderr, "--oat file name not specified\n"); |
| 126 | return EXIT_FAILURE; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 129 | if (image_filename == NULL && boot_image_option.empty()) { |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 130 | fprintf(stderr, "Either --image or --boot-image must be specified\n"); |
| 131 | return EXIT_FAILURE; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 134 | if (dex_filenames.empty()) { |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 135 | fprintf(stderr, "no --dex-file values specified\n"); |
| 136 | return EXIT_FAILURE; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 139 | if (boot_image_option.empty()) { |
| 140 | if (image_base == 0) { |
| 141 | fprintf(stderr, "non-zero --base not specified\n"); |
| 142 | return EXIT_FAILURE; |
| 143 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 146 | // Check early that the result of compilation can be written |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 147 | // TODO: implement a proper locking scheme here, probably hold onto the open file.. |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 148 | if (OS::FileExists(oat_filename.c_str())) { |
| 149 | // File exists, check we can write to it |
| 150 | UniquePtr<File> file(OS::OpenFile(oat_filename.c_str(), true)); |
| 151 | if (file.get() == NULL) { |
| 152 | PLOG(ERROR) << "Unable to create oat file " << oat_filename; |
| 153 | return EXIT_FAILURE; |
| 154 | } |
| 155 | } |
| 156 | LOG(INFO) << "dex2oat: " << oat_filename; |
| 157 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 158 | Runtime::Options options; |
Brian Carlstrom | 5de8fe5 | 2011-10-16 14:10:09 -0700 | [diff] [blame] | 159 | options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL))); |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 160 | std::string boot_class_path_string; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 161 | if (boot_image_option.empty()) { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 162 | boot_class_path_string += "-Xbootclasspath:"; |
| 163 | for (size_t i = 0; i < dex_filenames.size()-1; i++) { |
| 164 | boot_class_path_string += dex_filenames[i]; |
| 165 | boot_class_path_string += ":"; |
| 166 | } |
| 167 | boot_class_path_string += dex_filenames[dex_filenames.size()-1]; |
| 168 | options.push_back(std::make_pair(boot_class_path_string.c_str(), reinterpret_cast<void*>(NULL))); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 169 | } else { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 170 | options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL))); |
| 171 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 172 | if (!host_prefix.empty()) { |
| 173 | options.push_back(std::make_pair("host-prefix", host_prefix.c_str())); |
| 174 | } |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 175 | for (size_t i = 0; i < runtime_args.size(); i++) { |
| 176 | options.push_back(std::make_pair(runtime_args[i], reinterpret_cast<void*>(NULL))); |
| 177 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 178 | UniquePtr<Runtime> runtime(Runtime::Create(options, false)); |
| 179 | if (runtime.get() == NULL) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 180 | LOG(ERROR) << "Could not create runtime"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 181 | return EXIT_FAILURE; |
| 182 | } |
| 183 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 184 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 185 | // If we have an existing boot image, position new space after its oat file |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 186 | if (Heap::GetSpaces().size() > 1) { |
| 187 | Space* last_image_space = Heap::GetSpaces()[Heap::GetSpaces().size()-2]; |
| 188 | CHECK(last_image_space != NULL); |
| 189 | CHECK(last_image_space->IsImageSpace()); |
| 190 | CHECK(!Heap::GetSpaces()[Heap::GetSpaces().size()-1]->IsImageSpace()); |
| 191 | byte* oat_limit_addr = last_image_space->GetImageHeader().GetOatLimitAddr(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 192 | image_base = RoundUp(reinterpret_cast<uintptr_t>(oat_limit_addr), kPageSize); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // ClassLoader creation needs to come after Runtime::Create |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 196 | SirtRef<ClassLoader> class_loader(NULL); |
| 197 | if (!boot_image_option.empty()) { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 198 | std::vector<const DexFile*> dex_files; |
| 199 | DexFile::OpenDexFiles(dex_filenames, dex_files, host_prefix); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 200 | for (size_t i = 0; i < dex_files.size(); i++) { |
| 201 | class_linker->RegisterDexFile(*dex_files[i]); |
| 202 | } |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 203 | class_loader.reset(PathClassLoader::AllocCompileTime(dex_files)); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 206 | // if we loaded an existing image, we will reuse values from the image roots. |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 207 | if (!runtime->HasJniStubArray()) { |
| 208 | runtime->SetJniStubArray(JniCompiler::CreateJniStub(kThumb2)); |
| 209 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 210 | if (!runtime->HasAbstractMethodErrorStubArray()) { |
| 211 | runtime->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(kThumb2)); |
| 212 | } |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 213 | for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) { |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 214 | Runtime::TrampolineType type = Runtime::TrampolineType(i); |
| 215 | if (!runtime->HasResolutionStubArray(type)) { |
| 216 | runtime->SetResolutionStubArray(Compiler::CreateResolutionStub(kThumb2, type), type); |
| 217 | } |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 218 | } |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 219 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 220 | Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); |
| 221 | if (!runtime->HasCalleeSaveMethod(type)) { |
| 222 | runtime->SetCalleeSaveMethod(runtime->CreateCalleeSaveMethod(kThumb2, type), type); |
| 223 | } |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 224 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 225 | Compiler compiler(kThumb2, image_filename != NULL); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 226 | if (method_names.empty()) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 227 | compiler.CompileAll(class_loader.get()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 228 | } else { |
| 229 | for (size_t i = 0; i < method_names.size(); i++) { |
| 230 | // names are actually class_descriptor + name + signature. |
| 231 | // example: Ljava/lang/Object;<init>()V |
| 232 | StringPiece method_name = method_names[i]; |
| 233 | size_t end_of_class_descriptor = method_name.find(';'); |
| 234 | if (end_of_class_descriptor == method_name.npos) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 235 | LOG(ERROR) << "Could not find class descriptor in method " << method_name << "'"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 236 | return EXIT_FAILURE; |
| 237 | } |
| 238 | end_of_class_descriptor++; // want to include ; |
| 239 | std::string class_descriptor = method_name.substr(0, end_of_class_descriptor).ToString(); |
| 240 | size_t end_of_name = method_name.find('(', end_of_class_descriptor); |
| 241 | if (end_of_name == method_name.npos) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 242 | LOG(ERROR) << "Could not find start of method signature in method '" << method_name << "'"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 243 | return EXIT_FAILURE; |
| 244 | } |
| 245 | std::string name = method_name.substr(end_of_class_descriptor, |
| 246 | end_of_name - end_of_class_descriptor).ToString(); |
| 247 | std::string signature = method_name.substr(end_of_name).ToString(); |
| 248 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 249 | Class* klass = class_linker->FindClass(class_descriptor, class_loader.get()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 250 | if (klass == NULL) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 251 | LOG(ERROR) << "Could not find class for descriptor '" << class_descriptor |
| 252 | << "' in method '" << method_name << "'"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 253 | return EXIT_FAILURE; |
| 254 | } |
| 255 | Method* method = klass->FindDirectMethod(name, signature); |
| 256 | if (method == NULL) { |
| 257 | method = klass->FindVirtualMethod(name, signature); |
| 258 | } |
| 259 | if (method == NULL) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 260 | LOG(ERROR) << "Could not find method '" << method_name << "' with signature '" |
| 261 | << signature << "' in class '" << class_descriptor << "' for method argument '" |
| 262 | << method_name << "'"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 263 | return EXIT_FAILURE; |
| 264 | } |
| 265 | compiler.CompileOne(method); |
| 266 | } |
| 267 | } |
| 268 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 269 | if (!OatWriter::Create(oat_filename, class_loader.get(), compiler)) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 270 | LOG(ERROR) << "Failed to create oat file " << oat_filename; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 271 | return EXIT_FAILURE; |
| 272 | } |
| 273 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 274 | if (image_filename == NULL) { |
| 275 | return EXIT_SUCCESS; |
| 276 | } |
| 277 | CHECK(compiler.IsImage()); |
| 278 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 279 | ImageWriter image_writer; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 280 | if (!image_writer.Write(image_filename, image_base, oat_filename, host_prefix)) { |
Ian Rogers | 3fe7957 | 2011-11-02 18:24:30 -0700 | [diff] [blame] | 281 | LOG(ERROR) << "Failed to create image file " << image_filename; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 282 | return EXIT_FAILURE; |
| 283 | } |
| 284 | |
| 285 | return EXIT_SUCCESS; |
| 286 | } |
| 287 | |
| 288 | } // namespace art |
| 289 | |
| 290 | int main(int argc, char** argv) { |
| 291 | return art::dex2oat(argc, argv); |
| 292 | } |