Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 20 | #include <iostream> |
| 21 | #include <fstream> |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "class_linker.h" |
| 26 | #include "class_loader.h" |
| 27 | #include "compiler.h" |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 28 | #include "file.h" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 29 | #include "image_writer.h" |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 30 | #include "leb128.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 31 | #include "oat_writer.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 32 | #include "object_utils.h" |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 33 | #include "os.h" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 34 | #include "runtime.h" |
| 35 | #include "stringpiece.h" |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 36 | #include "timing_logger.h" |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 37 | #include "zip_archive.h" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
| 41 | static void usage() { |
| 42 | fprintf(stderr, |
| 43 | "Usage: dex2oat [options]...\n" |
| 44 | "\n"); |
| 45 | fprintf(stderr, |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 46 | " --dex-file=<dex-file>: specifies a .dex file to compile.\n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 47 | " Example: --dex-file=/system/framework/core.jar\n" |
| 48 | "\n"); |
| 49 | fprintf(stderr, |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 50 | " --zip-fd=<file-descriptor>: specifies a file descriptor of a zip file\n" |
| 51 | " containing a classes.dex file to compile.\n" |
| 52 | " Example: --zip-fd=5\n" |
| 53 | "\n"); |
| 54 | fprintf(stderr, |
| 55 | " --zip-name=<zip-name>: specifies a symbolic name for the file corresponding\n" |
| 56 | " to the file descriptor specified by --zip-fd.\n" |
| 57 | " Example: --zip-name=/system/app/Calculator.apk\n" |
| 58 | "\n"); |
| 59 | fprintf(stderr, |
| 60 | " --oat-file=<file.oat>: specifies the required oat filename.\n" |
| 61 | " Example: --oat-file=/system/framework/boot.oat\n" |
| 62 | "\n"); |
| 63 | fprintf(stderr, |
| 64 | " --oat-name=<oat-name>: specifies a symbolic name for the file corresponding\n" |
| 65 | " to the file descriptor specified by --oat-fd.\n" |
| 66 | " Example: --oat-name=/data/art-cache/system@app@Calculator.apk.oat\n" |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 67 | "\n"); |
| 68 | fprintf(stderr, |
| 69 | " --image=<file.art>: specifies the output image filename.\n" |
Brian Carlstrom | 29e7ac7 | 2011-12-05 23:42:57 -0800 | [diff] [blame] | 70 | " Example: --image=/system/framework/boot.art\n" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 71 | "\n"); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 72 | fprintf(stderr, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 73 | " --image-classes=<classname-file>: specifies classes to include in an image.\n" |
| 74 | " Example: --image=frameworks/base/preloaded-classes\n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 75 | "\n"); |
| 76 | fprintf(stderr, |
| 77 | " --base=<hex-address>: specifies the base address when creating a boot image.\n" |
| 78 | " Example: --base=0x50000000\n" |
| 79 | "\n"); |
| 80 | fprintf(stderr, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 81 | " --boot-image=<file.art>: provide the image file for the boot class path.\n" |
Brian Carlstrom | 29e7ac7 | 2011-12-05 23:42:57 -0800 | [diff] [blame] | 82 | " Example: --boot-image=/system/framework/boot.art\n" |
| 83 | " Default: <host-prefix>/system/framework/boot.art\n" |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 84 | "\n"); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 85 | fprintf(stderr, |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 86 | " --host-prefix may be used to translate host paths to target paths during\n" |
| 87 | " cross compilation.\n" |
| 88 | " Example: --host-prefix=out/target/product/crespo\n" |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 89 | " Default: $ANDROID_PRODUCT_OUT\n" |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 90 | "\n"); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 91 | fprintf(stderr, |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 92 | " --runtime-arg <argument>: used to specify various arguments for the runtime,\n" |
| 93 | " such as initial heap size, maximum heap size, and verbose output.\n" |
| 94 | " Use a separate --runtime-arg switch for each argument.\n" |
| 95 | " Example: --runtime-arg -Xms256m\n" |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 96 | "\n"); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 97 | exit(EXIT_FAILURE); |
| 98 | } |
| 99 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 100 | class Dex2Oat { |
| 101 | public: |
| 102 | |
| 103 | static Dex2Oat* Create(Runtime::Options& options) { |
| 104 | UniquePtr<Runtime> runtime(CreateRuntime(options)); |
| 105 | if (runtime.get() == NULL) { |
| 106 | return NULL; |
| 107 | } |
| 108 | return new Dex2Oat(runtime.release()); |
| 109 | } |
| 110 | |
| 111 | ~Dex2Oat() { |
| 112 | delete runtime_; |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 113 | LOG(INFO) << "dex2oat took " << PrettyDuration(NanoTime() - start_ns_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // Make a list of descriptors for classes to include in the image |
| 117 | const std::set<std::string>* GetImageClassDescriptors(const char* image_classes_filename) { |
| 118 | UniquePtr<std::ifstream> image_classes_file(new std::ifstream(image_classes_filename, std::ifstream::in)); |
| 119 | if (image_classes_file.get() == NULL) { |
| 120 | LOG(ERROR) << "Failed to open image classes file " << image_classes_filename; |
| 121 | return NULL; |
| 122 | } |
| 123 | |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 124 | // Load all the classes specified in the file |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 125 | ClassLinker* class_linker = runtime_->GetClassLinker(); |
| 126 | while (image_classes_file->good()) { |
| 127 | std::string dot; |
| 128 | std::getline(*image_classes_file.get(), dot); |
| 129 | if (StringPiece(dot).starts_with("#") || dot.empty()) { |
| 130 | continue; |
| 131 | } |
Elliott Hughes | 9557241 | 2011-12-13 18:14:20 -0800 | [diff] [blame] | 132 | std::string descriptor(DotToDescriptor(dot.c_str())); |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 133 | SirtRef<Class> klass(class_linker->FindSystemClass(descriptor.c_str())); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 134 | if (klass.get() == NULL) { |
| 135 | LOG(WARNING) << "Failed to find class " << descriptor; |
| 136 | Thread::Current()->ClearException(); |
| 137 | } |
| 138 | } |
| 139 | image_classes_file->close(); |
| 140 | |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 141 | // Resolve exception classes referenced by the loaded classes. The catch logic assumes |
| 142 | // exceptions are resolved by the verifier when there is a catch block in an interested method. |
| 143 | // Do this here so that exception classes appear to have been specified image classes. |
| 144 | std::set<std::pair<uint16_t, const DexFile*> > unresolved_exception_types; |
| 145 | do { |
| 146 | unresolved_exception_types.clear(); |
| 147 | class_linker->VisitClasses(ResolveCatchBlockExceptionsClassVisitor, |
| 148 | &unresolved_exception_types); |
| 149 | typedef std::set<std::pair<uint16_t, const DexFile*> >::const_iterator It; // TODO: C++0x auto |
| 150 | for (It it = unresolved_exception_types.begin(), |
| 151 | end = unresolved_exception_types.end(); |
| 152 | it != end; ++it) { |
| 153 | uint16_t exception_type_idx = it->first; |
| 154 | const DexFile* dex_file = it->second; |
| 155 | DexCache* dex_cache = class_linker->FindDexCache(*dex_file); |
| 156 | ClassLoader* class_loader = NULL; |
| 157 | SirtRef<Class> klass(class_linker->ResolveType(*dex_file, exception_type_idx, dex_cache, |
| 158 | class_loader)); |
| 159 | if (klass.get() == NULL) { |
| 160 | const DexFile::TypeId& type_id = dex_file->GetTypeId(exception_type_idx); |
| 161 | const char* descriptor = dex_file->GetTypeDescriptor(type_id); |
| 162 | LOG(FATAL) << "Failed to resolve class " << descriptor; |
| 163 | } |
| 164 | DCHECK(klass->IsThrowableClass()); |
| 165 | } |
| 166 | // Resolving exceptions may load classes that reference more exceptions, iterate until no |
| 167 | // more are found |
| 168 | } while (!unresolved_exception_types.empty()); |
| 169 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 170 | // We walk the roots looking for classes so that we'll pick up the |
| 171 | // above classes plus any classes them depend on such super |
| 172 | // classes, interfaces, and the required ClassLinker roots. |
| 173 | UniquePtr<std::set<std::string> > image_classes(new std::set<std::string>()); |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 174 | class_linker->VisitClasses(RecordImageClassesVisitor, image_classes.get()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 175 | CHECK_NE(image_classes->size(), 0U); |
| 176 | return image_classes.release(); |
| 177 | } |
| 178 | |
| 179 | bool CreateOatFile(const std::string& boot_image_option, |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 180 | const std::vector<const DexFile*>& dex_files, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 181 | File* oat_file, |
| 182 | bool image, |
| 183 | const std::set<std::string>* image_classes) { |
| 184 | // SirtRef and ClassLoader creation needs to come after Runtime::Create |
| 185 | UniquePtr<SirtRef<ClassLoader> > class_loader(new SirtRef<ClassLoader>(NULL)); |
| 186 | if (class_loader.get() == NULL) { |
| 187 | LOG(ERROR) << "Failed to create SirtRef for class loader"; |
| 188 | return false; |
| 189 | } |
| 190 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 191 | if (!boot_image_option.empty()) { |
| 192 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 193 | std::vector<const DexFile*> class_path_files(dex_files); |
| 194 | OpenClassPathFiles(runtime_->GetClassPath(), class_path_files); |
| 195 | for (size_t i = 0; i < class_path_files.size(); i++) { |
| 196 | class_linker->RegisterDexFile(*class_path_files[i]); |
| 197 | } |
| 198 | class_loader.get()->reset(PathClassLoader::AllocCompileTime(class_path_files)); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | Compiler compiler(instruction_set_, image, image_classes); |
| 202 | compiler.CompileAll(class_loader->get(), dex_files); |
| 203 | |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 204 | if (!OatWriter::Create(oat_file, class_loader->get(), dex_files, compiler)) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 205 | LOG(ERROR) << "Failed to create oat file " << oat_file->name(); |
| 206 | return false; |
| 207 | } |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | bool CreateImageFile(const char* image_filename, |
| 212 | uintptr_t image_base, |
| 213 | const std::set<std::string>* image_classes, |
| 214 | const std::string& oat_filename, |
| 215 | const std::string& host_prefix) { |
| 216 | // If we have an existing boot image, position new space after its oat file |
| 217 | if (Heap::GetSpaces().size() > 1) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 218 | ImageSpace* last_image_space = NULL; |
| 219 | const std::vector<Space*>& spaces = Heap::GetSpaces(); |
| 220 | for (size_t i=0; i < spaces.size(); i++) { |
| 221 | if (spaces[i]->IsImageSpace()) { |
| 222 | last_image_space = spaces[i]->AsImageSpace(); |
| 223 | } |
| 224 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 225 | CHECK(last_image_space != NULL); |
| 226 | CHECK(last_image_space->IsImageSpace()); |
| 227 | CHECK(!Heap::GetSpaces()[Heap::GetSpaces().size()-1]->IsImageSpace()); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 228 | byte* oat_limit_addr = last_image_space->GetImageHeader().GetOatEnd(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 229 | image_base = RoundUp(reinterpret_cast<uintptr_t>(oat_limit_addr), kPageSize); |
| 230 | } |
| 231 | |
| 232 | ImageWriter image_writer(image_classes); |
| 233 | if (!image_writer.Write(image_filename, image_base, oat_filename, host_prefix)) { |
| 234 | LOG(ERROR) << "Failed to create image file " << image_filename; |
| 235 | return false; |
| 236 | } |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | private: |
| 241 | |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 242 | explicit Dex2Oat(Runtime* runtime) : runtime_(runtime), start_ns_(NanoTime()) { |
| 243 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 244 | |
| 245 | static Runtime* CreateRuntime(Runtime::Options& options) { |
| 246 | Runtime* runtime = Runtime::Create(options, false); |
| 247 | if (runtime == NULL) { |
| 248 | LOG(ERROR) << "Failed to create runtime"; |
| 249 | return NULL; |
| 250 | } |
| 251 | |
| 252 | // if we loaded an existing image, we will reuse values from the image roots. |
| 253 | if (!runtime->HasJniDlsymLookupStub()) { |
Elliott Hughes | 8add92d | 2012-01-18 18:18:43 -0800 | [diff] [blame] | 254 | runtime->SetJniDlsymLookupStub(Compiler::CreateJniDlsymLookupStub(instruction_set_)); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 255 | } |
| 256 | if (!runtime->HasAbstractMethodErrorStubArray()) { |
| 257 | runtime->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(instruction_set_)); |
| 258 | } |
| 259 | for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) { |
| 260 | Runtime::TrampolineType type = Runtime::TrampolineType(i); |
| 261 | if (!runtime->HasResolutionStubArray(type)) { |
| 262 | runtime->SetResolutionStubArray(Compiler::CreateResolutionStub(instruction_set_, type), type); |
| 263 | } |
| 264 | } |
| 265 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 266 | Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); |
| 267 | if (!runtime->HasCalleeSaveMethod(type)) { |
| 268 | runtime->SetCalleeSaveMethod(runtime->CreateCalleeSaveMethod(instruction_set_, type), type); |
| 269 | } |
| 270 | } |
| 271 | return runtime; |
| 272 | } |
| 273 | |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 274 | static void ResolveExceptionsForMethod(MethodHelper* mh, |
| 275 | std::set<std::pair<uint16_t, const DexFile*> >& exceptions_to_resolve) { |
| 276 | const DexFile::CodeItem* code_item = mh->GetCodeItem(); |
| 277 | if (code_item == NULL) { |
| 278 | return; // native or abstract method |
| 279 | } |
| 280 | if (code_item->tries_size_ == 0) { |
| 281 | return; // nothing to process |
| 282 | } |
| 283 | const byte* encoded_catch_handler_list = DexFile::GetCatchHandlerData(*code_item, 0); |
| 284 | size_t num_encoded_catch_handlers = DecodeUnsignedLeb128(&encoded_catch_handler_list); |
| 285 | for (size_t i = 0; i < num_encoded_catch_handlers; i++) { |
| 286 | int32_t encoded_catch_handler_size = DecodeSignedLeb128(&encoded_catch_handler_list); |
| 287 | bool has_catch_all = false; |
| 288 | if (encoded_catch_handler_size <= 0) { |
| 289 | encoded_catch_handler_size = -encoded_catch_handler_size; |
| 290 | has_catch_all = true; |
| 291 | } |
| 292 | for (int32_t j = 0; j < encoded_catch_handler_size; j++) { |
| 293 | uint16_t encoded_catch_handler_handlers_type_idx = |
| 294 | DecodeUnsignedLeb128(&encoded_catch_handler_list); |
| 295 | // Add to set of types to resolve if not already in the dex cache resolved types |
| 296 | if (!mh->IsResolvedTypeIdx(encoded_catch_handler_handlers_type_idx)) { |
| 297 | exceptions_to_resolve.insert( |
| 298 | std::pair<uint16_t, const DexFile*>(encoded_catch_handler_handlers_type_idx, |
| 299 | &mh->GetDexFile())); |
| 300 | } |
| 301 | // ignore address associated with catch handler |
| 302 | DecodeUnsignedLeb128(&encoded_catch_handler_list); |
| 303 | } |
| 304 | if (has_catch_all) { |
| 305 | // ignore catch all address |
| 306 | DecodeUnsignedLeb128(&encoded_catch_handler_list); |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | static bool ResolveCatchBlockExceptionsClassVisitor(Class* c, void* arg) { |
| 311 | std::set<std::pair<uint16_t, const DexFile*> >* exceptions_to_resolve = |
| 312 | reinterpret_cast<std::set<std::pair<uint16_t, const DexFile*> >*>(arg); |
| 313 | MethodHelper mh; |
| 314 | for (size_t i = 0; i < c->NumVirtualMethods(); ++i) { |
| 315 | Method* m = c->GetVirtualMethod(i); |
| 316 | mh.ChangeMethod(m); |
| 317 | ResolveExceptionsForMethod(&mh, *exceptions_to_resolve); |
| 318 | } |
| 319 | for (size_t i = 0; i < c->NumDirectMethods(); ++i) { |
| 320 | Method* m = c->GetDirectMethod(i); |
| 321 | mh.ChangeMethod(m); |
| 322 | ResolveExceptionsForMethod(&mh, *exceptions_to_resolve); |
| 323 | } |
| 324 | return true; |
| 325 | } |
| 326 | static bool RecordImageClassesVisitor(Class* klass, void* arg) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 327 | std::set<std::string>* image_classes = reinterpret_cast<std::set<std::string>*>(arg); |
| 328 | if (klass->IsArrayClass() || klass->IsPrimitive()) { |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 329 | return true; |
| 330 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 331 | image_classes->insert(ClassHelper(klass).GetDescriptor()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 332 | return true; |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 333 | } |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 334 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 335 | // Appends to dex_files any elements of class_path that it doesn't already |
| 336 | // contain. This will open those dex files as necessary. |
| 337 | static void OpenClassPathFiles(const std::string& class_path, std::vector<const DexFile*>& dex_files) { |
| 338 | std::vector<std::string> parsed; |
| 339 | Split(class_path, ':', parsed); |
| 340 | for (size_t i = 0; i < parsed.size(); ++i) { |
| 341 | if (DexFilesContains(dex_files, parsed[i])) { |
| 342 | continue; |
| 343 | } |
| 344 | const DexFile* dex_file = DexFile::Open(parsed[i], Runtime::Current()->GetHostPrefix()); |
| 345 | if (dex_file == NULL) { |
| 346 | LOG(WARNING) << "Failed to open dex file " << parsed[i]; |
| 347 | } else { |
| 348 | dex_files.push_back(dex_file); |
| 349 | } |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 350 | } |
| 351 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 352 | |
| 353 | // Returns true if dex_files has a dex with the named location. |
| 354 | static bool DexFilesContains(const std::vector<const DexFile*>& dex_files, const std::string& location) { |
| 355 | for (size_t i = 0; i < dex_files.size(); ++i) { |
| 356 | if (dex_files[i]->GetLocation() == location) { |
| 357 | return true; |
| 358 | } |
| 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 363 | static const InstructionSet instruction_set_ = kThumb2; |
| 364 | |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 365 | Runtime* runtime_; |
| 366 | uint64_t start_ns_; |
| 367 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 368 | DISALLOW_IMPLICIT_CONSTRUCTORS(Dex2Oat); |
| 369 | }; |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 370 | |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 371 | bool ParseInt(const char* in, int* out) { |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 372 | char* end; |
| 373 | int result = strtol(in, &end, 10); |
| 374 | if (in == end || *end != '\0') { |
| 375 | return false; |
| 376 | } |
| 377 | *out = result; |
| 378 | return true; |
| 379 | } |
| 380 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 381 | int dex2oat(int argc, char** argv) { |
| 382 | // Skip over argv[0]. |
| 383 | argv++; |
| 384 | argc--; |
| 385 | |
| 386 | if (argc == 0) { |
| 387 | fprintf(stderr, "no arguments specified\n"); |
| 388 | usage(); |
| 389 | } |
| 390 | |
| 391 | std::vector<const char*> dex_filenames; |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 392 | int zip_fd = -1; |
| 393 | std::string zip_name; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 394 | std::string oat_filename; |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 395 | int oat_fd = -1; |
| 396 | std::string oat_name; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 397 | const char* image_filename = NULL; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 398 | const char* image_classes_filename = NULL; |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 399 | std::string boot_image_filename; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 400 | uintptr_t image_base = 0; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 401 | std::string host_prefix; |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 402 | std::vector<const char*> runtime_args; |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 403 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 404 | for (int i = 0; i < argc; i++) { |
| 405 | const StringPiece option(argv[i]); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 406 | bool log_options = false; |
| 407 | if (log_options) { |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 408 | LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i]; |
| 409 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 410 | if (option.starts_with("--dex-file=")) { |
| 411 | dex_filenames.push_back(option.substr(strlen("--dex-file=")).data()); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 412 | } else if (option.starts_with("--zip-fd=")) { |
| 413 | const char* zip_fd_str = option.substr(strlen("--zip-fd=")).data(); |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 414 | if (!ParseInt(zip_fd_str, &zip_fd)) { |
Brian Carlstrom | 866c862 | 2012-01-06 16:35:13 -0800 | [diff] [blame] | 415 | fprintf(stderr, "could not parse --zip-fd argument '%s' as an integer\n", zip_fd_str); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 416 | usage(); |
| 417 | } |
| 418 | } else if (option.starts_with("--zip-name=")) { |
| 419 | zip_name = option.substr(strlen("--zip-name=")).data(); |
| 420 | } else if (option.starts_with("--oat-file=")) { |
| 421 | oat_filename = option.substr(strlen("--oat-file=")).data(); |
| 422 | } else if (option.starts_with("--oat-fd=")) { |
| 423 | const char* oat_fd_str = option.substr(strlen("--oat-fd=")).data(); |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 424 | if (!ParseInt(oat_fd_str, &oat_fd)) { |
Brian Carlstrom | 866c862 | 2012-01-06 16:35:13 -0800 | [diff] [blame] | 425 | fprintf(stderr, "could not parse --oat-fd argument '%s' as an integer\n", oat_fd_str); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 426 | usage(); |
| 427 | } |
| 428 | } else if (option.starts_with("--oat-name=")) { |
| 429 | oat_name = option.substr(strlen("--oat-name=")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 430 | } else if (option.starts_with("--image=")) { |
| 431 | image_filename = option.substr(strlen("--image=")).data(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 432 | } else if (option.starts_with("--image-classes=")) { |
| 433 | image_classes_filename = option.substr(strlen("--image-classes=")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 434 | } else if (option.starts_with("--base=")) { |
| 435 | const char* image_base_str = option.substr(strlen("--base=")).data(); |
| 436 | char* end; |
| 437 | image_base = strtoul(image_base_str, &end, 16); |
| 438 | if (end == image_base_str || *end != '\0') { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 439 | 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] | 440 | usage(); |
| 441 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 442 | } else if (option.starts_with("--boot-image=")) { |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 443 | boot_image_filename = option.substr(strlen("--boot-image=")).data(); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 444 | } else if (option.starts_with("--host-prefix=")) { |
| 445 | host_prefix = option.substr(strlen("--host-prefix=")).data(); |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 446 | } else if (option == "--runtime-arg") { |
| 447 | if (++i >= argc) { |
| 448 | fprintf(stderr, "Missing required argument for --runtime-arg\n"); |
| 449 | usage(); |
| 450 | } |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 451 | if (log_options) { |
| 452 | LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i]; |
| 453 | } |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 454 | runtime_args.push_back(argv[i]); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 455 | } else { |
| 456 | fprintf(stderr, "unknown argument %s\n", option.data()); |
| 457 | usage(); |
| 458 | } |
| 459 | } |
| 460 | |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 461 | if (oat_filename.empty() && oat_fd == -1) { |
| 462 | fprintf(stderr, "Output must be supplied with either --oat-file or --oat-fd\n"); |
| 463 | return EXIT_FAILURE; |
| 464 | } |
| 465 | |
| 466 | if (!oat_filename.empty() && oat_fd != -1) { |
| 467 | fprintf(stderr, "--oat-file should not be used with --oat-fd\n"); |
| 468 | return EXIT_FAILURE; |
| 469 | } |
| 470 | |
| 471 | if (!oat_filename.empty() && oat_fd != -1) { |
| 472 | fprintf(stderr, "--oat-file should not be used with --oat-fd\n"); |
| 473 | return EXIT_FAILURE; |
| 474 | } |
| 475 | |
| 476 | if (!oat_filename.empty() && !oat_name.empty()) { |
| 477 | fprintf(stderr, "--oat-file should not be used with --oat-name\n"); |
| 478 | return EXIT_FAILURE; |
| 479 | } |
| 480 | |
| 481 | if (oat_fd != -1 && oat_name.empty()) { |
| 482 | fprintf(stderr, "--oat-name should be supplied with --oat-fd\n"); |
| 483 | return EXIT_FAILURE; |
| 484 | } |
| 485 | |
| 486 | if (oat_fd != -1 && image_filename != NULL) { |
| 487 | fprintf(stderr, "--oat-fd should not be used with --image\n"); |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 488 | return EXIT_FAILURE; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 491 | if (host_prefix.empty()) { |
| 492 | const char* android_product_out = getenv("ANDROID_PRODUCT_OUT"); |
| 493 | if (android_product_out != NULL) { |
| 494 | host_prefix = android_product_out; |
| 495 | } |
| 496 | } |
| 497 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 498 | bool image = (image_filename != NULL); |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 499 | if (!image && boot_image_filename.empty()) { |
| 500 | boot_image_filename += host_prefix; |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 501 | boot_image_filename += "/system/framework/boot.art"; |
Brian Carlstrom | b001126 | 2011-12-09 12:17:24 -0800 | [diff] [blame] | 502 | } |
| 503 | std::string boot_image_option; |
| 504 | if (boot_image_filename != NULL) { |
| 505 | boot_image_option += "-Ximage:"; |
| 506 | boot_image_option += boot_image_filename; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 509 | if (image_classes_filename != NULL && !image) { |
| 510 | fprintf(stderr, "--image-classes should only be used with --image\n"); |
| 511 | return EXIT_FAILURE; |
| 512 | } |
| 513 | |
| 514 | if (image_classes_filename != NULL && !boot_image_option.empty()) { |
| 515 | fprintf(stderr, "--image-classes should not be used with --boot-image\n"); |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 516 | return EXIT_FAILURE; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 519 | if (dex_filenames.empty() && zip_fd == -1) { |
| 520 | fprintf(stderr, "Input must be supplied with either --dex-file or --zip-fd\n"); |
| 521 | return EXIT_FAILURE; |
| 522 | } |
| 523 | |
| 524 | if (!dex_filenames.empty() && zip_fd != -1) { |
| 525 | fprintf(stderr, "--dex-file should not be used with --zip-fd\n"); |
| 526 | return EXIT_FAILURE; |
| 527 | } |
| 528 | |
| 529 | if (!dex_filenames.empty() && !zip_name.empty()) { |
| 530 | fprintf(stderr, "--dex-file should not be used with --zip-name\n"); |
| 531 | return EXIT_FAILURE; |
| 532 | } |
| 533 | |
| 534 | if (zip_fd != -1 && zip_name.empty()) { |
| 535 | fprintf(stderr, "--zip-name should be supplied with --zip-fd\n"); |
| 536 | return EXIT_FAILURE; |
| 537 | } |
| 538 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 539 | if (boot_image_option.empty()) { |
| 540 | if (image_base == 0) { |
| 541 | fprintf(stderr, "non-zero --base not specified\n"); |
| 542 | return EXIT_FAILURE; |
| 543 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Brian Carlstrom | 6ef827a | 2011-12-11 14:57:47 -0800 | [diff] [blame] | 546 | // Check early that the result of compilation can be written |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 547 | UniquePtr<File> oat_file; |
| 548 | if (!oat_filename.empty()) { |
| 549 | oat_file.reset(OS::OpenFile(oat_filename.c_str(), true)); |
| 550 | oat_name = oat_filename; |
| 551 | } else { |
| 552 | oat_file.reset(OS::FileFromFd(oat_name.c_str(), oat_fd)); |
| 553 | } |
Brian Carlstrom | 6ef827a | 2011-12-11 14:57:47 -0800 | [diff] [blame] | 554 | if (oat_file.get() == NULL) { |
Elliott Hughes | fd8cba4 | 2012-01-11 14:34:28 -0800 | [diff] [blame] | 555 | PLOG(ERROR) << "Unable to create oat file: " << oat_name; |
Brian Carlstrom | 6ef827a | 2011-12-11 14:57:47 -0800 | [diff] [blame] | 556 | return EXIT_FAILURE; |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 557 | } |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 558 | |
| 559 | LOG(INFO) << "dex2oat: " << oat_name; |
Ian Rogers | 5e863dd | 2011-11-02 20:00:10 -0700 | [diff] [blame] | 560 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 561 | Runtime::Options options; |
Brian Carlstrom | 5de8fe5 | 2011-10-16 14:10:09 -0700 | [diff] [blame] | 562 | options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL))); |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 563 | std::string boot_class_path_string; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 564 | if (boot_image_option.empty()) { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 565 | boot_class_path_string += "-Xbootclasspath:"; |
| 566 | for (size_t i = 0; i < dex_filenames.size()-1; i++) { |
| 567 | boot_class_path_string += dex_filenames[i]; |
| 568 | boot_class_path_string += ":"; |
| 569 | } |
| 570 | boot_class_path_string += dex_filenames[dex_filenames.size()-1]; |
| 571 | 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] | 572 | } else { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 573 | options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL))); |
| 574 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 575 | if (!host_prefix.empty()) { |
| 576 | options.push_back(std::make_pair("host-prefix", host_prefix.c_str())); |
| 577 | } |
jeffhao | 5d84040 | 2011-10-24 17:09:45 -0700 | [diff] [blame] | 578 | for (size_t i = 0; i < runtime_args.size(); i++) { |
| 579 | options.push_back(std::make_pair(runtime_args[i], reinterpret_cast<void*>(NULL))); |
| 580 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 581 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 582 | UniquePtr<Dex2Oat> dex2oat(Dex2Oat::Create(options)); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 583 | |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 584 | // If --image-classes was specified, calculate the full list of classes to include in the image |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 585 | UniquePtr<const std::set<std::string> > image_classes(NULL); |
| 586 | if (image_classes_filename != NULL) { |
| 587 | image_classes.reset(dex2oat->GetImageClassDescriptors(image_classes_filename)); |
| 588 | if (image_classes.get() == NULL) { |
| 589 | LOG(ERROR) << "Failed to create list of image classes from " << image_classes_filename; |
| 590 | return EXIT_FAILURE; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 594 | std::vector<const DexFile*> dex_files; |
| 595 | if (boot_image_option.empty()) { |
| 596 | dex_files = Runtime::Current()->GetClassLinker()->GetBootClassPath(); |
| 597 | } else { |
| 598 | if (dex_filenames.empty()) { |
| 599 | UniquePtr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(zip_fd)); |
| 600 | if (zip_archive.get() == NULL) { |
| 601 | LOG(ERROR) << "Failed to zip from file descriptor for " << zip_name; |
Brian Carlstrom | 2e3d1b2 | 2012-01-09 18:01:56 -0800 | [diff] [blame] | 602 | return EXIT_FAILURE; |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 603 | } |
| 604 | const DexFile* dex_file = DexFile::Open(*zip_archive.get(), zip_name); |
| 605 | if (dex_file == NULL) { |
Elliott Hughes | fd8cba4 | 2012-01-11 14:34:28 -0800 | [diff] [blame] | 606 | LOG(ERROR) << "Failed to open dex from file descriptor for zip file: " << zip_name; |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 607 | return EXIT_FAILURE; |
| 608 | } |
| 609 | dex_files.push_back(dex_file); |
| 610 | } else { |
| 611 | DexFile::OpenDexFiles(dex_filenames, dex_files, host_prefix); |
| 612 | } |
| 613 | } |
| 614 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 615 | if (!dex2oat->CreateOatFile(boot_image_option, |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 616 | dex_files, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 617 | oat_file.get(), |
| 618 | image, |
| 619 | image_classes.get())) { |
Elliott Hughes | fd8cba4 | 2012-01-11 14:34:28 -0800 | [diff] [blame] | 620 | LOG(ERROR) << "Failed to create oat file: " << oat_name; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 621 | return EXIT_FAILURE; |
| 622 | } |
| 623 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 624 | if (!image) { |
Elliott Hughes | fd8cba4 | 2012-01-11 14:34:28 -0800 | [diff] [blame] | 625 | LOG(INFO) << "Oat file written successfully: " << oat_name; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 626 | return EXIT_SUCCESS; |
| 627 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 628 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 629 | if (!dex2oat->CreateImageFile(image_filename, |
| 630 | image_base, |
| 631 | image_classes.get(), |
| 632 | oat_filename, |
| 633 | host_prefix)) { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 634 | return EXIT_FAILURE; |
| 635 | } |
| 636 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 637 | // We wrote the oat file successfully, and want to keep it. |
Elliott Hughes | bb551fa | 2012-01-25 16:35:29 -0800 | [diff] [blame] | 638 | LOG(INFO) << "Oat file written successfully: " << oat_filename; |
| 639 | LOG(INFO) << "Image written successfully: " << image_filename; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 640 | return EXIT_SUCCESS; |
| 641 | } |
| 642 | |
| 643 | } // namespace art |
| 644 | |
| 645 | int main(int argc, char** argv) { |
| 646 | return art::dex2oat(argc, argv); |
| 647 | } |