blob: 068a4504268edea28fc2d0dab92ec00229dd6cf3 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstrom78128a62011-09-15 17:21:19 -070016
17#include <stdio.h>
18#include <stdlib.h>
19
Brian Carlstrom27ec9612011-09-19 20:20:38 -070020#include <fstream>
21#include <iostream>
Brian Carlstrom78128a62011-09-15 17:21:19 -070022#include <string>
23#include <vector>
24
Elliott Hughese222ee02012-12-13 14:41:43 -080025#include "base/stringpiece.h"
Elliott Hughes76160052012-12-12 16:31:20 -080026#include "base/unix_file/fd_file.h"
Brian Carlstrom78128a62011-09-15 17:21:19 -070027#include "class_linker.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028#include "class_linker-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070029#include "dex_file-inl.h"
Elliott Hughese3c845c2012-02-28 17:23:01 -080030#include "dex_instruction.h"
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080031#include "disassembler.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070032#include "field_helper.h"
Ian Rogers2bcb4a42012-11-08 10:39:18 -080033#include "gc_map.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070034#include "gc/space/image_space.h"
35#include "gc/space/large_object_space.h"
36#include "gc/space/space-inl.h"
Brian Carlstrom78128a62011-09-15 17:21:19 -070037#include "image.h"
Ian Rogers2bcb4a42012-11-08 10:39:18 -080038#include "indenter.h"
Ian Rogers1809a722013-08-09 22:05:32 -070039#include "mapping_table.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070040#include "mirror/art_field-inl.h"
41#include "mirror/art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042#include "mirror/array-inl.h"
43#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044#include "mirror/object-inl.h"
45#include "mirror/object_array-inl.h"
Brian Carlstromc0a1b182014-03-04 23:19:06 -080046#include "noop_compiler_callbacks.h"
Brian Carlstrom700c8d32012-11-05 10:42:02 -080047#include "oat.h"
Vladimir Marko8a630572014-04-09 18:45:35 +010048#include "oat_file-inl.h"
Elliott Hughese5448b52012-01-18 16:44:06 -080049#include "os.h"
Brian Carlstrom78128a62011-09-15 17:21:19 -070050#include "runtime.h"
Elliott Hughesa0e18062012-04-13 15:59:59 -070051#include "safe_map.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070052#include "scoped_thread_state_change.h"
Mathieu Chartierc22c59e2014-02-24 15:16:06 -080053#include "thread_list.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080054#include "verifier/dex_gc_map.h"
Ian Rogers2bcb4a42012-11-08 10:39:18 -080055#include "verifier/method_verifier.h"
Ian Rogers1809a722013-08-09 22:05:32 -070056#include "vmap_table.h"
Brian Carlstrom78128a62011-09-15 17:21:19 -070057
58namespace art {
59
60static void usage() {
61 fprintf(stderr,
62 "Usage: oatdump [options] ...\n"
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000063 " Example: oatdump --image=$ANDROID_PRODUCT_OUT/system/framework/boot.art\n"
Brian Carlstrom29e7ac72011-12-05 23:42:57 -080064 " Example: adb shell oatdump --image=/system/framework/boot.art\n"
Brian Carlstrom78128a62011-09-15 17:21:19 -070065 "\n");
66 fprintf(stderr,
Brian Carlstroma6cc8932012-01-04 14:44:07 -080067 " --oat-file=<file.oat>: specifies an input oat filename.\n"
TDYa127a0a2a6c2012-10-16 22:47:38 -070068 " Example: --oat-file=/system/framework/boot.oat\n"
Brian Carlstromaded5f72011-10-07 17:15:04 -070069 "\n");
70 fprintf(stderr,
71 " --image=<file.art>: specifies an input image filename.\n"
Brian Carlstrom29e7ac72011-12-05 23:42:57 -080072 " Example: --image=/system/framework/boot.art\n"
Brian Carlstrome24fa612011-09-29 00:53:55 -070073 "\n");
Brian Carlstrom78128a62011-09-15 17:21:19 -070074 fprintf(stderr,
Brian Carlstrome24fa612011-09-29 00:53:55 -070075 " --boot-image=<file.art>: provide the image file for the boot class path.\n"
Brian Carlstrom29e7ac72011-12-05 23:42:57 -080076 " Example: --boot-image=/system/framework/boot.art\n"
Brian Carlstrom78128a62011-09-15 17:21:19 -070077 "\n");
Brian Carlstrome24fa612011-09-29 00:53:55 -070078 fprintf(stderr,
Brian Carlstrom0f5baa02014-05-22 11:54:18 -070079 " --instruction-set=(arm|arm64|mips|x86|x86_64): for locating the image file based on the image location\n"
80 " set.\n"
81 " Example: --instruction-set=x86\n"
82 " Default: %s\n"
83 "\n",
84 GetInstructionSetString(kRuntimeISA));
85 fprintf(stderr,
Brian Carlstrom27ec9612011-09-19 20:20:38 -070086 " --output=<file> may be used to send the output to a file.\n"
87 " Example: --output=/tmp/oatdump.txt\n"
88 "\n");
Dave Allison404f59f2014-02-24 11:10:01 -080089 fprintf(stderr,
90 " --dump:[raw_mapping_table|raw_gc_map]\n"
91 " Example: --dump:raw_gc_map\n"
92 " Default: neither\n"
93 "\n");
Brian Carlstrom78128a62011-09-15 17:21:19 -070094 exit(EXIT_FAILURE);
95}
96
Ian Rogersff1ed472011-09-20 13:46:24 -070097const char* image_roots_descriptions_[] = {
Ian Rogers19846512012-02-24 11:42:47 -080098 "kResolutionMethod",
Jeff Hao88474b42013-10-23 16:24:40 -070099 "kImtConflictMethod",
100 "kDefaultImt",
Brian Carlstrome24fa612011-09-29 00:53:55 -0700101 "kCalleeSaveMethod",
Brian Carlstromaded5f72011-10-07 17:15:04 -0700102 "kRefsOnlySaveMethod",
103 "kRefsAndArgsSaveMethod",
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700104 "kDexCaches",
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700105 "kClassRoots",
Brian Carlstrom78128a62011-09-15 17:21:19 -0700106};
107
Elliott Hughese3c845c2012-02-28 17:23:01 -0800108class OatDumper {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700109 public:
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000110 explicit OatDumper(const OatFile& oat_file, bool dump_raw_mapping_table, bool dump_raw_gc_map)
111 : oat_file_(oat_file),
Elliott Hughesa72ec822012-03-05 17:12:22 -0800112 oat_dex_files_(oat_file.GetOatDexFiles()),
Dave Allison404f59f2014-02-24 11:10:01 -0800113 dump_raw_mapping_table_(dump_raw_mapping_table),
114 dump_raw_gc_map_(dump_raw_gc_map),
Elliott Hughesa72ec822012-03-05 17:12:22 -0800115 disassembler_(Disassembler::Create(oat_file_.GetOatHeader().GetInstructionSet())) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800116 AddAllOffsets();
117 }
118
119 void Dump(std::ostream& os) {
120 const OatHeader& oat_header = oat_file_.GetOatHeader();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700121
122 os << "MAGIC:\n";
123 os << oat_header.GetMagic() << "\n\n";
124
125 os << "CHECKSUM:\n";
Elliott Hughesed2adb62012-02-29 14:41:01 -0800126 os << StringPrintf("0x%08x\n\n", oat_header.GetChecksum());
Brian Carlstromaded5f72011-10-07 17:15:04 -0700127
Elliott Hughesa72ec822012-03-05 17:12:22 -0800128 os << "INSTRUCTION SET:\n";
129 os << oat_header.GetInstructionSet() << "\n\n";
130
Dave Allison70202782013-10-22 17:52:19 -0700131 os << "INSTRUCTION SET FEATURES:\n";
132 os << oat_header.GetInstructionSetFeatures().GetFeatureString() << "\n\n";
133
Brian Carlstromaded5f72011-10-07 17:15:04 -0700134 os << "DEX FILE COUNT:\n";
135 os << oat_header.GetDexFileCount() << "\n\n";
136
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800137#define DUMP_OAT_HEADER_OFFSET(label, offset) \
138 os << label " OFFSET:\n"; \
139 os << StringPrintf("0x%08x", oat_header.offset()); \
140 if (oat_header.offset() != 0) { \
141 os << StringPrintf(" (%p)", oat_file_.Begin() + oat_header.offset()); \
142 } \
143 os << StringPrintf("\n\n");
144
145 DUMP_OAT_HEADER_OFFSET("EXECUTABLE", GetExecutableOffset);
146 DUMP_OAT_HEADER_OFFSET("INTERPRETER TO INTERPRETER BRIDGE",
147 GetInterpreterToInterpreterBridgeOffset);
148 DUMP_OAT_HEADER_OFFSET("INTERPRETER TO COMPILED CODE BRIDGE",
149 GetInterpreterToCompiledCodeBridgeOffset);
150 DUMP_OAT_HEADER_OFFSET("JNI DLSYM LOOKUP",
151 GetJniDlsymLookupOffset);
152 DUMP_OAT_HEADER_OFFSET("PORTABLE IMT CONFLICT TRAMPOLINE",
153 GetPortableImtConflictTrampolineOffset);
154 DUMP_OAT_HEADER_OFFSET("PORTABLE RESOLUTION TRAMPOLINE",
155 GetPortableResolutionTrampolineOffset);
156 DUMP_OAT_HEADER_OFFSET("PORTABLE TO INTERPRETER BRIDGE",
157 GetPortableToInterpreterBridgeOffset);
158 DUMP_OAT_HEADER_OFFSET("QUICK GENERIC JNI TRAMPOLINE",
159 GetQuickGenericJniTrampolineOffset);
160 DUMP_OAT_HEADER_OFFSET("QUICK IMT CONFLICT TRAMPOLINE",
161 GetQuickImtConflictTrampolineOffset);
162 DUMP_OAT_HEADER_OFFSET("QUICK RESOLUTION TRAMPOLINE",
163 GetQuickResolutionTrampolineOffset);
164 DUMP_OAT_HEADER_OFFSET("QUICK TO INTERPRETER BRIDGE",
165 GetQuickToInterpreterBridgeOffset);
166#undef DUMP_OAT_HEADER_OFFSET
Brian Carlstromaded5f72011-10-07 17:15:04 -0700167
Alex Lighta59dd802014-07-02 16:28:08 -0700168 os << "IMAGE PATCH DELTA:\n" << oat_header.GetImagePatchDelta();
169
Brian Carlstrom28db0122012-10-18 16:20:41 -0700170 os << "IMAGE FILE LOCATION OAT CHECKSUM:\n";
171 os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatChecksum());
172
173 os << "IMAGE FILE LOCATION OAT BEGIN:\n";
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800174 os << StringPrintf("0x%08x\n\n", oat_header.GetImageFileLocationOatDataBegin());
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700175
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700176 // Print the key-value store.
177 {
178 os << "KEY VALUE STORE:\n";
179 size_t index = 0;
180 const char* key;
181 const char* value;
182 while (oat_header.GetStoreKeyValuePairByIndex(index, &key, &value)) {
183 os << key << " = " << value << "\n";
184 index++;
185 }
186 os << "\n";
187 }
Brian Carlstrom81f3ca12012-03-17 00:27:35 -0700188
Ian Rogers30fab402012-01-23 15:43:46 -0800189 os << "BEGIN:\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800190 os << reinterpret_cast<const void*>(oat_file_.Begin()) << "\n\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700191
Ian Rogers30fab402012-01-23 15:43:46 -0800192 os << "END:\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800193 os << reinterpret_cast<const void*>(oat_file_.End()) << "\n\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700194
195 os << std::flush;
196
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800197 for (size_t i = 0; i < oat_dex_files_.size(); i++) {
198 const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i];
Brian Carlstromaded5f72011-10-07 17:15:04 -0700199 CHECK(oat_dex_file != NULL);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800200 DumpOatDexFile(os, *oat_dex_file);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700201 }
202 }
203
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800204 size_t ComputeSize(const void* oat_data) {
205 if (reinterpret_cast<const byte*>(oat_data) < oat_file_.Begin() ||
206 reinterpret_cast<const byte*>(oat_data) > oat_file_.End()) {
207 return 0; // Address not in oat file
208 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800209 uintptr_t begin_offset = reinterpret_cast<uintptr_t>(oat_data) -
210 reinterpret_cast<uintptr_t>(oat_file_.Begin());
211 auto it = offsets_.upper_bound(begin_offset);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800212 CHECK(it != offsets_.end());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800213 uintptr_t end_offset = *it;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800214 return end_offset - begin_offset;
215 }
216
Brian Carlstromf8bbb842012-03-14 03:01:42 -0700217 InstructionSet GetInstructionSet() {
218 return oat_file_.GetOatHeader().GetInstructionSet();
219 }
220
Ian Rogersef7d42f2014-01-06 12:55:46 -0800221 const void* GetQuickOatCode(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800222 for (size_t i = 0; i < oat_dex_files_.size(); i++) {
223 const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i];
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700224 CHECK(oat_dex_file != nullptr);
225 std::string error_msg;
Ian Rogers700a4022014-05-19 16:49:03 -0700226 std::unique_ptr<const DexFile> dex_file(oat_dex_file->OpenDexFile(&error_msg));
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700227 if (dex_file.get() == nullptr) {
228 LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation()
229 << "': " << error_msg;
230 } else {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700231 const DexFile::ClassDef* class_def =
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700232 dex_file->FindClassDef(m->GetDeclaringClassDescriptor());
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700233 if (class_def != NULL) {
234 uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100235 const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800236 size_t method_index = m->GetMethodIndex();
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100237 return oat_class.GetOatMethod(method_index).GetQuickCode();
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800238 }
239 }
240 }
241 return NULL;
242 }
243
Brian Carlstromaded5f72011-10-07 17:15:04 -0700244 private:
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800245 void AddAllOffsets() {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800246 // We don't know the length of the code for each method, but we need to know where to stop
247 // when disassembling. What we do know is that a region of code will be followed by some other
248 // region, so if we keep a sorted sequence of the start of each region, we can infer the length
249 // of a piece of code by using upper_bound to find the start of the next region.
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800250 for (size_t i = 0; i < oat_dex_files_.size(); i++) {
251 const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i];
Elliott Hughese3c845c2012-02-28 17:23:01 -0800252 CHECK(oat_dex_file != NULL);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700253 std::string error_msg;
Ian Rogers700a4022014-05-19 16:49:03 -0700254 std::unique_ptr<const DexFile> dex_file(oat_dex_file->OpenDexFile(&error_msg));
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700255 if (dex_file.get() == nullptr) {
256 LOG(WARNING) << "Failed to open dex file '" << oat_dex_file->GetDexFileLocation()
257 << "': " << error_msg;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800258 continue;
Elliott Hughese3c845c2012-02-28 17:23:01 -0800259 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800260 offsets_.insert(reinterpret_cast<uintptr_t>(&dex_file->GetHeader()));
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800261 for (size_t class_def_index = 0;
262 class_def_index < dex_file->NumClassDefs();
263 class_def_index++) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800264 const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100265 const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index);
Elliott Hughese3c845c2012-02-28 17:23:01 -0800266 const byte* class_data = dex_file->GetClassData(class_def);
267 if (class_data != NULL) {
268 ClassDataItemIterator it(*dex_file, class_data);
269 SkipAllFields(it);
270 uint32_t class_method_index = 0;
271 while (it.HasNextDirectMethod()) {
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100272 AddOffsets(oat_class.GetOatMethod(class_method_index++));
Elliott Hughese3c845c2012-02-28 17:23:01 -0800273 it.Next();
274 }
275 while (it.HasNextVirtualMethod()) {
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100276 AddOffsets(oat_class.GetOatMethod(class_method_index++));
Elliott Hughese3c845c2012-02-28 17:23:01 -0800277 it.Next();
278 }
279 }
280 }
281 }
282
283 // If the last thing in the file is code for a method, there won't be an offset for the "next"
284 // thing. Instead of having a special case in the upper_bound code, let's just add an entry
285 // for the end of the file.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800286 offsets_.insert(oat_file_.Size());
Elliott Hughese3c845c2012-02-28 17:23:01 -0800287 }
288
289 void AddOffsets(const OatFile::OatMethod& oat_method) {
Brian Carlstrom95ba0dc2012-03-05 22:06:14 -0800290 uint32_t code_offset = oat_method.GetCodeOffset();
291 if (oat_file_.GetOatHeader().GetInstructionSet() == kThumb2) {
292 code_offset &= ~0x1;
293 }
294 offsets_.insert(code_offset);
Elliott Hughese3c845c2012-02-28 17:23:01 -0800295 offsets_.insert(oat_method.GetMappingTableOffset());
296 offsets_.insert(oat_method.GetVmapTableOffset());
Ian Rogers0c7abda2012-09-19 13:33:42 -0700297 offsets_.insert(oat_method.GetNativeGcMapOffset());
Elliott Hughese3c845c2012-02-28 17:23:01 -0800298 }
299
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800300 void DumpOatDexFile(std::ostream& os, const OatFile::OatDexFile& oat_dex_file) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700301 os << "OAT DEX FILE:\n";
Brian Carlstroma004aa92012-02-08 18:05:09 -0800302 os << StringPrintf("location: %s\n", oat_dex_file.GetDexFileLocation().c_str());
Elliott Hughesed2adb62012-02-29 14:41:01 -0800303 os << StringPrintf("checksum: 0x%08x\n", oat_dex_file.GetDexFileLocationChecksum());
Mathieu Chartier590fee92013-09-13 13:46:47 -0700304
305 // Create the verifier early.
306
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700307 std::string error_msg;
Ian Rogers700a4022014-05-19 16:49:03 -0700308 std::unique_ptr<const DexFile> dex_file(oat_dex_file.OpenDexFile(&error_msg));
Brian Carlstroma004aa92012-02-08 18:05:09 -0800309 if (dex_file.get() == NULL) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700310 os << "NOT FOUND: " << error_msg << "\n\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700311 return;
312 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800313 for (size_t class_def_index = 0;
314 class_def_index < dex_file->NumClassDefs();
315 class_def_index++) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700316 const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
317 const char* descriptor = dex_file->GetClassDescriptor(class_def);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100318 const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index);
Brian Carlstromba150c32013-08-27 17:31:03 -0700319 os << StringPrintf("%zd: %s (type_idx=%d)", class_def_index, descriptor, class_def.class_idx_)
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100320 << " (" << oat_class.GetStatus() << ")"
321 << " (" << oat_class.GetType() << ")\n";
322 // TODO: include bitmap here if type is kOatClassSomeCompiled?
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800323 Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
324 std::ostream indented_os(&indent_filter);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100325 DumpOatClass(indented_os, oat_class, *(dex_file.get()), class_def);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700326 }
327
328 os << std::flush;
329 }
330
Elliott Hughese3c845c2012-02-28 17:23:01 -0800331 static void SkipAllFields(ClassDataItemIterator& it) {
Ian Rogers0571d352011-11-03 19:51:38 -0700332 while (it.HasNextStaticField()) {
333 it.Next();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700334 }
Ian Rogers0571d352011-11-03 19:51:38 -0700335 while (it.HasNextInstanceField()) {
336 it.Next();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700337 }
Elliott Hughese3c845c2012-02-28 17:23:01 -0800338 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700339
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800340 void DumpOatClass(std::ostream& os, const OatFile::OatClass& oat_class, const DexFile& dex_file,
341 const DexFile::ClassDef& class_def) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800342 const byte* class_data = dex_file.GetClassData(class_def);
343 if (class_data == NULL) { // empty class such as a marker interface?
344 return;
345 }
346 ClassDataItemIterator it(dex_file, class_data);
347 SkipAllFields(it);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800348 uint32_t class_method_idx = 0;
Ian Rogers0571d352011-11-03 19:51:38 -0700349 while (it.HasNextDirectMethod()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800350 const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700351 DumpOatMethod(os, class_def, class_method_idx, oat_method, dex_file,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800352 it.GetMemberIndex(), it.GetMethodCodeItem(), it.GetMemberAccessFlags());
353 class_method_idx++;
Ian Rogers0571d352011-11-03 19:51:38 -0700354 it.Next();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700355 }
Ian Rogers0571d352011-11-03 19:51:38 -0700356 while (it.HasNextVirtualMethod()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800357 const OatFile::OatMethod oat_method = oat_class.GetOatMethod(class_method_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700358 DumpOatMethod(os, class_def, class_method_idx, oat_method, dex_file,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800359 it.GetMemberIndex(), it.GetMethodCodeItem(), it.GetMemberAccessFlags());
360 class_method_idx++;
Ian Rogers0571d352011-11-03 19:51:38 -0700361 it.Next();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700362 }
Ian Rogers0571d352011-11-03 19:51:38 -0700363 DCHECK(!it.HasNext());
Brian Carlstromaded5f72011-10-07 17:15:04 -0700364 os << std::flush;
365 }
Elliott Hughese3c845c2012-02-28 17:23:01 -0800366
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700367 void DumpOatMethod(std::ostream& os, const DexFile::ClassDef& class_def,
368 uint32_t class_method_index,
Elliott Hughese3c845c2012-02-28 17:23:01 -0800369 const OatFile::OatMethod& oat_method, const DexFile& dex_file,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800370 uint32_t dex_method_idx, const DexFile::CodeItem* code_item,
371 uint32_t method_access_flags) {
372 os << StringPrintf("%d: %s (dex_method_idx=%d)\n",
Ian Rogersdb7bdc12012-04-09 21:27:15 -0700373 class_method_index, PrettyMethod(dex_method_idx, dex_file, true).c_str(),
374 dex_method_idx);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800375 Indenter indent1_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700376 std::unique_ptr<std::ostream> indent1_os(new std::ostream(&indent1_filter));
377 Indenter indent2_filter(indent1_os->rdbuf(), kIndentChar, kIndentBy1Count);
378 std::unique_ptr<std::ostream> indent2_os(new std::ostream(&indent2_filter));
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800379 {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700380 *indent1_os << "DEX CODE:\n";
381 DumpDexCode(*indent2_os, dex_file, code_item);
Ian Rogersb23a7722012-10-09 16:54:26 -0700382 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800383 if (Runtime::Current() != NULL) {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700384 *indent1_os << "VERIFIER TYPE ANALYSIS:\n";
385 DumpVerifier(*indent2_os, dex_method_idx, &dex_file, class_def, code_item,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700386 method_access_flags);
Ian Rogersb23a7722012-10-09 16:54:26 -0700387 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800388 {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700389 *indent1_os << "OAT DATA:\n";
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800390
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700391 *indent2_os << StringPrintf("frame_size_in_bytes: %zd\n", oat_method.GetFrameSizeInBytes());
392 *indent2_os << StringPrintf("core_spill_mask: 0x%08x ", oat_method.GetCoreSpillMask());
393 DumpSpillMask(*indent2_os, oat_method.GetCoreSpillMask(), false);
394 *indent2_os << StringPrintf("\nfp_spill_mask: 0x%08x ", oat_method.GetFpSpillMask());
395 DumpSpillMask(*indent2_os, oat_method.GetFpSpillMask(), true);
396 *indent2_os << StringPrintf("\nvmap_table: %p (offset=0x%08x)\n",
397 oat_method.GetVmapTable(), oat_method.GetVmapTableOffset());
398 DumpVmap(*indent2_os, oat_method);
399 *indent2_os << StringPrintf("mapping_table: %p (offset=0x%08x)\n",
400 oat_method.GetMappingTable(), oat_method.GetMappingTableOffset());
Dave Allison404f59f2014-02-24 11:10:01 -0800401 if (dump_raw_mapping_table_) {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700402 Indenter indent3_filter(indent2_os->rdbuf(), kIndentChar, kIndentBy1Count);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800403 std::ostream indent3_os(&indent3_filter);
404 DumpMappingTable(indent3_os, oat_method);
405 }
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700406 *indent2_os << StringPrintf("gc_map: %p (offset=0x%08x)\n",
407 oat_method.GetNativeGcMap(), oat_method.GetNativeGcMapOffset());
Dave Allison404f59f2014-02-24 11:10:01 -0800408 if (dump_raw_gc_map_) {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700409 Indenter indent3_filter(indent2_os->rdbuf(), kIndentChar, kIndentBy1Count);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800410 std::ostream indent3_os(&indent3_filter);
411 DumpGcMap(indent3_os, oat_method, code_item);
412 }
413 }
414 {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800415 const void* code = oat_method.GetQuickCode();
416 uint32_t code_size = oat_method.GetQuickCodeSize();
417 if (code == nullptr) {
418 code = oat_method.GetPortableCode();
419 code_size = oat_method.GetPortableCodeSize();
420 }
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700421 *indent1_os << StringPrintf("CODE: %p (offset=0x%08x size=%d)%s\n",
Ian Rogersef7d42f2014-01-06 12:55:46 -0800422 code,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800423 oat_method.GetCodeOffset(),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800424 code_size,
425 code != nullptr ? "..." : "");
Mathieu Chartier590fee92013-09-13 13:46:47 -0700426
427 Runtime* runtime = Runtime::Current();
428 if (runtime != nullptr) {
429 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700430 StackHandleScope<1> hs(soa.Self());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700431 Handle<mirror::DexCache> dex_cache(
432 hs.NewHandle(runtime->GetClassLinker()->FindDexCache(dex_file)));
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700433 NullHandle<mirror::ClassLoader> class_loader;
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800434 verifier::MethodVerifier verifier(&dex_file, &dex_cache, &class_loader, &class_def,
435 code_item, dex_method_idx, nullptr, method_access_flags,
Ian Rogers46960fe2014-05-23 10:43:43 -0700436 true, true, true);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700437 verifier.Verify();
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700438 DumpCode(*indent2_os, &verifier, oat_method, code_item);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700439 } else {
Andreas Gampea8b41aa2014-06-04 22:42:28 -0700440 DumpCode(*indent2_os, nullptr, oat_method, code_item);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700441 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800442 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700443 }
Elliott Hughese3c845c2012-02-28 17:23:01 -0800444
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800445 void DumpSpillMask(std::ostream& os, uint32_t spill_mask, bool is_float) {
446 if (spill_mask == 0) {
447 return;
448 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800449 os << "(";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800450 for (size_t i = 0; i < 32; i++) {
451 if ((spill_mask & (1 << i)) != 0) {
452 if (is_float) {
453 os << "fr" << i;
454 } else {
455 os << "r" << i;
456 }
457 spill_mask ^= 1 << i; // clear bit
458 if (spill_mask != 0) {
459 os << ", ";
460 } else {
461 break;
462 }
463 }
464 }
465 os << ")";
466 }
467
Ian Rogersb23a7722012-10-09 16:54:26 -0700468 void DumpVmap(std::ostream& os, const OatFile::OatMethod& oat_method) {
Ian Rogers1809a722013-08-09 22:05:32 -0700469 const uint8_t* raw_table = oat_method.GetVmapTable();
470 if (raw_table != NULL) {
471 const VmapTable vmap_table(raw_table);
472 bool first = true;
473 bool processing_fp = false;
474 uint32_t spill_mask = oat_method.GetCoreSpillMask();
475 for (size_t i = 0; i < vmap_table.Size(); i++) {
476 uint16_t dex_reg = vmap_table[i];
477 uint32_t cpu_reg = vmap_table.ComputeRegister(spill_mask, i,
478 processing_fp ? kFloatVReg : kIntVReg);
479 os << (first ? "v" : ", v") << dex_reg;
480 if (!processing_fp) {
481 os << "/r" << cpu_reg;
482 } else {
483 os << "/fr" << cpu_reg;
484 }
485 first = false;
486 if (!processing_fp && dex_reg == 0xFFFF) {
487 processing_fp = true;
488 spill_mask = oat_method.GetFpSpillMask();
489 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800490 }
Ian Rogers1809a722013-08-09 22:05:32 -0700491 os << "\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800492 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800493 }
494
Ian Rogersb23a7722012-10-09 16:54:26 -0700495 void DescribeVReg(std::ostream& os, const OatFile::OatMethod& oat_method,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800496 const DexFile::CodeItem* code_item, size_t reg, VRegKind kind) {
Ian Rogers1809a722013-08-09 22:05:32 -0700497 const uint8_t* raw_table = oat_method.GetVmapTable();
Ian Rogersb23a7722012-10-09 16:54:26 -0700498 if (raw_table != NULL) {
499 const VmapTable vmap_table(raw_table);
500 uint32_t vmap_offset;
Ian Rogers1809a722013-08-09 22:05:32 -0700501 if (vmap_table.IsInContext(reg, kind, &vmap_offset)) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800502 bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg);
503 uint32_t spill_mask = is_float ? oat_method.GetFpSpillMask()
504 : oat_method.GetCoreSpillMask();
505 os << (is_float ? "fr" : "r") << vmap_table.ComputeRegister(spill_mask, vmap_offset, kind);
Ian Rogersb23a7722012-10-09 16:54:26 -0700506 } else {
507 uint32_t offset = StackVisitor::GetVRegOffset(code_item, oat_method.GetCoreSpillMask(),
508 oat_method.GetFpSpillMask(),
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000509 oat_method.GetFrameSizeInBytes(), reg,
510 GetInstructionSet());
Ian Rogersb23a7722012-10-09 16:54:26 -0700511 os << "[sp + #" << offset << "]";
512 }
513 }
514 }
515
Ian Rogersef7d42f2014-01-06 12:55:46 -0800516 void DumpGcMapRegisters(std::ostream& os, const OatFile::OatMethod& oat_method,
517 const DexFile::CodeItem* code_item,
518 size_t num_regs, const uint8_t* reg_bitmap) {
519 bool first = true;
520 for (size_t reg = 0; reg < num_regs; reg++) {
521 if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) {
522 if (first) {
523 os << " v" << reg << " (";
524 DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg);
525 os << ")";
526 first = false;
527 } else {
528 os << ", v" << reg << " (";
529 DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg);
530 os << ")";
531 }
532 }
533 }
534 if (first) {
535 os << "No registers in GC map\n";
536 } else {
537 os << "\n";
538 }
539 }
Ian Rogersb23a7722012-10-09 16:54:26 -0700540 void DumpGcMap(std::ostream& os, const OatFile::OatMethod& oat_method,
541 const DexFile::CodeItem* code_item) {
542 const uint8_t* gc_map_raw = oat_method.GetNativeGcMap();
Ian Rogersef7d42f2014-01-06 12:55:46 -0800543 if (gc_map_raw == nullptr) {
544 return; // No GC map.
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800545 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800546 const void* quick_code = oat_method.GetQuickCode();
547 if (quick_code != nullptr) {
548 NativePcOffsetToReferenceMap map(gc_map_raw);
549 for (size_t entry = 0; entry < map.NumEntries(); entry++) {
550 const uint8_t* native_pc = reinterpret_cast<const uint8_t*>(quick_code) +
551 map.GetNativePcOffset(entry);
552 os << StringPrintf("%p", native_pc);
553 DumpGcMapRegisters(os, oat_method, code_item, map.RegWidth() * 8, map.GetBitMap(entry));
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800554 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800555 } else {
556 const void* portable_code = oat_method.GetPortableCode();
557 CHECK(portable_code != nullptr);
558 verifier::DexPcToReferenceMap map(gc_map_raw);
559 for (size_t entry = 0; entry < map.NumEntries(); entry++) {
560 uint32_t dex_pc = map.GetDexPc(entry);
561 os << StringPrintf("0x%08x", dex_pc);
562 DumpGcMapRegisters(os, oat_method, code_item, map.RegWidth() * 8, map.GetBitMap(entry));
563 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800564 }
565 }
566
567 void DumpMappingTable(std::ostream& os, const OatFile::OatMethod& oat_method) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800568 const void* quick_code = oat_method.GetQuickCode();
569 if (quick_code == nullptr) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800570 return;
571 }
Ian Rogers1809a722013-08-09 22:05:32 -0700572 MappingTable table(oat_method.GetMappingTable());
573 if (table.TotalSize() != 0) {
574 Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
575 std::ostream indent_os(&indent_filter);
576 if (table.PcToDexSize() != 0) {
577 typedef MappingTable::PcToDexIterator It;
578 os << "suspend point mappings {\n";
579 for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
580 indent_os << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc());
581 }
582 os << "}\n";
583 }
584 if (table.DexToPcSize() != 0) {
585 typedef MappingTable::DexToPcIterator It;
586 os << "catch entry mappings {\n";
587 for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
588 indent_os << StringPrintf("0x%04x -> 0x%04x\n", cur.NativePcOffset(), cur.DexPc());
589 }
590 os << "}\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800591 }
592 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800593 }
594
Ian Rogers1809a722013-08-09 22:05:32 -0700595 uint32_t DumpMappingAtOffset(std::ostream& os, const OatFile::OatMethod& oat_method,
596 size_t offset, bool suspend_point_mapping) {
597 MappingTable table(oat_method.GetMappingTable());
598 if (suspend_point_mapping && table.PcToDexSize() > 0) {
599 typedef MappingTable::PcToDexIterator It;
600 for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) {
601 if (offset == cur.NativePcOffset()) {
Brian Carlstrom4b8c13e2013-08-23 18:10:32 -0700602 os << StringPrintf("suspend point dex PC: 0x%04x\n", cur.DexPc());
Ian Rogers1809a722013-08-09 22:05:32 -0700603 return cur.DexPc();
604 }
Elliott Hughese3c845c2012-02-28 17:23:01 -0800605 }
Ian Rogers1809a722013-08-09 22:05:32 -0700606 } else if (!suspend_point_mapping && table.DexToPcSize() > 0) {
607 typedef MappingTable::DexToPcIterator It;
608 for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) {
609 if (offset == cur.NativePcOffset()) {
Brian Carlstrom4b8c13e2013-08-23 18:10:32 -0700610 os << StringPrintf("catch entry dex PC: 0x%04x\n", cur.DexPc());
Ian Rogers1809a722013-08-09 22:05:32 -0700611 return cur.DexPc();
Ian Rogersb23a7722012-10-09 16:54:26 -0700612 }
613 }
Elliott Hughese3c845c2012-02-28 17:23:01 -0800614 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800615 return DexFile::kDexNoIndex;
Ian Rogersb23a7722012-10-09 16:54:26 -0700616 }
617
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800618 void DumpGcMapAtNativePcOffset(std::ostream& os, const OatFile::OatMethod& oat_method,
619 const DexFile::CodeItem* code_item, size_t native_pc_offset) {
Ian Rogersb23a7722012-10-09 16:54:26 -0700620 const uint8_t* gc_map_raw = oat_method.GetNativeGcMap();
621 if (gc_map_raw != NULL) {
622 NativePcOffsetToReferenceMap map(gc_map_raw);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800623 if (map.HasEntry(native_pc_offset)) {
Ian Rogersb23a7722012-10-09 16:54:26 -0700624 size_t num_regs = map.RegWidth() * 8;
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800625 const uint8_t* reg_bitmap = map.FindBitMap(native_pc_offset);
Ian Rogersb23a7722012-10-09 16:54:26 -0700626 bool first = true;
627 for (size_t reg = 0; reg < num_regs; reg++) {
628 if (((reg_bitmap[reg / 8] >> (reg % 8)) & 0x01) != 0) {
629 if (first) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800630 os << "GC map objects: v" << reg << " (";
631 DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg);
Ian Rogersb23a7722012-10-09 16:54:26 -0700632 os << ")";
633 first = false;
634 } else {
635 os << ", v" << reg << " (";
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800636 DescribeVReg(os, oat_method, code_item, reg, kReferenceVReg);
Ian Rogersb23a7722012-10-09 16:54:26 -0700637 os << ")";
638 }
639 }
640 }
641 if (!first) {
642 os << "\n";
643 }
644 }
645 }
646 }
647
Mathieu Chartier590fee92013-09-13 13:46:47 -0700648 void DumpVRegsAtDexPc(std::ostream& os, verifier::MethodVerifier* verifier,
649 const OatFile::OatMethod& oat_method,
650 const DexFile::CodeItem* code_item, uint32_t dex_pc) {
651 DCHECK(verifier != nullptr);
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800652 std::vector<int32_t> kinds = verifier->DescribeVRegs(dex_pc);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800653 bool first = true;
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800654 for (size_t reg = 0; reg < code_item->registers_size_; reg++) {
655 VRegKind kind = static_cast<VRegKind>(kinds.at(reg * 2));
656 if (kind != kUndefined) {
657 if (first) {
658 os << "VRegs: v";
659 first = false;
660 } else {
661 os << ", v";
662 }
663 os << reg << " (";
664 switch (kind) {
665 case kImpreciseConstant:
666 os << "Imprecise Constant: " << kinds.at((reg * 2) + 1) << ", ";
667 DescribeVReg(os, oat_method, code_item, reg, kind);
668 break;
669 case kConstant:
670 os << "Constant: " << kinds.at((reg * 2) + 1);
671 break;
672 default:
673 DescribeVReg(os, oat_method, code_item, reg, kind);
674 break;
675 }
676 os << ")";
677 }
678 }
679 if (!first) {
680 os << "\n";
681 }
682 }
683
684
Ian Rogersb23a7722012-10-09 16:54:26 -0700685 void DumpDexCode(std::ostream& os, const DexFile& dex_file, const DexFile::CodeItem* code_item) {
686 if (code_item != NULL) {
687 size_t i = 0;
688 while (i < code_item->insns_size_in_code_units_) {
689 const Instruction* instruction = Instruction::At(&code_item->insns_[i]);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800690 os << StringPrintf("0x%04zx: %s\n", i, instruction->DumpString(&dex_file).c_str());
Ian Rogersb23a7722012-10-09 16:54:26 -0700691 i += instruction->SizeInCodeUnits();
692 }
693 }
694 }
695
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800696 void DumpVerifier(std::ostream& os, uint32_t dex_method_idx, const DexFile* dex_file,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700697 const DexFile::ClassDef& class_def, const DexFile::CodeItem* code_item,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800698 uint32_t method_access_flags) {
699 if ((method_access_flags & kAccNative) == 0) {
700 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700701 StackHandleScope<2> hs(soa.Self());
702 Handle<mirror::DexCache> dex_cache(
703 hs.NewHandle(Runtime::Current()->GetClassLinker()->FindDexCache(*dex_file)));
704 auto class_loader(hs.NewHandle<mirror::ClassLoader>(nullptr));
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800705 verifier::MethodVerifier::VerifyMethodAndDump(os, dex_method_idx, dex_file, dex_cache,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700706 class_loader, &class_def, code_item, nullptr,
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800707 method_access_flags);
708 }
709 }
710
Mathieu Chartier590fee92013-09-13 13:46:47 -0700711 void DumpCode(std::ostream& os, verifier::MethodVerifier* verifier,
712 const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800713 const void* portable_code = oat_method.GetPortableCode();
714 const void* quick_code = oat_method.GetQuickCode();
715
716 size_t code_size = oat_method.GetQuickCodeSize();
717 if ((code_size == 0) || ((portable_code == nullptr) && (quick_code == nullptr))) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800718 os << "NO CODE!\n";
Ian Rogersb23a7722012-10-09 16:54:26 -0700719 return;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800720 } else if (quick_code != nullptr) {
721 const uint8_t* quick_native_pc = reinterpret_cast<const uint8_t*>(quick_code);
722 size_t offset = 0;
723 while (offset < code_size) {
724 DumpMappingAtOffset(os, oat_method, offset, false);
725 offset += disassembler_->Dump(os, quick_native_pc + offset);
726 uint32_t dex_pc = DumpMappingAtOffset(os, oat_method, offset, true);
727 if (dex_pc != DexFile::kDexNoIndex) {
728 DumpGcMapAtNativePcOffset(os, oat_method, code_item, offset);
729 if (verifier != nullptr) {
730 DumpVRegsAtDexPc(os, verifier, oat_method, code_item, dex_pc);
731 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800732 }
733 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800734 } else {
735 CHECK(portable_code != nullptr);
736 CHECK_EQ(code_size, 0U); // TODO: disassembly of portable is currently not supported.
Ian Rogersb23a7722012-10-09 16:54:26 -0700737 }
738 }
739
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800740 const OatFile& oat_file_;
741 std::vector<const OatFile::OatDexFile*> oat_dex_files_;
Dave Allison404f59f2014-02-24 11:10:01 -0800742 bool dump_raw_mapping_table_;
743 bool dump_raw_gc_map_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800744 std::set<uintptr_t> offsets_;
Ian Rogers700a4022014-05-19 16:49:03 -0700745 std::unique_ptr<Disassembler> disassembler_;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700746};
747
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800748class ImageDumper {
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700749 public:
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800750 explicit ImageDumper(std::ostream* os, gc::space::ImageSpace& image_space,
Dave Allison404f59f2014-02-24 11:10:01 -0800751 const ImageHeader& image_header, bool dump_raw_mapping_table,
752 bool dump_raw_gc_map)
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800753 : os_(os), image_space_(image_space), image_header_(image_header),
Dave Allison404f59f2014-02-24 11:10:01 -0800754 dump_raw_mapping_table_(dump_raw_mapping_table),
755 dump_raw_gc_map_(dump_raw_gc_map) {}
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700756
Ian Rogersb726dcb2012-09-05 08:57:23 -0700757 void Dump() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800758 std::ostream& os = *os_;
759 os << "MAGIC: " << image_header_.GetMagic() << "\n\n";
Brian Carlstrome24fa612011-09-29 00:53:55 -0700760
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800761 os << "IMAGE BEGIN: " << reinterpret_cast<void*>(image_header_.GetImageBegin()) << "\n\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700762
Mathieu Chartier31e89252013-08-28 11:29:12 -0700763 os << "IMAGE BITMAP OFFSET: " << reinterpret_cast<void*>(image_header_.GetImageBitmapOffset())
764 << " SIZE: " << reinterpret_cast<void*>(image_header_.GetImageBitmapSize()) << "\n\n";
765
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800766 os << "OAT CHECKSUM: " << StringPrintf("0x%08x\n\n", image_header_.GetOatChecksum());
Brian Carlstrom916e74e2011-09-23 11:42:01 -0700767
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800768 os << "OAT FILE BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatFileBegin()) << "\n\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700769
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800770 os << "OAT DATA BEGIN:" << reinterpret_cast<void*>(image_header_.GetOatDataBegin()) << "\n\n";
771
772 os << "OAT DATA END:" << reinterpret_cast<void*>(image_header_.GetOatDataEnd()) << "\n\n";
773
774 os << "OAT FILE END:" << reinterpret_cast<void*>(image_header_.GetOatFileEnd()) << "\n\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800775
Alex Lighta59dd802014-07-02 16:28:08 -0700776 os << "PATCH DELTA:" << image_header_.GetPatchDelta() << "\n\n";
777
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800778 {
779 os << "ROOTS: " << reinterpret_cast<void*>(image_header_.GetImageRoots()) << "\n";
780 Indenter indent1_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
781 std::ostream indent1_os(&indent1_filter);
782 CHECK_EQ(arraysize(image_roots_descriptions_), size_t(ImageHeader::kImageRootsMax));
783 for (int i = 0; i < ImageHeader::kImageRootsMax; i++) {
784 ImageHeader::ImageRoot image_root = static_cast<ImageHeader::ImageRoot>(i);
785 const char* image_root_description = image_roots_descriptions_[i];
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800786 mirror::Object* image_root_object = image_header_.GetImageRoot(image_root);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800787 indent1_os << StringPrintf("%s: %p\n", image_root_description, image_root_object);
788 if (image_root_object->IsObjectArray()) {
789 Indenter indent2_filter(indent1_os.rdbuf(), kIndentChar, kIndentBy1Count);
790 std::ostream indent2_os(&indent2_filter);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800791 mirror::ObjectArray<mirror::Object>* image_root_object_array
Ian Rogersfa824272013-11-05 16:12:57 -0800792 = image_root_object->AsObjectArray<mirror::Object>();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800793 for (int i = 0; i < image_root_object_array->GetLength(); i++) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800794 mirror::Object* value = image_root_object_array->Get(i);
Ian Rogersfa824272013-11-05 16:12:57 -0800795 size_t run = 0;
796 for (int32_t j = i + 1; j < image_root_object_array->GetLength(); j++) {
797 if (value == image_root_object_array->Get(j)) {
798 run++;
799 } else {
800 break;
801 }
802 }
803 if (run == 0) {
804 indent2_os << StringPrintf("%d: ", i);
805 } else {
806 indent2_os << StringPrintf("%d to %zd: ", i, i + run);
807 i = i + run;
808 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800809 if (value != NULL) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800810 PrettyObjectValue(indent2_os, value->GetClass(), value);
811 } else {
812 indent2_os << i << ": null\n";
813 }
Ian Rogersd5b32602012-02-26 16:40:04 -0800814 }
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700815 }
816 }
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700817 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800818 os << "\n";
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700819
Brian Carlstromaded5f72011-10-07 17:15:04 -0700820 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800821 std::string image_filename = image_space_.GetImageFilename();
822 std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(image_filename);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800823 os << "OAT LOCATION: " << oat_location;
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800824 os << "\n";
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700825 std::string error_msg;
Alex Lighta59dd802014-07-02 16:28:08 -0700826 const OatFile* oat_file = class_linker->FindOpenedOatFileFromOatLocation(oat_location);
827 if (oat_file == nullptr) {
828 oat_file = OatFile::Open(oat_location, oat_location, NULL, false, &error_msg);
829 if (oat_file == nullptr) {
830 os << "NOT FOUND: " << error_msg << "\n";
831 return;
832 }
Brian Carlstromaded5f72011-10-07 17:15:04 -0700833 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800834 os << "\n";
Brian Carlstromaded5f72011-10-07 17:15:04 -0700835
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800836 stats_.oat_file_bytes = oat_file->Size();
837
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000838 oat_dumper_.reset(new OatDumper(*oat_file, dump_raw_mapping_table_,
Dave Allison404f59f2014-02-24 11:10:01 -0800839 dump_raw_gc_map_));
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800840
Mathieu Chartier02e25112013-08-14 16:14:24 -0700841 for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) {
Ian Rogers05f28c62012-10-23 18:12:13 -0700842 CHECK(oat_dex_file != NULL);
Mathieu Chartier02e25112013-08-14 16:14:24 -0700843 stats_.oat_dex_file_sizes.push_back(std::make_pair(oat_dex_file->GetDexFileLocation(),
844 oat_dex_file->FileSize()));
Ian Rogers05f28c62012-10-23 18:12:13 -0700845 }
846
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800847 os << "OBJECTS:\n" << std::flush;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700848
849 // Loop through all the image spaces and dump their objects.
Ian Rogers1d54e732013-05-02 21:10:01 -0700850 gc::Heap* heap = Runtime::Current()->GetHeap();
851 const std::vector<gc::space::ContinuousSpace*>& spaces = heap->GetContinuousSpaces();
Ian Rogers50b35e22012-10-04 10:09:15 -0700852 Thread* self = Thread::Current();
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700853 {
Mathieu Chartierc22c59e2014-02-24 15:16:06 -0800854 {
855 WriterMutexLock mu(self, *Locks::heap_bitmap_lock_);
856 heap->FlushAllocStack();
857 }
Hiroshi Yamauchi90d70682014-02-20 16:17:30 -0800858 // Since FlushAllocStack() above resets the (active) allocation
859 // stack. Need to revoke the thread-local allocation stacks that
860 // point into it.
Mathieu Chartierc22c59e2014-02-24 15:16:06 -0800861 {
862 self->TransitionFromRunnableToSuspended(kNative);
863 ThreadList* thread_list = Runtime::Current()->GetThreadList();
864 thread_list->SuspendAll();
865 heap->RevokeAllThreadLocalAllocationStacks(self);
866 thread_list->ResumeAll();
867 self->TransitionFromSuspendedToRunnable();
868 }
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700869 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800870 {
871 std::ostream* saved_os = os_;
872 Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
873 std::ostream indent_os(&indent_filter);
874 os_ = &indent_os;
875 ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_);
Mathieu Chartier02e25112013-08-14 16:14:24 -0700876 for (const auto& space : spaces) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800877 if (space->IsImageSpace()) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700878 gc::space::ImageSpace* image_space = space->AsImageSpace();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800879 image_space->GetLiveBitmap()->Walk(ImageDumper::Callback, this);
880 indent_os << "\n";
881 }
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700882 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800883 // Dump the large objects separately.
Mathieu Chartierbbd695c2014-04-16 09:48:48 -0700884 heap->GetLargeObjectsSpace()->GetLiveBitmap()->Walk(ImageDumper::Callback, this);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800885 indent_os << "\n";
886 os_ = saved_os;
Mathieu Chartierb062fdd2012-07-03 09:51:48 -0700887 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800888 os << "STATS:\n" << std::flush;
Ian Rogers700a4022014-05-19 16:49:03 -0700889 std::unique_ptr<File> file(OS::OpenFileForReading(image_filename.c_str()));
Brian Carlstrom6f277752013-09-30 17:56:45 -0700890 if (file.get() == NULL) {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800891 LOG(WARNING) << "Failed to find image in " << image_filename;
Brian Carlstrom6f277752013-09-30 17:56:45 -0700892 }
893 if (file.get() != NULL) {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800894 stats_.file_bytes = file->GetLength();
Brian Carlstrom6f277752013-09-30 17:56:45 -0700895 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800896 size_t header_bytes = sizeof(ImageHeader);
897 stats_.header_bytes = header_bytes;
898 size_t alignment_bytes = RoundUp(header_bytes, kObjectAlignment) - header_bytes;
899 stats_.alignment_bytes += alignment_bytes;
Mathieu Chartier32327092013-08-30 14:04:08 -0700900 stats_.alignment_bytes += image_header_.GetImageBitmapOffset() - image_header_.GetImageSize();
901 stats_.bitmap_bytes += image_header_.GetImageBitmapSize();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800902 stats_.Dump(os);
903 os << "\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800904
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800905 os << std::flush;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800906
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800907 oat_dumper_->Dump(os);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700908 }
909
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700910 private:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800911 static void PrettyObjectValue(std::ostream& os, mirror::Class* type, mirror::Object* value)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700912 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersd5b32602012-02-26 16:40:04 -0800913 CHECK(type != NULL);
914 if (value == NULL) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800915 os << StringPrintf("null %s\n", PrettyDescriptor(type).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -0800916 } else if (type->IsStringClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800917 mirror::String* string = value->AsString();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800918 os << StringPrintf("%p String: %s\n", string,
919 PrintableString(string->ToModifiedUtf8()).c_str());
Ian Rogers64b6d142012-10-29 16:34:15 -0700920 } else if (type->IsClassClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800921 mirror::Class* klass = value->AsClass();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800922 os << StringPrintf("%p Class: %s\n", klass, PrettyDescriptor(klass).c_str());
Brian Carlstromea46f952013-07-30 01:26:50 -0700923 } else if (type->IsArtFieldClass()) {
924 mirror::ArtField* field = value->AsArtField();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800925 os << StringPrintf("%p Field: %s\n", field, PrettyField(field).c_str());
Brian Carlstromea46f952013-07-30 01:26:50 -0700926 } else if (type->IsArtMethodClass()) {
927 mirror::ArtMethod* method = value->AsArtMethod();
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800928 os << StringPrintf("%p Method: %s\n", method, PrettyMethod(method).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -0800929 } else {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800930 os << StringPrintf("%p %s\n", value, PrettyDescriptor(type).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -0800931 }
932 }
933
Brian Carlstromea46f952013-07-30 01:26:50 -0700934 static void PrintField(std::ostream& os, mirror::ArtField* field, mirror::Object* obj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700935 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700936 const char* descriptor = field->GetTypeDescriptor();
937 os << StringPrintf("%s: ", field->GetName());
Ian Rogers48efc2b2012-08-27 17:20:31 -0700938 if (descriptor[0] != 'L' && descriptor[0] != '[') {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700939 StackHandleScope<1> hs(Thread::Current());
940 FieldHelper fh(hs.NewHandle(field));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800941 mirror::Class* type = fh.GetType();
Ian Rogers48efc2b2012-08-27 17:20:31 -0700942 if (type->IsPrimitiveLong()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800943 os << StringPrintf("%" PRId64 " (0x%" PRIx64 ")\n", field->Get64(obj), field->Get64(obj));
Ian Rogers48efc2b2012-08-27 17:20:31 -0700944 } else if (type->IsPrimitiveDouble()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800945 os << StringPrintf("%f (%a)\n", field->GetDouble(obj), field->GetDouble(obj));
Ian Rogers48efc2b2012-08-27 17:20:31 -0700946 } else if (type->IsPrimitiveFloat()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800947 os << StringPrintf("%f (%a)\n", field->GetFloat(obj), field->GetFloat(obj));
Ian Rogers48efc2b2012-08-27 17:20:31 -0700948 } else {
949 DCHECK(type->IsPrimitive());
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800950 os << StringPrintf("%d (0x%x)\n", field->Get32(obj), field->Get32(obj));
Ian Rogers48efc2b2012-08-27 17:20:31 -0700951 }
Ian Rogersd5b32602012-02-26 16:40:04 -0800952 } else {
Ian Rogers48efc2b2012-08-27 17:20:31 -0700953 // Get the value, don't compute the type unless it is non-null as we don't want
954 // to cause class loading.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800955 mirror::Object* value = field->GetObj(obj);
Ian Rogers48efc2b2012-08-27 17:20:31 -0700956 if (value == NULL) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800957 os << StringPrintf("null %s\n", PrettyDescriptor(descriptor).c_str());
Ian Rogers48efc2b2012-08-27 17:20:31 -0700958 } else {
Ian Rogers50239c72013-06-17 14:53:22 -0700959 // Grab the field type without causing resolution.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700960 StackHandleScope<1> hs(Thread::Current());
961 FieldHelper fh(hs.NewHandle(field));
Ian Rogers50239c72013-06-17 14:53:22 -0700962 mirror::Class* field_type = fh.GetType(false);
963 if (field_type != NULL) {
964 PrettyObjectValue(os, field_type, value);
965 } else {
966 os << StringPrintf("%p %s\n", value, PrettyDescriptor(descriptor).c_str());
967 }
Ian Rogers48efc2b2012-08-27 17:20:31 -0700968 }
Ian Rogersd5b32602012-02-26 16:40:04 -0800969 }
970 }
971
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800972 static void DumpFields(std::ostream& os, mirror::Object* obj, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700973 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800974 mirror::Class* super = klass->GetSuperClass();
Ian Rogersd5b32602012-02-26 16:40:04 -0800975 if (super != NULL) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800976 DumpFields(os, obj, super);
Ian Rogersd5b32602012-02-26 16:40:04 -0800977 }
Brian Carlstromea46f952013-07-30 01:26:50 -0700978 mirror::ObjectArray<mirror::ArtField>* fields = klass->GetIFields();
Ian Rogersd5b32602012-02-26 16:40:04 -0800979 if (fields != NULL) {
980 for (int32_t i = 0; i < fields->GetLength(); i++) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700981 mirror::ArtField* field = fields->Get(i);
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800982 PrintField(os, field, obj);
Ian Rogersd5b32602012-02-26 16:40:04 -0800983 }
984 }
985 }
986
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800987 bool InDumpSpace(const mirror::Object* object) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800988 return image_space_.Contains(object);
Brian Carlstromf8bbb842012-03-14 03:01:42 -0700989 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800990
Ian Rogersef7d42f2014-01-06 12:55:46 -0800991 const void* GetQuickOatCodeBegin(mirror::ArtMethod* m)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700992 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800993 const void* quick_code = m->GetEntryPointFromQuickCompiledCode();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700994 if (quick_code == Runtime::Current()->GetClassLinker()->GetQuickResolutionTrampoline()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800995 quick_code = oat_dumper_->GetQuickOatCode(m);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800996 }
Brian Carlstromf8bbb842012-03-14 03:01:42 -0700997 if (oat_dumper_->GetInstructionSet() == kThumb2) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800998 quick_code = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(quick_code) & ~0x1);
Brian Carlstromf8bbb842012-03-14 03:01:42 -0700999 }
Ian Rogersef7d42f2014-01-06 12:55:46 -08001000 return quick_code;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001001 }
1002
Ian Rogersef7d42f2014-01-06 12:55:46 -08001003 uint32_t GetQuickOatCodeSize(mirror::ArtMethod* m)
Ian Rogersb726dcb2012-09-05 08:57:23 -07001004 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001005 const uint32_t* oat_code_begin = reinterpret_cast<const uint32_t*>(GetQuickOatCodeBegin(m));
1006 if (oat_code_begin == nullptr) {
Brian Carlstromf8bbb842012-03-14 03:01:42 -07001007 return 0;
1008 }
1009 return oat_code_begin[-1];
1010 }
1011
Ian Rogersef7d42f2014-01-06 12:55:46 -08001012 const void* GetQuickOatCodeEnd(mirror::ArtMethod* m)
Ian Rogersb726dcb2012-09-05 08:57:23 -07001013 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001014 const uint8_t* oat_code_begin = reinterpret_cast<const uint8_t*>(GetQuickOatCodeBegin(m));
Brian Carlstromf8bbb842012-03-14 03:01:42 -07001015 if (oat_code_begin == NULL) {
1016 return NULL;
1017 }
Ian Rogersef7d42f2014-01-06 12:55:46 -08001018 return oat_code_begin + GetQuickOatCodeSize(m);
Brian Carlstromf8bbb842012-03-14 03:01:42 -07001019 }
1020
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001021 static void Callback(mirror::Object* obj, void* arg)
Ian Rogersb726dcb2012-09-05 08:57:23 -07001022 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom78128a62011-09-15 17:21:19 -07001023 DCHECK(obj != NULL);
1024 DCHECK(arg != NULL);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001025 ImageDumper* state = reinterpret_cast<ImageDumper*>(arg);
Brian Carlstrom78128a62011-09-15 17:21:19 -07001026 if (!state->InDumpSpace(obj)) {
1027 return;
1028 }
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001029
1030 size_t object_bytes = obj->SizeOf();
1031 size_t alignment_bytes = RoundUp(object_bytes, kObjectAlignment) - object_bytes;
1032 state->stats_.object_bytes += object_bytes;
1033 state->stats_.alignment_bytes += alignment_bytes;
1034
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001035 std::ostream& os = *state->os_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001036 mirror::Class* obj_class = obj->GetClass();
Ian Rogersd5b32602012-02-26 16:40:04 -08001037 if (obj_class->IsArrayClass()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001038 os << StringPrintf("%p: %s length:%d\n", obj, PrettyDescriptor(obj_class).c_str(),
1039 obj->AsArray()->GetLength());
Ian Rogersd5b32602012-02-26 16:40:04 -08001040 } else if (obj->IsClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001041 mirror::Class* klass = obj->AsClass();
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001042 os << StringPrintf("%p: java.lang.Class \"%s\" (", obj, PrettyDescriptor(klass).c_str())
1043 << klass->GetStatus() << ")\n";
Brian Carlstromea46f952013-07-30 01:26:50 -07001044 } else if (obj->IsArtField()) {
Brian Carlstrom4b8c13e2013-08-23 18:10:32 -07001045 os << StringPrintf("%p: java.lang.reflect.ArtField %s\n", obj,
Brian Carlstromea46f952013-07-30 01:26:50 -07001046 PrettyField(obj->AsArtField()).c_str());
1047 } else if (obj->IsArtMethod()) {
Brian Carlstrom4b8c13e2013-08-23 18:10:32 -07001048 os << StringPrintf("%p: java.lang.reflect.ArtMethod %s\n", obj,
Brian Carlstromea46f952013-07-30 01:26:50 -07001049 PrettyMethod(obj->AsArtMethod()).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -08001050 } else if (obj_class->IsStringClass()) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001051 os << StringPrintf("%p: java.lang.String %s\n", obj,
1052 PrintableString(obj->AsString()->ToModifiedUtf8()).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -08001053 } else {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001054 os << StringPrintf("%p: %s\n", obj, PrettyDescriptor(obj_class).c_str());
Ian Rogersd5b32602012-02-26 16:40:04 -08001055 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001056 Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
1057 std::ostream indent_os(&indent_filter);
1058 DumpFields(indent_os, obj, obj_class);
Ian Rogersd5b32602012-02-26 16:40:04 -08001059 if (obj->IsObjectArray()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001060 mirror::ObjectArray<mirror::Object>* obj_array = obj->AsObjectArray<mirror::Object>();
Ian Rogersd5b32602012-02-26 16:40:04 -08001061 int32_t length = obj_array->GetLength();
1062 for (int32_t i = 0; i < length; i++) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001063 mirror::Object* value = obj_array->Get(i);
Ian Rogersd5b32602012-02-26 16:40:04 -08001064 size_t run = 0;
1065 for (int32_t j = i + 1; j < length; j++) {
1066 if (value == obj_array->Get(j)) {
1067 run++;
1068 } else {
1069 break;
1070 }
1071 }
1072 if (run == 0) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001073 indent_os << StringPrintf("%d: ", i);
Ian Rogersd5b32602012-02-26 16:40:04 -08001074 } else {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001075 indent_os << StringPrintf("%d to %zd: ", i, i + run);
Ian Rogersd5b32602012-02-26 16:40:04 -08001076 i = i + run;
1077 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -08001078 mirror::Class* value_class =
1079 (value == NULL) ? obj_class->GetComponentType() : value->GetClass();
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001080 PrettyObjectValue(indent_os, value_class, value);
Ian Rogersd5b32602012-02-26 16:40:04 -08001081 }
1082 } else if (obj->IsClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -07001083 mirror::ObjectArray<mirror::ArtField>* sfields = obj->AsClass()->GetSFields();
Ian Rogersd5b32602012-02-26 16:40:04 -08001084 if (sfields != NULL) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001085 indent_os << "STATICS:\n";
1086 Indenter indent2_filter(indent_os.rdbuf(), kIndentChar, kIndentBy1Count);
1087 std::ostream indent2_os(&indent2_filter);
Ian Rogersd5b32602012-02-26 16:40:04 -08001088 for (int32_t i = 0; i < sfields->GetLength(); i++) {
Brian Carlstromea46f952013-07-30 01:26:50 -07001089 mirror::ArtField* field = sfields->Get(i);
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001090 PrintField(indent2_os, field, field->GetDeclaringClass());
Ian Rogersd5b32602012-02-26 16:40:04 -08001091 }
1092 }
Brian Carlstromea46f952013-07-30 01:26:50 -07001093 } else if (obj->IsArtMethod()) {
1094 mirror::ArtMethod* method = obj->AsArtMethod();
Brian Carlstrom78128a62011-09-15 17:21:19 -07001095 if (method->IsNative()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001096 // TODO: portable dumping.
1097 DCHECK(method->GetNativeGcMap() == nullptr) << PrettyMethod(method);
1098 DCHECK(method->GetMappingTable() == nullptr) << PrettyMethod(method);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001099 bool first_occurrence;
Ian Rogersef7d42f2014-01-06 12:55:46 -08001100 const void* quick_oat_code = state->GetQuickOatCodeBegin(method);
1101 uint32_t quick_oat_code_size = state->GetQuickOatCodeSize(method);
1102 state->ComputeOatSize(quick_oat_code, &first_occurrence);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001103 if (first_occurrence) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001104 state->stats_.native_to_managed_code_bytes += quick_oat_code_size;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001105 }
Ian Rogersef7d42f2014-01-06 12:55:46 -08001106 if (quick_oat_code != method->GetEntryPointFromQuickCompiledCode()) {
1107 indent_os << StringPrintf("OAT CODE: %p\n", quick_oat_code);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001108 }
Ian Rogers19846512012-02-24 11:42:47 -08001109 } else if (method->IsAbstract() || method->IsCalleeSaveMethod() ||
Jeff Hao88474b42013-10-23 16:24:40 -07001110 method->IsResolutionMethod() || method->IsImtConflictMethod() ||
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001111 method->IsClassInitializer()) {
Ian Rogers0c7abda2012-09-19 13:33:42 -07001112 DCHECK(method->GetNativeGcMap() == NULL) << PrettyMethod(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -07001113 DCHECK(method->GetMappingTable() == NULL) << PrettyMethod(method);
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001114 } else {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001115 const DexFile::CodeItem* code_item = method->GetCodeItem();
Ian Rogersd81871c2011-10-03 13:57:23 -07001116 size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001117 state->stats_.dex_instruction_bytes += dex_instruction_bytes;
Brian Carlstrome7d856b2012-01-11 18:10:55 -08001118
Elliott Hughesa0e18062012-04-13 15:59:59 -07001119 bool first_occurrence;
Ian Rogers0c7abda2012-09-19 13:33:42 -07001120 size_t gc_map_bytes = state->ComputeOatSize(method->GetNativeGcMap(), &first_occurrence);
Elliott Hughesa0e18062012-04-13 15:59:59 -07001121 if (first_occurrence) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001122 state->stats_.gc_map_bytes += gc_map_bytes;
1123 }
1124
1125 size_t pc_mapping_table_bytes =
Ian Rogers1809a722013-08-09 22:05:32 -07001126 state->ComputeOatSize(method->GetMappingTable(), &first_occurrence);
Elliott Hughesa0e18062012-04-13 15:59:59 -07001127 if (first_occurrence) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001128 state->stats_.pc_mapping_table_bytes += pc_mapping_table_bytes;
1129 }
1130
1131 size_t vmap_table_bytes =
Ian Rogers1809a722013-08-09 22:05:32 -07001132 state->ComputeOatSize(method->GetVmapTable(), &first_occurrence);
Elliott Hughesa0e18062012-04-13 15:59:59 -07001133 if (first_occurrence) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001134 state->stats_.vmap_table_bytes += vmap_table_bytes;
1135 }
1136
Ian Rogersef7d42f2014-01-06 12:55:46 -08001137 // TODO: portable dumping.
1138 const void* quick_oat_code_begin = state->GetQuickOatCodeBegin(method);
1139 const void* quick_oat_code_end = state->GetQuickOatCodeEnd(method);
1140 uint32_t quick_oat_code_size = state->GetQuickOatCodeSize(method);
1141 state->ComputeOatSize(quick_oat_code_begin, &first_occurrence);
Elliott Hughesa0e18062012-04-13 15:59:59 -07001142 if (first_occurrence) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001143 state->stats_.managed_code_bytes += quick_oat_code_size;
Ian Rogers0d2d3782012-04-10 11:09:18 -07001144 if (method->IsConstructor()) {
1145 if (method->IsStatic()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001146 state->stats_.class_initializer_code_bytes += quick_oat_code_size;
Ian Rogers0d2d3782012-04-10 11:09:18 -07001147 } else if (dex_instruction_bytes > kLargeConstructorDexBytes) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001148 state->stats_.large_initializer_code_bytes += quick_oat_code_size;
Ian Rogers0d2d3782012-04-10 11:09:18 -07001149 }
1150 } else if (dex_instruction_bytes > kLargeMethodDexBytes) {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001151 state->stats_.large_method_code_bytes += quick_oat_code_size;
Ian Rogers0d2d3782012-04-10 11:09:18 -07001152 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001153 }
Ian Rogersef7d42f2014-01-06 12:55:46 -08001154 state->stats_.managed_code_bytes_ignoring_deduplication += quick_oat_code_size;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001155
Ian Rogersef7d42f2014-01-06 12:55:46 -08001156 indent_os << StringPrintf("OAT CODE: %p-%p\n", quick_oat_code_begin, quick_oat_code_end);
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001157 indent_os << StringPrintf("SIZE: Dex Instructions=%zd GC=%zd Mapping=%zd\n",
1158 dex_instruction_bytes, gc_map_bytes, pc_mapping_table_bytes);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001159
1160 size_t total_size = dex_instruction_bytes + gc_map_bytes + pc_mapping_table_bytes +
Ian Rogersef7d42f2014-01-06 12:55:46 -08001161 vmap_table_bytes + quick_oat_code_size + object_bytes;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001162
1163 double expansion =
Ian Rogersef7d42f2014-01-06 12:55:46 -08001164 static_cast<double>(quick_oat_code_size) / static_cast<double>(dex_instruction_bytes);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001165 state->stats_.ComputeOutliers(total_size, expansion, method);
Brian Carlstrom78128a62011-09-15 17:21:19 -07001166 }
1167 }
Mathieu Chartierf8322842014-05-16 10:59:25 -07001168 state->stats_.Update(obj_class->GetDescriptor().c_str(), object_bytes);
Brian Carlstrom78128a62011-09-15 17:21:19 -07001169 }
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001170
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001171 std::set<const void*> already_seen_;
1172 // Compute the size of the given data within the oat file and whether this is the first time
1173 // this data has been requested
Elliott Hughesa0e18062012-04-13 15:59:59 -07001174 size_t ComputeOatSize(const void* oat_data, bool* first_occurrence) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001175 if (already_seen_.count(oat_data) == 0) {
Elliott Hughesa0e18062012-04-13 15:59:59 -07001176 *first_occurrence = true;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001177 already_seen_.insert(oat_data);
1178 } else {
Elliott Hughesa0e18062012-04-13 15:59:59 -07001179 *first_occurrence = false;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001180 }
1181 return oat_dumper_->ComputeSize(oat_data);
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001182 }
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001183
1184 public:
1185 struct Stats {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001186 size_t oat_file_bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001187 size_t file_bytes;
1188
1189 size_t header_bytes;
1190 size_t object_bytes;
Mathieu Chartier32327092013-08-30 14:04:08 -07001191 size_t bitmap_bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001192 size_t alignment_bytes;
1193
1194 size_t managed_code_bytes;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001195 size_t managed_code_bytes_ignoring_deduplication;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001196 size_t managed_to_native_code_bytes;
1197 size_t native_to_managed_code_bytes;
Ian Rogers0d2d3782012-04-10 11:09:18 -07001198 size_t class_initializer_code_bytes;
1199 size_t large_initializer_code_bytes;
1200 size_t large_method_code_bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001201
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001202 size_t gc_map_bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001203 size_t pc_mapping_table_bytes;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001204 size_t vmap_table_bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001205
1206 size_t dex_instruction_bytes;
1207
Brian Carlstromea46f952013-07-30 01:26:50 -07001208 std::vector<mirror::ArtMethod*> method_outlier;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001209 std::vector<size_t> method_outlier_size;
1210 std::vector<double> method_outlier_expansion;
Ian Rogers700a4022014-05-19 16:49:03 -07001211 std::vector<std::pair<std::string, size_t>> oat_dex_file_sizes;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001212
1213 explicit Stats()
1214 : oat_file_bytes(0),
1215 file_bytes(0),
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001216 header_bytes(0),
1217 object_bytes(0),
Mathieu Chartier32327092013-08-30 14:04:08 -07001218 bitmap_bytes(0),
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001219 alignment_bytes(0),
1220 managed_code_bytes(0),
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001221 managed_code_bytes_ignoring_deduplication(0),
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001222 managed_to_native_code_bytes(0),
1223 native_to_managed_code_bytes(0),
Ian Rogers0d2d3782012-04-10 11:09:18 -07001224 class_initializer_code_bytes(0),
1225 large_initializer_code_bytes(0),
1226 large_method_code_bytes(0),
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001227 gc_map_bytes(0),
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001228 pc_mapping_table_bytes(0),
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001229 vmap_table_bytes(0),
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001230 dex_instruction_bytes(0) {}
1231
Elliott Hughesa0e18062012-04-13 15:59:59 -07001232 struct SizeAndCount {
1233 SizeAndCount(size_t bytes, size_t count) : bytes(bytes), count(count) {}
1234 size_t bytes;
1235 size_t count;
1236 };
1237 typedef SafeMap<std::string, SizeAndCount> SizeAndCountTable;
1238 SizeAndCountTable sizes_and_counts;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001239
Ian Rogersfc0e94b2013-09-23 23:51:32 -07001240 void Update(const char* descriptor, size_t object_bytes) {
Elliott Hughesa0e18062012-04-13 15:59:59 -07001241 SizeAndCountTable::iterator it = sizes_and_counts.find(descriptor);
1242 if (it != sizes_and_counts.end()) {
1243 it->second.bytes += object_bytes;
1244 it->second.count += 1;
1245 } else {
1246 sizes_and_counts.Put(descriptor, SizeAndCount(object_bytes, 1));
1247 }
1248 }
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001249
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001250 double PercentOfOatBytes(size_t size) {
1251 return (static_cast<double>(size) / static_cast<double>(oat_file_bytes)) * 100;
1252 }
1253
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001254 double PercentOfFileBytes(size_t size) {
1255 return (static_cast<double>(size) / static_cast<double>(file_bytes)) * 100;
1256 }
1257
1258 double PercentOfObjectBytes(size_t size) {
1259 return (static_cast<double>(size) / static_cast<double>(object_bytes)) * 100;
1260 }
1261
Brian Carlstromea46f952013-07-30 01:26:50 -07001262 void ComputeOutliers(size_t total_size, double expansion, mirror::ArtMethod* method) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001263 method_outlier_size.push_back(total_size);
1264 method_outlier_expansion.push_back(expansion);
1265 method_outlier.push_back(method);
1266 }
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001267
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001268 void DumpOutliers(std::ostream& os)
Ian Rogersb726dcb2012-09-05 08:57:23 -07001269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001270 size_t sum_of_sizes = 0;
1271 size_t sum_of_sizes_squared = 0;
1272 size_t sum_of_expansion = 0;
1273 size_t sum_of_expansion_squared = 0;
1274 size_t n = method_outlier_size.size();
1275 for (size_t i = 0; i < n; i++) {
1276 size_t cur_size = method_outlier_size[i];
1277 sum_of_sizes += cur_size;
1278 sum_of_sizes_squared += cur_size * cur_size;
1279 double cur_expansion = method_outlier_expansion[i];
1280 sum_of_expansion += cur_expansion;
1281 sum_of_expansion_squared += cur_expansion * cur_expansion;
1282 }
1283 size_t size_mean = sum_of_sizes / n;
1284 size_t size_variance = (sum_of_sizes_squared - sum_of_sizes * size_mean) / (n - 1);
1285 double expansion_mean = sum_of_expansion / n;
1286 double expansion_variance =
1287 (sum_of_expansion_squared - sum_of_expansion * expansion_mean) / (n - 1);
1288
1289 // Dump methods whose size is a certain number of standard deviations from the mean
1290 size_t dumped_values = 0;
1291 size_t skipped_values = 0;
1292 for (size_t i = 100; i > 0; i--) { // i is the current number of standard deviations
1293 size_t cur_size_variance = i * i * size_variance;
1294 bool first = true;
1295 for (size_t j = 0; j < n; j++) {
1296 size_t cur_size = method_outlier_size[j];
1297 if (cur_size > size_mean) {
1298 size_t cur_var = cur_size - size_mean;
1299 cur_var = cur_var * cur_var;
1300 if (cur_var > cur_size_variance) {
1301 if (dumped_values > 20) {
1302 if (i == 1) {
1303 skipped_values++;
1304 } else {
1305 i = 2; // jump to counting for 1 standard deviation
1306 break;
1307 }
1308 } else {
1309 if (first) {
Elliott Hughesc073b072012-05-24 19:29:17 -07001310 os << "\nBig methods (size > " << i << " standard deviations the norm):\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001311 first = false;
1312 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001313 os << PrettyMethod(method_outlier[j]) << " requires storage of "
Elliott Hughesc073b072012-05-24 19:29:17 -07001314 << PrettySize(cur_size) << "\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001315 method_outlier_size[j] = 0; // don't consider this method again
1316 dumped_values++;
1317 }
1318 }
1319 }
1320 }
1321 }
1322 if (skipped_values > 0) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001323 os << "... skipped " << skipped_values
Elliott Hughesc073b072012-05-24 19:29:17 -07001324 << " methods with size > 1 standard deviation from the norm\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001325 }
Elliott Hughesc073b072012-05-24 19:29:17 -07001326 os << std::flush;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001327
1328 // Dump methods whose expansion is a certain number of standard deviations from the mean
1329 dumped_values = 0;
1330 skipped_values = 0;
1331 for (size_t i = 10; i > 0; i--) { // i is the current number of standard deviations
1332 double cur_expansion_variance = i * i * expansion_variance;
1333 bool first = true;
1334 for (size_t j = 0; j < n; j++) {
1335 double cur_expansion = method_outlier_expansion[j];
1336 if (cur_expansion > expansion_mean) {
1337 size_t cur_var = cur_expansion - expansion_mean;
1338 cur_var = cur_var * cur_var;
1339 if (cur_var > cur_expansion_variance) {
1340 if (dumped_values > 20) {
1341 if (i == 1) {
1342 skipped_values++;
1343 } else {
1344 i = 2; // jump to counting for 1 standard deviation
1345 break;
1346 }
1347 } else {
1348 if (first) {
1349 os << "\nLarge expansion methods (size > " << i
Elliott Hughesc073b072012-05-24 19:29:17 -07001350 << " standard deviations the norm):\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001351 first = false;
1352 }
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001353 os << PrettyMethod(method_outlier[j]) << " expanded code by "
Elliott Hughesc073b072012-05-24 19:29:17 -07001354 << cur_expansion << "\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001355 method_outlier_expansion[j] = 0.0; // don't consider this method again
1356 dumped_values++;
1357 }
1358 }
1359 }
1360 }
1361 }
1362 if (skipped_values > 0) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001363 os << "... skipped " << skipped_values
Elliott Hughesc073b072012-05-24 19:29:17 -07001364 << " methods with expansion > 1 standard deviation from the norm\n";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001365 }
Elliott Hughesc073b072012-05-24 19:29:17 -07001366 os << "\n" << std::flush;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001367 }
1368
Ian Rogersb726dcb2012-09-05 08:57:23 -07001369 void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001370 {
1371 os << "art_file_bytes = " << PrettySize(file_bytes) << "\n\n"
1372 << "art_file_bytes = header_bytes + object_bytes + alignment_bytes\n";
1373 Indenter indent_filter(os.rdbuf(), kIndentChar, kIndentBy1Count);
1374 std::ostream indent_os(&indent_filter);
1375 indent_os << StringPrintf("header_bytes = %8zd (%2.0f%% of art file bytes)\n"
1376 "object_bytes = %8zd (%2.0f%% of art file bytes)\n"
Mathieu Chartier32327092013-08-30 14:04:08 -07001377 "bitmap_bytes = %8zd (%2.0f%% of art file bytes)\n"
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001378 "alignment_bytes = %8zd (%2.0f%% of art file bytes)\n\n",
1379 header_bytes, PercentOfFileBytes(header_bytes),
1380 object_bytes, PercentOfFileBytes(object_bytes),
Mathieu Chartier32327092013-08-30 14:04:08 -07001381 bitmap_bytes, PercentOfFileBytes(bitmap_bytes),
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001382 alignment_bytes, PercentOfFileBytes(alignment_bytes))
1383 << std::flush;
Mathieu Chartier32327092013-08-30 14:04:08 -07001384 CHECK_EQ(file_bytes, bitmap_bytes + header_bytes + object_bytes + alignment_bytes);
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001385 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001386
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001387 os << "object_bytes breakdown:\n";
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001388 size_t object_bytes_total = 0;
Mathieu Chartier02e25112013-08-14 16:14:24 -07001389 for (const auto& sizes_and_count : sizes_and_counts) {
1390 const std::string& descriptor(sizes_and_count.first);
1391 double average = static_cast<double>(sizes_and_count.second.bytes) /
1392 static_cast<double>(sizes_and_count.second.count);
1393 double percent = PercentOfObjectBytes(sizes_and_count.second.bytes);
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001394 os << StringPrintf("%32s %8zd bytes %6zd instances "
Elliott Hughesa0e18062012-04-13 15:59:59 -07001395 "(%4.0f bytes/instance) %2.0f%% of object_bytes\n",
Mathieu Chartier02e25112013-08-14 16:14:24 -07001396 descriptor.c_str(), sizes_and_count.second.bytes,
1397 sizes_and_count.second.count, average, percent);
1398 object_bytes_total += sizes_and_count.second.bytes;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001399 }
Elliott Hughesc073b072012-05-24 19:29:17 -07001400 os << "\n" << std::flush;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001401 CHECK_EQ(object_bytes, object_bytes_total);
1402
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001403 os << StringPrintf("oat_file_bytes = %8zd\n"
1404 "managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n"
1405 "managed_to_native_code_bytes = %8zd (%2.0f%% of oat file bytes)\n"
1406 "native_to_managed_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n"
1407 "class_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n"
1408 "large_initializer_code_bytes = %8zd (%2.0f%% of oat file bytes)\n"
1409 "large_method_code_bytes = %8zd (%2.0f%% of oat file bytes)\n\n",
Ian Rogers05f28c62012-10-23 18:12:13 -07001410 oat_file_bytes,
Brian Carlstrom2ec65202014-03-03 15:16:37 -08001411 managed_code_bytes,
1412 PercentOfOatBytes(managed_code_bytes),
1413 managed_to_native_code_bytes,
1414 PercentOfOatBytes(managed_to_native_code_bytes),
1415 native_to_managed_code_bytes,
1416 PercentOfOatBytes(native_to_managed_code_bytes),
1417 class_initializer_code_bytes,
1418 PercentOfOatBytes(class_initializer_code_bytes),
1419 large_initializer_code_bytes,
1420 PercentOfOatBytes(large_initializer_code_bytes),
1421 large_method_code_bytes,
1422 PercentOfOatBytes(large_method_code_bytes))
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001423 << "DexFile sizes:\n";
Mathieu Chartier02e25112013-08-14 16:14:24 -07001424 for (const std::pair<std::string, size_t>& oat_dex_file_size : oat_dex_file_sizes) {
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001425 os << StringPrintf("%s = %zd (%2.0f%% of oat file bytes)\n",
Mathieu Chartier02e25112013-08-14 16:14:24 -07001426 oat_dex_file_size.first.c_str(), oat_dex_file_size.second,
1427 PercentOfOatBytes(oat_dex_file_size.second));
Ian Rogers05f28c62012-10-23 18:12:13 -07001428 }
1429
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001430 os << "\n" << StringPrintf("gc_map_bytes = %7zd (%2.0f%% of oat file bytes)\n"
1431 "pc_mapping_table_bytes = %7zd (%2.0f%% of oat file bytes)\n"
1432 "vmap_table_bytes = %7zd (%2.0f%% of oat file bytes)\n\n",
Ian Rogers05f28c62012-10-23 18:12:13 -07001433 gc_map_bytes, PercentOfOatBytes(gc_map_bytes),
1434 pc_mapping_table_bytes, PercentOfOatBytes(pc_mapping_table_bytes),
1435 vmap_table_bytes, PercentOfOatBytes(vmap_table_bytes))
Elliott Hughesc073b072012-05-24 19:29:17 -07001436 << std::flush;
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001437
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001438 os << StringPrintf("dex_instruction_bytes = %zd\n", dex_instruction_bytes)
1439 << StringPrintf("managed_code_bytes expansion = %.2f (ignoring deduplication %.2f)\n\n",
Brian Carlstrom2ec65202014-03-03 15:16:37 -08001440 static_cast<double>(managed_code_bytes) /
1441 static_cast<double>(dex_instruction_bytes),
Elliott Hughesc073b072012-05-24 19:29:17 -07001442 static_cast<double>(managed_code_bytes_ignoring_deduplication) /
Elliott Hughescf44e6f2012-05-24 19:42:18 -07001443 static_cast<double>(dex_instruction_bytes))
Elliott Hughesc073b072012-05-24 19:29:17 -07001444 << std::flush;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001445
1446 DumpOutliers(os);
Brian Carlstrom916e74e2011-09-23 11:42:01 -07001447 }
1448 } stats_;
1449
1450 private:
Ian Rogers0d2d3782012-04-10 11:09:18 -07001451 enum {
1452 // Number of bytes for a constructor to be considered large. Based on the 1000 basic block
1453 // threshold, we assume 2 bytes per instruction and 2 instructions per block.
1454 kLargeConstructorDexBytes = 4000,
1455 // Number of bytes for a method to be considered large. Based on the 4000 basic block
1456 // threshold, we assume 2 bytes per instruction and 2 instructions per block.
1457 kLargeMethodDexBytes = 16000
1458 };
Ian Rogers700a4022014-05-19 16:49:03 -07001459 std::unique_ptr<OatDumper> oat_dumper_;
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001460 std::ostream* os_;
Ian Rogers1d54e732013-05-02 21:10:01 -07001461 gc::space::ImageSpace& image_space_;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001462 const ImageHeader& image_header_;
Dave Allison404f59f2014-02-24 11:10:01 -08001463 bool dump_raw_mapping_table_;
1464 bool dump_raw_gc_map_;
Elliott Hughesd1bb4f62011-09-23 14:09:45 -07001465
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001466 DISALLOW_COPY_AND_ASSIGN(ImageDumper);
Brian Carlstrom78128a62011-09-15 17:21:19 -07001467};
1468
Elliott Hughes72395bf2012-04-24 13:45:26 -07001469static int oatdump(int argc, char** argv) {
Elliott Hughes0d39c122012-06-06 16:41:17 -07001470 InitLogging(argv);
Elliott Hughes72395bf2012-04-24 13:45:26 -07001471
Brian Carlstrom78128a62011-09-15 17:21:19 -07001472 // Skip over argv[0].
1473 argv++;
1474 argc--;
1475
1476 if (argc == 0) {
Brian Carlstromaded5f72011-10-07 17:15:04 -07001477 fprintf(stderr, "No arguments specified\n");
Brian Carlstrom78128a62011-09-15 17:21:19 -07001478 usage();
1479 }
1480
Brian Carlstromaded5f72011-10-07 17:15:04 -07001481 const char* oat_filename = NULL;
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001482 const char* image_location = NULL;
1483 const char* boot_image_location = NULL;
1484 InstructionSet instruction_set = kRuntimeISA;
Logan Chien0cc6ab62012-03-20 22:57:52 +08001485 std::string elf_filename_prefix;
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001486 std::ostream* os = &std::cout;
Ian Rogers700a4022014-05-19 16:49:03 -07001487 std::unique_ptr<std::ofstream> out;
Dave Allison404f59f2014-02-24 11:10:01 -08001488 bool dump_raw_mapping_table = false;
1489 bool dump_raw_gc_map = false;
Brian Carlstrom78128a62011-09-15 17:21:19 -07001490
1491 for (int i = 0; i < argc; i++) {
1492 const StringPiece option(argv[i]);
Brian Carlstroma6cc8932012-01-04 14:44:07 -08001493 if (option.starts_with("--oat-file=")) {
1494 oat_filename = option.substr(strlen("--oat-file=")).data();
Brian Carlstromaded5f72011-10-07 17:15:04 -07001495 } else if (option.starts_with("--image=")) {
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001496 image_location = option.substr(strlen("--image=")).data();
Brian Carlstrome24fa612011-09-29 00:53:55 -07001497 } else if (option.starts_with("--boot-image=")) {
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001498 boot_image_location = option.substr(strlen("--boot-image=")).data();
1499 } else if (option.starts_with("--instruction-set=")) {
1500 StringPiece instruction_set_str = option.substr(strlen("--instruction-set=")).data();
1501 if (instruction_set_str == "arm") {
1502 instruction_set = kThumb2;
1503 } else if (instruction_set_str == "arm64") {
1504 instruction_set = kArm64;
1505 } else if (instruction_set_str == "mips") {
1506 instruction_set = kMips;
1507 } else if (instruction_set_str == "x86") {
1508 instruction_set = kX86;
1509 } else if (instruction_set_str == "x86_64") {
1510 instruction_set = kX86_64;
1511 }
Dave Allison404f59f2014-02-24 11:10:01 -08001512 } else if (option.starts_with("--dump:")) {
1513 if (option == "--dump:raw_mapping_table") {
1514 dump_raw_mapping_table = true;
1515 } else if (option == "--dump:raw_gc_map") {
1516 dump_raw_gc_map = true;
1517 } else {
1518 fprintf(stderr, "Unknown argument %s\n", option.data());
1519 usage();
1520 }
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001521 } else if (option.starts_with("--output=")) {
1522 const char* filename = option.substr(strlen("--output=")).data();
1523 out.reset(new std::ofstream(filename));
1524 if (!out->good()) {
Brian Carlstromaded5f72011-10-07 17:15:04 -07001525 fprintf(stderr, "Failed to open output filename %s\n", filename);
Brian Carlstrom27ec9612011-09-19 20:20:38 -07001526 usage();
1527 }
1528 os = out.get();
Brian Carlstrom78128a62011-09-15 17:21:19 -07001529 } else {
Brian Carlstromaded5f72011-10-07 17:15:04 -07001530 fprintf(stderr, "Unknown argument %s\n", option.data());
Brian Carlstrom78128a62011-09-15 17:21:19 -07001531 usage();
1532 }
1533 }
1534
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001535 if (image_location == NULL && oat_filename == NULL) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -07001536 fprintf(stderr, "Either --image or --oat must be specified\n");
1537 return EXIT_FAILURE;
Brian Carlstrom78128a62011-09-15 17:21:19 -07001538 }
1539
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001540 if (image_location != NULL && oat_filename != NULL) {
Elliott Hughes362f9bc2011-10-17 18:56:41 -07001541 fprintf(stderr, "Either --image or --oat must be specified but not both\n");
1542 return EXIT_FAILURE;
Brian Carlstromaded5f72011-10-07 17:15:04 -07001543 }
1544
1545 if (oat_filename != NULL) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001546 std::string error_msg;
Logan Chien0c717dd2012-03-28 18:31:07 +08001547 OatFile* oat_file =
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001548 OatFile::Open(oat_filename, oat_filename, NULL, false, &error_msg);
Brian Carlstromaded5f72011-10-07 17:15:04 -07001549 if (oat_file == NULL) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001550 fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str());
Brian Carlstromaded5f72011-10-07 17:15:04 -07001551 return EXIT_FAILURE;
1552 }
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +00001553 OatDumper oat_dumper(*oat_file, dump_raw_mapping_table, dump_raw_gc_map);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001554 oat_dumper.Dump(*os);
Brian Carlstromaded5f72011-10-07 17:15:04 -07001555 return EXIT_SUCCESS;
1556 }
1557
Ian Rogerse63db272014-07-15 15:36:11 -07001558 RuntimeOptions options;
Brian Carlstrom78128a62011-09-15 17:21:19 -07001559 std::string image_option;
Brian Carlstrome24fa612011-09-29 00:53:55 -07001560 std::string oat_option;
Brian Carlstrom78128a62011-09-15 17:21:19 -07001561 std::string boot_image_option;
Brian Carlstrome24fa612011-09-29 00:53:55 -07001562 std::string boot_oat_option;
Brian Carlstrom6c871802013-07-17 14:25:35 -07001563
1564 // We are more like a compiler than a run-time. We don't want to execute code.
Brian Carlstromc0a1b182014-03-04 23:19:06 -08001565 NoopCompilerCallbacks callbacks;
1566 options.push_back(std::make_pair("compilercallbacks", &callbacks));
Brian Carlstrom6c871802013-07-17 14:25:35 -07001567
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001568 if (boot_image_location != NULL) {
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001569 boot_image_option += "-Ximage:";
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001570 boot_image_option += boot_image_location;
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001571 options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL)));
Brian Carlstrom78128a62011-09-15 17:21:19 -07001572 }
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001573 if (image_location != NULL) {
Brian Carlstromaded5f72011-10-07 17:15:04 -07001574 image_option += "-Ximage:";
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001575 image_option += image_location;
Brian Carlstromaded5f72011-10-07 17:15:04 -07001576 options.push_back(std::make_pair(image_option.c_str(), reinterpret_cast<void*>(NULL)));
1577 }
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001578 options.push_back(
1579 std::make_pair("imageinstructionset",
1580 reinterpret_cast<const void*>(GetInstructionSetString(instruction_set))));
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001581
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001582 if (!Runtime::Create(options, false)) {
Brian Carlstromaded5f72011-10-07 17:15:04 -07001583 fprintf(stderr, "Failed to create runtime\n");
Brian Carlstrom78128a62011-09-15 17:21:19 -07001584 return EXIT_FAILURE;
1585 }
Ian Rogers700a4022014-05-19 16:49:03 -07001586 std::unique_ptr<Runtime> runtime(Runtime::Current());
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001587 // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
Ian Rogersb9beb2e2014-05-09 16:57:40 -07001588 // give it away now and then switch to a more manageable ScopedObjectAccess.
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001589 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
1590 ScopedObjectAccess soa(Thread::Current());
Ian Rogers1d54e732013-05-02 21:10:01 -07001591 gc::Heap* heap = Runtime::Current()->GetHeap();
1592 gc::space::ImageSpace* image_space = heap->GetImageSpace();
Brian Carlstrom78128a62011-09-15 17:21:19 -07001593 CHECK(image_space != NULL);
1594 const ImageHeader& image_header = image_space->GetImageHeader();
1595 if (!image_header.IsValid()) {
Brian Carlstrom0f5baa02014-05-22 11:54:18 -07001596 fprintf(stderr, "Invalid image header %s\n", image_location);
Brian Carlstrom78128a62011-09-15 17:21:19 -07001597 return EXIT_FAILURE;
1598 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -08001599 ImageDumper image_dumper(os, *image_space, image_header,
1600 dump_raw_mapping_table, dump_raw_gc_map);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001601 image_dumper.Dump();
Brian Carlstrom78128a62011-09-15 17:21:19 -07001602 return EXIT_SUCCESS;
1603}
1604
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001605} // namespace art
Brian Carlstrom78128a62011-09-15 17:21:19 -07001606
1607int main(int argc, char** argv) {
1608 return art::oatdump(argc, argv);
1609}