blob: 5c0eb3f11682cb99ba85309632808ec89ec3a27c [file] [log] [blame]
Igor Murashkin37743352014-11-13 14:38:00 -08001/*
2 * Copyright (C) 2014 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 */
16
17#include <stdio.h>
18#include <stdlib.h>
19
20#include <fstream>
21#include <iostream>
22#include <string>
23#include <vector>
24#include <set>
25#include <map>
Mathieu Chartiercb044bc2016-04-01 13:56:41 -070026#include <unordered_set>
Igor Murashkin37743352014-11-13 14:38:00 -080027
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "art_method-inl.h"
Igor Murashkin37743352014-11-13 14:38:00 -080029#include "base/unix_file/fd_file.h"
30#include "base/stringprintf.h"
31#include "gc/space/image_space.h"
32#include "gc/heap.h"
33#include "mirror/class-inl.h"
34#include "mirror/object-inl.h"
Igor Murashkin37743352014-11-13 14:38:00 -080035#include "image.h"
36#include "scoped_thread_state_change.h"
37#include "os.h"
38#include "gc_map.h"
39
40#include "cmdline.h"
41#include "backtrace/BacktraceMap.h"
42
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <signal.h>
46
47namespace art {
48
49class ImgDiagDumper {
50 public:
51 explicit ImgDiagDumper(std::ostream* os,
Mathieu Chartiercb044bc2016-04-01 13:56:41 -070052 const ImageHeader& image_header,
53 const std::string& image_location,
54 pid_t image_diff_pid)
Igor Murashkin37743352014-11-13 14:38:00 -080055 : os_(os),
56 image_header_(image_header),
57 image_location_(image_location),
58 image_diff_pid_(image_diff_pid) {}
59
Mathieu Chartier90443472015-07-16 20:32:27 -070060 bool Dump() SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin37743352014-11-13 14:38:00 -080061 std::ostream& os = *os_;
Mathieu Chartiercb044bc2016-04-01 13:56:41 -070062 os << "IMAGE LOCATION: " << image_location_ << "\n\n";
63
Igor Murashkin37743352014-11-13 14:38:00 -080064 os << "MAGIC: " << image_header_.GetMagic() << "\n\n";
65
66 os << "IMAGE BEGIN: " << reinterpret_cast<void*>(image_header_.GetImageBegin()) << "\n\n";
67
68 bool ret = true;
69 if (image_diff_pid_ >= 0) {
70 os << "IMAGE DIFF PID (" << image_diff_pid_ << "): ";
71 ret = DumpImageDiff(image_diff_pid_);
72 os << "\n\n";
73 } else {
74 os << "IMAGE DIFF PID: disabled\n\n";
75 }
76
77 os << std::flush;
78
79 return ret;
80 }
81
82 private:
83 static bool EndsWith(const std::string& str, const std::string& suffix) {
84 return str.size() >= suffix.size() &&
85 str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
86 }
87
88 // Return suffix of the file path after the last /. (e.g. /foo/bar -> bar, bar -> bar)
89 static std::string BaseName(const std::string& str) {
90 size_t idx = str.rfind("/");
91 if (idx == std::string::npos) {
92 return str;
93 }
94
95 return str.substr(idx + 1);
96 }
97
Mathieu Chartier90443472015-07-16 20:32:27 -070098 bool DumpImageDiff(pid_t image_diff_pid) SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin37743352014-11-13 14:38:00 -080099 std::ostream& os = *os_;
100
101 {
102 struct stat sts;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700103 std::string proc_pid_str =
104 StringPrintf("/proc/%ld", static_cast<long>(image_diff_pid)); // NOLINT [runtime/int]
Igor Murashkin37743352014-11-13 14:38:00 -0800105 if (stat(proc_pid_str.c_str(), &sts) == -1) {
106 os << "Process does not exist";
107 return false;
108 }
109 }
110
111 // Open /proc/$pid/maps to view memory maps
112 auto proc_maps = std::unique_ptr<BacktraceMap>(BacktraceMap::Create(image_diff_pid));
113 if (proc_maps == nullptr) {
114 os << "Could not read backtrace maps";
115 return false;
116 }
117
118 bool found_boot_map = false;
119 backtrace_map_t boot_map = backtrace_map_t();
120 // Find the memory map only for boot.art
121 for (const backtrace_map_t& map : *proc_maps) {
122 if (EndsWith(map.name, GetImageLocationBaseName())) {
123 if ((map.flags & PROT_WRITE) != 0) {
124 boot_map = map;
125 found_boot_map = true;
126 break;
127 }
128 // In actuality there's more than 1 map, but the second one is read-only.
129 // The one we care about is the write-able map.
130 // The readonly maps are guaranteed to be identical, so its not interesting to compare
131 // them.
132 }
133 }
134
135 if (!found_boot_map) {
136 os << "Could not find map for " << GetImageLocationBaseName();
137 return false;
138 }
139
140 // Future idea: diff against zygote so we can ignore the shared dirty pages.
141 return DumpImageDiffMap(image_diff_pid, boot_map);
142 }
143
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700144 static std::string PrettyFieldValue(ArtField* field, mirror::Object* obj)
145 SHARED_REQUIRES(Locks::mutator_lock_) {
146 std::ostringstream oss;
147 switch (field->GetTypeAsPrimitiveType()) {
148 case Primitive::kPrimNot: {
149 oss << obj->GetFieldObject<mirror::Object, kVerifyNone, kWithoutReadBarrier>(
150 field->GetOffset());
151 break;
152 }
153 case Primitive::kPrimBoolean: {
154 oss << static_cast<bool>(obj->GetFieldBoolean<kVerifyNone>(field->GetOffset()));
155 break;
156 }
157 case Primitive::kPrimByte: {
158 oss << static_cast<int32_t>(obj->GetFieldByte<kVerifyNone>(field->GetOffset()));
159 break;
160 }
161 case Primitive::kPrimChar: {
162 oss << obj->GetFieldChar<kVerifyNone>(field->GetOffset());
163 break;
164 }
165 case Primitive::kPrimShort: {
166 oss << obj->GetFieldShort<kVerifyNone>(field->GetOffset());
167 break;
168 }
169 case Primitive::kPrimInt: {
170 oss << obj->GetField32<kVerifyNone>(field->GetOffset());
171 break;
172 }
173 case Primitive::kPrimLong: {
174 oss << obj->GetField64<kVerifyNone>(field->GetOffset());
175 break;
176 }
177 case Primitive::kPrimFloat: {
178 oss << obj->GetField32<kVerifyNone>(field->GetOffset());
179 break;
180 }
181 case Primitive::kPrimDouble: {
182 oss << obj->GetField64<kVerifyNone>(field->GetOffset());
183 break;
184 }
185 case Primitive::kPrimVoid: {
186 oss << "void";
187 break;
188 }
189 }
190 return oss.str();
191 }
192
193 // Look at /proc/$pid/mem and only diff the things from there
Igor Murashkin37743352014-11-13 14:38:00 -0800194 bool DumpImageDiffMap(pid_t image_diff_pid, const backtrace_map_t& boot_map)
Mathieu Chartier90443472015-07-16 20:32:27 -0700195 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin37743352014-11-13 14:38:00 -0800196 std::ostream& os = *os_;
197 const size_t pointer_size = InstructionSetPointerSize(
198 Runtime::Current()->GetInstructionSet());
199
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700200 std::string file_name =
201 StringPrintf("/proc/%ld/mem", static_cast<long>(image_diff_pid)); // NOLINT [runtime/int]
Igor Murashkin37743352014-11-13 14:38:00 -0800202
203 size_t boot_map_size = boot_map.end - boot_map.start;
204
205 // Open /proc/$pid/mem as a file
206 auto map_file = std::unique_ptr<File>(OS::OpenFileForReading(file_name.c_str()));
207 if (map_file == nullptr) {
208 os << "Failed to open " << file_name << " for reading";
209 return false;
210 }
211
212 // Memory-map /proc/$pid/mem subset from the boot map
213 CHECK(boot_map.end >= boot_map.start);
214
215 std::string error_msg;
216
217 // Walk the bytes and diff against our boot image
Andreas Gampe8994a042015-12-30 19:03:17 +0000218 const ImageHeader& boot_image_header = image_header_;
Igor Murashkin37743352014-11-13 14:38:00 -0800219
220 os << "\nObserving boot image header at address "
221 << reinterpret_cast<const void*>(&boot_image_header)
222 << "\n\n";
223
224 const uint8_t* image_begin_unaligned = boot_image_header.GetImageBegin();
Mathieu Chartierc7853442015-03-27 14:35:38 -0700225 const uint8_t* image_mirror_end_unaligned = image_begin_unaligned +
Mathieu Chartiere401d142015-04-22 13:56:20 -0700226 boot_image_header.GetImageSection(ImageHeader::kSectionObjects).Size();
227 const uint8_t* image_end_unaligned = image_begin_unaligned + boot_image_header.GetImageSize();
Igor Murashkin37743352014-11-13 14:38:00 -0800228
229 // Adjust range to nearest page
230 const uint8_t* image_begin = AlignDown(image_begin_unaligned, kPageSize);
231 const uint8_t* image_end = AlignUp(image_end_unaligned, kPageSize);
232
233 ptrdiff_t page_off_begin = boot_image_header.GetImageBegin() - image_begin;
234
235 if (reinterpret_cast<uintptr_t>(image_begin) > boot_map.start ||
236 reinterpret_cast<uintptr_t>(image_end) < boot_map.end) {
237 // Sanity check that we aren't trying to read a completely different boot image
238 os << "Remote boot map is out of range of local boot map: " <<
239 "local begin " << reinterpret_cast<const void*>(image_begin) <<
240 ", local end " << reinterpret_cast<const void*>(image_end) <<
241 ", remote begin " << reinterpret_cast<const void*>(boot_map.start) <<
242 ", remote end " << reinterpret_cast<const void*>(boot_map.end);
243 return false;
244 // If we wanted even more validation we could map the ImageHeader from the file
245 }
246
247 std::vector<uint8_t> remote_contents(boot_map_size);
248 if (!map_file->PreadFully(&remote_contents[0], boot_map_size, boot_map.start)) {
249 os << "Could not fully read file " << file_name;
250 return false;
251 }
252
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700253 std::string page_map_file_name = StringPrintf(
254 "/proc/%ld/pagemap", static_cast<long>(image_diff_pid)); // NOLINT [runtime/int]
Igor Murashkin37743352014-11-13 14:38:00 -0800255 auto page_map_file = std::unique_ptr<File>(OS::OpenFileForReading(page_map_file_name.c_str()));
256 if (page_map_file == nullptr) {
257 os << "Failed to open " << page_map_file_name << " for reading: " << strerror(errno);
258 return false;
259 }
260
261 // Not truly clean, mmap-ing boot.art again would be more pristine, but close enough
262 const char* clean_page_map_file_name = "/proc/self/pagemap";
263 auto clean_page_map_file = std::unique_ptr<File>(
264 OS::OpenFileForReading(clean_page_map_file_name));
265 if (clean_page_map_file == nullptr) {
266 os << "Failed to open " << clean_page_map_file_name << " for reading: " << strerror(errno);
267 return false;
268 }
269
270 auto kpage_flags_file = std::unique_ptr<File>(OS::OpenFileForReading("/proc/kpageflags"));
271 if (kpage_flags_file == nullptr) {
272 os << "Failed to open /proc/kpageflags for reading: " << strerror(errno);
273 return false;
274 }
275
276 auto kpage_count_file = std::unique_ptr<File>(OS::OpenFileForReading("/proc/kpagecount"));
277 if (kpage_count_file == nullptr) {
278 os << "Failed to open /proc/kpagecount for reading:" << strerror(errno);
279 return false;
280 }
281
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700282 // Set of the remote virtual page indices that are dirty
283 std::set<size_t> dirty_page_set_remote;
284 // Set of the local virtual page indices that are dirty
285 std::set<size_t> dirty_page_set_local;
Igor Murashkin37743352014-11-13 14:38:00 -0800286
287 size_t different_int32s = 0;
288 size_t different_bytes = 0;
289 size_t different_pages = 0;
290 size_t virtual_page_idx = 0; // Virtual page number (for an absolute memory address)
291 size_t page_idx = 0; // Page index relative to 0
292 size_t previous_page_idx = 0; // Previous page index relative to 0
293 size_t dirty_pages = 0;
294 size_t private_pages = 0;
295 size_t private_dirty_pages = 0;
296
297 // Iterate through one page at a time. Boot map begin/end already implicitly aligned.
298 for (uintptr_t begin = boot_map.start; begin != boot_map.end; begin += kPageSize) {
299 ptrdiff_t offset = begin - boot_map.start;
300
301 // We treat the image header as part of the memory map for now
302 // If we wanted to change this, we could pass base=start+sizeof(ImageHeader)
303 // But it might still be interesting to see if any of the ImageHeader data mutated
304 const uint8_t* local_ptr = reinterpret_cast<const uint8_t*>(&boot_image_header) + offset;
305 uint8_t* remote_ptr = &remote_contents[offset];
306
307 if (memcmp(local_ptr, remote_ptr, kPageSize) != 0) {
308 different_pages++;
309
310 // Count the number of 32-bit integers that are different.
311 for (size_t i = 0; i < kPageSize / sizeof(uint32_t); ++i) {
312 uint32_t* remote_ptr_int32 = reinterpret_cast<uint32_t*>(remote_ptr);
313 const uint32_t* local_ptr_int32 = reinterpret_cast<const uint32_t*>(local_ptr);
314
315 if (remote_ptr_int32[i] != local_ptr_int32[i]) {
316 different_int32s++;
317 }
318 }
319 }
320 }
321
322 // Iterate through one byte at a time.
323 for (uintptr_t begin = boot_map.start; begin != boot_map.end; ++begin) {
324 previous_page_idx = page_idx;
325 ptrdiff_t offset = begin - boot_map.start;
326
327 // We treat the image header as part of the memory map for now
328 // If we wanted to change this, we could pass base=start+sizeof(ImageHeader)
329 // But it might still be interesting to see if any of the ImageHeader data mutated
330 const uint8_t* local_ptr = reinterpret_cast<const uint8_t*>(&boot_image_header) + offset;
331 uint8_t* remote_ptr = &remote_contents[offset];
332
333 virtual_page_idx = reinterpret_cast<uintptr_t>(local_ptr) / kPageSize;
334
335 // Calculate the page index, relative to the 0th page where the image begins
336 page_idx = (offset + page_off_begin) / kPageSize;
337 if (*local_ptr != *remote_ptr) {
338 // Track number of bytes that are different
339 different_bytes++;
340 }
341
342 // Independently count the # of dirty pages on the remote side
343 size_t remote_virtual_page_idx = begin / kPageSize;
344 if (previous_page_idx != page_idx) {
345 uint64_t page_count = 0xC0FFEE;
346 // TODO: virtual_page_idx needs to be from the same process
347 int dirtiness = (IsPageDirty(page_map_file.get(), // Image-diff-pid procmap
348 clean_page_map_file.get(), // Self procmap
349 kpage_flags_file.get(),
350 kpage_count_file.get(),
351 remote_virtual_page_idx, // potentially "dirty" page
352 virtual_page_idx, // true "clean" page
353 &page_count,
354 &error_msg));
355 if (dirtiness < 0) {
356 os << error_msg;
357 return false;
358 } else if (dirtiness > 0) {
359 dirty_pages++;
360 dirty_page_set_remote.insert(dirty_page_set_remote.end(), remote_virtual_page_idx);
361 dirty_page_set_local.insert(dirty_page_set_local.end(), virtual_page_idx);
362 }
363
364 bool is_dirty = dirtiness > 0;
365 bool is_private = page_count == 1;
366
367 if (page_count == 1) {
368 private_pages++;
369 }
370
371 if (is_dirty && is_private) {
372 private_dirty_pages++;
373 }
374 }
375 }
376
377 // Walk each object in the remote image space and compare it against ours
378 size_t different_objects = 0;
379 std::map<mirror::Class*, int /*count*/> dirty_object_class_map;
380 // Track only the byte-per-byte dirtiness (in bytes)
381 std::map<mirror::Class*, int /*byte_count*/> dirty_object_byte_count;
382 // Track the object-by-object dirtiness (in bytes)
383 std::map<mirror::Class*, int /*byte_count*/> dirty_object_size_in_bytes;
384 std::map<mirror::Class*, int /*count*/> clean_object_class_map;
385
386 std::map<mirror::Class*, std::string> class_to_descriptor_map;
387
388 std::map<off_t /* field offset */, int /* count */> art_method_field_dirty_count;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700389 std::vector<ArtMethod*> art_method_dirty_objects;
Igor Murashkin37743352014-11-13 14:38:00 -0800390
391 std::map<off_t /* field offset */, int /* count */> class_field_dirty_count;
392 std::vector<mirror::Class*> class_dirty_objects;
393
394 // List of local objects that are clean, but located on dirty pages.
395 std::vector<mirror::Object*> false_dirty_objects;
396 std::map<mirror::Class*, int /*byte_count*/> false_dirty_byte_count;
397 std::map<mirror::Class*, int /*object_count*/> false_dirty_object_count;
398 std::map<mirror::Class*, std::vector<mirror::Object*>> false_dirty_objects_map;
399 size_t false_dirty_object_bytes = 0;
400
401 // Remote pointers to dirty objects
402 std::map<mirror::Class*, std::vector<mirror::Object*>> dirty_objects_by_class;
403 // Look up remote classes by their descriptor
404 std::map<std::string, mirror::Class*> remote_class_map;
405 // Look up local classes by their descriptor
406 std::map<std::string, mirror::Class*> local_class_map;
407
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700408 std::unordered_set<mirror::Object*> dirty_objects;
409
Igor Murashkin37743352014-11-13 14:38:00 -0800410 size_t dirty_object_bytes = 0;
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700411 const uint8_t* begin_image_ptr = image_begin_unaligned;
412 const uint8_t* end_image_ptr = image_mirror_end_unaligned;
Igor Murashkin37743352014-11-13 14:38:00 -0800413
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700414 const uint8_t* current = begin_image_ptr + RoundUp(sizeof(ImageHeader), kObjectAlignment);
415 while (reinterpret_cast<uintptr_t>(current) < reinterpret_cast<uintptr_t>(end_image_ptr)) {
416 CHECK_ALIGNED(current, kObjectAlignment);
417 mirror::Object* obj = reinterpret_cast<mirror::Object*>(const_cast<uint8_t*>(current));
Igor Murashkin37743352014-11-13 14:38:00 -0800418
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700419 // Sanity check that we are reading a real object
420 CHECK(obj->GetClass() != nullptr) << "Image object at address " << obj << " has null class";
421 if (kUseBakerOrBrooksReadBarrier) {
422 obj->AssertReadBarrierPointer();
423 }
424
425 // Iterate every page this object belongs to
426 bool on_dirty_page = false;
427 size_t page_off = 0;
428 size_t current_page_idx;
429 uintptr_t object_address;
430 do {
431 object_address = reinterpret_cast<uintptr_t>(current);
432 current_page_idx = object_address / kPageSize + page_off;
433
434 if (dirty_page_set_local.find(current_page_idx) != dirty_page_set_local.end()) {
435 // This object is on a dirty page
436 on_dirty_page = true;
Igor Murashkin37743352014-11-13 14:38:00 -0800437 }
438
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700439 page_off++;
440 } while ((current_page_idx * kPageSize) <
441 RoundUp(object_address + obj->SizeOf(), kObjectAlignment));
Igor Murashkin37743352014-11-13 14:38:00 -0800442
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700443 mirror::Class* klass = obj->GetClass();
444
445 bool different_object = false;
446
447 // Check against the other object and see if they are different
448 ptrdiff_t offset = current - begin_image_ptr;
449 const uint8_t* current_remote = &remote_contents[offset];
450 mirror::Object* remote_obj = reinterpret_cast<mirror::Object*>(
451 const_cast<uint8_t*>(current_remote));
452 if (memcmp(current, current_remote, obj->SizeOf()) != 0) {
453 different_objects++;
454 dirty_object_bytes += obj->SizeOf();
455 dirty_objects.insert(obj);
456
457 ++dirty_object_class_map[klass];
458
459 // Go byte-by-byte and figure out what exactly got dirtied
460 size_t dirty_byte_count_per_object = 0;
461 for (size_t i = 0; i < obj->SizeOf(); ++i) {
462 if (current[i] != current_remote[i]) {
463 dirty_byte_count_per_object++;
Igor Murashkin37743352014-11-13 14:38:00 -0800464 }
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700465 }
466 dirty_object_byte_count[klass] += dirty_byte_count_per_object;
467 dirty_object_size_in_bytes[klass] += obj->SizeOf();
Igor Murashkin37743352014-11-13 14:38:00 -0800468
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700469 different_object = true;
Igor Murashkin37743352014-11-13 14:38:00 -0800470
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700471 dirty_objects_by_class[klass].push_back(remote_obj);
472 } else {
473 ++clean_object_class_map[klass];
474 }
Igor Murashkin37743352014-11-13 14:38:00 -0800475
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700476 std::string descriptor = GetClassDescriptor(klass);
477 if (different_object) {
478 if (klass->IsClassClass()) {
479 // this is a "Class"
480 mirror::Class* obj_as_class = reinterpret_cast<mirror::Class*>(remote_obj);
Igor Murashkin37743352014-11-13 14:38:00 -0800481
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700482 // print the fields that are dirty
Igor Murashkin37743352014-11-13 14:38:00 -0800483 for (size_t i = 0; i < obj->SizeOf(); ++i) {
484 if (current[i] != current_remote[i]) {
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700485 class_field_dirty_count[i]++;
Igor Murashkin37743352014-11-13 14:38:00 -0800486 }
487 }
Igor Murashkin37743352014-11-13 14:38:00 -0800488
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700489 class_dirty_objects.push_back(obj_as_class);
490 } else if (strcmp(descriptor.c_str(), "Ljava/lang/reflect/ArtMethod;") == 0) {
491 // this is an ArtMethod
492 ArtMethod* art_method = reinterpret_cast<ArtMethod*>(remote_obj);
Igor Murashkin37743352014-11-13 14:38:00 -0800493
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700494 // print the fields that are dirty
495 for (size_t i = 0; i < obj->SizeOf(); ++i) {
496 if (current[i] != current_remote[i]) {
497 art_method_field_dirty_count[i]++;
Igor Murashkin37743352014-11-13 14:38:00 -0800498 }
Igor Murashkin37743352014-11-13 14:38:00 -0800499 }
Igor Murashkin37743352014-11-13 14:38:00 -0800500
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700501 art_method_dirty_objects.push_back(art_method);
Igor Murashkin37743352014-11-13 14:38:00 -0800502 }
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700503 } else if (on_dirty_page) {
504 // This object was either never mutated or got mutated back to the same value.
505 // TODO: Do I want to distinguish a "different" vs a "dirty" page here?
506 false_dirty_objects.push_back(obj);
507 false_dirty_objects_map[klass].push_back(obj);
508 false_dirty_object_bytes += obj->SizeOf();
509 false_dirty_byte_count[obj->GetClass()] += obj->SizeOf();
510 false_dirty_object_count[obj->GetClass()] += 1;
Igor Murashkin37743352014-11-13 14:38:00 -0800511 }
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700512
513 if (strcmp(descriptor.c_str(), "Ljava/lang/Class;") == 0) {
514 local_class_map[descriptor] = reinterpret_cast<mirror::Class*>(obj);
515 remote_class_map[descriptor] = reinterpret_cast<mirror::Class*>(remote_obj);
516 }
517
518 // Unconditionally store the class descriptor in case we need it later
519 class_to_descriptor_map[klass] = descriptor;
520 current += RoundUp(obj->SizeOf(), kObjectAlignment);
Igor Murashkin37743352014-11-13 14:38:00 -0800521 }
522
523 // Looking at only dirty pages, figure out how many of those bytes belong to dirty objects.
524 float true_dirtied_percent = dirty_object_bytes * 1.0f / (dirty_pages * kPageSize);
525 size_t false_dirty_pages = dirty_pages - different_pages;
526
527 os << "Mapping at [" << reinterpret_cast<void*>(boot_map.start) << ", "
528 << reinterpret_cast<void*>(boot_map.end) << ") had: \n "
529 << different_bytes << " differing bytes, \n "
530 << different_int32s << " differing int32s, \n "
531 << different_objects << " different objects, \n "
532 << dirty_object_bytes << " different object [bytes], \n "
533 << false_dirty_objects.size() << " false dirty objects,\n "
534 << false_dirty_object_bytes << " false dirty object [bytes], \n "
535 << true_dirtied_percent << " different objects-vs-total in a dirty page;\n "
536 << different_pages << " different pages; \n "
537 << dirty_pages << " pages are dirty; \n "
538 << false_dirty_pages << " pages are false dirty; \n "
539 << private_pages << " pages are private; \n "
540 << private_dirty_pages << " pages are Private_Dirty\n "
541 << "";
542
543 // vector of pairs (int count, Class*)
544 auto dirty_object_class_values = SortByValueDesc(dirty_object_class_map);
545 auto clean_object_class_values = SortByValueDesc(clean_object_class_map);
546
Mathieu Chartiercb044bc2016-04-01 13:56:41 -0700547 os << "\n" << " Dirty objects: " << dirty_objects.size() << "\n";
548 for (mirror::Object* obj : dirty_objects) {
549 const char* tabs = " ";
550 // Attempt to find fields for all dirty bytes.
551 mirror::Class* klass = obj->GetClass();
552 if (obj->IsClass()) {
553 os << tabs << "Class " << PrettyClass(obj->AsClass()) << " " << obj << "\n";
554 } else {
555 os << tabs << "Instance of " << PrettyClass(klass) << " " << obj << "\n";
556 }
557
558 std::unordered_set<ArtField*> dirty_instance_fields;
559 std::unordered_set<ArtField*> dirty_static_fields;
560 const uint8_t* obj_bytes = reinterpret_cast<const uint8_t*>(obj);
561 ptrdiff_t offset = obj_bytes - begin_image_ptr;
562 uint8_t* remote_bytes = &remote_contents[offset];
563 mirror::Object* remote_obj = reinterpret_cast<mirror::Object*>(remote_bytes);
564 for (size_t i = 0, count = obj->SizeOf(); i < count; ++i) {
565 if (obj_bytes[i] != remote_bytes[i]) {
566 ArtField* field = ArtField::FindInstanceFieldWithOffset</*exact*/false>(klass, i);
567 if (field != nullptr) {
568 dirty_instance_fields.insert(field);
569 } else if (obj->IsClass()) {
570 field = ArtField::FindStaticFieldWithOffset</*exact*/false>(obj->AsClass(), i);
571 if (field != nullptr) {
572 dirty_static_fields.insert(field);
573 }
574 }
575 if (field == nullptr) {
576 if (klass->IsArrayClass()) {
577 mirror::Class* component_type = klass->GetComponentType();
578 Primitive::Type primitive_type = component_type->GetPrimitiveType();
579 size_t component_size = Primitive::ComponentSize(primitive_type);
580 size_t data_offset = mirror::Array::DataOffset(component_size).Uint32Value();
581 if (i >= data_offset) {
582 os << tabs << "Dirty array element " << (i - data_offset) / component_size << "\n";
583 // Skip to next element to prevent spam.
584 i += component_size - 1;
585 continue;
586 }
587 }
588 os << tabs << "No field for byte offset " << i << "\n";
589 }
590 }
591 }
592 // Dump different fields. TODO: Dump field contents.
593 if (!dirty_instance_fields.empty()) {
594 os << tabs << "Dirty instance fields " << dirty_instance_fields.size() << "\n";
595 for (ArtField* field : dirty_instance_fields) {
596 os << tabs << PrettyField(field)
597 << " original=" << PrettyFieldValue(field, obj)
598 << " remote=" << PrettyFieldValue(field, remote_obj) << "\n";
599 }
600 }
601 if (!dirty_static_fields.empty()) {
602 os << tabs << "Dirty static fields " << dirty_static_fields.size() << "\n";
603 for (ArtField* field : dirty_static_fields) {
604 os << tabs << PrettyField(field)
605 << " original=" << PrettyFieldValue(field, obj)
606 << " remote=" << PrettyFieldValue(field, remote_obj) << "\n";
607 }
608 }
609 os << "\n";
610 }
611
Igor Murashkin37743352014-11-13 14:38:00 -0800612 os << "\n" << " Dirty object count by class:\n";
613 for (const auto& vk_pair : dirty_object_class_values) {
614 int dirty_object_count = vk_pair.first;
615 mirror::Class* klass = vk_pair.second;
616 int object_sizes = dirty_object_size_in_bytes[klass];
617 float avg_dirty_bytes_per_class = dirty_object_byte_count[klass] * 1.0f / object_sizes;
618 float avg_object_size = object_sizes * 1.0f / dirty_object_count;
619 const std::string& descriptor = class_to_descriptor_map[klass];
620 os << " " << PrettyClass(klass) << " ("
621 << "objects: " << dirty_object_count << ", "
622 << "avg dirty bytes: " << avg_dirty_bytes_per_class << ", "
623 << "avg object size: " << avg_object_size << ", "
624 << "class descriptor: '" << descriptor << "'"
625 << ")\n";
626
627 constexpr size_t kMaxAddressPrint = 5;
628 if (strcmp(descriptor.c_str(), "Ljava/lang/reflect/ArtMethod;") == 0) {
629 os << " sample object addresses: ";
630 for (size_t i = 0; i < art_method_dirty_objects.size() && i < kMaxAddressPrint; ++i) {
631 auto art_method = art_method_dirty_objects[i];
632
633 os << reinterpret_cast<void*>(art_method) << ", ";
634 }
635 os << "\n";
636
637 os << " dirty byte +offset:count list = ";
638 auto art_method_field_dirty_count_sorted = SortByValueDesc(art_method_field_dirty_count);
639 for (auto pair : art_method_field_dirty_count_sorted) {
640 off_t offset = pair.second;
641 int count = pair.first;
642
643 os << "+" << offset << ":" << count << ", ";
644 }
645
646 os << "\n";
647
648 os << " field contents:\n";
649 const auto& dirty_objects_list = dirty_objects_by_class[klass];
650 for (mirror::Object* obj : dirty_objects_list) {
651 // remote method
Mathieu Chartiere401d142015-04-22 13:56:20 -0700652 auto art_method = reinterpret_cast<ArtMethod*>(obj);
Igor Murashkin37743352014-11-13 14:38:00 -0800653
654 // remote class
655 mirror::Class* remote_declaring_class =
656 FixUpRemotePointer(art_method->GetDeclaringClass(), remote_contents, boot_map);
657
658 // local class
659 mirror::Class* declaring_class =
660 RemoteContentsPointerToLocal(remote_declaring_class,
661 remote_contents,
662 boot_image_header);
663
664 os << " " << reinterpret_cast<void*>(obj) << " ";
665 os << " entryPointFromJni: "
666 << reinterpret_cast<const void*>(
667 art_method->GetEntryPointFromJniPtrSize(pointer_size)) << ", ";
Igor Murashkin37743352014-11-13 14:38:00 -0800668 os << " entryPointFromQuickCompiledCode: "
669 << reinterpret_cast<const void*>(
670 art_method->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size))
671 << ", ";
672 os << " isNative? " << (art_method->IsNative() ? "yes" : "no") << ", ";
673 os << " class_status (local): " << declaring_class->GetStatus();
674 os << " class_status (remote): " << remote_declaring_class->GetStatus();
675 os << "\n";
676 }
677 }
678 if (strcmp(descriptor.c_str(), "Ljava/lang/Class;") == 0) {
679 os << " sample object addresses: ";
680 for (size_t i = 0; i < class_dirty_objects.size() && i < kMaxAddressPrint; ++i) {
681 auto class_ptr = class_dirty_objects[i];
682
683 os << reinterpret_cast<void*>(class_ptr) << ", ";
684 }
685 os << "\n";
686
687 os << " dirty byte +offset:count list = ";
688 auto class_field_dirty_count_sorted = SortByValueDesc(class_field_dirty_count);
689 for (auto pair : class_field_dirty_count_sorted) {
690 off_t offset = pair.second;
691 int count = pair.first;
692
693 os << "+" << offset << ":" << count << ", ";
694 }
695 os << "\n";
696
697 os << " field contents:\n";
698 const auto& dirty_objects_list = dirty_objects_by_class[klass];
699 for (mirror::Object* obj : dirty_objects_list) {
700 // remote class object
701 auto remote_klass = reinterpret_cast<mirror::Class*>(obj);
702
703 // local class object
704 auto local_klass = RemoteContentsPointerToLocal(remote_klass,
705 remote_contents,
706 boot_image_header);
707
708 os << " " << reinterpret_cast<void*>(obj) << " ";
709 os << " class_status (remote): " << remote_klass->GetStatus() << ", ";
710 os << " class_status (local): " << local_klass->GetStatus();
711 os << "\n";
712 }
713 }
714 }
715
716 auto false_dirty_object_class_values = SortByValueDesc(false_dirty_object_count);
717
718 os << "\n" << " False-dirty object count by class:\n";
719 for (const auto& vk_pair : false_dirty_object_class_values) {
720 int object_count = vk_pair.first;
721 mirror::Class* klass = vk_pair.second;
722 int object_sizes = false_dirty_byte_count[klass];
723 float avg_object_size = object_sizes * 1.0f / object_count;
724 const std::string& descriptor = class_to_descriptor_map[klass];
725 os << " " << PrettyClass(klass) << " ("
726 << "objects: " << object_count << ", "
727 << "avg object size: " << avg_object_size << ", "
728 << "total bytes: " << object_sizes << ", "
729 << "class descriptor: '" << descriptor << "'"
730 << ")\n";
731
732 if (strcmp(descriptor.c_str(), "Ljava/lang/reflect/ArtMethod;") == 0) {
733 auto& art_method_false_dirty_objects = false_dirty_objects_map[klass];
734
735 os << " field contents:\n";
736 for (mirror::Object* obj : art_method_false_dirty_objects) {
737 // local method
Mathieu Chartiere401d142015-04-22 13:56:20 -0700738 auto art_method = reinterpret_cast<ArtMethod*>(obj);
Igor Murashkin37743352014-11-13 14:38:00 -0800739
740 // local class
741 mirror::Class* declaring_class = art_method->GetDeclaringClass();
742
743 os << " " << reinterpret_cast<void*>(obj) << " ";
744 os << " entryPointFromJni: "
745 << reinterpret_cast<const void*>(
746 art_method->GetEntryPointFromJniPtrSize(pointer_size)) << ", ";
Igor Murashkin37743352014-11-13 14:38:00 -0800747 os << " entryPointFromQuickCompiledCode: "
748 << reinterpret_cast<const void*>(
749 art_method->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size))
750 << ", ";
751 os << " isNative? " << (art_method->IsNative() ? "yes" : "no") << ", ";
752 os << " class_status (local): " << declaring_class->GetStatus();
753 os << "\n";
754 }
755 }
756 }
757
758 os << "\n" << " Clean object count by class:\n";
759 for (const auto& vk_pair : clean_object_class_values) {
760 os << " " << PrettyClass(vk_pair.second) << " (" << vk_pair.first << ")\n";
761 }
762
763 return true;
764 }
765
766 // Fixup a remote pointer that we read from a foreign boot.art to point to our own memory.
767 // Returned pointer will point to inside of remote_contents.
768 template <typename T>
769 static T* FixUpRemotePointer(T* remote_ptr,
770 std::vector<uint8_t>& remote_contents,
771 const backtrace_map_t& boot_map) {
772 if (remote_ptr == nullptr) {
773 return nullptr;
774 }
775
776 uintptr_t remote = reinterpret_cast<uintptr_t>(remote_ptr);
777
778 CHECK_LE(boot_map.start, remote);
779 CHECK_GT(boot_map.end, remote);
780
781 off_t boot_offset = remote - boot_map.start;
782
783 return reinterpret_cast<T*>(&remote_contents[boot_offset]);
784 }
785
786 template <typename T>
787 static T* RemoteContentsPointerToLocal(T* remote_ptr,
788 std::vector<uint8_t>& remote_contents,
789 const ImageHeader& image_header) {
790 if (remote_ptr == nullptr) {
791 return nullptr;
792 }
793
794 uint8_t* remote = reinterpret_cast<uint8_t*>(remote_ptr);
795 ptrdiff_t boot_offset = remote - &remote_contents[0];
796
797 const uint8_t* local_ptr = reinterpret_cast<const uint8_t*>(&image_header) + boot_offset;
798
799 return reinterpret_cast<T*>(const_cast<uint8_t*>(local_ptr));
800 }
801
802 static std::string GetClassDescriptor(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700803 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin37743352014-11-13 14:38:00 -0800804 CHECK(klass != nullptr);
805
806 std::string descriptor;
807 const char* descriptor_str = klass->GetDescriptor(&descriptor);
808
809 return std::string(descriptor_str);
810 }
811
812 template <typename K, typename V>
813 static std::vector<std::pair<V, K>> SortByValueDesc(const std::map<K, V> map) {
814 // Store value->key so that we can use the default sort from pair which
815 // sorts by value first and then key
816 std::vector<std::pair<V, K>> value_key_vector;
817
818 for (const auto& kv_pair : map) {
819 value_key_vector.push_back(std::make_pair(kv_pair.second, kv_pair.first));
820 }
821
822 // Sort in reverse (descending order)
823 std::sort(value_key_vector.rbegin(), value_key_vector.rend());
824 return value_key_vector;
825 }
826
827 static bool GetPageFrameNumber(File* page_map_file,
828 size_t virtual_page_index,
829 uint64_t* page_frame_number,
830 std::string* error_msg) {
831 CHECK(page_map_file != nullptr);
832 CHECK(page_frame_number != nullptr);
833 CHECK(error_msg != nullptr);
834
835 constexpr size_t kPageMapEntrySize = sizeof(uint64_t);
836 constexpr uint64_t kPageFrameNumberMask = (1ULL << 55) - 1; // bits 0-54 [in /proc/$pid/pagemap]
837 constexpr uint64_t kPageSoftDirtyMask = (1ULL << 55); // bit 55 [in /proc/$pid/pagemap]
838
839 uint64_t page_map_entry = 0;
840
841 // Read 64-bit entry from /proc/$pid/pagemap to get the physical page frame number
842 if (!page_map_file->PreadFully(&page_map_entry, kPageMapEntrySize,
843 virtual_page_index * kPageMapEntrySize)) {
844 *error_msg = StringPrintf("Failed to read the virtual page index entry from %s",
845 page_map_file->GetPath().c_str());
846 return false;
847 }
848
849 // TODO: seems useless, remove this.
850 bool soft_dirty = (page_map_entry & kPageSoftDirtyMask) != 0;
851 if ((false)) {
852 LOG(VERBOSE) << soft_dirty; // Suppress unused warning
853 UNREACHABLE();
854 }
855
856 *page_frame_number = page_map_entry & kPageFrameNumberMask;
857
858 return true;
859 }
860
861 static int IsPageDirty(File* page_map_file,
862 File* clean_page_map_file,
863 File* kpage_flags_file,
864 File* kpage_count_file,
865 size_t virtual_page_idx,
866 size_t clean_virtual_page_idx,
867 // Out parameters:
868 uint64_t* page_count, std::string* error_msg) {
869 CHECK(page_map_file != nullptr);
870 CHECK(clean_page_map_file != nullptr);
871 CHECK_NE(page_map_file, clean_page_map_file);
872 CHECK(kpage_flags_file != nullptr);
873 CHECK(kpage_count_file != nullptr);
874 CHECK(page_count != nullptr);
875 CHECK(error_msg != nullptr);
876
877 // Constants are from https://www.kernel.org/doc/Documentation/vm/pagemap.txt
878
879 constexpr size_t kPageFlagsEntrySize = sizeof(uint64_t);
880 constexpr size_t kPageCountEntrySize = sizeof(uint64_t);
881 constexpr uint64_t kPageFlagsDirtyMask = (1ULL << 4); // in /proc/kpageflags
882 constexpr uint64_t kPageFlagsNoPageMask = (1ULL << 20); // in /proc/kpageflags
883 constexpr uint64_t kPageFlagsMmapMask = (1ULL << 11); // in /proc/kpageflags
884
885 uint64_t page_frame_number = 0;
886 if (!GetPageFrameNumber(page_map_file, virtual_page_idx, &page_frame_number, error_msg)) {
887 return -1;
888 }
889
890 uint64_t page_frame_number_clean = 0;
891 if (!GetPageFrameNumber(clean_page_map_file, clean_virtual_page_idx, &page_frame_number_clean,
892 error_msg)) {
893 return -1;
894 }
895
896 // Read 64-bit entry from /proc/kpageflags to get the dirty bit for a page
897 uint64_t kpage_flags_entry = 0;
898 if (!kpage_flags_file->PreadFully(&kpage_flags_entry,
899 kPageFlagsEntrySize,
900 page_frame_number * kPageFlagsEntrySize)) {
901 *error_msg = StringPrintf("Failed to read the page flags from %s",
902 kpage_flags_file->GetPath().c_str());
903 return -1;
904 }
905
906 // Read 64-bit entyry from /proc/kpagecount to get mapping counts for a page
907 if (!kpage_count_file->PreadFully(page_count /*out*/,
908 kPageCountEntrySize,
909 page_frame_number * kPageCountEntrySize)) {
910 *error_msg = StringPrintf("Failed to read the page count from %s",
911 kpage_count_file->GetPath().c_str());
912 return -1;
913 }
914
915 // There must be a page frame at the requested address.
916 CHECK_EQ(kpage_flags_entry & kPageFlagsNoPageMask, 0u);
917 // The page frame must be memory mapped
918 CHECK_NE(kpage_flags_entry & kPageFlagsMmapMask, 0u);
919
920 // Page is dirty, i.e. has diverged from file, if the 4th bit is set to 1
921 bool flags_dirty = (kpage_flags_entry & kPageFlagsDirtyMask) != 0;
922
923 // page_frame_number_clean must come from the *same* process
924 // but a *different* mmap than page_frame_number
925 if (flags_dirty) {
926 CHECK_NE(page_frame_number, page_frame_number_clean);
927 }
928
929 return page_frame_number != page_frame_number_clean;
930 }
931
Igor Murashkin37743352014-11-13 14:38:00 -0800932 private:
933 // Return the image location, stripped of any directories, e.g. "boot.art" or "core.art"
934 std::string GetImageLocationBaseName() const {
935 return BaseName(std::string(image_location_));
936 }
937
938 std::ostream* os_;
939 const ImageHeader& image_header_;
Andreas Gampe8994a042015-12-30 19:03:17 +0000940 const std::string image_location_;
Igor Murashkin37743352014-11-13 14:38:00 -0800941 pid_t image_diff_pid_; // Dump image diff against boot.art if pid is non-negative
942
943 DISALLOW_COPY_AND_ASSIGN(ImgDiagDumper);
944};
945
Jeff Haodcdc85b2015-12-04 14:06:18 -0800946static int DumpImage(Runtime* runtime, std::ostream* os, pid_t image_diff_pid) {
Igor Murashkin37743352014-11-13 14:38:00 -0800947 ScopedObjectAccess soa(Thread::Current());
948 gc::Heap* heap = runtime->GetHeap();
Jeff Haodcdc85b2015-12-04 14:06:18 -0800949 std::vector<gc::space::ImageSpace*> image_spaces = heap->GetBootImageSpaces();
950 CHECK(!image_spaces.empty());
951 for (gc::space::ImageSpace* image_space : image_spaces) {
952 const ImageHeader& image_header = image_space->GetImageHeader();
953 if (!image_header.IsValid()) {
954 fprintf(stderr, "Invalid image header %s\n", image_space->GetImageLocation().c_str());
955 return EXIT_FAILURE;
956 }
957
958 ImgDiagDumper img_diag_dumper(
Andreas Gampe8994a042015-12-30 19:03:17 +0000959 os, image_header, image_space->GetImageLocation(), image_diff_pid);
Jeff Haodcdc85b2015-12-04 14:06:18 -0800960 if (!img_diag_dumper.Dump()) {
961 return EXIT_FAILURE;
962 }
Igor Murashkin37743352014-11-13 14:38:00 -0800963 }
Jeff Haodcdc85b2015-12-04 14:06:18 -0800964 return EXIT_SUCCESS;
Igor Murashkin37743352014-11-13 14:38:00 -0800965}
966
967struct ImgDiagArgs : public CmdlineArgs {
968 protected:
969 using Base = CmdlineArgs;
970
971 virtual ParseStatus ParseCustom(const StringPiece& option,
972 std::string* error_msg) OVERRIDE {
973 {
974 ParseStatus base_parse = Base::ParseCustom(option, error_msg);
975 if (base_parse != kParseUnknownArgument) {
976 return base_parse;
977 }
978 }
979
980 if (option.starts_with("--image-diff-pid=")) {
981 const char* image_diff_pid = option.substr(strlen("--image-diff-pid=")).data();
982
983 if (!ParseInt(image_diff_pid, &image_diff_pid_)) {
984 *error_msg = "Image diff pid out of range";
985 return kParseError;
986 }
987 } else {
988 return kParseUnknownArgument;
989 }
990
991 return kParseOk;
992 }
993
994 virtual ParseStatus ParseChecks(std::string* error_msg) OVERRIDE {
995 // Perform the parent checks.
996 ParseStatus parent_checks = Base::ParseChecks(error_msg);
997 if (parent_checks != kParseOk) {
998 return parent_checks;
999 }
1000
1001 // Perform our own checks.
1002
1003 if (kill(image_diff_pid_,
1004 /*sig*/0) != 0) { // No signal is sent, perform error-checking only.
1005 // Check if the pid exists before proceeding.
1006 if (errno == ESRCH) {
1007 *error_msg = "Process specified does not exist";
1008 } else {
1009 *error_msg = StringPrintf("Failed to check process status: %s", strerror(errno));
1010 }
1011 return kParseError;
1012 } else if (instruction_set_ != kRuntimeISA) {
1013 // Don't allow different ISAs since the images are ISA-specific.
1014 // Right now the code assumes both the runtime ISA and the remote ISA are identical.
1015 *error_msg = "Must use the default runtime ISA; changing ISA is not supported.";
1016 return kParseError;
1017 }
1018
1019 return kParseOk;
1020 }
1021
1022 virtual std::string GetUsage() const {
1023 std::string usage;
1024
1025 usage +=
1026 "Usage: imgdiag [options] ...\n"
1027 " Example: imgdiag --image-diff-pid=$(pidof dex2oat)\n"
1028 " Example: adb shell imgdiag --image-diff-pid=$(pid zygote)\n"
1029 "\n";
1030
1031 usage += Base::GetUsage();
1032
1033 usage += // Optional.
1034 " --image-diff-pid=<pid>: provide the PID of a process whose boot.art you want to diff.\n"
1035 " Example: --image-diff-pid=$(pid zygote)\n"
1036 "\n";
1037
1038 return usage;
1039 }
1040
1041 public:
1042 pid_t image_diff_pid_ = -1;
1043};
1044
1045struct ImgDiagMain : public CmdlineMain<ImgDiagArgs> {
1046 virtual bool ExecuteWithRuntime(Runtime* runtime) {
1047 CHECK(args_ != nullptr);
1048
1049 return DumpImage(runtime,
Igor Murashkin37743352014-11-13 14:38:00 -08001050 args_->os_,
1051 args_->image_diff_pid_) == EXIT_SUCCESS;
1052 }
1053};
1054
1055} // namespace art
1056
1057int main(int argc, char** argv) {
1058 art::ImgDiagMain main;
1059 return main.Main(argc, argv);
1060}