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