Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 6 | #include <fstream> |
| 7 | #include <iostream> |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "class_linker.h" |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 12 | #include "file.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 13 | #include "image.h" |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 14 | #include "os.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 15 | #include "runtime.h" |
| 16 | #include "space.h" |
| 17 | #include "stringpiece.h" |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 18 | #include "unordered_map.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | static void usage() { |
| 23 | fprintf(stderr, |
| 24 | "Usage: oatdump [options] ...\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 25 | " Example: oatdump --image=$ANDROID_PRODUCT_OUT/data/art-cache/boot.art --host-prefix=$ANDROID_PRODUCT_OUT\n" |
| 26 | " Example: adb shell oatdump --image=/data/art-cache/boot.art\n" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 27 | "\n"); |
| 28 | fprintf(stderr, |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 29 | " --oat=<file.oat>: specifies an input oat filename.\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 30 | " Example: --image=/data/art-cache/boot.oat\n" |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 31 | "\n"); |
| 32 | fprintf(stderr, |
| 33 | " --image=<file.art>: specifies an input image filename.\n" |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 34 | " Example: --image=/data/art-cache/boot.art\n" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 35 | "\n"); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 36 | fprintf(stderr, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 37 | " --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] | 38 | " Example: --boot-image=/data/art-cache/boot.art\n" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 39 | "\n"); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 40 | fprintf(stderr, |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 41 | " --host-prefix may be used to translate host paths to target paths during\n" |
| 42 | " cross compilation.\n" |
| 43 | " Example: --host-prefix=out/target/product/crespo\n" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 44 | "\n"); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 45 | fprintf(stderr, |
| 46 | " --output=<file> may be used to send the output to a file.\n" |
| 47 | " Example: --output=/tmp/oatdump.txt\n" |
| 48 | "\n"); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 49 | exit(EXIT_FAILURE); |
| 50 | } |
| 51 | |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 52 | const char* image_roots_descriptions_[] = { |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 53 | "kJniStubArray", |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 54 | "kAbstractMethodErrorStubArray", |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 55 | "kInstanceResolutionStubArray", |
| 56 | "kStaticResolutionStubArray", |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 57 | "kUnknownMethodResolutionStubArray", |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 58 | "kCalleeSaveMethod", |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 59 | "kRefsOnlySaveMethod", |
| 60 | "kRefsAndArgsSaveMethod", |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 61 | "kOatLocation", |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 62 | "kDexCaches", |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 63 | "kClassRoots", |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 66 | class OatDump { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 67 | public: |
| 68 | static void Dump(const std::string& oat_filename, |
| 69 | const std::string& host_prefix, |
| 70 | std::ostream& os, |
| 71 | const OatFile& oat_file) { |
| 72 | const OatHeader& oat_header = oat_file.GetOatHeader(); |
| 73 | |
| 74 | os << "MAGIC:\n"; |
| 75 | os << oat_header.GetMagic() << "\n\n"; |
| 76 | |
| 77 | os << "CHECKSUM:\n"; |
| 78 | os << StringPrintf("%08x\n\n", oat_header.GetChecksum()); |
| 79 | |
| 80 | os << "DEX FILE COUNT:\n"; |
| 81 | os << oat_header.GetDexFileCount() << "\n\n"; |
| 82 | |
| 83 | os << "EXECUTABLE OFFSET:\n"; |
| 84 | os << StringPrintf("%08x\n\n", oat_header.GetExecutableOffset()); |
| 85 | |
| 86 | os << "BASE:\n"; |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 87 | os << reinterpret_cast<const void*>(oat_file.GetBase()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 88 | |
| 89 | os << "LIMIT:\n"; |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 90 | os << reinterpret_cast<const void*>(oat_file.GetLimit()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 91 | |
| 92 | os << std::flush; |
| 93 | |
| 94 | std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file.GetOatDexFiles() ; |
| 95 | for (size_t i = 0; i < oat_dex_files.size(); i++) { |
| 96 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i]; |
| 97 | CHECK(oat_dex_file != NULL); |
| 98 | DumpOatDexFile(host_prefix, os, oat_file, *oat_dex_file); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | static void DumpOatDexFile(const std::string& host_prefix, |
| 104 | std::ostream& os, |
| 105 | const OatFile& oat_file, |
| 106 | const OatFile::OatDexFile& oat_dex_file) { |
| 107 | os << "OAT DEX FILE:\n"; |
| 108 | std::string dex_file_location = oat_dex_file.GetDexFileLocation(); |
| 109 | os << "location: " << dex_file_location; |
| 110 | if (!host_prefix.empty()) { |
| 111 | dex_file_location = host_prefix + dex_file_location; |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 112 | os << " (" << dex_file_location << ")"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 113 | } |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 114 | os << "\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 115 | os << StringPrintf("checksum: %08x\n", oat_dex_file.GetDexFileChecksum()); |
| 116 | const DexFile* dex_file = DexFile::Open(dex_file_location, ""); |
| 117 | if (dex_file == NULL) { |
| 118 | os << "NOT FOUND\n\n"; |
| 119 | return; |
| 120 | } |
| 121 | for (size_t class_def_index = 0; class_def_index < dex_file->NumClassDefs(); class_def_index++) { |
| 122 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
| 123 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 124 | os << StringPrintf("%d: %s (type_idx=%d)\n", class_def_index, descriptor, class_def.class_idx_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 125 | UniquePtr<const OatFile::OatClass> oat_class(oat_dex_file.GetOatClass(class_def_index)); |
| 126 | CHECK(oat_class.get() != NULL); |
| 127 | DumpOatClass(os, oat_file, *oat_class.get(), *dex_file, class_def); |
| 128 | } |
| 129 | |
| 130 | os << std::flush; |
| 131 | } |
| 132 | |
| 133 | static void DumpOatClass(std::ostream& os, |
| 134 | const OatFile& oat_file, |
| 135 | const OatFile::OatClass& oat_class, |
| 136 | const DexFile& dex_file, |
| 137 | const DexFile::ClassDef& class_def) { |
| 138 | const byte* class_data = dex_file.GetClassData(class_def); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 139 | if (class_data == NULL) { // empty class such as a marker interface? |
| 140 | return; |
| 141 | } |
| 142 | ClassDataItemIterator it(dex_file, class_data); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 143 | |
| 144 | // just skipping through the fields to advance class_data |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 145 | while (it.HasNextStaticField()) { |
| 146 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 147 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 148 | while (it.HasNextInstanceField()) { |
| 149 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 152 | uint32_t method_index = 0; |
| 153 | while (it.HasNextDirectMethod()) { |
| 154 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(method_index); |
| 155 | DumpOatMethod(os, method_index, oat_file, oat_method, dex_file, it.GetMemberIndex()); |
| 156 | method_index++; |
| 157 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 158 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 159 | while (it.HasNextVirtualMethod()) { |
| 160 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(method_index); |
| 161 | DumpOatMethod(os, method_index, oat_file, oat_method, dex_file, it.GetMemberIndex()); |
| 162 | method_index++; |
| 163 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 164 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 165 | DCHECK(!it.HasNext()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 166 | os << std::flush; |
| 167 | } |
| 168 | static void DumpOatMethod(std::ostream& os, |
| 169 | uint32_t method_index, |
| 170 | const OatFile& oat_file, |
| 171 | const OatFile::OatMethod& oat_method, |
| 172 | const DexFile& dex_file, |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 173 | uint32_t method_idx) { |
| 174 | const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 175 | const char* name = dex_file.GetMethodName(method_id); |
| 176 | std::string signature = dex_file.GetMethodSignature(method_id); |
| 177 | os << StringPrintf("\t%d: %s %s (method_idx=%d)\n", |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 178 | method_index, name, signature.c_str(), method_idx); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 179 | os << StringPrintf("\t\tcode: %p (offset=%08x)\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 180 | oat_method.GetCode(), oat_method.GetCodeOffset()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 181 | os << StringPrintf("\t\tframe_size_in_bytes: %d\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 182 | oat_method.GetFrameSizeInBytes()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 183 | os << StringPrintf("\t\tcore_spill_mask: %08x\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 184 | oat_method.GetCoreSpillMask()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 185 | os << StringPrintf("\t\tfp_spill_mask: %08x\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 186 | oat_method.GetFpSpillMask()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 187 | os << StringPrintf("\t\tmapping_table: %p (offset=%08x)\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 188 | oat_method.GetMappingTable(), oat_method.GetMappingTableOffset()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 189 | os << StringPrintf("\t\tvmap_table: %p (offset=%08x)\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 190 | oat_method.GetVmapTable(), oat_method.GetVmapTableOffset()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 191 | os << StringPrintf("\t\tinvoke_stub: %p (offset=%08x)\n", |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 192 | oat_method.GetInvokeStub(), oat_method.GetInvokeStubOffset()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 193 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | class ImageDump { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 197 | public: |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 198 | static void Dump(const std::string& image_filename, |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 199 | const std::string& host_prefix, |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 200 | std::ostream& os, |
| 201 | Space& image_space, |
| 202 | const ImageHeader& image_header) { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 203 | os << "MAGIC:\n"; |
| 204 | os << image_header.GetMagic() << "\n\n"; |
| 205 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 206 | os << "IMAGE BASE:\n"; |
| 207 | os << reinterpret_cast<void*>(image_header.GetImageBaseAddr()) << "\n\n"; |
| 208 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 209 | os << "OAT CHECKSUM:\n"; |
| 210 | os << StringPrintf("%08x\n\n", image_header.GetOatChecksum()); |
| 211 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 212 | os << "OAT BASE:\n"; |
| 213 | os << reinterpret_cast<void*>(image_header.GetOatBaseAddr()) << "\n\n"; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 214 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 215 | os << "OAT LIMIT:\n"; |
| 216 | os << reinterpret_cast<void*>(image_header.GetOatLimitAddr()) << "\n\n"; |
| 217 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 218 | os << "ROOTS:\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 219 | os << reinterpret_cast<void*>(image_header.GetImageRoots()) << "\n"; |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 220 | CHECK_EQ(arraysize(image_roots_descriptions_), size_t(ImageHeader::kImageRootsMax)); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 221 | for (int i = 0; i < ImageHeader::kImageRootsMax; i++) { |
| 222 | ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i); |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 223 | const char* image_root_description = image_roots_descriptions_[i]; |
| 224 | Object* image_root_object = image_header.GetImageRoot(image_root); |
| 225 | os << StringPrintf("%s: %p\n", image_root_description, image_root_object); |
| 226 | if (image_root_object->IsObjectArray()) { |
| 227 | // TODO: replace down_cast with AsObjectArray (g++ currently has a problem with this) |
| 228 | ObjectArray<Object>* image_root_object_array |
| 229 | = down_cast<ObjectArray<Object>*>(image_root_object); |
| 230 | // = image_root_object->AsObjectArray<Object>(); |
| 231 | for (int i = 0; i < image_root_object_array->GetLength(); i++) { |
| 232 | os << StringPrintf("\t%d: %p\n", i, image_root_object_array->Get(i)); |
| 233 | } |
| 234 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 235 | } |
| 236 | os << "\n"; |
| 237 | |
| 238 | os << "OBJECTS:\n" << std::flush; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 239 | ImageDump state(image_space, os); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 240 | HeapBitmap* heap_bitmap = Heap::GetLiveBits(); |
| 241 | DCHECK(heap_bitmap != NULL); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 242 | heap_bitmap->Walk(ImageDump::Callback, &state); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 243 | os << "\n"; |
| 244 | |
| 245 | os << "STATS:\n" << std::flush; |
| 246 | UniquePtr<File> file(OS::OpenFile(image_filename.c_str(), false)); |
| 247 | state.stats_.file_bytes = file->Length(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 248 | size_t header_bytes = sizeof(ImageHeader); |
| 249 | state.stats_.header_bytes = header_bytes; |
| 250 | size_t alignment_bytes = RoundUp(header_bytes, kObjectAlignment) - header_bytes; |
| 251 | state.stats_.alignment_bytes += alignment_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 252 | state.stats_.Dump(os); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 253 | os << "\n"; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 254 | |
| 255 | os << std::flush; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 256 | |
| 257 | os << "OAT LOCATION:\n" << std::flush; |
| 258 | Object* oat_location_object = image_header.GetImageRoot(ImageHeader::kOatLocation); |
| 259 | std::string oat_location = oat_location_object->AsString()->ToModifiedUtf8(); |
| 260 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 261 | os << oat_location; |
| 262 | if (!host_prefix.empty()) { |
| 263 | oat_location = host_prefix + oat_location; |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 264 | os << " (" << oat_location << ")"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 265 | } |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 266 | os << "\n"; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 267 | const OatFile* oat_file = class_linker->FindOatFileFromOatLocation(oat_location); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 268 | if (oat_file == NULL) { |
| 269 | os << "NOT FOUND\n"; |
| 270 | os << std::flush; |
| 271 | return; |
| 272 | } |
| 273 | os << "\n"; |
| 274 | os << std::flush; |
| 275 | |
| 276 | OatDump::Dump(oat_location, host_prefix, os, *oat_file); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 279 | private: |
| 280 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 281 | ImageDump(const Space& dump_space, std::ostream& os) : dump_space_(dump_space), os_(os) {} |
Elliott Hughes | d1bb4f6 | 2011-09-23 14:09:45 -0700 | [diff] [blame] | 282 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 283 | ~ImageDump() {} |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 284 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 285 | static void Callback(Object* obj, void* arg) { |
| 286 | DCHECK(obj != NULL); |
| 287 | DCHECK(arg != NULL); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 288 | ImageDump* state = reinterpret_cast<ImageDump*>(arg); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 289 | if (!state->InDumpSpace(obj)) { |
| 290 | return; |
| 291 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 292 | |
| 293 | size_t object_bytes = obj->SizeOf(); |
| 294 | size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes; |
| 295 | state->stats_.object_bytes += object_bytes; |
| 296 | state->stats_.alignment_bytes += alignment_bytes; |
| 297 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 298 | std::string summary; |
| 299 | StringAppendF(&summary, "%p: ", obj); |
| 300 | if (obj->IsClass()) { |
| 301 | Class* klass = obj->AsClass(); |
| 302 | StringAppendF(&summary, "CLASS %s", klass->GetDescriptor()->ToModifiedUtf8().c_str()); |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 303 | std::ostringstream ss; |
Brian Carlstrom | e10b697 | 2011-09-26 13:49:03 -0700 | [diff] [blame] | 304 | ss << " (" << klass->GetStatus() << ")"; |
| 305 | summary += ss.str(); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 306 | } else if (obj->IsMethod()) { |
| 307 | Method* method = obj->AsMethod(); |
| 308 | StringAppendF(&summary, "METHOD %s", PrettyMethod(method).c_str()); |
| 309 | } else if (obj->IsField()) { |
| 310 | Field* field = obj->AsField(); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 311 | StringAppendF(&summary, "FIELD %s", PrettyField(field).c_str()); |
| 312 | } else if (obj->IsArrayInstance()) { |
| 313 | StringAppendF(&summary, "ARRAY %d", obj->AsArray()->GetLength()); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 314 | } else if (obj->GetClass()->IsStringClass()) { |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 315 | StringAppendF(&summary, "STRING %s", obj->AsString()->ToModifiedUtf8().c_str()); |
| 316 | } else { |
| 317 | StringAppendF(&summary, "OBJECT"); |
| 318 | } |
| 319 | StringAppendF(&summary, "\n"); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 320 | std::string descriptor = obj->GetClass()->GetDescriptor()->ToModifiedUtf8(); |
| 321 | StringAppendF(&summary, "\tclass %p: %s\n", obj->GetClass(), descriptor.c_str()); |
| 322 | state->stats_.descriptor_to_bytes[descriptor] += object_bytes; |
| 323 | state->stats_.descriptor_to_count[descriptor] += 1; |
| 324 | // StringAppendF(&summary, "\tsize %d (alignment padding %d)\n", |
| 325 | // object_bytes, RoundUp(object_bytes, kObjectAlignment) - object_bytes); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 326 | if (obj->IsMethod()) { |
| 327 | Method* method = obj->AsMethod(); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 328 | if (!method->IsCalleeSaveMethod()) { |
| 329 | const int8_t* code =reinterpret_cast<const int8_t*>(method->GetCode()); |
| 330 | StringAppendF(&summary, "\tCODE %p\n", code); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 331 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 332 | const Method::InvokeStub* invoke_stub = method->GetInvokeStub(); |
| 333 | StringAppendF(&summary, "\tJNI STUB %p\n", invoke_stub); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 334 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 335 | if (method->IsNative()) { |
| 336 | if (method->IsRegistered()) { |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 337 | StringAppendF(&summary, "\tNATIVE REGISTERED %p\n", method->GetNativeMethod()); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 338 | } else { |
| 339 | StringAppendF(&summary, "\tNATIVE UNREGISTERED\n"); |
| 340 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 341 | DCHECK(method->GetGcMap() == NULL) << PrettyMethod(method); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 342 | DCHECK(method->GetMappingTable() == NULL) << PrettyMethod(method); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 343 | } else if (method->IsAbstract()) { |
| 344 | StringAppendF(&summary, "\tABSTRACT\n"); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 345 | DCHECK(method->GetGcMap() == NULL) << PrettyMethod(method); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 346 | DCHECK(method->GetMappingTable() == NULL) << PrettyMethod(method); |
| 347 | } else if (method->IsCalleeSaveMethod()) { |
| 348 | StringAppendF(&summary, "\tCALLEE SAVE METHOD\n"); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 349 | DCHECK(method->GetGcMap() == NULL) << PrettyMethod(method); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 350 | DCHECK(method->GetMappingTable() == NULL) << PrettyMethod(method); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 351 | } else { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame^] | 352 | if (method->GetGcMap() != NULL) { |
| 353 | size_t register_map_bytes = method->GetGcMap()->SizeOf(); |
| 354 | state->stats_.register_map_bytes += register_map_bytes; |
| 355 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 356 | |
Brian Carlstrom | e10b697 | 2011-09-26 13:49:03 -0700 | [diff] [blame] | 357 | if (method->GetMappingTable() != NULL) { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 358 | size_t pc_mapping_table_bytes = method->GetMappingTableLength(); |
Brian Carlstrom | e10b697 | 2011-09-26 13:49:03 -0700 | [diff] [blame] | 359 | state->stats_.pc_mapping_table_bytes += pc_mapping_table_bytes; |
| 360 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 361 | |
| 362 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 363 | class DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
| 364 | const DexFile& dex_file = class_linker->FindDexFile(dex_cache); |
| 365 | const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->GetCodeItemOffset()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 366 | size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 367 | state->stats_.dex_instruction_bytes += dex_instruction_bytes; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 370 | state->os_ << summary << std::flush; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 371 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 372 | |
| 373 | bool InDumpSpace(const Object* object) { |
| 374 | const byte* o = reinterpret_cast<const byte*>(object); |
| 375 | return (o >= dump_space_.GetBase() && o < dump_space_.GetLimit()); |
| 376 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 377 | |
| 378 | public: |
| 379 | struct Stats { |
| 380 | size_t file_bytes; |
| 381 | |
| 382 | size_t header_bytes; |
| 383 | size_t object_bytes; |
| 384 | size_t alignment_bytes; |
| 385 | |
| 386 | size_t managed_code_bytes; |
| 387 | size_t managed_to_native_code_bytes; |
| 388 | size_t native_to_managed_code_bytes; |
| 389 | |
| 390 | size_t register_map_bytes; |
| 391 | size_t pc_mapping_table_bytes; |
| 392 | |
| 393 | size_t dex_instruction_bytes; |
| 394 | |
| 395 | Stats() |
| 396 | : file_bytes(0), |
| 397 | header_bytes(0), |
| 398 | object_bytes(0), |
| 399 | alignment_bytes(0), |
| 400 | managed_code_bytes(0), |
| 401 | managed_to_native_code_bytes(0), |
| 402 | native_to_managed_code_bytes(0), |
| 403 | register_map_bytes(0), |
| 404 | pc_mapping_table_bytes(0), |
| 405 | dex_instruction_bytes(0) {} |
| 406 | |
| 407 | typedef std::tr1::unordered_map<std::string,size_t> TableBytes; |
| 408 | TableBytes descriptor_to_bytes; |
| 409 | |
| 410 | typedef std::tr1::unordered_map<std::string,size_t> TableCount; |
| 411 | TableCount descriptor_to_count; |
| 412 | |
| 413 | double PercentOfFileBytes(size_t size) { |
| 414 | return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100; |
| 415 | } |
| 416 | |
| 417 | double PercentOfObjectBytes(size_t size) { |
| 418 | return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100; |
| 419 | } |
| 420 | |
| 421 | void Dump(std::ostream& os) { |
| 422 | os << StringPrintf("\tfile_bytes = %d\n", file_bytes); |
| 423 | os << "\n"; |
| 424 | |
| 425 | os << "\tfile_bytes = header_bytes + object_bytes + alignment_bytes\n"; |
| 426 | os << StringPrintf("\theader_bytes = %10d (%2.0f%% of file_bytes)\n", |
| 427 | header_bytes, PercentOfFileBytes(header_bytes)); |
| 428 | os << StringPrintf("\tobject_bytes = %10d (%2.0f%% of file_bytes)\n", |
| 429 | object_bytes, PercentOfFileBytes(object_bytes)); |
| 430 | os << StringPrintf("\talignment_bytes = %10d (%2.0f%% of file_bytes)\n", |
| 431 | alignment_bytes, PercentOfFileBytes(alignment_bytes)); |
| 432 | os << "\n"; |
| 433 | os << std::flush; |
| 434 | CHECK_EQ(file_bytes, header_bytes + object_bytes + alignment_bytes); |
| 435 | |
| 436 | os << "\tobject_bytes = sum of descriptor_to_bytes values below:\n"; |
| 437 | size_t object_bytes_total = 0; |
| 438 | typedef TableBytes::const_iterator It; // TODO: C++0x auto |
| 439 | for (It it = descriptor_to_bytes.begin(), end = descriptor_to_bytes.end(); it != end; ++it) { |
| 440 | const std::string& descriptor = it->first; |
| 441 | size_t bytes = it->second; |
| 442 | size_t count = descriptor_to_count[descriptor]; |
| 443 | double average = static_cast<double>(bytes) / static_cast<double>(count); |
| 444 | double percent = PercentOfObjectBytes(bytes); |
Brian Carlstrom | f153fe1 | 2011-09-27 16:27:12 -0700 | [diff] [blame] | 445 | os << StringPrintf("\t%32s %8d bytes %6d instances " |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 446 | "(%3.0f bytes/instance) %2.0f%% of object_bytes\n", |
| 447 | descriptor.c_str(), bytes, count, |
| 448 | average, percent); |
| 449 | |
| 450 | object_bytes_total += bytes; |
| 451 | } |
| 452 | os << "\n"; |
| 453 | os << std::flush; |
| 454 | CHECK_EQ(object_bytes, object_bytes_total); |
| 455 | |
| 456 | os << StringPrintf("\tmanaged_code_bytes = %8d (%2.0f%% of object_bytes)\n", |
| 457 | managed_code_bytes, PercentOfObjectBytes(managed_code_bytes)); |
| 458 | os << StringPrintf("\tmanaged_to_native_code_bytes = %8d (%2.0f%% of object_bytes)\n", |
| 459 | managed_to_native_code_bytes, |
| 460 | PercentOfObjectBytes(managed_to_native_code_bytes)); |
| 461 | os << StringPrintf("\tnative_to_managed_code_bytes = %8d (%2.0f%% of object_bytes)\n", |
| 462 | native_to_managed_code_bytes, |
| 463 | PercentOfObjectBytes(native_to_managed_code_bytes)); |
| 464 | os << "\n"; |
| 465 | os << std::flush; |
| 466 | |
| 467 | os << StringPrintf("\tregister_map_bytes = %7d (%2.0f%% of object_bytes)\n", |
| 468 | register_map_bytes, PercentOfObjectBytes(register_map_bytes)); |
| 469 | os << StringPrintf("\tpc_mapping_table_bytes = %7d (%2.0f%% of object_bytes)\n", |
| 470 | pc_mapping_table_bytes, PercentOfObjectBytes(pc_mapping_table_bytes)); |
| 471 | os << "\n"; |
| 472 | os << std::flush; |
| 473 | |
| 474 | os << StringPrintf("\tdex_instruction_bytes = %d\n", dex_instruction_bytes); |
| 475 | os << StringPrintf("\tmanaged_code_bytes expansion = %.2f\n", |
| 476 | static_cast<double>(managed_code_bytes) |
| 477 | / static_cast<double>(dex_instruction_bytes)); |
| 478 | os << "\n"; |
| 479 | os << std::flush; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 480 | } |
| 481 | } stats_; |
| 482 | |
| 483 | private: |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 484 | const Space& dump_space_; |
| 485 | std::ostream& os_; |
Elliott Hughes | d1bb4f6 | 2011-09-23 14:09:45 -0700 | [diff] [blame] | 486 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 487 | DISALLOW_COPY_AND_ASSIGN(ImageDump); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | int oatdump(int argc, char** argv) { |
| 491 | // Skip over argv[0]. |
| 492 | argv++; |
| 493 | argc--; |
| 494 | |
| 495 | if (argc == 0) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 496 | fprintf(stderr, "No arguments specified\n"); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 497 | usage(); |
| 498 | } |
| 499 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 500 | const char* oat_filename = NULL; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 501 | const char* image_filename = NULL; |
| 502 | const char* boot_image_filename = NULL; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 503 | std::string host_prefix; |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 504 | std::ostream* os = &std::cout; |
| 505 | UniquePtr<std::ofstream> out; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 506 | |
| 507 | for (int i = 0; i < argc; i++) { |
| 508 | const StringPiece option(argv[i]); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 509 | if (option.starts_with("--oat=")) { |
| 510 | oat_filename = option.substr(strlen("--oat=")).data(); |
| 511 | } else if (option.starts_with("--image=")) { |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 512 | image_filename = option.substr(strlen("--image=")).data(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 513 | } else if (option.starts_with("--boot-image=")) { |
| 514 | boot_image_filename = option.substr(strlen("--boot-image=")).data(); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 515 | } else if (option.starts_with("--host-prefix=")) { |
| 516 | host_prefix = option.substr(strlen("--host-prefix=")).data(); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 517 | } else if (option.starts_with("--output=")) { |
| 518 | const char* filename = option.substr(strlen("--output=")).data(); |
| 519 | out.reset(new std::ofstream(filename)); |
| 520 | if (!out->good()) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 521 | fprintf(stderr, "Failed to open output filename %s\n", filename); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 522 | usage(); |
| 523 | } |
| 524 | os = out.get(); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 525 | } else { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 526 | fprintf(stderr, "Unknown argument %s\n", option.data()); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 527 | usage(); |
| 528 | } |
| 529 | } |
| 530 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 531 | if (image_filename == NULL && oat_filename == NULL) { |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 532 | fprintf(stderr, "Either --image or --oat must be specified\n"); |
| 533 | return EXIT_FAILURE; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 536 | if (image_filename != NULL && oat_filename != NULL) { |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 537 | fprintf(stderr, "Either --image or --oat must be specified but not both\n"); |
| 538 | return EXIT_FAILURE; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | if (oat_filename != NULL) { |
| 542 | const OatFile* oat_file = OatFile::Open(oat_filename, "", NULL); |
| 543 | if (oat_file == NULL) { |
| 544 | fprintf(stderr, "Failed to open oat file from %s\n", oat_filename); |
| 545 | return EXIT_FAILURE; |
| 546 | } |
| 547 | OatDump::Dump(oat_filename, host_prefix, *os, *oat_file); |
| 548 | return EXIT_SUCCESS; |
| 549 | } |
| 550 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 551 | Runtime::Options options; |
| 552 | std::string image_option; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 553 | std::string oat_option; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 554 | std::string boot_image_option; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 555 | std::string boot_oat_option; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 556 | if (boot_image_filename != NULL) { |
| 557 | boot_image_option += "-Ximage:"; |
| 558 | boot_image_option += boot_image_filename; |
| 559 | options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL))); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 560 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 561 | if (image_filename != NULL) { |
| 562 | image_option += "-Ximage:"; |
| 563 | image_option += image_filename; |
| 564 | options.push_back(std::make_pair(image_option.c_str(), reinterpret_cast<void*>(NULL))); |
| 565 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 566 | |
| 567 | if (!host_prefix.empty()) { |
| 568 | options.push_back(std::make_pair("host-prefix", host_prefix.c_str())); |
| 569 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 570 | |
| 571 | UniquePtr<Runtime> runtime(Runtime::Create(options, false)); |
| 572 | if (runtime.get() == NULL) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 573 | fprintf(stderr, "Failed to create runtime\n"); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 574 | return EXIT_FAILURE; |
| 575 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 576 | |
| 577 | Space* image_space = Heap::GetSpaces()[Heap::GetSpaces().size()-2]; |
| 578 | CHECK(image_space != NULL); |
| 579 | const ImageHeader& image_header = image_space->GetImageHeader(); |
| 580 | if (!image_header.IsValid()) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 581 | fprintf(stderr, "Invalid image header %s\n", image_filename); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 582 | return EXIT_FAILURE; |
| 583 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 584 | ImageDump::Dump(image_filename, host_prefix, *os, *image_space, image_header); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 585 | return EXIT_SUCCESS; |
| 586 | } |
| 587 | |
| 588 | } // namespace art |
| 589 | |
| 590 | int main(int argc, char** argv) { |
| 591 | return art::oatdump(argc, argv); |
| 592 | } |