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> |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 26 | #include <unordered_set> |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 29 | #include "android-base/stringprintf.h" |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 30 | #include "android-base/strings.h" |
| 31 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 32 | #include "arch/instruction_set_features.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 33 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | #include "art_method-inl.h" |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 35 | #include "base/stl_util.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 36 | #include "base/unix_file/fd_file.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 37 | #include "class_linker.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | #include "class_linker-inl.h" |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 39 | #include "debug/elf_debug_writer.h" |
| 40 | #include "debug/method_debug_info.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 41 | #include "dex_file-inl.h" |
Christina Wadsworth | bc233ac | 2016-06-20 15:01:32 -0700 | [diff] [blame] | 42 | #include "dex_instruction-inl.h" |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 43 | #include "disassembler.h" |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 44 | #include "elf_builder.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 45 | #include "gc/space/image_space.h" |
| 46 | #include "gc/space/large_object_space.h" |
| 47 | #include "gc/space/space-inl.h" |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 48 | #include "image-inl.h" |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 49 | #include "imtable-inl.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 50 | #include "indenter.h" |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 51 | #include "interpreter/unstarted_runtime.h" |
Vladimir Marko | 131980f | 2015-12-03 18:29:23 +0000 | [diff] [blame] | 52 | #include "linker/buffered_output_stream.h" |
| 53 | #include "linker/file_output_stream.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 54 | #include "mirror/array-inl.h" |
| 55 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 56 | #include "mirror/dex_cache-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | #include "mirror/object-inl.h" |
| 58 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 59 | #include "oat.h" |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 60 | #include "oat_file-inl.h" |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 61 | #include "oat_file_manager.h" |
Elliott Hughes | e5448b5 | 2012-01-18 16:44:06 -0800 | [diff] [blame] | 62 | #include "os.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 63 | #include "safe_map.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 64 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 9c05578 | 2016-07-14 09:24:30 +0000 | [diff] [blame] | 65 | #include "ScopedLocalRef.h" |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 66 | #include "stack_map.h" |
| 67 | #include "string_reference.h" |
Mathieu Chartier | c22c59e | 2014-02-24 15:16:06 -0800 | [diff] [blame] | 68 | #include "thread_list.h" |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 69 | #include "type_lookup_table.h" |
Nicolas Geoffray | 4acefd3 | 2016-10-24 13:14:58 +0100 | [diff] [blame] | 70 | #include "vdex_file.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 71 | #include "verifier/method_verifier.h" |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 72 | #include "verifier/verifier_deps.h" |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 73 | #include "well_known_classes.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 74 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 75 | #include <sys/stat.h> |
| 76 | #include "cmdline.h" |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 77 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 78 | namespace art { |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 79 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 80 | using android::base::StringPrintf; |
| 81 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 82 | const char* image_methods_descriptions_[] = { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 83 | "kResolutionMethod", |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 84 | "kImtConflictMethod", |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 85 | "kImtUnimplementedMethod", |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 86 | "kSaveAllCalleeSavesMethod", |
| 87 | "kSaveRefsOnlyMethod", |
| 88 | "kSaveRefsAndArgsMethod", |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 89 | "kSaveEverythingMethod", |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | const char* image_roots_descriptions_[] = { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 93 | "kDexCaches", |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 94 | "kClassRoots", |
Vladimir Marko | eca3eda | 2016-11-09 16:26:44 +0000 | [diff] [blame] | 95 | "kClassLoader", |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 98 | // Map is so that we don't allocate multiple dex files for the same OatDexFile. |
| 99 | static std::map<const OatFile::OatDexFile*, |
| 100 | std::unique_ptr<const DexFile>> opened_dex_files; |
| 101 | |
| 102 | const DexFile* OpenDexFile(const OatFile::OatDexFile* oat_dex_file, std::string* error_msg) { |
| 103 | DCHECK(oat_dex_file != nullptr); |
| 104 | auto it = opened_dex_files.find(oat_dex_file); |
| 105 | if (it != opened_dex_files.end()) { |
| 106 | return it->second.get(); |
| 107 | } |
| 108 | const DexFile* ret = oat_dex_file->OpenDexFile(error_msg).release(); |
| 109 | opened_dex_files.emplace(oat_dex_file, std::unique_ptr<const DexFile>(ret)); |
| 110 | return ret; |
| 111 | } |
| 112 | |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 113 | template <typename ElfTypes> |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 114 | class OatSymbolizer FINAL { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 115 | public: |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 116 | OatSymbolizer(const OatFile* oat_file, const std::string& output_name, bool no_bits) : |
| 117 | oat_file_(oat_file), |
| 118 | builder_(nullptr), |
| 119 | output_name_(output_name.empty() ? "symbolized.oat" : output_name), |
| 120 | no_bits_(no_bits) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 123 | bool Symbolize() { |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 124 | const InstructionSet isa = oat_file_->GetOatHeader().GetInstructionSet(); |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 125 | std::unique_ptr<const InstructionSetFeatures> features = InstructionSetFeatures::FromBitmap( |
David Srbecky | 5d81120 | 2016-03-08 13:21:22 +0000 | [diff] [blame] | 126 | isa, oat_file_->GetOatHeader().GetInstructionSetFeaturesBitmap()); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 127 | |
| 128 | File* elf_file = OS::CreateEmptyFile(output_name_.c_str()); |
| 129 | std::unique_ptr<BufferedOutputStream> output_stream( |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 130 | MakeUnique<BufferedOutputStream>(MakeUnique<FileOutputStream>(elf_file))); |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 131 | builder_.reset(new ElfBuilder<ElfTypes>(isa, features.get(), output_stream.get())); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 132 | |
| 133 | builder_->Start(); |
| 134 | |
| 135 | auto* rodata = builder_->GetRoData(); |
| 136 | auto* text = builder_->GetText(); |
| 137 | auto* bss = builder_->GetBss(); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 138 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 139 | const uint8_t* rodata_begin = oat_file_->Begin(); |
| 140 | const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset(); |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 141 | if (no_bits_) { |
| 142 | rodata->WriteNoBitsSection(rodata_size); |
| 143 | } else { |
| 144 | rodata->Start(); |
| 145 | rodata->WriteFully(rodata_begin, rodata_size); |
| 146 | rodata->End(); |
| 147 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 148 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 149 | const uint8_t* text_begin = oat_file_->Begin() + rodata_size; |
| 150 | const size_t text_size = oat_file_->End() - text_begin; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 151 | if (no_bits_) { |
| 152 | text->WriteNoBitsSection(text_size); |
| 153 | } else { |
| 154 | text->Start(); |
| 155 | text->WriteFully(text_begin, text_size); |
| 156 | text->End(); |
| 157 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 158 | |
| 159 | if (oat_file_->BssSize() != 0) { |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 160 | bss->WriteNoBitsSection(oat_file_->BssSize()); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Douglas Leung | 316a218 | 2015-09-17 15:26:25 -0700 | [diff] [blame] | 163 | if (isa == kMips || isa == kMips64) { |
| 164 | builder_->WriteMIPSabiflagsSection(); |
| 165 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 166 | builder_->PrepareDynamicSection(elf_file->GetPath(), |
| 167 | rodata_size, |
| 168 | text_size, |
| 169 | oat_file_->BssSize(), |
| 170 | oat_file_->BssRootsOffset()); |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 171 | builder_->WriteDynamicSection(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 172 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 173 | Walk(); |
| 174 | for (const auto& trampoline : debug::MakeTrampolineInfos(oat_file_->GetOatHeader())) { |
| 175 | method_debug_infos_.push_back(trampoline); |
| 176 | } |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 177 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 178 | debug::WriteDebugInfo(builder_.get(), |
| 179 | ArrayRef<const debug::MethodDebugInfo>(method_debug_infos_), |
| 180 | dwarf::DW_DEBUG_FRAME_FORMAT, |
| 181 | true /* write_oat_patches */); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 182 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 183 | builder_->End(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 184 | |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 185 | return builder_->Good(); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 186 | } |
| 187 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 188 | void Walk() { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 189 | std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file_->GetOatDexFiles(); |
| 190 | for (size_t i = 0; i < oat_dex_files.size(); i++) { |
| 191 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i]; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 192 | CHECK(oat_dex_file != nullptr); |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 193 | WalkOatDexFile(oat_dex_file); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 197 | void WalkOatDexFile(const OatFile::OatDexFile* oat_dex_file) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 198 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 199 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 200 | if (dex_file == nullptr) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | for (size_t class_def_index = 0; |
| 204 | class_def_index < dex_file->NumClassDefs(); |
| 205 | class_def_index++) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 206 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
| 207 | OatClassType type = oat_class.GetType(); |
| 208 | switch (type) { |
| 209 | case kOatClassAllCompiled: |
| 210 | case kOatClassSomeCompiled: |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 211 | WalkOatClass(oat_class, *dex_file, class_def_index); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 212 | break; |
| 213 | |
| 214 | case kOatClassNoneCompiled: |
| 215 | case kOatClassMax: |
| 216 | // Ignore. |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 222 | void WalkOatClass(const OatFile::OatClass& oat_class, |
| 223 | const DexFile& dex_file, |
| 224 | uint32_t class_def_index) { |
| 225 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 226 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 227 | if (class_data == nullptr) { // empty class such as a marker interface? |
| 228 | return; |
| 229 | } |
| 230 | // Note: even if this is an interface or a native class, we still have to walk it, as there |
| 231 | // might be a static initializer. |
| 232 | ClassDataItemIterator it(dex_file, class_data); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 233 | uint32_t class_method_idx = 0; |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 234 | for (; it.HasNextStaticField(); it.Next()) { /* skip */ } |
| 235 | for (; it.HasNextInstanceField(); it.Next()) { /* skip */ } |
| 236 | for (; it.HasNextDirectMethod() || it.HasNextVirtualMethod(); it.Next()) { |
| 237 | WalkOatMethod(oat_class.GetOatMethod(class_method_idx++), |
| 238 | dex_file, |
| 239 | class_def_index, |
| 240 | it.GetMemberIndex(), |
| 241 | it.GetMethodCodeItem(), |
| 242 | it.GetMethodAccessFlags()); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 243 | } |
| 244 | DCHECK(!it.HasNext()); |
| 245 | } |
| 246 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 247 | void WalkOatMethod(const OatFile::OatMethod& oat_method, |
| 248 | const DexFile& dex_file, |
| 249 | uint32_t class_def_index, |
| 250 | uint32_t dex_method_index, |
| 251 | const DexFile::CodeItem* code_item, |
| 252 | uint32_t method_access_flags) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 253 | if ((method_access_flags & kAccAbstract) != 0) { |
| 254 | // Abstract method, no code. |
| 255 | return; |
| 256 | } |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 257 | const OatHeader& oat_header = oat_file_->GetOatHeader(); |
| 258 | const OatQuickMethodHeader* method_header = oat_method.GetOatQuickMethodHeader(); |
| 259 | if (method_header == nullptr || method_header->GetCodeSize() == 0) { |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 260 | // No code. |
| 261 | return; |
| 262 | } |
| 263 | |
David Srbecky | a1b4c5f | 2016-03-31 18:17:59 +0100 | [diff] [blame] | 264 | uint32_t entry_point = oat_method.GetCodeOffset() - oat_header.GetExecutableOffset(); |
| 265 | // Clear Thumb2 bit. |
| 266 | const void* code_address = EntryPointToCodePointer(reinterpret_cast<void*>(entry_point)); |
| 267 | |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 268 | debug::MethodDebugInfo info = debug::MethodDebugInfo(); |
| 269 | info.trampoline_name = nullptr; |
| 270 | info.dex_file = &dex_file; |
| 271 | info.class_def_index = class_def_index; |
| 272 | info.dex_method_index = dex_method_index; |
| 273 | info.access_flags = method_access_flags; |
| 274 | info.code_item = code_item; |
| 275 | info.isa = oat_header.GetInstructionSet(); |
| 276 | info.deduped = !seen_offsets_.insert(oat_method.GetCodeOffset()).second; |
| 277 | info.is_native_debuggable = oat_header.IsNativeDebuggable(); |
| 278 | info.is_optimized = method_header->IsOptimized(); |
| 279 | info.is_code_address_text_relative = true; |
David Srbecky | a1b4c5f | 2016-03-31 18:17:59 +0100 | [diff] [blame] | 280 | info.code_address = reinterpret_cast<uintptr_t>(code_address); |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 281 | info.code_size = method_header->GetCodeSize(); |
| 282 | info.frame_size_in_bytes = method_header->GetFrameSizeInBytes(); |
| 283 | info.code_info = info.is_optimized ? method_header->GetOptimizedCodeInfoPtr() : nullptr; |
| 284 | info.cfi = ArrayRef<uint8_t>(); |
| 285 | method_debug_infos_.push_back(info); |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 288 | private: |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 289 | const OatFile* oat_file_; |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 290 | std::unique_ptr<ElfBuilder<ElfTypes> > builder_; |
David Srbecky | 5d95076 | 2016-03-07 20:47:29 +0000 | [diff] [blame] | 291 | std::vector<debug::MethodDebugInfo> method_debug_infos_; |
| 292 | std::unordered_set<uint32_t> seen_offsets_; |
Ian Rogers | 0279ebb | 2014-10-08 17:27:48 -0700 | [diff] [blame] | 293 | const std::string output_name_; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 294 | bool no_bits_; |
Andreas Gampe | 54fc26c | 2014-09-04 21:47:42 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 297 | class OatDumperOptions { |
| 298 | public: |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 299 | OatDumperOptions(bool dump_vmap, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 300 | bool dump_code_info_stack_maps, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 301 | bool disassemble_code, |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 302 | bool absolute_addresses, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 303 | const char* class_filter, |
| 304 | const char* method_filter, |
| 305 | bool list_classes, |
| 306 | bool list_methods, |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 307 | bool dump_header_only, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 308 | const char* export_dex_location, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 309 | const char* app_image, |
| 310 | const char* app_oat, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 311 | uint32_t addr2instr) |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 312 | : dump_vmap_(dump_vmap), |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 313 | dump_code_info_stack_maps_(dump_code_info_stack_maps), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 314 | disassemble_code_(disassemble_code), |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 315 | absolute_addresses_(absolute_addresses), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 316 | class_filter_(class_filter), |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 317 | method_filter_(method_filter), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 318 | list_classes_(list_classes), |
| 319 | list_methods_(list_methods), |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 320 | dump_header_only_(dump_header_only), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 321 | export_dex_location_(export_dex_location), |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 322 | app_image_(app_image), |
| 323 | app_oat_(app_oat), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 324 | addr2instr_(addr2instr), |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 325 | class_loader_(nullptr) {} |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 326 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 327 | const bool dump_vmap_; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 328 | const bool dump_code_info_stack_maps_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 329 | const bool disassemble_code_; |
| 330 | const bool absolute_addresses_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 331 | const char* const class_filter_; |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 332 | const char* const method_filter_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 333 | const bool list_classes_; |
| 334 | const bool list_methods_; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 335 | const bool dump_header_only_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 336 | const char* const export_dex_location_; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 337 | const char* const app_image_; |
| 338 | const char* const app_oat_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 339 | uint32_t addr2instr_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 340 | Handle<mirror::ClassLoader>* class_loader_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 341 | }; |
| 342 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 343 | class OatDumper { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 344 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 345 | OatDumper(const OatFile& oat_file, const OatDumperOptions& options) |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 346 | : oat_file_(oat_file), |
Elliott Hughes | a72ec82 | 2012-03-05 17:12:22 -0800 | [diff] [blame] | 347 | oat_dex_files_(oat_file.GetOatDexFiles()), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 348 | options_(options), |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 349 | resolved_addr2instr_(0), |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 350 | instruction_set_(oat_file_.GetOatHeader().GetInstructionSet()), |
| 351 | disassembler_(Disassembler::Create(instruction_set_, |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 352 | new DisassemblerOptions( |
| 353 | options_.absolute_addresses_, |
| 354 | oat_file.Begin(), |
| 355 | oat_file.End(), |
| 356 | true /* can_read_literals_ */, |
| 357 | Is64BitInstructionSet(instruction_set_) |
| 358 | ? &Thread::DumpThreadOffset<PointerSize::k64> |
| 359 | : &Thread::DumpThreadOffset<PointerSize::k32>))) { |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 360 | CHECK(options_.class_loader_ != nullptr); |
| 361 | CHECK(options_.class_filter_ != nullptr); |
| 362 | CHECK(options_.method_filter_ != nullptr); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 363 | AddAllOffsets(); |
| 364 | } |
| 365 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 366 | ~OatDumper() { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 367 | delete disassembler_; |
| 368 | } |
| 369 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 370 | InstructionSet GetInstructionSet() { |
| 371 | return instruction_set_; |
| 372 | } |
| 373 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 374 | bool Dump(std::ostream& os) { |
| 375 | bool success = true; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 376 | const OatHeader& oat_header = oat_file_.GetOatHeader(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 377 | |
| 378 | os << "MAGIC:\n"; |
| 379 | os << oat_header.GetMagic() << "\n\n"; |
| 380 | |
Jeff Hao | 4b07a6e | 2016-01-15 12:50:44 -0800 | [diff] [blame] | 381 | os << "LOCATION:\n"; |
| 382 | os << oat_file_.GetLocation() << "\n\n"; |
| 383 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 384 | os << "CHECKSUM:\n"; |
Elliott Hughes | ed2adb6 | 2012-02-29 14:41:01 -0800 | [diff] [blame] | 385 | os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 386 | |
Elliott Hughes | a72ec82 | 2012-03-05 17:12:22 -0800 | [diff] [blame] | 387 | os << "INSTRUCTION SET:\n"; |
| 388 | os << oat_header.GetInstructionSet() << "\n\n"; |
| 389 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 390 | { |
| 391 | std::unique_ptr<const InstructionSetFeatures> features( |
| 392 | InstructionSetFeatures::FromBitmap(oat_header.GetInstructionSet(), |
| 393 | oat_header.GetInstructionSetFeaturesBitmap())); |
| 394 | os << "INSTRUCTION SET FEATURES:\n"; |
| 395 | os << features->GetFeatureString() << "\n\n"; |
| 396 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 397 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 398 | os << "DEX FILE COUNT:\n"; |
| 399 | os << oat_header.GetDexFileCount() << "\n\n"; |
| 400 | |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 401 | #define DUMP_OAT_HEADER_OFFSET(label, offset) \ |
| 402 | os << label " OFFSET:\n"; \ |
| 403 | os << StringPrintf("0x%08x", oat_header.offset()); \ |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 404 | if (oat_header.offset() != 0 && options_.absolute_addresses_) { \ |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 405 | os << StringPrintf(" (%p)", oat_file_.Begin() + oat_header.offset()); \ |
| 406 | } \ |
| 407 | os << StringPrintf("\n\n"); |
| 408 | |
| 409 | DUMP_OAT_HEADER_OFFSET("EXECUTABLE", GetExecutableOffset); |
| 410 | DUMP_OAT_HEADER_OFFSET("INTERPRETER TO INTERPRETER BRIDGE", |
| 411 | GetInterpreterToInterpreterBridgeOffset); |
| 412 | DUMP_OAT_HEADER_OFFSET("INTERPRETER TO COMPILED CODE BRIDGE", |
| 413 | GetInterpreterToCompiledCodeBridgeOffset); |
| 414 | DUMP_OAT_HEADER_OFFSET("JNI DLSYM LOOKUP", |
| 415 | GetJniDlsymLookupOffset); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 416 | DUMP_OAT_HEADER_OFFSET("QUICK GENERIC JNI TRAMPOLINE", |
| 417 | GetQuickGenericJniTrampolineOffset); |
| 418 | DUMP_OAT_HEADER_OFFSET("QUICK IMT CONFLICT TRAMPOLINE", |
| 419 | GetQuickImtConflictTrampolineOffset); |
| 420 | DUMP_OAT_HEADER_OFFSET("QUICK RESOLUTION TRAMPOLINE", |
| 421 | GetQuickResolutionTrampolineOffset); |
| 422 | DUMP_OAT_HEADER_OFFSET("QUICK TO INTERPRETER BRIDGE", |
| 423 | GetQuickToInterpreterBridgeOffset); |
| 424 | #undef DUMP_OAT_HEADER_OFFSET |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 425 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 426 | os << "IMAGE PATCH DELTA:\n"; |
| 427 | os << StringPrintf("%d (0x%08x)\n\n", |
| 428 | oat_header.GetImagePatchDelta(), |
| 429 | oat_header.GetImagePatchDelta()); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 430 | |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 431 | os << "IMAGE FILE LOCATION OAT CHECKSUM:\n"; |
| 432 | os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatChecksum()); |
| 433 | |
| 434 | os << "IMAGE FILE LOCATION OAT BEGIN:\n"; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 435 | os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatDataBegin()); |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 436 | |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 437 | // Print the key-value store. |
| 438 | { |
| 439 | os << "KEY VALUE STORE:\n"; |
| 440 | size_t index = 0; |
| 441 | const char* key; |
| 442 | const char* value; |
| 443 | while (oat_header.GetStoreKeyValuePairByIndex(index, &key, &value)) { |
| 444 | os << key << " = " << value << "\n"; |
| 445 | index++; |
| 446 | } |
| 447 | os << "\n"; |
| 448 | } |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 449 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 450 | if (options_.absolute_addresses_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 451 | os << "BEGIN:\n"; |
| 452 | os << reinterpret_cast<const void*>(oat_file_.Begin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 453 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 454 | os << "END:\n"; |
| 455 | os << reinterpret_cast<const void*>(oat_file_.End()) << "\n\n"; |
| 456 | } |
| 457 | |
| 458 | os << "SIZE:\n"; |
| 459 | os << oat_file_.Size() << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 460 | |
| 461 | os << std::flush; |
| 462 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 463 | // If set, adjust relative address to be searched |
| 464 | if (options_.addr2instr_ != 0) { |
| 465 | resolved_addr2instr_ = options_.addr2instr_ + oat_header.GetExecutableOffset(); |
| 466 | os << "SEARCH ADDRESS (executable offset + input):\n"; |
| 467 | os << StringPrintf("0x%08x\n\n", resolved_addr2instr_); |
| 468 | } |
| 469 | |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 470 | // Dumping the dex file overview is compact enough to do even if header only. |
| 471 | DexFileData cumulative; |
| 472 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 473 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
| 474 | CHECK(oat_dex_file != nullptr); |
| 475 | std::string error_msg; |
| 476 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 477 | if (dex_file == nullptr) { |
| 478 | os << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() << "': " |
| 479 | << error_msg; |
| 480 | continue; |
| 481 | } |
| 482 | DexFileData data(*dex_file); |
| 483 | os << "Dex file data for " << dex_file->GetLocation() << "\n"; |
| 484 | data.Dump(os); |
| 485 | os << "\n"; |
| 486 | cumulative.Add(data); |
| 487 | } |
| 488 | os << "Cumulative dex file data\n"; |
| 489 | cumulative.Dump(os); |
| 490 | os << "\n"; |
| 491 | |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 492 | if (!options_.dump_header_only_) { |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 493 | VariableIndentationOutputStream vios(&os); |
| 494 | VdexFile::Header vdex_header = oat_file_.GetVdexFile()->GetHeader(); |
| 495 | if (vdex_header.IsValid()) { |
| 496 | std::string error_msg; |
| 497 | std::vector<const DexFile*> dex_files; |
| 498 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 499 | const DexFile* dex_file = OpenDexFile(oat_dex_files_[i], &error_msg); |
| 500 | if (dex_file == nullptr) { |
| 501 | os << "Error opening dex file: " << error_msg << std::endl; |
| 502 | return false; |
| 503 | } |
| 504 | dex_files.push_back(dex_file); |
| 505 | } |
| 506 | verifier::VerifierDeps deps(dex_files, oat_file_.GetVdexFile()->GetVerifierDepsData()); |
| 507 | deps.Dump(&vios); |
| 508 | } else { |
| 509 | os << "UNRECOGNIZED vdex file, magic " |
| 510 | << vdex_header.GetMagic() |
| 511 | << ", version " |
| 512 | << vdex_header.GetVersion() |
| 513 | << "\n"; |
| 514 | } |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 515 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 516 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
| 517 | CHECK(oat_dex_file != nullptr); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 518 | |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 519 | // If file export selected skip file analysis |
| 520 | if (options_.export_dex_location_) { |
| 521 | if (!ExportDexFile(os, *oat_dex_file)) { |
| 522 | success = false; |
| 523 | } |
| 524 | } else { |
| 525 | if (!DumpOatDexFile(os, *oat_dex_file)) { |
| 526 | success = false; |
| 527 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 528 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 529 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 530 | } |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 531 | |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 532 | { |
| 533 | os << "OAT FILE STATS:\n"; |
| 534 | VariableIndentationOutputStream vios(&os); |
| 535 | stats_.Dump(vios); |
| 536 | } |
| 537 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 538 | os << std::flush; |
| 539 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 542 | size_t ComputeSize(const void* oat_data) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 543 | if (reinterpret_cast<const uint8_t*>(oat_data) < oat_file_.Begin() || |
| 544 | reinterpret_cast<const uint8_t*>(oat_data) > oat_file_.End()) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 545 | return 0; // Address not in oat file |
| 546 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 547 | uintptr_t begin_offset = reinterpret_cast<uintptr_t>(oat_data) - |
| 548 | reinterpret_cast<uintptr_t>(oat_file_.Begin()); |
| 549 | auto it = offsets_.upper_bound(begin_offset); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 550 | CHECK(it != offsets_.end()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 551 | uintptr_t end_offset = *it; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 552 | return end_offset - begin_offset; |
| 553 | } |
| 554 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 555 | InstructionSet GetOatInstructionSet() { |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 556 | return oat_file_.GetOatHeader().GetInstructionSet(); |
| 557 | } |
| 558 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 559 | const void* GetQuickOatCode(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 560 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 561 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 562 | CHECK(oat_dex_file != nullptr); |
| 563 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 564 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 565 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 566 | LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() |
| 567 | << "': " << error_msg; |
| 568 | } else { |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 569 | const char* descriptor = m->GetDeclaringClassDescriptor(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 570 | const DexFile::ClassDef* class_def = |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 571 | OatDexFile::FindClassDef(*dex_file, descriptor, ComputeModifiedUtf8Hash(descriptor)); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 572 | if (class_def != nullptr) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 573 | uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 574 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 575 | size_t method_index = m->GetMethodIndex(); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 576 | return oat_class.GetOatMethod(method_index).GetQuickCode(); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 580 | return nullptr; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 583 | struct Stats { |
| 584 | enum ByteKind { |
| 585 | kByteKindCode, |
| 586 | kByteKindQuickMethodHeader, |
| 587 | kByteKindCodeInfoLocationCatalog, |
| 588 | kByteKindCodeInfoDexRegisterMap, |
| 589 | kByteKindCodeInfoInlineInfo, |
| 590 | kByteKindCodeInfoEncoding, |
| 591 | kByteKindCodeInfoOther, |
| 592 | kByteKindStackMapNativePc, |
| 593 | kByteKindStackMapDexPc, |
| 594 | kByteKindStackMapDexRegisterMap, |
| 595 | kByteKindStackMapInlineInfo, |
| 596 | kByteKindStackMapRegisterMask, |
| 597 | kByteKindStackMapMask, |
| 598 | kByteKindStackMapOther, |
| 599 | kByteKindCount, |
| 600 | kByteKindStackMapFirst = kByteKindCodeInfoOther, |
| 601 | kByteKindStackMapLast = kByteKindStackMapOther, |
| 602 | }; |
| 603 | int64_t bits[kByteKindCount] = {}; |
| 604 | // Since code has deduplication, seen tracks already seen pointers to avoid double counting |
| 605 | // deduplicated code and tables. |
| 606 | std::unordered_set<const void*> seen; |
| 607 | |
| 608 | // Returns true if it was newly added. |
| 609 | bool AddBitsIfUnique(ByteKind kind, int64_t count, const void* address) { |
| 610 | if (seen.insert(address).second == true) { |
| 611 | // True means the address was not already in the set. |
| 612 | AddBits(kind, count); |
| 613 | return true; |
| 614 | } |
| 615 | return false; |
| 616 | } |
| 617 | |
| 618 | void AddBits(ByteKind kind, int64_t count) { |
| 619 | bits[kind] += count; |
| 620 | } |
| 621 | |
| 622 | void Dump(VariableIndentationOutputStream& os) { |
| 623 | const int64_t sum = std::accumulate(bits, bits + kByteKindCount, 0u); |
| 624 | os.Stream() << "Dumping cumulative use of " << sum / kBitsPerByte << " accounted bytes\n"; |
| 625 | if (sum > 0) { |
| 626 | const int64_t stack_map_bits = std::accumulate(bits + kByteKindStackMapFirst, |
| 627 | bits + kByteKindStackMapLast + 1, |
| 628 | 0u); |
| 629 | Dump(os, "Code ", bits[kByteKindCode], sum); |
| 630 | Dump(os, "QuickMethodHeader ", bits[kByteKindQuickMethodHeader], sum); |
| 631 | Dump(os, "CodeInfoEncoding ", bits[kByteKindCodeInfoEncoding], sum); |
| 632 | Dump(os, "CodeInfoLocationCatalog ", bits[kByteKindCodeInfoLocationCatalog], sum); |
| 633 | Dump(os, "CodeInfoDexRegisterMap ", bits[kByteKindCodeInfoDexRegisterMap], sum); |
| 634 | Dump(os, "CodeInfoInlineInfo ", bits[kByteKindCodeInfoInlineInfo], sum); |
| 635 | Dump(os, "CodeInfoStackMap ", stack_map_bits, sum); |
| 636 | { |
| 637 | ScopedIndentation indent1(&os); |
| 638 | Dump(os, |
| 639 | "StackMapNativePc ", |
| 640 | bits[kByteKindStackMapNativePc], |
| 641 | stack_map_bits, |
| 642 | "stack map"); |
| 643 | Dump(os, |
| 644 | "StackMapDexPcEncoding ", |
| 645 | bits[kByteKindStackMapDexPc], |
| 646 | stack_map_bits, |
| 647 | "stack map"); |
| 648 | Dump(os, |
| 649 | "StackMapDexRegisterMap ", |
| 650 | bits[kByteKindStackMapDexRegisterMap], |
| 651 | stack_map_bits, |
| 652 | "stack map"); |
| 653 | Dump(os, |
| 654 | "StackMapInlineInfo ", |
| 655 | bits[kByteKindStackMapInlineInfo], |
| 656 | stack_map_bits, |
| 657 | "stack map"); |
| 658 | Dump(os, |
| 659 | "StackMapRegisterMaskEncoding ", |
| 660 | bits[kByteKindStackMapRegisterMask], |
| 661 | stack_map_bits, |
| 662 | "stack map"); |
| 663 | Dump(os, |
| 664 | "StackMapMask ", |
| 665 | bits[kByteKindStackMapMask], |
| 666 | stack_map_bits, |
| 667 | "stack map"); |
| 668 | Dump(os, |
| 669 | "StackMapOther ", |
| 670 | bits[kByteKindStackMapOther], |
| 671 | stack_map_bits, |
| 672 | "stack map"); |
| 673 | } |
| 674 | } |
| 675 | os.Stream() << "\n" << std::flush; |
| 676 | } |
| 677 | |
| 678 | private: |
| 679 | void Dump(VariableIndentationOutputStream& os, |
| 680 | const char* name, |
| 681 | int64_t size, |
| 682 | int64_t total, |
| 683 | const char* sum_of = "total") { |
| 684 | const double percent = (static_cast<double>(size) / static_cast<double>(total)) * 100; |
| 685 | os.Stream() << StringPrintf("%s = %8" PRId64 " (%2.0f%% of %s)\n", |
| 686 | name, |
| 687 | size / kBitsPerByte, |
| 688 | percent, |
| 689 | sum_of); |
| 690 | } |
| 691 | }; |
| 692 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 693 | private: |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 694 | void AddAllOffsets() { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 695 | // We don't know the length of the code for each method, but we need to know where to stop |
| 696 | // when disassembling. What we do know is that a region of code will be followed by some other |
| 697 | // region, so if we keep a sorted sequence of the start of each region, we can infer the length |
| 698 | // 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] | 699 | for (size_t i = 0; i < oat_dex_files_.size(); i++) { |
| 700 | const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 701 | CHECK(oat_dex_file != nullptr); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 702 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 703 | const DexFile* const dex_file = OpenDexFile(oat_dex_file, &error_msg); |
| 704 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 705 | LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation() |
| 706 | << "': " << error_msg; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 707 | continue; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 708 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 709 | offsets_.insert(reinterpret_cast<uintptr_t>(&dex_file->GetHeader())); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 710 | for (size_t class_def_index = 0; |
| 711 | class_def_index < dex_file->NumClassDefs(); |
| 712 | class_def_index++) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 713 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 714 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 715 | const uint8_t* class_data = dex_file->GetClassData(class_def); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 716 | if (class_data != nullptr) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 717 | ClassDataItemIterator it(*dex_file, class_data); |
| 718 | SkipAllFields(it); |
| 719 | uint32_t class_method_index = 0; |
| 720 | while (it.HasNextDirectMethod()) { |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 721 | AddOffsets(oat_class.GetOatMethod(class_method_index++)); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 722 | it.Next(); |
| 723 | } |
| 724 | while (it.HasNextVirtualMethod()) { |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 725 | AddOffsets(oat_class.GetOatMethod(class_method_index++)); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 726 | it.Next(); |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | // If the last thing in the file is code for a method, there won't be an offset for the "next" |
| 733 | // thing. Instead of having a special case in the upper_bound code, let's just add an entry |
| 734 | // for the end of the file. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 735 | offsets_.insert(oat_file_.Size()); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 738 | static uint32_t AlignCodeOffset(uint32_t maybe_thumb_offset) { |
| 739 | return maybe_thumb_offset & ~0x1; // TODO: Make this Thumb2 specific. |
| 740 | } |
| 741 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 742 | void AddOffsets(const OatFile::OatMethod& oat_method) { |
Brian Carlstrom | 95ba0dc | 2012-03-05 22:06:14 -0800 | [diff] [blame] | 743 | uint32_t code_offset = oat_method.GetCodeOffset(); |
| 744 | if (oat_file_.GetOatHeader().GetInstructionSet() == kThumb2) { |
| 745 | code_offset &= ~0x1; |
| 746 | } |
| 747 | offsets_.insert(code_offset); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 748 | offsets_.insert(oat_method.GetVmapTableOffset()); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 751 | // Dex file data, may be for multiple different dex files. |
| 752 | class DexFileData { |
| 753 | public: |
| 754 | DexFileData() {} |
| 755 | |
| 756 | explicit DexFileData(const DexFile& dex_file) |
| 757 | : num_string_ids_(dex_file.NumStringIds()), |
| 758 | num_method_ids_(dex_file.NumMethodIds()), |
| 759 | num_field_ids_(dex_file.NumFieldIds()), |
| 760 | num_type_ids_(dex_file.NumTypeIds()), |
| 761 | num_class_defs_(dex_file.NumClassDefs()) { |
| 762 | for (size_t class_def_index = 0; class_def_index < num_class_defs_; ++class_def_index) { |
| 763 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); |
| 764 | WalkClass(dex_file, class_def); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | void Add(const DexFileData& other) { |
| 769 | AddAll(unique_string_ids_from_code_, other.unique_string_ids_from_code_); |
| 770 | num_string_ids_from_code_ += other.num_string_ids_from_code_; |
| 771 | AddAll(dex_code_item_ptrs_, other.dex_code_item_ptrs_); |
| 772 | dex_code_bytes_ += other.dex_code_bytes_; |
| 773 | num_string_ids_ += other.num_string_ids_; |
| 774 | num_method_ids_ += other.num_method_ids_; |
| 775 | num_field_ids_ += other.num_field_ids_; |
| 776 | num_type_ids_ += other.num_type_ids_; |
| 777 | num_class_defs_ += other.num_class_defs_; |
| 778 | } |
| 779 | |
| 780 | void Dump(std::ostream& os) { |
| 781 | os << "Num string ids: " << num_string_ids_ << "\n"; |
| 782 | os << "Num method ids: " << num_method_ids_ << "\n"; |
| 783 | os << "Num field ids: " << num_field_ids_ << "\n"; |
| 784 | os << "Num type ids: " << num_type_ids_ << "\n"; |
| 785 | os << "Num class defs: " << num_class_defs_ << "\n"; |
| 786 | os << "Unique strings loaded from dex code: " << unique_string_ids_from_code_.size() << "\n"; |
| 787 | os << "Total strings loaded from dex code: " << num_string_ids_from_code_ << "\n"; |
| 788 | os << "Number of unique dex code items: " << dex_code_item_ptrs_.size() << "\n"; |
| 789 | os << "Total number of dex code bytes: " << dex_code_bytes_ << "\n"; |
| 790 | } |
| 791 | |
| 792 | private: |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 793 | // All of the elements from one container to another. |
| 794 | template <typename Dest, typename Src> |
| 795 | static void AddAll(Dest& dest, const Src& src) { |
| 796 | dest.insert(src.begin(), src.end()); |
| 797 | } |
| 798 | |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 799 | void WalkClass(const DexFile& dex_file, const DexFile::ClassDef& class_def) { |
| 800 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
| 801 | if (class_data == nullptr) { // empty class such as a marker interface? |
| 802 | return; |
| 803 | } |
| 804 | ClassDataItemIterator it(dex_file, class_data); |
| 805 | SkipAllFields(it); |
| 806 | while (it.HasNextDirectMethod()) { |
| 807 | WalkCodeItem(dex_file, it.GetMethodCodeItem()); |
| 808 | it.Next(); |
| 809 | } |
| 810 | while (it.HasNextVirtualMethod()) { |
| 811 | WalkCodeItem(dex_file, it.GetMethodCodeItem()); |
| 812 | it.Next(); |
| 813 | } |
| 814 | DCHECK(!it.HasNext()); |
| 815 | } |
| 816 | |
| 817 | void WalkCodeItem(const DexFile& dex_file, const DexFile::CodeItem* code_item) { |
| 818 | if (code_item == nullptr) { |
| 819 | return; |
| 820 | } |
| 821 | const size_t code_item_size = code_item->insns_size_in_code_units_; |
| 822 | const uint16_t* code_ptr = code_item->insns_; |
| 823 | const uint16_t* code_end = code_item->insns_ + code_item_size; |
| 824 | |
| 825 | // If we inserted a new dex code item pointer, add to total code bytes. |
| 826 | if (dex_code_item_ptrs_.insert(code_ptr).second) { |
| 827 | dex_code_bytes_ += code_item_size * sizeof(code_ptr[0]); |
| 828 | } |
| 829 | |
| 830 | while (code_ptr < code_end) { |
| 831 | const Instruction* inst = Instruction::At(code_ptr); |
| 832 | switch (inst->Opcode()) { |
| 833 | case Instruction::CONST_STRING: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 834 | const dex::StringIndex string_index(inst->VRegB_21c()); |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 835 | unique_string_ids_from_code_.insert(StringReference(&dex_file, string_index)); |
| 836 | ++num_string_ids_from_code_; |
| 837 | break; |
| 838 | } |
| 839 | case Instruction::CONST_STRING_JUMBO: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 840 | const dex::StringIndex string_index(inst->VRegB_31c()); |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 841 | unique_string_ids_from_code_.insert(StringReference(&dex_file, string_index)); |
| 842 | ++num_string_ids_from_code_; |
| 843 | break; |
| 844 | } |
| 845 | default: |
| 846 | break; |
| 847 | } |
| 848 | |
| 849 | code_ptr += inst->SizeInCodeUnits(); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | // Unique string ids loaded from dex code. |
| 854 | std::set<StringReference, StringReferenceComparator> unique_string_ids_from_code_; |
| 855 | |
| 856 | // Total string ids loaded from dex code. |
| 857 | size_t num_string_ids_from_code_ = 0; |
| 858 | |
| 859 | // Unique code pointers. |
| 860 | std::set<const void*> dex_code_item_ptrs_; |
| 861 | |
| 862 | // Total "unique" dex code bytes. |
| 863 | size_t dex_code_bytes_ = 0; |
| 864 | |
| 865 | // Other dex ids. |
| 866 | size_t num_string_ids_ = 0; |
| 867 | size_t num_method_ids_ = 0; |
| 868 | size_t num_field_ids_ = 0; |
| 869 | size_t num_type_ids_ = 0; |
| 870 | size_t num_class_defs_ = 0; |
| 871 | }; |
| 872 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 873 | bool DumpOatDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { |
| 874 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 875 | bool stop_analysis = false; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 876 | os << "OatDexFile:\n"; |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 877 | os << StringPrintf("location: %s\n", oat_dex_file.GetDexFileLocation().c_str()); |
Elliott Hughes | ed2adb6 | 2012-02-29 14:41:01 -0800 | [diff] [blame] | 878 | os << StringPrintf("checksum: 0x%08x\n", oat_dex_file.GetDexFileLocationChecksum()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 879 | |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 880 | const uint8_t* const oat_file_begin = oat_dex_file.GetOatFile()->Begin(); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 881 | const uint8_t* const vdex_file_begin = oat_dex_file.GetOatFile()->DexBegin(); |
| 882 | |
| 883 | // Print data range of the dex file embedded inside the corresponding vdex file. |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 884 | const uint8_t* const dex_file_pointer = oat_dex_file.GetDexFilePointer(); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 885 | uint32_t dex_offset = dchecked_integral_cast<uint32_t>(dex_file_pointer - vdex_file_begin); |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 886 | os << StringPrintf("dex-file: 0x%08x..0x%08x\n", |
| 887 | dex_offset, |
| 888 | dchecked_integral_cast<uint32_t>(dex_offset + oat_dex_file.FileSize() - 1)); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 889 | |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 890 | // Create the dex file early. A lot of print-out things depend on it. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 891 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 892 | const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); |
| 893 | if (dex_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 894 | os << "NOT FOUND: " << error_msg << "\n\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 895 | os << std::flush; |
| 896 | return false; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 897 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 898 | |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 899 | // Print lookup table, if it exists. |
| 900 | if (oat_dex_file.GetLookupTableData() != nullptr) { |
| 901 | uint32_t table_offset = dchecked_integral_cast<uint32_t>( |
| 902 | oat_dex_file.GetLookupTableData() - oat_file_begin); |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 903 | uint32_t table_size = TypeLookupTable::RawDataLength(dex_file->NumClassDefs()); |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 904 | os << StringPrintf("type-table: 0x%08x..0x%08x\n", |
| 905 | table_offset, |
| 906 | table_offset + table_size - 1); |
| 907 | } |
| 908 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 909 | VariableIndentationOutputStream vios(&os); |
| 910 | ScopedIndentation indent1(&vios); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 911 | for (size_t class_def_index = 0; |
| 912 | class_def_index < dex_file->NumClassDefs(); |
| 913 | class_def_index++) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 914 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
| 915 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 916 | |
| 917 | // TODO: Support regex |
| 918 | if (DescriptorToDot(descriptor).find(options_.class_filter_) == std::string::npos) { |
| 919 | continue; |
| 920 | } |
| 921 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 922 | uint32_t oat_class_offset = oat_dex_file.GetOatClassOffset(class_def_index); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 923 | const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 924 | os << StringPrintf("%zd: %s (offset=0x%08x) (type_idx=%d)", |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 925 | class_def_index, descriptor, oat_class_offset, class_def.class_idx_.index_) |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 926 | << " (" << oat_class.GetStatus() << ")" |
| 927 | << " (" << oat_class.GetType() << ")\n"; |
| 928 | // TODO: include bitmap here if type is kOatClassSomeCompiled? |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 929 | if (options_.list_classes_) { |
| 930 | continue; |
| 931 | } |
| 932 | if (!DumpOatClass(&vios, oat_class, *dex_file, class_def, &stop_analysis)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 933 | success = false; |
| 934 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 935 | if (stop_analysis) { |
| 936 | os << std::flush; |
| 937 | return success; |
| 938 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 939 | } |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 940 | os << "\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 941 | os << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 942 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 945 | bool ExportDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) { |
| 946 | std::string error_msg; |
| 947 | std::string dex_file_location = oat_dex_file.GetDexFileLocation(); |
| 948 | |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 949 | const DexFile* const dex_file = OpenDexFile(&oat_dex_file, &error_msg); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 950 | if (dex_file == nullptr) { |
| 951 | os << "Failed to open dex file '" << dex_file_location << "': " << error_msg; |
| 952 | return false; |
| 953 | } |
| 954 | size_t fsize = oat_dex_file.FileSize(); |
| 955 | |
| 956 | // Some quick checks just in case |
| 957 | if (fsize == 0 || fsize < sizeof(DexFile::Header)) { |
| 958 | os << "Invalid dex file\n"; |
| 959 | return false; |
| 960 | } |
| 961 | |
| 962 | // Verify output directory exists |
| 963 | if (!OS::DirectoryExists(options_.export_dex_location_)) { |
| 964 | // TODO: Extend OS::DirectoryExists if symlink support is required |
| 965 | os << options_.export_dex_location_ << " output directory not found or symlink\n"; |
| 966 | return false; |
| 967 | } |
| 968 | |
| 969 | // Beautify path names |
| 970 | if (dex_file_location.size() > PATH_MAX || dex_file_location.size() <= 0) { |
| 971 | return false; |
| 972 | } |
| 973 | |
| 974 | std::string dex_orig_name; |
| 975 | size_t dex_orig_pos = dex_file_location.rfind('/'); |
| 976 | if (dex_orig_pos == std::string::npos) |
| 977 | dex_orig_name = dex_file_location; |
| 978 | else |
| 979 | dex_orig_name = dex_file_location.substr(dex_orig_pos + 1); |
| 980 | |
| 981 | // A more elegant approach to efficiently name user installed apps is welcome |
| 982 | if (dex_orig_name.size() == 8 && !dex_orig_name.compare("base.apk")) { |
| 983 | dex_file_location.erase(dex_orig_pos, strlen("base.apk") + 1); |
| 984 | size_t apk_orig_pos = dex_file_location.rfind('/'); |
| 985 | if (apk_orig_pos != std::string::npos) { |
| 986 | dex_orig_name = dex_file_location.substr(++apk_orig_pos); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | std::string out_dex_path(options_.export_dex_location_); |
| 991 | if (out_dex_path.back() != '/') { |
| 992 | out_dex_path.append("/"); |
| 993 | } |
| 994 | out_dex_path.append(dex_orig_name); |
| 995 | out_dex_path.append("_export.dex"); |
| 996 | if (out_dex_path.length() > PATH_MAX) { |
| 997 | return false; |
| 998 | } |
| 999 | |
| 1000 | std::unique_ptr<File> file(OS::CreateEmptyFile(out_dex_path.c_str())); |
| 1001 | if (file.get() == nullptr) { |
| 1002 | os << "Failed to open output dex file " << out_dex_path; |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
| 1006 | if (!file->WriteFully(dex_file->Begin(), fsize)) { |
| 1007 | os << "Failed to write dex file"; |
| 1008 | file->Erase(); |
| 1009 | return false; |
| 1010 | } |
| 1011 | |
| 1012 | if (file->FlushCloseOrErase() != 0) { |
| 1013 | os << "Flush and close failed"; |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
| 1017 | os << StringPrintf("Dex file exported at %s (%zd bytes)\n", out_dex_path.c_str(), fsize); |
| 1018 | os << std::flush; |
| 1019 | |
| 1020 | return true; |
| 1021 | } |
| 1022 | |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1023 | static void SkipAllFields(ClassDataItemIterator& it) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1024 | while (it.HasNextStaticField()) { |
| 1025 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1026 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1027 | while (it.HasNextInstanceField()) { |
| 1028 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1029 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1030 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1031 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1032 | bool DumpOatClass(VariableIndentationOutputStream* vios, |
| 1033 | const OatFile::OatClass& oat_class, const DexFile& dex_file, |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 1034 | const DexFile::ClassDef& class_def, bool* stop_analysis) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1035 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1036 | bool addr_found = false; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1037 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1038 | if (class_data == nullptr) { // empty class such as a marker interface? |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1039 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1040 | return success; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1041 | } |
| 1042 | ClassDataItemIterator it(dex_file, class_data); |
| 1043 | SkipAllFields(it); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1044 | uint32_t class_method_index = 0; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1045 | while (it.HasNextDirectMethod()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1046 | if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1047 | it.GetMemberIndex(), it.GetMethodCodeItem(), |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 1048 | it.GetRawMemberAccessFlags(), &addr_found)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1049 | success = false; |
| 1050 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1051 | if (addr_found) { |
| 1052 | *stop_analysis = true; |
| 1053 | return success; |
| 1054 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1055 | class_method_index++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1056 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1057 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1058 | while (it.HasNextVirtualMethod()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1059 | if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1060 | it.GetMemberIndex(), it.GetMethodCodeItem(), |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 1061 | it.GetRawMemberAccessFlags(), &addr_found)) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1062 | success = false; |
| 1063 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1064 | if (addr_found) { |
| 1065 | *stop_analysis = true; |
| 1066 | return success; |
| 1067 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1068 | class_method_index++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1069 | it.Next(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1070 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1071 | DCHECK(!it.HasNext()); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1072 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1073 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1074 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1075 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1076 | static constexpr uint32_t kPrologueBytes = 16; |
| 1077 | |
| 1078 | // When this was picked, the largest arm method was 55,256 bytes and arm64 was 50,412 bytes. |
| 1079 | static constexpr uint32_t kMaxCodeSize = 100 * 1000; |
| 1080 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1081 | bool DumpOatMethod(VariableIndentationOutputStream* vios, |
| 1082 | const DexFile::ClassDef& class_def, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 1083 | uint32_t class_method_index, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1084 | const OatFile::OatClass& oat_class, const DexFile& dex_file, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1085 | uint32_t dex_method_idx, const DexFile::CodeItem* code_item, |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 1086 | uint32_t method_access_flags, bool* addr_found) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1087 | bool success = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1088 | |
| 1089 | // TODO: Support regex |
| 1090 | std::string method_name = dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx)); |
| 1091 | if (method_name.find(options_.method_filter_) == std::string::npos) { |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 1092 | return success; |
| 1093 | } |
| 1094 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1095 | std::string pretty_method = dex_file.PrettyMethod(dex_method_idx, true); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1096 | vios->Stream() << StringPrintf("%d: %s (dex_method_idx=%d)\n", |
| 1097 | class_method_index, pretty_method.c_str(), |
| 1098 | dex_method_idx); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1099 | if (options_.list_methods_) return success; |
| 1100 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1101 | uint32_t oat_method_offsets_offset = oat_class.GetOatMethodOffsetsOffset(class_method_index); |
| 1102 | const OatMethodOffsets* oat_method_offsets = oat_class.GetOatMethodOffsets(class_method_index); |
| 1103 | const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_index); |
| 1104 | uint32_t code_offset = oat_method.GetCodeOffset(); |
| 1105 | uint32_t code_size = oat_method.GetQuickCodeSize(); |
| 1106 | if (resolved_addr2instr_ != 0) { |
| 1107 | if (resolved_addr2instr_ > code_offset + code_size) { |
| 1108 | return success; |
| 1109 | } else { |
| 1110 | *addr_found = true; // stop analyzing file at next iteration |
| 1111 | } |
| 1112 | } |
| 1113 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1114 | // Everything below is indented at least once. |
| 1115 | ScopedIndentation indent1(vios); |
| 1116 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1117 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1118 | vios->Stream() << "DEX CODE:\n"; |
| 1119 | ScopedIndentation indent2(vios); |
| 1120 | DumpDexCode(vios->Stream(), dex_file, code_item); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1121 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1122 | |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1123 | std::unique_ptr<StackHandleScope<1>> hs; |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1124 | std::unique_ptr<verifier::MethodVerifier> verifier; |
| 1125 | if (Runtime::Current() != nullptr) { |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1126 | // We need to have the handle scope stay live until after the verifier since the verifier has |
| 1127 | // a handle to the dex cache from hs. |
| 1128 | hs.reset(new StackHandleScope<1>(Thread::Current())); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1129 | vios->Stream() << "VERIFIER TYPE ANALYSIS:\n"; |
| 1130 | ScopedIndentation indent2(vios); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1131 | verifier.reset(DumpVerifier(vios, hs.get(), |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1132 | dex_method_idx, &dex_file, class_def, code_item, |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1133 | method_access_flags)); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1134 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1135 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1136 | vios->Stream() << "OatMethodOffsets "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1137 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1138 | vios->Stream() << StringPrintf("%p ", oat_method_offsets); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1139 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1140 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", oat_method_offsets_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1141 | if (oat_method_offsets_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1142 | vios->Stream() << StringPrintf( |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1143 | "WARNING: oat method offsets offset 0x%08x is past end of file 0x%08zx.\n", |
| 1144 | oat_method_offsets_offset, oat_file_.Size()); |
| 1145 | // 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] | 1146 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1147 | return false; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1148 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1149 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1150 | ScopedIndentation indent2(vios); |
| 1151 | vios->Stream() << StringPrintf("code_offset: 0x%08x ", code_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1152 | uint32_t aligned_code_begin = AlignCodeOffset(oat_method.GetCodeOffset()); |
| 1153 | if (aligned_code_begin > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1154 | vios->Stream() << StringPrintf("WARNING: " |
| 1155 | "code offset 0x%08x is past end of file 0x%08zx.\n", |
| 1156 | aligned_code_begin, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1157 | success = false; |
| 1158 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1159 | vios->Stream() << "\n"; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1160 | } |
| 1161 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1162 | vios->Stream() << "OatQuickMethodHeader "; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1163 | uint32_t method_header_offset = oat_method.GetOatQuickMethodHeaderOffset(); |
| 1164 | const OatQuickMethodHeader* method_header = oat_method.GetOatQuickMethodHeader(); |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 1165 | stats_.AddBitsIfUnique(Stats::kByteKindQuickMethodHeader, |
| 1166 | sizeof(*method_header) * kBitsPerByte, |
| 1167 | method_header); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1168 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1169 | vios->Stream() << StringPrintf("%p ", method_header); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1170 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1171 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", method_header_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1172 | if (method_header_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1173 | vios->Stream() << StringPrintf( |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1174 | "WARNING: oat quick method header offset 0x%08x is past end of file 0x%08zx.\n", |
| 1175 | method_header_offset, oat_file_.Size()); |
| 1176 | // 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] | 1177 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1178 | return false; |
| 1179 | } |
| 1180 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1181 | ScopedIndentation indent2(vios); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1182 | vios->Stream() << "vmap_table: "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1183 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1184 | vios->Stream() << StringPrintf("%p ", oat_method.GetVmapTable()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1185 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1186 | uint32_t vmap_table_offset = method_header == |
| 1187 | nullptr ? 0 : method_header->GetVmapTableOffset(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1188 | vios->Stream() << StringPrintf("(offset=0x%08x)\n", vmap_table_offset); |
Nicolas Geoffray | 4acefd3 | 2016-10-24 13:14:58 +0100 | [diff] [blame] | 1189 | |
| 1190 | size_t vmap_table_offset_limit = |
| 1191 | (kIsVdexEnabled && IsMethodGeneratedByDexToDexCompiler(oat_method, code_item)) |
| 1192 | ? oat_file_.GetVdexFile()->Size() |
| 1193 | : method_header->GetCode() - oat_file_.Begin(); |
| 1194 | if (vmap_table_offset >= vmap_table_offset_limit) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1195 | vios->Stream() << StringPrintf("WARNING: " |
| 1196 | "vmap table offset 0x%08x is past end of file 0x%08zx. " |
| 1197 | "vmap table offset was loaded from offset 0x%08x.\n", |
Nicolas Geoffray | 4acefd3 | 2016-10-24 13:14:58 +0100 | [diff] [blame] | 1198 | vmap_table_offset, |
| 1199 | vmap_table_offset_limit, |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1200 | oat_method.GetVmapTableOffsetOffset()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1201 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1202 | } else if (options_.dump_vmap_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1203 | DumpVmapData(vios, oat_method, code_item); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1204 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1205 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1206 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1207 | vios->Stream() << "QuickMethodFrameInfo\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1208 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1209 | ScopedIndentation indent2(vios); |
| 1210 | vios->Stream() |
| 1211 | << StringPrintf("frame_size_in_bytes: %zd\n", oat_method.GetFrameSizeInBytes()); |
| 1212 | vios->Stream() << StringPrintf("core_spill_mask: 0x%08x ", oat_method.GetCoreSpillMask()); |
| 1213 | DumpSpillMask(vios->Stream(), oat_method.GetCoreSpillMask(), false); |
| 1214 | vios->Stream() << "\n"; |
| 1215 | vios->Stream() << StringPrintf("fp_spill_mask: 0x%08x ", oat_method.GetFpSpillMask()); |
| 1216 | DumpSpillMask(vios->Stream(), oat_method.GetFpSpillMask(), true); |
| 1217 | vios->Stream() << "\n"; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1218 | } |
| 1219 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1220 | // Based on spill masks from QuickMethodFrameInfo so placed |
| 1221 | // after it is dumped, but useful for understanding quick |
| 1222 | // code, so dumped here. |
| 1223 | ScopedIndentation indent2(vios); |
| 1224 | DumpVregLocations(vios->Stream(), oat_method, code_item); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1225 | } |
| 1226 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1227 | vios->Stream() << "CODE: "; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1228 | uint32_t code_size_offset = oat_method.GetQuickCodeSizeOffset(); |
| 1229 | if (code_size_offset > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1230 | ScopedIndentation indent2(vios); |
| 1231 | vios->Stream() << StringPrintf("WARNING: " |
| 1232 | "code size offset 0x%08x is past end of file 0x%08zx.", |
| 1233 | code_size_offset, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1234 | success = false; |
| 1235 | } else { |
| 1236 | const void* code = oat_method.GetQuickCode(); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1237 | uint32_t aligned_code_begin = AlignCodeOffset(code_offset); |
| 1238 | uint64_t aligned_code_end = aligned_code_begin + code_size; |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 1239 | stats_.AddBitsIfUnique(Stats::kByteKindCode, code_size * kBitsPerByte, code); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1240 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1241 | if (options_.absolute_addresses_) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1242 | vios->Stream() << StringPrintf("%p ", code); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1243 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1244 | vios->Stream() << StringPrintf("(code_offset=0x%08x size_offset=0x%08x size=%u)%s\n", |
| 1245 | code_offset, |
| 1246 | code_size_offset, |
| 1247 | code_size, |
| 1248 | code != nullptr ? "..." : ""); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1249 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1250 | ScopedIndentation indent2(vios); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1251 | if (aligned_code_begin > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1252 | vios->Stream() << StringPrintf("WARNING: " |
| 1253 | "start of code at 0x%08x is past end of file 0x%08zx.", |
| 1254 | aligned_code_begin, oat_file_.Size()); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1255 | success = false; |
| 1256 | } else if (aligned_code_end > oat_file_.Size()) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1257 | vios->Stream() << StringPrintf( |
| 1258 | "WARNING: " |
| 1259 | "end of code at 0x%08" PRIx64 " is past end of file 0x%08zx. " |
| 1260 | "code size is 0x%08x loaded from offset 0x%08x.\n", |
| 1261 | aligned_code_end, oat_file_.Size(), |
| 1262 | code_size, code_size_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1263 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1264 | if (options_.disassemble_code_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1265 | if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 1266 | DumpCode(vios, oat_method, code_item, true, kPrologueBytes); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | } else if (code_size > kMaxCodeSize) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1270 | vios->Stream() << StringPrintf( |
| 1271 | "WARNING: " |
| 1272 | "code size %d is bigger than max expected threshold of %d. " |
| 1273 | "code size is 0x%08x loaded from offset 0x%08x.\n", |
| 1274 | code_size, kMaxCodeSize, |
| 1275 | code_size, code_size_offset); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1276 | success = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1277 | if (options_.disassemble_code_) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1278 | if (code_size_offset + kPrologueBytes <= oat_file_.Size()) { |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 1279 | DumpCode(vios, oat_method, code_item, true, kPrologueBytes); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1280 | } |
| 1281 | } |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1282 | } else if (options_.disassemble_code_) { |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 1283 | DumpCode(vios, oat_method, code_item, !success, 0); |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1287 | vios->Stream() << std::flush; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1288 | return success; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1289 | } |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 1290 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1291 | void DumpSpillMask(std::ostream& os, uint32_t spill_mask, bool is_float) { |
| 1292 | if (spill_mask == 0) { |
| 1293 | return; |
| 1294 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1295 | os << "("; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1296 | for (size_t i = 0; i < 32; i++) { |
| 1297 | if ((spill_mask & (1 << i)) != 0) { |
| 1298 | if (is_float) { |
| 1299 | os << "fr" << i; |
| 1300 | } else { |
| 1301 | os << "r" << i; |
| 1302 | } |
| 1303 | spill_mask ^= 1 << i; // clear bit |
| 1304 | if (spill_mask != 0) { |
| 1305 | os << ", "; |
| 1306 | } else { |
| 1307 | break; |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | os << ")"; |
| 1312 | } |
| 1313 | |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1314 | // Display data stored at the the vmap offset of an oat method. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1315 | void DumpVmapData(VariableIndentationOutputStream* vios, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1316 | const OatFile::OatMethod& oat_method, |
| 1317 | const DexFile::CodeItem* code_item) { |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1318 | if (IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { |
| 1319 | // The optimizing compiler outputs its CodeInfo data in the vmap table. |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1320 | const void* raw_code_info = oat_method.GetVmapTable(); |
| 1321 | if (raw_code_info != nullptr) { |
| 1322 | CodeInfo code_info(raw_code_info); |
| 1323 | DCHECK(code_item != nullptr); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1324 | ScopedIndentation indent1(vios); |
| 1325 | DumpCodeInfo(vios, code_info, oat_method, *code_item); |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1326 | } |
Nicolas Geoffray | 0a5cd12 | 2015-07-16 14:15:05 +0100 | [diff] [blame] | 1327 | } else if (IsMethodGeneratedByDexToDexCompiler(oat_method, code_item)) { |
| 1328 | // We don't encode the size in the table, so just emit that we have quickened |
| 1329 | // information. |
| 1330 | ScopedIndentation indent(vios); |
| 1331 | vios->Stream() << "quickened data\n"; |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1332 | } else { |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 1333 | // Otherwise, there is nothing to display. |
Nicolas Geoffray | 20d3eae | 2014-09-17 11:27:23 +0100 | [diff] [blame] | 1334 | } |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | // Display a CodeInfo object emitted by the optimizing compiler. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1338 | void DumpCodeInfo(VariableIndentationOutputStream* vios, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1339 | const CodeInfo& code_info, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1340 | const OatFile::OatMethod& oat_method, |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 1341 | const DexFile::CodeItem& code_item) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1342 | code_info.Dump(vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1343 | oat_method.GetCodeOffset(), |
| 1344 | code_item.registers_size_, |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1345 | options_.dump_code_info_stack_maps_, |
| 1346 | instruction_set_); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Razvan A Lupusoru | faf9f0d | 2014-08-29 17:56:46 -0700 | [diff] [blame] | 1349 | void DumpVregLocations(std::ostream& os, const OatFile::OatMethod& oat_method, |
| 1350 | const DexFile::CodeItem* code_item) { |
| 1351 | if (code_item != nullptr) { |
| 1352 | size_t num_locals_ins = code_item->registers_size_; |
| 1353 | size_t num_ins = code_item->ins_size_; |
| 1354 | size_t num_locals = num_locals_ins - num_ins; |
| 1355 | size_t num_outs = code_item->outs_size_; |
| 1356 | |
| 1357 | os << "vr_stack_locations:"; |
| 1358 | for (size_t reg = 0; reg <= num_locals_ins; reg++) { |
| 1359 | // For readability, delimit the different kinds of VRs. |
| 1360 | if (reg == num_locals_ins) { |
| 1361 | os << "\n\tmethod*:"; |
| 1362 | } else if (reg == num_locals && num_ins > 0) { |
| 1363 | os << "\n\tins:"; |
| 1364 | } else if (reg == 0 && num_locals > 0) { |
| 1365 | os << "\n\tlocals:"; |
| 1366 | } |
| 1367 | |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 1368 | uint32_t offset = StackVisitor::GetVRegOffsetFromQuickCode( |
| 1369 | code_item, |
| 1370 | oat_method.GetCoreSpillMask(), |
| 1371 | oat_method.GetFpSpillMask(), |
| 1372 | oat_method.GetFrameSizeInBytes(), |
| 1373 | reg, |
| 1374 | GetInstructionSet()); |
Razvan A Lupusoru | faf9f0d | 2014-08-29 17:56:46 -0700 | [diff] [blame] | 1375 | os << " v" << reg << "[sp + #" << offset << "]"; |
| 1376 | } |
| 1377 | |
| 1378 | for (size_t out_reg = 0; out_reg < num_outs; out_reg++) { |
| 1379 | if (out_reg == 0) { |
| 1380 | os << "\n\touts:"; |
| 1381 | } |
| 1382 | |
| 1383 | uint32_t offset = StackVisitor::GetOutVROffset(out_reg, GetInstructionSet()); |
| 1384 | os << " v" << out_reg << "[sp + #" << offset << "]"; |
| 1385 | } |
| 1386 | |
| 1387 | os << "\n"; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1391 | 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] | 1392 | if (code_item != nullptr) { |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1393 | size_t i = 0; |
| 1394 | while (i < code_item->insns_size_in_code_units_) { |
| 1395 | const Instruction* instruction = Instruction::At(&code_item->insns_[i]); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1396 | os << StringPrintf("0x%04zx: ", i) << instruction->DumpHexLE(5) |
| 1397 | << StringPrintf("\t| %s\n", instruction->DumpString(&dex_file).c_str()); |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1398 | i += instruction->SizeInCodeUnits(); |
| 1399 | } |
| 1400 | } |
| 1401 | } |
| 1402 | |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1403 | // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by |
| 1404 | // the optimizing compiler? |
| 1405 | static bool IsMethodGeneratedByOptimizingCompiler(const OatFile::OatMethod& oat_method, |
| 1406 | const DexFile::CodeItem* code_item) { |
| 1407 | // If the native GC map is null and the Dex `code_item` is not |
| 1408 | // null, then this method has been compiled with the optimizing |
| 1409 | // compiler. |
Nicolas Geoffray | 0a5cd12 | 2015-07-16 14:15:05 +0100 | [diff] [blame] | 1410 | return oat_method.GetQuickCode() != nullptr && |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 1411 | oat_method.GetVmapTable() != nullptr && |
Nicolas Geoffray | 0a5cd12 | 2015-07-16 14:15:05 +0100 | [diff] [blame] | 1412 | code_item != nullptr; |
| 1413 | } |
| 1414 | |
| 1415 | // Has `oat_method` -- corresponding to the Dex `code_item` -- been compiled by |
| 1416 | // the dextodex compiler? |
| 1417 | static bool IsMethodGeneratedByDexToDexCompiler(const OatFile::OatMethod& oat_method, |
| 1418 | const DexFile::CodeItem* code_item) { |
| 1419 | // If the quick code is null, the Dex `code_item` is not |
| 1420 | // null, and the vmap table is not null, then this method has been compiled |
| 1421 | // with the dextodex compiler. |
| 1422 | return oat_method.GetQuickCode() == nullptr && |
| 1423 | oat_method.GetVmapTable() != nullptr && |
| 1424 | code_item != nullptr; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1427 | verifier::MethodVerifier* DumpVerifier(VariableIndentationOutputStream* vios, |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1428 | StackHandleScope<1>* hs, |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1429 | uint32_t dex_method_idx, |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1430 | const DexFile* dex_file, |
| 1431 | const DexFile::ClassDef& class_def, |
| 1432 | const DexFile::CodeItem* code_item, |
| 1433 | uint32_t method_access_flags) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1434 | if ((method_access_flags & kAccNative) == 0) { |
| 1435 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 1436 | Runtime* const runtime = Runtime::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1437 | Handle<mirror::DexCache> dex_cache( |
Mathieu Chartier | f284d44 | 2016-06-02 11:48:30 -0700 | [diff] [blame] | 1438 | hs->NewHandle(runtime->GetClassLinker()->RegisterDexFile(*dex_file, nullptr))); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1439 | DCHECK(options_.class_loader_ != nullptr); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1440 | return verifier::MethodVerifier::VerifyMethodAndDump( |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1441 | soa.Self(), vios, dex_method_idx, dex_file, dex_cache, *options_.class_loader_, |
David Brazdil | 15fc729 | 2016-09-02 14:13:18 +0100 | [diff] [blame] | 1442 | class_def, code_item, nullptr, method_access_flags); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1443 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1444 | |
| 1445 | return nullptr; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1448 | // The StackMapsHelper provides the stack maps in the native PC order. |
| 1449 | // For identical native PCs, the order from the CodeInfo is preserved. |
| 1450 | class StackMapsHelper { |
| 1451 | public: |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1452 | explicit StackMapsHelper(const uint8_t* raw_code_info, InstructionSet instruction_set) |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1453 | : code_info_(raw_code_info), |
| 1454 | encoding_(code_info_.ExtractEncoding()), |
| 1455 | number_of_stack_maps_(code_info_.GetNumberOfStackMaps(encoding_)), |
| 1456 | indexes_(), |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1457 | offset_(static_cast<uint32_t>(-1)), |
| 1458 | stack_map_index_(0u), |
| 1459 | instruction_set_(instruction_set) { |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1460 | if (number_of_stack_maps_ != 0u) { |
| 1461 | // Check if native PCs are ordered. |
| 1462 | bool ordered = true; |
| 1463 | StackMap last = code_info_.GetStackMapAt(0u, encoding_); |
| 1464 | for (size_t i = 1; i != number_of_stack_maps_; ++i) { |
| 1465 | StackMap current = code_info_.GetStackMapAt(i, encoding_); |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1466 | if (last.GetNativePcOffset(encoding_.stack_map_encoding, instruction_set) > |
| 1467 | current.GetNativePcOffset(encoding_.stack_map_encoding, instruction_set)) { |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1468 | ordered = false; |
| 1469 | break; |
| 1470 | } |
| 1471 | last = current; |
| 1472 | } |
| 1473 | if (!ordered) { |
| 1474 | // Create indirection indexes for access in native PC order. We do not optimize |
| 1475 | // for the fact that there can currently be only two separately ordered ranges, |
| 1476 | // namely normal stack maps and catch-point stack maps. |
| 1477 | indexes_.resize(number_of_stack_maps_); |
| 1478 | std::iota(indexes_.begin(), indexes_.end(), 0u); |
| 1479 | std::sort(indexes_.begin(), |
| 1480 | indexes_.end(), |
| 1481 | [this](size_t lhs, size_t rhs) { |
| 1482 | StackMap left = code_info_.GetStackMapAt(lhs, encoding_); |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1483 | uint32_t left_pc = left.GetNativePcOffset(encoding_.stack_map_encoding, |
| 1484 | instruction_set_); |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1485 | StackMap right = code_info_.GetStackMapAt(rhs, encoding_); |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1486 | uint32_t right_pc = right.GetNativePcOffset(encoding_.stack_map_encoding, |
| 1487 | instruction_set_); |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1488 | // If the PCs are the same, compare indexes to preserve the original order. |
| 1489 | return (left_pc < right_pc) || (left_pc == right_pc && lhs < rhs); |
| 1490 | }); |
| 1491 | } |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1492 | offset_ = GetStackMapAt(0).GetNativePcOffset(encoding_.stack_map_encoding, |
| 1493 | instruction_set_); |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | const CodeInfo& GetCodeInfo() const { |
| 1498 | return code_info_; |
| 1499 | } |
| 1500 | |
| 1501 | const CodeInfoEncoding& GetEncoding() const { |
| 1502 | return encoding_; |
| 1503 | } |
| 1504 | |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1505 | uint32_t GetOffset() const { |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1506 | return offset_; |
| 1507 | } |
| 1508 | |
| 1509 | StackMap GetStackMap() const { |
| 1510 | return GetStackMapAt(stack_map_index_); |
| 1511 | } |
| 1512 | |
| 1513 | void Next() { |
| 1514 | ++stack_map_index_; |
| 1515 | offset_ = (stack_map_index_ == number_of_stack_maps_) |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1516 | ? static_cast<uint32_t>(-1) |
| 1517 | : GetStackMapAt(stack_map_index_).GetNativePcOffset(encoding_.stack_map_encoding, |
| 1518 | instruction_set_); |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | private: |
| 1522 | StackMap GetStackMapAt(size_t i) const { |
| 1523 | if (!indexes_.empty()) { |
| 1524 | i = indexes_[i]; |
| 1525 | } |
| 1526 | DCHECK_LT(i, number_of_stack_maps_); |
| 1527 | return code_info_.GetStackMapAt(i, encoding_); |
| 1528 | } |
| 1529 | |
| 1530 | const CodeInfo code_info_; |
| 1531 | const CodeInfoEncoding encoding_; |
| 1532 | const size_t number_of_stack_maps_; |
| 1533 | dchecked_vector<size_t> indexes_; // Used if stack map native PCs are not ordered. |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1534 | uint32_t offset_; |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1535 | size_t stack_map_index_; |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1536 | const InstructionSet instruction_set_; |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1537 | }; |
| 1538 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1539 | void DumpCode(VariableIndentationOutputStream* vios, |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1540 | const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item, |
| 1541 | bool bad_input, size_t code_size) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1542 | const void* quick_code = oat_method.GetQuickCode(); |
| 1543 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1544 | if (code_size == 0) { |
| 1545 | code_size = oat_method.GetQuickCodeSize(); |
| 1546 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 1547 | if (code_size == 0 || quick_code == nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1548 | vios->Stream() << "NO CODE!\n"; |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1549 | return; |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1550 | } else if (!bad_input && IsMethodGeneratedByOptimizingCompiler(oat_method, code_item)) { |
| 1551 | // The optimizing compiler outputs its CodeInfo data in the vmap table. |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1552 | StackMapsHelper helper(oat_method.GetVmapTable(), instruction_set_); |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 1553 | { |
| 1554 | CodeInfoEncoding encoding(helper.GetEncoding()); |
| 1555 | StackMapEncoding stack_map_encoding(encoding.stack_map_encoding); |
| 1556 | // helper.GetCodeInfo().GetStackMapAt(0, encoding).; |
| 1557 | const size_t num_stack_maps = encoding.number_of_stack_maps; |
| 1558 | std::vector<uint8_t> size_vector; |
| 1559 | encoding.Compress(&size_vector); |
| 1560 | if (stats_.AddBitsIfUnique(Stats::kByteKindCodeInfoEncoding, |
| 1561 | size_vector.size() * kBitsPerByte, |
| 1562 | oat_method.GetVmapTable())) { |
| 1563 | stats_.AddBits( |
| 1564 | Stats::kByteKindStackMapNativePc, |
| 1565 | stack_map_encoding.GetNativePcEncoding().BitSize() * num_stack_maps); |
| 1566 | stats_.AddBits( |
| 1567 | Stats::kByteKindStackMapDexPc, |
| 1568 | stack_map_encoding.GetDexPcEncoding().BitSize() * num_stack_maps); |
| 1569 | stats_.AddBits( |
| 1570 | Stats::kByteKindStackMapDexRegisterMap, |
| 1571 | stack_map_encoding.GetDexRegisterMapEncoding().BitSize() * num_stack_maps); |
| 1572 | stats_.AddBits( |
| 1573 | Stats::kByteKindStackMapInlineInfo, |
| 1574 | stack_map_encoding.GetInlineInfoEncoding().BitSize() * num_stack_maps); |
| 1575 | stats_.AddBits( |
| 1576 | Stats::kByteKindStackMapRegisterMask, |
| 1577 | stack_map_encoding.GetRegisterMaskEncoding().BitSize() * num_stack_maps); |
| 1578 | const size_t stack_mask_bits = encoding.stack_map_size_in_bytes * kBitsPerByte - |
| 1579 | stack_map_encoding.GetStackMaskBitOffset(); |
| 1580 | stats_.AddBits( |
| 1581 | Stats::kByteKindStackMapMask, |
| 1582 | stack_mask_bits * num_stack_maps); |
| 1583 | const size_t stack_map_bits = |
| 1584 | stack_map_encoding.GetStackMaskBitOffset() + stack_mask_bits; |
| 1585 | stats_.AddBits( |
| 1586 | Stats::kByteKindStackMapOther, |
| 1587 | (encoding.stack_map_size_in_bytes * kBitsPerByte - stack_map_bits) * num_stack_maps); |
| 1588 | const size_t stack_map_bytes = helper.GetCodeInfo().GetStackMapsSize(encoding); |
| 1589 | const size_t location_catalog_bytes = |
| 1590 | helper.GetCodeInfo().GetDexRegisterLocationCatalogSize(encoding); |
| 1591 | stats_.AddBits(Stats::kByteKindCodeInfoLocationCatalog, |
| 1592 | kBitsPerByte * location_catalog_bytes); |
| 1593 | const size_t dex_register_bytes = |
| 1594 | helper.GetCodeInfo().GetDexRegisterMapsSize(encoding, code_item->registers_size_); |
| 1595 | stats_.AddBits( |
| 1596 | Stats::kByteKindCodeInfoDexRegisterMap, |
| 1597 | kBitsPerByte * dex_register_bytes); |
| 1598 | const size_t inline_info_bytes = |
| 1599 | encoding.non_header_size - |
| 1600 | stack_map_bytes - |
| 1601 | location_catalog_bytes - |
| 1602 | dex_register_bytes; |
| 1603 | stats_.AddBits(Stats::kByteKindCodeInfoInlineInfo, |
| 1604 | inline_info_bytes * kBitsPerByte); |
| 1605 | } |
| 1606 | } |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1607 | const uint8_t* quick_native_pc = reinterpret_cast<const uint8_t*>(quick_code); |
| 1608 | size_t offset = 0; |
| 1609 | while (offset < code_size) { |
| 1610 | offset += disassembler_->Dump(vios->Stream(), quick_native_pc + offset); |
| 1611 | if (offset == helper.GetOffset()) { |
| 1612 | ScopedIndentation indent1(vios); |
| 1613 | StackMap stack_map = helper.GetStackMap(); |
| 1614 | DCHECK(stack_map.IsValid()); |
| 1615 | stack_map.Dump(vios, |
| 1616 | helper.GetCodeInfo(), |
| 1617 | helper.GetEncoding(), |
| 1618 | oat_method.GetCodeOffset(), |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1619 | code_item->registers_size_, |
| 1620 | instruction_set_); |
Vladimir Marko | adbf93e | 2016-04-08 11:18:25 +0100 | [diff] [blame] | 1621 | do { |
| 1622 | helper.Next(); |
| 1623 | // There may be multiple stack maps at a given PC. We display only the first one. |
| 1624 | } while (offset == helper.GetOffset()); |
| 1625 | } |
| 1626 | DCHECK_LT(offset, helper.GetOffset()); |
| 1627 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 1628 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1629 | const uint8_t* quick_native_pc = reinterpret_cast<const uint8_t*>(quick_code); |
| 1630 | size_t offset = 0; |
| 1631 | while (offset < code_size) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1632 | offset += disassembler_->Dump(vios->Stream(), quick_native_pc + offset); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1633 | } |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1637 | const OatFile& oat_file_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1638 | const std::vector<const OatFile::OatDexFile*> oat_dex_files_; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1639 | const OatDumperOptions& options_; |
| 1640 | uint32_t resolved_addr2instr_; |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 1641 | const InstructionSet instruction_set_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1642 | std::set<uintptr_t> offsets_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1643 | Disassembler* disassembler_; |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame^] | 1644 | Stats stats_; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1645 | }; |
| 1646 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1647 | class ImageDumper { |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1648 | public: |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1649 | ImageDumper(std::ostream* os, |
| 1650 | gc::space::ImageSpace& image_space, |
| 1651 | const ImageHeader& image_header, |
| 1652 | OatDumperOptions* oat_dumper_options) |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1653 | : os_(os), |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1654 | vios_(os), |
| 1655 | indent1_(&vios_), |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1656 | image_space_(image_space), |
| 1657 | image_header_(image_header), |
| 1658 | oat_dumper_options_(oat_dumper_options) {} |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1659 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1660 | bool Dump() REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1661 | std::ostream& os = *os_; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1662 | std::ostream& indent_os = vios_.Stream(); |
| 1663 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1664 | os << "MAGIC: " << image_header_.GetMagic() << "\n\n"; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 1665 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1666 | os << "IMAGE LOCATION: " << image_space_.GetImageLocation() << "\n\n"; |
| 1667 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1668 | os << "IMAGE BEGIN: " << reinterpret_cast<void*>(image_header_.GetImageBegin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1669 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1670 | os << "IMAGE SIZE: " << image_header_.GetImageSize() << "\n\n"; |
| 1671 | |
| 1672 | for (size_t i = 0; i < ImageHeader::kSectionCount; ++i) { |
| 1673 | auto section = static_cast<ImageHeader::ImageSections>(i); |
| 1674 | os << "IMAGE SECTION " << section << ": " << image_header_.GetImageSection(section) << "\n\n"; |
| 1675 | } |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 1676 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1677 | os << "OAT CHECKSUM: " << StringPrintf("0x%08x\n\n", image_header_.GetOatChecksum()); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 1678 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 1679 | os << "OAT FILE BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatFileBegin()) << "\n\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1680 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 1681 | os << "OAT DATA BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatDataBegin()) << "\n\n"; |
| 1682 | |
| 1683 | os << "OAT DATA END:" << reinterpret_cast<void*>(image_header_.GetOatDataEnd()) << "\n\n"; |
| 1684 | |
| 1685 | os << "OAT FILE END:" << reinterpret_cast<void*>(image_header_.GetOatFileEnd()) << "\n\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1686 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1687 | os << "PATCH DELTA:" << image_header_.GetPatchDelta() << "\n\n"; |
| 1688 | |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 1689 | os << "COMPILE PIC: " << (image_header_.CompilePic() ? "yes" : "no") << "\n\n"; |
| 1690 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1691 | { |
| 1692 | os << "ROOTS: " << reinterpret_cast<void*>(image_header_.GetImageRoots()) << "\n"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1693 | static_assert(arraysize(image_roots_descriptions_) == |
| 1694 | static_cast<size_t>(ImageHeader::kImageRootsMax), "sizes must match"); |
Vladimir Marko | eca3eda | 2016-11-09 16:26:44 +0000 | [diff] [blame] | 1695 | DCHECK_LE(image_header_.GetImageRoots()->GetLength(), ImageHeader::kImageRootsMax); |
| 1696 | for (int32_t i = 0, size = image_header_.GetImageRoots()->GetLength(); i != size; ++i) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1697 | ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i); |
| 1698 | const char* image_root_description = image_roots_descriptions_[i]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1699 | mirror::Object* image_root_object = image_header_.GetImageRoot(image_root); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1700 | indent_os << StringPrintf("%s: %p\n", image_root_description, image_root_object); |
Vladimir Marko | eca3eda | 2016-11-09 16:26:44 +0000 | [diff] [blame] | 1701 | if (image_root_object != nullptr && image_root_object->IsObjectArray()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1702 | mirror::ObjectArray<mirror::Object>* image_root_object_array |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1703 | = image_root_object->AsObjectArray<mirror::Object>(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1704 | ScopedIndentation indent2(&vios_); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1705 | for (int j = 0; j < image_root_object_array->GetLength(); j++) { |
| 1706 | mirror::Object* value = image_root_object_array->Get(j); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1707 | size_t run = 0; |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1708 | for (int32_t k = j + 1; k < image_root_object_array->GetLength(); k++) { |
| 1709 | if (value == image_root_object_array->Get(k)) { |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1710 | run++; |
| 1711 | } else { |
| 1712 | break; |
| 1713 | } |
| 1714 | } |
| 1715 | if (run == 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1716 | indent_os << StringPrintf("%d: ", j); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1717 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1718 | indent_os << StringPrintf("%d to %zd: ", j, j + run); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1719 | j = j + run; |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 1720 | } |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1721 | if (value != nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1722 | PrettyObjectValue(indent_os, value->GetClass(), value); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1723 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1724 | indent_os << j << ": null\n"; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1725 | } |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1726 | } |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 1727 | } |
| 1728 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1729 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1730 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1731 | { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1732 | os << "METHOD ROOTS\n"; |
| 1733 | static_assert(arraysize(image_methods_descriptions_) == |
| 1734 | static_cast<size_t>(ImageHeader::kImageMethodsCount), "sizes must match"); |
| 1735 | for (int i = 0; i < ImageHeader::kImageMethodsCount; i++) { |
| 1736 | auto image_root = static_cast<ImageHeader::ImageMethod>(i); |
| 1737 | const char* description = image_methods_descriptions_[i]; |
| 1738 | auto* image_method = image_header_.GetImageMethod(image_root); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1739 | indent_os << StringPrintf("%s: %p\n", description, image_method); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1740 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1741 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1742 | os << "\n"; |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1743 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1744 | Runtime* const runtime = Runtime::Current(); |
| 1745 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1746 | std::string image_filename = image_space_.GetImageFilename(); |
| 1747 | std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(image_filename); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1748 | os << "OAT LOCATION: " << oat_location; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1749 | os << "\n"; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 1750 | std::string error_msg; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1751 | const OatFile* oat_file = image_space_.GetOatFile(); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1752 | if (oat_file == nullptr) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1753 | oat_file = runtime->GetOatFileManager().FindOpenedOatFileFromOatLocation(oat_location); |
| 1754 | } |
| 1755 | if (oat_file == nullptr) { |
| 1756 | oat_file = OatFile::Open(oat_location, |
| 1757 | oat_location, |
| 1758 | nullptr, |
| 1759 | nullptr, |
| 1760 | false, |
| 1761 | /*low_4gb*/false, |
| 1762 | nullptr, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1763 | &error_msg); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1764 | } |
| 1765 | if (oat_file == nullptr) { |
| 1766 | os << "OAT FILE NOT FOUND: " << error_msg << "\n"; |
| 1767 | return EXIT_FAILURE; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1768 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1769 | os << "\n"; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 1770 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1771 | stats_.oat_file_bytes = oat_file->Size(); |
| 1772 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 1773 | oat_dumper_.reset(new OatDumper(*oat_file, *oat_dumper_options_)); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1774 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1775 | for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1776 | CHECK(oat_dex_file != nullptr); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1777 | stats_.oat_dex_file_sizes.push_back(std::make_pair(oat_dex_file->GetDexFileLocation(), |
| 1778 | oat_dex_file->FileSize())); |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1781 | os << "OBJECTS:\n" << std::flush; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1782 | |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1783 | // Loop through the image space and dump its objects. |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1784 | gc::Heap* heap = runtime->GetHeap(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1785 | Thread* self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1786 | { |
Mathieu Chartier | c22c59e | 2014-02-24 15:16:06 -0800 | [diff] [blame] | 1787 | { |
| 1788 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
| 1789 | heap->FlushAllocStack(); |
| 1790 | } |
Hiroshi Yamauchi | 90d7068 | 2014-02-20 16:17:30 -0800 | [diff] [blame] | 1791 | // Since FlushAllocStack() above resets the (active) allocation |
| 1792 | // stack. Need to revoke the thread-local allocation stacks that |
| 1793 | // point into it. |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 1794 | ScopedThreadSuspension sts(self, kNative); |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 1795 | ScopedSuspendAll ssa(__FUNCTION__); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 1796 | heap->RevokeAllThreadLocalAllocationStacks(self); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 1797 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1798 | { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1799 | // Mark dex caches. |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1800 | dex_caches_.clear(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1801 | { |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1802 | ReaderMutexLock mu(self, *Locks::dex_lock_); |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 1803 | for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) { |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 1804 | ObjPtr<mirror::DexCache> dex_cache = |
| 1805 | ObjPtr<mirror::DexCache>::DownCast(self->DecodeJObject(data.weak_root)); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1806 | if (dex_cache != nullptr) { |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 1807 | dex_caches_.insert(dex_cache.Ptr()); |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1808 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1809 | } |
| 1810 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1811 | ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1812 | // Dump the normal objects before ArtMethods. |
| 1813 | image_space_.GetLiveBitmap()->Walk(ImageDumper::Callback, this); |
| 1814 | indent_os << "\n"; |
| 1815 | // TODO: Dump fields. |
| 1816 | // Dump methods after. |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 1817 | DumpArtMethodVisitor visitor(this); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1818 | image_header_.VisitPackedArtMethods(&visitor, |
| 1819 | image_space_.Begin(), |
| 1820 | image_header_.GetPointerSize()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1821 | // Dump the large objects separately. |
Mathieu Chartier | bbd695c | 2014-04-16 09:48:48 -0700 | [diff] [blame] | 1822 | heap->GetLargeObjectsSpace()->GetLiveBitmap()->Walk(ImageDumper::Callback, this); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1823 | indent_os << "\n"; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 1824 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1825 | os << "STATS:\n" << std::flush; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1826 | std::unique_ptr<File> file(OS::OpenFileForReading(image_filename.c_str())); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1827 | size_t data_size = image_header_.GetDataSize(); // stored size in file. |
| 1828 | if (file == nullptr) { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1829 | LOG(WARNING) << "Failed to find image in " << image_filename; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1830 | } else { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1831 | stats_.file_bytes = file->GetLength(); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1832 | // If the image is compressed, adjust to decompressed size. |
| 1833 | size_t uncompressed_size = image_header_.GetImageSize() - sizeof(ImageHeader); |
| 1834 | if (image_header_.GetStorageMode() == ImageHeader::kStorageModeUncompressed) { |
| 1835 | DCHECK_EQ(uncompressed_size, data_size) << "Sizes should match for uncompressed image"; |
| 1836 | } |
| 1837 | stats_.file_bytes += uncompressed_size - data_size; |
Brian Carlstrom | 6f27775 | 2013-09-30 17:56:45 -0700 | [diff] [blame] | 1838 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1839 | size_t header_bytes = sizeof(ImageHeader); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1840 | const auto& object_section = image_header_.GetImageSection(ImageHeader::kSectionObjects); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1841 | const auto& field_section = image_header_.GetImageSection(ImageHeader::kSectionArtFields); |
| 1842 | const auto& method_section = image_header_.GetMethodsSection(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1843 | const auto& dex_cache_arrays_section = image_header_.GetImageSection( |
| 1844 | ImageHeader::kSectionDexCacheArrays); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 1845 | const auto& intern_section = image_header_.GetImageSection( |
| 1846 | ImageHeader::kSectionInternedStrings); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 1847 | const auto& class_table_section = image_header_.GetImageSection( |
| 1848 | ImageHeader::kSectionClassTable); |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1849 | const auto& bitmap_section = image_header_.GetImageSection(ImageHeader::kSectionImageBitmap); |
| 1850 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1851 | stats_.header_bytes = header_bytes; |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1852 | |
| 1853 | // Objects are kObjectAlignment-aligned. |
| 1854 | // CHECK_EQ(RoundUp(header_bytes, kObjectAlignment), object_section.Offset()); |
| 1855 | if (object_section.Offset() > header_bytes) { |
| 1856 | stats_.alignment_bytes += object_section.Offset() - header_bytes; |
| 1857 | } |
| 1858 | |
| 1859 | // Field section is 4-byte aligned. |
| 1860 | constexpr size_t kFieldSectionAlignment = 4U; |
| 1861 | uint32_t end_objects = object_section.Offset() + object_section.Size(); |
| 1862 | CHECK_EQ(RoundUp(end_objects, kFieldSectionAlignment), field_section.Offset()); |
| 1863 | stats_.alignment_bytes += field_section.Offset() - end_objects; |
| 1864 | |
| 1865 | // Method section is 4/8 byte aligned depending on target. Just check for 4-byte alignment. |
| 1866 | uint32_t end_fields = field_section.Offset() + field_section.Size(); |
| 1867 | CHECK_ALIGNED(method_section.Offset(), 4); |
| 1868 | stats_.alignment_bytes += method_section.Offset() - end_fields; |
| 1869 | |
| 1870 | // Dex cache arrays section is aligned depending on the target. Just check for 4-byte alignment. |
| 1871 | uint32_t end_methods = method_section.Offset() + method_section.Size(); |
| 1872 | CHECK_ALIGNED(dex_cache_arrays_section.Offset(), 4); |
| 1873 | stats_.alignment_bytes += dex_cache_arrays_section.Offset() - end_methods; |
| 1874 | |
| 1875 | // Intern table is 8-byte aligned. |
| 1876 | uint32_t end_caches = dex_cache_arrays_section.Offset() + dex_cache_arrays_section.Size(); |
| 1877 | CHECK_EQ(RoundUp(end_caches, 8U), intern_section.Offset()); |
| 1878 | stats_.alignment_bytes += intern_section.Offset() - end_caches; |
| 1879 | |
| 1880 | // Add space between intern table and class table. |
| 1881 | uint32_t end_intern = intern_section.Offset() + intern_section.Size(); |
| 1882 | stats_.alignment_bytes += class_table_section.Offset() - end_intern; |
| 1883 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1884 | // Add space between end of image data and bitmap. Expect the bitmap to be page-aligned. |
| 1885 | const size_t bitmap_offset = sizeof(ImageHeader) + data_size; |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1886 | CHECK_ALIGNED(bitmap_section.Offset(), kPageSize); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1887 | stats_.alignment_bytes += RoundUp(bitmap_offset, kPageSize) - bitmap_offset; |
Andreas Gampe | ace0dc1 | 2016-01-20 13:33:13 -0800 | [diff] [blame] | 1888 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1889 | stats_.bitmap_bytes += bitmap_section.Size(); |
| 1890 | stats_.art_field_bytes += field_section.Size(); |
Vladimir Marko | cf36d49 | 2015-08-12 19:27:26 +0100 | [diff] [blame] | 1891 | stats_.art_method_bytes += method_section.Size(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1892 | stats_.dex_cache_arrays_bytes += dex_cache_arrays_section.Size(); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 1893 | stats_.interned_strings_bytes += intern_section.Size(); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 1894 | stats_.class_table_bytes += class_table_section.Size(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1895 | stats_.Dump(os, indent_os); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1896 | os << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1897 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1898 | os << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1899 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1900 | return oat_dumper_->Dump(os); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 1903 | private: |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1904 | class DumpArtMethodVisitor : public ArtMethodVisitor { |
| 1905 | public: |
| 1906 | explicit DumpArtMethodVisitor(ImageDumper* image_dumper) : image_dumper_(image_dumper) {} |
| 1907 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1908 | virtual void Visit(ArtMethod* method) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1909 | std::ostream& indent_os = image_dumper_->vios_.Stream(); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1910 | indent_os << method << " " << " ArtMethod: " << ArtMethod::PrettyMethod(method) << "\n"; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 1911 | image_dumper_->DumpMethod(method, indent_os); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1912 | indent_os << "\n"; |
| 1913 | } |
| 1914 | |
| 1915 | private: |
| 1916 | ImageDumper* const image_dumper_; |
| 1917 | }; |
| 1918 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 1919 | static void PrettyObjectValue(std::ostream& os, |
| 1920 | ObjPtr<mirror::Class> type, |
| 1921 | ObjPtr<mirror::Object> value) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1922 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1923 | CHECK(type != nullptr); |
| 1924 | if (value == nullptr) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1925 | os << StringPrintf("null %s\n", type->PrettyDescriptor().c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1926 | } else if (type->IsStringClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1927 | mirror::String* string = value->AsString(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1928 | os << StringPrintf("%p String: %s\n", string, |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 1929 | PrintableString(string->ToModifiedUtf8().c_str()).c_str()); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 1930 | } else if (type->IsClassClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1931 | mirror::Class* klass = value->AsClass(); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1932 | os << StringPrintf("%p Class: %s\n", klass, mirror::Class::PrettyDescriptor(klass).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1933 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1934 | os << StringPrintf("%p %s\n", value.Ptr(), type->PrettyDescriptor().c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1935 | } |
| 1936 | } |
| 1937 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 1938 | static void PrintField(std::ostream& os, ArtField* field, ObjPtr<mirror::Object> obj) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1939 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 1940 | os << StringPrintf("%s: ", field->GetName()); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1941 | switch (field->GetTypeAsPrimitiveType()) { |
| 1942 | case Primitive::kPrimLong: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1943 | os << StringPrintf("%" PRId64 " (0x%" PRIx64 ")\n", field->Get64(obj), field->Get64(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1944 | break; |
| 1945 | case Primitive::kPrimDouble: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1946 | os << StringPrintf("%f (%a)\n", field->GetDouble(obj), field->GetDouble(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1947 | break; |
| 1948 | case Primitive::kPrimFloat: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1949 | os << StringPrintf("%f (%a)\n", field->GetFloat(obj), field->GetFloat(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1950 | break; |
| 1951 | case Primitive::kPrimInt: |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1952 | os << StringPrintf("%d (0x%x)\n", field->Get32(obj), field->Get32(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1953 | break; |
| 1954 | case Primitive::kPrimChar: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1955 | os << StringPrintf("%u (0x%x)\n", field->GetChar(obj), field->GetChar(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1956 | break; |
| 1957 | case Primitive::kPrimShort: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1958 | os << StringPrintf("%d (0x%x)\n", field->GetShort(obj), field->GetShort(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1959 | break; |
| 1960 | case Primitive::kPrimBoolean: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1961 | os << StringPrintf("%s (0x%x)\n", field->GetBoolean(obj)? "true" : "false", |
| 1962 | field->GetBoolean(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1963 | break; |
| 1964 | case Primitive::kPrimByte: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1965 | os << StringPrintf("%d (0x%x)\n", field->GetByte(obj), field->GetByte(obj)); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1966 | break; |
| 1967 | case Primitive::kPrimNot: { |
| 1968 | // Get the value, don't compute the type unless it is non-null as we don't want |
| 1969 | // to cause class loading. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 1970 | ObjPtr<mirror::Object> value = field->GetObj(obj); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1971 | if (value == nullptr) { |
| 1972 | os << StringPrintf("null %s\n", PrettyDescriptor(field->GetTypeDescriptor()).c_str()); |
Ian Rogers | 50239c7 | 2013-06-17 14:53:22 -0700 | [diff] [blame] | 1973 | } else { |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1974 | // Grab the field type without causing resolution. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 1975 | ObjPtr<mirror::Class> field_type = field->GetType<false>(); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1976 | if (field_type != nullptr) { |
| 1977 | PrettyObjectValue(os, field_type, value); |
| 1978 | } else { |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 1979 | os << StringPrintf("%p %s\n", |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 1980 | value.Ptr(), |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1981 | PrettyDescriptor(field->GetTypeDescriptor()).c_str()); |
| 1982 | } |
Ian Rogers | 50239c7 | 2013-06-17 14:53:22 -0700 | [diff] [blame] | 1983 | } |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1984 | break; |
Ian Rogers | 48efc2b | 2012-08-27 17:20:31 -0700 | [diff] [blame] | 1985 | } |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 1986 | default: |
| 1987 | os << "unexpected field type: " << field->GetTypeDescriptor() << "\n"; |
| 1988 | break; |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1992 | static void DumpFields(std::ostream& os, mirror::Object* obj, mirror::Class* klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1993 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1994 | mirror::Class* super = klass->GetSuperClass(); |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 1995 | if (super != nullptr) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1996 | DumpFields(os, obj, super); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 1997 | } |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1998 | for (ArtField& field : klass->GetIFields()) { |
| 1999 | PrintField(os, &field, obj); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2000 | } |
| 2001 | } |
| 2002 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2003 | bool InDumpSpace(const mirror::Object* object) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2004 | return image_space_.Contains(object); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2005 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2006 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2007 | const void* GetQuickOatCodeBegin(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 2008 | const void* quick_code = m->GetEntryPointFromQuickCompiledCodePtrSize( |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2009 | image_header_.GetPointerSize()); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2010 | if (Runtime::Current()->GetClassLinker()->IsQuickResolutionStub(quick_code)) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2011 | quick_code = oat_dumper_->GetQuickOatCode(m); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2012 | } |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2013 | if (oat_dumper_->GetInstructionSet() == kThumb2) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2014 | quick_code = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(quick_code) & ~0x1); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2015 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2016 | return quick_code; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2017 | } |
| 2018 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2019 | uint32_t GetQuickOatCodeSize(ArtMethod* m) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2020 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2021 | const uint32_t* oat_code_begin = reinterpret_cast<const uint32_t*>(GetQuickOatCodeBegin(m)); |
| 2022 | if (oat_code_begin == nullptr) { |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2023 | return 0; |
| 2024 | } |
| 2025 | return oat_code_begin[-1]; |
| 2026 | } |
| 2027 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2028 | const void* GetQuickOatCodeEnd(ArtMethod* m) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2029 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2030 | 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] | 2031 | if (oat_code_begin == nullptr) { |
| 2032 | return nullptr; |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2033 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 2034 | return oat_code_begin + GetQuickOatCodeSize(m); |
Brian Carlstrom | f8bbb84 | 2012-03-14 03:01:42 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2037 | static void Callback(mirror::Object* obj, void* arg) REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 2038 | DCHECK(obj != nullptr); |
| 2039 | DCHECK(arg != nullptr); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2040 | ImageDumper* state = reinterpret_cast<ImageDumper*>(arg); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2041 | if (!state->InDumpSpace(obj)) { |
| 2042 | return; |
| 2043 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2044 | |
| 2045 | size_t object_bytes = obj->SizeOf(); |
| 2046 | size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes; |
| 2047 | state->stats_.object_bytes += object_bytes; |
| 2048 | state->stats_.alignment_bytes += alignment_bytes; |
| 2049 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2050 | std::ostream& os = state->vios_.Stream(); |
| 2051 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2052 | mirror::Class* obj_class = obj->GetClass(); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2053 | if (obj_class->IsArrayClass()) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2054 | os << StringPrintf("%p: %s length:%d\n", obj, obj_class->PrettyDescriptor().c_str(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2055 | obj->AsArray()->GetLength()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2056 | } else if (obj->IsClass()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2057 | mirror::Class* klass = obj->AsClass(); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2058 | os << StringPrintf("%p: java.lang.Class \"%s\" (", obj, |
| 2059 | mirror::Class::PrettyDescriptor(klass).c_str()) |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2060 | << klass->GetStatus() << ")\n"; |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2061 | } else if (obj_class->IsStringClass()) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2062 | os << StringPrintf("%p: java.lang.String %s\n", obj, |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 2063 | PrintableString(obj->AsString()->ToModifiedUtf8().c_str()).c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2064 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2065 | os << StringPrintf("%p: %s\n", obj, obj_class->PrettyDescriptor().c_str()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2066 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2067 | ScopedIndentation indent1(&state->vios_); |
| 2068 | DumpFields(os, obj, obj_class); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2069 | const PointerSize image_pointer_size = state->image_header_.GetPointerSize(); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2070 | if (obj->IsObjectArray()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2071 | auto* obj_array = obj->AsObjectArray<mirror::Object>(); |
| 2072 | for (int32_t i = 0, length = obj_array->GetLength(); i < length; i++) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2073 | mirror::Object* value = obj_array->Get(i); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2074 | size_t run = 0; |
| 2075 | for (int32_t j = i + 1; j < length; j++) { |
| 2076 | if (value == obj_array->Get(j)) { |
| 2077 | run++; |
| 2078 | } else { |
| 2079 | break; |
| 2080 | } |
| 2081 | } |
| 2082 | if (run == 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2083 | os << StringPrintf("%d: ", i); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2084 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2085 | os << StringPrintf("%d to %zd: ", i, i + run); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2086 | i = i + run; |
| 2087 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2088 | mirror::Class* value_class = |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 2089 | (value == nullptr) ? obj_class->GetComponentType() : value->GetClass(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2090 | PrettyObjectValue(os, value_class, value); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2091 | } |
| 2092 | } else if (obj->IsClass()) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 2093 | mirror::Class* klass = obj->AsClass(); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 2094 | if (klass->NumStaticFields() != 0) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2095 | os << "STATICS:\n"; |
| 2096 | ScopedIndentation indent2(&state->vios_); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 2097 | for (ArtField& field : klass->GetSFields()) { |
| 2098 | PrintField(os, &field, field.GetDeclaringClass()); |
Ian Rogers | d5b3260 | 2012-02-26 16:40:04 -0800 | [diff] [blame] | 2099 | } |
| 2100 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2101 | } else { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2102 | auto it = state->dex_caches_.find(obj); |
| 2103 | if (it != state->dex_caches_.end()) { |
| 2104 | auto* dex_cache = down_cast<mirror::DexCache*>(obj); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2105 | const auto& field_section = state->image_header_.GetImageSection( |
| 2106 | ImageHeader::kSectionArtFields); |
| 2107 | const auto& method_section = state->image_header_.GetMethodsSection(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2108 | size_t num_methods = dex_cache->NumResolvedMethods(); |
| 2109 | if (num_methods != 0u) { |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2110 | os << "Methods (size=" << num_methods << "):\n"; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2111 | ScopedIndentation indent2(&state->vios_); |
| 2112 | auto* resolved_methods = dex_cache->GetResolvedMethods(); |
| 2113 | for (size_t i = 0, length = dex_cache->NumResolvedMethods(); i < length; ++i) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2114 | auto* elem = mirror::DexCache::GetElementPtrSize(resolved_methods, |
| 2115 | i, |
| 2116 | image_pointer_size); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2117 | size_t run = 0; |
| 2118 | for (size_t j = i + 1; |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2119 | j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_methods, |
| 2120 | j, |
| 2121 | image_pointer_size); |
| 2122 | ++j) { |
| 2123 | ++run; |
| 2124 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2125 | if (run == 0) { |
| 2126 | os << StringPrintf("%zd: ", i); |
| 2127 | } else { |
| 2128 | os << StringPrintf("%zd to %zd: ", i, i + run); |
| 2129 | i = i + run; |
| 2130 | } |
| 2131 | std::string msg; |
| 2132 | if (elem == nullptr) { |
| 2133 | msg = "null"; |
| 2134 | } else if (method_section.Contains( |
| 2135 | reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2136 | msg = reinterpret_cast<ArtMethod*>(elem)->PrettyMethod(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2137 | } else { |
| 2138 | msg = "<not in method section>"; |
| 2139 | } |
| 2140 | os << StringPrintf("%p %s\n", elem, msg.c_str()); |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2141 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2142 | } |
| 2143 | size_t num_fields = dex_cache->NumResolvedFields(); |
| 2144 | if (num_fields != 0u) { |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2145 | os << "Fields (size=" << num_fields << "):\n"; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2146 | ScopedIndentation indent2(&state->vios_); |
| 2147 | auto* resolved_fields = dex_cache->GetResolvedFields(); |
| 2148 | for (size_t i = 0, length = dex_cache->NumResolvedFields(); i < length; ++i) { |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2149 | auto* elem = mirror::DexCache::GetElementPtrSize( |
| 2150 | resolved_fields, i, image_pointer_size); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2151 | size_t run = 0; |
| 2152 | for (size_t j = i + 1; |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2153 | j != length && elem == mirror::DexCache::GetElementPtrSize(resolved_fields, |
| 2154 | j, |
| 2155 | image_pointer_size); |
| 2156 | ++j) { |
| 2157 | ++run; |
| 2158 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2159 | if (run == 0) { |
| 2160 | os << StringPrintf("%zd: ", i); |
| 2161 | } else { |
| 2162 | os << StringPrintf("%zd to %zd: ", i, i + run); |
| 2163 | i = i + run; |
| 2164 | } |
| 2165 | std::string msg; |
| 2166 | if (elem == nullptr) { |
| 2167 | msg = "null"; |
| 2168 | } else if (field_section.Contains( |
| 2169 | reinterpret_cast<uint8_t*>(elem) - state->image_space_.Begin())) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2170 | msg = reinterpret_cast<ArtField*>(elem)->PrettyField(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2171 | } else { |
| 2172 | msg = "<not in field section>"; |
| 2173 | } |
| 2174 | os << StringPrintf("%p %s\n", elem, msg.c_str()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2175 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2176 | } |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2177 | size_t num_types = dex_cache->NumResolvedTypes(); |
| 2178 | if (num_types != 0u) { |
| 2179 | os << "Types (size=" << num_types << "):\n"; |
| 2180 | ScopedIndentation indent2(&state->vios_); |
| 2181 | auto* resolved_types = dex_cache->GetResolvedTypes(); |
| 2182 | for (size_t i = 0; i < num_types; ++i) { |
| 2183 | auto* elem = resolved_types[i].Read(); |
| 2184 | size_t run = 0; |
| 2185 | for (size_t j = i + 1; j != num_types && elem == resolved_types[j].Read(); ++j) { |
| 2186 | ++run; |
| 2187 | } |
| 2188 | if (run == 0) { |
| 2189 | os << StringPrintf("%zd: ", i); |
| 2190 | } else { |
| 2191 | os << StringPrintf("%zd to %zd: ", i, i + run); |
| 2192 | i = i + run; |
| 2193 | } |
| 2194 | std::string msg; |
| 2195 | if (elem == nullptr) { |
| 2196 | msg = "null"; |
| 2197 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2198 | msg = elem->PrettyClass(); |
Nicolas Geoffray | c6df1e3 | 2016-07-04 10:15:47 +0100 | [diff] [blame] | 2199 | } |
| 2200 | os << StringPrintf("%p %s\n", elem, msg.c_str()); |
| 2201 | } |
| 2202 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2203 | } |
| 2204 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2205 | std::string temp; |
| 2206 | state->stats_.Update(obj_class->GetDescriptor(&temp), object_bytes); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2207 | } |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 2208 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2209 | void DumpMethod(ArtMethod* method, std::ostream& indent_os) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2210 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2211 | DCHECK(method != nullptr); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2212 | const void* quick_oat_code_begin = GetQuickOatCodeBegin(method); |
| 2213 | const void* quick_oat_code_end = GetQuickOatCodeEnd(method); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2214 | const PointerSize pointer_size = image_header_.GetPointerSize(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2215 | OatQuickMethodHeader* method_header = reinterpret_cast<OatQuickMethodHeader*>( |
| 2216 | reinterpret_cast<uintptr_t>(quick_oat_code_begin) - sizeof(OatQuickMethodHeader)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2217 | if (method->IsNative()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2218 | bool first_occurrence; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2219 | uint32_t quick_oat_code_size = GetQuickOatCodeSize(method); |
| 2220 | ComputeOatSize(quick_oat_code_begin, &first_occurrence); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2221 | if (first_occurrence) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2222 | stats_.native_to_managed_code_bytes += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2223 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2224 | if (quick_oat_code_begin != method->GetEntryPointFromQuickCompiledCodePtrSize( |
| 2225 | image_header_.GetPointerSize())) { |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 2226 | indent_os << StringPrintf("OAT CODE: %p\n", quick_oat_code_begin); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2227 | } |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 2228 | } else if (method->IsAbstract() || method->IsClassInitializer()) { |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2229 | // Don't print information for these. |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 2230 | } else if (method->IsRuntimeMethod()) { |
| 2231 | ImtConflictTable* table = method->GetImtConflictTable(image_header_.GetPointerSize()); |
| 2232 | if (table != nullptr) { |
| 2233 | indent_os << "IMT conflict table " << table << " method: "; |
| 2234 | for (size_t i = 0, count = table->NumEntries(pointer_size); i < count; ++i) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2235 | indent_os << ArtMethod::PrettyMethod(table->GetImplementationMethod(i, pointer_size)) |
| 2236 | << " "; |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2239 | } else { |
| 2240 | const DexFile::CodeItem* code_item = method->GetCodeItem(); |
| 2241 | size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2242 | stats_.dex_instruction_bytes += dex_instruction_bytes; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2243 | |
| 2244 | bool first_occurrence; |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2245 | size_t vmap_table_bytes = 0u; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 2246 | if (!method_header->IsOptimized()) { |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2247 | // Method compiled with the optimizing compiler have no vmap table. |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2248 | vmap_table_bytes = ComputeOatSize(method_header->GetVmapTable(), &first_occurrence); |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2249 | if (first_occurrence) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2250 | stats_.vmap_table_bytes += vmap_table_bytes; |
Roland Levillain | 6d7f179 | 2015-07-02 10:59:15 +0100 | [diff] [blame] | 2251 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2254 | uint32_t quick_oat_code_size = GetQuickOatCodeSize(method); |
| 2255 | ComputeOatSize(quick_oat_code_begin, &first_occurrence); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2256 | if (first_occurrence) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2257 | stats_.managed_code_bytes += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2258 | if (method->IsConstructor()) { |
| 2259 | if (method->IsStatic()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2260 | stats_.class_initializer_code_bytes += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2261 | } else if (dex_instruction_bytes > kLargeConstructorDexBytes) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2262 | stats_.large_initializer_code_bytes += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2263 | } |
| 2264 | } else if (dex_instruction_bytes > kLargeMethodDexBytes) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2265 | stats_.large_method_code_bytes += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2268 | stats_.managed_code_bytes_ignoring_deduplication += quick_oat_code_size; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2269 | |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 2270 | uint32_t method_access_flags = method->GetAccessFlags(); |
| 2271 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2272 | indent_os << StringPrintf("OAT CODE: %p-%p\n", quick_oat_code_begin, quick_oat_code_end); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 2273 | indent_os << StringPrintf("SIZE: Dex Instructions=%zd StackMaps=%zd AccessFlags=0x%x\n", |
| 2274 | dex_instruction_bytes, |
| 2275 | vmap_table_bytes, |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 2276 | method_access_flags); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2277 | |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 2278 | size_t total_size = dex_instruction_bytes + |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2279 | vmap_table_bytes + quick_oat_code_size + ArtMethod::Size(image_header_.GetPointerSize()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2280 | |
| 2281 | double expansion = |
| 2282 | static_cast<double>(quick_oat_code_size) / static_cast<double>(dex_instruction_bytes); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2283 | stats_.ComputeOutliers(total_size, expansion, method); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2287 | std::set<const void*> already_seen_; |
| 2288 | // Compute the size of the given data within the oat file and whether this is the first time |
| 2289 | // this data has been requested |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2290 | size_t ComputeOatSize(const void* oat_data, bool* first_occurrence) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2291 | if (already_seen_.count(oat_data) == 0) { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2292 | *first_occurrence = true; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2293 | already_seen_.insert(oat_data); |
| 2294 | } else { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2295 | *first_occurrence = false; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2296 | } |
| 2297 | return oat_dumper_->ComputeSize(oat_data); |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 2298 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2299 | |
| 2300 | public: |
| 2301 | struct Stats { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2302 | size_t oat_file_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2303 | size_t file_bytes; |
| 2304 | |
| 2305 | size_t header_bytes; |
| 2306 | size_t object_bytes; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2307 | size_t art_field_bytes; |
| 2308 | size_t art_method_bytes; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2309 | size_t dex_cache_arrays_bytes; |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2310 | size_t interned_strings_bytes; |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2311 | size_t class_table_bytes; |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2312 | size_t bitmap_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2313 | size_t alignment_bytes; |
| 2314 | |
| 2315 | size_t managed_code_bytes; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2316 | size_t managed_code_bytes_ignoring_deduplication; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2317 | size_t native_to_managed_code_bytes; |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2318 | size_t class_initializer_code_bytes; |
| 2319 | size_t large_initializer_code_bytes; |
| 2320 | size_t large_method_code_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2321 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2322 | size_t vmap_table_bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2323 | |
| 2324 | size_t dex_instruction_bytes; |
| 2325 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2326 | std::vector<ArtMethod*> method_outlier; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2327 | std::vector<size_t> method_outlier_size; |
| 2328 | std::vector<double> method_outlier_expansion; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 2329 | std::vector<std::pair<std::string, size_t>> oat_dex_file_sizes; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2330 | |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 2331 | Stats() |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2332 | : oat_file_bytes(0), |
| 2333 | file_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2334 | header_bytes(0), |
| 2335 | object_bytes(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2336 | art_field_bytes(0), |
| 2337 | art_method_bytes(0), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2338 | dex_cache_arrays_bytes(0), |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2339 | interned_strings_bytes(0), |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2340 | class_table_bytes(0), |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2341 | bitmap_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2342 | alignment_bytes(0), |
| 2343 | managed_code_bytes(0), |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2344 | managed_code_bytes_ignoring_deduplication(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2345 | native_to_managed_code_bytes(0), |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2346 | class_initializer_code_bytes(0), |
| 2347 | large_initializer_code_bytes(0), |
| 2348 | large_method_code_bytes(0), |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2349 | vmap_table_bytes(0), |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2350 | dex_instruction_bytes(0) {} |
| 2351 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2352 | struct SizeAndCount { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2353 | 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] | 2354 | size_t bytes; |
| 2355 | size_t count; |
| 2356 | }; |
| 2357 | typedef SafeMap<std::string, SizeAndCount> SizeAndCountTable; |
| 2358 | SizeAndCountTable sizes_and_counts; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2359 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2360 | void Update(const char* descriptor, size_t object_bytes_in) { |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2361 | SizeAndCountTable::iterator it = sizes_and_counts.find(descriptor); |
| 2362 | if (it != sizes_and_counts.end()) { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2363 | it->second.bytes += object_bytes_in; |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2364 | it->second.count += 1; |
| 2365 | } else { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 2366 | sizes_and_counts.Put(descriptor, SizeAndCount(object_bytes_in, 1)); |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2367 | } |
| 2368 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2369 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2370 | double PercentOfOatBytes(size_t size) { |
| 2371 | return (static_cast<double>(size) / static_cast<double>(oat_file_bytes)) * 100; |
| 2372 | } |
| 2373 | |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2374 | double PercentOfFileBytes(size_t size) { |
| 2375 | return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100; |
| 2376 | } |
| 2377 | |
| 2378 | double PercentOfObjectBytes(size_t size) { |
| 2379 | return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100; |
| 2380 | } |
| 2381 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2382 | void ComputeOutliers(size_t total_size, double expansion, ArtMethod* method) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2383 | method_outlier_size.push_back(total_size); |
| 2384 | method_outlier_expansion.push_back(expansion); |
| 2385 | method_outlier.push_back(method); |
| 2386 | } |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2387 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2388 | void DumpOutliers(std::ostream& os) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2389 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2390 | size_t sum_of_sizes = 0; |
| 2391 | size_t sum_of_sizes_squared = 0; |
| 2392 | size_t sum_of_expansion = 0; |
| 2393 | size_t sum_of_expansion_squared = 0; |
| 2394 | size_t n = method_outlier_size.size(); |
Mathieu Chartier | 1ebf8d3 | 2016-06-09 11:51:27 -0700 | [diff] [blame] | 2395 | if (n <= 1) { |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2396 | return; |
| 2397 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2398 | for (size_t i = 0; i < n; i++) { |
| 2399 | size_t cur_size = method_outlier_size[i]; |
| 2400 | sum_of_sizes += cur_size; |
| 2401 | sum_of_sizes_squared += cur_size * cur_size; |
| 2402 | double cur_expansion = method_outlier_expansion[i]; |
| 2403 | sum_of_expansion += cur_expansion; |
| 2404 | sum_of_expansion_squared += cur_expansion * cur_expansion; |
| 2405 | } |
| 2406 | size_t size_mean = sum_of_sizes / n; |
| 2407 | size_t size_variance = (sum_of_sizes_squared - sum_of_sizes * size_mean) / (n - 1); |
| 2408 | double expansion_mean = sum_of_expansion / n; |
| 2409 | double expansion_variance = |
| 2410 | (sum_of_expansion_squared - sum_of_expansion * expansion_mean) / (n - 1); |
| 2411 | |
| 2412 | // Dump methods whose size is a certain number of standard deviations from the mean |
| 2413 | size_t dumped_values = 0; |
| 2414 | size_t skipped_values = 0; |
| 2415 | for (size_t i = 100; i > 0; i--) { // i is the current number of standard deviations |
| 2416 | size_t cur_size_variance = i * i * size_variance; |
| 2417 | bool first = true; |
| 2418 | for (size_t j = 0; j < n; j++) { |
| 2419 | size_t cur_size = method_outlier_size[j]; |
| 2420 | if (cur_size > size_mean) { |
| 2421 | size_t cur_var = cur_size - size_mean; |
| 2422 | cur_var = cur_var * cur_var; |
| 2423 | if (cur_var > cur_size_variance) { |
| 2424 | if (dumped_values > 20) { |
| 2425 | if (i == 1) { |
| 2426 | skipped_values++; |
| 2427 | } else { |
| 2428 | i = 2; // jump to counting for 1 standard deviation |
| 2429 | break; |
| 2430 | } |
| 2431 | } else { |
| 2432 | if (first) { |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2433 | os << "\nBig methods (size > " << i << " standard deviations the norm):\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2434 | first = false; |
| 2435 | } |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2436 | os << ArtMethod::PrettyMethod(method_outlier[j]) << " requires storage of " |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2437 | << PrettySize(cur_size) << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2438 | method_outlier_size[j] = 0; // don't consider this method again |
| 2439 | dumped_values++; |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | if (skipped_values > 0) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2446 | os << "... skipped " << skipped_values |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2447 | << " methods with size > 1 standard deviation from the norm\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2448 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2449 | os << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2450 | |
| 2451 | // Dump methods whose expansion is a certain number of standard deviations from the mean |
| 2452 | dumped_values = 0; |
| 2453 | skipped_values = 0; |
| 2454 | for (size_t i = 10; i > 0; i--) { // i is the current number of standard deviations |
| 2455 | double cur_expansion_variance = i * i * expansion_variance; |
| 2456 | bool first = true; |
| 2457 | for (size_t j = 0; j < n; j++) { |
| 2458 | double cur_expansion = method_outlier_expansion[j]; |
| 2459 | if (cur_expansion > expansion_mean) { |
| 2460 | size_t cur_var = cur_expansion - expansion_mean; |
| 2461 | cur_var = cur_var * cur_var; |
| 2462 | if (cur_var > cur_expansion_variance) { |
| 2463 | if (dumped_values > 20) { |
| 2464 | if (i == 1) { |
| 2465 | skipped_values++; |
| 2466 | } else { |
| 2467 | i = 2; // jump to counting for 1 standard deviation |
| 2468 | break; |
| 2469 | } |
| 2470 | } else { |
| 2471 | if (first) { |
| 2472 | os << "\nLarge expansion methods (size > " << i |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2473 | << " standard deviations the norm):\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2474 | first = false; |
| 2475 | } |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2476 | os << ArtMethod::PrettyMethod(method_outlier[j]) << " expanded code by " |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2477 | << cur_expansion << "\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2478 | method_outlier_expansion[j] = 0.0; // don't consider this method again |
| 2479 | dumped_values++; |
| 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | if (skipped_values > 0) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2486 | os << "... skipped " << skipped_values |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2487 | << " methods with expansion > 1 standard deviation from the norm\n"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2488 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2489 | os << "\n" << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2490 | } |
| 2491 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2492 | void Dump(std::ostream& os, std::ostream& indent_os) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2493 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2494 | { |
| 2495 | os << "art_file_bytes = " << PrettySize(file_bytes) << "\n\n" |
| 2496 | << "art_file_bytes = header_bytes + object_bytes + alignment_bytes\n"; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2497 | indent_os << StringPrintf("header_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2498 | "object_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2499 | "art_field_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2500 | "art_method_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2501 | "dex_cache_arrays_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2502 | "interned_string_bytes = %8zd (%2.0f%% of art file bytes)\n" |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2503 | "class_table_bytes = %8zd (%2.0f%% of art file bytes)\n" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2504 | "bitmap_bytes = %8zd (%2.0f%% of art file bytes)\n" |
| 2505 | "alignment_bytes = %8zd (%2.0f%% of art file bytes)\n\n", |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2506 | header_bytes, PercentOfFileBytes(header_bytes), |
| 2507 | object_bytes, PercentOfFileBytes(object_bytes), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2508 | art_field_bytes, PercentOfFileBytes(art_field_bytes), |
| 2509 | art_method_bytes, PercentOfFileBytes(art_method_bytes), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2510 | dex_cache_arrays_bytes, |
| 2511 | PercentOfFileBytes(dex_cache_arrays_bytes), |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 2512 | interned_strings_bytes, |
| 2513 | PercentOfFileBytes(interned_strings_bytes), |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2514 | class_table_bytes, PercentOfFileBytes(class_table_bytes), |
Mathieu Chartier | 3232709 | 2013-08-30 14:04:08 -0700 | [diff] [blame] | 2515 | bitmap_bytes, PercentOfFileBytes(bitmap_bytes), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2516 | alignment_bytes, PercentOfFileBytes(alignment_bytes)) |
| 2517 | << std::flush; |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 2518 | CHECK_EQ(file_bytes, |
| 2519 | header_bytes + object_bytes + art_field_bytes + art_method_bytes + |
| 2520 | dex_cache_arrays_bytes + interned_strings_bytes + class_table_bytes + |
| 2521 | bitmap_bytes + alignment_bytes); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2522 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2523 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2524 | os << "object_bytes breakdown:\n"; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2525 | size_t object_bytes_total = 0; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2526 | for (const auto& sizes_and_count : sizes_and_counts) { |
| 2527 | const std::string& descriptor(sizes_and_count.first); |
| 2528 | double average = static_cast<double>(sizes_and_count.second.bytes) / |
| 2529 | static_cast<double>(sizes_and_count.second.count); |
| 2530 | double percent = PercentOfObjectBytes(sizes_and_count.second.bytes); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2531 | os << StringPrintf("%32s %8zd bytes %6zd instances " |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 2532 | "(%4.0f bytes/instance) %2.0f%% of object_bytes\n", |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2533 | descriptor.c_str(), sizes_and_count.second.bytes, |
| 2534 | sizes_and_count.second.count, average, percent); |
| 2535 | object_bytes_total += sizes_and_count.second.bytes; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2536 | } |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2537 | os << "\n" << std::flush; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2538 | CHECK_EQ(object_bytes, object_bytes_total); |
| 2539 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2540 | os << StringPrintf("oat_file_bytes = %8zd\n" |
| 2541 | "managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2542 | "native_to_managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n" |
| 2543 | "class_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2544 | "large_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n" |
| 2545 | "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] | 2546 | oat_file_bytes, |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2547 | managed_code_bytes, |
| 2548 | PercentOfOatBytes(managed_code_bytes), |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2549 | native_to_managed_code_bytes, |
| 2550 | PercentOfOatBytes(native_to_managed_code_bytes), |
| 2551 | class_initializer_code_bytes, |
| 2552 | PercentOfOatBytes(class_initializer_code_bytes), |
| 2553 | large_initializer_code_bytes, |
| 2554 | PercentOfOatBytes(large_initializer_code_bytes), |
| 2555 | large_method_code_bytes, |
| 2556 | PercentOfOatBytes(large_method_code_bytes)) |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2557 | << "DexFile sizes:\n"; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2558 | 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] | 2559 | os << StringPrintf("%s = %zd (%2.0f%% of oat file bytes)\n", |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 2560 | oat_dex_file_size.first.c_str(), oat_dex_file_size.second, |
| 2561 | PercentOfOatBytes(oat_dex_file_size.second)); |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 2564 | os << "\n" << StringPrintf("vmap_table_bytes = %7zd (%2.0f%% of oat file bytes)\n\n", |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 2565 | vmap_table_bytes, PercentOfOatBytes(vmap_table_bytes)) |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2566 | << std::flush; |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2567 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2568 | os << StringPrintf("dex_instruction_bytes = %zd\n", dex_instruction_bytes) |
| 2569 | << StringPrintf("managed_code_bytes expansion = %.2f (ignoring deduplication %.2f)\n\n", |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 2570 | static_cast<double>(managed_code_bytes) / |
| 2571 | static_cast<double>(dex_instruction_bytes), |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2572 | static_cast<double>(managed_code_bytes_ignoring_deduplication) / |
Elliott Hughes | cf44e6f | 2012-05-24 19:42:18 -0700 | [diff] [blame] | 2573 | static_cast<double>(dex_instruction_bytes)) |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 2574 | << std::flush; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2575 | |
| 2576 | DumpOutliers(os); |
Brian Carlstrom | 916e74e | 2011-09-23 11:42:01 -0700 | [diff] [blame] | 2577 | } |
| 2578 | } stats_; |
| 2579 | |
| 2580 | private: |
Ian Rogers | 0d2d378 | 2012-04-10 11:09:18 -0700 | [diff] [blame] | 2581 | enum { |
| 2582 | // Number of bytes for a constructor to be considered large. Based on the 1000 basic block |
| 2583 | // threshold, we assume 2 bytes per instruction and 2 instructions per block. |
| 2584 | kLargeConstructorDexBytes = 4000, |
| 2585 | // Number of bytes for a method to be considered large. Based on the 4000 basic block |
| 2586 | // threshold, we assume 2 bytes per instruction and 2 instructions per block. |
| 2587 | kLargeMethodDexBytes = 16000 |
| 2588 | }; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2589 | |
| 2590 | // For performance, use the *os_ directly for anything that doesn't need indentation |
| 2591 | // and prepare an indentation stream with default indentation 1. |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2592 | std::ostream* os_; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 2593 | VariableIndentationOutputStream vios_; |
| 2594 | ScopedIndentation indent1_; |
| 2595 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 2596 | gc::space::ImageSpace& image_space_; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2597 | const ImageHeader& image_header_; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 2598 | std::unique_ptr<OatDumper> oat_dumper_; |
Andreas Gampe | df2bb1f | 2015-05-04 18:25:23 -0700 | [diff] [blame] | 2599 | OatDumperOptions* oat_dumper_options_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2600 | std::set<mirror::Object*> dex_caches_; |
Elliott Hughes | d1bb4f6 | 2011-09-23 14:09:45 -0700 | [diff] [blame] | 2601 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 2602 | DISALLOW_COPY_AND_ASSIGN(ImageDumper); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2603 | }; |
| 2604 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2605 | static int DumpImage(gc::space::ImageSpace* image_space, |
| 2606 | OatDumperOptions* options, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2607 | std::ostream* os) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2608 | const ImageHeader& image_header = image_space->GetImageHeader(); |
| 2609 | if (!image_header.IsValid()) { |
| 2610 | fprintf(stderr, "Invalid image header %s\n", image_space->GetImageLocation().c_str()); |
| 2611 | return EXIT_FAILURE; |
| 2612 | } |
| 2613 | ImageDumper image_dumper(os, *image_space, image_header, options); |
| 2614 | if (!image_dumper.Dump()) { |
| 2615 | return EXIT_FAILURE; |
| 2616 | } |
| 2617 | return EXIT_SUCCESS; |
| 2618 | } |
| 2619 | |
| 2620 | static int DumpImages(Runtime* runtime, OatDumperOptions* options, std::ostream* os) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2621 | // Dumping the image, no explicit class loader. |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 2622 | ScopedNullHandle<mirror::ClassLoader> null_class_loader; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2623 | options->class_loader_ = &null_class_loader; |
| 2624 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 2625 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2626 | if (options->app_image_ != nullptr) { |
| 2627 | if (options->app_oat_ == nullptr) { |
| 2628 | LOG(ERROR) << "Can not dump app image without app oat file"; |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2629 | return EXIT_FAILURE; |
| 2630 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2631 | // We can't know if the app image is 32 bits yet, but it contains pointers into the oat file. |
| 2632 | // We need to map the oat file in the low 4gb or else the fixup wont be able to fit oat file |
| 2633 | // pointers into 32 bit pointer sized ArtMethods. |
| 2634 | std::string error_msg; |
| 2635 | std::unique_ptr<OatFile> oat_file(OatFile::Open(options->app_oat_, |
| 2636 | options->app_oat_, |
| 2637 | nullptr, |
| 2638 | nullptr, |
| 2639 | false, |
| 2640 | /*low_4gb*/true, |
| 2641 | nullptr, |
| 2642 | &error_msg)); |
| 2643 | if (oat_file == nullptr) { |
| 2644 | LOG(ERROR) << "Failed to open oat file " << options->app_oat_ << " with error " << error_msg; |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2645 | return EXIT_FAILURE; |
| 2646 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2647 | std::unique_ptr<gc::space::ImageSpace> space( |
| 2648 | gc::space::ImageSpace::CreateFromAppImage(options->app_image_, oat_file.get(), &error_msg)); |
| 2649 | if (space == nullptr) { |
| 2650 | LOG(ERROR) << "Failed to open app image " << options->app_image_ << " with error " |
| 2651 | << error_msg; |
| 2652 | } |
| 2653 | // Open dex files for the image. |
| 2654 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 2655 | if (!runtime->GetClassLinker()->OpenImageDexFiles(space.get(), &dex_files, &error_msg)) { |
| 2656 | LOG(ERROR) << "Failed to open app image dex files " << options->app_image_ << " with error " |
| 2657 | << error_msg; |
| 2658 | } |
| 2659 | // Dump the actual image. |
| 2660 | int result = DumpImage(space.get(), options, os); |
| 2661 | if (result != EXIT_SUCCESS) { |
| 2662 | return result; |
| 2663 | } |
| 2664 | // Fall through to dump the boot images. |
| 2665 | } |
| 2666 | |
| 2667 | gc::Heap* heap = runtime->GetHeap(); |
| 2668 | CHECK(heap->HasBootImageSpace()) << "No image spaces"; |
| 2669 | for (gc::space::ImageSpace* image_space : heap->GetBootImageSpaces()) { |
| 2670 | int result = DumpImage(image_space, options, os); |
| 2671 | if (result != EXIT_SUCCESS) { |
| 2672 | return result; |
| 2673 | } |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2674 | } |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 2675 | return EXIT_SUCCESS; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2678 | static jobject InstallOatFile(Runtime* runtime, |
| 2679 | std::unique_ptr<OatFile> oat_file, |
| 2680 | std::vector<const DexFile*>* class_path) |
| 2681 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2682 | Thread* self = Thread::Current(); |
| 2683 | CHECK(self != nullptr); |
| 2684 | // Need well-known-classes. |
| 2685 | WellKnownClasses::Init(self->GetJniEnv()); |
| 2686 | |
| 2687 | // Need to register dex files to get a working dex cache. |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2688 | OatFile* oat_file_ptr = oat_file.get(); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2689 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2690 | runtime->GetOatFileManager().RegisterOatFile(std::move(oat_file)); |
| 2691 | for (const OatFile::OatDexFile* odf : oat_file_ptr->GetOatDexFiles()) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2692 | std::string error_msg; |
Mathieu Chartier | ac8f439 | 2015-08-27 13:54:20 -0700 | [diff] [blame] | 2693 | const DexFile* const dex_file = OpenDexFile(odf, &error_msg); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2694 | CHECK(dex_file != nullptr) << error_msg; |
Mathieu Chartier | f284d44 | 2016-06-02 11:48:30 -0700 | [diff] [blame] | 2695 | class_linker->RegisterDexFile(*dex_file, nullptr); |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2696 | class_path->push_back(dex_file); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2699 | // Need a class loader. Fake that we're a compiler. |
| 2700 | // Note: this will run initializers through the unstarted runtime, so make sure it's |
| 2701 | // initialized. |
| 2702 | interpreter::UnstartedRuntime::Initialize(); |
| 2703 | |
| 2704 | jobject class_loader = class_linker->CreatePathClassLoader(self, *class_path); |
| 2705 | |
| 2706 | return class_loader; |
| 2707 | } |
| 2708 | |
| 2709 | static int DumpOatWithRuntime(Runtime* runtime, |
| 2710 | std::unique_ptr<OatFile> oat_file, |
| 2711 | OatDumperOptions* options, |
| 2712 | std::ostream* os) { |
| 2713 | CHECK(runtime != nullptr && oat_file != nullptr && options != nullptr); |
| 2714 | ScopedObjectAccess soa(Thread::Current()); |
| 2715 | |
| 2716 | OatFile* oat_file_ptr = oat_file.get(); |
| 2717 | std::vector<const DexFile*> class_path; |
| 2718 | jobject class_loader = InstallOatFile(runtime, std::move(oat_file), &class_path); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2719 | |
| 2720 | // Use the class loader while dumping. |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2721 | StackHandleScope<1> scope(soa.Self()); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2722 | Handle<mirror::ClassLoader> loader_handle = scope.NewHandle( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 2723 | soa.Decode<mirror::ClassLoader>(class_loader)); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2724 | options->class_loader_ = &loader_handle; |
| 2725 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2726 | OatDumper oat_dumper(*oat_file_ptr, *options); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2727 | bool success = oat_dumper.Dump(*os); |
| 2728 | return (success) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 2729 | } |
| 2730 | |
| 2731 | static int DumpOatWithoutRuntime(OatFile* oat_file, OatDumperOptions* options, std::ostream* os) { |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2732 | CHECK(oat_file != nullptr && options != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2733 | // No image = no class loader. |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 2734 | ScopedNullHandle<mirror::ClassLoader> null_class_loader; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2735 | options->class_loader_ = &null_class_loader; |
| 2736 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 2737 | OatDumper oat_dumper(*oat_file, *options); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2738 | bool success = oat_dumper.Dump(*os); |
| 2739 | return (success) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 2740 | } |
| 2741 | |
| 2742 | static int DumpOat(Runtime* runtime, const char* oat_filename, OatDumperOptions* options, |
| 2743 | std::ostream* os) { |
| 2744 | std::string error_msg; |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2745 | std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_filename, |
| 2746 | oat_filename, |
| 2747 | nullptr, |
| 2748 | nullptr, |
| 2749 | false, |
| 2750 | /*low_4gb*/false, |
| 2751 | nullptr, |
| 2752 | &error_msg)); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2753 | if (oat_file == nullptr) { |
| 2754 | fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); |
| 2755 | return EXIT_FAILURE; |
| 2756 | } |
| 2757 | |
| 2758 | if (runtime != nullptr) { |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2759 | return DumpOatWithRuntime(runtime, std::move(oat_file), options, os); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2760 | } else { |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2761 | return DumpOatWithoutRuntime(oat_file.get(), options, os); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2762 | } |
| 2763 | } |
| 2764 | |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 2765 | static int SymbolizeOat(const char* oat_filename, std::string& output_name, bool no_bits) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2766 | std::string error_msg; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 2767 | OatFile* oat_file = OatFile::Open(oat_filename, |
| 2768 | oat_filename, |
| 2769 | nullptr, |
| 2770 | nullptr, |
| 2771 | false, |
| 2772 | /*low_4gb*/false, |
| 2773 | nullptr, |
| 2774 | &error_msg); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2775 | if (oat_file == nullptr) { |
| 2776 | fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); |
| 2777 | return EXIT_FAILURE; |
| 2778 | } |
| 2779 | |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2780 | bool result; |
| 2781 | // Try to produce an ELF file of the same type. This is finicky, as we have used 32-bit ELF |
| 2782 | // files for 64-bit code in the past. |
| 2783 | if (Is64BitInstructionSet(oat_file->GetOatHeader().GetInstructionSet())) { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 2784 | OatSymbolizer<ElfTypes64> oat_symbolizer(oat_file, output_name, no_bits); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2785 | result = oat_symbolizer.Symbolize(); |
| 2786 | } else { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 2787 | OatSymbolizer<ElfTypes32> oat_symbolizer(oat_file, output_name, no_bits); |
Andreas Gampe | 2d8614b | 2016-03-07 16:31:34 -0800 | [diff] [blame] | 2788 | result = oat_symbolizer.Symbolize(); |
| 2789 | } |
| 2790 | if (!result) { |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 2791 | fprintf(stderr, "Failed to symbolize\n"); |
| 2792 | return EXIT_FAILURE; |
| 2793 | } |
| 2794 | |
| 2795 | return EXIT_SUCCESS; |
| 2796 | } |
| 2797 | |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2798 | class IMTDumper { |
| 2799 | public: |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2800 | static bool Dump(Runtime* runtime, |
| 2801 | const std::string& imt_file, |
| 2802 | bool dump_imt_stats, |
| 2803 | const char* oat_filename) { |
| 2804 | Thread* self = Thread::Current(); |
| 2805 | |
| 2806 | ScopedObjectAccess soa(self); |
| 2807 | StackHandleScope<1> scope(self); |
| 2808 | MutableHandle<mirror::ClassLoader> class_loader = scope.NewHandle<mirror::ClassLoader>(nullptr); |
| 2809 | std::vector<const DexFile*> class_path; |
| 2810 | |
| 2811 | if (oat_filename != nullptr) { |
| 2812 | std::string error_msg; |
| 2813 | std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_filename, |
| 2814 | oat_filename, |
| 2815 | nullptr, |
| 2816 | nullptr, |
| 2817 | false, |
| 2818 | /*low_4gb*/false, |
| 2819 | nullptr, |
| 2820 | &error_msg)); |
| 2821 | if (oat_file == nullptr) { |
| 2822 | fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); |
| 2823 | return false; |
| 2824 | } |
| 2825 | |
| 2826 | class_loader.Assign(soa.Decode<mirror::ClassLoader>( |
| 2827 | InstallOatFile(runtime, std::move(oat_file), &class_path))); |
| 2828 | } else { |
| 2829 | class_loader.Assign(nullptr); // Boot classloader. Just here for explicit documentation. |
| 2830 | class_path = runtime->GetClassLinker()->GetBootClassPath(); |
| 2831 | } |
| 2832 | |
| 2833 | if (!imt_file.empty()) { |
| 2834 | return DumpImt(runtime, imt_file, class_loader); |
| 2835 | } |
| 2836 | |
| 2837 | if (dump_imt_stats) { |
| 2838 | return DumpImtStats(runtime, class_path, class_loader); |
| 2839 | } |
| 2840 | |
| 2841 | LOG(FATAL) << "Should not reach here"; |
| 2842 | UNREACHABLE(); |
| 2843 | } |
| 2844 | |
| 2845 | private: |
| 2846 | static bool DumpImt(Runtime* runtime, |
| 2847 | const std::string& imt_file, |
| 2848 | Handle<mirror::ClassLoader> h_class_loader) |
| 2849 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2850 | std::vector<std::string> lines = ReadCommentedInputFromFile(imt_file); |
| 2851 | std::unordered_set<std::string> prepared; |
| 2852 | |
| 2853 | for (const std::string& line : lines) { |
| 2854 | // A line should be either a class descriptor, in which case we will dump the complete IMT, |
| 2855 | // or a class descriptor and an interface method, in which case we will lookup the method, |
| 2856 | // determine its IMT slot, and check the class' IMT. |
| 2857 | size_t first_space = line.find(' '); |
| 2858 | if (first_space == std::string::npos) { |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2859 | DumpIMTForClass(runtime, line, h_class_loader, &prepared); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2860 | } else { |
| 2861 | DumpIMTForMethod(runtime, |
| 2862 | line.substr(0, first_space), |
| 2863 | line.substr(first_space + 1, std::string::npos), |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2864 | h_class_loader, |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2865 | &prepared); |
| 2866 | } |
| 2867 | std::cerr << std::endl; |
| 2868 | } |
| 2869 | |
| 2870 | return true; |
| 2871 | } |
| 2872 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2873 | static bool DumpImtStats(Runtime* runtime, |
| 2874 | const std::vector<const DexFile*>& dex_files, |
| 2875 | Handle<mirror::ClassLoader> h_class_loader) |
| 2876 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2877 | size_t without_imt = 0; |
| 2878 | size_t with_imt = 0; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2879 | std::map<size_t, size_t> histogram; |
| 2880 | |
| 2881 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 2882 | const PointerSize pointer_size = class_linker->GetImagePointerSize(); |
| 2883 | std::unordered_set<std::string> prepared; |
| 2884 | |
| 2885 | Thread* self = Thread::Current(); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2886 | StackHandleScope<1> scope(self); |
| 2887 | MutableHandle<mirror::Class> h_klass(scope.NewHandle<mirror::Class>(nullptr)); |
| 2888 | |
| 2889 | for (const DexFile* dex_file : dex_files) { |
| 2890 | for (uint32_t class_def_index = 0; |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2891 | class_def_index != dex_file->NumClassDefs(); |
| 2892 | ++class_def_index) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2893 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); |
| 2894 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2895 | h_klass.Assign(class_linker->FindClass(self, descriptor, h_class_loader)); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2896 | if (h_klass.Get() == nullptr) { |
| 2897 | std::cerr << "Warning: could not load " << descriptor << std::endl; |
| 2898 | continue; |
| 2899 | } |
| 2900 | |
| 2901 | if (HasNoIMT(runtime, h_klass, pointer_size, &prepared)) { |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2902 | without_imt++; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2903 | continue; |
| 2904 | } |
| 2905 | |
| 2906 | ImTable* im_table = PrepareAndGetImTable(runtime, h_klass, pointer_size, &prepared); |
| 2907 | if (im_table == nullptr) { |
| 2908 | // Should not happen, but accept. |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2909 | without_imt++; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2910 | continue; |
| 2911 | } |
| 2912 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2913 | with_imt++; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2914 | for (size_t imt_index = 0; imt_index != ImTable::kSize; ++imt_index) { |
| 2915 | ArtMethod* ptr = im_table->Get(imt_index, pointer_size); |
| 2916 | if (ptr->IsRuntimeMethod()) { |
| 2917 | if (ptr->IsImtUnimplementedMethod()) { |
| 2918 | histogram[0]++; |
| 2919 | } else { |
| 2920 | ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size); |
| 2921 | histogram[current_table->NumEntries(pointer_size)]++; |
| 2922 | } |
| 2923 | } else { |
| 2924 | histogram[1]++; |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | std::cerr << "IMT stats:" |
| 2931 | << std::endl << std::endl; |
| 2932 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2933 | std::cerr << " " << with_imt << " classes with IMT." |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2934 | << std::endl << std::endl; |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2935 | std::cerr << " " << without_imt << " classes without IMT (or copy from Object)." |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2936 | << std::endl << std::endl; |
| 2937 | |
| 2938 | double sum_one = 0; |
| 2939 | size_t count_one = 0; |
| 2940 | |
| 2941 | std::cerr << " " << "IMT histogram" << std::endl; |
| 2942 | for (auto& bucket : histogram) { |
| 2943 | std::cerr << " " << bucket.first << " " << bucket.second << std::endl; |
| 2944 | if (bucket.first > 0) { |
| 2945 | sum_one += bucket.second * bucket.first; |
| 2946 | count_one += bucket.second; |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | double count_zero = count_one + histogram[0]; |
| 2951 | std::cerr << " Stats:" << std::endl; |
| 2952 | std::cerr << " Average depth (including empty): " << (sum_one / count_zero) << std::endl; |
| 2953 | std::cerr << " Average depth (excluding empty): " << (sum_one / count_one) << std::endl; |
| 2954 | |
| 2955 | return true; |
| 2956 | } |
| 2957 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 2958 | // Return whether the given class has no IMT (or the one shared with java.lang.Object). |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2959 | static bool HasNoIMT(Runtime* runtime, |
| 2960 | Handle<mirror::Class> klass, |
| 2961 | const PointerSize pointer_size, |
| 2962 | std::unordered_set<std::string>* prepared) |
| 2963 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2964 | if (klass->IsObjectClass() || !klass->ShouldHaveImt()) { |
| 2965 | return true; |
| 2966 | } |
| 2967 | |
| 2968 | if (klass->GetImt(pointer_size) == nullptr) { |
| 2969 | PrepareClass(runtime, klass, prepared); |
| 2970 | } |
| 2971 | |
| 2972 | mirror::Class* object_class = mirror::Class::GetJavaLangClass()->GetSuperClass(); |
| 2973 | DCHECK(object_class->IsObjectClass()); |
| 2974 | |
| 2975 | bool result = klass->GetImt(pointer_size) == object_class->GetImt(pointer_size); |
| 2976 | |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 2977 | if (klass->GetIfTable()->Count() == 0) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2978 | DCHECK(result); |
| 2979 | } |
| 2980 | |
| 2981 | return result; |
| 2982 | } |
| 2983 | |
| 2984 | static void PrintTable(ImtConflictTable* table, PointerSize pointer_size) |
| 2985 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2986 | if (table == nullptr) { |
| 2987 | std::cerr << " <No IMT?>" << std::endl; |
| 2988 | return; |
| 2989 | } |
| 2990 | size_t table_index = 0; |
| 2991 | for (;;) { |
| 2992 | ArtMethod* ptr = table->GetInterfaceMethod(table_index, pointer_size); |
| 2993 | if (ptr == nullptr) { |
| 2994 | return; |
| 2995 | } |
| 2996 | table_index++; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2997 | std::cerr << " " << ptr->PrettyMethod(true) << std::endl; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | static ImTable* PrepareAndGetImTable(Runtime* runtime, |
| 3002 | Thread* self, |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3003 | Handle<mirror::ClassLoader> h_loader, |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3004 | const std::string& class_name, |
| 3005 | const PointerSize pointer_size, |
| 3006 | mirror::Class** klass_out, |
| 3007 | std::unordered_set<std::string>* prepared) |
| 3008 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 3009 | if (class_name.empty()) { |
| 3010 | return nullptr; |
| 3011 | } |
| 3012 | |
| 3013 | std::string descriptor; |
| 3014 | if (class_name[0] == 'L') { |
| 3015 | descriptor = class_name; |
| 3016 | } else { |
| 3017 | descriptor = DotToDescriptor(class_name.c_str()); |
| 3018 | } |
| 3019 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3020 | mirror::Class* klass = runtime->GetClassLinker()->FindClass(self, descriptor.c_str(), h_loader); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3021 | |
| 3022 | if (klass == nullptr) { |
| 3023 | self->ClearException(); |
| 3024 | std::cerr << "Did not find " << class_name << std::endl; |
| 3025 | *klass_out = nullptr; |
| 3026 | return nullptr; |
| 3027 | } |
| 3028 | |
| 3029 | StackHandleScope<1> scope(Thread::Current()); |
| 3030 | Handle<mirror::Class> h_klass = scope.NewHandle<mirror::Class>(klass); |
| 3031 | |
| 3032 | ImTable* ret = PrepareAndGetImTable(runtime, h_klass, pointer_size, prepared); |
| 3033 | *klass_out = h_klass.Get(); |
| 3034 | return ret; |
| 3035 | } |
| 3036 | |
| 3037 | static ImTable* PrepareAndGetImTable(Runtime* runtime, |
| 3038 | Handle<mirror::Class> h_klass, |
| 3039 | const PointerSize pointer_size, |
| 3040 | std::unordered_set<std::string>* prepared) |
| 3041 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 3042 | PrepareClass(runtime, h_klass, prepared); |
| 3043 | return h_klass->GetImt(pointer_size); |
| 3044 | } |
| 3045 | |
| 3046 | static void DumpIMTForClass(Runtime* runtime, |
| 3047 | const std::string& class_name, |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3048 | Handle<mirror::ClassLoader> h_loader, |
| 3049 | std::unordered_set<std::string>* prepared) |
| 3050 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3051 | const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize(); |
| 3052 | mirror::Class* klass; |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3053 | ImTable* imt = PrepareAndGetImTable(runtime, |
| 3054 | Thread::Current(), |
| 3055 | h_loader, |
| 3056 | class_name, |
| 3057 | pointer_size, |
| 3058 | &klass, |
| 3059 | prepared); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3060 | if (imt == nullptr) { |
| 3061 | return; |
| 3062 | } |
| 3063 | |
| 3064 | std::cerr << class_name << std::endl << " IMT:" << std::endl; |
| 3065 | for (size_t index = 0; index < ImTable::kSize; ++index) { |
| 3066 | std::cerr << " " << index << ":" << std::endl; |
| 3067 | ArtMethod* ptr = imt->Get(index, pointer_size); |
| 3068 | if (ptr->IsRuntimeMethod()) { |
| 3069 | if (ptr->IsImtUnimplementedMethod()) { |
| 3070 | std::cerr << " <empty>" << std::endl; |
| 3071 | } else { |
| 3072 | ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size); |
| 3073 | PrintTable(current_table, pointer_size); |
| 3074 | } |
| 3075 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 3076 | std::cerr << " " << ptr->PrettyMethod(true) << std::endl; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | std::cerr << " Interfaces:" << std::endl; |
| 3081 | // Run through iftable, find methods that slot here, see if they fit. |
| 3082 | mirror::IfTable* if_table = klass->GetIfTable(); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3083 | for (size_t i = 0, num_interfaces = klass->GetIfTableCount(); i < num_interfaces; ++i) { |
| 3084 | mirror::Class* iface = if_table->GetInterface(i); |
| 3085 | std::string iface_name; |
| 3086 | std::cerr << " " << iface->GetDescriptor(&iface_name) << std::endl; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3087 | |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3088 | for (ArtMethod& iface_method : iface->GetVirtualMethods(pointer_size)) { |
| 3089 | uint32_t class_hash, name_hash, signature_hash; |
| 3090 | ImTable::GetImtHashComponents(&iface_method, &class_hash, &name_hash, &signature_hash); |
| 3091 | uint32_t imt_slot = ImTable::GetImtIndex(&iface_method); |
| 3092 | std::cerr << " " << iface_method.PrettyMethod(true) |
| 3093 | << " slot=" << imt_slot |
| 3094 | << std::hex |
| 3095 | << " class_hash=0x" << class_hash |
| 3096 | << " name_hash=0x" << name_hash |
| 3097 | << " signature_hash=0x" << signature_hash |
| 3098 | << std::dec |
| 3099 | << std::endl; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | static void DumpIMTForMethod(Runtime* runtime, |
| 3105 | const std::string& class_name, |
| 3106 | const std::string& method, |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3107 | Handle<mirror::ClassLoader> h_loader, |
| 3108 | std::unordered_set<std::string>* prepared) |
| 3109 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3110 | const PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize(); |
| 3111 | mirror::Class* klass; |
| 3112 | ImTable* imt = PrepareAndGetImTable(runtime, |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3113 | Thread::Current(), |
| 3114 | h_loader, |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3115 | class_name, |
| 3116 | pointer_size, |
| 3117 | &klass, |
| 3118 | prepared); |
| 3119 | if (imt == nullptr) { |
| 3120 | return; |
| 3121 | } |
| 3122 | |
| 3123 | std::cerr << class_name << " <" << method << ">" << std::endl; |
| 3124 | for (size_t index = 0; index < ImTable::kSize; ++index) { |
| 3125 | ArtMethod* ptr = imt->Get(index, pointer_size); |
| 3126 | if (ptr->IsRuntimeMethod()) { |
| 3127 | if (ptr->IsImtUnimplementedMethod()) { |
| 3128 | continue; |
| 3129 | } |
| 3130 | |
| 3131 | ImtConflictTable* current_table = ptr->GetImtConflictTable(pointer_size); |
| 3132 | if (current_table == nullptr) { |
| 3133 | continue; |
| 3134 | } |
| 3135 | |
| 3136 | size_t table_index = 0; |
| 3137 | for (;;) { |
| 3138 | ArtMethod* ptr2 = current_table->GetInterfaceMethod(table_index, pointer_size); |
| 3139 | if (ptr2 == nullptr) { |
| 3140 | break; |
| 3141 | } |
| 3142 | table_index++; |
| 3143 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 3144 | std::string p_name = ptr2->PrettyMethod(true); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 3145 | if (android::base::StartsWith(p_name, method.c_str())) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3146 | std::cerr << " Slot " |
| 3147 | << index |
| 3148 | << " (" |
| 3149 | << current_table->NumEntries(pointer_size) |
| 3150 | << ")" |
| 3151 | << std::endl; |
| 3152 | PrintTable(current_table, pointer_size); |
| 3153 | return; |
| 3154 | } |
| 3155 | } |
| 3156 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 3157 | std::string p_name = ptr->PrettyMethod(true); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 3158 | if (android::base::StartsWith(p_name, method.c_str())) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3159 | std::cerr << " Slot " << index << " (1)" << std::endl; |
| 3160 | std::cerr << " " << p_name << std::endl; |
| 3161 | } else { |
| 3162 | // Run through iftable, find methods that slot here, see if they fit. |
| 3163 | mirror::IfTable* if_table = klass->GetIfTable(); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3164 | for (size_t i = 0, num_interfaces = klass->GetIfTableCount(); i < num_interfaces; ++i) { |
| 3165 | mirror::Class* iface = if_table->GetInterface(i); |
| 3166 | size_t num_methods = iface->NumDeclaredVirtualMethods(); |
| 3167 | if (num_methods > 0) { |
| 3168 | for (ArtMethod& iface_method : iface->GetMethods(pointer_size)) { |
| 3169 | if (ImTable::GetImtIndex(&iface_method) == index) { |
| 3170 | std::string i_name = iface_method.PrettyMethod(true); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 3171 | if (android::base::StartsWith(i_name, method.c_str())) { |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3172 | std::cerr << " Slot " << index << " (1)" << std::endl; |
| 3173 | std::cerr << " " << p_name << " (" << i_name << ")" << std::endl; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | // Read lines from the given stream, dropping comments and empty lines |
| 3185 | static std::vector<std::string> ReadCommentedInputStream(std::istream& in_stream) { |
| 3186 | std::vector<std::string> output; |
| 3187 | while (in_stream.good()) { |
| 3188 | std::string dot; |
| 3189 | std::getline(in_stream, dot); |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 3190 | if (android::base::StartsWith(dot, "#") || dot.empty()) { |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3191 | continue; |
| 3192 | } |
| 3193 | output.push_back(dot); |
| 3194 | } |
| 3195 | return output; |
| 3196 | } |
| 3197 | |
| 3198 | // Read lines from the given file, dropping comments and empty lines. |
| 3199 | static std::vector<std::string> ReadCommentedInputFromFile(const std::string& input_filename) { |
| 3200 | std::unique_ptr<std::ifstream> input_file(new std::ifstream(input_filename, std::ifstream::in)); |
| 3201 | if (input_file.get() == nullptr) { |
| 3202 | LOG(ERROR) << "Failed to open input file " << input_filename; |
| 3203 | return std::vector<std::string>(); |
| 3204 | } |
| 3205 | std::vector<std::string> result = ReadCommentedInputStream(*input_file); |
| 3206 | input_file->close(); |
| 3207 | return result; |
| 3208 | } |
| 3209 | |
| 3210 | // Prepare a class, i.e., ensure it has a filled IMT. Will do so recursively for superclasses, |
| 3211 | // and note in the given set that the work was done. |
| 3212 | static void PrepareClass(Runtime* runtime, |
| 3213 | Handle<mirror::Class> h_klass, |
| 3214 | std::unordered_set<std::string>* done) |
| 3215 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 3216 | if (!h_klass->ShouldHaveImt()) { |
| 3217 | return; |
| 3218 | } |
| 3219 | |
| 3220 | std::string name; |
| 3221 | name = h_klass->GetDescriptor(&name); |
| 3222 | |
| 3223 | if (done->find(name) != done->end()) { |
| 3224 | return; |
| 3225 | } |
| 3226 | done->insert(name); |
| 3227 | |
| 3228 | if (h_klass->HasSuperClass()) { |
| 3229 | StackHandleScope<1> h(Thread::Current()); |
| 3230 | PrepareClass(runtime, h.NewHandle<mirror::Class>(h_klass->GetSuperClass()), done); |
| 3231 | } |
| 3232 | |
| 3233 | if (!h_klass->IsTemp()) { |
| 3234 | runtime->GetClassLinker()->FillIMTAndConflictTables(h_klass.Get()); |
| 3235 | } |
| 3236 | } |
| 3237 | }; |
| 3238 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3239 | struct OatdumpArgs : public CmdlineArgs { |
| 3240 | protected: |
| 3241 | using Base = CmdlineArgs; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3242 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3243 | virtual ParseStatus ParseCustom(const StringPiece& option, |
| 3244 | std::string* error_msg) OVERRIDE { |
| 3245 | { |
| 3246 | ParseStatus base_parse = Base::ParseCustom(option, error_msg); |
| 3247 | if (base_parse != kParseUnknownArgument) { |
| 3248 | return base_parse; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3252 | if (option.starts_with("--oat-file=")) { |
| 3253 | oat_filename_ = option.substr(strlen("--oat-file=")).data(); |
| 3254 | } else if (option.starts_with("--image=")) { |
| 3255 | image_location_ = option.substr(strlen("--image=")).data(); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3256 | } else if (option == "--no-dump:vmap") { |
| 3257 | dump_vmap_ = false; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 3258 | } else if (option =="--dump:code_info_stack_maps") { |
| 3259 | dump_code_info_stack_maps_ = true; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3260 | } else if (option == "--no-disassemble") { |
| 3261 | disassemble_code_ = false; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 3262 | } else if (option =="--header-only") { |
| 3263 | dump_header_only_ = true; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3264 | } else if (option.starts_with("--symbolize=")) { |
| 3265 | oat_filename_ = option.substr(strlen("--symbolize=")).data(); |
| 3266 | symbolize_ = true; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 3267 | } else if (option.starts_with("--only-keep-debug")) { |
| 3268 | only_keep_debug_ = true; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3269 | } else if (option.starts_with("--class-filter=")) { |
| 3270 | class_filter_ = option.substr(strlen("--class-filter=")).data(); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3271 | } else if (option.starts_with("--method-filter=")) { |
| 3272 | method_filter_ = option.substr(strlen("--method-filter=")).data(); |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3273 | } else if (option.starts_with("--list-classes")) { |
| 3274 | list_classes_ = true; |
| 3275 | } else if (option.starts_with("--list-methods")) { |
| 3276 | list_methods_ = true; |
| 3277 | } else if (option.starts_with("--export-dex-to=")) { |
| 3278 | export_dex_location_ = option.substr(strlen("--export-dex-to=")).data(); |
| 3279 | } else if (option.starts_with("--addr2instr=")) { |
| 3280 | if (!ParseUint(option.substr(strlen("--addr2instr=")).data(), &addr2instr_)) { |
| 3281 | *error_msg = "Address conversion failed"; |
| 3282 | return kParseError; |
| 3283 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3284 | } else if (option.starts_with("--app-image=")) { |
| 3285 | app_image_ = option.substr(strlen("--app-image=")).data(); |
| 3286 | } else if (option.starts_with("--app-oat=")) { |
| 3287 | app_oat_ = option.substr(strlen("--app-oat=")).data(); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3288 | } else if (option.starts_with("--dump-imt=")) { |
| 3289 | imt_dump_ = option.substr(strlen("--dump-imt=")).data(); |
| 3290 | } else if (option == "--dump-imt-stats") { |
| 3291 | imt_stat_dump_ = true; |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3292 | } else { |
| 3293 | return kParseUnknownArgument; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3296 | return kParseOk; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3299 | virtual ParseStatus ParseChecks(std::string* error_msg) OVERRIDE { |
| 3300 | // Infer boot image location from the image location if possible. |
| 3301 | if (boot_image_location_ == nullptr) { |
| 3302 | boot_image_location_ = image_location_; |
| 3303 | } |
| 3304 | |
| 3305 | // Perform the parent checks. |
| 3306 | ParseStatus parent_checks = Base::ParseChecks(error_msg); |
| 3307 | if (parent_checks != kParseOk) { |
| 3308 | return parent_checks; |
| 3309 | } |
| 3310 | |
| 3311 | // Perform our own checks. |
| 3312 | if (image_location_ == nullptr && oat_filename_ == nullptr) { |
| 3313 | *error_msg = "Either --image or --oat-file must be specified"; |
| 3314 | return kParseError; |
| 3315 | } else if (image_location_ != nullptr && oat_filename_ != nullptr) { |
| 3316 | *error_msg = "Either --image or --oat-file must be specified but not both"; |
| 3317 | return kParseError; |
| 3318 | } |
| 3319 | |
| 3320 | return kParseOk; |
| 3321 | } |
| 3322 | |
| 3323 | virtual std::string GetUsage() const { |
| 3324 | std::string usage; |
| 3325 | |
| 3326 | usage += |
| 3327 | "Usage: oatdump [options] ...\n" |
| 3328 | " Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art\n" |
| 3329 | " Example: adb shell oatdump --image=/system/framework/boot.art\n" |
| 3330 | "\n" |
| 3331 | // Either oat-file or image is required. |
| 3332 | " --oat-file=<file.oat>: specifies an input oat filename.\n" |
| 3333 | " Example: --oat-file=/system/framework/boot.oat\n" |
| 3334 | "\n" |
| 3335 | " --image=<file.art>: specifies an input image location.\n" |
| 3336 | " Example: --image=/system/framework/boot.art\n" |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3337 | "\n" |
| 3338 | " --app-image=<file.art>: specifies an input app image. Must also have a specified\n" |
| 3339 | " boot image and app oat file.\n" |
| 3340 | " Example: --app-image=app.art\n" |
| 3341 | "\n" |
| 3342 | " --app-oat=<file.odex>: specifies an input app oat.\n" |
| 3343 | " Example: --app-oat=app.odex\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3344 | "\n"; |
| 3345 | |
| 3346 | usage += Base::GetUsage(); |
| 3347 | |
| 3348 | usage += // Optional. |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3349 | " --no-dump:vmap may be used to disable vmap dumping.\n" |
| 3350 | " Example: --no-dump:vmap\n" |
| 3351 | "\n" |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 3352 | " --dump:code_info_stack_maps enables dumping of stack maps in CodeInfo sections.\n" |
| 3353 | " Example: --dump:code_info_stack_maps\n" |
| 3354 | "\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3355 | " --no-disassemble may be used to disable disassembly.\n" |
| 3356 | " Example: --no-disassemble\n" |
| 3357 | "\n" |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 3358 | " --header-only may be used to print only the oat header.\n" |
| 3359 | " Example: --header-only\n" |
| 3360 | "\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3361 | " --list-classes may be used to list target file classes (can be used with filters).\n" |
| 3362 | " Example: --list-classes\n" |
| 3363 | " Example: --list-classes --class-filter=com.example.foo\n" |
| 3364 | "\n" |
| 3365 | " --list-methods may be used to list target file methods (can be used with filters).\n" |
| 3366 | " Example: --list-methods\n" |
| 3367 | " Example: --list-methods --class-filter=com.example --method-filter=foo\n" |
| 3368 | "\n" |
| 3369 | " --symbolize=<file.oat>: output a copy of file.oat with elf symbols included.\n" |
| 3370 | " Example: --symbolize=/system/framework/boot.oat\n" |
| 3371 | "\n" |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 3372 | " --only-keep-debug<file.oat>: Modifies the behaviour of --symbolize so that\n" |
| 3373 | " .rodata and .text sections are omitted in the output file to save space.\n" |
| 3374 | " Example: --symbolize=/system/framework/boot.oat --only-keep-debug\n" |
| 3375 | "\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3376 | " --class-filter=<class name>: only dumps classes that contain the filter.\n" |
| 3377 | " Example: --class-filter=com.example.foo\n" |
| 3378 | "\n" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3379 | " --method-filter=<method name>: only dumps methods that contain the filter.\n" |
| 3380 | " Example: --method-filter=foo\n" |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3381 | "\n" |
| 3382 | " --export-dex-to=<directory>: may be used to export oat embedded dex files.\n" |
| 3383 | " Example: --export-dex-to=/data/local/tmp\n" |
| 3384 | "\n" |
| 3385 | " --addr2instr=<address>: output matching method disassembled code from relative\n" |
| 3386 | " address (e.g. PC from crash dump)\n" |
| 3387 | " Example: --addr2instr=0x00001a3b\n" |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3388 | "\n" |
| 3389 | " --dump-imt=<file.txt>: output IMT collisions (if any) for the given receiver\n" |
| 3390 | " types and interface methods in the given file. The file\n" |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3391 | " is read line-wise, where each line should either be a class\n" |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3392 | " name or descriptor, or a class name/descriptor and a prefix\n" |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3393 | " of a complete method name (separated by a whitespace).\n" |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3394 | " Example: --dump-imt=imt.txt\n" |
| 3395 | "\n" |
| 3396 | " --dump-imt-stats: output IMT statistics for the given boot image\n" |
| 3397 | " Example: --dump-imt-stats" |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3398 | "\n"; |
| 3399 | |
| 3400 | return usage; |
| 3401 | } |
| 3402 | |
| 3403 | public: |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3404 | const char* oat_filename_ = nullptr; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3405 | const char* class_filter_ = ""; |
Nicolas Geoffray | 3fcd220 | 2014-11-12 18:02:36 +0000 | [diff] [blame] | 3406 | const char* method_filter_ = ""; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3407 | const char* image_location_ = nullptr; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3408 | std::string elf_filename_prefix_; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3409 | std::string imt_dump_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3410 | bool dump_vmap_ = true; |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 3411 | bool dump_code_info_stack_maps_ = false; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3412 | bool disassemble_code_ = true; |
| 3413 | bool symbolize_ = false; |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 3414 | bool only_keep_debug_ = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3415 | bool list_classes_ = false; |
| 3416 | bool list_methods_ = false; |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 3417 | bool dump_header_only_ = false; |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3418 | bool imt_stat_dump_ = false; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3419 | uint32_t addr2instr_ = 0; |
| 3420 | const char* export_dex_location_ = nullptr; |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3421 | const char* app_image_ = nullptr; |
| 3422 | const char* app_oat_ = nullptr; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3423 | }; |
| 3424 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3425 | struct OatdumpMain : public CmdlineMain<OatdumpArgs> { |
| 3426 | virtual bool NeedsRuntime() OVERRIDE { |
| 3427 | CHECK(args_ != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3428 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3429 | // If we are only doing the oat file, disable absolute_addresses. Keep them for image dumping. |
| 3430 | bool absolute_addresses = (args_->oat_filename_ == nullptr); |
| 3431 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3432 | oat_dumper_options_.reset(new OatDumperOptions( |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3433 | args_->dump_vmap_, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 3434 | args_->dump_code_info_stack_maps_, |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3435 | args_->disassemble_code_, |
| 3436 | absolute_addresses, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3437 | args_->class_filter_, |
| 3438 | args_->method_filter_, |
| 3439 | args_->list_classes_, |
| 3440 | args_->list_methods_, |
David Brazdil | c03d7b6 | 2016-03-02 12:18:03 +0000 | [diff] [blame] | 3441 | args_->dump_header_only_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3442 | args_->export_dex_location_, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3443 | args_->app_image_, |
| 3444 | args_->app_oat_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3445 | args_->addr2instr_)); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3446 | |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3447 | return (args_->boot_image_location_ != nullptr || |
| 3448 | args_->image_location_ != nullptr || |
| 3449 | !args_->imt_dump_.empty()) && |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3450 | !args_->symbolize_; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3453 | virtual bool ExecuteWithoutRuntime() OVERRIDE { |
| 3454 | CHECK(args_ != nullptr); |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 3455 | CHECK(args_->oat_filename_ != nullptr); |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3456 | |
Mathieu Chartier | d424d08 | 2014-10-15 10:31:46 -0700 | [diff] [blame] | 3457 | MemMap::Init(); |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3458 | |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 3459 | if (args_->symbolize_) { |
David Srbecky | 2fdd03c | 2016-03-10 15:32:37 +0000 | [diff] [blame] | 3460 | // ELF has special kind of section called SHT_NOBITS which allows us to create |
| 3461 | // sections which exist but their data is omitted from the ELF file to save space. |
| 3462 | // This is what "strip --only-keep-debug" does when it creates separate ELF file |
| 3463 | // with only debug data. We use it in similar way to exclude .rodata and .text. |
| 3464 | bool no_bits = args_->only_keep_debug_; |
| 3465 | return SymbolizeOat(args_->oat_filename_, args_->output_name_, no_bits) == EXIT_SUCCESS; |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 3466 | } else { |
| 3467 | return DumpOat(nullptr, |
| 3468 | args_->oat_filename_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3469 | oat_dumper_options_.get(), |
Andreas Gampe | c24f399 | 2014-12-17 20:40:11 -0800 | [diff] [blame] | 3470 | args_->os_) == EXIT_SUCCESS; |
| 3471 | } |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3474 | virtual bool ExecuteWithRuntime(Runtime* runtime) { |
| 3475 | CHECK(args_ != nullptr); |
| 3476 | |
Andreas Gampe | ebfc1ac | 2016-09-29 19:50:27 -0700 | [diff] [blame] | 3477 | if (!args_->imt_dump_.empty() || args_->imt_stat_dump_) { |
| 3478 | return IMTDumper::Dump(runtime, |
| 3479 | args_->imt_dump_, |
| 3480 | args_->imt_stat_dump_, |
| 3481 | args_->oat_filename_); |
Andreas Gampe | 9fded87 | 2016-09-25 16:08:35 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3484 | if (args_->oat_filename_ != nullptr) { |
| 3485 | return DumpOat(runtime, |
| 3486 | args_->oat_filename_, |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 3487 | oat_dumper_options_.get(), |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3488 | args_->os_) == EXIT_SUCCESS; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3489 | } |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3490 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 3491 | return DumpImages(runtime, oat_dumper_options_.get(), args_->os_) == EXIT_SUCCESS; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3494 | std::unique_ptr<OatDumperOptions> oat_dumper_options_; |
| 3495 | }; |
Andreas Gampe | 00b25f3 | 2014-09-17 21:49:05 -0700 | [diff] [blame] | 3496 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 3497 | } // namespace art |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 3498 | |
| 3499 | int main(int argc, char** argv) { |
Igor Murashkin | 3774335 | 2014-11-13 14:38:00 -0800 | [diff] [blame] | 3500 | art::OatdumpMain main; |
| 3501 | return main.Main(argc, argv); |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 3502 | } |