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