oatdump.cc revision 34f426c49ac2de8cea70acef6b9ecdd8e62209d2
178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom// Copyright 2011 Google Inc. All Rights Reserved. 278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <stdio.h> 478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <stdlib.h> 578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#include <fstream> 727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#include <iostream> 878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <string> 978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <vector> 1078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 1178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "class_linker.h" 12916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom#include "file.h" 1378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "image.h" 14916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom#include "os.h" 1578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "runtime.h" 1678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "space.h" 1778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "stringpiece.h" 18916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom#include "unordered_map.h" 1978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 2078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstromnamespace art { 2178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 2278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstromstatic void usage() { 2378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, 2478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom "Usage: oatdump [options] ...\n" 2558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom " Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art --host-prefix=$ANDROID_PRODUCT_OUT\n" 2658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom " Example: adb shell oatdump --image=/system/framework/boot.art\n" 2778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom "\n"); 2878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, 29e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom " --image=<file.art>: specifies the required input image filename.\n" 30e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom " Example: --image=/system/framework/boot.art\n" 31e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "\n"); 3278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, 33e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom " --boot-image=<file.art>: provide the image file for the boot class path.\n" 34e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom " Example: --boot-image=/system/framework/boot.art\n" 35e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "\n"); 36e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom fprintf(stderr, 3758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom " --host-prefix may be used to translate host paths to target paths during\n" 3858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom " cross compilation.\n" 3958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom " Example: --host-prefix=out/target/product/crespo\n" 4078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom "\n"); 4127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom fprintf(stderr, 4227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom " --output=<file> may be used to send the output to a file.\n" 4327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom " Example: --output=/tmp/oatdump.txt\n" 4427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom "\n"); 4578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom exit(EXIT_FAILURE); 4678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} 4778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 48ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogersconst char* image_roots_descriptions_[] = { 4978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom "kJniStubArray", 50e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "kAbstractMethodErrorStubArray", 51e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "kCalleeSaveMethod", 52e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "kOatLocation", 5358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom "kDexCaches", 5434f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom "kClassRoots", 5578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom}; 5678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 5727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstromclass OatDump { 5878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 5927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom public: 60916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom static void Dump(const std::string& image_filename, 61916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom std::ostream& os, 62916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom Space& image_space, 63916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom const ImageHeader& image_header) { 6427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os << "MAGIC:\n"; 6527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os << image_header.GetMagic() << "\n\n"; 6627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 67e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom os << "IMAGE BASE:\n"; 68e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom os << reinterpret_cast<void*>(image_header.GetImageBaseAddr()) << "\n\n"; 69e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 70e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom os << "OAT BASE:\n"; 71e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom os << reinterpret_cast<void*>(image_header.GetOatBaseAddr()) << "\n\n"; 72916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 7327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os << "ROOTS:\n"; 74418d20fc407052d4152157f61e7453359f902383Elliott Hughes CHECK_EQ(arraysize(image_roots_descriptions_), size_t(ImageHeader::kImageRootsMax)); 7527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom for (int i = 0; i < ImageHeader::kImageRootsMax; i++) { 7627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i); 7734f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom const char* image_root_description = image_roots_descriptions_[i]; 7834f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom Object* image_root_object = image_header.GetImageRoot(image_root); 7934f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom os << StringPrintf("%s: %p\n", image_root_description, image_root_object); 8034f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom if (image_root_object->IsObjectArray()) { 8134f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom // TODO: replace down_cast with AsObjectArray (g++ currently has a problem with this) 8234f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom ObjectArray<Object>* image_root_object_array 8334f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom = down_cast<ObjectArray<Object>*>(image_root_object); 8434f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom // = image_root_object->AsObjectArray<Object>(); 8534f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom for (int i = 0; i < image_root_object_array->GetLength(); i++) { 8634f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom os << StringPrintf("\t%d: %p\n", i, image_root_object_array->Get(i)); 8734f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom } 8834f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom } 8927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 9027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os << "\n"; 9127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 9227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os << "OBJECTS:\n" << std::flush; 9327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom OatDump state(image_space, os); 9427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom HeapBitmap* heap_bitmap = Heap::GetLiveBits(); 9527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom DCHECK(heap_bitmap != NULL); 9627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom heap_bitmap->Walk(OatDump::Callback, &state); 97916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 98916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 99916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "STATS:\n" << std::flush; 100916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom UniquePtr<File> file(OS::OpenFile(image_filename.c_str(), false)); 101916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state.stats_.file_bytes = file->Length(); 102e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom size_t header_bytes = sizeof(ImageHeader); 103e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom state.stats_.header_bytes = header_bytes; 104e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom size_t alignment_bytes = RoundUp(header_bytes, kObjectAlignment) - header_bytes; 105e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom state.stats_.alignment_bytes += alignment_bytes; 106916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state.stats_.Dump(os); 107916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 108916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 10978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 11078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 11127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom private: 11227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 113d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes OatDump(const Space& dump_space, std::ostream& os) : dump_space_(dump_space), os_(os) { 114d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes } 115d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes 116d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes ~OatDump() { 117d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes } 11827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 11978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom static void Callback(Object* obj, void* arg) { 12078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom DCHECK(obj != NULL); 12178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom DCHECK(arg != NULL); 12278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom OatDump* state = reinterpret_cast<OatDump*>(arg); 12378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (!state->InDumpSpace(obj)) { 12478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return; 12578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 126916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 127916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes = obj->SizeOf(); 128916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes; 129916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.object_bytes += object_bytes; 130916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.alignment_bytes += alignment_bytes; 131916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 13278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom std::string summary; 13378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "%p: ", obj); 13478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (obj->IsClass()) { 13578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Class* klass = obj->AsClass(); 13678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "CLASS %s", klass->GetDescriptor()->ToModifiedUtf8().c_str()); 137e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom std::stringstream ss; 138e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom ss << " (" << klass->GetStatus() << ")"; 139e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom summary += ss.str(); 14078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else if (obj->IsMethod()) { 14178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Method* method = obj->AsMethod(); 14278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "METHOD %s", PrettyMethod(method).c_str()); 14378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else if (obj->IsField()) { 14478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Field* field = obj->AsField(); 14578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Class* type = field->GetType(); 14678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom std::string type_string; 14778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom type_string += (type == NULL) ? "<UNKNOWN>" : type->GetDescriptor()->ToModifiedUtf8(); 14878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "FIELD %s", PrettyField(field).c_str()); 14978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else if (obj->IsArrayInstance()) { 15078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "ARRAY %d", obj->AsArray()->GetLength()); 15178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else if (obj->IsString()) { 15278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "STRING %s", obj->AsString()->ToModifiedUtf8().c_str()); 15378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else { 15478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "OBJECT"); 15578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 15678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "\n"); 157916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom std::string descriptor = obj->GetClass()->GetDescriptor()->ToModifiedUtf8(); 158916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom StringAppendF(&summary, "\tclass %p: %s\n", obj->GetClass(), descriptor.c_str()); 159916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.descriptor_to_bytes[descriptor] += object_bytes; 160916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.descriptor_to_count[descriptor] += 1; 161916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom // StringAppendF(&summary, "\tsize %d (alignment padding %d)\n", 162916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom // object_bytes, RoundUp(object_bytes, kObjectAlignment) - object_bytes); 16378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (obj->IsMethod()) { 16478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Method* method = obj->AsMethod(); 165916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom if (!method->IsPhony()) { 166e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom const ByteArray* code = method->GetCodeArray(); 167e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom const int8_t* code_base = NULL; 168e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom const int8_t* code_limit = NULL; 169e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom if (code != NULL) { 170e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom size_t code_bytes = code->GetLength(); 171e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom code_base = code->GetData(); 172e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom code_limit = code_base + code_bytes; 173e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom if (method->IsNative()) { 174e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom state->stats_.managed_to_native_code_bytes += code_bytes; 175e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom } else { 176e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom state->stats_.managed_code_bytes += code_bytes; 177e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom } 178e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } else { 179e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom code_base = reinterpret_cast<const int8_t*>(method->GetCode()); 180916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 181e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom StringAppendF(&summary, "\tCODE %p-%p\n", code_base, code_limit); 182916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 183ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers const ByteArray* invoke = method->GetInvokeStubArray(); 184e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom const int8_t* invoke_base = NULL; 185e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom const int8_t* invoke_limit = NULL; 186e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom if (invoke != NULL) { 187e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom size_t native_to_managed_code_bytes = invoke->GetLength(); 188e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom invoke_base = invoke->GetData(); 189e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom invoke_limit = invoke_base + native_to_managed_code_bytes; 190e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom state->stats_.native_to_managed_code_bytes += native_to_managed_code_bytes; 191e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom StringAppendF(&summary, "\tJNI STUB %p-%p\n", invoke_base, invoke_limit); 192e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom } 193ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers } 19478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (method->IsNative()) { 19578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (method->IsRegistered()) { 196916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom StringAppendF(&summary, "\tNATIVE REGISTERED %p\n", method->GetNativeMethod()); 19778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else { 19878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom StringAppendF(&summary, "\tNATIVE UNREGISTERED\n"); 19978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 200916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapHeader() == NULL); 201916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapData() == NULL); 202916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetMappingTable() == NULL); 203916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } else if (method->IsAbstract()) { 204916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom StringAppendF(&summary, "\tABSTRACT\n"); 205916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapHeader() == NULL); 206916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapData() == NULL); 207916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetMappingTable() == NULL); 208916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } else if (method->IsPhony()) { 209916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom StringAppendF(&summary, "\tPHONY\n"); 210916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapHeader() == NULL); 211916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetRegisterMapData() == NULL); 212916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom DCHECK(method->GetMappingTable() == NULL); 213916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } else { 214916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t register_map_bytes = (method->GetRegisterMapHeader()->GetLength() + 215916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom method->GetRegisterMapData()->GetLength()); 216916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.register_map_bytes += register_map_bytes; 217916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 218e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom if (method->GetMappingTable() != NULL) { 219e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom size_t pc_mapping_table_bytes = method->GetMappingTable()->GetLength(); 220e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom state->stats_.pc_mapping_table_bytes += pc_mapping_table_bytes; 221e10b6974d54f38001aee7bec518d45a7d4fb64c1Brian Carlstrom } 222916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 223916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); 224916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom class DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); 225916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom const DexFile& dex_file = class_linker->FindDexFile(dex_cache); 226916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->GetCodeItemOffset()); 227916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t dex_instruction_bytes = code_item->insns_size_ * 2; 228916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.dex_instruction_bytes += dex_instruction_bytes; 22978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 23078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 23127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom state->os_ << summary << std::flush; 23278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 23327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 23427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom bool InDumpSpace(const Object* object) { 23527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom const byte* o = reinterpret_cast<const byte*>(object); 23627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom return (o >= dump_space_.GetBase() && o < dump_space_.GetLimit()); 23727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 238916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 239916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom public: 240916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom struct Stats { 241916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t file_bytes; 242916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 243916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t header_bytes; 244916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes; 245916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t alignment_bytes; 246916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 247916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t managed_code_bytes; 248916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t managed_to_native_code_bytes; 249916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t native_to_managed_code_bytes; 250916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 251916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t register_map_bytes; 252916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t pc_mapping_table_bytes; 253916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 254916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t dex_instruction_bytes; 255916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 256916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom Stats() 257916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom : file_bytes(0), 258916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom header_bytes(0), 259916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom object_bytes(0), 260916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom alignment_bytes(0), 261916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_code_bytes(0), 262916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_to_native_code_bytes(0), 263916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom native_to_managed_code_bytes(0), 264916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom register_map_bytes(0), 265916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom pc_mapping_table_bytes(0), 266916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom dex_instruction_bytes(0) {} 267916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 268916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom typedef std::tr1::unordered_map<std::string,size_t> TableBytes; 269916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom TableBytes descriptor_to_bytes; 270916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 271916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom typedef std::tr1::unordered_map<std::string,size_t> TableCount; 272916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom TableCount descriptor_to_count; 273916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 274916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double PercentOfFileBytes(size_t size) { 275916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100; 276916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 277916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 278916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double PercentOfObjectBytes(size_t size) { 279916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100; 280916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 281916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 282916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom void Dump(std::ostream& os) { 283916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tfile_bytes = %d\n", file_bytes); 284916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 285916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 286916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\tfile_bytes = header_bytes + object_bytes + alignment_bytes\n"; 287916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\theader_bytes = %10d (%2.0f%% of file_bytes)\n", 288916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom header_bytes, PercentOfFileBytes(header_bytes)); 289916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tobject_bytes = %10d (%2.0f%% of file_bytes)\n", 290916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom object_bytes, PercentOfFileBytes(object_bytes)); 291916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\talignment_bytes = %10d (%2.0f%% of file_bytes)\n", 292916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom alignment_bytes, PercentOfFileBytes(alignment_bytes)); 293916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 294916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 295916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom CHECK_EQ(file_bytes, header_bytes + object_bytes + alignment_bytes); 296916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 297916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\tobject_bytes = sum of descriptor_to_bytes values below:\n"; 298916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes_total = 0; 299916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom typedef TableBytes::const_iterator It; // TODO: C++0x auto 300916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom for (It it = descriptor_to_bytes.begin(), end = descriptor_to_bytes.end(); it != end; ++it) { 301916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom const std::string& descriptor = it->first; 302916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t bytes = it->second; 303916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t count = descriptor_to_count[descriptor]; 304916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double average = static_cast<double>(bytes) / static_cast<double>(count); 305916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double percent = PercentOfObjectBytes(bytes); 306f153fe1ff3c901a1c63b6ec5495c5046869a60e3Brian Carlstrom os << StringPrintf("\t%32s %8d bytes %6d instances " 307916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom "(%3.0f bytes/instance) %2.0f%% of object_bytes\n", 308916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom descriptor.c_str(), bytes, count, 309916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom average, percent); 310916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 311916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom object_bytes_total += bytes; 312916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 313916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 314916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 315916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom CHECK_EQ(object_bytes, object_bytes_total); 316916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 317916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tmanaged_code_bytes = %8d (%2.0f%% of object_bytes)\n", 318916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_code_bytes, PercentOfObjectBytes(managed_code_bytes)); 319916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tmanaged_to_native_code_bytes = %8d (%2.0f%% of object_bytes)\n", 320916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_to_native_code_bytes, 321916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom PercentOfObjectBytes(managed_to_native_code_bytes)); 322916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tnative_to_managed_code_bytes = %8d (%2.0f%% of object_bytes)\n", 323916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom native_to_managed_code_bytes, 324916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom PercentOfObjectBytes(native_to_managed_code_bytes)); 325916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 326916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 327916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 328916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tregister_map_bytes = %7d (%2.0f%% of object_bytes)\n", 329916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom register_map_bytes, PercentOfObjectBytes(register_map_bytes)); 330916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tpc_mapping_table_bytes = %7d (%2.0f%% of object_bytes)\n", 331916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom pc_mapping_table_bytes, PercentOfObjectBytes(pc_mapping_table_bytes)); 332916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 333916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 334916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 335916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tdex_instruction_bytes = %d\n", dex_instruction_bytes); 336916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << StringPrintf("\tmanaged_code_bytes expansion = %.2f\n", 337916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom static_cast<double>(managed_code_bytes) 338916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom / static_cast<double>(dex_instruction_bytes)); 339916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << "\n"; 340916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom os << std::flush; 341916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 342916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 343916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } stats_; 344916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 345916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom private: 34627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom const Space& dump_space_; 34727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::ostream& os_; 348d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes 349d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes DISALLOW_COPY_AND_ASSIGN(OatDump); 35078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom}; 35178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 35278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstromint oatdump(int argc, char** argv) { 35378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom // Skip over argv[0]. 35478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom argv++; 35578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom argc--; 35678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 35778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (argc == 0) { 35878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, "no arguments specified\n"); 35978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom usage(); 36078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 36178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 36278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom const char* image_filename = NULL; 36378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom const char* boot_image_filename = NULL; 36458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom std::string host_prefix; 36527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom std::ostream* os = &std::cout; 36627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom UniquePtr<std::ofstream> out; 36778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 36878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom for (int i = 0; i < argc; i++) { 36978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom const StringPiece option(argv[i]); 37058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom if (option.starts_with("--image=")) { 37178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom image_filename = option.substr(strlen("--image=")).data(); 372e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } else if (option.starts_with("--boot-image=")) { 373e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom boot_image_filename = option.substr(strlen("--boot-image=")).data(); 37458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } else if (option.starts_with("--host-prefix=")) { 37558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom host_prefix = option.substr(strlen("--host-prefix=")).data(); 37627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } else if (option.starts_with("--output=")) { 37727ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom const char* filename = option.substr(strlen("--output=")).data(); 37827ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom out.reset(new std::ofstream(filename)); 37927ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom if (!out->good()) { 38027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom fprintf(stderr, "failed to open output filename %s\n", filename); 38127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom usage(); 38227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 38327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom os = out.get(); 38478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else { 38578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, "unknown argument %s\n", option.data()); 38678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom usage(); 38778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 38878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 38978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 39078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (image_filename == NULL) { 39178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, "--image file name not specified\n"); 39278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return EXIT_FAILURE; 39378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 39478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 39578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Runtime::Options options; 39678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom std::string image_option; 397e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom std::string oat_option; 39878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom std::string boot_image_option; 399e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom std::string boot_oat_option; 40058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom if (boot_image_filename != NULL) { 40158ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom boot_image_option += "-Ximage:"; 40258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom boot_image_option += boot_image_filename; 40358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL))); 40458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 40558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom image_option += "-Ximage:"; 40658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom image_option += image_filename; 40758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom options.push_back(std::make_pair(image_option.c_str(), reinterpret_cast<void*>(NULL))); 40858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 40958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom if (!host_prefix.empty()) { 41058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom options.push_back(std::make_pair("host-prefix", host_prefix.c_str())); 41178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 41278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 41378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom UniquePtr<Runtime> runtime(Runtime::Create(options, false)); 41478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (runtime.get() == NULL) { 41578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, "could not create runtime\n"); 41678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return EXIT_FAILURE; 41778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 41878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 41978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom Space* image_space = Heap::GetSpaces()[Heap::GetSpaces().size()-2]; 42078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom CHECK(image_space != NULL); 42178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom const ImageHeader& image_header = image_space->GetImageHeader(); 42278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (!image_header.IsValid()) { 42378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom fprintf(stderr, "invalid image header %s\n", image_filename); 42478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return EXIT_FAILURE; 42578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 426916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom OatDump::Dump(image_filename, *os, *image_space, image_header); 42778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return EXIT_SUCCESS; 42878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} 42978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 43078128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} // namespace art 43178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 43278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstromint main(int argc, char** argv) { 43378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return art::oatdump(argc, argv); 43478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} 435