blob: 231ca9c405bdce68cb33273f1d878df1208da81c [file] [log] [blame]
Brian Carlstrom69b15fb2011-09-03 12:25:21 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include <stdio.h>
4#include <stdlib.h>
Elliott Hughes234da572011-11-03 22:13:06 -07005#include <sys/file.h>
Brian Carlstrom69b15fb2011-09-03 12:25:21 -07006
7#include <string>
8#include <vector>
9
10#include "class_linker.h"
11#include "class_loader.h"
12#include "compiler.h"
Ian Rogers5e863dd2011-11-02 20:00:10 -070013#include "file.h"
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070014#include "image_writer.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070015#include "oat_writer.h"
Ian Rogers5e863dd2011-11-02 20:00:10 -070016#include "os.h"
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070017#include "runtime.h"
18#include "stringpiece.h"
19
20namespace art {
21
22static void usage() {
23 fprintf(stderr,
24 "Usage: dex2oat [options]...\n"
25 "\n");
26 fprintf(stderr,
Brian Carlstrom78128a62011-09-15 17:21:19 -070027 " --dex-file=<dex-file>: specifies a .dex file to compile. At least one .dex\n"
28 " file must be specified. \n"
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070029 " Example: --dex-file=/system/framework/core.jar\n"
30 "\n");
31 fprintf(stderr,
Brian Carlstrome24fa612011-09-29 00:53:55 -070032 " --image=<file.art>: specifies the required output image filename.\n"
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -070033 " Example: --image=/data/art-cache/boot.art\n"
Brian Carlstrome24fa612011-09-29 00:53:55 -070034 "\n");
35 // TODO: remove this by inferring from --image
36 fprintf(stderr,
37 " --oat=<file.oat>: specifies the required oat filename.\n"
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -070038 " Example: --image=/data/art-cache/boot.oat\n"
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070039 "\n");
40 fprintf(stderr,
41 " --base=<hex-address>: specifies the base address when creating a boot image.\n"
42 " Example: --base=0x50000000\n"
43 "\n");
44 fprintf(stderr,
Brian Carlstrome24fa612011-09-29 00:53:55 -070045 " --boot-image=<file.art>: provide the image file for the boot class path.\n"
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -070046 " Example: --boot-image=/data/art-cache/boot.art\n"
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070047 "\n");
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070048 fprintf(stderr,
49 " --method may be used to limit compilation to a subset of methods.\n"
50 " Example: --method=Ljava/lang/Object;<init>()V\n"
51 "\n");
Brian Carlstrom16192862011-09-12 17:50:06 -070052 fprintf(stderr,
Brian Carlstrom58ae9412011-10-04 00:56:06 -070053 " --host-prefix may be used to translate host paths to target paths during\n"
54 " cross compilation.\n"
55 " Example: --host-prefix=out/target/product/crespo\n"
Brian Carlstrom16192862011-09-12 17:50:06 -070056 "\n");
Brian Carlstrom27ec9612011-09-19 20:20:38 -070057 fprintf(stderr,
jeffhao5d840402011-10-24 17:09:45 -070058 " --runtime-arg <argument>: used to specify various arguments for the runtime,\n"
59 " such as initial heap size, maximum heap size, and verbose output.\n"
60 " Use a separate --runtime-arg switch for each argument.\n"
61 " Example: --runtime-arg -Xms256m\n"
Brian Carlstrom27ec9612011-09-19 20:20:38 -070062 "\n");
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070063 exit(EXIT_FAILURE);
64}
65
Elliott Hughes234da572011-11-03 22:13:06 -070066class FileJanitor {
67public:
68 FileJanitor(const std::string& filename, int fd)
69 : filename_(filename), fd_(fd), do_unlink_(true) {
70 }
71
72 void KeepFile() {
73 do_unlink_ = false;
74 }
75
76 ~FileJanitor() {
77 if (fd_ != -1) {
Elliott Hughesb1f9f222011-11-04 18:04:00 -070078 int rc = TEMP_FAILURE_RETRY(flock(fd_, LOCK_UN));
79 if (rc == -1) {
80 PLOG(ERROR) << "Failed to unlock " << filename_;
81 }
Elliott Hughes234da572011-11-03 22:13:06 -070082 }
83 if (do_unlink_) {
Elliott Hughesb1f9f222011-11-04 18:04:00 -070084 int rc = TEMP_FAILURE_RETRY(unlink(filename_.c_str()));
85 if (rc == -1) {
86 PLOG(ERROR) << "Failed to unlink " << filename_;
87 }
Elliott Hughes234da572011-11-03 22:13:06 -070088 }
89 }
90
91private:
92 std::string filename_;
93 int fd_;
94 bool do_unlink_;
95};
96
Jesse Wilson254db0f2011-11-16 16:44:11 -050097// Returns true if dex_files has a dex with the named location.
98bool DexFilesContains(const std::vector<const DexFile*>& dex_files, const std::string& location) {
99 for (size_t i = 0; i < dex_files.size(); ++i) {
100 if (dex_files[i]->GetLocation() == location) {
101 return true;
102 }
103 }
104 return false;
105}
106
107// Appends to dex_files any elements of class_path that it doesn't already
108// contain. This will open those dex files as necessary.
109void OpenClassPathFiles(const std::string& class_path, std::vector<const DexFile*>& dex_files) {
110 std::vector<std::string> parsed;
111 Split(class_path, ':', parsed);
112 for (size_t i = 0; i < parsed.size(); ++i) {
113 if (DexFilesContains(dex_files, parsed[i])) {
114 continue;
115 }
116 const DexFile* dex_file = DexFile::Open(parsed[i], Runtime::Current()->GetHostPrefix());
117 if (dex_file == NULL) {
118 LOG(WARNING) << "Failed to open dex file " << parsed[i];
119 } else {
120 dex_files.push_back(dex_file);
121 }
122 }
123}
124
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700125int dex2oat(int argc, char** argv) {
126 // Skip over argv[0].
127 argv++;
128 argc--;
129
130 if (argc == 0) {
131 fprintf(stderr, "no arguments specified\n");
132 usage();
133 }
134
135 std::vector<const char*> dex_filenames;
136 std::vector<const char*> method_names;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700137 std::string oat_filename;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700138 const char* image_filename = NULL;
139 std::string boot_image_option;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700140 uintptr_t image_base = 0;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700141 std::string host_prefix;
jeffhao5d840402011-10-24 17:09:45 -0700142 std::vector<const char*> runtime_args;
Brian Carlstrom16192862011-09-12 17:50:06 -0700143
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700144 for (int i = 0; i < argc; i++) {
145 const StringPiece option(argv[i]);
Brian Carlstromb7bbba42011-10-13 14:58:47 -0700146 if (false) {
147 LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i];
148 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700149 if (option.starts_with("--dex-file=")) {
150 dex_filenames.push_back(option.substr(strlen("--dex-file=")).data());
151 } else if (option.starts_with("--method=")) {
152 method_names.push_back(option.substr(strlen("--method=")).data());
Brian Carlstrome24fa612011-09-29 00:53:55 -0700153 } else if (option.starts_with("--oat=")) {
154 oat_filename = option.substr(strlen("--oat=")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700155 } else if (option.starts_with("--image=")) {
156 image_filename = option.substr(strlen("--image=")).data();
157 } else if (option.starts_with("--base=")) {
158 const char* image_base_str = option.substr(strlen("--base=")).data();
159 char* end;
160 image_base = strtoul(image_base_str, &end, 16);
161 if (end == image_base_str || *end != '\0') {
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700162 fprintf(stderr, "Failed to parse hexadecimal value for option %s\n", option.data());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700163 usage();
164 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700165 } else if (option.starts_with("--boot-image=")) {
166 const char* boot_image_filename = option.substr(strlen("--boot-image=")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700167 boot_image_option.clear();
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700168 boot_image_option += "-Ximage:";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700169 boot_image_option += boot_image_filename;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700170 } else if (option.starts_with("--host-prefix=")) {
171 host_prefix = option.substr(strlen("--host-prefix=")).data();
jeffhao5d840402011-10-24 17:09:45 -0700172 } else if (option == "--runtime-arg") {
173 if (++i >= argc) {
174 fprintf(stderr, "Missing required argument for --runtime-arg\n");
175 usage();
176 }
177 runtime_args.push_back(argv[i]);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700178 } else {
179 fprintf(stderr, "unknown argument %s\n", option.data());
180 usage();
181 }
182 }
183
Brian Carlstrome24fa612011-09-29 00:53:55 -0700184 if (oat_filename == NULL) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700185 fprintf(stderr, "--oat file name not specified\n");
186 return EXIT_FAILURE;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700187 }
188
Brian Carlstromaded5f72011-10-07 17:15:04 -0700189 if (image_filename == NULL && boot_image_option.empty()) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700190 fprintf(stderr, "Either --image or --boot-image must be specified\n");
191 return EXIT_FAILURE;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700192 }
193
Brian Carlstrom78128a62011-09-15 17:21:19 -0700194 if (dex_filenames.empty()) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700195 fprintf(stderr, "no --dex-file values specified\n");
196 return EXIT_FAILURE;
Brian Carlstrom78128a62011-09-15 17:21:19 -0700197 }
198
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700199 if (boot_image_option.empty()) {
200 if (image_base == 0) {
201 fprintf(stderr, "non-zero --base not specified\n");
202 return EXIT_FAILURE;
203 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700204 }
205
Elliott Hughes234da572011-11-03 22:13:06 -0700206 // Create the output file if we can, or open it read-only if we weren't first.
207 bool did_create = true;
208 int fd = open(oat_filename.c_str(), O_EXCL | O_CREAT | O_TRUNC | O_RDWR, 0666);
209 if (fd == -1) {
210 if (errno != EEXIST) {
Ian Rogers5e863dd2011-11-02 20:00:10 -0700211 PLOG(ERROR) << "Unable to create oat file " << oat_filename;
212 return EXIT_FAILURE;
213 }
Elliott Hughes234da572011-11-03 22:13:06 -0700214 did_create = false;
215 fd = open(oat_filename.c_str(), O_RDONLY);
216 if (fd == -1) {
217 PLOG(ERROR) << "Unable to open oat file for reading " << oat_filename;
218 return EXIT_FAILURE;
219 }
Ian Rogers5e863dd2011-11-02 20:00:10 -0700220 }
Elliott Hughes234da572011-11-03 22:13:06 -0700221
222 // Handles removing the file on failure and unlocking on both failure and success.
223 FileJanitor file_janitor(oat_filename, fd);
224
Elliott Hughes234da572011-11-03 22:13:06 -0700225 // If we won the creation race, block trying to take the lock (since we're going to be doing
226 // the work, we need the lock). If we lost the creation race, spin trying to take the lock
227 // non-blocking until we fail -- at which point we know the other guy has the lock -- and then
228 // block trying to take the now-taken lock.
229 if (did_create) {
230 LOG(INFO) << "This process created " << oat_filename;
Elliott Hughesb1f9f222011-11-04 18:04:00 -0700231 while (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX)) != 0) {
Elliott Hughes234da572011-11-03 22:13:06 -0700232 // Try again.
233 }
234 LOG(INFO) << "This process created and locked " << oat_filename;
235 } else {
236 LOG(INFO) << "Another process has already created " << oat_filename;
Elliott Hughesb1f9f222011-11-04 18:04:00 -0700237 while (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX | LOCK_NB)) == 0) {
Elliott Hughes234da572011-11-03 22:13:06 -0700238 // Give up the lock and hope the creator has taken the lock next time round.
Elliott Hughesb1f9f222011-11-04 18:04:00 -0700239 int rc = TEMP_FAILURE_RETRY(flock(fd, LOCK_UN));
240 if (rc == -1) {
241 PLOG(FATAL) << "Failed to unlock " << oat_filename;
242 }
Elliott Hughes234da572011-11-03 22:13:06 -0700243 }
244 // Now a non-blocking attempt to take the lock has failed, we know the other guy has the
245 // lock, so block waiting to take it.
246 LOG(INFO) << "Another process is already working on " << oat_filename;
Elliott Hughesb1f9f222011-11-04 18:04:00 -0700247 if (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX)) != 0) {
Elliott Hughes234da572011-11-03 22:13:06 -0700248 PLOG(ERROR) << "Waiter unable to wait for creator to finish " << oat_filename;
249 return EXIT_FAILURE;
250 }
251 // We have the lock and the creator has finished.
252 // TODO: check the creator did a good job by checking the header.
253 LOG(INFO) << "Another process finished working on " << oat_filename;
254 // Job done.
255 file_janitor.KeepFile();
256 return EXIT_SUCCESS;
257 }
258
259 // If we get this far, we won the creation race and have locked the file.
260 UniquePtr<File> oat_file(OS::FileFromFd(oat_filename.c_str(), fd));
261
262 LOG(INFO) << "dex2oat: " << oat_file->name();
Ian Rogers5e863dd2011-11-02 20:00:10 -0700263
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700264 Runtime::Options options;
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700265 options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL)));
Brian Carlstromb7bbba42011-10-13 14:58:47 -0700266 std::string boot_class_path_string;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700267 if (boot_image_option.empty()) {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700268 boot_class_path_string += "-Xbootclasspath:";
269 for (size_t i = 0; i < dex_filenames.size()-1; i++) {
270 boot_class_path_string += dex_filenames[i];
271 boot_class_path_string += ":";
272 }
273 boot_class_path_string += dex_filenames[dex_filenames.size()-1];
274 options.push_back(std::make_pair(boot_class_path_string.c_str(), reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700275 } else {
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700276 options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL)));
277 }
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700278 if (!host_prefix.empty()) {
279 options.push_back(std::make_pair("host-prefix", host_prefix.c_str()));
280 }
jeffhao5d840402011-10-24 17:09:45 -0700281 for (size_t i = 0; i < runtime_args.size(); i++) {
282 options.push_back(std::make_pair(runtime_args[i], reinterpret_cast<void*>(NULL)));
283 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700284 UniquePtr<Runtime> runtime(Runtime::Create(options, false));
285 if (runtime.get() == NULL) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700286 LOG(ERROR) << "Could not create runtime";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700287 return EXIT_FAILURE;
288 }
289 ClassLinker* class_linker = runtime->GetClassLinker();
290
Brian Carlstrome24fa612011-09-29 00:53:55 -0700291 // If we have an existing boot image, position new space after its oat file
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700292 if (Heap::GetSpaces().size() > 1) {
293 Space* last_image_space = Heap::GetSpaces()[Heap::GetSpaces().size()-2];
294 CHECK(last_image_space != NULL);
295 CHECK(last_image_space->IsImageSpace());
296 CHECK(!Heap::GetSpaces()[Heap::GetSpaces().size()-1]->IsImageSpace());
297 byte* oat_limit_addr = last_image_space->GetImageHeader().GetOatLimitAddr();
Brian Carlstrome24fa612011-09-29 00:53:55 -0700298 image_base = RoundUp(reinterpret_cast<uintptr_t>(oat_limit_addr), kPageSize);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700299 }
300
301 // ClassLoader creation needs to come after Runtime::Create
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700302 SirtRef<ClassLoader> class_loader(NULL);
Jesse Wilson254db0f2011-11-16 16:44:11 -0500303 std::vector<const DexFile*> dex_files;
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700304 if (!boot_image_option.empty()) {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700305 DexFile::OpenDexFiles(dex_filenames, dex_files, host_prefix);
Jesse Wilson254db0f2011-11-16 16:44:11 -0500306 std::vector<const DexFile*> class_path_files(dex_files);
307 OpenClassPathFiles(runtime->GetClassPath(), class_path_files);
308 for (size_t i = 0; i < class_path_files.size(); i++) {
309 class_linker->RegisterDexFile(*class_path_files[i]);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700310 }
Jesse Wilson254db0f2011-11-16 16:44:11 -0500311 class_loader.reset(PathClassLoader::AllocCompileTime(class_path_files));
312 } else {
313 dex_files = runtime->GetClassLinker()->GetBootClassPath();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700314 }
315
Brian Carlstrome24fa612011-09-29 00:53:55 -0700316 // if we loaded an existing image, we will reuse values from the image roots.
Ian Rogers169c9a72011-11-13 20:13:17 -0800317 if (!runtime->HasJniDlsymLookupStub()) {
318 runtime->SetJniDlsymLookupStub(Compiler::CreateJniDlysmLookupStub(kThumb2));
Brian Carlstrom16192862011-09-12 17:50:06 -0700319 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700320 if (!runtime->HasAbstractMethodErrorStubArray()) {
321 runtime->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(kThumb2));
322 }
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700323 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700324 Runtime::TrampolineType type = Runtime::TrampolineType(i);
325 if (!runtime->HasResolutionStubArray(type)) {
326 runtime->SetResolutionStubArray(Compiler::CreateResolutionStub(kThumb2, type), type);
327 }
Ian Rogersad25ac52011-10-04 19:13:33 -0700328 }
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700329 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
330 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i);
331 if (!runtime->HasCalleeSaveMethod(type)) {
332 runtime->SetCalleeSaveMethod(runtime->CreateCalleeSaveMethod(kThumb2, type), type);
333 }
Ian Rogersff1ed472011-09-20 13:46:24 -0700334 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700335 Compiler compiler(kThumb2, image_filename != NULL);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700336 if (method_names.empty()) {
Jesse Wilson254db0f2011-11-16 16:44:11 -0500337 compiler.CompileAll(class_loader.get(), dex_files);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700338 } else {
339 for (size_t i = 0; i < method_names.size(); i++) {
340 // names are actually class_descriptor + name + signature.
341 // example: Ljava/lang/Object;<init>()V
342 StringPiece method_name = method_names[i];
343 size_t end_of_class_descriptor = method_name.find(';');
344 if (end_of_class_descriptor == method_name.npos) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700345 LOG(ERROR) << "Could not find class descriptor in method " << method_name << "'";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700346 return EXIT_FAILURE;
347 }
348 end_of_class_descriptor++; // want to include ;
349 std::string class_descriptor = method_name.substr(0, end_of_class_descriptor).ToString();
350 size_t end_of_name = method_name.find('(', end_of_class_descriptor);
351 if (end_of_name == method_name.npos) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700352 LOG(ERROR) << "Could not find start of method signature in method '" << method_name << "'";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700353 return EXIT_FAILURE;
354 }
355 std::string name = method_name.substr(end_of_class_descriptor,
356 end_of_name - end_of_class_descriptor).ToString();
357 std::string signature = method_name.substr(end_of_name).ToString();
358
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700359 Class* klass = class_linker->FindClass(class_descriptor, class_loader.get());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700360 if (klass == NULL) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700361 LOG(ERROR) << "Could not find class for descriptor '" << class_descriptor
362 << "' in method '" << method_name << "'";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700363 return EXIT_FAILURE;
364 }
365 Method* method = klass->FindDirectMethod(name, signature);
366 if (method == NULL) {
367 method = klass->FindVirtualMethod(name, signature);
368 }
369 if (method == NULL) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700370 LOG(ERROR) << "Could not find method '" << method_name << "' with signature '"
371 << signature << "' in class '" << class_descriptor << "' for method argument '"
372 << method_name << "'";
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700373 return EXIT_FAILURE;
374 }
375 compiler.CompileOne(method);
376 }
377 }
378
Elliott Hughes234da572011-11-03 22:13:06 -0700379 if (!OatWriter::Create(oat_file.get(), class_loader.get(), compiler)) {
380 LOG(ERROR) << "Failed to create oat file " << oat_file->name();
Brian Carlstrome24fa612011-09-29 00:53:55 -0700381 return EXIT_FAILURE;
382 }
383
Brian Carlstromaded5f72011-10-07 17:15:04 -0700384 if (image_filename == NULL) {
Ian Rogers97170512011-11-06 21:06:20 -0800385 file_janitor.KeepFile();
386 LOG(INFO) << "Oat file written successfully " << oat_file->name();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700387 return EXIT_SUCCESS;
388 }
389 CHECK(compiler.IsImage());
390
Brian Carlstrome24fa612011-09-29 00:53:55 -0700391 ImageWriter image_writer;
Elliott Hughes234da572011-11-03 22:13:06 -0700392 if (!image_writer.Write(image_filename, image_base, oat_file->name(), host_prefix)) {
Ian Rogers3fe79572011-11-02 18:24:30 -0700393 LOG(ERROR) << "Failed to create image file " << image_filename;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700394 return EXIT_FAILURE;
395 }
396
Elliott Hughes234da572011-11-03 22:13:06 -0700397 // We wrote the file successfully, and want to keep it.
398 LOG(INFO) << "Image written successfully " << image_filename;
399 file_janitor.KeepFile();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700400 return EXIT_SUCCESS;
401}
402
403} // namespace art
404
405int main(int argc, char** argv) {
406 return art::dex2oat(argc, argv);
407}