oatdump.cc revision 796d63050a18f263b93ea34951a61deaecab3422
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/* 22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project 32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License. 62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at 72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software 112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and 142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License. 152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */ 1678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 1778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <stdio.h> 1878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <stdlib.h> 1978128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 2027ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#include <fstream> 2127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom#include <iostream> 223774335b08076117d6950cd472cdd59a167470b5Igor Murashkin#include <map> 233774335b08076117d6950cd472cdd59a167470b5Igor Murashkin#include <set> 2478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <string> 2554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe#include <unordered_map> 2678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include <vector> 2778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 28d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#include "arch/instruction_set_features.h" 29c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier#include "art_field-inl.h" 30e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "art_method-inl.h" 3110c13565474de2786aad7c2e79757ea250747a15Vladimir Marko#include "base/stl_util.h" 32761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/unix_file/fd_file.h" 3378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom#include "class_linker.h" 342dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "class_linker-inl.h" 355d950769b607b4f76413212db640a32d796911deDavid Srbecky#include "debug/elf_debug_writer.h" 365d950769b607b4f76413212db640a32d796911deDavid Srbecky#include "debug/method_debug_info.h" 374f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers#include "dex_file-inl.h" 38e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes#include "dex_instruction.h" 393a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers#include "disassembler.h" 4054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe#include "elf_builder.h" 412bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers#include "gc_map.h" 421d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/space/image_space.h" 431d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/space/large_object_space.h" 441d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/space/space-inl.h" 454a26f17b055cadc949c3e9fdfa637fe5656339d9Mathieu Chartier#include "image-inl.h" 462bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers#include "indenter.h" 47131980fc9aeb2b4d03480443e0fb494c76ce03a2Vladimir Marko#include "linker/buffered_output_stream.h" 48131980fc9aeb2b4d03480443e0fb494c76ce03a2Vladimir Marko#include "linker/file_output_stream.h" 491809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers#include "mapping_table.h" 502dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/array-inl.h" 512dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/class-inl.h" 5205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko#include "mirror/dex_cache-inl.h" 532dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object-inl.h" 542dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object_array-inl.h" 55700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom#include "oat.h" 568a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko#include "oat_file-inl.h" 57f9c6fc610b27887f832e453a0da1789187293408Mathieu Chartier#include "oat_file_manager.h" 58e5448b5a12003b405b22cde3b94f962ab4888a87Elliott Hughes#include "os.h" 59a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "safe_map.h" 6000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "scoped_thread_state_change.h" 616bc4374e3fa00e3ee5e832e1761c43e0b8a71558Nicolas Geoffray#include "stack_map.h" 6200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe#include "ScopedLocalRef.h" 63c22c59ef8513b4cbbfd25073d1afbf58196b522aMathieu Chartier#include "thread_list.h" 64ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers#include "verifier/dex_gc_map.h" 652bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers#include "verifier/method_verifier.h" 661809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers#include "vmap_table.h" 6700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe#include "well_known_classes.h" 6878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 693774335b08076117d6950cd472cdd59a167470b5Igor Murashkin#include <sys/stat.h> 703774335b08076117d6950cd472cdd59a167470b5Igor Murashkin#include "cmdline.h" 7178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 723774335b08076117d6950cd472cdd59a167470b5Igor Murashkinnamespace art { 7378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 74e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartierconst char* image_methods_descriptions_[] = { 751984651929744dd603fd082e23eacd877b9bc177Ian Rogers "kResolutionMethod", 7688474b416eb257078e590bf9bc7957cee604a186Jeff Hao "kImtConflictMethod", 772d2621a1463d2f3f03fa73503fa42e43657cdcfcMathieu Chartier "kImtUnimplementedMethod", 78e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom "kCalleeSaveMethod", 79aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom "kRefsOnlySaveMethod", 80aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom "kRefsAndArgsSaveMethod", 81e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier}; 82e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 83e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartierconst char* image_roots_descriptions_[] = { 8458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom "kDexCaches", 8534f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom "kClassRoots", 8678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom}; 8778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 88ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier// Map is so that we don't allocate multiple dex files for the same OatDexFile. 89ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartierstatic std::map<const OatFile::OatDexFile*, 90ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier std::unique_ptr<const DexFile>> opened_dex_files; 91ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier 92ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartierconst DexFile* OpenDexFile(const OatFile::OatDexFile* oat_dex_file, std::string* error_msg) { 93ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier DCHECK(oat_dex_file != nullptr); 94ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier auto it = opened_dex_files.find(oat_dex_file); 95ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (it != opened_dex_files.end()) { 96ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier return it->second.get(); 97ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier } 98ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* ret = oat_dex_file->OpenDexFile(error_msg).release(); 99ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier opened_dex_files.emplace(oat_dex_file, std::unique_ptr<const DexFile>(ret)); 100ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier return ret; 101ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier} 102ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier 1032d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampetemplate <typename ElfTypes> 104bc90fd09e09a845ae6ea0d84ad67560575a94142David Srbeckyclass OatSymbolizer FINAL { 10554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe public: 1062fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky OatSymbolizer(const OatFile* oat_file, const std::string& output_name, bool no_bits) : 1072fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky oat_file_(oat_file), 1082fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky builder_(nullptr), 1092fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky output_name_(output_name.empty() ? "symbolized.oat" : output_name), 1102fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky no_bits_(no_bits) { 11154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 11254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 11354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe bool Symbolize() { 1146d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky const InstructionSet isa = oat_file_->GetOatHeader().GetInstructionSet(); 1155d8112029d0e085c5a0099257daa4c7e29c12310David Srbecky const InstructionSetFeatures* features = InstructionSetFeatures::FromBitmap( 1165d8112029d0e085c5a0099257daa4c7e29c12310David Srbecky isa, oat_file_->GetOatHeader().GetInstructionSetFeaturesBitmap()); 1176d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1186d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky File* elf_file = OS::CreateEmptyFile(output_name_.c_str()); 1196d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky std::unique_ptr<BufferedOutputStream> output_stream( 12010c13565474de2786aad7c2e79757ea250747a15Vladimir Marko MakeUnique<BufferedOutputStream>(MakeUnique<FileOutputStream>(elf_file))); 1212d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe builder_.reset(new ElfBuilder<ElfTypes>(isa, features, output_stream.get())); 1226d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1236d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky builder_->Start(); 1246d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1256d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky auto* rodata = builder_->GetRoData(); 1266d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky auto* text = builder_->GetText(); 1276d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky auto* bss = builder_->GetBss(); 1286d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1296d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky const uint8_t* rodata_begin = oat_file_->Begin(); 1306d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset(); 1312fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky if (no_bits_) { 1322fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky rodata->WriteNoBitsSection(rodata_size); 1332fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky } else { 1342fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky rodata->Start(); 1352fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky rodata->WriteFully(rodata_begin, rodata_size); 1362fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky rodata->End(); 1372fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky } 1386d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1396d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky const uint8_t* text_begin = oat_file_->Begin() + rodata_size; 1406d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky const size_t text_size = oat_file_->End() - text_begin; 1412fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky if (no_bits_) { 1422fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky text->WriteNoBitsSection(text_size); 1432fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky } else { 1442fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky text->Start(); 1452fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky text->WriteFully(text_begin, text_size); 1462fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky text->End(); 1472fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky } 1486d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 1496d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky if (oat_file_->BssSize() != 0) { 1505b1c2ca30dad519be285f0a1e839c23cc4e3a51dDavid Srbecky bss->WriteNoBitsSection(oat_file_->BssSize()); 1516d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky } 1526d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky 153316a2186b7fa9e03187d45ac0fa320f4dff1f3dfDouglas Leung if (isa == kMips || isa == kMips64) { 154316a2186b7fa9e03187d45ac0fa320f4dff1f3dfDouglas Leung builder_->WriteMIPSabiflagsSection(); 155316a2186b7fa9e03187d45ac0fa320f4dff1f3dfDouglas Leung } 156944da603cde59a4277f3bbc31d860a90842a1a2aVladimir Marko builder_->PrepareDynamicSection( 157944da603cde59a4277f3bbc31d860a90842a1a2aVladimir Marko elf_file->GetPath(), rodata_size, text_size, oat_file_->BssSize()); 158944da603cde59a4277f3bbc31d860a90842a1a2aVladimir Marko builder_->WriteDynamicSection(); 15954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 1605d950769b607b4f76413212db640a32d796911deDavid Srbecky Walk(); 1615d950769b607b4f76413212db640a32d796911deDavid Srbecky for (const auto& trampoline : debug::MakeTrampolineInfos(oat_file_->GetOatHeader())) { 1625d950769b607b4f76413212db640a32d796911deDavid Srbecky method_debug_infos_.push_back(trampoline); 1635d950769b607b4f76413212db640a32d796911deDavid Srbecky } 16454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 1655d950769b607b4f76413212db640a32d796911deDavid Srbecky debug::WriteDebugInfo(builder_.get(), 1665d950769b607b4f76413212db640a32d796911deDavid Srbecky ArrayRef<const debug::MethodDebugInfo>(method_debug_infos_), 1675d950769b607b4f76413212db640a32d796911deDavid Srbecky dwarf::DW_DEBUG_FRAME_FORMAT, 1685d950769b607b4f76413212db640a32d796911deDavid Srbecky true /* write_oat_patches */); 16954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 1706d8c8f0344a706df651567387ede683ab3ec1b5fDavid Srbecky builder_->End(); 17154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 17210c13565474de2786aad7c2e79757ea250747a15Vladimir Marko return builder_->Good(); 17354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 17454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 1755d950769b607b4f76413212db640a32d796911deDavid Srbecky void Walk() { 17654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file_->GetOatDexFiles(); 17754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe for (size_t i = 0; i < oat_dex_files.size(); i++) { 17854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i]; 1792cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier CHECK(oat_dex_file != nullptr); 1805d950769b607b4f76413212db640a32d796911deDavid Srbecky WalkOatDexFile(oat_dex_file); 18154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 18254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 18354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 1845d950769b607b4f76413212db640a32d796911deDavid Srbecky void WalkOatDexFile(const OatFile::OatDexFile* oat_dex_file) { 18554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe std::string error_msg; 186ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); 187ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (dex_file == nullptr) { 18854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe return; 18954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 19054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe for (size_t class_def_index = 0; 19154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe class_def_index < dex_file->NumClassDefs(); 19254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe class_def_index++) { 19354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); 19454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe OatClassType type = oat_class.GetType(); 19554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe switch (type) { 19654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe case kOatClassAllCompiled: 19754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe case kOatClassSomeCompiled: 1985d950769b607b4f76413212db640a32d796911deDavid Srbecky WalkOatClass(oat_class, *dex_file, class_def_index); 19954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe break; 20054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 20154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe case kOatClassNoneCompiled: 20254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe case kOatClassMax: 20354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe // Ignore. 20454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe break; 20554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 20654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 20754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 20854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2095d950769b607b4f76413212db640a32d796911deDavid Srbecky void WalkOatClass(const OatFile::OatClass& oat_class, 2105d950769b607b4f76413212db640a32d796911deDavid Srbecky const DexFile& dex_file, 2115d950769b607b4f76413212db640a32d796911deDavid Srbecky uint32_t class_def_index) { 2125d950769b607b4f76413212db640a32d796911deDavid Srbecky const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); 21313735955f39b3b304c37d2b2840663c131262c18Ian Rogers const uint8_t* class_data = dex_file.GetClassData(class_def); 21454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe if (class_data == nullptr) { // empty class such as a marker interface? 21554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe return; 21654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 21754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe // Note: even if this is an interface or a native class, we still have to walk it, as there 21854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe // might be a static initializer. 21954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe ClassDataItemIterator it(dex_file, class_data); 22054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe uint32_t class_method_idx = 0; 2215d950769b607b4f76413212db640a32d796911deDavid Srbecky for (; it.HasNextStaticField(); it.Next()) { /* skip */ } 2225d950769b607b4f76413212db640a32d796911deDavid Srbecky for (; it.HasNextInstanceField(); it.Next()) { /* skip */ } 2235d950769b607b4f76413212db640a32d796911deDavid Srbecky for (; it.HasNextDirectMethod() || it.HasNextVirtualMethod(); it.Next()) { 2245d950769b607b4f76413212db640a32d796911deDavid Srbecky WalkOatMethod(oat_class.GetOatMethod(class_method_idx++), 2255d950769b607b4f76413212db640a32d796911deDavid Srbecky dex_file, 2265d950769b607b4f76413212db640a32d796911deDavid Srbecky class_def_index, 2275d950769b607b4f76413212db640a32d796911deDavid Srbecky it.GetMemberIndex(), 2285d950769b607b4f76413212db640a32d796911deDavid Srbecky it.GetMethodCodeItem(), 2295d950769b607b4f76413212db640a32d796911deDavid Srbecky it.GetMethodAccessFlags()); 23054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 23154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe DCHECK(!it.HasNext()); 23254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 23354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2345d950769b607b4f76413212db640a32d796911deDavid Srbecky void WalkOatMethod(const OatFile::OatMethod& oat_method, 2355d950769b607b4f76413212db640a32d796911deDavid Srbecky const DexFile& dex_file, 2365d950769b607b4f76413212db640a32d796911deDavid Srbecky uint32_t class_def_index, 2375d950769b607b4f76413212db640a32d796911deDavid Srbecky uint32_t dex_method_index, 2385d950769b607b4f76413212db640a32d796911deDavid Srbecky const DexFile::CodeItem* code_item, 2395d950769b607b4f76413212db640a32d796911deDavid Srbecky uint32_t method_access_flags) { 24054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe if ((method_access_flags & kAccAbstract) != 0) { 24154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe // Abstract method, no code. 24254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe return; 24354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 2445d950769b607b4f76413212db640a32d796911deDavid Srbecky const OatHeader& oat_header = oat_file_->GetOatHeader(); 2455d950769b607b4f76413212db640a32d796911deDavid Srbecky const OatQuickMethodHeader* method_header = oat_method.GetOatQuickMethodHeader(); 2465d950769b607b4f76413212db640a32d796911deDavid Srbecky if (method_header == nullptr || method_header->GetCodeSize() == 0) { 24754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe // No code. 24854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe return; 24954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 25054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2515d950769b607b4f76413212db640a32d796911deDavid Srbecky debug::MethodDebugInfo info = debug::MethodDebugInfo(); 2525d950769b607b4f76413212db640a32d796911deDavid Srbecky info.trampoline_name = nullptr; 2535d950769b607b4f76413212db640a32d796911deDavid Srbecky info.dex_file = &dex_file; 2545d950769b607b4f76413212db640a32d796911deDavid Srbecky info.class_def_index = class_def_index; 2555d950769b607b4f76413212db640a32d796911deDavid Srbecky info.dex_method_index = dex_method_index; 2565d950769b607b4f76413212db640a32d796911deDavid Srbecky info.access_flags = method_access_flags; 2575d950769b607b4f76413212db640a32d796911deDavid Srbecky info.code_item = code_item; 2585d950769b607b4f76413212db640a32d796911deDavid Srbecky info.isa = oat_header.GetInstructionSet(); 2595d950769b607b4f76413212db640a32d796911deDavid Srbecky info.deduped = !seen_offsets_.insert(oat_method.GetCodeOffset()).second; 2605d950769b607b4f76413212db640a32d796911deDavid Srbecky info.is_native_debuggable = oat_header.IsNativeDebuggable(); 2615d950769b607b4f76413212db640a32d796911deDavid Srbecky info.is_optimized = method_header->IsOptimized(); 2625d950769b607b4f76413212db640a32d796911deDavid Srbecky info.is_code_address_text_relative = true; 2635d950769b607b4f76413212db640a32d796911deDavid Srbecky info.code_address = oat_method.GetCodeOffset() - oat_header.GetExecutableOffset(); 2645d950769b607b4f76413212db640a32d796911deDavid Srbecky info.code_size = method_header->GetCodeSize(); 2655d950769b607b4f76413212db640a32d796911deDavid Srbecky info.frame_size_in_bytes = method_header->GetFrameSizeInBytes(); 2665d950769b607b4f76413212db640a32d796911deDavid Srbecky info.code_info = info.is_optimized ? method_header->GetOptimizedCodeInfoPtr() : nullptr; 2675d950769b607b4f76413212db640a32d796911deDavid Srbecky info.cfi = ArrayRef<uint8_t>(); 2685d950769b607b4f76413212db640a32d796911deDavid Srbecky method_debug_infos_.push_back(info); 26954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe } 27054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 27154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe private: 27254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe const OatFile* oat_file_; 2732d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe std::unique_ptr<ElfBuilder<ElfTypes> > builder_; 2745d950769b607b4f76413212db640a32d796911deDavid Srbecky std::vector<debug::MethodDebugInfo> method_debug_infos_; 2755d950769b607b4f76413212db640a32d796911deDavid Srbecky std::unordered_set<uint32_t> seen_offsets_; 2760279ebb3efd653e6bb255470c99d26949c7bcd95Ian Rogers const std::string output_name_; 2772fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky bool no_bits_; 27854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe}; 27954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2802cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstromclass OatDumperOptions { 2812cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom public: 2822cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom OatDumperOptions(bool dump_raw_mapping_table, 2832cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool dump_raw_gc_map, 2842cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool dump_vmap, 285f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain bool dump_code_info_stack_maps, 2862cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool disassemble_code, 28700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool absolute_addresses, 28832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* class_filter, 28932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* method_filter, 29032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool list_classes, 29132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool list_methods, 292c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil bool dump_header_only, 29332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* export_dex_location, 2940b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* app_image, 2950b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* app_oat, 29632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t addr2instr) 2972cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom : dump_raw_mapping_table_(dump_raw_mapping_table), 2982cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom dump_raw_gc_map_(dump_raw_gc_map), 2992cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom dump_vmap_(dump_vmap), 300f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain dump_code_info_stack_maps_(dump_code_info_stack_maps), 3012cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom disassemble_code_(disassemble_code), 30200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe absolute_addresses_(absolute_addresses), 30332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis class_filter_(class_filter), 3043fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray method_filter_(method_filter), 30532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis list_classes_(list_classes), 30632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis list_methods_(list_methods), 307c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil dump_header_only_(dump_header_only), 30832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis export_dex_location_(export_dex_location), 3090b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier app_image_(app_image), 3100b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier app_oat_(app_oat), 31132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis addr2instr_(addr2instr), 3123774335b08076117d6950cd472cdd59a167470b5Igor Murashkin class_loader_(nullptr) {} 3132cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 3142cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const bool dump_raw_mapping_table_; 3152cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const bool dump_raw_gc_map_; 3162cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const bool dump_vmap_; 317f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const bool dump_code_info_stack_maps_; 3182cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const bool disassemble_code_; 3192cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const bool absolute_addresses_; 32032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* const class_filter_; 3213fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray const char* const method_filter_; 32232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const bool list_classes_; 32332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const bool list_methods_; 324c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil const bool dump_header_only_; 32532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* const export_dex_location_; 3260b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* const app_image_; 3270b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* const app_oat_; 32832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t addr2instr_; 32900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe Handle<mirror::ClassLoader>* class_loader_; 3302cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom}; 3312cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 332e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughesclass OatDumper { 333aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom public: 3343887c468d731420e929e6ad3acf190d5431e94fcRoland Levillain OatDumper(const OatFile& oat_file, const OatDumperOptions& options) 3359583fbcf597eff6d0b3c5359b8e8d5f70ed82c40Nicolas Geoffray : oat_file_(oat_file), 336a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes oat_dex_files_(oat_file.GetOatDexFiles()), 3372cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom options_(options), 33832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis resolved_addr2instr_(0), 339a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier instruction_set_(oat_file_.GetOatHeader().GetInstructionSet()), 340a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier disassembler_(Disassembler::Create(instruction_set_, 34132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis new DisassemblerOptions(options_.absolute_addresses_, 342a37d925d405be9f589ac282869a997e73414d859Alexandre Rames oat_file.Begin(), 343eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames true /* can_read_literals_ */))) { 34432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis CHECK(options_.class_loader_ != nullptr); 34532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis CHECK(options_.class_filter_ != nullptr); 34632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis CHECK(options_.method_filter_ != nullptr); 3473a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers AddAllOffsets(); 3483a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 3493a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 3502cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom ~OatDumper() { 3512cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom delete disassembler_; 3522cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 3532cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 354a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier InstructionSet GetInstructionSet() { 355a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier return instruction_set_; 356a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier } 357a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier 3582cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool Dump(std::ostream& os) { 3592cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool success = true; 3603a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers const OatHeader& oat_header = oat_file_.GetOatHeader(); 361aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 362aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << "MAGIC:\n"; 363aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << oat_header.GetMagic() << "\n\n"; 364aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 3654b07a6e518a42eac43f5746e646e90a7865beb83Jeff Hao os << "LOCATION:\n"; 3664b07a6e518a42eac43f5746e646e90a7865beb83Jeff Hao os << oat_file_.GetLocation() << "\n\n"; 3674b07a6e518a42eac43f5746e646e90a7865beb83Jeff Hao 368aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << "CHECKSUM:\n"; 369ed2adb6158ffbe85c89aa5c9892a35bafa5006cdElliott Hughes os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum()); 370aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 371a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes os << "INSTRUCTION SET:\n"; 372a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes os << oat_header.GetInstructionSet() << "\n\n"; 373a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes 3746f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers { 3756f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers std::unique_ptr<const InstructionSetFeatures> features( 3766f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers InstructionSetFeatures::FromBitmap(oat_header.GetInstructionSet(), 3776f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers oat_header.GetInstructionSetFeaturesBitmap())); 3786f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers os << "INSTRUCTION SET FEATURES:\n"; 3796f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers os << features->GetFeatureString() << "\n\n"; 3806f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers } 3817020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison 382aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << "DEX FILE COUNT:\n"; 383aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << oat_header.GetDexFileCount() << "\n\n"; 384aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 3852ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom#define DUMP_OAT_HEADER_OFFSET(label, offset) \ 3862ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom os << label " OFFSET:\n"; \ 3872ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom os << StringPrintf("0x%08x", oat_header.offset()); \ 38832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (oat_header.offset() != 0 && options_.absolute_addresses_) { \ 3892ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom os << StringPrintf(" (%p)", oat_file_.Begin() + oat_header.offset()); \ 3902ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom } \ 3912ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom os << StringPrintf("\n\n"); 3922ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom 3932ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("EXECUTABLE", GetExecutableOffset); 3942ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("INTERPRETER TO INTERPRETER BRIDGE", 3952ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetInterpreterToInterpreterBridgeOffset); 3962ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("INTERPRETER TO COMPILED CODE BRIDGE", 3972ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetInterpreterToCompiledCodeBridgeOffset); 3982ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("JNI DLSYM LOOKUP", 3992ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetJniDlsymLookupOffset); 4002ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("QUICK GENERIC JNI TRAMPOLINE", 4012ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetQuickGenericJniTrampolineOffset); 4022ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("QUICK IMT CONFLICT TRAMPOLINE", 4032ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetQuickImtConflictTrampolineOffset); 4042ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("QUICK RESOLUTION TRAMPOLINE", 4052ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetQuickResolutionTrampolineOffset); 4062ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom DUMP_OAT_HEADER_OFFSET("QUICK TO INTERPRETER BRIDGE", 4072ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom GetQuickToInterpreterBridgeOffset); 4082ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom#undef DUMP_OAT_HEADER_OFFSET 409aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 4102cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << "IMAGE PATCH DELTA:\n"; 4112cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << StringPrintf("%d (0x%08x)\n\n", 4122cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom oat_header.GetImagePatchDelta(), 4132cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom oat_header.GetImagePatchDelta()); 414a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light 41528db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom os << "IMAGE FILE LOCATION OAT CHECKSUM:\n"; 41628db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatChecksum()); 41728db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom 41828db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom os << "IMAGE FILE LOCATION OAT BEGIN:\n"; 419700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatDataBegin()); 42081f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom 42122f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe // Print the key-value store. 42222f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe { 42322f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe os << "KEY VALUE STORE:\n"; 42422f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe size_t index = 0; 42522f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe const char* key; 42622f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe const char* value; 42722f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe while (oat_header.GetStoreKeyValuePairByIndex(index, &key, &value)) { 42822f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe os << key << " = " << value << "\n"; 42922f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe index++; 43022f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe } 43122f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe os << "\n"; 43222f8e5c82d12951be38cd893426e13bee33fd69dAndreas Gampe } 43381f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom 43432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 4352cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << "BEGIN:\n"; 4362cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << reinterpret_cast<const void*>(oat_file_.Begin()) << "\n\n"; 4372cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 4382cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << "END:\n"; 4392cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << reinterpret_cast<const void*>(oat_file_.End()) << "\n\n"; 4402cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 441aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 4422cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << "SIZE:\n"; 4432cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << oat_file_.Size() << "\n\n"; 444aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 445aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << std::flush; 446aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 44732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // If set, adjust relative address to be searched 44832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.addr2instr_ != 0) { 44932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis resolved_addr2instr_ = options_.addr2instr_ + oat_header.GetExecutableOffset(); 45032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "SEARCH ADDRESS (executable offset + input):\n"; 45132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << StringPrintf("0x%08x\n\n", resolved_addr2instr_); 45232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 45332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 454c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil if (!options_.dump_header_only_) { 455c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil for (size_t i = 0; i < oat_dex_files_.size(); i++) { 456c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; 457c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil CHECK(oat_dex_file != nullptr); 45832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 459c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil // If file export selected skip file analysis 460c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil if (options_.export_dex_location_) { 461c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil if (!ExportDexFile(os, *oat_dex_file)) { 462c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil success = false; 463c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil } 464c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil } else { 465c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil if (!DumpOatDexFile(os, *oat_dex_file)) { 466c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil success = false; 467c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil } 46832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 4692cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 4703a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 471c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil 4722cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << std::flush; 4732cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return success; 4743a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 4753a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 4763a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t ComputeSize(const void* oat_data) { 47713735955f39b3b304c37d2b2840663c131262c18Ian Rogers if (reinterpret_cast<const uint8_t*>(oat_data) < oat_file_.Begin() || 47813735955f39b3b304c37d2b2840663c131262c18Ian Rogers reinterpret_cast<const uint8_t*>(oat_data) > oat_file_.End()) { 4793a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return 0; // Address not in oat file 4803a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 481ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uintptr_t begin_offset = reinterpret_cast<uintptr_t>(oat_data) - 482ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers reinterpret_cast<uintptr_t>(oat_file_.Begin()); 483ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers auto it = offsets_.upper_bound(begin_offset); 4843a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers CHECK(it != offsets_.end()); 485ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uintptr_t end_offset = *it; 4863a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return end_offset - begin_offset; 4873a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 488e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 489a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier InstructionSet GetOatInstructionSet() { 490f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom return oat_file_.GetOatHeader().GetInstructionSet(); 491f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 492f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom 49390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier const void* GetQuickOatCode(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_) { 4943a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 0; i < oat_dex_files_.size(); i++) { 4953a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; 4968d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers CHECK(oat_dex_file != nullptr); 4978d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string error_msg; 498ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); 499ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (dex_file == nullptr) { 5008d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() 5018d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers << "': " << error_msg; 5028d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers } else { 503e7c9a8c2b8481aafbc6af4ce6229bd361ba24742Mathieu Chartier const char* descriptor = m->GetDeclaringClassDescriptor(); 5048b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers const DexFile::ClassDef* class_def = 505e7c9a8c2b8481aafbc6af4ce6229bd361ba24742Mathieu Chartier dex_file->FindClassDef(descriptor, ComputeModifiedUtf8Hash(descriptor)); 5062ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (class_def != nullptr) { 5078b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); 508d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); 5093a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t method_index = m->GetMethodIndex(); 510d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko return oat_class.GetOatMethod(method_index).GetQuickCode(); 5113a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 5123a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 513aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 5142ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe return nullptr; 515aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 516aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 517aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom private: 5183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers void AddAllOffsets() { 519e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // We don't know the length of the code for each method, but we need to know where to stop 520e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // when disassembling. What we do know is that a region of code will be followed by some other 521e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // region, so if we keep a sorted sequence of the start of each region, we can infer the length 522e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // of a piece of code by using upper_bound to find the start of the next region. 5233a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 0; i < oat_dex_files_.size(); i++) { 5243a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; 5252ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe CHECK(oat_dex_file != nullptr); 5268d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string error_msg; 527ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); 528ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (dex_file == nullptr) { 5298d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() 5308d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers << "': " << error_msg; 5313a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers continue; 532e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 533ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers offsets_.insert(reinterpret_cast<uintptr_t>(&dex_file->GetHeader())); 5342ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom for (size_t class_def_index = 0; 5352ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom class_def_index < dex_file->NumClassDefs(); 5362ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom class_def_index++) { 537e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); 538d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); 53913735955f39b3b304c37d2b2840663c131262c18Ian Rogers const uint8_t* class_data = dex_file->GetClassData(class_def); 5402ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (class_data != nullptr) { 541e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes ClassDataItemIterator it(*dex_file, class_data); 542e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes SkipAllFields(it); 543e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes uint32_t class_method_index = 0; 544e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes while (it.HasNextDirectMethod()) { 545d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko AddOffsets(oat_class.GetOatMethod(class_method_index++)); 546e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes it.Next(); 547e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 548e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes while (it.HasNextVirtualMethod()) { 549d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko AddOffsets(oat_class.GetOatMethod(class_method_index++)); 550e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes it.Next(); 551e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 552e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 553e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 554e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 555e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 556e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // If the last thing in the file is code for a method, there won't be an offset for the "next" 557e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // thing. Instead of having a special case in the upper_bound code, let's just add an entry 558e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes // for the end of the file. 559ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers offsets_.insert(oat_file_.Size()); 560e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 561e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 5622cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom static uint32_t AlignCodeOffset(uint32_t maybe_thumb_offset) { 5632cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return maybe_thumb_offset & ~0x1; // TODO: Make this Thumb2 specific. 5642cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 5652cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 566e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes void AddOffsets(const OatFile::OatMethod& oat_method) { 56795ba0dc516531776813c426e85ce868ead564a7bBrian Carlstrom uint32_t code_offset = oat_method.GetCodeOffset(); 56895ba0dc516531776813c426e85ce868ead564a7bBrian Carlstrom if (oat_file_.GetOatHeader().GetInstructionSet() == kThumb2) { 56995ba0dc516531776813c426e85ce868ead564a7bBrian Carlstrom code_offset &= ~0x1; 57095ba0dc516531776813c426e85ce868ead564a7bBrian Carlstrom } 57195ba0dc516531776813c426e85ce868ead564a7bBrian Carlstrom offsets_.insert(code_offset); 572e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes offsets_.insert(oat_method.GetMappingTableOffset()); 573e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes offsets_.insert(oat_method.GetVmapTableOffset()); 574957ca1cd025104fccb0b08928f955f9bdb4ab91cMathieu Chartier offsets_.insert(oat_method.GetGcMapOffset()); 575e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 576e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 5772cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool DumpOatDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { 5782cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool success = true; 57932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool stop_analysis = false; 5802cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << "OatDexFile:\n"; 581a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom os << StringPrintf("location: %s\n", oat_dex_file.GetDexFileLocation().c_str()); 582ed2adb6158ffbe85c89aa5c9892a35bafa5006cdElliott Hughes os << StringPrintf("checksum: 0x%08x\n", oat_dex_file.GetDexFileLocationChecksum()); 583590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier 584590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier // Create the verifier early. 585590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier 5868d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string error_msg; 587ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); 588ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (dex_file == nullptr) { 5898d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers os << "NOT FOUND: " << error_msg << "\n\n"; 5902cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << std::flush; 5912cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return false; 592aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 5938f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 5948f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko VariableIndentationOutputStream vios(&os); 5958f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(&vios); 5962ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom for (size_t class_def_index = 0; 5972ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom class_def_index < dex_file->NumClassDefs(); 5982ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom class_def_index++) { 599aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); 600aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const char* descriptor = dex_file->GetClassDescriptor(class_def); 60132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 60232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // TODO: Support regex 60332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (DescriptorToDot(descriptor).find(options_.class_filter_) == std::string::npos) { 60432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis continue; 60532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 60632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 6072cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t oat_class_offset = oat_dex_file.GetOatClassOffset(class_def_index); 608d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index); 6092cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom os << StringPrintf("%zd: %s (offset=0x%08x) (type_idx=%d)", 6102cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom class_def_index, descriptor, oat_class_offset, class_def.class_idx_) 611d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko << " (" << oat_class.GetStatus() << ")" 612d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko << " (" << oat_class.GetType() << ")\n"; 613d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko // TODO: include bitmap here if type is kOatClassSomeCompiled? 61432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.list_classes_) continue; 615ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier if (!DumpOatClass(&vios, oat_class, *dex_file, class_def, &stop_analysis)) { 6162cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 6172cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 61832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (stop_analysis) { 61932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << std::flush; 62032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return success; 62132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 622aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 623aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 624aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom os << std::flush; 6252cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return success; 626aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 627aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 62832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool ExportDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { 62932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string error_msg; 63032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string dex_file_location = oat_dex_file.GetDexFileLocation(); 63132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 632ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); 63332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (dex_file == nullptr) { 63432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "Failed to open dex file '" << dex_file_location << "': " << error_msg; 63532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 63632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 63732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis size_t fsize = oat_dex_file.FileSize(); 63832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 63932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // Some quick checks just in case 64032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (fsize == 0 || fsize < sizeof(DexFile::Header)) { 64132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "Invalid dex file\n"; 64232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 64332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 64432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 64532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // Verify output directory exists 64632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (!OS::DirectoryExists(options_.export_dex_location_)) { 64732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // TODO: Extend OS::DirectoryExists if symlink support is required 64832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << options_.export_dex_location_ << " output directory not found or symlink\n"; 64932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 65032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 65132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 65232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // Beautify path names 65332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (dex_file_location.size() > PATH_MAX || dex_file_location.size() <= 0) { 65432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 65532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 65632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 65732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string dex_orig_name; 65832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis size_t dex_orig_pos = dex_file_location.rfind('/'); 65932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (dex_orig_pos == std::string::npos) 66032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis dex_orig_name = dex_file_location; 66132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis else 66232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis dex_orig_name = dex_file_location.substr(dex_orig_pos + 1); 66332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 66432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // A more elegant approach to efficiently name user installed apps is welcome 66532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (dex_orig_name.size() == 8 && !dex_orig_name.compare("base.apk")) { 66632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis dex_file_location.erase(dex_orig_pos, strlen("base.apk") + 1); 66732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis size_t apk_orig_pos = dex_file_location.rfind('/'); 66832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (apk_orig_pos != std::string::npos) { 66932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis dex_orig_name = dex_file_location.substr(++apk_orig_pos); 67032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 67132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 67232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 67332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string out_dex_path(options_.export_dex_location_); 67432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (out_dex_path.back() != '/') { 67532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis out_dex_path.append("/"); 67632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 67732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis out_dex_path.append(dex_orig_name); 67832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis out_dex_path.append("_export.dex"); 67932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (out_dex_path.length() > PATH_MAX) { 68032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 68132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 68232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 68332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::unique_ptr<File> file(OS::CreateEmptyFile(out_dex_path.c_str())); 68432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (file.get() == nullptr) { 68532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "Failed to open output dex file " << out_dex_path; 68632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 68732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 68832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 68932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (!file->WriteFully(dex_file->Begin(), fsize)) { 69032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "Failed to write dex file"; 69132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis file->Erase(); 69232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 69332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 69432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 69532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (file->FlushCloseOrErase() != 0) { 69632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << "Flush and close failed"; 69732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return false; 69832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 69932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 70032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << StringPrintf("Dex file exported at %s (%zd bytes)\n", out_dex_path.c_str(), fsize); 70132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << std::flush; 70232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 70332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return true; 70432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 70532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 706e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes static void SkipAllFields(ClassDataItemIterator& it) { 7070571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers while (it.HasNextStaticField()) { 7080571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers it.Next(); 709aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 7100571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers while (it.HasNextInstanceField()) { 7110571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers it.Next(); 712aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 713e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 714aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 7158f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko bool DumpOatClass(VariableIndentationOutputStream* vios, 7168f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko const OatFile::OatClass& oat_class, const DexFile& dex_file, 71732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const DexFile::ClassDef& class_def, bool* stop_analysis) { 7182cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool success = true; 71932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool addr_found = false; 72013735955f39b3b304c37d2b2840663c131262c18Ian Rogers const uint8_t* class_data = dex_file.GetClassData(class_def); 7212ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (class_data == nullptr) { // empty class such as a marker interface? 7228f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << std::flush; 7232cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return success; 724e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 725e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes ClassDataItemIterator it(dex_file, class_data); 726e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes SkipAllFields(it); 7272cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t class_method_index = 0; 7280571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers while (it.HasNextDirectMethod()) { 7298f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, 7302cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom it.GetMemberIndex(), it.GetMethodCodeItem(), 73132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis it.GetRawMemberAccessFlags(), &addr_found)) { 7322cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 7332cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 73432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (addr_found) { 73532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis *stop_analysis = true; 73632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return success; 73732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 7382cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom class_method_index++; 7390571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers it.Next(); 740aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 7410571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers while (it.HasNextVirtualMethod()) { 7428f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, 7432cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom it.GetMemberIndex(), it.GetMethodCodeItem(), 74432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis it.GetRawMemberAccessFlags(), &addr_found)) { 7452cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 7462cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 74732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (addr_found) { 74832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis *stop_analysis = true; 74932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return success; 75032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 7512cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom class_method_index++; 7520571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers it.Next(); 753aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 7540571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogers DCHECK(!it.HasNext()); 7558f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << std::flush; 7562cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return success; 757aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 758e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 7592cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom static constexpr uint32_t kPrologueBytes = 16; 7602cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 7612cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom // When this was picked, the largest arm method was 55,256 bytes and arm64 was 50,412 bytes. 7622cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom static constexpr uint32_t kMaxCodeSize = 100 * 1000; 7632cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 7648f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko bool DumpOatMethod(VariableIndentationOutputStream* vios, 7658f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko const DexFile::ClassDef& class_def, 7668b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers uint32_t class_method_index, 7672cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const OatFile::OatClass& oat_class, const DexFile& dex_file, 7682bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers uint32_t dex_method_idx, const DexFile::CodeItem* code_item, 76932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t method_access_flags, bool* addr_found) { 7702cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool success = true; 77132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 77232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis // TODO: Support regex 77332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string method_name = dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx)); 77432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (method_name.find(options_.method_filter_) == std::string::npos) { 7753fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray return success; 7763fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray } 7773fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray 77832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis std::string pretty_method = PrettyMethod(dex_method_idx, dex_file, true); 7798f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%d: %s (dex_method_idx=%d)\n", 7808f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko class_method_index, pretty_method.c_str(), 7818f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko dex_method_idx); 78232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.list_methods_) return success; 78332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 78432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t oat_method_offsets_offset = oat_class.GetOatMethodOffsetsOffset(class_method_index); 78532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const OatMethodOffsets* oat_method_offsets = oat_class.GetOatMethodOffsets(class_method_index); 78632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_index); 78732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t code_offset = oat_method.GetCodeOffset(); 78832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t code_size = oat_method.GetQuickCodeSize(); 78932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (resolved_addr2instr_ != 0) { 79032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (resolved_addr2instr_ > code_offset + code_size) { 79132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return success; 79232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else { 79332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis *addr_found = true; // stop analyzing file at next iteration 79432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 79532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 79632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis 7978f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // Everything below is indented at least once. 7988f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(vios); 7998f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 8002bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 8018f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "DEX CODE:\n"; 8028f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 8038f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpDexCode(vios->Stream(), dex_file, code_item); 8042bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 8052ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe 806673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier std::unique_ptr<StackHandleScope<1>> hs; 8072ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe std::unique_ptr<verifier::MethodVerifier> verifier; 8082ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (Runtime::Current() != nullptr) { 809673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier // We need to have the handle scope stay live until after the verifier since the verifier has 810673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier // a handle to the dex cache from hs. 811673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier hs.reset(new StackHandleScope<1>(Thread::Current())); 8128f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "VERIFIER TYPE ANALYSIS:\n"; 8138f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 814673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier verifier.reset(DumpVerifier(vios, hs.get(), 8158f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko dex_method_idx, &dex_file, class_def, code_item, 8162ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe method_access_flags)); 8172bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 8182bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 8198f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "OatMethodOffsets "; 82032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 8218f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", oat_method_offsets); 8222cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8238f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(offset=0x%08x)\n", oat_method_offsets_offset); 8242cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (oat_method_offsets_offset > oat_file_.Size()) { 8258f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf( 8262cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom "WARNING: oat method offsets offset 0x%08x is past end of file 0x%08zx.\n", 8272cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom oat_method_offsets_offset, oat_file_.Size()); 8282cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom // If we can't read OatMethodOffsets, the rest of the data is dangerous to read. 8298f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << std::flush; 8302cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return false; 8312cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 832a8b41aaa08283390606e6515d178ca3cc4c6ca41Andreas Gampe 8338f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 8348f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("code_offset: 0x%08x ", code_offset); 8352cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t aligned_code_begin = AlignCodeOffset(oat_method.GetCodeOffset()); 8362cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (aligned_code_begin > oat_file_.Size()) { 8378f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 8388f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "code offset 0x%08x is past end of file 0x%08zx.\n", 8398f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko aligned_code_begin, oat_file_.Size()); 8402cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 8412cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8428f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "\n"; 8433946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray 8448f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "gc_map: "; 84532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 8468f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", oat_method.GetGcMap()); 8473946844c34ad965515f677084b07d663d70ad1b8Nicolas Geoffray } 848957ca1cd025104fccb0b08928f955f9bdb4ab91cMathieu Chartier uint32_t gc_map_offset = oat_method.GetGcMapOffset(); 8498f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(offset=0x%08x)\n", gc_map_offset); 8502cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (gc_map_offset > oat_file_.Size()) { 8518f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 8528f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "gc map table offset 0x%08x is past end of file 0x%08zx.\n", 8538f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko gc_map_offset, oat_file_.Size()); 8542cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 85532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (options_.dump_raw_gc_map_) { 8568f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent3(vios); 8578f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpGcMap(vios->Stream(), oat_method, code_item); 8582cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8592cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8602cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom { 8618f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "OatQuickMethodHeader "; 8622cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t method_header_offset = oat_method.GetOatQuickMethodHeaderOffset(); 8632cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const OatQuickMethodHeader* method_header = oat_method.GetOatQuickMethodHeader(); 8642cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 86532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 8668f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", method_header); 8672bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 8688f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(offset=0x%08x)\n", method_header_offset); 8692cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (method_header_offset > oat_file_.Size()) { 8708f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf( 8712cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom "WARNING: oat quick method header offset 0x%08x is past end of file 0x%08zx.\n", 8722cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom method_header_offset, oat_file_.Size()); 8732cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom // If we can't read the OatQuickMethodHeader, the rest of the data is dangerous to read. 8748f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << std::flush; 8752cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return false; 8762cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8772cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 8788f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 8798f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "mapping_table: "; 88032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 8818f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", oat_method.GetMappingTable()); 8822cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8832cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t mapping_table_offset = oat_method.GetMappingTableOffset(); 8848f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(offset=0x%08x)\n", oat_method.GetMappingTableOffset()); 8852cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (mapping_table_offset > oat_file_.Size()) { 8868f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 8878f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "mapping table offset 0x%08x is past end of file 0x%08zx. " 8888f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "mapping table offset was loaded from offset 0x%08x.\n", 8898f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko mapping_table_offset, oat_file_.Size(), 8908f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko oat_method.GetMappingTableOffsetOffset()); 8912cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 89232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (options_.dump_raw_mapping_table_) { 8938f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent3(vios); 8948f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpMappingTable(vios, oat_method); 8952cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 8962cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 8978f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "vmap_table: "; 89832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 8998f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", oat_method.GetVmapTable()); 9002cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9012cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t vmap_table_offset = oat_method.GetVmapTableOffset(); 9028f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(offset=0x%08x)\n", vmap_table_offset); 9032cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (vmap_table_offset > oat_file_.Size()) { 9048f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 9058f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "vmap table offset 0x%08x is past end of file 0x%08zx. " 9068f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "vmap table offset was loaded from offset 0x%08x.\n", 9078f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vmap_table_offset, oat_file_.Size(), 9088f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko oat_method.GetVmapTableOffsetOffset()); 9092cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 91032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (options_.dump_vmap_) { 9118f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpVmapData(vios, oat_method, code_item); 9122bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 9132bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 9142bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 9158f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "QuickMethodFrameInfo\n"; 9168f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 9178f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 9188f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() 9198f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko << StringPrintf("frame_size_in_bytes: %zd\n", oat_method.GetFrameSizeInBytes()); 9208f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("core_spill_mask: 0x%08x ", oat_method.GetCoreSpillMask()); 9218f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpSpillMask(vios->Stream(), oat_method.GetCoreSpillMask(), false); 9228f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "\n"; 9238f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("fp_spill_mask: 0x%08x ", oat_method.GetFpSpillMask()); 9248f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpSpillMask(vios->Stream(), oat_method.GetFpSpillMask(), true); 9258f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "\n"; 9262cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9272cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom { 9288f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // Based on spill masks from QuickMethodFrameInfo so placed 9298f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // after it is dumped, but useful for understanding quick 9308f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // code, so dumped here. 9318f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 9328f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpVregLocations(vios->Stream(), oat_method, code_item); 9332cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9342cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom { 9358f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "CODE: "; 9362cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t code_size_offset = oat_method.GetQuickCodeSizeOffset(); 9372cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (code_size_offset > oat_file_.Size()) { 9388f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 9398f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 9408f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "code size offset 0x%08x is past end of file 0x%08zx.", 9418f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size_offset, oat_file_.Size()); 9422cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 9432cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } else { 9442cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const void* code = oat_method.GetQuickCode(); 9452cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint32_t aligned_code_begin = AlignCodeOffset(code_offset); 9462cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom uint64_t aligned_code_end = aligned_code_begin + code_size; 947590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier 94832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.absolute_addresses_) { 9498f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("%p ", code); 9502cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9518f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("(code_offset=0x%08x size_offset=0x%08x size=%u)%s\n", 9528f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_offset, 9538f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size_offset, 9548f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size, 9558f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code != nullptr ? "..." : ""); 9562cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 9578f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(vios); 9582cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (aligned_code_begin > oat_file_.Size()) { 9598f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("WARNING: " 9608f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "start of code at 0x%08x is past end of file 0x%08zx.", 9618f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko aligned_code_begin, oat_file_.Size()); 9622cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 9632cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } else if (aligned_code_end > oat_file_.Size()) { 9648f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf( 9658f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "WARNING: " 9668f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "end of code at 0x%08" PRIx64 " is past end of file 0x%08zx. " 9678f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "code size is 0x%08x loaded from offset 0x%08x.\n", 9688f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko aligned_code_end, oat_file_.Size(), 9698f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size, code_size_offset); 9702cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 97132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.disassemble_code_) { 9722cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { 9738f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpCode(vios, verifier.get(), oat_method, code_item, true, kPrologueBytes); 9742cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9752cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9762cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } else if (code_size > kMaxCodeSize) { 9778f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf( 9788f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "WARNING: " 9798f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "code size %d is bigger than max expected threshold of %d. " 9808f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko "code size is 0x%08x loaded from offset 0x%08x.\n", 9818f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size, kMaxCodeSize, 9828f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_size, code_size_offset); 9832cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom success = false; 98432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (options_.disassemble_code_) { 9852cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { 9868f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpCode(vios, verifier.get(), oat_method, code_item, true, kPrologueBytes); 9872cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9882cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 98932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (options_.disassemble_code_) { 9908f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpCode(vios, verifier.get(), oat_method, code_item, !success, 0); 9912cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9922cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 9932bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 9948f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << std::flush; 9952cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return success; 9963a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 9973a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 9983a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers void DumpSpillMask(std::ostream& os, uint32_t spill_mask, bool is_float) { 9993a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (spill_mask == 0) { 10003a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return; 10013a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10022bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "("; 10033a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 0; i < 32; i++) { 10043a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if ((spill_mask & (1 << i)) != 0) { 10053a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (is_float) { 10063a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers os << "fr" << i; 10073a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 10083a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers os << "r" << i; 10093a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10103a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers spill_mask ^= 1 << i; // clear bit 10113a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (spill_mask != 0) { 10123a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers os << ", "; 10133a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 10143a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers break; 10153a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10163a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10173a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers os << ")"; 10193a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10203a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 1021442b46a087c389a91a0b51547ac9205058432364Roland Levillain // Display data stored at the the vmap offset of an oat method. 10228f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void DumpVmapData(VariableIndentationOutputStream* vios, 1023442b46a087c389a91a0b51547ac9205058432364Roland Levillain const OatFile::OatMethod& oat_method, 1024442b46a087c389a91a0b51547ac9205058432364Roland Levillain const DexFile::CodeItem* code_item) { 1025f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain if (IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { 1026f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // The optimizing compiler outputs its CodeInfo data in the vmap table. 1027442b46a087c389a91a0b51547ac9205058432364Roland Levillain const void* raw_code_info = oat_method.GetVmapTable(); 1028442b46a087c389a91a0b51547ac9205058432364Roland Levillain if (raw_code_info != nullptr) { 1029442b46a087c389a91a0b51547ac9205058432364Roland Levillain CodeInfo code_info(raw_code_info); 1030442b46a087c389a91a0b51547ac9205058432364Roland Levillain DCHECK(code_item != nullptr); 10318f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(vios); 10328f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpCodeInfo(vios, code_info, oat_method, *code_item); 1033442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 10340a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray } else if (IsMethodGeneratedByDexToDexCompiler(oat_method, code_item)) { 10350a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // We don't encode the size in the table, so just emit that we have quickened 10360a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // information. 10370a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray ScopedIndentation indent(vios); 10380a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray vios->Stream() << "quickened data\n"; 1039442b46a087c389a91a0b51547ac9205058432364Roland Levillain } else { 1040442b46a087c389a91a0b51547ac9205058432364Roland Levillain // Otherwise, display the vmap table. 1041442b46a087c389a91a0b51547ac9205058432364Roland Levillain const uint8_t* raw_table = oat_method.GetVmapTable(); 1042442b46a087c389a91a0b51547ac9205058432364Roland Levillain if (raw_table != nullptr) { 1043442b46a087c389a91a0b51547ac9205058432364Roland Levillain VmapTable vmap_table(raw_table); 10448f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpVmapTable(vios->Stream(), oat_method, vmap_table); 1045442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 104620d3eae6bd65bea5206e57acab8145956e36ab08Nicolas Geoffray } 1047442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 1048442b46a087c389a91a0b51547ac9205058432364Roland Levillain 1049442b46a087c389a91a0b51547ac9205058432364Roland Levillain // Display a CodeInfo object emitted by the optimizing compiler. 10508f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void DumpCodeInfo(VariableIndentationOutputStream* vios, 1051442b46a087c389a91a0b51547ac9205058432364Roland Levillain const CodeInfo& code_info, 1052f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const OatFile::OatMethod& oat_method, 1053442b46a087c389a91a0b51547ac9205058432364Roland Levillain const DexFile::CodeItem& code_item) { 10548f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_info.Dump(vios, 1055f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain oat_method.GetCodeOffset(), 1056f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain code_item.registers_size_, 1057f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain options_.dump_code_info_stack_maps_); 1058442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 1059442b46a087c389a91a0b51547ac9205058432364Roland Levillain 1060442b46a087c389a91a0b51547ac9205058432364Roland Levillain // Display a vmap table. 1061442b46a087c389a91a0b51547ac9205058432364Roland Levillain void DumpVmapTable(std::ostream& os, 1062442b46a087c389a91a0b51547ac9205058432364Roland Levillain const OatFile::OatMethod& oat_method, 1063442b46a087c389a91a0b51547ac9205058432364Roland Levillain const VmapTable& vmap_table) { 1064442b46a087c389a91a0b51547ac9205058432364Roland Levillain bool first = true; 1065442b46a087c389a91a0b51547ac9205058432364Roland Levillain bool processing_fp = false; 1066442b46a087c389a91a0b51547ac9205058432364Roland Levillain uint32_t spill_mask = oat_method.GetCoreSpillMask(); 1067442b46a087c389a91a0b51547ac9205058432364Roland Levillain for (size_t i = 0; i < vmap_table.Size(); i++) { 1068442b46a087c389a91a0b51547ac9205058432364Roland Levillain uint16_t dex_reg = vmap_table[i]; 1069442b46a087c389a91a0b51547ac9205058432364Roland Levillain uint32_t cpu_reg = vmap_table.ComputeRegister(spill_mask, i, 1070442b46a087c389a91a0b51547ac9205058432364Roland Levillain processing_fp ? kFloatVReg : kIntVReg); 1071442b46a087c389a91a0b51547ac9205058432364Roland Levillain os << (first ? "v" : ", v") << dex_reg; 1072442b46a087c389a91a0b51547ac9205058432364Roland Levillain if (!processing_fp) { 1073442b46a087c389a91a0b51547ac9205058432364Roland Levillain os << "/r" << cpu_reg; 1074442b46a087c389a91a0b51547ac9205058432364Roland Levillain } else { 1075442b46a087c389a91a0b51547ac9205058432364Roland Levillain os << "/fr" << cpu_reg; 1076442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 1077442b46a087c389a91a0b51547ac9205058432364Roland Levillain first = false; 1078442b46a087c389a91a0b51547ac9205058432364Roland Levillain if (!processing_fp && dex_reg == 0xFFFF) { 1079442b46a087c389a91a0b51547ac9205058432364Roland Levillain processing_fp = true; 1080442b46a087c389a91a0b51547ac9205058432364Roland Levillain spill_mask = oat_method.GetFpSpillMask(); 1081442b46a087c389a91a0b51547ac9205058432364Roland Levillain } 10823a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1083442b46a087c389a91a0b51547ac9205058432364Roland Levillain os << "\n"; 10843a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 10853a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 1086faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru void DumpVregLocations(std::ostream& os, const OatFile::OatMethod& oat_method, 1087faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru const DexFile::CodeItem* code_item) { 1088faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru if (code_item != nullptr) { 1089faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru size_t num_locals_ins = code_item->registers_size_; 1090faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru size_t num_ins = code_item->ins_size_; 1091faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru size_t num_locals = num_locals_ins - num_ins; 1092faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru size_t num_outs = code_item->outs_size_; 1093faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 1094faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "vr_stack_locations:"; 1095faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru for (size_t reg = 0; reg <= num_locals_ins; reg++) { 1096faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru // For readability, delimit the different kinds of VRs. 1097faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru if (reg == num_locals_ins) { 1098faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "\n\tmethod*:"; 1099faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } else if (reg == num_locals && num_ins > 0) { 1100faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "\n\tins:"; 1101faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } else if (reg == 0 && num_locals > 0) { 1102faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "\n\tlocals:"; 1103faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1104faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 110515b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray uint32_t offset = StackVisitor::GetVRegOffsetFromQuickCode( 110615b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray code_item, 110715b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetCoreSpillMask(), 110815b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetFpSpillMask(), 110915b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetFrameSizeInBytes(), 111015b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray reg, 111115b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray GetInstructionSet()); 1112faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << " v" << reg << "[sp + #" << offset << "]"; 1113faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1114faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 1115faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru for (size_t out_reg = 0; out_reg < num_outs; out_reg++) { 1116faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru if (out_reg == 0) { 1117faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "\n\touts:"; 1118faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1119faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 1120faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru uint32_t offset = StackVisitor::GetOutVROffset(out_reg, GetInstructionSet()); 1121faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << " v" << out_reg << "[sp + #" << offset << "]"; 1122faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1123faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 1124faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru os << "\n"; 1125faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1126faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru } 1127faf9f0d53573025dc5ae5ff6c4412396030cf1daRazvan A Lupusoru 1128b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers void DescribeVReg(std::ostream& os, const OatFile::OatMethod& oat_method, 11292bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers const DexFile::CodeItem* code_item, size_t reg, VRegKind kind) { 11301809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers const uint8_t* raw_table = oat_method.GetVmapTable(); 11312ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (raw_table != nullptr) { 1132b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers const VmapTable vmap_table(raw_table); 1133b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers uint32_t vmap_offset; 11341809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (vmap_table.IsInContext(reg, kind, &vmap_offset)) { 11352bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); 11362bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers uint32_t spill_mask = is_float ? oat_method.GetFpSpillMask() 11372bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers : oat_method.GetCoreSpillMask(); 11382bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << (is_float ? "fr" : "r") << vmap_table.ComputeRegister(spill_mask, vmap_offset, kind); 1139b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } else { 114015b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray uint32_t offset = StackVisitor::GetVRegOffsetFromQuickCode( 114115b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray code_item, 114215b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetCoreSpillMask(), 114315b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetFpSpillMask(), 114415b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray oat_method.GetFrameSizeInBytes(), 114515b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray reg, 114615b9d5274399736ac09705f0507df24fac4f00c1Nicolas Geoffray GetInstructionSet()); 1147b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers os << "[sp + #" << offset << "]"; 1148b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1149b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1150b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1151b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers 1152ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers void DumpGcMapRegisters(std::ostream& os, const OatFile::OatMethod& oat_method, 1153ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const DexFile::CodeItem* code_item, 1154ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers size_t num_regs, const uint8_t* reg_bitmap) { 1155ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers bool first = true; 1156ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers for (size_t reg = 0; reg < num_regs; reg++) { 1157ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) { 1158ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (first) { 1159ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << " v" << reg << " ("; 1160ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); 1161ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << ")"; 1162ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers first = false; 1163ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 1164ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << ", v" << reg << " ("; 1165ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); 1166ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << ")"; 1167ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 1168ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 1169ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 1170ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (first) { 1171ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << "No registers in GC map\n"; 1172ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 1173ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << "\n"; 1174ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 1175ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 1176b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers void DumpGcMap(std::ostream& os, const OatFile::OatMethod& oat_method, 1177b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers const DexFile::CodeItem* code_item) { 1178957ca1cd025104fccb0b08928f955f9bdb4ab91cMathieu Chartier const uint8_t* gc_map_raw = oat_method.GetGcMap(); 1179ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (gc_map_raw == nullptr) { 1180ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return; // No GC map. 11813a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1182ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* quick_code = oat_method.GetQuickCode(); 1183956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes NativePcOffsetToReferenceMap map(gc_map_raw); 1184956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes for (size_t entry = 0; entry < map.NumEntries(); entry++) { 1185956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes const uint8_t* native_pc = reinterpret_cast<const uint8_t*>(quick_code) + 1186956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes map.GetNativePcOffset(entry); 1187956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes os << StringPrintf("%p", native_pc); 1188956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes DumpGcMapRegisters(os, oat_method, code_item, map.RegWidth() * 8, map.GetBitMap(entry)); 11893a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1190aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 1191e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes 11928f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void DumpMappingTable(VariableIndentationOutputStream* vios, 11938f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko const OatFile::OatMethod& oat_method) { 1194ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* quick_code = oat_method.GetQuickCode(); 1195ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (quick_code == nullptr) { 11962bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers return; 11972bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 11981809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers MappingTable table(oat_method.GetMappingTable()); 11991809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (table.TotalSize() != 0) { 12001809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (table.PcToDexSize() != 0) { 12011809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers typedef MappingTable::PcToDexIterator It; 12028f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "suspend point mappings {\n"; 12031809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { 12048f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(vios); 12058f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc()); 12061809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers } 12078f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "}\n"; 12081809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers } 12091809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (table.DexToPcSize() != 0) { 12101809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers typedef MappingTable::DexToPcIterator It; 12118f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "catch entry mappings {\n"; 12121809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { 12138f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(vios); 12148f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc()); 12151809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers } 12168f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "}\n"; 12173a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 12183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 12193a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 12203a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 12218f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko uint32_t DumpInformationAtOffset(VariableIndentationOutputStream* vios, 1222f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const OatFile::OatMethod& oat_method, 1223f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const DexFile::CodeItem* code_item, 1224f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain size_t offset, 1225f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain bool suspend_point_mapping) { 1226f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain if (IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { 1227f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain if (suspend_point_mapping) { 12288f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(vios); 12298f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpDexRegisterMapAtOffset(vios, oat_method, code_item, offset); 1230f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1231f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // The return value is not used in the case of a method compiled 1232f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // with the optimizing compiler. 1233f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain return DexFile::kDexNoIndex; 1234f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } else { 12358f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko return DumpMappingAtOffset(vios->Stream(), oat_method, offset, suspend_point_mapping); 1236f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1237f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1238f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain 12391809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers uint32_t DumpMappingAtOffset(std::ostream& os, const OatFile::OatMethod& oat_method, 12401809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers size_t offset, bool suspend_point_mapping) { 12411809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers MappingTable table(oat_method.GetMappingTable()); 12421809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (suspend_point_mapping && table.PcToDexSize() > 0) { 12431809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers typedef MappingTable::PcToDexIterator It; 12441809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { 12451809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (offset == cur.NativePcOffset()) { 12464b8c13ee44c4c959d7b8de9adff7ce6df48c31d0Brian Carlstrom os << StringPrintf("suspend point dex PC: 0x%04x\n", cur.DexPc()); 12471809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers return cur.DexPc(); 12481809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers } 1249b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 12501809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers } else if (!suspend_point_mapping && table.DexToPcSize() > 0) { 12511809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers typedef MappingTable::DexToPcIterator It; 12521809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { 12531809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers if (offset == cur.NativePcOffset()) { 12544b8c13ee44c4c959d7b8de9adff7ce6df48c31d0Brian Carlstrom os << StringPrintf("catch entry dex PC: 0x%04x\n", cur.DexPc()); 12551809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers return cur.DexPc(); 1256b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1257b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 12583a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 12592bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers return DexFile::kDexNoIndex; 1260b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 12613a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 12622bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers void DumpGcMapAtNativePcOffset(std::ostream& os, const OatFile::OatMethod& oat_method, 12632bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers const DexFile::CodeItem* code_item, size_t native_pc_offset) { 1264957ca1cd025104fccb0b08928f955f9bdb4ab91cMathieu Chartier const uint8_t* gc_map_raw = oat_method.GetGcMap(); 12652ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (gc_map_raw != nullptr) { 1266b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers NativePcOffsetToReferenceMap map(gc_map_raw); 12672bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (map.HasEntry(native_pc_offset)) { 1268b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers size_t num_regs = map.RegWidth() * 8; 12692bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers const uint8_t* reg_bitmap = map.FindBitMap(native_pc_offset); 1270b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers bool first = true; 1271b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers for (size_t reg = 0; reg < num_regs; reg++) { 1272b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) { 1273b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers if (first) { 12742bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "GC map objects: v" << reg << " ("; 12752bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); 1276b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers os << ")"; 1277b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers first = false; 1278b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } else { 1279b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers os << ", v" << reg << " ("; 12802bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); 1281b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers os << ")"; 1282b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1283b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1284b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1285b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers if (!first) { 1286b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers os << "\n"; 1287b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1288b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 12893a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1290b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 12913a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 1292590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier void DumpVRegsAtDexPc(std::ostream& os, verifier::MethodVerifier* verifier, 1293590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier const OatFile::OatMethod& oat_method, 1294590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier const DexFile::CodeItem* code_item, uint32_t dex_pc) { 1295590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier DCHECK(verifier != nullptr); 12967b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers std::vector<int32_t> kinds = verifier->DescribeVRegs(dex_pc); 12972bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers bool first = true; 12982bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers for (size_t reg = 0; reg < code_item->registers_size_; reg++) { 12992bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers VRegKind kind = static_cast<VRegKind>(kinds.at(reg * 2)); 13002bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (kind != kUndefined) { 13012bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (first) { 13022bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "VRegs: v"; 13032bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers first = false; 13042bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } else { 13052bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << ", v"; 13062bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13072bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << reg << " ("; 13082bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers switch (kind) { 13092bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers case kImpreciseConstant: 13102bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "Imprecise Constant: " << kinds.at((reg * 2) + 1) << ", "; 13112bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers DescribeVReg(os, oat_method, code_item, reg, kind); 13122bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers break; 13132bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers case kConstant: 13142bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "Constant: " << kinds.at((reg * 2) + 1); 13152bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers break; 13162bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers default: 13172bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers DescribeVReg(os, oat_method, code_item, reg, kind); 13182bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers break; 13192bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13202bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << ")"; 13212bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13222bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13232bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (!first) { 13242bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n"; 13252bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13262bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 13272bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 13282bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1329b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers void DumpDexCode(std::ostream& os, const DexFile& dex_file, const DexFile::CodeItem* code_item) { 13302ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (code_item != nullptr) { 1331b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers size_t i = 0; 1332b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers while (i < code_item->insns_size_in_code_units_) { 1333b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers const Instruction* instruction = Instruction::At(&code_item->insns_[i]); 133432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis os << StringPrintf("0x%04zx: ", i) << instruction->DumpHexLE(5) 133532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis << StringPrintf("\t| %s\n", instruction->DumpString(&dex_file).c_str()); 1336b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers i += instruction->SizeInCodeUnits(); 1337e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 1338e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes } 1339b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1340b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers 1341f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by 1342f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // the optimizing compiler? 1343f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain static bool IsMethodGeneratedByOptimizingCompiler(const OatFile::OatMethod& oat_method, 1344f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const DexFile::CodeItem* code_item) { 1345f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // If the native GC map is null and the Dex `code_item` is not 1346f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // null, then this method has been compiled with the optimizing 1347f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // compiler. 13480a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray return oat_method.GetQuickCode() != nullptr && 13490a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray oat_method.GetGcMap() == nullptr && 13500a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray code_item != nullptr; 13510a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray } 13520a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray 13530a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by 13540a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // the dextodex compiler? 13550a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray static bool IsMethodGeneratedByDexToDexCompiler(const OatFile::OatMethod& oat_method, 13560a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray const DexFile::CodeItem* code_item) { 13570a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // If the quick code is null, the Dex `code_item` is not 13580a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // null, and the vmap table is not null, then this method has been compiled 13590a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray // with the dextodex compiler. 13600a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray return oat_method.GetQuickCode() == nullptr && 13610a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray oat_method.GetVmapTable() != nullptr && 13620a5cd12a30e1b02833bdd94f11b74ecf4835ecb3Nicolas Geoffray code_item != nullptr; 1363f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1364f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain 13658f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void DumpDexRegisterMapAtOffset(VariableIndentationOutputStream* vios, 1366f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const OatFile::OatMethod& oat_method, 1367f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const DexFile::CodeItem* code_item, 1368f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain size_t offset) { 1369f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // This method is only relevant for oat methods compiled with the 1370f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // optimizing compiler. 1371f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain DCHECK(IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)); 1372f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain 1373f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain // The optimizing compiler outputs its CodeInfo data in the vmap table. 1374f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain const void* raw_code_info = oat_method.GetVmapTable(); 1375f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain if (raw_code_info != nullptr) { 1376f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain CodeInfo code_info(raw_code_info); 1377f677ebfd832c9c614fea5e6735725fec2f7a3f2aDavid Brazdil StackMapEncoding encoding = code_info.ExtractEncoding(); 1378f677ebfd832c9c614fea5e6735725fec2f7a3f2aDavid Brazdil StackMap stack_map = code_info.GetStackMapForNativePcOffset(offset, encoding); 1379f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain if (stack_map.IsValid()) { 13808f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko stack_map.Dump(vios, code_info, encoding, oat_method.GetCodeOffset(), 13818f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko code_item->registers_size_); 1382f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1383f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1384f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } 1385f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain 13868f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko verifier::MethodVerifier* DumpVerifier(VariableIndentationOutputStream* vios, 1387673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier StackHandleScope<1>* hs, 13888f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko uint32_t dex_method_idx, 13892ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile* dex_file, 13902ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile::ClassDef& class_def, 13912ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile::CodeItem* code_item, 13922ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe uint32_t method_access_flags) { 13932bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if ((method_access_flags & kAccNative) == 0) { 13942bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers ScopedObjectAccess soa(Thread::Current()); 1395d57d454a11ac6f49eaa397ec14d6231e3a2727b7Mathieu Chartier Runtime* const runtime = Runtime::Current(); 1396eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier Handle<mirror::DexCache> dex_cache( 1397d57d454a11ac6f49eaa397ec14d6231e3a2727b7Mathieu Chartier hs->NewHandle(runtime->GetClassLinker()->RegisterDexFile(*dex_file, 1398d57d454a11ac6f49eaa397ec14d6231e3a2727b7Mathieu Chartier runtime->GetLinearAlloc()))); 139932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis DCHECK(options_.class_loader_ != nullptr); 1400e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier return verifier::MethodVerifier::VerifyMethodAndDump( 14018f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko soa.Self(), vios, dex_method_idx, dex_file, dex_cache, *options_.class_loader_, 14028f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko &class_def, code_item, nullptr, method_access_flags); 14032bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 14042ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe 14052ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe return nullptr; 14062bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 14072bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 14088f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void DumpCode(VariableIndentationOutputStream* vios, 14098f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko verifier::MethodVerifier* verifier, 14102cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item, 14112cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom bool bad_input, size_t code_size) { 1412ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* quick_code = oat_method.GetQuickCode(); 1413ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 14142cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (code_size == 0) { 14152cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom code_size = oat_method.GetQuickCodeSize(); 14162cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 1417956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes if (code_size == 0 || quick_code == nullptr) { 14188f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios->Stream() << "NO CODE!\n"; 1419b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers return; 1420956af0f0cb05422e38c1d22cbef309d16b8a1a12Elliott Hughes } else { 1421ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const uint8_t* quick_native_pc = reinterpret_cast<const uint8_t*>(quick_code); 1422ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers size_t offset = 0; 1423ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers while (offset < code_size) { 14242cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (!bad_input) { 14258f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpInformationAtOffset(vios, oat_method, code_item, offset, false); 14262cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 14278f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko offset += disassembler_->Dump(vios->Stream(), quick_native_pc + offset); 14282cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (!bad_input) { 14298f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko uint32_t dex_pc = 14308f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpInformationAtOffset(vios, oat_method, code_item, offset, true); 14312cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (dex_pc != DexFile::kDexNoIndex) { 14328f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpGcMapAtNativePcOffset(vios->Stream(), oat_method, code_item, offset); 14332cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (verifier != nullptr) { 14348f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpVRegsAtDexPc(vios->Stream(), verifier, oat_method, code_item, dex_pc); 14352cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 1436ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 14372bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 14382bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 1439b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1440b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers } 1441b23a7729cf7855fa05345d03a4d84111d5ec7172Ian Rogers 14423a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers const OatFile& oat_file_; 14432cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom const std::vector<const OatFile::OatDexFile*> oat_dex_files_; 144432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const OatDumperOptions& options_; 144532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t resolved_addr2instr_; 1446a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier InstructionSet instruction_set_; 1447ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers std::set<uintptr_t> offsets_; 14482cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom Disassembler* disassembler_; 1449aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom}; 1450aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 14513a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogersclass ImageDumper { 145227ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom public: 14530b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier ImageDumper(std::ostream* os, 14540b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier gc::space::ImageSpace& image_space, 14550b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const ImageHeader& image_header, 14560b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier OatDumperOptions* oat_dumper_options) 14572cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom : os_(os), 14588f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko vios_(os), 14598f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent1_(&vios_), 14602cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom image_space_(image_space), 14612cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom image_header_(image_header), 14622cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom oat_dumper_options_(oat_dumper_options) {} 146327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 146490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool Dump() SHARED_REQUIRES(Locks::mutator_lock_) { 14652bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers std::ostream& os = *os_; 14668f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko std::ostream& indent_os = vios_.Stream(); 14678f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 14682bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "MAGIC: " << image_header_.GetMagic() << "\n\n"; 14692bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1470dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao os << "IMAGE LOCATION: " << image_space_.GetImageLocation() << "\n\n"; 1471dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao 14722bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "IMAGE BEGIN: " << reinterpret_cast<void*>(image_header_.GetImageBegin()) << "\n\n"; 14732bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1474e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier os << "IMAGE SIZE: " << image_header_.GetImageSize() << "\n\n"; 1475e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 1476e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier for (size_t i = 0; i < ImageHeader::kSectionCount; ++i) { 1477e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier auto section = static_cast<ImageHeader::ImageSections>(i); 1478e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier os << "IMAGE SECTION " << section << ": " << image_header_.GetImageSection(section) << "\n\n"; 1479e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 148031e8925781c2302f1d1a9b39e216ba415bfe0d7eMathieu Chartier 14812bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "OAT CHECKSUM: " << StringPrintf("0x%08x\n\n", image_header_.GetOatChecksum()); 14822bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1483700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom os << "OAT FILE BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatFileBegin()) << "\n\n"; 14842bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1485700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom os << "OAT DATA BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatDataBegin()) << "\n\n"; 1486700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 1487700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom os << "OAT DATA END:" << reinterpret_cast<void*>(image_header_.GetOatDataEnd()) << "\n\n"; 1488700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 1489700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom os << "OAT FILE END:" << reinterpret_cast<void*>(image_header_.GetOatFileEnd()) << "\n\n"; 14902bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 1491a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light os << "PATCH DELTA:" << image_header_.GetPatchDelta() << "\n\n"; 1492a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light 149346774767fcf7780d1455e755729198648d08742eIgor Murashkin os << "COMPILE PIC: " << (image_header_.CompilePic() ? "yes" : "no") << "\n\n"; 149446774767fcf7780d1455e755729198648d08742eIgor Murashkin 14952bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 14962bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "ROOTS: " << reinterpret_cast<void*>(image_header_.GetImageRoots()) << "\n"; 1497e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static_assert(arraysize(image_roots_descriptions_) == 1498e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static_cast<size_t>(ImageHeader::kImageRootsMax), "sizes must match"); 14992bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers for (int i = 0; i < ImageHeader::kImageRootsMax; i++) { 15002bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i); 15012bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers const char* image_root_description = image_roots_descriptions_[i]; 15022dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* image_root_object = image_header_.GetImageRoot(image_root); 15038f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent_os << StringPrintf("%s: %p\n", image_root_description, image_root_object); 15042bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (image_root_object->IsObjectArray()) { 15052dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::ObjectArray<mirror::Object>* image_root_object_array 1506fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers = image_root_object->AsObjectArray<mirror::Object>(); 15078f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(&vios_); 1508277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe for (int j = 0; j < image_root_object_array->GetLength(); j++) { 1509277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe mirror::Object* value = image_root_object_array->Get(j); 1510fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers size_t run = 0; 1511277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe for (int32_t k = j + 1; k < image_root_object_array->GetLength(); k++) { 1512277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe if (value == image_root_object_array->Get(k)) { 1513fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers run++; 1514fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers } else { 1515fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers break; 1516fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers } 1517fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers } 1518fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers if (run == 0) { 15198f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent_os << StringPrintf("%d: ", j); 1520fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers } else { 15218f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent_os << StringPrintf("%d to %zd: ", j, j + run); 1522277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe j = j + run; 1523fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers } 15242ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (value != nullptr) { 15258f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko PrettyObjectValue(indent_os, value->GetClass(), value); 15262bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } else { 15278f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent_os << j << ": null\n"; 15282bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 1529d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 153034f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom } 153134f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom } 15328f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko } 1533e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 15348f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko { 1535e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier os << "METHOD ROOTS\n"; 1536e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static_assert(arraysize(image_methods_descriptions_) == 1537e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static_cast<size_t>(ImageHeader::kImageMethodsCount), "sizes must match"); 1538e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier for (int i = 0; i < ImageHeader::kImageMethodsCount; i++) { 1539e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier auto image_root = static_cast<ImageHeader::ImageMethod>(i); 1540e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const char* description = image_methods_descriptions_[i]; 1541e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier auto* image_method = image_header_.GetImageMethod(image_root); 15428f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko indent_os << StringPrintf("%s: %p\n", description, image_method); 1543e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 154427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 15452bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n"; 154627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 1547f9c6fc610b27887f832e453a0da1789187293408Mathieu Chartier Runtime* const runtime = Runtime::Current(); 1548f9c6fc610b27887f832e453a0da1789187293408Mathieu Chartier ClassLinker* class_linker = runtime->GetClassLinker(); 15492ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom std::string image_filename = image_space_.GetImageFilename(); 15502ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(image_filename); 15512bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "OAT LOCATION: " << oat_location; 15522bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n"; 15538d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string error_msg; 15540b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const OatFile* oat_file = image_space_.GetOatFile(); 1555a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light if (oat_file == nullptr) { 15560b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_file = runtime->GetOatFileManager().FindOpenedOatFileFromOatLocation(oat_location); 15570b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 15580b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (oat_file == nullptr) { 15590b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_file = OatFile::Open(oat_location, 15600b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_location, 15610b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 15620b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 15630b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier false, 15640b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier /*low_4gb*/false, 15650b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 1566b1d8c314b55bb2df2b2bb72a3daaf5db65b7ebc7Igor Murashkin &error_msg); 15670b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 15680b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (oat_file == nullptr) { 15690b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier os << "OAT FILE NOT FOUND: " << error_msg << "\n"; 15700b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return EXIT_FAILURE; 1571aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 15722bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n"; 1573aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 15743a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers stats_.oat_file_bytes = oat_file->Size(); 157578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 157632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis oat_dumper_.reset(new OatDumper(*oat_file, *oat_dumper_options_)); 15773a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 157802e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { 15792ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe CHECK(oat_dex_file != nullptr); 158002e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier stats_.oat_dex_file_sizes.push_back(std::make_pair(oat_dex_file->GetDexFileLocation(), 158102e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier oat_dex_file->FileSize())); 158205f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers } 158305f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers 15842bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "OBJECTS:\n" << std::flush; 1585b062fdd4cb097fbae69b4bcb479c34d83ecab8caMathieu Chartier 1586dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao // Loop through the image space and dump its objects. 1587f9c6fc610b27887f832e453a0da1789187293408Mathieu Chartier gc::Heap* heap = runtime->GetHeap(); 158850b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers Thread* self = Thread::Current(); 1589357e9be24c17a6bc2ae9fb53f25c73503116101dMathieu Chartier { 1590c22c59ef8513b4cbbfd25073d1afbf58196b522aMathieu Chartier { 1591c22c59ef8513b4cbbfd25073d1afbf58196b522aMathieu Chartier WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); 1592c22c59ef8513b4cbbfd25073d1afbf58196b522aMathieu Chartier heap->FlushAllocStack(); 1593c22c59ef8513b4cbbfd25073d1afbf58196b522aMathieu Chartier } 159490d706849a09590f150748ff97256ef718aca441Hiroshi Yamauchi // Since FlushAllocStack() above resets the (active) allocation 159590d706849a09590f150748ff97256ef718aca441Hiroshi Yamauchi // stack. Need to revoke the thread-local allocation stacks that 159690d706849a09590f150748ff97256ef718aca441Hiroshi Yamauchi // point into it. 1597f1d666e1b48f8070ef1177fce156c08827f08eb8Mathieu Chartier ScopedThreadSuspension sts(self, kNative); 15984f55e22630d99ca0edd9e951e5ee96b57bb9b980Mathieu Chartier ScopedSuspendAll ssa(__FUNCTION__); 1599f1d666e1b48f8070ef1177fce156c08827f08eb8Mathieu Chartier heap->RevokeAllThreadLocalAllocationStacks(self); 1600357e9be24c17a6bc2ae9fb53f25c73503116101dMathieu Chartier } 16012bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 1602e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier // Mark dex caches. 160305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko dex_caches_.clear(); 1604e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier { 1605e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ReaderMutexLock mu(self, *class_linker->DexLock()); 160604302dbb106d590ff72c0dfecda23d85b6565059Hiroshi Yamauchi for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) { 1607673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier mirror::DexCache* dex_cache = 160804302dbb106d590ff72c0dfecda23d85b6565059Hiroshi Yamauchi down_cast<mirror::DexCache*>(self->DecodeJObject(data.weak_root)); 1609673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier if (dex_cache != nullptr) { 161005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko dex_caches_.insert(dex_cache); 1611673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier } 1612e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 1613e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 16142bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_); 1615dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao // Dump the normal objects before ArtMethods. 1616dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao image_space_.GetLiveBitmap()->Walk(ImageDumper::Callback, this); 1617dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao indent_os << "\n"; 1618dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao // TODO: Dump fields. 1619dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao // Dump methods after. 1620dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao const auto& methods_section = image_header_.GetMethodsSection(); 1621dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao DumpArtMethodVisitor visitor(this); 16220b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier methods_section.VisitPackedArtMethods(&visitor, 16230b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_space_.Begin(), 16240b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_header_.GetPointerSize()); 16252bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers // Dump the large objects separately. 1626bbd695c71e0bf518f582e84524e1cdeb3de3896cMathieu Chartier heap->GetLargeObjectsSpace()->GetLiveBitmap()->Walk(ImageDumper::Callback, this); 16272bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers indent_os << "\n"; 1628b062fdd4cb097fbae69b4bcb479c34d83ecab8caMathieu Chartier } 16292bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "STATS:\n" << std::flush; 1630700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::unique_ptr<File> file(OS::OpenFileForReading(image_filename.c_str())); 16310b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier size_t data_size = image_header_.GetDataSize(); // stored size in file. 16320b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (file == nullptr) { 16332ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom LOG(WARNING) << "Failed to find image in " << image_filename; 16340b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } else { 16352ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom stats_.file_bytes = file->GetLength(); 16360b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // If the image is compressed, adjust to decompressed size. 16370b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier size_t uncompressed_size = image_header_.GetImageSize() - sizeof(ImageHeader); 16380b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (image_header_.GetStorageMode() == ImageHeader::kStorageModeUncompressed) { 16390b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier DCHECK_EQ(uncompressed_size, data_size) << "Sizes should match for uncompressed image"; 16400b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 16410b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.file_bytes += uncompressed_size - data_size; 16426f277751ec5bfc0d7469b2cc7f7134e9032593f1Brian Carlstrom } 16433a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t header_bytes = sizeof(ImageHeader); 1644ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe const auto& object_section = image_header_.GetImageSection(ImageHeader::kSectionObjects); 1645e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const auto& field_section = image_header_.GetImageSection(ImageHeader::kSectionArtFields); 1646e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const auto& method_section = image_header_.GetMethodsSection(); 164705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko const auto& dex_cache_arrays_section = image_header_.GetImageSection( 164805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko ImageHeader::kSectionDexCacheArrays); 1649d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier const auto& intern_section = image_header_.GetImageSection( 1650d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier ImageHeader::kSectionInternedStrings); 1651208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier const auto& class_table_section = image_header_.GetImageSection( 1652208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier ImageHeader::kSectionClassTable); 1653ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe const auto& bitmap_section = image_header_.GetImageSection(ImageHeader::kSectionImageBitmap); 1654ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 16553a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers stats_.header_bytes = header_bytes; 1656ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1657ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Objects are kObjectAlignment-aligned. 1658ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // CHECK_EQ(RoundUp(header_bytes, kObjectAlignment), object_section.Offset()); 1659ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe if (object_section.Offset() > header_bytes) { 1660ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += object_section.Offset() - header_bytes; 1661ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe } 1662ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1663ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Field section is 4-byte aligned. 1664ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe constexpr size_t kFieldSectionAlignment = 4U; 1665ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe uint32_t end_objects = object_section.Offset() + object_section.Size(); 1666ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe CHECK_EQ(RoundUp(end_objects, kFieldSectionAlignment), field_section.Offset()); 1667ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += field_section.Offset() - end_objects; 1668ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1669ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Method section is 4/8 byte aligned depending on target. Just check for 4-byte alignment. 1670ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe uint32_t end_fields = field_section.Offset() + field_section.Size(); 1671ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe CHECK_ALIGNED(method_section.Offset(), 4); 1672ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += method_section.Offset() - end_fields; 1673ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1674ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Dex cache arrays section is aligned depending on the target. Just check for 4-byte alignment. 1675ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe uint32_t end_methods = method_section.Offset() + method_section.Size(); 1676ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe CHECK_ALIGNED(dex_cache_arrays_section.Offset(), 4); 1677ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += dex_cache_arrays_section.Offset() - end_methods; 1678ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1679ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Intern table is 8-byte aligned. 1680ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe uint32_t end_caches = dex_cache_arrays_section.Offset() + dex_cache_arrays_section.Size(); 1681ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe CHECK_EQ(RoundUp(end_caches, 8U), intern_section.Offset()); 1682ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += intern_section.Offset() - end_caches; 1683ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1684ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe // Add space between intern table and class table. 1685ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe uint32_t end_intern = intern_section.Offset() + intern_section.Size(); 1686ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe stats_.alignment_bytes += class_table_section.Offset() - end_intern; 1687ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 16880b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // Add space between end of image data and bitmap. Expect the bitmap to be page-aligned. 16890b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const size_t bitmap_offset = sizeof(ImageHeader) + data_size; 1690ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe CHECK_ALIGNED(bitmap_section.Offset(), kPageSize); 16910b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.alignment_bytes += RoundUp(bitmap_offset, kPageSize) - bitmap_offset; 1692ace0dc1dd5480ad458e622085e51583653853fb9Andreas Gampe 1693e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier stats_.bitmap_bytes += bitmap_section.Size(); 1694e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier stats_.art_field_bytes += field_section.Size(); 1695cf36d493124d8048efa0bd6f67d817ce3cd6b725Vladimir Marko stats_.art_method_bytes += method_section.Size(); 169605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko stats_.dex_cache_arrays_bytes += dex_cache_arrays_section.Size(); 1697d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier stats_.interned_strings_bytes += intern_section.Size(); 1698208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier stats_.class_table_bytes += class_table_section.Size(); 16998f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko stats_.Dump(os, indent_os); 17002bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n"; 170127ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 17022bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << std::flush; 17033a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 17042cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return oat_dumper_->Dump(os); 17053a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1706d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes 17073a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers private: 170854d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier class DumpArtMethodVisitor : public ArtMethodVisitor { 170954d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier public: 171054d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier explicit DumpArtMethodVisitor(ImageDumper* image_dumper) : image_dumper_(image_dumper) {} 171154d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier 171254d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier virtual void Visit(ArtMethod* method) OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { 171354d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier std::ostream& indent_os = image_dumper_->vios_.Stream(); 171454d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier indent_os << method << " " << " ArtMethod: " << PrettyMethod(method) << "\n"; 17150b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_dumper_->DumpMethod(method, indent_os); 171654d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier indent_os << "\n"; 171754d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier } 171854d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier 171954d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier private: 172054d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier ImageDumper* const image_dumper_; 172154d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier }; 172254d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier 17232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers static void PrettyObjectValue(std::ostream& os, mirror::Class* type, mirror::Object* value) 172490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 17252ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe CHECK(type != nullptr); 17262ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (value == nullptr) { 17272bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("null %s\n", PrettyDescriptor(type).c_str()); 1728d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else if (type->IsStringClass()) { 17292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::String* string = value->AsString(); 17302bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p String: %s\n", string, 173168b56858367e29461ae290fd797443a1ef6d8005Ian Rogers PrintableString(string->ToModifiedUtf8().c_str()).c_str()); 173264b6d145fa53b8dfb07a8fc2426af13f155d5a4dIan Rogers } else if (type->IsClassClass()) { 17332dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* klass = value->AsClass(); 17342bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p Class: %s\n", klass, PrettyDescriptor(klass).c_str()); 1735d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else { 17362bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p %s\n", value, PrettyDescriptor(type).c_str()); 1737d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1738d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1739d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers 1740c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier static void PrintField(std::ostream& os, ArtField* field, mirror::Object* obj) 174190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 174261c5ebc6aee2cac1c363de6fbdac25ada1697fdbMathieu Chartier os << StringPrintf("%s: ", field->GetName()); 174308f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers switch (field->GetTypeAsPrimitiveType()) { 174408f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimLong: 1745ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers os << StringPrintf("%" PRId64 " (0x%" PRIx64 ")\n", field->Get64(obj), field->Get64(obj)); 174608f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 174708f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimDouble: 17482bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%f (%a)\n", field->GetDouble(obj), field->GetDouble(obj)); 174908f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 175008f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimFloat: 17512bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%f (%a)\n", field->GetFloat(obj), field->GetFloat(obj)); 175208f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 175308f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimInt: 17542bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%d (0x%x)\n", field->Get32(obj), field->Get32(obj)); 175508f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 175608f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimChar: 175737f05ef45e0393de812d51261dc293240c17294dFred Shih os << StringPrintf("%u (0x%x)\n", field->GetChar(obj), field->GetChar(obj)); 175808f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 175908f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimShort: 176037f05ef45e0393de812d51261dc293240c17294dFred Shih os << StringPrintf("%d (0x%x)\n", field->GetShort(obj), field->GetShort(obj)); 176108f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 176208f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimBoolean: 176337f05ef45e0393de812d51261dc293240c17294dFred Shih os << StringPrintf("%s (0x%x)\n", field->GetBoolean(obj)? "true" : "false", 176437f05ef45e0393de812d51261dc293240c17294dFred Shih field->GetBoolean(obj)); 176508f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 176608f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimByte: 176737f05ef45e0393de812d51261dc293240c17294dFred Shih os << StringPrintf("%d (0x%x)\n", field->GetByte(obj), field->GetByte(obj)); 176808f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 176908f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers case Primitive::kPrimNot: { 177008f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers // Get the value, don't compute the type unless it is non-null as we don't want 177108f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers // to cause class loading. 177208f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers mirror::Object* value = field->GetObj(obj); 177308f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers if (value == nullptr) { 177408f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers os << StringPrintf("null %s\n", PrettyDescriptor(field->GetTypeDescriptor()).c_str()); 177550239c75041df9e12f9cbb018ccc08af6890e102Ian Rogers } else { 177608f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers // Grab the field type without causing resolution. 1777daaf3265806eb2eadb2e03302bd68022fab5ca28Mathieu Chartier mirror::Class* field_type = field->GetType<false>(); 177808f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers if (field_type != nullptr) { 177908f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers PrettyObjectValue(os, field_type, value); 178008f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers } else { 178108f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers os << StringPrintf("%p %s\n", value, 178208f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers PrettyDescriptor(field->GetTypeDescriptor()).c_str()); 178308f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers } 178450239c75041df9e12f9cbb018ccc08af6890e102Ian Rogers } 178508f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 178648efc2b5c4b95ac507de5150cd315c6e1c96b381Ian Rogers } 178708f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers default: 178808f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers os << "unexpected field type: " << field->GetTypeDescriptor() << "\n"; 178908f1f50d6c2e8f247b8f5f19711d75a792851c7aIan Rogers break; 1790d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1791d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1792d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers 17932dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers static void DumpFields(std::ostream& os, mirror::Object* obj, mirror::Class* klass) 179490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 17952dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* super = klass->GetSuperClass(); 17962ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (super != nullptr) { 17972bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers DumpFields(os, obj, super); 1798d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 179954d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier for (ArtField& field : klass->GetIFields()) { 180054d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier PrintField(os, &field, obj); 1801d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1802d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1803d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers 18042dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers bool InDumpSpace(const mirror::Object* object) { 18053a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return image_space_.Contains(object); 1806f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 18073a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 18080b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const void* GetQuickOatCodeBegin(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_) { 1809a7dd0386f35c0ba4aef3f5b16bc84c6f4e2fc702Mathieu Chartier const void* quick_code = m->GetEntryPointFromQuickCompiledCodePtrSize( 18100b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_header_.GetPointerSize()); 18116f3dbbadf4ce66982eb3d400e0a74cb73eb034f3Ian Rogers if (Runtime::Current()->GetClassLinker()->IsQuickResolutionStub(quick_code)) { 1812ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers quick_code = oat_dumper_->GetQuickOatCode(m); 18133a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1814f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom if (oat_dumper_->GetInstructionSet() == kThumb2) { 1815ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers quick_code = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(quick_code) & ~0x1); 1816f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 1817ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return quick_code; 18183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 18193a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 1820e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier uint32_t GetQuickOatCodeSize(ArtMethod* m) 182190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 1822ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const uint32_t* oat_code_begin = reinterpret_cast<const uint32_t*>(GetQuickOatCodeBegin(m)); 1823ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (oat_code_begin == nullptr) { 1824f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom return 0; 1825f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 1826f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom return oat_code_begin[-1]; 1827f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 1828f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom 1829e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const void* GetQuickOatCodeEnd(ArtMethod* m) 183090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 1831ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const uint8_t* oat_code_begin = reinterpret_cast<const uint8_t*>(GetQuickOatCodeBegin(m)); 18322ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe if (oat_code_begin == nullptr) { 18332ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe return nullptr; 1834f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 1835ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return oat_code_begin + GetQuickOatCodeSize(m); 1836f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom } 1837f8bbb8448c733e9e3ad43aad69774c37888329b1Brian Carlstrom 183890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier static void Callback(mirror::Object* obj, void* arg) SHARED_REQUIRES(Locks::mutator_lock_) { 18392ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe DCHECK(obj != nullptr); 18402ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe DCHECK(arg != nullptr); 18413a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers ImageDumper* state = reinterpret_cast<ImageDumper*>(arg); 184278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom if (!state->InDumpSpace(obj)) { 184378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom return; 184478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 1845916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 1846916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes = obj->SizeOf(); 1847916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes; 1848916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.object_bytes += object_bytes; 1849916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom state->stats_.alignment_bytes += alignment_bytes; 1850916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 18518f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko std::ostream& os = state->vios_.Stream(); 18528f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 18532dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* obj_class = obj->GetClass(); 1854d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers if (obj_class->IsArrayClass()) { 18552bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p: %s length:%d\n", obj, PrettyDescriptor(obj_class).c_str(), 18562bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers obj->AsArray()->GetLength()); 1857d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else if (obj->IsClass()) { 18582dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* klass = obj->AsClass(); 18592bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p: java.lang.Class \"%s\" (", obj, PrettyDescriptor(klass).c_str()) 18602bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers << klass->GetStatus() << ")\n"; 1861d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else if (obj_class->IsStringClass()) { 18622bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p: java.lang.String %s\n", obj, 186368b56858367e29461ae290fd797443a1ef6d8005Ian Rogers PrintableString(obj->AsString()->ToModifiedUtf8().c_str()).c_str()); 186478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else { 18652bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%p: %s\n", obj, PrettyDescriptor(obj_class).c_str()); 186678128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 18678f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1(&state->vios_); 18688f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko DumpFields(os, obj, obj_class); 18690b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const size_t image_pointer_size = state->image_header_.GetPointerSize(); 1870d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers if (obj->IsObjectArray()) { 1871e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier auto* obj_array = obj->AsObjectArray<mirror::Object>(); 1872e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier for (int32_t i = 0, length = obj_array->GetLength(); i < length; i++) { 18732dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* value = obj_array->Get(i); 1874d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers size_t run = 0; 1875d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers for (int32_t j = i + 1; j < length; j++) { 1876d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers if (value == obj_array->Get(j)) { 1877d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers run++; 1878d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else { 1879d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers break; 1880d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1881d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1882d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers if (run == 0) { 18838f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko os << StringPrintf("%d: ", i); 188478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } else { 18858f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko os << StringPrintf("%d to %zd: ", i, i + run); 1886d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers i = i + run; 188778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 18882ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom mirror::Class* value_class = 18892ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe (value == nullptr) ? obj_class->GetComponentType() : value->GetClass(); 18908f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko PrettyObjectValue(os, value_class, value); 1891d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1892d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } else if (obj->IsClass()) { 1893c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier mirror::Class* klass = obj->AsClass(); 189454d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier if (klass->NumStaticFields() != 0) { 18958f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko os << "STATICS:\n"; 18968f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent2(&state->vios_); 189754d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier for (ArtField& field : klass->GetSFields()) { 189854d220eb9cc51215d75b9e0fe921b94bebbb3fd6Mathieu Chartier PrintField(os, &field, field.GetDeclaringClass()); 1899d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1900d5b32607798a46a905ba2d8d5bf7507cc970aa58Ian Rogers } 1901e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } else { 190205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko auto it = state->dex_caches_.find(obj); 190305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (it != state->dex_caches_.end()) { 190405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko auto* dex_cache = down_cast<mirror::DexCache*>(obj); 1905e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const auto& field_section = state->image_header_.GetImageSection( 1906e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ImageHeader::kSectionArtFields); 1907e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const auto& method_section = state->image_header_.GetMethodsSection(); 190805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko size_t num_methods = dex_cache->NumResolvedMethods(); 190905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (num_methods != 0u) { 191005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << "Methods (size=" << num_methods << "):"; 191105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko ScopedIndentation indent2(&state->vios_); 191205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko auto* resolved_methods = dex_cache->GetResolvedMethods(); 191305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko for (size_t i = 0, length = dex_cache->NumResolvedMethods(); i < length; ++i) { 19140b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier auto* elem = mirror::DexCache::GetElementPtrSize(resolved_methods, 19150b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier i, 19160b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_pointer_size); 191705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko size_t run = 0; 191805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko for (size_t j = i + 1; 191905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_methods, 192005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko j, 192105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko image_pointer_size); 192205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko ++j, ++run) {} 192305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (run == 0) { 192405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%zd: ", i); 192505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else { 192605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%zd to %zd: ", i, i + run); 192705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko i = i + run; 192805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } 192905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko std::string msg; 193005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (elem == nullptr) { 193105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = "null"; 193205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else if (method_section.Contains( 193305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { 193405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = PrettyMethod(reinterpret_cast<ArtMethod*>(elem)); 193505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else { 193605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = "<not in method section>"; 193705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } 193805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%p %s\n", elem, msg.c_str()); 1939e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 194005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } 194105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko size_t num_fields = dex_cache->NumResolvedFields(); 194205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (num_fields != 0u) { 194305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << "Fields (size=" << num_fields << "):"; 194405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko ScopedIndentation indent2(&state->vios_); 194505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko auto* resolved_fields = dex_cache->GetResolvedFields(); 194605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko for (size_t i = 0, length = dex_cache->NumResolvedFields(); i < length; ++i) { 194705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko auto* elem = mirror::DexCache::GetElementPtrSize(resolved_fields, i, image_pointer_size); 194805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko size_t run = 0; 194905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko for (size_t j = i + 1; 195005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_fields, 195105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko j, 195205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko image_pointer_size); 195305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko ++j, ++run) {} 195405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (run == 0) { 195505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%zd: ", i); 195605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else { 195705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%zd to %zd: ", i, i + run); 195805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko i = i + run; 195905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } 196005792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko std::string msg; 196105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko if (elem == nullptr) { 196205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = "null"; 196305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else if (field_section.Contains( 196405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { 196505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = PrettyField(reinterpret_cast<ArtField*>(elem)); 196605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } else { 196705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko msg = "<not in field section>"; 196805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko } 196905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko os << StringPrintf("%p %s\n", elem, msg.c_str()); 1970e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 19713a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 1972e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 1973e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 1974e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier std::string temp; 1975e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier state->stats_.Update(obj_class->GetDescriptor(&temp), object_bytes); 1976e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 19773a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 19780b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier void DumpMethod(ArtMethod* method, std::ostream& indent_os) 197990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 1980e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier DCHECK(method != nullptr); 19810b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const void* quick_oat_code_begin = GetQuickOatCodeBegin(method); 19820b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const void* quick_oat_code_end = GetQuickOatCodeEnd(method); 1983524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray OatQuickMethodHeader* method_header = reinterpret_cast<OatQuickMethodHeader*>( 1984524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray reinterpret_cast<uintptr_t>(quick_oat_code_begin) - sizeof(OatQuickMethodHeader)); 1985e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (method->IsNative()) { 1986524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray if (!Runtime::Current()->GetClassLinker()->IsQuickGenericJniStub(quick_oat_code_begin)) { 1987524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray DCHECK(method_header->GetNativeGcMap() == nullptr) << PrettyMethod(method); 1988524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray DCHECK(method_header->GetMappingTable() == nullptr) << PrettyMethod(method); 1989524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray } 1990e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier bool first_occurrence; 19910b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier uint32_t quick_oat_code_size = GetQuickOatCodeSize(method); 19920b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier ComputeOatSize(quick_oat_code_begin, &first_occurrence); 1993e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (first_occurrence) { 19940b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.native_to_managed_code_bytes += quick_oat_code_size; 1995e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 19960b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (quick_oat_code_begin != method->GetEntryPointFromQuickCompiledCodePtrSize( 19970b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier image_header_.GetPointerSize())) { 19986bc4374e3fa00e3ee5e832e1761c43e0b8a71558Nicolas Geoffray indent_os << StringPrintf("OAT CODE: %p\n", quick_oat_code_begin); 1999e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 2000796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray } else if (method->IsAbstract() || 2001796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray method->IsCalleeSaveMethod() || 2002796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray method->IsResolutionMethod() || 2003796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray (method == Runtime::Current()->GetImtConflictMethod()) || 2004796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray method->IsImtUnimplementedMethod() || 2005796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray method->IsClassInitializer()) { 2006796d63050a18f263b93ea34951a61deaecab3422Nicolas Geoffray // Don't print information for these. 2007e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } else { 2008e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const DexFile::CodeItem* code_item = method->GetCodeItem(); 2009e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2; 20100b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.dex_instruction_bytes += dex_instruction_bytes; 2011e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 2012e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier bool first_occurrence; 20130b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier size_t gc_map_bytes = ComputeOatSize(method_header->GetNativeGcMap(), &first_occurrence); 2014e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (first_occurrence) { 20150b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.gc_map_bytes += gc_map_bytes; 2016e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 2017e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 20180b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier size_t pc_mapping_table_bytes = ComputeOatSize( 2019524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray method_header->GetMappingTable(), &first_occurrence); 2020e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (first_occurrence) { 20210b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.pc_mapping_table_bytes += pc_mapping_table_bytes; 2022e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 2023e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 20246d7f1796f3afafaaae4bf71088f92184adcff858Roland Levillain size_t vmap_table_bytes = 0u; 2025524e7ea8cd17bad17bd9f3e0ccbb19ad0d4d9c02Nicolas Geoffray if (!method_header->IsOptimized()) { 20266d7f1796f3afafaaae4bf71088f92184adcff858Roland Levillain // Method compiled with the optimizing compiler have no vmap table. 20270b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier vmap_table_bytes = ComputeOatSize(method_header->GetVmapTable(), &first_occurrence); 20286d7f1796f3afafaaae4bf71088f92184adcff858Roland Levillain if (first_occurrence) { 20290b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.vmap_table_bytes += vmap_table_bytes; 20306d7f1796f3afafaaae4bf71088f92184adcff858Roland Levillain } 2031e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 2032e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier 20330b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier uint32_t quick_oat_code_size = GetQuickOatCodeSize(method); 20340b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier ComputeOatSize(quick_oat_code_begin, &first_occurrence); 2035e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (first_occurrence) { 20360b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.managed_code_bytes += quick_oat_code_size; 2037e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (method->IsConstructor()) { 2038e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier if (method->IsStatic()) { 20390b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.class_initializer_code_bytes += quick_oat_code_size; 2040e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } else if (dex_instruction_bytes > kLargeConstructorDexBytes) { 20410b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.large_initializer_code_bytes += quick_oat_code_size; 20420d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers } 2043e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } else if (dex_instruction_bytes > kLargeMethodDexBytes) { 20440b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.large_method_code_bytes += quick_oat_code_size; 20453a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 2046e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier } 20470b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.managed_code_bytes_ignoring_deduplication += quick_oat_code_size; 20483a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 20497617abdb402fd0419daa3eefb2ad059ccbb8b6dbIgor Murashkin uint32_t method_access_flags = method->GetAccessFlags(); 20507617abdb402fd0419daa3eefb2ad059ccbb8b6dbIgor Murashkin 2051e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier indent_os << StringPrintf("OAT CODE: %p-%p\n", quick_oat_code_begin, quick_oat_code_end); 20527617abdb402fd0419daa3eefb2ad059ccbb8b6dbIgor Murashkin indent_os << StringPrintf("SIZE: Dex Instructions=%zd GC=%zd Mapping=%zd AccessFlags=0x%x\n", 20537617abdb402fd0419daa3eefb2ad059ccbb8b6dbIgor Murashkin dex_instruction_bytes, gc_map_bytes, pc_mapping_table_bytes, 20547617abdb402fd0419daa3eefb2ad059ccbb8b6dbIgor Murashkin method_access_flags); 20553a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 2056e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier size_t total_size = dex_instruction_bytes + gc_map_bytes + pc_mapping_table_bytes + 20570b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier vmap_table_bytes + quick_oat_code_size + ArtMethod::Size(image_header_.GetPointerSize()); 20583a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 2059e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier double expansion = 2060e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static_cast<double>(quick_oat_code_size) / static_cast<double>(dex_instruction_bytes); 20610b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier stats_.ComputeOutliers(total_size, expansion, method); 206278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 206378128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom } 206427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom 20653a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers std::set<const void*> already_seen_; 20663a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers // Compute the size of the given data within the oat file and whether this is the first time 20673a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers // this data has been requested 2068a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes size_t ComputeOatSize(const void* oat_data, bool* first_occurrence) { 20693a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (already_seen_.count(oat_data) == 0) { 2070a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes *first_occurrence = true; 20713a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers already_seen_.insert(oat_data); 20723a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 2073a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes *first_occurrence = false; 20743a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 20753a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return oat_dumper_->ComputeSize(oat_data); 207627ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom } 2077916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2078916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom public: 2079916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom struct Stats { 20803a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t oat_file_bytes; 2081916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t file_bytes; 2082916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2083916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t header_bytes; 2084916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes; 2085e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier size_t art_field_bytes; 2086e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier size_t art_method_bytes; 208705792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko size_t dex_cache_arrays_bytes; 2088d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier size_t interned_strings_bytes; 2089208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier size_t class_table_bytes; 209032327098e300ab66671b891a18bf669576fc896aMathieu Chartier size_t bitmap_bytes; 2091916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t alignment_bytes; 2092916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2093916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t managed_code_bytes; 20943a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t managed_code_bytes_ignoring_deduplication; 2095916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t managed_to_native_code_bytes; 2096916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t native_to_managed_code_bytes; 20970d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers size_t class_initializer_code_bytes; 20980d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers size_t large_initializer_code_bytes; 20990d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers size_t large_method_code_bytes; 2100916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 21013a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t gc_map_bytes; 2102916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t pc_mapping_table_bytes; 21033a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t vmap_table_bytes; 2104916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2105916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t dex_instruction_bytes; 2106916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2107e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier std::vector<ArtMethod*> method_outlier; 21083a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers std::vector<size_t> method_outlier_size; 21093a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers std::vector<double> method_outlier_expansion; 2110700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::vector<std::pair<std::string, size_t>> oat_dex_file_sizes; 21113a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 21123887c468d731420e929e6ad3acf190d5431e94fcRoland Levillain Stats() 21133a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers : oat_file_bytes(0), 21143a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers file_bytes(0), 2115916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom header_bytes(0), 2116916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom object_bytes(0), 2117e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier art_field_bytes(0), 2118e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier art_method_bytes(0), 211905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko dex_cache_arrays_bytes(0), 2120d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier interned_strings_bytes(0), 2121208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier class_table_bytes(0), 212232327098e300ab66671b891a18bf669576fc896aMathieu Chartier bitmap_bytes(0), 2123916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom alignment_bytes(0), 2124916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_code_bytes(0), 21253a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers managed_code_bytes_ignoring_deduplication(0), 2126916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom managed_to_native_code_bytes(0), 2127916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom native_to_managed_code_bytes(0), 21280d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers class_initializer_code_bytes(0), 21290d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers large_initializer_code_bytes(0), 21300d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers large_method_code_bytes(0), 21313a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers gc_map_bytes(0), 2132916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom pc_mapping_table_bytes(0), 21333a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers vmap_table_bytes(0), 2134916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom dex_instruction_bytes(0) {} 2135916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2136a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes struct SizeAndCount { 2137277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe SizeAndCount(size_t bytes_in, size_t count_in) : bytes(bytes_in), count(count_in) {} 2138a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes size_t bytes; 2139a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes size_t count; 2140a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes }; 2141a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes typedef SafeMap<std::string, SizeAndCount> SizeAndCountTable; 2142a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes SizeAndCountTable sizes_and_counts; 2143a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes 2144277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe void Update(const char* descriptor, size_t object_bytes_in) { 2145a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes SizeAndCountTable::iterator it = sizes_and_counts.find(descriptor); 2146a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes if (it != sizes_and_counts.end()) { 2147277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe it->second.bytes += object_bytes_in; 2148a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes it->second.count += 1; 2149a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes } else { 2150277ccbd200ea43590dfc06a93ae184a765327ad0Andreas Gampe sizes_and_counts.Put(descriptor, SizeAndCount(object_bytes_in, 1)); 2151a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes } 2152a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes } 2153916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 21543a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double PercentOfOatBytes(size_t size) { 21553a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers return (static_cast<double>(size) / static_cast<double>(oat_file_bytes)) * 100; 21563a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 21573a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 2158916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double PercentOfFileBytes(size_t size) { 2159916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100; 2160916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 2161916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2162916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom double PercentOfObjectBytes(size_t size) { 2163916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100; 2164916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 2165916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2166e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier void ComputeOutliers(size_t total_size, double expansion, ArtMethod* method) { 21673a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers method_outlier_size.push_back(total_size); 21683a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers method_outlier_expansion.push_back(expansion); 21693a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers method_outlier.push_back(method); 21703a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 21713a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 217200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers void DumpOutliers(std::ostream& os) 217390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 21743a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t sum_of_sizes = 0; 21753a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t sum_of_sizes_squared = 0; 21763a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t sum_of_expansion = 0; 21773a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t sum_of_expansion_squared = 0; 21783a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t n = method_outlier_size.size(); 2179dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao if (n == 0) { 2180dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao return; 2181dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao } 21823a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 0; i < n; i++) { 21833a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t cur_size = method_outlier_size[i]; 21843a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers sum_of_sizes += cur_size; 21853a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers sum_of_sizes_squared += cur_size * cur_size; 21863a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double cur_expansion = method_outlier_expansion[i]; 21873a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers sum_of_expansion += cur_expansion; 21883a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers sum_of_expansion_squared += cur_expansion * cur_expansion; 21893a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 21903a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t size_mean = sum_of_sizes / n; 21913a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t size_variance = (sum_of_sizes_squared - sum_of_sizes * size_mean) / (n - 1); 21923a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double expansion_mean = sum_of_expansion / n; 21933a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double expansion_variance = 21943a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers (sum_of_expansion_squared - sum_of_expansion * expansion_mean) / (n - 1); 21953a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 21963a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers // Dump methods whose size is a certain number of standard deviations from the mean 21973a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t dumped_values = 0; 21983a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t skipped_values = 0; 21993a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 100; i > 0; i--) { // i is the current number of standard deviations 22003a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t cur_size_variance = i * i * size_variance; 22013a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers bool first = true; 22023a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t j = 0; j < n; j++) { 22033a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t cur_size = method_outlier_size[j]; 22043a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (cur_size > size_mean) { 22053a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t cur_var = cur_size - size_mean; 22063a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers cur_var = cur_var * cur_var; 22073a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (cur_var > cur_size_variance) { 22083a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (dumped_values > 20) { 22093a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (i == 1) { 22103a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers skipped_values++; 22113a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 22123a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers i = 2; // jump to counting for 1 standard deviation 22133a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers break; 22143a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22153a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 22163a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (first) { 2217c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes os << "\nBig methods (size > " << i << " standard deviations the norm):\n"; 22183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers first = false; 22193a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22202bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << PrettyMethod(method_outlier[j]) << " requires storage of " 2221c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << PrettySize(cur_size) << "\n"; 22223a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers method_outlier_size[j] = 0; // don't consider this method again 22233a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers dumped_values++; 22243a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22253a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22263a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22273a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22283a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22293a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (skipped_values > 0) { 22302bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "... skipped " << skipped_values 2231c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << " methods with size > 1 standard deviation from the norm\n"; 22323a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 2233c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes os << std::flush; 22343a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 22353a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers // Dump methods whose expansion is a certain number of standard deviations from the mean 22363a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers dumped_values = 0; 22373a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers skipped_values = 0; 22383a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t i = 10; i > 0; i--) { // i is the current number of standard deviations 22393a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double cur_expansion_variance = i * i * expansion_variance; 22403a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers bool first = true; 22413a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers for (size_t j = 0; j < n; j++) { 22423a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers double cur_expansion = method_outlier_expansion[j]; 22433a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (cur_expansion > expansion_mean) { 22443a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers size_t cur_var = cur_expansion - expansion_mean; 22453a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers cur_var = cur_var * cur_var; 22463a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (cur_var > cur_expansion_variance) { 22473a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (dumped_values > 20) { 22483a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (i == 1) { 22493a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers skipped_values++; 22503a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 22513a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers i = 2; // jump to counting for 1 standard deviation 22523a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers break; 22533a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22543a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 22553a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (first) { 22563a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers os << "\nLarge expansion methods (size > " << i 2257c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << " standard deviations the norm):\n"; 22583a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers first = false; 22593a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22602bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << PrettyMethod(method_outlier[j]) << " expanded code by " 2261c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << cur_expansion << "\n"; 22623a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers method_outlier_expansion[j] = 0.0; // don't consider this method again 22633a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers dumped_values++; 22643a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22653a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22663a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22673a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22683a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22693a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (skipped_values > 0) { 22702bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "... skipped " << skipped_values 2271c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << " methods with expansion > 1 standard deviation from the norm\n"; 22723a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 2273c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes os << "\n" << std::flush; 22743a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 22753a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 22768f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko void Dump(std::ostream& os, std::ostream& indent_os) 227790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) { 22782bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers { 22792bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "art_file_bytes = " << PrettySize(file_bytes) << "\n\n" 22802bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers << "art_file_bytes = header_bytes + object_bytes + alignment_bytes\n"; 228105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko indent_os << StringPrintf("header_bytes = %8zd (%2.0f%% of art file bytes)\n" 228205792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "object_bytes = %8zd (%2.0f%% of art file bytes)\n" 228305792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "art_field_bytes = %8zd (%2.0f%% of art file bytes)\n" 228405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "art_method_bytes = %8zd (%2.0f%% of art file bytes)\n" 228505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "dex_cache_arrays_bytes = %8zd (%2.0f%% of art file bytes)\n" 228605792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "interned_string_bytes = %8zd (%2.0f%% of art file bytes)\n" 2287208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier "class_table_bytes = %8zd (%2.0f%% of art file bytes)\n" 228805792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "bitmap_bytes = %8zd (%2.0f%% of art file bytes)\n" 228905792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko "alignment_bytes = %8zd (%2.0f%% of art file bytes)\n\n", 22902bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers header_bytes, PercentOfFileBytes(header_bytes), 22912bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers object_bytes, PercentOfFileBytes(object_bytes), 2292e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier art_field_bytes, PercentOfFileBytes(art_field_bytes), 2293e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier art_method_bytes, PercentOfFileBytes(art_method_bytes), 229405792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko dex_cache_arrays_bytes, 229505792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko PercentOfFileBytes(dex_cache_arrays_bytes), 2296d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier interned_strings_bytes, 2297d39645e22b8db1767cf64dc1200a9e4b2f939ed2Mathieu Chartier PercentOfFileBytes(interned_strings_bytes), 2298208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier class_table_bytes, PercentOfFileBytes(class_table_bytes), 229932327098e300ab66671b891a18bf669576fc896aMathieu Chartier bitmap_bytes, PercentOfFileBytes(bitmap_bytes), 23002bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers alignment_bytes, PercentOfFileBytes(alignment_bytes)) 23012bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers << std::flush; 2302208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier CHECK_EQ(file_bytes, 2303208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier header_bytes + object_bytes + art_field_bytes + art_method_bytes + 2304208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier dex_cache_arrays_bytes + interned_strings_bytes + class_table_bytes + 2305208a5cb383dd9dcd3461f89b74af5df67dc8d794Mathieu Chartier bitmap_bytes + alignment_bytes); 23062bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 2307916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 23082bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "object_bytes breakdown:\n"; 2309916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom size_t object_bytes_total = 0; 231002e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier for (const auto& sizes_and_count : sizes_and_counts) { 231102e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier const std::string& descriptor(sizes_and_count.first); 231202e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier double average = static_cast<double>(sizes_and_count.second.bytes) / 231302e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier static_cast<double>(sizes_and_count.second.count); 231402e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier double percent = PercentOfObjectBytes(sizes_and_count.second.bytes); 23152bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%32s %8zd bytes %6zd instances " 2316a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes "(%4.0f bytes/instance) %2.0f%% of object_bytes\n", 231702e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier descriptor.c_str(), sizes_and_count.second.bytes, 231802e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier sizes_and_count.second.count, average, percent); 231902e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier object_bytes_total += sizes_and_count.second.bytes; 2320916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 2321c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes os << "\n" << std::flush; 2322916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom CHECK_EQ(object_bytes, object_bytes_total); 2323916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 23242bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("oat_file_bytes = %8zd\n" 23252bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" 23262bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "managed_to_native_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" 23272bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "native_to_managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n" 23282bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "class_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" 23292bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "large_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" 23302bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "large_method_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n", 233105f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers oat_file_bytes, 23322ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom managed_code_bytes, 23332ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(managed_code_bytes), 23342ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom managed_to_native_code_bytes, 23352ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(managed_to_native_code_bytes), 23362ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom native_to_managed_code_bytes, 23372ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(native_to_managed_code_bytes), 23382ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom class_initializer_code_bytes, 23392ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(class_initializer_code_bytes), 23402ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom large_initializer_code_bytes, 23412ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(large_initializer_code_bytes), 23422ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom large_method_code_bytes, 23432ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom PercentOfOatBytes(large_method_code_bytes)) 23442bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers << "DexFile sizes:\n"; 234502e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier for (const std::pair<std::string, size_t>& oat_dex_file_size : oat_dex_file_sizes) { 23462bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("%s = %zd (%2.0f%% of oat file bytes)\n", 234702e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier oat_dex_file_size.first.c_str(), oat_dex_file_size.second, 234802e25119b15a6f619f17db99f5d05124a5807ff3Mathieu Chartier PercentOfOatBytes(oat_dex_file_size.second)); 234905f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers } 235005f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers 23512bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << "\n" << StringPrintf("gc_map_bytes = %7zd (%2.0f%% of oat file bytes)\n" 23522bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "pc_mapping_table_bytes = %7zd (%2.0f%% of oat file bytes)\n" 23532bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "vmap_table_bytes = %7zd (%2.0f%% of oat file bytes)\n\n", 235405f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers gc_map_bytes, PercentOfOatBytes(gc_map_bytes), 235505f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers pc_mapping_table_bytes, PercentOfOatBytes(pc_mapping_table_bytes), 235605f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers vmap_table_bytes, PercentOfOatBytes(vmap_table_bytes)) 2357c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << std::flush; 2358916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 23592bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers os << StringPrintf("dex_instruction_bytes = %zd\n", dex_instruction_bytes) 23602bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers << StringPrintf("managed_code_bytes expansion = %.2f (ignoring deduplication %.2f)\n\n", 23612ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom static_cast<double>(managed_code_bytes) / 23622ec6520d57479d393bffa05defa1479b25ca8382Brian Carlstrom static_cast<double>(dex_instruction_bytes), 2363c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes static_cast<double>(managed_code_bytes_ignoring_deduplication) / 2364cf44e6f1ec194a906f4760a7c0395fdb0123d7aeElliott Hughes static_cast<double>(dex_instruction_bytes)) 2365c073b075241640c94c27e661ed6f29ff5fcee5d8Elliott Hughes << std::flush; 23663a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 23673a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers DumpOutliers(os); 2368916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } 2369916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom } stats_; 2370916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom 2371916e74e45b60902af342a71bdbfb806ff29c6c2bBrian Carlstrom private: 23720d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers enum { 23730d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers // Number of bytes for a constructor to be considered large. Based on the 1000 basic block 23740d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers // threshold, we assume 2 bytes per instruction and 2 instructions per block. 23750d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers kLargeConstructorDexBytes = 4000, 23760d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers // Number of bytes for a method to be considered large. Based on the 4000 basic block 23770d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers // threshold, we assume 2 bytes per instruction and 2 instructions per block. 23780d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers kLargeMethodDexBytes = 16000 23790d2d3785961d8d542cba68a8e9126b01d3102f64Ian Rogers }; 23808f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 23818f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // For performance, use the *os_ directly for anything that doesn't need indentation 23828f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko // and prepare an indentation stream with default indentation 1. 23832bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers std::ostream* os_; 23848f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko VariableIndentationOutputStream vios_; 23858f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko ScopedIndentation indent1_; 23868f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko 23871d54e73444e017d3a65234e0f193846f3e27472bIan Rogers gc::space::ImageSpace& image_space_; 23883a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers const ImageHeader& image_header_; 23892cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom std::unique_ptr<OatDumper> oat_dumper_; 2390df2bb1f36c0d755f0bdb2b1562e52669f3de4a09Andreas Gampe OatDumperOptions* oat_dumper_options_; 239105792b98980741111b4d0a24d68cff2a8e070a3aVladimir Marko std::set<mirror::Object*> dex_caches_; 2392d1bb4f6b7c8dda429f61937cd42f3a0b7367c271Elliott Hughes 23933a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers DISALLOW_COPY_AND_ASSIGN(ImageDumper); 239478128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom}; 239578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 23960b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartierstatic int DumpImage(gc::space::ImageSpace* image_space, 23970b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier OatDumperOptions* options, 23980b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier std::ostream* os) SHARED_REQUIRES(Locks::mutator_lock_) { 23990b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const ImageHeader& image_header = image_space->GetImageHeader(); 24000b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (!image_header.IsValid()) { 24010b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier fprintf(stderr, "Invalid image header %s\n", image_space->GetImageLocation().c_str()); 24020b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return EXIT_FAILURE; 24030b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24040b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier ImageDumper image_dumper(os, *image_space, image_header, options); 24050b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (!image_dumper.Dump()) { 24060b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return EXIT_FAILURE; 24070b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24080b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return EXIT_SUCCESS; 24090b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier} 24100b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier 24110b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartierstatic int DumpImages(Runtime* runtime, OatDumperOptions* options, std::ostream* os) { 241200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Dumping the image, no explicit class loader. 24139865bde5d822f56c4732214c2005dfcaa41f94cfMathieu Chartier ScopedNullHandle<mirror::ClassLoader> null_class_loader; 241400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe options->class_loader_ = &null_class_loader; 241500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 241600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(Thread::Current()); 24170b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (options->app_image_ != nullptr) { 24180b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (options->app_oat_ == nullptr) { 24190b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier LOG(ERROR) << "Can not dump app image without app oat file"; 2420dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao return EXIT_FAILURE; 2421dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao } 24220b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // We can't know if the app image is 32 bits yet, but it contains pointers into the oat file. 24230b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // We need to map the oat file in the low 4gb or else the fixup wont be able to fit oat file 24240b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // pointers into 32 bit pointer sized ArtMethods. 24250b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier std::string error_msg; 24260b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier std::unique_ptr<OatFile> oat_file(OatFile::Open(options->app_oat_, 24270b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier options->app_oat_, 24280b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 24290b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 24300b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier false, 24310b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier /*low_4gb*/true, 24320b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 24330b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier &error_msg)); 24340b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (oat_file == nullptr) { 24350b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier LOG(ERROR) << "Failed to open oat file " << options->app_oat_ << " with error " << error_msg; 2436dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao return EXIT_FAILURE; 2437dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao } 24380b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier std::unique_ptr<gc::space::ImageSpace> space( 24390b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier gc::space::ImageSpace::CreateFromAppImage(options->app_image_, oat_file.get(), &error_msg)); 24400b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (space == nullptr) { 24410b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier LOG(ERROR) << "Failed to open app image " << options->app_image_ << " with error " 24420b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier << error_msg; 24430b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24440b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // Open dex files for the image. 24450b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier std::vector<std::unique_ptr<const DexFile>> dex_files; 24460b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (!runtime->GetClassLinker()->OpenImageDexFiles(space.get(), &dex_files, &error_msg)) { 24470b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier LOG(ERROR) << "Failed to open app image dex files " << options->app_image_ << " with error " 24480b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier << error_msg; 24490b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24500b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // Dump the actual image. 24510b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier int result = DumpImage(space.get(), options, os); 24520b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (result != EXIT_SUCCESS) { 24530b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return result; 24540b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24550b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier // Fall through to dump the boot images. 24560b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 24570b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier 24580b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier gc::Heap* heap = runtime->GetHeap(); 24590b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier CHECK(heap->HasBootImageSpace()) << "No image spaces"; 24600b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier for (gc::space::ImageSpace* image_space : heap->GetBootImageSpaces()) { 24610b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier int result = DumpImage(image_space, options, os); 24620b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier if (result != EXIT_SUCCESS) { 24630b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return result; 24640b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } 2465dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao } 2466dcdc85bbd569f0ee66c331b4219c19304a616214Jeff Hao return EXIT_SUCCESS; 246778128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} 246878128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 246900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampestatic int DumpOatWithRuntime(Runtime* runtime, OatFile* oat_file, OatDumperOptions* options, 247000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::ostream* os) { 247100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe CHECK(runtime != nullptr && oat_file != nullptr && options != nullptr); 247200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 247300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe Thread* self = Thread::Current(); 247400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe CHECK(self != nullptr); 247500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Need well-known-classes. 247600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe WellKnownClasses::Init(self->GetJniEnv()); 247700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 247800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Need to register dex files to get a working dex cache. 247900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe ScopedObjectAccess soa(self); 248000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe ClassLinker* class_linker = runtime->GetClassLinker(); 2481d57d454a11ac6f49eaa397ec14d6231e3a2727b7Mathieu Chartier runtime->GetOatFileManager().RegisterOatFile(std::unique_ptr<const OatFile>(oat_file)); 2482ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier std::vector<const DexFile*> class_path; 248300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe for (const OatFile::OatDexFile* odf : oat_file->GetOatDexFiles()) { 248400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::string error_msg; 2485ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier const DexFile* const dex_file = OpenDexFile(odf, &error_msg); 248600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe CHECK(dex_file != nullptr) << error_msg; 2487d57d454a11ac6f49eaa397ec14d6231e3a2727b7Mathieu Chartier class_linker->RegisterDexFile(*dex_file, runtime->GetLinearAlloc()); 2488ac8f4397f6978484fad6769526e9e3b3f7e7bd19Mathieu Chartier class_path.push_back(dex_file); 248900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 249000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 249100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Need a class loader. 249200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Fake that we're a compiler. 2493966878d987cec1940fdfa8633fc79f8112320821Mathieu Chartier jobject class_loader = class_linker->CreatePathClassLoader(self, class_path); 249400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 249500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // Use the class loader while dumping. 249600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe StackHandleScope<1> scope(self); 249700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe Handle<mirror::ClassLoader> loader_handle = scope.NewHandle( 249800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe soa.Decode<mirror::ClassLoader*>(class_loader)); 249900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe options->class_loader_ = &loader_handle; 250000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 250132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis OatDumper oat_dumper(*oat_file, *options); 250200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool success = oat_dumper.Dump(*os); 250300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return (success) ? EXIT_SUCCESS : EXIT_FAILURE; 250400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe} 250500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 250600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampestatic int DumpOatWithoutRuntime(OatFile* oat_file, OatDumperOptions* options, std::ostream* os) { 250732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis CHECK(oat_file != nullptr && options != nullptr); 250800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe // No image = no class loader. 25099865bde5d822f56c4732214c2005dfcaa41f94cfMathieu Chartier ScopedNullHandle<mirror::ClassLoader> null_class_loader; 251000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe options->class_loader_ = &null_class_loader; 251100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 251232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis OatDumper oat_dumper(*oat_file, *options); 251300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool success = oat_dumper.Dump(*os); 251400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return (success) ? EXIT_SUCCESS : EXIT_FAILURE; 251500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe} 251600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 251700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampestatic int DumpOat(Runtime* runtime, const char* oat_filename, OatDumperOptions* options, 251800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::ostream* os) { 251900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::string error_msg; 25200b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier OatFile* oat_file = OatFile::Open(oat_filename, 25210b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_filename, 25220b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25230b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25240b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier false, 25250b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier /*low_4gb*/false, 25260b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25270b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier &error_msg); 252800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe if (oat_file == nullptr) { 252900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); 253000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return EXIT_FAILURE; 253100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 253200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 253300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe if (runtime != nullptr) { 253400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return DumpOatWithRuntime(runtime, oat_file, options, os); 253500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } else { 253600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return DumpOatWithoutRuntime(oat_file, options, os); 253700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 253800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe} 253900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 25402fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbeckystatic int SymbolizeOat(const char* oat_filename, std::string& output_name, bool no_bits) { 254100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::string error_msg; 25420b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier OatFile* oat_file = OatFile::Open(oat_filename, 25430b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_filename, 25440b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25450b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25460b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier false, 25470b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier /*low_4gb*/false, 25480b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier nullptr, 25490b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier &error_msg); 255000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe if (oat_file == nullptr) { 255100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); 255200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return EXIT_FAILURE; 255300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 255400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 25552d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe bool result; 25562d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe // Try to produce an ELF file of the same type. This is finicky, as we have used 32-bit ELF 25572d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe // files for 64-bit code in the past. 25582d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe if (Is64BitInstructionSet(oat_file->GetOatHeader().GetInstructionSet())) { 25592fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky OatSymbolizer<ElfTypes64> oat_symbolizer(oat_file, output_name, no_bits); 25602d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe result = oat_symbolizer.Symbolize(); 25612d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe } else { 25622fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky OatSymbolizer<ElfTypes32> oat_symbolizer(oat_file, output_name, no_bits); 25632d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe result = oat_symbolizer.Symbolize(); 25642d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe } 25652d8614bf1ba44468c834d9d3d5562466637f63f2Andreas Gampe if (!result) { 256600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe fprintf(stderr, "Failed to symbolize\n"); 256700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return EXIT_FAILURE; 256800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 256900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 257000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe return EXIT_SUCCESS; 257100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe} 257200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 25733774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstruct OatdumpArgs : public CmdlineArgs { 25743774335b08076117d6950cd472cdd59a167470b5Igor Murashkin protected: 25753774335b08076117d6950cd472cdd59a167470b5Igor Murashkin using Base = CmdlineArgs; 257600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 25773774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual ParseStatus ParseCustom(const StringPiece& option, 25783774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::string* error_msg) OVERRIDE { 25793774335b08076117d6950cd472cdd59a167470b5Igor Murashkin { 25803774335b08076117d6950cd472cdd59a167470b5Igor Murashkin ParseStatus base_parse = Base::ParseCustom(option, error_msg); 25813774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (base_parse != kParseUnknownArgument) { 25823774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return base_parse; 25833774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 258400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 258500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 25863774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (option.starts_with("--oat-file=")) { 25873774335b08076117d6950cd472cdd59a167470b5Igor Murashkin oat_filename_ = option.substr(strlen("--oat-file=")).data(); 25883774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option.starts_with("--image=")) { 25893774335b08076117d6950cd472cdd59a167470b5Igor Murashkin image_location_ = option.substr(strlen("--image=")).data(); 25903774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option =="--dump:raw_mapping_table") { 25913774335b08076117d6950cd472cdd59a167470b5Igor Murashkin dump_raw_mapping_table_ = true; 25923774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option == "--dump:raw_gc_map") { 25933774335b08076117d6950cd472cdd59a167470b5Igor Murashkin dump_raw_gc_map_ = true; 25943774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option == "--no-dump:vmap") { 25953774335b08076117d6950cd472cdd59a167470b5Igor Murashkin dump_vmap_ = false; 2596f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain } else if (option =="--dump:code_info_stack_maps") { 2597f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain dump_code_info_stack_maps_ = true; 25983774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option == "--no-disassemble") { 25993774335b08076117d6950cd472cdd59a167470b5Igor Murashkin disassemble_code_ = false; 2600c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil } else if (option =="--header-only") { 2601c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil dump_header_only_ = true; 26023774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option.starts_with("--symbolize=")) { 26033774335b08076117d6950cd472cdd59a167470b5Igor Murashkin oat_filename_ = option.substr(strlen("--symbolize=")).data(); 26043774335b08076117d6950cd472cdd59a167470b5Igor Murashkin symbolize_ = true; 26052fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky } else if (option.starts_with("--only-keep-debug")) { 26062fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky only_keep_debug_ = true; 260732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (option.starts_with("--class-filter=")) { 260832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis class_filter_ = option.substr(strlen("--class-filter=")).data(); 26093774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (option.starts_with("--method-filter=")) { 26103774335b08076117d6950cd472cdd59a167470b5Igor Murashkin method_filter_ = option.substr(strlen("--method-filter=")).data(); 261132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (option.starts_with("--list-classes")) { 261232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis list_classes_ = true; 261332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (option.starts_with("--list-methods")) { 261432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis list_methods_ = true; 261532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (option.starts_with("--export-dex-to=")) { 261632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis export_dex_location_ = option.substr(strlen("--export-dex-to=")).data(); 261732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } else if (option.starts_with("--addr2instr=")) { 261832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis if (!ParseUint(option.substr(strlen("--addr2instr=")).data(), &addr2instr_)) { 261932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis *error_msg = "Address conversion failed"; 262032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis return kParseError; 262132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis } 26220b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } else if (option.starts_with("--app-image=")) { 26230b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier app_image_ = option.substr(strlen("--app-image=")).data(); 26240b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier } else if (option.starts_with("--app-oat=")) { 26250b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier app_oat_ = option.substr(strlen("--app-oat=")).data(); 26263774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else { 26273774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return kParseUnknownArgument; 262800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 262900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 26303774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return kParseOk; 26313774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 26323774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26333774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual ParseStatus ParseChecks(std::string* error_msg) OVERRIDE { 26343774335b08076117d6950cd472cdd59a167470b5Igor Murashkin // Infer boot image location from the image location if possible. 26353774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (boot_image_location_ == nullptr) { 26363774335b08076117d6950cd472cdd59a167470b5Igor Murashkin boot_image_location_ = image_location_; 263700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 263800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 26393774335b08076117d6950cd472cdd59a167470b5Igor Murashkin // Perform the parent checks. 26403774335b08076117d6950cd472cdd59a167470b5Igor Murashkin ParseStatus parent_checks = Base::ParseChecks(error_msg); 26413774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (parent_checks != kParseOk) { 26423774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return parent_checks; 264300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 264400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 26453774335b08076117d6950cd472cdd59a167470b5Igor Murashkin // Perform our own checks. 26463774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (image_location_ == nullptr && oat_filename_ == nullptr) { 26473774335b08076117d6950cd472cdd59a167470b5Igor Murashkin *error_msg = "Either --image or --oat-file must be specified"; 26483774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return kParseError; 26493774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else if (image_location_ != nullptr && oat_filename_ != nullptr) { 26503774335b08076117d6950cd472cdd59a167470b5Igor Murashkin *error_msg = "Either --image or --oat-file must be specified but not both"; 26513774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return kParseError; 26523774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 26533774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26543774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return kParseOk; 26553774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 26563774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26573774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual std::string GetUsage() const { 26583774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::string usage; 26593774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26603774335b08076117d6950cd472cdd59a167470b5Igor Murashkin usage += 26613774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "Usage: oatdump [options] ...\n" 26623774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art\n" 26633774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: adb shell oatdump --image=/system/framework/boot.art\n" 26643774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 26653774335b08076117d6950cd472cdd59a167470b5Igor Murashkin // Either oat-file or image is required. 26663774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --oat-file=<file.oat>: specifies an input oat filename.\n" 26673774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --oat-file=/system/framework/boot.oat\n" 26683774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 26693774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --image=<file.art>: specifies an input image location.\n" 26703774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --image=/system/framework/boot.art\n" 26710b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier "\n" 26720b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier " --app-image=<file.art>: specifies an input app image. Must also have a specified\n" 26730b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier " boot image and app oat file.\n" 26740b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier " Example: --app-image=app.art\n" 26750b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier "\n" 26760b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier " --app-oat=<file.odex>: specifies an input app oat.\n" 26770b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier " Example: --app-oat=app.odex\n" 26783774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n"; 26793774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26803774335b08076117d6950cd472cdd59a167470b5Igor Murashkin usage += Base::GetUsage(); 26813774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 26823774335b08076117d6950cd472cdd59a167470b5Igor Murashkin usage += // Optional. 26833774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --dump:raw_mapping_table enables dumping of the mapping table.\n" 26843774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --dump:raw_mapping_table\n" 26853774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 268619510f02b011e545665f6219e6144c8e47aed5f0Mathieu Chartier " --dump:raw_gc_map enables dumping of the GC map.\n" 26873774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --dump:raw_gc_map\n" 26883774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 26893774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --no-dump:vmap may be used to disable vmap dumping.\n" 26903774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --no-dump:vmap\n" 26913774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 2692f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain " --dump:code_info_stack_maps enables dumping of stack maps in CodeInfo sections.\n" 2693f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain " Example: --dump:code_info_stack_maps\n" 2694f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain "\n" 26953774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --no-disassemble may be used to disable disassembly.\n" 26963774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --no-disassemble\n" 26973774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n" 2698c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil " --header-only may be used to print only the oat header.\n" 2699c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil " Example: --header-only\n" 2700c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil "\n" 270132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --list-classes may be used to list target file classes (can be used with filters).\n" 270232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --list-classes\n" 270332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --list-classes --class-filter=com.example.foo\n" 270432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 270532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --list-methods may be used to list target file methods (can be used with filters).\n" 270632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --list-methods\n" 270732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --list-methods --class-filter=com.example --method-filter=foo\n" 270832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 270932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --symbolize=<file.oat>: output a copy of file.oat with elf symbols included.\n" 271032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --symbolize=/system/framework/boot.oat\n" 271132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 27122fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky " --only-keep-debug<file.oat>: Modifies the behaviour of --symbolize so that\n" 27132fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky " .rodata and .text sections are omitted in the output file to save space.\n" 27142fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky " Example: --symbolize=/system/framework/boot.oat --only-keep-debug\n" 27152fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky "\n" 271632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --class-filter=<class name>: only dumps classes that contain the filter.\n" 271732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --class-filter=com.example.foo\n" 271832f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 27193774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " --method-filter=<method name>: only dumps methods that contain the filter.\n" 27203774335b08076117d6950cd472cdd59a167470b5Igor Murashkin " Example: --method-filter=foo\n" 272132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 272232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --export-dex-to=<directory>: may be used to export oat embedded dex files.\n" 272332f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --export-dex-to=/data/local/tmp\n" 272432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis "\n" 272532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " --addr2instr=<address>: output matching method disassembled code from relative\n" 272632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " address (e.g. PC from crash dump)\n" 272732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis " Example: --addr2instr=0x00001a3b\n" 27283774335b08076117d6950cd472cdd59a167470b5Igor Murashkin "\n"; 27293774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 27303774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return usage; 273100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 273200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 27333774335b08076117d6950cd472cdd59a167470b5Igor Murashkin public: 273400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe const char* oat_filename_ = nullptr; 273532f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* class_filter_ = ""; 27363fcd22051f5ac12f0825204b534912af38f02c61Nicolas Geoffray const char* method_filter_ = ""; 273700b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe const char* image_location_ = nullptr; 273800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe std::string elf_filename_prefix_; 273900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool dump_raw_mapping_table_ = false; 274000b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool dump_raw_gc_map_ = false; 274100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool dump_vmap_ = true; 2742f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain bool dump_code_info_stack_maps_ = false; 274300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool disassemble_code_ = true; 274400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe bool symbolize_ = false; 27452fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky bool only_keep_debug_ = false; 274632f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool list_classes_ = false; 274732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis bool list_methods_ = false; 2748c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil bool dump_header_only_ = false; 274932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis uint32_t addr2instr_ = 0; 275032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis const char* export_dex_location_ = nullptr; 27510b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* app_image_ = nullptr; 27520b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier const char* app_oat_ = nullptr; 275300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe}; 275400b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 27553774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstruct OatdumpMain : public CmdlineMain<OatdumpArgs> { 27563774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual bool NeedsRuntime() OVERRIDE { 27573774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(args_ != nullptr); 275800b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 27593774335b08076117d6950cd472cdd59a167470b5Igor Murashkin // If we are only doing the oat file, disable absolute_addresses. Keep them for image dumping. 27603774335b08076117d6950cd472cdd59a167470b5Igor Murashkin bool absolute_addresses = (args_->oat_filename_ == nullptr); 27613774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 27620b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier oat_dumper_options_.reset(new OatDumperOptions( 27633774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->dump_raw_mapping_table_, 27643774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->dump_raw_gc_map_, 27653774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->dump_vmap_, 2766f2650d1f957b158496de8016bc43fb575e81d6bcRoland Levillain args_->dump_code_info_stack_maps_, 27673774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->disassemble_code_, 27683774335b08076117d6950cd472cdd59a167470b5Igor Murashkin absolute_addresses, 276932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->class_filter_, 277032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->method_filter_, 277132f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->list_classes_, 277232f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->list_methods_, 2773c03d7b6bcac15ce8f829fee654b91a7e4583769dDavid Brazdil args_->dump_header_only_, 277432f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->export_dex_location_, 27750b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier args_->app_image_, 27760b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier args_->app_oat_, 277732f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis args_->addr2instr_)); 27783774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 27793774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return (args_->boot_image_location_ != nullptr || args_->image_location_ != nullptr) && 27803774335b08076117d6950cd472cdd59a167470b5Igor Murashkin !args_->symbolize_; 278100b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 278200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 27833774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual bool ExecuteWithoutRuntime() OVERRIDE { 27843774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(args_ != nullptr); 2785c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe CHECK(args_->oat_filename_ != nullptr); 27863774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 2787d424d0856927a5d771644b0ef18cb48ef8c04817Mathieu Chartier MemMap::Init(); 27883774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 2789c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe if (args_->symbolize_) { 27902fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky // ELF has special kind of section called SHT_NOBITS which allows us to create 27912fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky // sections which exist but their data is omitted from the ELF file to save space. 27922fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky // This is what "strip --only-keep-debug" does when it creates separate ELF file 27932fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky // with only debug data. We use it in similar way to exclude .rodata and .text. 27942fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky bool no_bits = args_->only_keep_debug_; 27952fdd03c982386e1d13aed9f1b51e1f0eee237971David Srbecky return SymbolizeOat(args_->oat_filename_, args_->output_name_, no_bits) == EXIT_SUCCESS; 2796c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe } else { 2797c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe return DumpOat(nullptr, 2798c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe args_->oat_filename_, 279932f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis oat_dumper_options_.get(), 2800c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe args_->os_) == EXIT_SUCCESS; 2801c24f3990db5845691016b935df3d9382b6762f0fAndreas Gampe } 280200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 280300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 28043774335b08076117d6950cd472cdd59a167470b5Igor Murashkin virtual bool ExecuteWithRuntime(Runtime* runtime) { 28053774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(args_ != nullptr); 28063774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 28073774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (args_->oat_filename_ != nullptr) { 28083774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return DumpOat(runtime, 28093774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->oat_filename_, 281032f500daa2c04b1efe946c12c90502736e47d5fcAnestis Bechtsoudis oat_dumper_options_.get(), 28113774335b08076117d6950cd472cdd59a167470b5Igor Murashkin args_->os_) == EXIT_SUCCESS; 281200b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 281300b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 28140b4cbd0c2a75b47ae09d21e5d73d2b1709cb5b9eMathieu Chartier return DumpImages(runtime, oat_dumper_options_.get(), args_->os_) == EXIT_SUCCESS; 281500b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe } 281600b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 28173774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::unique_ptr<OatDumperOptions> oat_dumper_options_; 28183774335b08076117d6950cd472cdd59a167470b5Igor Murashkin}; 281900b25f33737b281938347cca535beb77de6e8cd5Andreas Gampe 28207934ac288acfb2552bb0b06ec1f61e5820d924a4Brian Carlstrom} // namespace art 282178128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom 282278128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstromint main(int argc, char** argv) { 28233774335b08076117d6950cd472cdd59a167470b5Igor Murashkin art::OatdumpMain main; 28243774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return main.Main(argc, argv); 282578128a63b2615744760b7f8ab83df9764a5d4a95Brian Carlstrom} 2826