Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 20 | #include <fstream> |
| 21 | #include <iostream> |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 22 | #include <map> |
| 23 | #include <set> |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 24 | #include <string> |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 25 | #include <unordered_map> |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 26 | #include <vector> |
| 27 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 28 | #include "arch/instruction_set_features.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 29 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 30 | #include "art_method-inl.h" |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 31 | #include "base/stl_util.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 32 | #include "base/unix_file/fd_file.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 33 | #include "class_linker.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 35 | #include "dex_file-inl.h" |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 36 | #include "dex_instruction.h" |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 37 | #include "disassembler.h" |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 38 | #include "elf_builder.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 39 | #include "gc_map.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 40 | #include "gc/space/image_space.h" |
| 41 | #include "gc/space/large_object_space.h" |
| 42 | #include "gc/space/space-inl.h" |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 43 | #include "image-inl.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 44 | #include "indenter.h" |
Vladimir Marko | 131980f | 2015-12-03 18:29:23 +0000 | [diff] [blame] | 45 | #include "linker/buffered_output_stream.h" |
| 46 | #include "linker/file_output_stream.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 47 | #include "mapping_table.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | #include "mirror/array-inl.h" |
| 49 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 50 | #include "mirror/dex_cache-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 51 | #include "mirror/object-inl.h" |
| 52 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 53 | #include "oat.h" |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 54 | #include "oat_file-inl.h" |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 55 | #include "oat_file_manager.h" |
Elliott Hughes | e5448b5 | 2012-01-18 16:44:06 -0800 | [diff] [blame] | 56 | #include "os.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 57 | #include "safe_map.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 58 | #include "scoped_thread_state_change.h" |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 59 | #include "stack_map.h" |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 60 | #include "ScopedLocalRef.h" |
Mathieu Chartier | c22c59e | 2014-02-24 15:16:06 -0800 | [diff] [blame] | 61 | #include "thread_list.h" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 62 | #include "verifier/dex_gc_map.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 63 | #include "verifier/method_verifier.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 64 | #include "vmap_table.h" |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 65 | #include "well_known_classes.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 66 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 67 | #include <sys/stat.h> |
| 68 | #include "cmdline.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 69 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 70 | namespace art { |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 71 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 72 | const char* image_methods_descriptions_[] = { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 73 | "kResolutionMethod", |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 74 | "kImtConflictMethod", |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 75 | "kImtUnimplementedMethod", |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 76 | "kCalleeSaveMethod", |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 77 | "kRefsOnlySaveMethod", |
| 78 | "kRefsAndArgsSaveMethod", |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | const char* image_roots_descriptions_[] = { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 82 | "kDexCaches", |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 83 | "kClassRoots", |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 86 | // Map is so that we don't allocate multiple dex files for the same OatDexFile. |
| 87 | static std::map<const OatFile::OatDexFile*, |
| 88 | std::unique_ptr<const DexFile>> opened_dex_files; |
| 89 | |
| 90 | const DexFile* OpenDexFile(const OatFile::OatDexFile* oat_dex_file, std::string* error_msg) { |
| 91 | DCHECK(oat_dex_file != nullptr); |
| 92 | auto it = opened_dex_files.find(oat_dex_file); |
| 93 | if (it != opened_dex_files.end()) { |
| 94 | return it->second.get(); |
| 95 | } |
| 96 | const DexFile* ret = oat_dex_file->OpenDexFile(error_msg).release(); |
| 97 | opened_dex_files.emplace(oat_dex_file, std::unique_ptr<const DexFile>(ret)); |
| 98 | return ret; |
| 99 | } |
| 100 | |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 101 | template <typename ElfTypes> |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 102 | class OatSymbolizer FINAL { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 103 | public: |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 104 | OatSymbolizer(const OatFile* oat_file, const std::string& output_name, bool no_bits) : |
| 105 | oat_file_(oat_file), |
| 106 | builder_(nullptr), |
| 107 | output_name_(output_name.empty() ? "symbolized.oat" : output_name), |
| 108 | no_bits_(no_bits) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | typedef void (OatSymbolizer::*Callback)(const DexFile::ClassDef&, |
| 112 | uint32_t, |
| 113 | const OatFile::OatMethod&, |
| 114 | const DexFile&, |
| 115 | uint32_t, |
| 116 | const DexFile::CodeItem*, |
| 117 | uint32_t); |
| 118 | |
| 119 | bool Symbolize() { |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 120 | const InstructionSet isa = oat_file_->GetOatHeader().GetInstructionSet(); |
David Srbecky | 5d81120 | 2016-03-08 13:21:22 +0000 | [diff] [blame] | 121 | const InstructionSetFeatures* features = InstructionSetFeatures::FromBitmap( |
| 122 | isa, oat_file_->GetOatHeader().GetInstructionSetFeaturesBitmap()); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 123 | |
| 124 | File* elf_file = OS::CreateEmptyFile(output_name_.c_str()); |
| 125 | std::unique_ptr<BufferedOutputStream> output_stream( |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 126 | MakeUnique<BufferedOutputStream>(MakeUnique<FileOutputStream>(elf_file))); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 127 | builder_.reset(new ElfBuilder<ElfTypes>(isa, features, output_stream.get())); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 128 | |
| 129 | builder_->Start(); |
| 130 | |
| 131 | auto* rodata = builder_->GetRoData(); |
| 132 | auto* text = builder_->GetText(); |
| 133 | auto* bss = builder_->GetBss(); |
| 134 | auto* strtab = builder_->GetStrTab(); |
| 135 | auto* symtab = builder_->GetSymTab(); |
| 136 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 137 | const uint8_t* rodata_begin = oat_file_->Begin(); |
| 138 | const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset(); |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 139 | if (no_bits_) { |
| 140 | rodata->WriteNoBitsSection(rodata_size); |
| 141 | } else { |
| 142 | rodata->Start(); |
| 143 | rodata->WriteFully(rodata_begin, rodata_size); |
| 144 | rodata->End(); |
| 145 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 146 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 147 | const uint8_t* text_begin = oat_file_->Begin() + rodata_size; |
| 148 | const size_t text_size = oat_file_->End() - text_begin; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 149 | if (no_bits_) { |
| 150 | text->WriteNoBitsSection(text_size); |
| 151 | } else { |
| 152 | text->Start(); |
| 153 | text->WriteFully(text_begin, text_size); |
| 154 | text->End(); |
| 155 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 156 | |
| 157 | if (oat_file_->BssSize() != 0) { |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 158 | bss->WriteNoBitsSection(oat_file_->BssSize()); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Douglas Leung | 316a218 | 2015-09-17 15:26:25 -0700 | [diff] [blame] | 161 | if (isa == kMips || isa == kMips64) { |
| 162 | builder_->WriteMIPSabiflagsSection(); |
| 163 | } |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 164 | builder_->PrepareDynamicSection( |
| 165 | elf_file->GetPath(), rodata_size, text_size, oat_file_->BssSize()); |
| 166 | builder_->WriteDynamicSection(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 167 | |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 168 | Walk(&art::OatSymbolizer<ElfTypes>::RegisterForDedup); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 169 | |
| 170 | NormalizeState(); |
| 171 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 172 | strtab->Start(); |
| 173 | strtab->Write(""); // strtab should start with empty string. |
Tamas Berghammer | 8f75c45 | 2016-01-26 18:03:43 +0000 | [diff] [blame] | 174 | AddTrampolineSymbols(); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 175 | Walk(&art::OatSymbolizer<ElfTypes>::AddSymbol); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 176 | strtab->End(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 177 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 178 | symtab->Start(); |
| 179 | symtab->Write(); |
| 180 | symtab->End(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 181 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 182 | builder_->End(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 183 | |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 184 | return builder_->Good(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Tamas Berghammer | 8f75c45 | 2016-01-26 18:03:43 +0000 | [diff] [blame] | 187 | void AddTrampolineSymbol(const char* name, uint32_t code_offset) { |
| 188 | if (code_offset != 0) { |
| 189 | uint32_t name_offset = builder_->GetStrTab()->Write(name); |
| 190 | uint64_t symbol_value = code_offset - oat_file_->GetOatHeader().GetExecutableOffset(); |
Tamas Berghammer | 9e49ab1 | 2016-01-28 16:30:14 +0000 | [diff] [blame] | 191 | // Specifying 0 as the symbol size means that the symbol lasts until the next symbol or until |
| 192 | // the end of the section in case of the last symbol. |
David Srbecky | 197160d | 2016-03-07 17:33:57 +0000 | [diff] [blame] | 193 | builder_->GetSymTab()->Add( |
| 194 | name_offset, |
| 195 | builder_->GetText(), |
| 196 | builder_->GetText()->GetAddress() + symbol_value, |
| 197 | /* size */ 0, |
| 198 | STB_GLOBAL, |
| 199 | STT_FUNC); |
Tamas Berghammer | 8f75c45 | 2016-01-26 18:03:43 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | void AddTrampolineSymbols() { |
| 204 | const OatHeader& oat_header = oat_file_->GetOatHeader(); |
| 205 | AddTrampolineSymbol("interpreterToInterpreterBridge", |
| 206 | oat_header.GetInterpreterToInterpreterBridgeOffset()); |
| 207 | AddTrampolineSymbol("interpreterToCompiledCodeBridge", |
| 208 | oat_header.GetInterpreterToCompiledCodeBridgeOffset()); |
| 209 | AddTrampolineSymbol("jniDlsymLookup", |
| 210 | oat_header.GetJniDlsymLookupOffset()); |
| 211 | AddTrampolineSymbol("quickGenericJniTrampoline", |
| 212 | oat_header.GetQuickGenericJniTrampolineOffset()); |
| 213 | AddTrampolineSymbol("quickImtConflictTrampoline", |
| 214 | oat_header.GetQuickImtConflictTrampolineOffset()); |
| 215 | AddTrampolineSymbol("quickResolutionTrampoline", |
| 216 | oat_header.GetQuickResolutionTrampolineOffset()); |
| 217 | AddTrampolineSymbol("quickToInterpreterBridge", |
| 218 | oat_header.GetQuickToInterpreterBridgeOffset()); |
| 219 | } |
| 220 | |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 221 | void Walk(Callback callback) { |
| 222 | std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file_->GetOatDexFiles(); |
| 223 | for (size_t i = 0; i < oat_dex_files.size(); i++) { |
| 224 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i]; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 225 | CHECK(oat_dex_file != nullptr); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 226 | WalkOatDexFile(oat_dex_file, callback); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | void WalkOatDexFile(const OatFile::OatDexFile* oat_dex_file, Callback callback) { |
| 231 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 232 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 233 | if (dex_file == nullptr) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 234 | return; |
| 235 | } |
| 236 | for (size_t class_def_index = 0; |
| 237 | class_def_index < dex_file->NumClassDefs(); |
| 238 | class_def_index++) { |
| 239 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
| 240 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
| 241 | OatClassType type = oat_class.GetType(); |
| 242 | switch (type) { |
| 243 | case kOatClassAllCompiled: |
| 244 | case kOatClassSomeCompiled: |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 245 | WalkOatClass(oat_class, *dex_file, class_def, callback); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 246 | break; |
| 247 | |
| 248 | case kOatClassNoneCompiled: |
| 249 | case kOatClassMax: |
| 250 | // Ignore. |
| 251 | break; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void WalkOatClass(const OatFile::OatClass& oat_class, const DexFile& dex_file, |
| 257 | const DexFile::ClassDef& class_def, Callback callback) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 258 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 259 | if (class_data == nullptr) { // empty class such as a marker interface? |
| 260 | return; |
| 261 | } |
| 262 | // Note: even if this is an interface or a native class, we still have to walk it, as there |
| 263 | // might be a static initializer. |
| 264 | ClassDataItemIterator it(dex_file, class_data); |
| 265 | SkipAllFields(&it); |
| 266 | uint32_t class_method_idx = 0; |
| 267 | while (it.HasNextDirectMethod()) { |
| 268 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_idx); |
| 269 | WalkOatMethod(class_def, class_method_idx, oat_method, dex_file, it.GetMemberIndex(), |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 270 | it.GetMethodCodeItem(), it.GetMethodAccessFlags(), callback); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 271 | class_method_idx++; |
| 272 | it.Next(); |
| 273 | } |
| 274 | while (it.HasNextVirtualMethod()) { |
| 275 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_idx); |
| 276 | WalkOatMethod(class_def, class_method_idx, oat_method, dex_file, it.GetMemberIndex(), |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 277 | it.GetMethodCodeItem(), it.GetMethodAccessFlags(), callback); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 278 | class_method_idx++; |
| 279 | it.Next(); |
| 280 | } |
| 281 | DCHECK(!it.HasNext()); |
| 282 | } |
| 283 | |
| 284 | void WalkOatMethod(const DexFile::ClassDef& class_def, uint32_t class_method_index, |
| 285 | const OatFile::OatMethod& oat_method, const DexFile& dex_file, |
| 286 | uint32_t dex_method_idx, const DexFile::CodeItem* code_item, |
| 287 | uint32_t method_access_flags, Callback callback) { |
| 288 | if ((method_access_flags & kAccAbstract) != 0) { |
| 289 | // Abstract method, no code. |
| 290 | return; |
| 291 | } |
| 292 | if (oat_method.GetCodeOffset() == 0) { |
| 293 | // No code. |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | (this->*callback)(class_def, class_method_index, oat_method, dex_file, dex_method_idx, code_item, |
| 298 | method_access_flags); |
| 299 | } |
| 300 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 301 | void RegisterForDedup(const DexFile::ClassDef& class_def ATTRIBUTE_UNUSED, |
| 302 | uint32_t class_method_index ATTRIBUTE_UNUSED, |
| 303 | const OatFile::OatMethod& oat_method, |
| 304 | const DexFile& dex_file ATTRIBUTE_UNUSED, |
| 305 | uint32_t dex_method_idx ATTRIBUTE_UNUSED, |
| 306 | const DexFile::CodeItem* code_item ATTRIBUTE_UNUSED, |
| 307 | uint32_t method_access_flags ATTRIBUTE_UNUSED) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 308 | state_[oat_method.GetCodeOffset()]++; |
| 309 | } |
| 310 | |
| 311 | void NormalizeState() { |
| 312 | for (auto& x : state_) { |
| 313 | if (x.second == 1) { |
| 314 | state_[x.first] = 0; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | enum class DedupState { // private |
| 320 | kNotDeduplicated, |
| 321 | kDeduplicatedFirst, |
| 322 | kDeduplicatedOther |
| 323 | }; |
| 324 | DedupState IsDuplicated(uint32_t offset) { |
| 325 | if (state_[offset] == 0) { |
| 326 | return DedupState::kNotDeduplicated; |
| 327 | } |
| 328 | if (state_[offset] == 1) { |
| 329 | return DedupState::kDeduplicatedOther; |
| 330 | } |
| 331 | state_[offset] = 1; |
| 332 | return DedupState::kDeduplicatedFirst; |
| 333 | } |
| 334 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 335 | void AddSymbol(const DexFile::ClassDef& class_def ATTRIBUTE_UNUSED, |
| 336 | uint32_t class_method_index ATTRIBUTE_UNUSED, |
| 337 | const OatFile::OatMethod& oat_method, |
| 338 | const DexFile& dex_file, |
| 339 | uint32_t dex_method_idx, |
| 340 | const DexFile::CodeItem* code_item ATTRIBUTE_UNUSED, |
| 341 | uint32_t method_access_flags ATTRIBUTE_UNUSED) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 342 | DedupState dedup = IsDuplicated(oat_method.GetCodeOffset()); |
| 343 | if (dedup != DedupState::kDeduplicatedOther) { |
| 344 | std::string pretty_name = PrettyMethod(dex_method_idx, dex_file, true); |
| 345 | |
| 346 | if (dedup == DedupState::kDeduplicatedFirst) { |
| 347 | pretty_name = "[Dedup]" + pretty_name; |
| 348 | } |
| 349 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 350 | int name_offset = builder_->GetStrTab()->Write(pretty_name); |
David Srbecky | 197160d | 2016-03-07 17:33:57 +0000 | [diff] [blame] | 351 | uint64_t address = oat_method.GetCodeOffset() - |
| 352 | oat_file_->GetOatHeader().GetExecutableOffset() + |
| 353 | builder_->GetText()->GetAddress(); |
| 354 | builder_->GetSymTab()->Add(name_offset, |
| 355 | builder_->GetText(), |
| 356 | address, |
| 357 | oat_method.GetQuickCodeSize(), |
| 358 | STB_GLOBAL, |
| 359 | STT_FUNC); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 363 | private: |
| 364 | static void SkipAllFields(ClassDataItemIterator* it) { |
| 365 | while (it->HasNextStaticField()) { |
| 366 | it->Next(); |
| 367 | } |
| 368 | while (it->HasNextInstanceField()) { |
| 369 | it->Next(); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | const OatFile* oat_file_; |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 374 | std::unique_ptr<ElfBuilder<ElfTypes> > builder_; |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 375 | std::unordered_map<uint32_t, uint32_t> state_; |
Ian Rogers | 0279ebb | 2014-10-08 17:27:48 -0700 | [diff] [blame] | 376 | const std::string output_name_; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 377 | bool no_bits_; |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 380 | class OatDumperOptions { |
| 381 | public: |
| 382 | OatDumperOptions(bool dump_raw_mapping_table, |
| 383 | bool dump_raw_gc_map, |
| 384 | bool dump_vmap, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 385 | bool dump_code_info_stack_maps, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 386 | bool disassemble_code, |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 387 | bool absolute_addresses, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 388 | const char* class_filter, |
| 389 | const char* method_filter, |
| 390 | bool list_classes, |
| 391 | bool list_methods, |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 392 | bool dump_header_only, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 393 | const char* export_dex_location, |
| 394 | uint32_t addr2instr) |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 395 | : dump_raw_mapping_table_(dump_raw_mapping_table), |
| 396 | dump_raw_gc_map_(dump_raw_gc_map), |
| 397 | dump_vmap_(dump_vmap), |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 398 | dump_code_info_stack_maps_(dump_code_info_stack_maps), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 399 | disassemble_code_(disassemble_code), |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 400 | absolute_addresses_(absolute_addresses), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 401 | class_filter_(class_filter), |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 402 | method_filter_(method_filter), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 403 | list_classes_(list_classes), |
| 404 | list_methods_(list_methods), |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 405 | dump_header_only_(dump_header_only), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 406 | export_dex_location_(export_dex_location), |
| 407 | addr2instr_(addr2instr), |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 408 | class_loader_(nullptr) {} |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 409 | |
| 410 | const bool dump_raw_mapping_table_; |
| 411 | const bool dump_raw_gc_map_; |
| 412 | const bool dump_vmap_; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 413 | const bool dump_code_info_stack_maps_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 414 | const bool disassemble_code_; |
| 415 | const bool absolute_addresses_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 416 | const char* const class_filter_; |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 417 | const char* const method_filter_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 418 | const bool list_classes_; |
| 419 | const bool list_methods_; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 420 | const bool dump_header_only_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 421 | const char* const export_dex_location_; |
| 422 | uint32_t addr2instr_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 423 | Handle<mirror::ClassLoader>* class_loader_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 424 | }; |
| 425 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 426 | class OatDumper { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 427 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 428 | OatDumper(const OatFile& oat_file, const OatDumperOptions& options) |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 429 | : oat_file_(oat_file), |
Elliott Hughes | a72ec82 | 2012-03-05 17:12:22 -0800 | [diff] [blame] | 430 | oat_dex_files_(oat_file.GetOatDexFiles()), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 431 | options_(options), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 432 | resolved_addr2instr_(0), |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 433 | instruction_set_(oat_file_.GetOatHeader().GetInstructionSet()), |
| 434 | disassembler_(Disassembler::Create(instruction_set_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 435 | new DisassemblerOptions(options_.absolute_addresses_, |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 436 | oat_file.Begin(), |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 437 | true /* can_read_literals_ */))) { |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 438 | CHECK(options_.class_loader_ != nullptr); |
| 439 | CHECK(options_.class_filter_ != nullptr); |
| 440 | CHECK(options_.method_filter_ != nullptr); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 441 | AddAllOffsets(); |
| 442 | } |
| 443 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 444 | ~OatDumper() { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 445 | delete disassembler_; |
| 446 | } |
| 447 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 448 | InstructionSet GetInstructionSet() { |
| 449 | return instruction_set_; |
| 450 | } |
| 451 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 452 | bool Dump(std::ostream& os) { |
| 453 | bool success = true; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 454 | const OatHeader& oat_header = oat_file_.GetOatHeader(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 455 | |
| 456 | os << "MAGIC:\n"; |
| 457 | os << oat_header.GetMagic() << "\n\n"; |
| 458 | |
Jeff Hao | 4b07a6e | 2016-01-15 12:50:44 -0800 | [diff] [blame] | 459 | os << "LOCATION:\n"; |
| 460 | os << oat_file_.GetLocation() << "\n\n"; |
| 461 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 462 | os << "CHECKSUM:\n"; |
Elliott Hughes | ed2adb6 | 2012-02-29 14:41:01 -0800 | [diff] [blame] | 463 | os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 464 | |
Elliott Hughes | a72ec82 | 2012-03-05 17:12:22 -0800 | [diff] [blame] | 465 | os << "INSTRUCTION SET:\n"; |
| 466 | os << oat_header.GetInstructionSet() << "\n\n"; |
| 467 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 468 | { |
| 469 | std::unique_ptr<const InstructionSetFeatures> features( |
| 470 | InstructionSetFeatures::FromBitmap(oat_header.GetInstructionSet(), |
| 471 | oat_header.GetInstructionSetFeaturesBitmap())); |
| 472 | os << "INSTRUCTION SET FEATURES:\n"; |
| 473 | os << features->GetFeatureString() << "\n\n"; |
| 474 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 475 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 476 | os << "DEX FILE COUNT:\n"; |
| 477 | os << oat_header.GetDexFileCount() << "\n\n"; |
| 478 | |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 479 | #define DUMP_OAT_HEADER_OFFSET(label, offset) \ |
| 480 | os << label " OFFSET:\n"; \ |
| 481 | os << StringPrintf("0x%08x", oat_header.offset()); \ |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 482 | if (oat_header.offset() != 0 && options_.absolute_addresses_) { \ |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 483 | os << StringPrintf(" (%p)", oat_file_.Begin() + oat_header.offset()); \ |
| 484 | } \ |
| 485 | os << StringPrintf("\n\n"); |
| 486 | |
| 487 | DUMP_OAT_HEADER_OFFSET("EXECUTABLE", GetExecutableOffset); |
| 488 | DUMP_OAT_HEADER_OFFSET("INTERPRETER TO INTERPRETER BRIDGE", |
| 489 | GetInterpreterToInterpreterBridgeOffset); |
| 490 | DUMP_OAT_HEADER_OFFSET("INTERPRETER TO COMPILED CODE BRIDGE", |
| 491 | GetInterpreterToCompiledCodeBridgeOffset); |
| 492 | DUMP_OAT_HEADER_OFFSET("JNI DLSYM LOOKUP", |
| 493 | GetJniDlsymLookupOffset); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 494 | DUMP_OAT_HEADER_OFFSET("QUICK GENERIC JNI TRAMPOLINE", |
| 495 | GetQuickGenericJniTrampolineOffset); |
| 496 | DUMP_OAT_HEADER_OFFSET("QUICK IMT CONFLICT TRAMPOLINE", |
| 497 | GetQuickImtConflictTrampolineOffset); |
| 498 | DUMP_OAT_HEADER_OFFSET("QUICK RESOLUTION TRAMPOLINE", |
| 499 | GetQuickResolutionTrampolineOffset); |
| 500 | DUMP_OAT_HEADER_OFFSET("QUICK TO INTERPRETER BRIDGE", |
| 501 | GetQuickToInterpreterBridgeOffset); |
| 502 | #undef DUMP_OAT_HEADER_OFFSET |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 503 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 504 | os << "IMAGE PATCH DELTA:\n"; |
| 505 | os << StringPrintf("%d (0x%08x)\n\n", |
| 506 | oat_header.GetImagePatchDelta(), |
| 507 | oat_header.GetImagePatchDelta()); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 508 | |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 509 | os << "IMAGE FILE LOCATION OAT CHECKSUM:\n"; |
| 510 | os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatChecksum()); |
| 511 | |
| 512 | os << "IMAGE FILE LOCATION OAT BEGIN:\n"; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 513 | os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatDataBegin()); |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 514 | |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 515 | // Print the key-value store. |
| 516 | { |
| 517 | os << "KEY VALUE STORE:\n"; |
| 518 | size_t index = 0; |
| 519 | const char* key; |
| 520 | const char* value; |
| 521 | while (oat_header.GetStoreKeyValuePairByIndex(index, &key, &value)) { |
| 522 | os << key << " = " << value << "\n"; |
| 523 | index++; |
| 524 | } |
| 525 | os << "\n"; |
| 526 | } |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 527 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 528 | if (options_.absolute_addresses_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 529 | os << "BEGIN:\n"; |
| 530 | os << reinterpret_cast<const void*>(oat_file_.Begin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 531 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 532 | os << "END:\n"; |
| 533 | os << reinterpret_cast<const void*>(oat_file_.End()) << "\n\n"; |
| 534 | } |
| 535 | |
| 536 | os << "SIZE:\n"; |
| 537 | os << oat_file_.Size() << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 538 | |
| 539 | os << std::flush; |
| 540 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 541 | // If set, adjust relative address to be searched |
| 542 | if (options_.addr2instr_ != 0) { |
| 543 | resolved_addr2instr_ = options_.addr2instr_ + oat_header.GetExecutableOffset(); |
| 544 | os << "SEARCH ADDRESS (executable offset + input):\n"; |
| 545 | os << StringPrintf("0x%08x\n\n", resolved_addr2instr_); |
| 546 | } |
| 547 | |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 548 | if (!options_.dump_header_only_) { |
| 549 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 550 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
| 551 | CHECK(oat_dex_file != nullptr); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 552 | |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 553 | // If file export selected skip file analysis |
| 554 | if (options_.export_dex_location_) { |
| 555 | if (!ExportDexFile(os, *oat_dex_file)) { |
| 556 | success = false; |
| 557 | } |
| 558 | } else { |
| 559 | if (!DumpOatDexFile(os, *oat_dex_file)) { |
| 560 | success = false; |
| 561 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 562 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 563 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 564 | } |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 565 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 566 | os << std::flush; |
| 567 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 570 | size_t ComputeSize(const void* oat_data) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 571 | if (reinterpret_cast<const uint8_t*>(oat_data) < oat_file_.Begin() || |
| 572 | reinterpret_cast<const uint8_t*>(oat_data) > oat_file_.End()) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 573 | return 0; // Address not in oat file |
| 574 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 575 | uintptr_t begin_offset = reinterpret_cast<uintptr_t>(oat_data) - |
| 576 | reinterpret_cast<uintptr_t>(oat_file_.Begin()); |
| 577 | auto it = offsets_.upper_bound(begin_offset); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 578 | CHECK(it != offsets_.end()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 579 | uintptr_t end_offset = *it; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 580 | return end_offset - begin_offset; |
| 581 | } |
| 582 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 583 | InstructionSet GetOatInstructionSet() { |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 584 | return oat_file_.GetOatHeader().GetInstructionSet(); |
| 585 | } |
| 586 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 587 | const void* GetQuickOatCode(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 588 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 589 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 590 | CHECK(oat_dex_file != nullptr); |
| 591 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 592 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 593 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 594 | LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() |
| 595 | << "': " << error_msg; |
| 596 | } else { |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 597 | const char* descriptor = m->GetDeclaringClassDescriptor(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 598 | const DexFile::ClassDef* class_def = |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 599 | dex_file->FindClassDef(descriptor, ComputeModifiedUtf8Hash(descriptor)); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 600 | if (class_def != nullptr) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 601 | uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 602 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 603 | size_t method_index = m->GetMethodIndex(); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 604 | return oat_class.GetOatMethod(method_index).GetQuickCode(); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 608 | return nullptr; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 611 | private: |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 612 | void AddAllOffsets() { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 613 | // We don't know the length of the code for each method, but we need to know where to stop |
| 614 | // when disassembling. What we do know is that a region of code will be followed by some other |
| 615 | // region, so if we keep a sorted sequence of the start of each region, we can infer the length |
| 616 | // of a piece of code by using upper_bound to find the start of the next region. |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 617 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 618 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 619 | CHECK(oat_dex_file != nullptr); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 620 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 621 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 622 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 623 | LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() |
| 624 | << "': " << error_msg; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 625 | continue; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 626 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 627 | offsets_.insert(reinterpret_cast<uintptr_t>(&dex_file->GetHeader())); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 628 | for (size_t class_def_index = 0; |
| 629 | class_def_index < dex_file->NumClassDefs(); |
| 630 | class_def_index++) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 631 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 632 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 633 | const uint8_t* class_data = dex_file->GetClassData(class_def); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 634 | if (class_data != nullptr) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 635 | ClassDataItemIterator it(*dex_file, class_data); |
| 636 | SkipAllFields(it); |
| 637 | uint32_t class_method_index = 0; |
| 638 | while (it.HasNextDirectMethod()) { |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 639 | AddOffsets(oat_class.GetOatMethod(class_method_index++)); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 640 | it.Next(); |
| 641 | } |
| 642 | while (it.HasNextVirtualMethod()) { |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 643 | AddOffsets(oat_class.GetOatMethod(class_method_index++)); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 644 | it.Next(); |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // If the last thing in the file is code for a method, there won't be an offset for the "next" |
| 651 | // thing. Instead of having a special case in the upper_bound code, let's just add an entry |
| 652 | // for the end of the file. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 653 | offsets_.insert(oat_file_.Size()); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 656 | static uint32_t AlignCodeOffset(uint32_t maybe_thumb_offset) { |
| 657 | return maybe_thumb_offset & ~0x1; // TODO: Make this Thumb2 specific. |
| 658 | } |
| 659 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 660 | void AddOffsets(const OatFile::OatMethod& oat_method) { |
Brian Carlstrom | 95ba0dc | 2012-03-05 22:06:14 -0800 | [diff] [blame] | 661 | uint32_t code_offset = oat_method.GetCodeOffset(); |
| 662 | if (oat_file_.GetOatHeader().GetInstructionSet() == kThumb2) { |
| 663 | code_offset &= ~0x1; |
| 664 | } |
| 665 | offsets_.insert(code_offset); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 666 | offsets_.insert(oat_method.GetMappingTableOffset()); |
| 667 | offsets_.insert(oat_method.GetVmapTableOffset()); |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 668 | offsets_.insert(oat_method.GetGcMapOffset()); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 671 | bool DumpOatDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { |
| 672 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 673 | bool stop_analysis = false; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 674 | os << "OatDexFile:\n"; |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 675 | os << StringPrintf("location: %s\n", oat_dex_file.GetDexFileLocation().c_str()); |
Elliott Hughes | ed2adb6 | 2012-02-29 14:41:01 -0800 | [diff] [blame] | 676 | os << StringPrintf("checksum: 0x%08x\n", oat_dex_file.GetDexFileLocationChecksum()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 677 | |
| 678 | // Create the verifier early. |
| 679 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 680 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 681 | const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); |
| 682 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 683 | os << "NOT FOUND: " << error_msg << "\n\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 684 | os << std::flush; |
| 685 | return false; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 686 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 687 | |
| 688 | VariableIndentationOutputStream vios(&os); |
| 689 | ScopedIndentation indent1(&vios); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 690 | for (size_t class_def_index = 0; |
| 691 | class_def_index < dex_file->NumClassDefs(); |
| 692 | class_def_index++) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 693 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
| 694 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 695 | |
| 696 | // TODO: Support regex |
| 697 | if (DescriptorToDot(descriptor).find(options_.class_filter_) == std::string::npos) { |
| 698 | continue; |
| 699 | } |
| 700 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 701 | uint32_t oat_class_offset = oat_dex_file.GetOatClassOffset(class_def_index); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 702 | const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 703 | os << StringPrintf("%zd: %s (offset=0x%08x) (type_idx=%d)", |
| 704 | class_def_index, descriptor, oat_class_offset, class_def.class_idx_) |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 705 | << " (" << oat_class.GetStatus() << ")" |
| 706 | << " (" << oat_class.GetType() << ")\n"; |
| 707 | // TODO: include bitmap here if type is kOatClassSomeCompiled? |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 708 | if (options_.list_classes_) continue; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 709 | if (!DumpOatClass(&vios, oat_class, *dex_file, class_def, &stop_analysis)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 710 | success = false; |
| 711 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 712 | if (stop_analysis) { |
| 713 | os << std::flush; |
| 714 | return success; |
| 715 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | os << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 719 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 722 | bool ExportDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { |
| 723 | std::string error_msg; |
| 724 | std::string dex_file_location = oat_dex_file.GetDexFileLocation(); |
| 725 | |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 726 | const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 727 | if (dex_file == nullptr) { |
| 728 | os << "Failed to open dex file '" << dex_file_location << "': " << error_msg; |
| 729 | return false; |
| 730 | } |
| 731 | size_t fsize = oat_dex_file.FileSize(); |
| 732 | |
| 733 | // Some quick checks just in case |
| 734 | if (fsize == 0 || fsize < sizeof(DexFile::Header)) { |
| 735 | os << "Invalid dex file\n"; |
| 736 | return false; |
| 737 | } |
| 738 | |
| 739 | // Verify output directory exists |
| 740 | if (!OS::DirectoryExists(options_.export_dex_location_)) { |
| 741 | // TODO: Extend OS::DirectoryExists if symlink support is required |
| 742 | os << options_.export_dex_location_ << " output directory not found or symlink\n"; |
| 743 | return false; |
| 744 | } |
| 745 | |
| 746 | // Beautify path names |
| 747 | if (dex_file_location.size() > PATH_MAX || dex_file_location.size() <= 0) { |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | std::string dex_orig_name; |
| 752 | size_t dex_orig_pos = dex_file_location.rfind('/'); |
| 753 | if (dex_orig_pos == std::string::npos) |
| 754 | dex_orig_name = dex_file_location; |
| 755 | else |
| 756 | dex_orig_name = dex_file_location.substr(dex_orig_pos + 1); |
| 757 | |
| 758 | // A more elegant approach to efficiently name user installed apps is welcome |
| 759 | if (dex_orig_name.size() == 8 && !dex_orig_name.compare("base.apk")) { |
| 760 | dex_file_location.erase(dex_orig_pos, strlen("base.apk") + 1); |
| 761 | size_t apk_orig_pos = dex_file_location.rfind('/'); |
| 762 | if (apk_orig_pos != std::string::npos) { |
| 763 | dex_orig_name = dex_file_location.substr(++apk_orig_pos); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | std::string out_dex_path(options_.export_dex_location_); |
| 768 | if (out_dex_path.back() != '/') { |
| 769 | out_dex_path.append("/"); |
| 770 | } |
| 771 | out_dex_path.append(dex_orig_name); |
| 772 | out_dex_path.append("_export.dex"); |
| 773 | if (out_dex_path.length() > PATH_MAX) { |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | std::unique_ptr<File> file(OS::CreateEmptyFile(out_dex_path.c_str())); |
| 778 | if (file.get() == nullptr) { |
| 779 | os << "Failed to open output dex file " << out_dex_path; |
| 780 | return false; |
| 781 | } |
| 782 | |
| 783 | if (!file->WriteFully(dex_file->Begin(), fsize)) { |
| 784 | os << "Failed to write dex file"; |
| 785 | file->Erase(); |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | if (file->FlushCloseOrErase() != 0) { |
| 790 | os << "Flush and close failed"; |
| 791 | return false; |
| 792 | } |
| 793 | |
| 794 | os << StringPrintf("Dex file exported at %s (%zd bytes)\n", out_dex_path.c_str(), fsize); |
| 795 | os << std::flush; |
| 796 | |
| 797 | return true; |
| 798 | } |
| 799 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 800 | static void SkipAllFields(ClassDataItemIterator& it) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 801 | while (it.HasNextStaticField()) { |
| 802 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 803 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 804 | while (it.HasNextInstanceField()) { |
| 805 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 806 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 807 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 808 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 809 | bool DumpOatClass(VariableIndentationOutputStream* vios, |
| 810 | const OatFile::OatClass& oat_class, const DexFile& dex_file, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 811 | const DexFile::ClassDef& class_def, bool* stop_analysis) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 812 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 813 | bool addr_found = false; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 814 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 815 | if (class_data == nullptr) { // empty class such as a marker interface? |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 816 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 817 | return success; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 818 | } |
| 819 | ClassDataItemIterator it(dex_file, class_data); |
| 820 | SkipAllFields(it); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 821 | uint32_t class_method_index = 0; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 822 | while (it.HasNextDirectMethod()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 823 | if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 824 | it.GetMemberIndex(), it.GetMethodCodeItem(), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 825 | it.GetRawMemberAccessFlags(), &addr_found)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 826 | success = false; |
| 827 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 828 | if (addr_found) { |
| 829 | *stop_analysis = true; |
| 830 | return success; |
| 831 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 832 | class_method_index++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 833 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 834 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 835 | while (it.HasNextVirtualMethod()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 836 | if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 837 | it.GetMemberIndex(), it.GetMethodCodeItem(), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 838 | it.GetRawMemberAccessFlags(), &addr_found)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 839 | success = false; |
| 840 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 841 | if (addr_found) { |
| 842 | *stop_analysis = true; |
| 843 | return success; |
| 844 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 845 | class_method_index++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 846 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 847 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 848 | DCHECK(!it.HasNext()); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 849 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 850 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 851 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 852 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 853 | static constexpr uint32_t kPrologueBytes = 16; |
| 854 | |
| 855 | // When this was picked, the largest arm method was 55,256 bytes and arm64 was 50,412 bytes. |
| 856 | static constexpr uint32_t kMaxCodeSize = 100 * 1000; |
| 857 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 858 | bool DumpOatMethod(VariableIndentationOutputStream* vios, |
| 859 | const DexFile::ClassDef& class_def, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 860 | uint32_t class_method_index, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 861 | const OatFile::OatClass& oat_class, const DexFile& dex_file, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 862 | uint32_t dex_method_idx, const DexFile::CodeItem* code_item, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 863 | uint32_t method_access_flags, bool* addr_found) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 864 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 865 | |
| 866 | // TODO: Support regex |
| 867 | std::string method_name = dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx)); |
| 868 | if (method_name.find(options_.method_filter_) == std::string::npos) { |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 869 | return success; |
| 870 | } |
| 871 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 872 | std::string pretty_method = PrettyMethod(dex_method_idx, dex_file, true); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 873 | vios->Stream() << StringPrintf("%d: %s (dex_method_idx=%d)\n", |
| 874 | class_method_index, pretty_method.c_str(), |
| 875 | dex_method_idx); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 876 | if (options_.list_methods_) return success; |
| 877 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 878 | uint32_t oat_method_offsets_offset = oat_class.GetOatMethodOffsetsOffset(class_method_index); |
| 879 | const OatMethodOffsets* oat_method_offsets = oat_class.GetOatMethodOffsets(class_method_index); |
| 880 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_index); |
| 881 | uint32_t code_offset = oat_method.GetCodeOffset(); |
| 882 | uint32_t code_size = oat_method.GetQuickCodeSize(); |
| 883 | if (resolved_addr2instr_ != 0) { |
| 884 | if (resolved_addr2instr_ > code_offset + code_size) { |
| 885 | return success; |
| 886 | } else { |
| 887 | *addr_found = true; // stop analyzing file at next iteration |
| 888 | } |
| 889 | } |
| 890 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 891 | // Everything below is indented at least once. |
| 892 | ScopedIndentation indent1(vios); |
| 893 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 894 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 895 | vios->Stream() << "DEX CODE:\n"; |
| 896 | ScopedIndentation indent2(vios); |
| 897 | DumpDexCode(vios->Stream(), dex_file, code_item); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 898 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 899 | |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 900 | std::unique_ptr<StackHandleScope<1>> hs; |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 901 | std::unique_ptr<verifier::MethodVerifier> verifier; |
| 902 | if (Runtime::Current() != nullptr) { |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 903 | // We need to have the handle scope stay live until after the verifier since the verifier has |
| 904 | // a handle to the dex cache from hs. |
| 905 | hs.reset(new StackHandleScope<1>(Thread::Current())); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 906 | vios->Stream() << "VERIFIER TYPE ANALYSIS:\n"; |
| 907 | ScopedIndentation indent2(vios); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 908 | verifier.reset(DumpVerifier(vios, hs.get(), |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 909 | dex_method_idx, &dex_file, class_def, code_item, |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 910 | method_access_flags)); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 911 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 912 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 913 | vios->Stream() << "OatMethodOffsets "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 914 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 915 | vios->Stream() << StringPrintf("%p ", oat_method_offsets); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 916 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 917 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", oat_method_offsets_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 918 | if (oat_method_offsets_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 919 | vios->Stream() << StringPrintf( |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 920 | "WARNING: oat method offsets offset 0x%08x is past end of file 0x%08zx.\n", |
| 921 | oat_method_offsets_offset, oat_file_.Size()); |
| 922 | // If we can't read OatMethodOffsets, the rest of the data is dangerous to read. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 923 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 924 | return false; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 925 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 926 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 927 | ScopedIndentation indent2(vios); |
| 928 | vios->Stream() << StringPrintf("code_offset: 0x%08x ", code_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 929 | uint32_t aligned_code_begin = AlignCodeOffset(oat_method.GetCodeOffset()); |
| 930 | if (aligned_code_begin > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 931 | vios->Stream() << StringPrintf("WARNING: " |
| 932 | "code offset 0x%08x is past end of file 0x%08zx.\n", |
| 933 | aligned_code_begin, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 934 | success = false; |
| 935 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 936 | vios->Stream() << "\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 937 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 938 | vios->Stream() << "gc_map: "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 939 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 940 | vios->Stream() << StringPrintf("%p ", oat_method.GetGcMap()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 941 | } |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 942 | uint32_t gc_map_offset = oat_method.GetGcMapOffset(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 943 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", gc_map_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 944 | if (gc_map_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 945 | vios->Stream() << StringPrintf("WARNING: " |
| 946 | "gc map table offset 0x%08x is past end of file 0x%08zx.\n", |
| 947 | gc_map_offset, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 948 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 949 | } else if (options_.dump_raw_gc_map_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 950 | ScopedIndentation indent3(vios); |
| 951 | DumpGcMap(vios->Stream(), oat_method, code_item); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 955 | vios->Stream() << "OatQuickMethodHeader "; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 956 | uint32_t method_header_offset = oat_method.GetOatQuickMethodHeaderOffset(); |
| 957 | const OatQuickMethodHeader* method_header = oat_method.GetOatQuickMethodHeader(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 958 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 959 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 960 | vios->Stream() << StringPrintf("%p ", method_header); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 961 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 962 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", method_header_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 963 | if (method_header_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 964 | vios->Stream() << StringPrintf( |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 965 | "WARNING: oat quick method header offset 0x%08x is past end of file 0x%08zx.\n", |
| 966 | method_header_offset, oat_file_.Size()); |
| 967 | // If we can't read the OatQuickMethodHeader, the rest of the data is dangerous to read. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 968 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 969 | return false; |
| 970 | } |
| 971 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 972 | ScopedIndentation indent2(vios); |
| 973 | vios->Stream() << "mapping_table: "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 974 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 975 | vios->Stream() << StringPrintf("%p ", oat_method.GetMappingTable()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 976 | } |
| 977 | uint32_t mapping_table_offset = oat_method.GetMappingTableOffset(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 978 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", oat_method.GetMappingTableOffset()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 979 | if (mapping_table_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 980 | vios->Stream() << StringPrintf("WARNING: " |
| 981 | "mapping table offset 0x%08x is past end of file 0x%08zx. " |
| 982 | "mapping table offset was loaded from offset 0x%08x.\n", |
| 983 | mapping_table_offset, oat_file_.Size(), |
| 984 | oat_method.GetMappingTableOffsetOffset()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 985 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 986 | } else if (options_.dump_raw_mapping_table_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 987 | ScopedIndentation indent3(vios); |
| 988 | DumpMappingTable(vios, oat_method); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 991 | vios->Stream() << "vmap_table: "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 992 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 993 | vios->Stream() << StringPrintf("%p ", oat_method.GetVmapTable()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 994 | } |
| 995 | uint32_t vmap_table_offset = oat_method.GetVmapTableOffset(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 996 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", vmap_table_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 997 | if (vmap_table_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 998 | vios->Stream() << StringPrintf("WARNING: " |
| 999 | "vmap table offset 0x%08x is past end of file 0x%08zx. " |
| 1000 | "vmap table offset was loaded from offset 0x%08x.\n", |
| 1001 | vmap_table_offset, oat_file_.Size(), |
| 1002 | oat_method.GetVmapTableOffsetOffset()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1003 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1004 | } else if (options_.dump_vmap_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1005 | DumpVmapData(vios, oat_method, code_item); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1006 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1007 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1008 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1009 | vios->Stream() << "QuickMethodFrameInfo\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1010 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1011 | ScopedIndentation indent2(vios); |
| 1012 | vios->Stream() |
| 1013 | << StringPrintf("frame_size_in_bytes: %zd\n", oat_method.GetFrameSizeInBytes()); |
| 1014 | vios->Stream() << StringPrintf("core_spill_mask: 0x%08x ", oat_method.GetCoreSpillMask()); |
| 1015 | DumpSpillMask(vios->Stream(), oat_method.GetCoreSpillMask(), false); |
| 1016 | vios->Stream() << "\n"; |
| 1017 | vios->Stream() << StringPrintf("fp_spill_mask: 0x%08x ", oat_method.GetFpSpillMask()); |
| 1018 | DumpSpillMask(vios->Stream(), oat_method.GetFpSpillMask(), true); |
| 1019 | vios->Stream() << "\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1020 | } |
| 1021 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1022 | // Based on spill masks from QuickMethodFrameInfo so placed |
| 1023 | // after it is dumped, but useful for understanding quick |
| 1024 | // code, so dumped here. |
| 1025 | ScopedIndentation indent2(vios); |
| 1026 | DumpVregLocations(vios->Stream(), oat_method, code_item); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1027 | } |
| 1028 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1029 | vios->Stream() << "CODE: "; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1030 | uint32_t code_size_offset = oat_method.GetQuickCodeSizeOffset(); |
| 1031 | if (code_size_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1032 | ScopedIndentation indent2(vios); |
| 1033 | vios->Stream() << StringPrintf("WARNING: " |
| 1034 | "code size offset 0x%08x is past end of file 0x%08zx.", |
| 1035 | code_size_offset, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1036 | success = false; |
| 1037 | } else { |
| 1038 | const void* code = oat_method.GetQuickCode(); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1039 | uint32_t aligned_code_begin = AlignCodeOffset(code_offset); |
| 1040 | uint64_t aligned_code_end = aligned_code_begin + code_size; |
| 1041 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1042 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1043 | vios->Stream() << StringPrintf("%p ", code); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1044 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1045 | vios->Stream() << StringPrintf("(code_offset=0x%08x size_offset=0x%08x size=%u)%s\n", |
| 1046 | code_offset, |
| 1047 | code_size_offset, |
| 1048 | code_size, |
| 1049 | code != nullptr ? "..." : ""); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1050 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1051 | ScopedIndentation indent2(vios); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1052 | if (aligned_code_begin > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1053 | vios->Stream() << StringPrintf("WARNING: " |
| 1054 | "start of code at 0x%08x is past end of file 0x%08zx.", |
| 1055 | aligned_code_begin, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1056 | success = false; |
| 1057 | } else if (aligned_code_end > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1058 | vios->Stream() << StringPrintf( |
| 1059 | "WARNING: " |
| 1060 | "end of code at 0x%08" PRIx64 " is past end of file 0x%08zx. " |
| 1061 | "code size is 0x%08x loaded from offset 0x%08x.\n", |
| 1062 | aligned_code_end, oat_file_.Size(), |
| 1063 | code_size, code_size_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1064 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1065 | if (options_.disassemble_code_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1066 | if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1067 | DumpCode(vios, verifier.get(), oat_method, code_item, true, kPrologueBytes); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | } else if (code_size > kMaxCodeSize) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1071 | vios->Stream() << StringPrintf( |
| 1072 | "WARNING: " |
| 1073 | "code size %d is bigger than max expected threshold of %d. " |
| 1074 | "code size is 0x%08x loaded from offset 0x%08x.\n", |
| 1075 | code_size, kMaxCodeSize, |
| 1076 | code_size, code_size_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1077 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1078 | if (options_.disassemble_code_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1079 | if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1080 | DumpCode(vios, verifier.get(), oat_method, code_item, true, kPrologueBytes); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1081 | } |
| 1082 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1083 | } else if (options_.disassemble_code_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1084 | DumpCode(vios, verifier.get(), oat_method, code_item, !success, 0); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1088 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1089 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1090 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1091 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1092 | void DumpSpillMask(std::ostream& os, uint32_t spill_mask, bool is_float) { |
| 1093 | if (spill_mask == 0) { |
| 1094 | return; |
| 1095 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1096 | os << "("; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1097 | for (size_t i = 0; i < 32; i++) { |
| 1098 | if ((spill_mask & (1 << i)) != 0) { |
| 1099 | if (is_float) { |
| 1100 | os << "fr" << i; |
| 1101 | } else { |
| 1102 | os << "r" << i; |
| 1103 | } |
| 1104 | spill_mask ^= 1 << i; // clear bit |
| 1105 | if (spill_mask != 0) { |
| 1106 | os << ", "; |
| 1107 | } else { |
| 1108 | break; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | os << ")"; |
| 1113 | } |
| 1114 | |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1115 | // Display data stored at the the vmap offset of an oat method. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1116 | void DumpVmapData(VariableIndentationOutputStream* vios, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1117 | const OatFile::OatMethod& oat_method, |
| 1118 | const DexFile::CodeItem* code_item) { |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1119 | if (IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { |
| 1120 | // The optimizing compiler outputs its CodeInfo data in the vmap table. |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1121 | const void* raw_code_info = oat_method.GetVmapTable(); |
| 1122 | if (raw_code_info != nullptr) { |
| 1123 | CodeInfo code_info(raw_code_info); |
| 1124 | DCHECK(code_item != nullptr); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1125 | ScopedIndentation indent1(vios); |
| 1126 | DumpCodeInfo(vios, code_info, oat_method, *code_item); |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1127 | } |
Nicolas Geoffray | 0a5cd12 | 2015-07-16 14:15:05 +0100 | [diff] [blame] | 1128 | } else if (IsMethodGeneratedByDexToDexCompiler(oat_method, code_item)) { |
| 1129 | // We don't encode the size in the table, so just emit that we have quickened |
| 1130 | // information. |
| 1131 | ScopedIndentation indent(vios); |
| 1132 | vios->Stream() << "quickened data\n"; |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1133 | } else { |
| 1134 | // Otherwise, display the vmap table. |
| 1135 | const uint8_t* raw_table = oat_method.GetVmapTable(); |
| 1136 | if (raw_table != nullptr) { |
| 1137 | VmapTable vmap_table(raw_table); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1138 | DumpVmapTable(vios->Stream(), oat_method, vmap_table); |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1139 | } |
Nicolas Geoffray | 20d3eae | 2014-09-17 11:27:23 +0100 | [diff] [blame] | 1140 | } |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | // Display a CodeInfo object emitted by the optimizing compiler. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1144 | void DumpCodeInfo(VariableIndentationOutputStream* vios, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1145 | const CodeInfo& code_info, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1146 | const OatFile::OatMethod& oat_method, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1147 | const DexFile::CodeItem& code_item) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1148 | code_info.Dump(vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1149 | oat_method.GetCodeOffset(), |
| 1150 | code_item.registers_size_, |
| 1151 | options_.dump_code_info_stack_maps_); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1152 | } |
| 1153 | |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1154 | // Display a vmap table. |
| 1155 | void DumpVmapTable(std::ostream& os, |
| 1156 | const OatFile::OatMethod& oat_method, |
| 1157 | const VmapTable& vmap_table) { |
| 1158 | bool first = true; |
| 1159 | bool processing_fp = false; |
| 1160 | uint32_t spill_mask = oat_method.GetCoreSpillMask(); |
| 1161 | for (size_t i = 0; i < vmap_table.Size(); i++) { |
| 1162 | uint16_t dex_reg = vmap_table[i]; |
| 1163 | uint32_t cpu_reg = vmap_table.ComputeRegister(spill_mask, i, |
| 1164 | processing_fp ? kFloatVReg : kIntVReg); |
| 1165 | os << (first ? "v" : ", v") << dex_reg; |
| 1166 | if (!processing_fp) { |
| 1167 | os << "/r" << cpu_reg; |
| 1168 | } else { |
| 1169 | os << "/fr" << cpu_reg; |
| 1170 | } |
| 1171 | first = false; |
| 1172 | if (!processing_fp && dex_reg == 0xFFFF) { |
| 1173 | processing_fp = true; |
| 1174 | spill_mask = oat_method.GetFpSpillMask(); |
| 1175 | } |
| 1176 | } |
| 1177 | os << "\n"; |
| 1178 | } |
| 1179 | |
Razvan A Lupusoru | faf9f0d | 2014-08-29 17:56:46 -0700 | [diff] [blame] | 1180 | void DumpVregLocations(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1181 | const DexFile::CodeItem* code_item) { |
| 1182 | if (code_item != nullptr) { |
| 1183 | size_t num_locals_ins = code_item->registers_size_; |
| 1184 | size_t num_ins = code_item->ins_size_; |
| 1185 | size_t num_locals = num_locals_ins - num_ins; |
| 1186 | size_t num_outs = code_item->outs_size_; |
| 1187 | |
| 1188 | os << "vr_stack_locations:"; |
| 1189 | for (size_t reg = 0; reg <= num_locals_ins; reg++) { |
| 1190 | // For readability, delimit the different kinds of VRs. |
| 1191 | if (reg == num_locals_ins) { |
| 1192 | os << "\n\tmethod*:"; |
| 1193 | } else if (reg == num_locals && num_ins > 0) { |
| 1194 | os << "\n\tins:"; |
| 1195 | } else if (reg == 0 && num_locals > 0) { |
| 1196 | os << "\n\tlocals:"; |
| 1197 | } |
| 1198 | |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 1199 | uint32_t offset = StackVisitor::GetVRegOffsetFromQuickCode( |
| 1200 | code_item, |
| 1201 | oat_method.GetCoreSpillMask(), |
| 1202 | oat_method.GetFpSpillMask(), |
| 1203 | oat_method.GetFrameSizeInBytes(), |
| 1204 | reg, |
| 1205 | GetInstructionSet()); |
Razvan A Lupusoru | faf9f0d | 2014-08-29 17:56:46 -0700 | [diff] [blame] | 1206 | os << " v" << reg << "[sp + #" << offset << "]"; |
| 1207 | } |
| 1208 | |
| 1209 | for (size_t out_reg = 0; out_reg < num_outs; out_reg++) { |
| 1210 | if (out_reg == 0) { |
| 1211 | os << "\n\touts:"; |
| 1212 | } |
| 1213 | |
| 1214 | uint32_t offset = StackVisitor::GetOutVROffset(out_reg, GetInstructionSet()); |
| 1215 | os << " v" << out_reg << "[sp + #" << offset << "]"; |
| 1216 | } |
| 1217 | |
| 1218 | os << "\n"; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1222 | void DescribeVReg(std::ostream& os, const OatFile::OatMethod& oat_method, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1223 | const DexFile::CodeItem* code_item, size_t reg, VRegKind kind) { |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1224 | const uint8_t* raw_table = oat_method.GetVmapTable(); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1225 | if (raw_table != nullptr) { |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1226 | const VmapTable vmap_table(raw_table); |
| 1227 | uint32_t vmap_offset; |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1228 | if (vmap_table.IsInContext(reg, kind, &vmap_offset)) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1229 | bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
| 1230 | uint32_t spill_mask = is_float ? oat_method.GetFpSpillMask() |
| 1231 | : oat_method.GetCoreSpillMask(); |
| 1232 | os << (is_float ? "fr" : "r") << vmap_table.ComputeRegister(spill_mask, vmap_offset, kind); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1233 | } else { |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 1234 | uint32_t offset = StackVisitor::GetVRegOffsetFromQuickCode( |
| 1235 | code_item, |
| 1236 | oat_method.GetCoreSpillMask(), |
| 1237 | oat_method.GetFpSpillMask(), |
| 1238 | oat_method.GetFrameSizeInBytes(), |
| 1239 | reg, |
| 1240 | GetInstructionSet()); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1241 | os << "[sp + #" << offset << "]"; |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1246 | void DumpGcMapRegisters(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1247 | const DexFile::CodeItem* code_item, |
| 1248 | size_t num_regs, const uint8_t* reg_bitmap) { |
| 1249 | bool first = true; |
| 1250 | for (size_t reg = 0; reg < num_regs; reg++) { |
| 1251 | if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) { |
| 1252 | if (first) { |
| 1253 | os << " v" << reg << " ("; |
| 1254 | DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); |
| 1255 | os << ")"; |
| 1256 | first = false; |
| 1257 | } else { |
| 1258 | os << ", v" << reg << " ("; |
| 1259 | DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); |
| 1260 | os << ")"; |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | if (first) { |
| 1265 | os << "No registers in GC map\n"; |
| 1266 | } else { |
| 1267 | os << "\n"; |
| 1268 | } |
| 1269 | } |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1270 | void DumpGcMap(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1271 | const DexFile::CodeItem* code_item) { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 1272 | const uint8_t* gc_map_raw = oat_method.GetGcMap(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1273 | if (gc_map_raw == nullptr) { |
| 1274 | return; // No GC map. |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1275 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1276 | const void* quick_code = oat_method.GetQuickCode(); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 1277 | NativePcOffsetToReferenceMap map(gc_map_raw); |
| 1278 | for (size_t entry = 0; entry < map.NumEntries(); entry++) { |
| 1279 | const uint8_t* native_pc = reinterpret_cast<const uint8_t*>(quick_code) + |
| 1280 | map.GetNativePcOffset(entry); |
| 1281 | os << StringPrintf("%p", native_pc); |
| 1282 | DumpGcMapRegisters(os, oat_method, code_item, map.RegWidth() * 8, map.GetBitMap(entry)); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1286 | void DumpMappingTable(VariableIndentationOutputStream* vios, |
| 1287 | const OatFile::OatMethod& oat_method) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1288 | const void* quick_code = oat_method.GetQuickCode(); |
| 1289 | if (quick_code == nullptr) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1290 | return; |
| 1291 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1292 | MappingTable table(oat_method.GetMappingTable()); |
| 1293 | if (table.TotalSize() != 0) { |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1294 | if (table.PcToDexSize() != 0) { |
| 1295 | typedef MappingTable::PcToDexIterator It; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1296 | vios->Stream() << "suspend point mappings {\n"; |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1297 | for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1298 | ScopedIndentation indent1(vios); |
| 1299 | vios->Stream() << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1300 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1301 | vios->Stream() << "}\n"; |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1302 | } |
| 1303 | if (table.DexToPcSize() != 0) { |
| 1304 | typedef MappingTable::DexToPcIterator It; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1305 | vios->Stream() << "catch entry mappings {\n"; |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1306 | for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1307 | ScopedIndentation indent1(vios); |
| 1308 | vios->Stream() << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1309 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1310 | vios->Stream() << "}\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1311 | } |
| 1312 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1315 | uint32_t DumpInformationAtOffset(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1316 | const OatFile::OatMethod& oat_method, |
| 1317 | const DexFile::CodeItem* code_item, |
| 1318 | size_t offset, |
| 1319 | bool suspend_point_mapping) { |
| 1320 | if (IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { |
| 1321 | if (suspend_point_mapping) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1322 | ScopedIndentation indent1(vios); |
| 1323 | DumpDexRegisterMapAtOffset(vios, oat_method, code_item, offset); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1324 | } |
| 1325 | // The return value is not used in the case of a method compiled |
| 1326 | // with the optimizing compiler. |
| 1327 | return DexFile::kDexNoIndex; |
| 1328 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1329 | return DumpMappingAtOffset(vios->Stream(), oat_method, offset, suspend_point_mapping); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1333 | uint32_t DumpMappingAtOffset(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1334 | size_t offset, bool suspend_point_mapping) { |
| 1335 | MappingTable table(oat_method.GetMappingTable()); |
| 1336 | if (suspend_point_mapping && table.PcToDexSize() > 0) { |
| 1337 | typedef MappingTable::PcToDexIterator It; |
| 1338 | for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 1339 | if (offset == cur.NativePcOffset()) { |
Brian Carlstrom | 4b8c13e | 2013-08-23 18:10:32 -0700 | [diff] [blame] | 1340 | os << StringPrintf("suspend point dex PC: 0x%04x\n", cur.DexPc()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1341 | return cur.DexPc(); |
| 1342 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1343 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1344 | } else if (!suspend_point_mapping && table.DexToPcSize() > 0) { |
| 1345 | typedef MappingTable::DexToPcIterator It; |
| 1346 | for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 1347 | if (offset == cur.NativePcOffset()) { |
Brian Carlstrom | 4b8c13e | 2013-08-23 18:10:32 -0700 | [diff] [blame] | 1348 | os << StringPrintf("catch entry dex PC: 0x%04x\n", cur.DexPc()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 1349 | return cur.DexPc(); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1350 | } |
| 1351 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1352 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1353 | return DexFile::kDexNoIndex; |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1356 | void DumpGcMapAtNativePcOffset(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1357 | const DexFile::CodeItem* code_item, size_t native_pc_offset) { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 1358 | const uint8_t* gc_map_raw = oat_method.GetGcMap(); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1359 | if (gc_map_raw != nullptr) { |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1360 | NativePcOffsetToReferenceMap map(gc_map_raw); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1361 | if (map.HasEntry(native_pc_offset)) { |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1362 | size_t num_regs = map.RegWidth() * 8; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1363 | const uint8_t* reg_bitmap = map.FindBitMap(native_pc_offset); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1364 | bool first = true; |
| 1365 | for (size_t reg = 0; reg < num_regs; reg++) { |
| 1366 | if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) { |
| 1367 | if (first) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1368 | os << "GC map objects: v" << reg << " ("; |
| 1369 | DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1370 | os << ")"; |
| 1371 | first = false; |
| 1372 | } else { |
| 1373 | os << ", v" << reg << " ("; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1374 | DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1375 | os << ")"; |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | if (!first) { |
| 1380 | os << "\n"; |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1386 | void DumpVRegsAtDexPc(std::ostream& os, verifier::MethodVerifier* verifier, |
| 1387 | const OatFile::OatMethod& oat_method, |
| 1388 | const DexFile::CodeItem* code_item, uint32_t dex_pc) { |
| 1389 | DCHECK(verifier != nullptr); |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 1390 | std::vector<int32_t> kinds = verifier->DescribeVRegs(dex_pc); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1391 | bool first = true; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1392 | for (size_t reg = 0; reg < code_item->registers_size_; reg++) { |
| 1393 | VRegKind kind = static_cast<VRegKind>(kinds.at(reg * 2)); |
| 1394 | if (kind != kUndefined) { |
| 1395 | if (first) { |
| 1396 | os << "VRegs: v"; |
| 1397 | first = false; |
| 1398 | } else { |
| 1399 | os << ", v"; |
| 1400 | } |
| 1401 | os << reg << " ("; |
| 1402 | switch (kind) { |
| 1403 | case kImpreciseConstant: |
| 1404 | os << "Imprecise Constant: " << kinds.at((reg * 2) + 1) << ", "; |
| 1405 | DescribeVReg(os, oat_method, code_item, reg, kind); |
| 1406 | break; |
| 1407 | case kConstant: |
| 1408 | os << "Constant: " << kinds.at((reg * 2) + 1); |
| 1409 | break; |
| 1410 | default: |
| 1411 | DescribeVReg(os, oat_method, code_item, reg, kind); |
| 1412 | break; |
| 1413 | } |
| 1414 | os << ")"; |
| 1415 | } |
| 1416 | } |
| 1417 | if (!first) { |
| 1418 | os << "\n"; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1423 | void DumpDexCode(std::ostream& os, const DexFile& dex_file, const DexFile::CodeItem* code_item) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1424 | if (code_item != nullptr) { |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1425 | size_t i = 0; |
| 1426 | while (i < code_item->insns_size_in_code_units_) { |
| 1427 | const Instruction* instruction = Instruction::At(&code_item->insns_[i]); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1428 | os << StringPrintf("0x%04zx: ", i) << instruction->DumpHexLE(5) |
| 1429 | << StringPrintf("\t| %s\n", instruction->DumpString(&dex_file).c_str()); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1430 | i += instruction->SizeInCodeUnits(); |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1435 | // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by |
| 1436 | // the optimizing compiler? |
| 1437 | static bool IsMethodGeneratedByOptimizingCompiler(const OatFile::OatMethod& oat_method, |
| 1438 | const DexFile::CodeItem* code_item) { |
| 1439 | // If the native GC map is null and the Dex `code_item` is not |
| 1440 | // null, then this method has been compiled with the optimizing |
| 1441 | // compiler. |
Nicolas Geoffray | 0a5cd12 | 2015-07-16 14:15:05 +0100 | [diff] [blame] | 1442 | return oat_method.GetQuickCode() != nullptr && |
| 1443 | oat_method.GetGcMap() == nullptr && |
| 1444 | code_item != nullptr; |
| 1445 | } |
| 1446 | |
| 1447 | // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by |
| 1448 | // the dextodex compiler? |
| 1449 | static bool IsMethodGeneratedByDexToDexCompiler(const OatFile::OatMethod& oat_method, |
| 1450 | const DexFile::CodeItem* code_item) { |
| 1451 | // If the quick code is null, the Dex `code_item` is not |
| 1452 | // null, and the vmap table is not null, then this method has been compiled |
| 1453 | // with the dextodex compiler. |
| 1454 | return oat_method.GetQuickCode() == nullptr && |
| 1455 | oat_method.GetVmapTable() != nullptr && |
| 1456 | code_item != nullptr; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1457 | } |
| 1458 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1459 | void DumpDexRegisterMapAtOffset(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1460 | const OatFile::OatMethod& oat_method, |
| 1461 | const DexFile::CodeItem* code_item, |
| 1462 | size_t offset) { |
| 1463 | // This method is only relevant for oat methods compiled with the |
| 1464 | // optimizing compiler. |
| 1465 | DCHECK(IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)); |
| 1466 | |
| 1467 | // The optimizing compiler outputs its CodeInfo data in the vmap table. |
| 1468 | const void* raw_code_info = oat_method.GetVmapTable(); |
| 1469 | if (raw_code_info != nullptr) { |
| 1470 | CodeInfo code_info(raw_code_info); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 1471 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 1472 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(offset, encoding); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1473 | if (stack_map.IsValid()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1474 | stack_map.Dump(vios, code_info, encoding, oat_method.GetCodeOffset(), |
| 1475 | code_item->registers_size_); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1480 | verifier::MethodVerifier* DumpVerifier(VariableIndentationOutputStream* vios, |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1481 | StackHandleScope<1>* hs, |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1482 | uint32_t dex_method_idx, |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1483 | const DexFile* dex_file, |
| 1484 | const DexFile::ClassDef& class_def, |
| 1485 | const DexFile::CodeItem* code_item, |
| 1486 | uint32_t method_access_flags) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1487 | if ((method_access_flags & kAccNative) == 0) { |
| 1488 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 1489 | Runtime* const runtime = Runtime::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1490 | Handle<mirror::DexCache> dex_cache( |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 1491 | hs->NewHandle(runtime->GetClassLinker()->RegisterDexFile(*dex_file, |
| 1492 | runtime->GetLinearAlloc()))); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1493 | DCHECK(options_.class_loader_ != nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1494 | return verifier::MethodVerifier::VerifyMethodAndDump( |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1495 | soa.Self(), vios, dex_method_idx, dex_file, dex_cache, *options_.class_loader_, |
| 1496 | &class_def, code_item, nullptr, method_access_flags); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1497 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1498 | |
| 1499 | return nullptr; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1502 | void DumpCode(VariableIndentationOutputStream* vios, |
| 1503 | verifier::MethodVerifier* verifier, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1504 | const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item, |
| 1505 | bool bad_input, size_t code_size) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1506 | const void* quick_code = oat_method.GetQuickCode(); |
| 1507 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1508 | if (code_size == 0) { |
| 1509 | code_size = oat_method.GetQuickCodeSize(); |
| 1510 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 1511 | if (code_size == 0 || quick_code == nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1512 | vios->Stream() << "NO CODE!\n"; |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1513 | return; |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 1514 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1515 | const uint8_t* quick_native_pc = reinterpret_cast<const uint8_t*>(quick_code); |
| 1516 | size_t offset = 0; |
| 1517 | while (offset < code_size) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1518 | if (!bad_input) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1519 | DumpInformationAtOffset(vios, oat_method, code_item, offset, false); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1520 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1521 | offset += disassembler_->Dump(vios->Stream(), quick_native_pc + offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1522 | if (!bad_input) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1523 | uint32_t dex_pc = |
| 1524 | DumpInformationAtOffset(vios, oat_method, code_item, offset, true); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1525 | if (dex_pc != DexFile::kDexNoIndex) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1526 | DumpGcMapAtNativePcOffset(vios->Stream(), oat_method, code_item, offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1527 | if (verifier != nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1528 | DumpVRegsAtDexPc(vios->Stream(), verifier, oat_method, code_item, dex_pc); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1529 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1530 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1531 | } |
| 1532 | } |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1536 | const OatFile& oat_file_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1537 | const std::vector<const OatFile::OatDexFile*> oat_dex_files_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1538 | const OatDumperOptions& options_; |
| 1539 | uint32_t resolved_addr2instr_; |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 1540 | InstructionSet instruction_set_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1541 | std::set<uintptr_t> offsets_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1542 | Disassembler* disassembler_; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1543 | }; |
| 1544 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1545 | class ImageDumper { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1546 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 1547 | ImageDumper(std::ostream* os, gc::space::ImageSpace& image_space, |
| 1548 | const ImageHeader& image_header, OatDumperOptions* oat_dumper_options) |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1549 | : os_(os), |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1550 | vios_(os), |
| 1551 | indent1_(&vios_), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1552 | image_space_(image_space), |
| 1553 | image_header_(image_header), |
| 1554 | oat_dumper_options_(oat_dumper_options) {} |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1555 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1556 | bool Dump() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1557 | std::ostream& os = *os_; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1558 | std::ostream& indent_os = vios_.Stream(); |
| 1559 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1560 | os << "MAGIC: " << image_header_.GetMagic() << "\n\n"; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 1561 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1562 | os << "IMAGE LOCATION: " << image_space_.GetImageLocation() << "\n\n"; |
| 1563 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1564 | os << "IMAGE BEGIN: " << reinterpret_cast<void*>(image_header_.GetImageBegin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1565 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1566 | os << "IMAGE SIZE: " << image_header_.GetImageSize() << "\n\n"; |
| 1567 | |
| 1568 | for (size_t i = 0; i < ImageHeader::kSectionCount; ++i) { |
| 1569 | auto section = static_cast<ImageHeader::ImageSections>(i); |
| 1570 | os << "IMAGE SECTION " << section << ": " << image_header_.GetImageSection(section) << "\n\n"; |
| 1571 | } |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 1572 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1573 | os << "OAT CHECKSUM: " << StringPrintf("0x%08x\n\n", image_header_.GetOatChecksum()); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 1574 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 1575 | os << "OAT FILE BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatFileBegin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1576 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 1577 | os << "OAT DATA BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatDataBegin()) << "\n\n"; |
| 1578 | |
| 1579 | os << "OAT DATA END:" << reinterpret_cast<void*>(image_header_.GetOatDataEnd()) << "\n\n"; |
| 1580 | |
| 1581 | os << "OAT FILE END:" << reinterpret_cast<void*>(image_header_.GetOatFileEnd()) << "\n\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1582 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1583 | os << "PATCH DELTA:" << image_header_.GetPatchDelta() << "\n\n"; |
| 1584 | |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 1585 | os << "COMPILE PIC: " << (image_header_.CompilePic() ? "yes" : "no") << "\n\n"; |
| 1586 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1587 | { |
| 1588 | os << "ROOTS: " << reinterpret_cast<void*>(image_header_.GetImageRoots()) << "\n"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1589 | static_assert(arraysize(image_roots_descriptions_) == |
| 1590 | static_cast<size_t>(ImageHeader::kImageRootsMax), "sizes must match"); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1591 | for (int i = 0; i < ImageHeader::kImageRootsMax; i++) { |
| 1592 | ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i); |
| 1593 | const char* image_root_description = image_roots_descriptions_[i]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1594 | mirror::Object* image_root_object = image_header_.GetImageRoot(image_root); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1595 | indent_os << StringPrintf("%s: %p\n", image_root_description, image_root_object); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1596 | if (image_root_object->IsObjectArray()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1597 | mirror::ObjectArray<mirror::Object>* image_root_object_array |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1598 | = image_root_object->AsObjectArray<mirror::Object>(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1599 | ScopedIndentation indent2(&vios_); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1600 | for (int j = 0; j < image_root_object_array->GetLength(); j++) { |
| 1601 | mirror::Object* value = image_root_object_array->Get(j); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1602 | size_t run = 0; |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1603 | for (int32_t k = j + 1; k < image_root_object_array->GetLength(); k++) { |
| 1604 | if (value == image_root_object_array->Get(k)) { |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1605 | run++; |
| 1606 | } else { |
| 1607 | break; |
| 1608 | } |
| 1609 | } |
| 1610 | if (run == 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1611 | indent_os << StringPrintf("%d: ", j); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1612 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1613 | indent_os << StringPrintf("%d to %zd: ", j, j + run); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1614 | j = j + run; |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1615 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1616 | if (value != nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1617 | PrettyObjectValue(indent_os, value->GetClass(), value); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1618 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1619 | indent_os << j << ": null\n"; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1620 | } |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1621 | } |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 1622 | } |
| 1623 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1624 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1625 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1626 | { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1627 | os << "METHOD ROOTS\n"; |
| 1628 | static_assert(arraysize(image_methods_descriptions_) == |
| 1629 | static_cast<size_t>(ImageHeader::kImageMethodsCount), "sizes must match"); |
| 1630 | for (int i = 0; i < ImageHeader::kImageMethodsCount; i++) { |
| 1631 | auto image_root = static_cast<ImageHeader::ImageMethod>(i); |
| 1632 | const char* description = image_methods_descriptions_[i]; |
| 1633 | auto* image_method = image_header_.GetImageMethod(image_root); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1634 | indent_os << StringPrintf("%s: %p\n", description, image_method); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1635 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1636 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1637 | os << "\n"; |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1638 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1639 | Runtime* const runtime = Runtime::Current(); |
| 1640 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1641 | std::string image_filename = image_space_.GetImageFilename(); |
| 1642 | std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(image_filename); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1643 | os << "OAT LOCATION: " << oat_location; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1644 | os << "\n"; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 1645 | std::string error_msg; |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1646 | const OatFile* oat_file = runtime->GetOatFileManager().FindOpenedOatFileFromOatLocation( |
| 1647 | oat_location); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1648 | if (oat_file == nullptr) { |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 1649 | oat_file = OatFile::Open(oat_location, oat_location, |
| 1650 | nullptr, nullptr, false, nullptr, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1651 | &error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1652 | if (oat_file == nullptr) { |
| 1653 | os << "NOT FOUND: " << error_msg << "\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1654 | return false; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1655 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1656 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1657 | os << "\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1658 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1659 | stats_.oat_file_bytes = oat_file->Size(); |
| 1660 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1661 | oat_dumper_.reset(new OatDumper(*oat_file, *oat_dumper_options_)); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1662 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1663 | for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1664 | CHECK(oat_dex_file != nullptr); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1665 | stats_.oat_dex_file_sizes.push_back(std::make_pair(oat_dex_file->GetDexFileLocation(), |
| 1666 | oat_dex_file->FileSize())); |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1669 | os << "OBJECTS:\n" << std::flush; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1670 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1671 | // Loop through the image space and dump its objects. |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1672 | gc::Heap* heap = runtime->GetHeap(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1673 | Thread* self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1674 | { |
Mathieu Chartier | c22c59e | 2014-02-24 15:16:06 -0800 | [diff] [blame] | 1675 | { |
| 1676 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 1677 | heap->FlushAllocStack(); |
| 1678 | } |
Hiroshi Yamauchi | 90d7068 | 2014-02-20 16:17:30 -0800 | [diff] [blame] | 1679 | // Since FlushAllocStack() above resets the (active) allocation |
| 1680 | // stack. Need to revoke the thread-local allocation stacks that |
| 1681 | // point into it. |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 1682 | ScopedThreadSuspension sts(self, kNative); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 1683 | ScopedSuspendAll ssa(__FUNCTION__); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 1684 | heap->RevokeAllThreadLocalAllocationStacks(self); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1685 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1686 | { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1687 | // Mark dex caches. |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1688 | dex_caches_.clear(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1689 | { |
| 1690 | ReaderMutexLock mu(self, *class_linker->DexLock()); |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 1691 | for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) { |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1692 | mirror::DexCache* dex_cache = |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 1693 | down_cast<mirror::DexCache*>(self->DecodeJObject(data.weak_root)); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1694 | if (dex_cache != nullptr) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1695 | dex_caches_.insert(dex_cache); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1696 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1697 | } |
| 1698 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1699 | ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1700 | // Dump the normal objects before ArtMethods. |
| 1701 | image_space_.GetLiveBitmap()->Walk(ImageDumper::Callback, this); |
| 1702 | indent_os << "\n"; |
| 1703 | // TODO: Dump fields. |
| 1704 | // Dump methods after. |
| 1705 | const auto& methods_section = image_header_.GetMethodsSection(); |
| 1706 | const size_t pointer_size = |
| 1707 | InstructionSetPointerSize(oat_dumper_->GetOatInstructionSet()); |
| 1708 | DumpArtMethodVisitor visitor(this); |
| 1709 | methods_section.VisitPackedArtMethods(&visitor, image_space_.Begin(), pointer_size); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1710 | // Dump the large objects separately. |
Mathieu Chartier | bbd695c | 2014-04-16 09:48:48 -0700 | [diff] [blame] | 1711 | heap->GetLargeObjectsSpace()->GetLiveBitmap()->Walk(ImageDumper::Callback, this); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1712 | indent_os << "\n"; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1713 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1714 | os << "STATS:\n" << std::flush; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1715 | std::unique_ptr<File> file(OS::OpenFileForReading(image_filename.c_str())); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1716 | if (file.get() == nullptr) { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1717 | LOG(WARNING) << "Failed to find image in " << image_filename; |
Brian Carlstrom | 6f27775 | 2013-09-30 17:56:45 -0700 | [diff] [blame] | 1718 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1719 | if (file.get() != nullptr) { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1720 | stats_.file_bytes = file->GetLength(); |
Brian Carlstrom | 6f27775 | 2013-09-30 17:56:45 -0700 | [diff] [blame] | 1721 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1722 | size_t header_bytes = sizeof(ImageHeader); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1723 | const auto& object_section = image_header_.GetImageSection(ImageHeader::kSectionObjects); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1724 | const auto& field_section = image_header_.GetImageSection(ImageHeader::kSectionArtFields); |
| 1725 | const auto& method_section = image_header_.GetMethodsSection(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1726 | const auto& dex_cache_arrays_section = image_header_.GetImageSection( |
| 1727 | ImageHeader::kSectionDexCacheArrays); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 1728 | const auto& intern_section = image_header_.GetImageSection( |
| 1729 | ImageHeader::kSectionInternedStrings); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 1730 | const auto& class_table_section = image_header_.GetImageSection( |
| 1731 | ImageHeader::kSectionClassTable); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1732 | const auto& bitmap_section = image_header_.GetImageSection(ImageHeader::kSectionImageBitmap); |
| 1733 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1734 | stats_.header_bytes = header_bytes; |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1735 | |
| 1736 | // Objects are kObjectAlignment-aligned. |
| 1737 | // CHECK_EQ(RoundUp(header_bytes, kObjectAlignment), object_section.Offset()); |
| 1738 | if (object_section.Offset() > header_bytes) { |
| 1739 | stats_.alignment_bytes += object_section.Offset() - header_bytes; |
| 1740 | } |
| 1741 | |
| 1742 | // Field section is 4-byte aligned. |
| 1743 | constexpr size_t kFieldSectionAlignment = 4U; |
| 1744 | uint32_t end_objects = object_section.Offset() + object_section.Size(); |
| 1745 | CHECK_EQ(RoundUp(end_objects, kFieldSectionAlignment), field_section.Offset()); |
| 1746 | stats_.alignment_bytes += field_section.Offset() - end_objects; |
| 1747 | |
| 1748 | // Method section is 4/8 byte aligned depending on target. Just check for 4-byte alignment. |
| 1749 | uint32_t end_fields = field_section.Offset() + field_section.Size(); |
| 1750 | CHECK_ALIGNED(method_section.Offset(), 4); |
| 1751 | stats_.alignment_bytes += method_section.Offset() - end_fields; |
| 1752 | |
| 1753 | // Dex cache arrays section is aligned depending on the target. Just check for 4-byte alignment. |
| 1754 | uint32_t end_methods = method_section.Offset() + method_section.Size(); |
| 1755 | CHECK_ALIGNED(dex_cache_arrays_section.Offset(), 4); |
| 1756 | stats_.alignment_bytes += dex_cache_arrays_section.Offset() - end_methods; |
| 1757 | |
| 1758 | // Intern table is 8-byte aligned. |
| 1759 | uint32_t end_caches = dex_cache_arrays_section.Offset() + dex_cache_arrays_section.Size(); |
| 1760 | CHECK_EQ(RoundUp(end_caches, 8U), intern_section.Offset()); |
| 1761 | stats_.alignment_bytes += intern_section.Offset() - end_caches; |
| 1762 | |
| 1763 | // Add space between intern table and class table. |
| 1764 | uint32_t end_intern = intern_section.Offset() + intern_section.Size(); |
| 1765 | stats_.alignment_bytes += class_table_section.Offset() - end_intern; |
| 1766 | |
| 1767 | // Add space between class table and bitmap. Expect the bitmap to be page-aligned. |
| 1768 | uint32_t end_ctable = class_table_section.Offset() + class_table_section.Size(); |
| 1769 | CHECK_ALIGNED(bitmap_section.Offset(), kPageSize); |
| 1770 | stats_.alignment_bytes += bitmap_section.Offset() - end_ctable; |
| 1771 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1772 | stats_.bitmap_bytes += bitmap_section.Size(); |
| 1773 | stats_.art_field_bytes += field_section.Size(); |
Vladimir Marko | cf36d49 | 2015-08-12 19:27:26 +0100 | [diff] [blame] | 1774 | stats_.art_method_bytes += method_section.Size(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1775 | stats_.dex_cache_arrays_bytes += dex_cache_arrays_section.Size(); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 1776 | stats_.interned_strings_bytes += intern_section.Size(); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 1777 | stats_.class_table_bytes += class_table_section.Size(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1778 | stats_.Dump(os, indent_os); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1779 | os << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1780 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1781 | os << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1782 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1783 | return oat_dumper_->Dump(os); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1786 | private: |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1787 | class DumpArtMethodVisitor : public ArtMethodVisitor { |
| 1788 | public: |
| 1789 | explicit DumpArtMethodVisitor(ImageDumper* image_dumper) : image_dumper_(image_dumper) {} |
| 1790 | |
| 1791 | virtual void Visit(ArtMethod* method) OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1792 | std::ostream& indent_os = image_dumper_->vios_.Stream(); |
| 1793 | indent_os << method << " " << " ArtMethod: " << PrettyMethod(method) << "\n"; |
| 1794 | image_dumper_->DumpMethod(method, image_dumper_, indent_os); |
| 1795 | indent_os << "\n"; |
| 1796 | } |
| 1797 | |
| 1798 | private: |
| 1799 | ImageDumper* const image_dumper_; |
| 1800 | }; |
| 1801 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1802 | static void PrettyObjectValue(std::ostream& os, mirror::Class* type, mirror::Object* value) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1803 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1804 | CHECK(type != nullptr); |
| 1805 | if (value == nullptr) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1806 | os << StringPrintf("null %s\n", PrettyDescriptor(type).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1807 | } else if (type->IsStringClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1808 | mirror::String* string = value->AsString(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1809 | os << StringPrintf("%p String: %s\n", string, |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 1810 | PrintableString(string->ToModifiedUtf8().c_str()).c_str()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1811 | } else if (type->IsClassClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1812 | mirror::Class* klass = value->AsClass(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1813 | os << StringPrintf("%p Class: %s\n", klass, PrettyDescriptor(klass).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1814 | } else { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1815 | os << StringPrintf("%p %s\n", value, PrettyDescriptor(type).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1819 | static void PrintField(std::ostream& os, ArtField* field, mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1820 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 1821 | os << StringPrintf("%s: ", field->GetName()); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1822 | switch (field->GetTypeAsPrimitiveType()) { |
| 1823 | case Primitive::kPrimLong: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1824 | os << StringPrintf("%" PRId64 " (0x%" PRIx64 ")\n", field->Get64(obj), field->Get64(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1825 | break; |
| 1826 | case Primitive::kPrimDouble: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1827 | os << StringPrintf("%f (%a)\n", field->GetDouble(obj), field->GetDouble(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1828 | break; |
| 1829 | case Primitive::kPrimFloat: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1830 | os << StringPrintf("%f (%a)\n", field->GetFloat(obj), field->GetFloat(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1831 | break; |
| 1832 | case Primitive::kPrimInt: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1833 | os << StringPrintf("%d (0x%x)\n", field->Get32(obj), field->Get32(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1834 | break; |
| 1835 | case Primitive::kPrimChar: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1836 | os << StringPrintf("%u (0x%x)\n", field->GetChar(obj), field->GetChar(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1837 | break; |
| 1838 | case Primitive::kPrimShort: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1839 | os << StringPrintf("%d (0x%x)\n", field->GetShort(obj), field->GetShort(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1840 | break; |
| 1841 | case Primitive::kPrimBoolean: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1842 | os << StringPrintf("%s (0x%x)\n", field->GetBoolean(obj)? "true" : "false", |
| 1843 | field->GetBoolean(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1844 | break; |
| 1845 | case Primitive::kPrimByte: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1846 | os << StringPrintf("%d (0x%x)\n", field->GetByte(obj), field->GetByte(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1847 | break; |
| 1848 | case Primitive::kPrimNot: { |
| 1849 | // Get the value, don't compute the type unless it is non-null as we don't want |
| 1850 | // to cause class loading. |
| 1851 | mirror::Object* value = field->GetObj(obj); |
| 1852 | if (value == nullptr) { |
| 1853 | os << StringPrintf("null %s\n", PrettyDescriptor(field->GetTypeDescriptor()).c_str()); |
Ian Rogers | 50239c7 | 2013-06-17 14:53:22 -0700 | [diff] [blame] | 1854 | } else { |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1855 | // Grab the field type without causing resolution. |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 1856 | mirror::Class* field_type = field->GetType<false>(); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1857 | if (field_type != nullptr) { |
| 1858 | PrettyObjectValue(os, field_type, value); |
| 1859 | } else { |
| 1860 | os << StringPrintf("%p %s\n", value, |
| 1861 | PrettyDescriptor(field->GetTypeDescriptor()).c_str()); |
| 1862 | } |
Ian Rogers | 50239c7 | 2013-06-17 14:53:22 -0700 | [diff] [blame] | 1863 | } |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1864 | break; |
Ian Rogers | 48efc2b | 2012-08-27 17:20:31 -0700 | [diff] [blame] | 1865 | } |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1866 | default: |
| 1867 | os << "unexpected field type: " << field->GetTypeDescriptor() << "\n"; |
| 1868 | break; |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1872 | static void DumpFields(std::ostream& os, mirror::Object* obj, mirror::Class* klass) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1873 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1874 | mirror::Class* super = klass->GetSuperClass(); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1875 | if (super != nullptr) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1876 | DumpFields(os, obj, super); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1877 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1878 | for (ArtField& field : klass->GetIFields()) { |
| 1879 | PrintField(os, &field, obj); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1883 | bool InDumpSpace(const mirror::Object* object) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1884 | return image_space_.Contains(object); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1885 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1886 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1887 | const void* GetQuickOatCodeBegin(ArtMethod* m) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1888 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 1889 | const void* quick_code = m->GetEntryPointFromQuickCompiledCodePtrSize( |
| 1890 | InstructionSetPointerSize(oat_dumper_->GetOatInstructionSet())); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1891 | if (Runtime::Current()->GetClassLinker()->IsQuickResolutionStub(quick_code)) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1892 | quick_code = oat_dumper_->GetQuickOatCode(m); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1893 | } |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1894 | if (oat_dumper_->GetInstructionSet() == kThumb2) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1895 | quick_code = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(quick_code) & ~0x1); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1896 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1897 | return quick_code; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1898 | } |
| 1899 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1900 | uint32_t GetQuickOatCodeSize(ArtMethod* m) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1901 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1902 | const uint32_t* oat_code_begin = reinterpret_cast<const uint32_t*>(GetQuickOatCodeBegin(m)); |
| 1903 | if (oat_code_begin == nullptr) { |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1904 | return 0; |
| 1905 | } |
| 1906 | return oat_code_begin[-1]; |
| 1907 | } |
| 1908 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1909 | const void* GetQuickOatCodeEnd(ArtMethod* m) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1910 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1911 | const uint8_t* oat_code_begin = reinterpret_cast<const uint8_t*>(GetQuickOatCodeBegin(m)); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1912 | if (oat_code_begin == nullptr) { |
| 1913 | return nullptr; |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1914 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1915 | return oat_code_begin + GetQuickOatCodeSize(m); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1918 | static void Callback(mirror::Object* obj, void* arg) SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1919 | DCHECK(obj != nullptr); |
| 1920 | DCHECK(arg != nullptr); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1921 | ImageDumper* state = reinterpret_cast<ImageDumper*>(arg); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 1922 | if (!state->InDumpSpace(obj)) { |
| 1923 | return; |
| 1924 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 1925 | |
| 1926 | size_t object_bytes = obj->SizeOf(); |
| 1927 | size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes; |
| 1928 | state->stats_.object_bytes += object_bytes; |
| 1929 | state->stats_.alignment_bytes += alignment_bytes; |
| 1930 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1931 | std::ostream& os = state->vios_.Stream(); |
| 1932 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1933 | mirror::Class* obj_class = obj->GetClass(); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1934 | if (obj_class->IsArrayClass()) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1935 | os << StringPrintf("%p: %s length:%d\n", obj, PrettyDescriptor(obj_class).c_str(), |
| 1936 | obj->AsArray()->GetLength()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1937 | } else if (obj->IsClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1938 | mirror::Class* klass = obj->AsClass(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1939 | os << StringPrintf("%p: java.lang.Class \"%s\" (", obj, PrettyDescriptor(klass).c_str()) |
| 1940 | << klass->GetStatus() << ")\n"; |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1941 | } else if (obj_class->IsStringClass()) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1942 | os << StringPrintf("%p: java.lang.String %s\n", obj, |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 1943 | PrintableString(obj->AsString()->ToModifiedUtf8().c_str()).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1944 | } else { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1945 | os << StringPrintf("%p: %s\n", obj, PrettyDescriptor(obj_class).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1946 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1947 | ScopedIndentation indent1(&state->vios_); |
| 1948 | DumpFields(os, obj, obj_class); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1949 | const auto image_pointer_size = |
| 1950 | InstructionSetPointerSize(state->oat_dumper_->GetOatInstructionSet()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1951 | if (obj->IsObjectArray()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1952 | auto* obj_array = obj->AsObjectArray<mirror::Object>(); |
| 1953 | for (int32_t i = 0, length = obj_array->GetLength(); i < length; i++) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1954 | mirror::Object* value = obj_array->Get(i); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1955 | size_t run = 0; |
| 1956 | for (int32_t j = i + 1; j < length; j++) { |
| 1957 | if (value == obj_array->Get(j)) { |
| 1958 | run++; |
| 1959 | } else { |
| 1960 | break; |
| 1961 | } |
| 1962 | } |
| 1963 | if (run == 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1964 | os << StringPrintf("%d: ", i); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1965 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1966 | os << StringPrintf("%d to %zd: ", i, i + run); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1967 | i = i + run; |
| 1968 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1969 | mirror::Class* value_class = |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1970 | (value == nullptr) ? obj_class->GetComponentType() : value->GetClass(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1971 | PrettyObjectValue(os, value_class, value); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1972 | } |
| 1973 | } else if (obj->IsClass()) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1974 | mirror::Class* klass = obj->AsClass(); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1975 | if (klass->NumStaticFields() != 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1976 | os << "STATICS:\n"; |
| 1977 | ScopedIndentation indent2(&state->vios_); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1978 | for (ArtField& field : klass->GetSFields()) { |
| 1979 | PrintField(os, &field, field.GetDeclaringClass()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1980 | } |
| 1981 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1982 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1983 | auto it = state->dex_caches_.find(obj); |
| 1984 | if (it != state->dex_caches_.end()) { |
| 1985 | auto* dex_cache = down_cast<mirror::DexCache*>(obj); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1986 | const auto& field_section = state->image_header_.GetImageSection( |
| 1987 | ImageHeader::kSectionArtFields); |
| 1988 | const auto& method_section = state->image_header_.GetMethodsSection(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1989 | size_t num_methods = dex_cache->NumResolvedMethods(); |
| 1990 | if (num_methods != 0u) { |
| 1991 | os << "Methods (size=" << num_methods << "):"; |
| 1992 | ScopedIndentation indent2(&state->vios_); |
| 1993 | auto* resolved_methods = dex_cache->GetResolvedMethods(); |
| 1994 | for (size_t i = 0, length = dex_cache->NumResolvedMethods(); i < length; ++i) { |
| 1995 | auto* elem = mirror::DexCache::GetElementPtrSize(resolved_methods, i, image_pointer_size); |
| 1996 | size_t run = 0; |
| 1997 | for (size_t j = i + 1; |
| 1998 | j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_methods, |
| 1999 | j, |
| 2000 | image_pointer_size); |
| 2001 | ++j, ++run) {} |
| 2002 | if (run == 0) { |
| 2003 | os << StringPrintf("%zd: ", i); |
| 2004 | } else { |
| 2005 | os << StringPrintf("%zd to %zd: ", i, i + run); |
| 2006 | i = i + run; |
| 2007 | } |
| 2008 | std::string msg; |
| 2009 | if (elem == nullptr) { |
| 2010 | msg = "null"; |
| 2011 | } else if (method_section.Contains( |
| 2012 | reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { |
| 2013 | msg = PrettyMethod(reinterpret_cast<ArtMethod*>(elem)); |
| 2014 | } else { |
| 2015 | msg = "<not in method section>"; |
| 2016 | } |
| 2017 | os << StringPrintf("%p %s\n", elem, msg.c_str()); |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2018 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2019 | } |
| 2020 | size_t num_fields = dex_cache->NumResolvedFields(); |
| 2021 | if (num_fields != 0u) { |
| 2022 | os << "Fields (size=" << num_fields << "):"; |
| 2023 | ScopedIndentation indent2(&state->vios_); |
| 2024 | auto* resolved_fields = dex_cache->GetResolvedFields(); |
| 2025 | for (size_t i = 0, length = dex_cache->NumResolvedFields(); i < length; ++i) { |
| 2026 | auto* elem = mirror::DexCache::GetElementPtrSize(resolved_fields, i, image_pointer_size); |
| 2027 | size_t run = 0; |
| 2028 | for (size_t j = i + 1; |
| 2029 | j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_fields, |
| 2030 | j, |
| 2031 | image_pointer_size); |
| 2032 | ++j, ++run) {} |
| 2033 | if (run == 0) { |
| 2034 | os << StringPrintf("%zd: ", i); |
| 2035 | } else { |
| 2036 | os << StringPrintf("%zd to %zd: ", i, i + run); |
| 2037 | i = i + run; |
| 2038 | } |
| 2039 | std::string msg; |
| 2040 | if (elem == nullptr) { |
| 2041 | msg = "null"; |
| 2042 | } else if (field_section.Contains( |
| 2043 | reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { |
| 2044 | msg = PrettyField(reinterpret_cast<ArtField*>(elem)); |
| 2045 | } else { |
| 2046 | msg = "<not in field section>"; |
| 2047 | } |
| 2048 | os << StringPrintf("%p %s\n", elem, msg.c_str()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2049 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2050 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2053 | std::string temp; |
| 2054 | state->stats_.Update(obj_class->GetDescriptor(&temp), object_bytes); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2055 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 2056 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2057 | void DumpMethod(ArtMethod* method, ImageDumper* state, std::ostream& indent_os) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 2058 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2059 | DCHECK(method != nullptr); |
| 2060 | const auto image_pointer_size = |
| 2061 | InstructionSetPointerSize(state->oat_dumper_->GetOatInstructionSet()); |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 2062 | const void* quick_oat_code_begin = state->GetQuickOatCodeBegin(method); |
| 2063 | const void* quick_oat_code_end = state->GetQuickOatCodeEnd(method); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2064 | OatQuickMethodHeader* method_header = reinterpret_cast<OatQuickMethodHeader*>( |
| 2065 | reinterpret_cast<uintptr_t>(quick_oat_code_begin) - sizeof(OatQuickMethodHeader)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2066 | if (method->IsNative()) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2067 | if (!Runtime::Current()->GetClassLinker()->IsQuickGenericJniStub(quick_oat_code_begin)) { |
| 2068 | DCHECK(method_header->GetNativeGcMap() == nullptr) << PrettyMethod(method); |
| 2069 | DCHECK(method_header->GetMappingTable() == nullptr) << PrettyMethod(method); |
| 2070 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2071 | bool first_occurrence; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2072 | uint32_t quick_oat_code_size = state->GetQuickOatCodeSize(method); |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 2073 | state->ComputeOatSize(quick_oat_code_begin, &first_occurrence); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2074 | if (first_occurrence) { |
| 2075 | state->stats_.native_to_managed_code_bytes += quick_oat_code_size; |
| 2076 | } |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 2077 | if (quick_oat_code_begin != |
| 2078 | method->GetEntryPointFromQuickCompiledCodePtrSize(image_pointer_size)) { |
| 2079 | indent_os << StringPrintf("OAT CODE: %p\n", quick_oat_code_begin); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2080 | } |
| 2081 | } else if (method->IsAbstract() || method->IsCalleeSaveMethod() || |
| 2082 | method->IsResolutionMethod() || method->IsImtConflictMethod() || |
| 2083 | method->IsImtUnimplementedMethod() || method->IsClassInitializer()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2084 | } else { |
| 2085 | const DexFile::CodeItem* code_item = method->GetCodeItem(); |
| 2086 | size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2; |
| 2087 | state->stats_.dex_instruction_bytes += dex_instruction_bytes; |
| 2088 | |
| 2089 | bool first_occurrence; |
| 2090 | size_t gc_map_bytes = state->ComputeOatSize( |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2091 | method_header->GetNativeGcMap(), &first_occurrence); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2092 | if (first_occurrence) { |
| 2093 | state->stats_.gc_map_bytes += gc_map_bytes; |
| 2094 | } |
| 2095 | |
| 2096 | size_t pc_mapping_table_bytes = state->ComputeOatSize( |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2097 | method_header->GetMappingTable(), &first_occurrence); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2098 | if (first_occurrence) { |
| 2099 | state->stats_.pc_mapping_table_bytes += pc_mapping_table_bytes; |
| 2100 | } |
| 2101 | |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2102 | size_t vmap_table_bytes = 0u; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2103 | if (!method_header->IsOptimized()) { |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2104 | // Method compiled with the optimizing compiler have no vmap table. |
| 2105 | vmap_table_bytes = state->ComputeOatSize( |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2106 | method_header->GetVmapTable(), &first_occurrence); |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2107 | if (first_occurrence) { |
| 2108 | state->stats_.vmap_table_bytes += vmap_table_bytes; |
| 2109 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2112 | uint32_t quick_oat_code_size = state->GetQuickOatCodeSize(method); |
| 2113 | state->ComputeOatSize(quick_oat_code_begin, &first_occurrence); |
| 2114 | if (first_occurrence) { |
| 2115 | state->stats_.managed_code_bytes += quick_oat_code_size; |
| 2116 | if (method->IsConstructor()) { |
| 2117 | if (method->IsStatic()) { |
| 2118 | state->stats_.class_initializer_code_bytes += quick_oat_code_size; |
| 2119 | } else if (dex_instruction_bytes > kLargeConstructorDexBytes) { |
| 2120 | state->stats_.large_initializer_code_bytes += quick_oat_code_size; |
| 2121 | } |
| 2122 | } else if (dex_instruction_bytes > kLargeMethodDexBytes) { |
| 2123 | state->stats_.large_method_code_bytes += quick_oat_code_size; |
| 2124 | } |
| 2125 | } |
| 2126 | state->stats_.managed_code_bytes_ignoring_deduplication += quick_oat_code_size; |
| 2127 | |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 2128 | uint32_t method_access_flags = method->GetAccessFlags(); |
| 2129 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2130 | indent_os << StringPrintf("OAT CODE: %p-%p\n", quick_oat_code_begin, quick_oat_code_end); |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 2131 | indent_os << StringPrintf("SIZE: Dex Instructions=%zd GC=%zd Mapping=%zd AccessFlags=0x%x\n", |
| 2132 | dex_instruction_bytes, gc_map_bytes, pc_mapping_table_bytes, |
| 2133 | method_access_flags); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2134 | |
| 2135 | size_t total_size = dex_instruction_bytes + gc_map_bytes + pc_mapping_table_bytes + |
Vladimir Marko | 1463285 | 2015-08-17 12:07:23 +0100 | [diff] [blame] | 2136 | vmap_table_bytes + quick_oat_code_size + ArtMethod::Size(image_pointer_size); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2137 | |
| 2138 | double expansion = |
| 2139 | static_cast<double>(quick_oat_code_size) / static_cast<double>(dex_instruction_bytes); |
| 2140 | state->stats_.ComputeOutliers(total_size, expansion, method); |
| 2141 | } |
| 2142 | } |
| 2143 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2144 | std::set<const void*> already_seen_; |
| 2145 | // Compute the size of the given data within the oat file and whether this is the first time |
| 2146 | // this data has been requested |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2147 | size_t ComputeOatSize(const void* oat_data, bool* first_occurrence) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2148 | if (already_seen_.count(oat_data) == 0) { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2149 | *first_occurrence = true; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2150 | already_seen_.insert(oat_data); |
| 2151 | } else { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2152 | *first_occurrence = false; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2153 | } |
| 2154 | return oat_dumper_->ComputeSize(oat_data); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 2155 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2156 | |
| 2157 | public: |
| 2158 | struct Stats { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2159 | size_t oat_file_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2160 | size_t file_bytes; |
| 2161 | |
| 2162 | size_t header_bytes; |
| 2163 | size_t object_bytes; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2164 | size_t art_field_bytes; |
| 2165 | size_t art_method_bytes; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2166 | size_t dex_cache_arrays_bytes; |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2167 | size_t interned_strings_bytes; |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2168 | size_t class_table_bytes; |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2169 | size_t bitmap_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2170 | size_t alignment_bytes; |
| 2171 | |
| 2172 | size_t managed_code_bytes; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2173 | size_t managed_code_bytes_ignoring_deduplication; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2174 | size_t managed_to_native_code_bytes; |
| 2175 | size_t native_to_managed_code_bytes; |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2176 | size_t class_initializer_code_bytes; |
| 2177 | size_t large_initializer_code_bytes; |
| 2178 | size_t large_method_code_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2179 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2180 | size_t gc_map_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2181 | size_t pc_mapping_table_bytes; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2182 | size_t vmap_table_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2183 | |
| 2184 | size_t dex_instruction_bytes; |
| 2185 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2186 | std::vector<ArtMethod*> method_outlier; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2187 | std::vector<size_t> method_outlier_size; |
| 2188 | std::vector<double> method_outlier_expansion; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 2189 | std::vector<std::pair<std::string, size_t>> oat_dex_file_sizes; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2190 | |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 2191 | Stats() |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2192 | : oat_file_bytes(0), |
| 2193 | file_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2194 | header_bytes(0), |
| 2195 | object_bytes(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2196 | art_field_bytes(0), |
| 2197 | art_method_bytes(0), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2198 | dex_cache_arrays_bytes(0), |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2199 | interned_strings_bytes(0), |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2200 | class_table_bytes(0), |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2201 | bitmap_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2202 | alignment_bytes(0), |
| 2203 | managed_code_bytes(0), |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2204 | managed_code_bytes_ignoring_deduplication(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2205 | managed_to_native_code_bytes(0), |
| 2206 | native_to_managed_code_bytes(0), |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2207 | class_initializer_code_bytes(0), |
| 2208 | large_initializer_code_bytes(0), |
| 2209 | large_method_code_bytes(0), |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2210 | gc_map_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2211 | pc_mapping_table_bytes(0), |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2212 | vmap_table_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2213 | dex_instruction_bytes(0) {} |
| 2214 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2215 | struct SizeAndCount { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2216 | SizeAndCount(size_t bytes_in, size_t count_in) : bytes(bytes_in), count(count_in) {} |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2217 | size_t bytes; |
| 2218 | size_t count; |
| 2219 | }; |
| 2220 | typedef SafeMap<std::string, SizeAndCount> SizeAndCountTable; |
| 2221 | SizeAndCountTable sizes_and_counts; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2222 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2223 | void Update(const char* descriptor, size_t object_bytes_in) { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2224 | SizeAndCountTable::iterator it = sizes_and_counts.find(descriptor); |
| 2225 | if (it != sizes_and_counts.end()) { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2226 | it->second.bytes += object_bytes_in; |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2227 | it->second.count += 1; |
| 2228 | } else { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2229 | sizes_and_counts.Put(descriptor, SizeAndCount(object_bytes_in, 1)); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2230 | } |
| 2231 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2232 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2233 | double PercentOfOatBytes(size_t size) { |
| 2234 | return (static_cast<double>(size) / static_cast<double>(oat_file_bytes)) * 100; |
| 2235 | } |
| 2236 | |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2237 | double PercentOfFileBytes(size_t size) { |
| 2238 | return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100; |
| 2239 | } |
| 2240 | |
| 2241 | double PercentOfObjectBytes(size_t size) { |
| 2242 | return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100; |
| 2243 | } |
| 2244 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2245 | void ComputeOutliers(size_t total_size, double expansion, ArtMethod* method) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2246 | method_outlier_size.push_back(total_size); |
| 2247 | method_outlier_expansion.push_back(expansion); |
| 2248 | method_outlier.push_back(method); |
| 2249 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2250 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2251 | void DumpOutliers(std::ostream& os) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 2252 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2253 | size_t sum_of_sizes = 0; |
| 2254 | size_t sum_of_sizes_squared = 0; |
| 2255 | size_t sum_of_expansion = 0; |
| 2256 | size_t sum_of_expansion_squared = 0; |
| 2257 | size_t n = method_outlier_size.size(); |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2258 | if (n == 0) { |
| 2259 | return; |
| 2260 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2261 | for (size_t i = 0; i < n; i++) { |
| 2262 | size_t cur_size = method_outlier_size[i]; |
| 2263 | sum_of_sizes += cur_size; |
| 2264 | sum_of_sizes_squared += cur_size * cur_size; |
| 2265 | double cur_expansion = method_outlier_expansion[i]; |
| 2266 | sum_of_expansion += cur_expansion; |
| 2267 | sum_of_expansion_squared += cur_expansion * cur_expansion; |
| 2268 | } |
| 2269 | size_t size_mean = sum_of_sizes / n; |
| 2270 | size_t size_variance = (sum_of_sizes_squared - sum_of_sizes * size_mean) / (n - 1); |
| 2271 | double expansion_mean = sum_of_expansion / n; |
| 2272 | double expansion_variance = |
| 2273 | (sum_of_expansion_squared - sum_of_expansion * expansion_mean) / (n - 1); |
| 2274 | |
| 2275 | // Dump methods whose size is a certain number of standard deviations from the mean |
| 2276 | size_t dumped_values = 0; |
| 2277 | size_t skipped_values = 0; |
| 2278 | for (size_t i = 100; i > 0; i--) { // i is the current number of standard deviations |
| 2279 | size_t cur_size_variance = i * i * size_variance; |
| 2280 | bool first = true; |
| 2281 | for (size_t j = 0; j < n; j++) { |
| 2282 | size_t cur_size = method_outlier_size[j]; |
| 2283 | if (cur_size > size_mean) { |
| 2284 | size_t cur_var = cur_size - size_mean; |
| 2285 | cur_var = cur_var * cur_var; |
| 2286 | if (cur_var > cur_size_variance) { |
| 2287 | if (dumped_values > 20) { |
| 2288 | if (i == 1) { |
| 2289 | skipped_values++; |
| 2290 | } else { |
| 2291 | i = 2; // jump to counting for 1 standard deviation |
| 2292 | break; |
| 2293 | } |
| 2294 | } else { |
| 2295 | if (first) { |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2296 | os << "\nBig methods (size > " << i << " standard deviations the norm):\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2297 | first = false; |
| 2298 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2299 | os << PrettyMethod(method_outlier[j]) << " requires storage of " |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2300 | << PrettySize(cur_size) << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2301 | method_outlier_size[j] = 0; // don't consider this method again |
| 2302 | dumped_values++; |
| 2303 | } |
| 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | if (skipped_values > 0) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2309 | os << "... skipped " << skipped_values |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2310 | << " methods with size > 1 standard deviation from the norm\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2311 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2312 | os << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2313 | |
| 2314 | // Dump methods whose expansion is a certain number of standard deviations from the mean |
| 2315 | dumped_values = 0; |
| 2316 | skipped_values = 0; |
| 2317 | for (size_t i = 10; i > 0; i--) { // i is the current number of standard deviations |
| 2318 | double cur_expansion_variance = i * i * expansion_variance; |
| 2319 | bool first = true; |
| 2320 | for (size_t j = 0; j < n; j++) { |
| 2321 | double cur_expansion = method_outlier_expansion[j]; |
| 2322 | if (cur_expansion > expansion_mean) { |
| 2323 | size_t cur_var = cur_expansion - expansion_mean; |
| 2324 | cur_var = cur_var * cur_var; |
| 2325 | if (cur_var > cur_expansion_variance) { |
| 2326 | if (dumped_values > 20) { |
| 2327 | if (i == 1) { |
| 2328 | skipped_values++; |
| 2329 | } else { |
| 2330 | i = 2; // jump to counting for 1 standard deviation |
| 2331 | break; |
| 2332 | } |
| 2333 | } else { |
| 2334 | if (first) { |
| 2335 | os << "\nLarge expansion methods (size > " << i |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2336 | << " standard deviations the norm):\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2337 | first = false; |
| 2338 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2339 | os << PrettyMethod(method_outlier[j]) << " expanded code by " |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2340 | << cur_expansion << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2341 | method_outlier_expansion[j] = 0.0; // don't consider this method again |
| 2342 | dumped_values++; |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | if (skipped_values > 0) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2349 | os << "... skipped " << skipped_values |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2350 | << " methods with expansion > 1 standard deviation from the norm\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2351 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2352 | os << "\n" << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2353 | } |
| 2354 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2355 | void Dump(std::ostream& os, std::ostream& indent_os) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 2356 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2357 | { |
| 2358 | os << "art_file_bytes = " << PrettySize(file_bytes) << "\n\n" |
| 2359 | << "art_file_bytes = header_bytes + object_bytes + alignment_bytes\n"; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2360 | indent_os << StringPrintf("header_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2361 | "object_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2362 | "art_field_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2363 | "art_method_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2364 | "dex_cache_arrays_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2365 | "interned_string_bytes = %8zd (%2.0f%% of art file bytes)\n" |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2366 | "class_table_bytes = %8zd (%2.0f%% of art file bytes)\n" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2367 | "bitmap_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2368 | "alignment_bytes = %8zd (%2.0f%% of art file bytes)\n\n", |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2369 | header_bytes, PercentOfFileBytes(header_bytes), |
| 2370 | object_bytes, PercentOfFileBytes(object_bytes), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2371 | art_field_bytes, PercentOfFileBytes(art_field_bytes), |
| 2372 | art_method_bytes, PercentOfFileBytes(art_method_bytes), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2373 | dex_cache_arrays_bytes, |
| 2374 | PercentOfFileBytes(dex_cache_arrays_bytes), |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2375 | interned_strings_bytes, |
| 2376 | PercentOfFileBytes(interned_strings_bytes), |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2377 | class_table_bytes, PercentOfFileBytes(class_table_bytes), |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2378 | bitmap_bytes, PercentOfFileBytes(bitmap_bytes), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2379 | alignment_bytes, PercentOfFileBytes(alignment_bytes)) |
| 2380 | << std::flush; |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2381 | CHECK_EQ(file_bytes, |
| 2382 | header_bytes + object_bytes + art_field_bytes + art_method_bytes + |
| 2383 | dex_cache_arrays_bytes + interned_strings_bytes + class_table_bytes + |
| 2384 | bitmap_bytes + alignment_bytes); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2385 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2386 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2387 | os << "object_bytes breakdown:\n"; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2388 | size_t object_bytes_total = 0; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2389 | for (const auto& sizes_and_count : sizes_and_counts) { |
| 2390 | const std::string& descriptor(sizes_and_count.first); |
| 2391 | double average = static_cast<double>(sizes_and_count.second.bytes) / |
| 2392 | static_cast<double>(sizes_and_count.second.count); |
| 2393 | double percent = PercentOfObjectBytes(sizes_and_count.second.bytes); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2394 | os << StringPrintf("%32s %8zd bytes %6zd instances " |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2395 | "(%4.0f bytes/instance) %2.0f%% of object_bytes\n", |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2396 | descriptor.c_str(), sizes_and_count.second.bytes, |
| 2397 | sizes_and_count.second.count, average, percent); |
| 2398 | object_bytes_total += sizes_and_count.second.bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2399 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2400 | os << "\n" << std::flush; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2401 | CHECK_EQ(object_bytes, object_bytes_total); |
| 2402 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2403 | os << StringPrintf("oat_file_bytes = %8zd\n" |
| 2404 | "managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2405 | "managed_to_native_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2406 | "native_to_managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n" |
| 2407 | "class_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2408 | "large_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2409 | "large_method_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n", |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 2410 | oat_file_bytes, |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2411 | managed_code_bytes, |
| 2412 | PercentOfOatBytes(managed_code_bytes), |
| 2413 | managed_to_native_code_bytes, |
| 2414 | PercentOfOatBytes(managed_to_native_code_bytes), |
| 2415 | native_to_managed_code_bytes, |
| 2416 | PercentOfOatBytes(native_to_managed_code_bytes), |
| 2417 | class_initializer_code_bytes, |
| 2418 | PercentOfOatBytes(class_initializer_code_bytes), |
| 2419 | large_initializer_code_bytes, |
| 2420 | PercentOfOatBytes(large_initializer_code_bytes), |
| 2421 | large_method_code_bytes, |
| 2422 | PercentOfOatBytes(large_method_code_bytes)) |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2423 | << "DexFile sizes:\n"; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2424 | for (const std::pair<std::string, size_t>& oat_dex_file_size : oat_dex_file_sizes) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2425 | os << StringPrintf("%s = %zd (%2.0f%% of oat file bytes)\n", |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2426 | oat_dex_file_size.first.c_str(), oat_dex_file_size.second, |
| 2427 | PercentOfOatBytes(oat_dex_file_size.second)); |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2430 | os << "\n" << StringPrintf("gc_map_bytes = %7zd (%2.0f%% of oat file bytes)\n" |
| 2431 | "pc_mapping_table_bytes = %7zd (%2.0f%% of oat file bytes)\n" |
| 2432 | "vmap_table_bytes = %7zd (%2.0f%% of oat file bytes)\n\n", |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 2433 | gc_map_bytes, PercentOfOatBytes(gc_map_bytes), |
| 2434 | pc_mapping_table_bytes, PercentOfOatBytes(pc_mapping_table_bytes), |
| 2435 | vmap_table_bytes, PercentOfOatBytes(vmap_table_bytes)) |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2436 | << std::flush; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2437 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2438 | os << StringPrintf("dex_instruction_bytes = %zd\n", dex_instruction_bytes) |
| 2439 | << StringPrintf("managed_code_bytes expansion = %.2f (ignoring deduplication %.2f)\n\n", |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2440 | static_cast<double>(managed_code_bytes) / |
| 2441 | static_cast<double>(dex_instruction_bytes), |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2442 | static_cast<double>(managed_code_bytes_ignoring_deduplication) / |
Elliott Hughes | cf44e6f | 2012-05-24 19:42:18 -0700 | [diff] [blame] | 2443 | static_cast<double>(dex_instruction_bytes)) |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2444 | << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2445 | |
| 2446 | DumpOutliers(os); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2447 | } |
| 2448 | } stats_; |
| 2449 | |
| 2450 | private: |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2451 | enum { |
| 2452 | // Number of bytes for a constructor to be considered large. Based on the 1000 basic block |
| 2453 | // threshold, we assume 2 bytes per instruction and 2 instructions per block. |
| 2454 | kLargeConstructorDexBytes = 4000, |
| 2455 | // Number of bytes for a method to be considered large. Based on the 4000 basic block |
| 2456 | // threshold, we assume 2 bytes per instruction and 2 instructions per block. |
| 2457 | kLargeMethodDexBytes = 16000 |
| 2458 | }; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2459 | |
| 2460 | // For performance, use the *os_ directly for anything that doesn't need indentation |
| 2461 | // and prepare an indentation stream with default indentation 1. |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2462 | std::ostream* os_; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2463 | VariableIndentationOutputStream vios_; |
| 2464 | ScopedIndentation indent1_; |
| 2465 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 2466 | gc::space::ImageSpace& image_space_; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2467 | const ImageHeader& image_header_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 2468 | std::unique_ptr<OatDumper> oat_dumper_; |
Andreas Gampe | df2bb1f | 2015-05-04 18:25:23 -0700 | [diff] [blame] | 2469 | OatDumperOptions* oat_dumper_options_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2470 | std::set<mirror::Object*> dex_caches_; |
Elliott Hughes | d1bb4f6 | 2011-09-23 14:09:45 -0700 | [diff] [blame] | 2471 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2472 | DISALLOW_COPY_AND_ASSIGN(ImageDumper); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2473 | }; |
| 2474 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2475 | static int DumpImage(Runtime* runtime, OatDumperOptions* options, std::ostream* os) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2476 | // Dumping the image, no explicit class loader. |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 2477 | ScopedNullHandle<mirror::ClassLoader> null_class_loader; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2478 | options->class_loader_ = &null_class_loader; |
| 2479 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2480 | ScopedObjectAccess soa(Thread::Current()); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2481 | gc::Heap* heap = runtime->GetHeap(); |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2482 | std::vector<gc::space::ImageSpace*> image_spaces = heap->GetBootImageSpaces(); |
| 2483 | CHECK(!image_spaces.empty()); |
| 2484 | for (gc::space::ImageSpace* image_space : image_spaces) { |
| 2485 | const ImageHeader& image_header = image_space->GetImageHeader(); |
| 2486 | if (!image_header.IsValid()) { |
| 2487 | fprintf(stderr, "Invalid image header %s\n", image_space->GetImageLocation().c_str()); |
| 2488 | return EXIT_FAILURE; |
| 2489 | } |
| 2490 | |
| 2491 | ImageDumper image_dumper(os, *image_space, image_header, options); |
| 2492 | if (!image_dumper.Dump()) { |
| 2493 | return EXIT_FAILURE; |
| 2494 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2495 | } |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2496 | return EXIT_SUCCESS; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2499 | static int DumpOatWithRuntime(Runtime* runtime, OatFile* oat_file, OatDumperOptions* options, |
| 2500 | std::ostream* os) { |
| 2501 | CHECK(runtime != nullptr && oat_file != nullptr && options != nullptr); |
| 2502 | |
| 2503 | Thread* self = Thread::Current(); |
| 2504 | CHECK(self != nullptr); |
| 2505 | // Need well-known-classes. |
| 2506 | WellKnownClasses::Init(self->GetJniEnv()); |
| 2507 | |
| 2508 | // Need to register dex files to get a working dex cache. |
| 2509 | ScopedObjectAccess soa(self); |
| 2510 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 2511 | runtime->GetOatFileManager().RegisterOatFile(std::unique_ptr<const OatFile>(oat_file)); |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 2512 | std::vector<const DexFile*> class_path; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2513 | for (const OatFile::OatDexFile* odf : oat_file->GetOatDexFiles()) { |
| 2514 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 2515 | const DexFile* const dex_file = OpenDexFile(odf, &error_msg); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2516 | CHECK(dex_file != nullptr) << error_msg; |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 2517 | class_linker->RegisterDexFile(*dex_file, runtime->GetLinearAlloc()); |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 2518 | class_path.push_back(dex_file); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | // Need a class loader. |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2522 | // Fake that we're a compiler. |
Mathieu Chartier | 966878d | 2016-01-14 14:33:29 -0800 | [diff] [blame] | 2523 | jobject class_loader = class_linker->CreatePathClassLoader(self, class_path); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2524 | |
| 2525 | // Use the class loader while dumping. |
| 2526 | StackHandleScope<1> scope(self); |
| 2527 | Handle<mirror::ClassLoader> loader_handle = scope.NewHandle( |
| 2528 | soa.Decode<mirror::ClassLoader*>(class_loader)); |
| 2529 | options->class_loader_ = &loader_handle; |
| 2530 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2531 | OatDumper oat_dumper(*oat_file, *options); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2532 | bool success = oat_dumper.Dump(*os); |
| 2533 | return (success) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 2534 | } |
| 2535 | |
| 2536 | static int DumpOatWithoutRuntime(OatFile* oat_file, OatDumperOptions* options, std::ostream* os) { |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2537 | CHECK(oat_file != nullptr && options != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2538 | // No image = no class loader. |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 2539 | ScopedNullHandle<mirror::ClassLoader> null_class_loader; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2540 | options->class_loader_ = &null_class_loader; |
| 2541 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2542 | OatDumper oat_dumper(*oat_file, *options); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2543 | bool success = oat_dumper.Dump(*os); |
| 2544 | return (success) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 2545 | } |
| 2546 | |
| 2547 | static int DumpOat(Runtime* runtime, const char* oat_filename, OatDumperOptions* options, |
| 2548 | std::ostream* os) { |
| 2549 | std::string error_msg; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2550 | OatFile* oat_file = OatFile::Open(oat_filename, oat_filename, nullptr, nullptr, false, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 2551 | nullptr, &error_msg); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2552 | if (oat_file == nullptr) { |
| 2553 | fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); |
| 2554 | return EXIT_FAILURE; |
| 2555 | } |
| 2556 | |
| 2557 | if (runtime != nullptr) { |
| 2558 | return DumpOatWithRuntime(runtime, oat_file, options, os); |
| 2559 | } else { |
| 2560 | return DumpOatWithoutRuntime(oat_file, options, os); |
| 2561 | } |
| 2562 | } |
| 2563 | |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2564 | static int SymbolizeOat(const char* oat_filename, std::string& output_name, bool no_bits) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2565 | std::string error_msg; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2566 | OatFile* oat_file = OatFile::Open(oat_filename, oat_filename, nullptr, nullptr, false, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 2567 | nullptr, &error_msg); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2568 | if (oat_file == nullptr) { |
| 2569 | fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); |
| 2570 | return EXIT_FAILURE; |
| 2571 | } |
| 2572 | |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2573 | bool result; |
| 2574 | // Try to produce an ELF file of the same type. This is finicky, as we have used 32-bit ELF |
| 2575 | // files for 64-bit code in the past. |
| 2576 | if (Is64BitInstructionSet(oat_file->GetOatHeader().GetInstructionSet())) { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2577 | OatSymbolizer<ElfTypes64> oat_symbolizer(oat_file, output_name, no_bits); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2578 | result = oat_symbolizer.Symbolize(); |
| 2579 | } else { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2580 | OatSymbolizer<ElfTypes32> oat_symbolizer(oat_file, output_name, no_bits); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2581 | result = oat_symbolizer.Symbolize(); |
| 2582 | } |
| 2583 | if (!result) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2584 | fprintf(stderr, "Failed to symbolize\n"); |
| 2585 | return EXIT_FAILURE; |
| 2586 | } |
| 2587 | |
| 2588 | return EXIT_SUCCESS; |
| 2589 | } |
| 2590 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2591 | struct OatdumpArgs : public CmdlineArgs { |
| 2592 | protected: |
| 2593 | using Base = CmdlineArgs; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2594 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2595 | virtual ParseStatus ParseCustom(const StringPiece& option, |
| 2596 | std::string* error_msg) OVERRIDE { |
| 2597 | { |
| 2598 | ParseStatus base_parse = Base::ParseCustom(option, error_msg); |
| 2599 | if (base_parse != kParseUnknownArgument) { |
| 2600 | return base_parse; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2604 | if (option.starts_with("--oat-file=")) { |
| 2605 | oat_filename_ = option.substr(strlen("--oat-file=")).data(); |
| 2606 | } else if (option.starts_with("--image=")) { |
| 2607 | image_location_ = option.substr(strlen("--image=")).data(); |
| 2608 | } else if (option =="--dump:raw_mapping_table") { |
| 2609 | dump_raw_mapping_table_ = true; |
| 2610 | } else if (option == "--dump:raw_gc_map") { |
| 2611 | dump_raw_gc_map_ = true; |
| 2612 | } else if (option == "--no-dump:vmap") { |
| 2613 | dump_vmap_ = false; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 2614 | } else if (option =="--dump:code_info_stack_maps") { |
| 2615 | dump_code_info_stack_maps_ = true; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2616 | } else if (option == "--no-disassemble") { |
| 2617 | disassemble_code_ = false; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 2618 | } else if (option =="--header-only") { |
| 2619 | dump_header_only_ = true; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2620 | } else if (option.starts_with("--symbolize=")) { |
| 2621 | oat_filename_ = option.substr(strlen("--symbolize=")).data(); |
| 2622 | symbolize_ = true; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2623 | } else if (option.starts_with("--only-keep-debug")) { |
| 2624 | only_keep_debug_ = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2625 | } else if (option.starts_with("--class-filter=")) { |
| 2626 | class_filter_ = option.substr(strlen("--class-filter=")).data(); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2627 | } else if (option.starts_with("--method-filter=")) { |
| 2628 | method_filter_ = option.substr(strlen("--method-filter=")).data(); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2629 | } else if (option.starts_with("--list-classes")) { |
| 2630 | list_classes_ = true; |
| 2631 | } else if (option.starts_with("--list-methods")) { |
| 2632 | list_methods_ = true; |
| 2633 | } else if (option.starts_with("--export-dex-to=")) { |
| 2634 | export_dex_location_ = option.substr(strlen("--export-dex-to=")).data(); |
| 2635 | } else if (option.starts_with("--addr2instr=")) { |
| 2636 | if (!ParseUint(option.substr(strlen("--addr2instr=")).data(), &addr2instr_)) { |
| 2637 | *error_msg = "Address conversion failed"; |
| 2638 | return kParseError; |
| 2639 | } |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2640 | } else { |
| 2641 | return kParseUnknownArgument; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2644 | return kParseOk; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2647 | virtual ParseStatus ParseChecks(std::string* error_msg) OVERRIDE { |
| 2648 | // Infer boot image location from the image location if possible. |
| 2649 | if (boot_image_location_ == nullptr) { |
| 2650 | boot_image_location_ = image_location_; |
| 2651 | } |
| 2652 | |
| 2653 | // Perform the parent checks. |
| 2654 | ParseStatus parent_checks = Base::ParseChecks(error_msg); |
| 2655 | if (parent_checks != kParseOk) { |
| 2656 | return parent_checks; |
| 2657 | } |
| 2658 | |
| 2659 | // Perform our own checks. |
| 2660 | if (image_location_ == nullptr && oat_filename_ == nullptr) { |
| 2661 | *error_msg = "Either --image or --oat-file must be specified"; |
| 2662 | return kParseError; |
| 2663 | } else if (image_location_ != nullptr && oat_filename_ != nullptr) { |
| 2664 | *error_msg = "Either --image or --oat-file must be specified but not both"; |
| 2665 | return kParseError; |
| 2666 | } |
| 2667 | |
| 2668 | return kParseOk; |
| 2669 | } |
| 2670 | |
| 2671 | virtual std::string GetUsage() const { |
| 2672 | std::string usage; |
| 2673 | |
| 2674 | usage += |
| 2675 | "Usage: oatdump [options] ...\n" |
| 2676 | " Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art\n" |
| 2677 | " Example: adb shell oatdump --image=/system/framework/boot.art\n" |
| 2678 | "\n" |
| 2679 | // Either oat-file or image is required. |
| 2680 | " --oat-file=<file.oat>: specifies an input oat filename.\n" |
| 2681 | " Example: --oat-file=/system/framework/boot.oat\n" |
| 2682 | "\n" |
| 2683 | " --image=<file.art>: specifies an input image location.\n" |
| 2684 | " Example: --image=/system/framework/boot.art\n" |
| 2685 | "\n"; |
| 2686 | |
| 2687 | usage += Base::GetUsage(); |
| 2688 | |
| 2689 | usage += // Optional. |
| 2690 | " --dump:raw_mapping_table enables dumping of the mapping table.\n" |
| 2691 | " Example: --dump:raw_mapping_table\n" |
| 2692 | "\n" |
Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 2693 | " --dump:raw_gc_map enables dumping of the GC map.\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2694 | " Example: --dump:raw_gc_map\n" |
| 2695 | "\n" |
| 2696 | " --no-dump:vmap may be used to disable vmap dumping.\n" |
| 2697 | " Example: --no-dump:vmap\n" |
| 2698 | "\n" |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 2699 | " --dump:code_info_stack_maps enables dumping of stack maps in CodeInfo sections.\n" |
| 2700 | " Example: --dump:code_info_stack_maps\n" |
| 2701 | "\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2702 | " --no-disassemble may be used to disable disassembly.\n" |
| 2703 | " Example: --no-disassemble\n" |
| 2704 | "\n" |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 2705 | " --header-only may be used to print only the oat header.\n" |
| 2706 | " Example: --header-only\n" |
| 2707 | "\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2708 | " --list-classes may be used to list target file classes (can be used with filters).\n" |
| 2709 | " Example: --list-classes\n" |
| 2710 | " Example: --list-classes --class-filter=com.example.foo\n" |
| 2711 | "\n" |
| 2712 | " --list-methods may be used to list target file methods (can be used with filters).\n" |
| 2713 | " Example: --list-methods\n" |
| 2714 | " Example: --list-methods --class-filter=com.example --method-filter=foo\n" |
| 2715 | "\n" |
| 2716 | " --symbolize=<file.oat>: output a copy of file.oat with elf symbols included.\n" |
| 2717 | " Example: --symbolize=/system/framework/boot.oat\n" |
| 2718 | "\n" |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2719 | " --only-keep-debug<file.oat>: Modifies the behaviour of --symbolize so that\n" |
| 2720 | " .rodata and .text sections are omitted in the output file to save space.\n" |
| 2721 | " Example: --symbolize=/system/framework/boot.oat --only-keep-debug\n" |
| 2722 | "\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2723 | " --class-filter=<class name>: only dumps classes that contain the filter.\n" |
| 2724 | " Example: --class-filter=com.example.foo\n" |
| 2725 | "\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2726 | " --method-filter=<method name>: only dumps methods that contain the filter.\n" |
| 2727 | " Example: --method-filter=foo\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2728 | "\n" |
| 2729 | " --export-dex-to=<directory>: may be used to export oat embedded dex files.\n" |
| 2730 | " Example: --export-dex-to=/data/local/tmp\n" |
| 2731 | "\n" |
| 2732 | " --addr2instr=<address>: output matching method disassembled code from relative\n" |
| 2733 | " address (e.g. PC from crash dump)\n" |
| 2734 | " Example: --addr2instr=0x00001a3b\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2735 | "\n"; |
| 2736 | |
| 2737 | return usage; |
| 2738 | } |
| 2739 | |
| 2740 | public: |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2741 | const char* oat_filename_ = nullptr; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2742 | const char* class_filter_ = ""; |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 2743 | const char* method_filter_ = ""; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2744 | const char* image_location_ = nullptr; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2745 | std::string elf_filename_prefix_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2746 | bool dump_raw_mapping_table_ = false; |
| 2747 | bool dump_raw_gc_map_ = false; |
| 2748 | bool dump_vmap_ = true; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 2749 | bool dump_code_info_stack_maps_ = false; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2750 | bool disassemble_code_ = true; |
| 2751 | bool symbolize_ = false; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2752 | bool only_keep_debug_ = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2753 | bool list_classes_ = false; |
| 2754 | bool list_methods_ = false; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 2755 | bool dump_header_only_ = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2756 | uint32_t addr2instr_ = 0; |
| 2757 | const char* export_dex_location_ = nullptr; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2758 | }; |
| 2759 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2760 | struct OatdumpMain : public CmdlineMain<OatdumpArgs> { |
| 2761 | virtual bool NeedsRuntime() OVERRIDE { |
| 2762 | CHECK(args_ != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2763 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2764 | // If we are only doing the oat file, disable absolute_addresses. Keep them for image dumping. |
| 2765 | bool absolute_addresses = (args_->oat_filename_ == nullptr); |
| 2766 | |
| 2767 | oat_dumper_options_ = std::unique_ptr<OatDumperOptions>(new OatDumperOptions( |
| 2768 | args_->dump_raw_mapping_table_, |
| 2769 | args_->dump_raw_gc_map_, |
| 2770 | args_->dump_vmap_, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 2771 | args_->dump_code_info_stack_maps_, |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2772 | args_->disassemble_code_, |
| 2773 | absolute_addresses, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2774 | args_->class_filter_, |
| 2775 | args_->method_filter_, |
| 2776 | args_->list_classes_, |
| 2777 | args_->list_methods_, |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 2778 | args_->dump_header_only_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2779 | args_->export_dex_location_, |
| 2780 | args_->addr2instr_)); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2781 | |
| 2782 | return (args_->boot_image_location_ != nullptr || args_->image_location_ != nullptr) && |
| 2783 | !args_->symbolize_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2786 | virtual bool ExecuteWithoutRuntime() OVERRIDE { |
| 2787 | CHECK(args_ != nullptr); |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 2788 | CHECK(args_->oat_filename_ != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2789 | |
Mathieu Chartier | d424d08 | 2014-10-15 10:31:46 -0700 | [diff] [blame] | 2790 | MemMap::Init(); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2791 | |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 2792 | if (args_->symbolize_) { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame^] | 2793 | // ELF has special kind of section called SHT_NOBITS which allows us to create |
| 2794 | // sections which exist but their data is omitted from the ELF file to save space. |
| 2795 | // This is what "strip --only-keep-debug" does when it creates separate ELF file |
| 2796 | // with only debug data. We use it in similar way to exclude .rodata and .text. |
| 2797 | bool no_bits = args_->only_keep_debug_; |
| 2798 | return SymbolizeOat(args_->oat_filename_, args_->output_name_, no_bits) == EXIT_SUCCESS; |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 2799 | } else { |
| 2800 | return DumpOat(nullptr, |
| 2801 | args_->oat_filename_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2802 | oat_dumper_options_.get(), |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 2803 | args_->os_) == EXIT_SUCCESS; |
| 2804 | } |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2807 | virtual bool ExecuteWithRuntime(Runtime* runtime) { |
| 2808 | CHECK(args_ != nullptr); |
| 2809 | |
| 2810 | if (args_->oat_filename_ != nullptr) { |
| 2811 | return DumpOat(runtime, |
| 2812 | args_->oat_filename_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2813 | oat_dumper_options_.get(), |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2814 | args_->os_) == EXIT_SUCCESS; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2815 | } |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2816 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2817 | return DumpImage(runtime, oat_dumper_options_.get(), args_->os_) == EXIT_SUCCESS; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2820 | std::unique_ptr<OatDumperOptions> oat_dumper_options_; |
| 2821 | }; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2822 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 2823 | } // namespace art |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2824 | |
| 2825 | int main(int argc, char** argv) { |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 2826 | art::OatdumpMain main; |
| 2827 | return main.Main(argc, argv); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2828 | } |