Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | /* |
| 18 | * Preparation and completion of hprof data generation. The output is |
| 19 | * written into two files and then combined. This is necessary because |
| 20 | * we generate some of the data (strings and classes) while we dump the |
| 21 | * heap, and some analysis tools require that the class and string data |
| 22 | * appear first. |
| 23 | */ |
| 24 | |
| 25 | #include "hprof.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 26 | |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 27 | #include <cutils/open_memstream.h> |
| 28 | #include <errno.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <sys/time.h> |
| 33 | #include <sys/uio.h> |
| 34 | #include <time.h> |
| 35 | #include <time.h> |
| 36 | #include <unistd.h> |
| 37 | |
| 38 | #include <set> |
| 39 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 40 | #include "art_field-inl.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 41 | #include "base/logging.h" |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 42 | #include "base/stringprintf.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 43 | #include "base/time_utils.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 44 | #include "base/unix_file/fd_file.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 45 | #include "class_linker.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 46 | #include "common_throws.h" |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 47 | #include "debugger.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 48 | #include "dex_file-inl.h" |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 49 | #include "gc_root.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 50 | #include "gc/accounting/heap_bitmap.h" |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 51 | #include "gc/allocation_record.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 52 | #include "gc/heap.h" |
| 53 | #include "gc/space/space.h" |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 54 | #include "globals.h" |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 55 | #include "jdwp/jdwp.h" |
| 56 | #include "jdwp/jdwp_priv.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | #include "mirror/class.h" |
| 58 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | #include "mirror/object-inl.h" |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 60 | #include "os.h" |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 61 | #include "safe_map.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 62 | #include "scoped_thread_state_change.h" |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 63 | #include "thread_list.h" |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 64 | |
| 65 | namespace art { |
| 66 | |
| 67 | namespace hprof { |
| 68 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 69 | static constexpr bool kDirectStream = true; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 70 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 71 | static constexpr uint32_t kHprofTime = 0; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 72 | static constexpr uint32_t kHprofNullThread = 0; |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 73 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 74 | static constexpr size_t kMaxObjectsPerSegment = 128; |
| 75 | static constexpr size_t kMaxBytesPerSegment = 4096; |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 76 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 77 | // The static field-name for the synthetic object generated to account for class static overhead. |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 78 | static constexpr const char* kClassOverheadName = "$classOverhead"; |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 79 | |
| 80 | enum HprofTag { |
| 81 | HPROF_TAG_STRING = 0x01, |
| 82 | HPROF_TAG_LOAD_CLASS = 0x02, |
| 83 | HPROF_TAG_UNLOAD_CLASS = 0x03, |
| 84 | HPROF_TAG_STACK_FRAME = 0x04, |
| 85 | HPROF_TAG_STACK_TRACE = 0x05, |
| 86 | HPROF_TAG_ALLOC_SITES = 0x06, |
| 87 | HPROF_TAG_HEAP_SUMMARY = 0x07, |
| 88 | HPROF_TAG_START_THREAD = 0x0A, |
| 89 | HPROF_TAG_END_THREAD = 0x0B, |
| 90 | HPROF_TAG_HEAP_DUMP = 0x0C, |
| 91 | HPROF_TAG_HEAP_DUMP_SEGMENT = 0x1C, |
| 92 | HPROF_TAG_HEAP_DUMP_END = 0x2C, |
| 93 | HPROF_TAG_CPU_SAMPLES = 0x0D, |
| 94 | HPROF_TAG_CONTROL_SETTINGS = 0x0E, |
| 95 | }; |
| 96 | |
| 97 | // Values for the first byte of HEAP_DUMP and HEAP_DUMP_SEGMENT records: |
| 98 | enum HprofHeapTag { |
| 99 | // Traditional. |
| 100 | HPROF_ROOT_UNKNOWN = 0xFF, |
| 101 | HPROF_ROOT_JNI_GLOBAL = 0x01, |
| 102 | HPROF_ROOT_JNI_LOCAL = 0x02, |
| 103 | HPROF_ROOT_JAVA_FRAME = 0x03, |
| 104 | HPROF_ROOT_NATIVE_STACK = 0x04, |
| 105 | HPROF_ROOT_STICKY_CLASS = 0x05, |
| 106 | HPROF_ROOT_THREAD_BLOCK = 0x06, |
| 107 | HPROF_ROOT_MONITOR_USED = 0x07, |
| 108 | HPROF_ROOT_THREAD_OBJECT = 0x08, |
| 109 | HPROF_CLASS_DUMP = 0x20, |
| 110 | HPROF_INSTANCE_DUMP = 0x21, |
| 111 | HPROF_OBJECT_ARRAY_DUMP = 0x22, |
| 112 | HPROF_PRIMITIVE_ARRAY_DUMP = 0x23, |
| 113 | |
| 114 | // Android. |
| 115 | HPROF_HEAP_DUMP_INFO = 0xfe, |
| 116 | HPROF_ROOT_INTERNED_STRING = 0x89, |
| 117 | HPROF_ROOT_FINALIZING = 0x8a, // Obsolete. |
| 118 | HPROF_ROOT_DEBUGGER = 0x8b, |
| 119 | HPROF_ROOT_REFERENCE_CLEANUP = 0x8c, // Obsolete. |
| 120 | HPROF_ROOT_VM_INTERNAL = 0x8d, |
| 121 | HPROF_ROOT_JNI_MONITOR = 0x8e, |
| 122 | HPROF_UNREACHABLE = 0x90, // Obsolete. |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 123 | HPROF_PRIMITIVE_ARRAY_NODATA_DUMP = 0xc3, // Obsolete. |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | enum HprofHeapId { |
| 127 | HPROF_HEAP_DEFAULT = 0, |
| 128 | HPROF_HEAP_ZYGOTE = 'Z', |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 129 | HPROF_HEAP_APP = 'A', |
| 130 | HPROF_HEAP_IMAGE = 'I', |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | enum HprofBasicType { |
| 134 | hprof_basic_object = 2, |
| 135 | hprof_basic_boolean = 4, |
| 136 | hprof_basic_char = 5, |
| 137 | hprof_basic_float = 6, |
| 138 | hprof_basic_double = 7, |
| 139 | hprof_basic_byte = 8, |
| 140 | hprof_basic_short = 9, |
| 141 | hprof_basic_int = 10, |
| 142 | hprof_basic_long = 11, |
| 143 | }; |
| 144 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 145 | typedef uint32_t HprofStringId; |
| 146 | typedef uint32_t HprofClassObjectId; |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 147 | typedef uint32_t HprofClassSerialNumber; |
| 148 | typedef uint32_t HprofStackTraceSerialNumber; |
| 149 | typedef uint32_t HprofStackFrameId; |
| 150 | static constexpr HprofStackTraceSerialNumber kHprofNullStackTrace = 0; |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 151 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 152 | class EndianOutput { |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 153 | public: |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 154 | EndianOutput() : length_(0), sum_length_(0), max_length_(0), started_(false) {} |
| 155 | virtual ~EndianOutput() {} |
| 156 | |
| 157 | void StartNewRecord(uint8_t tag, uint32_t time) { |
| 158 | if (length_ > 0) { |
| 159 | EndRecord(); |
| 160 | } |
| 161 | DCHECK_EQ(length_, 0U); |
| 162 | AddU1(tag); |
| 163 | AddU4(time); |
| 164 | AddU4(0xdeaddead); // Length, replaced on flush. |
| 165 | started_ = true; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 168 | void EndRecord() { |
| 169 | // Replace length in header. |
| 170 | if (started_) { |
| 171 | UpdateU4(sizeof(uint8_t) + sizeof(uint32_t), |
| 172 | length_ - sizeof(uint8_t) - 2 * sizeof(uint32_t)); |
| 173 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 174 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 175 | HandleEndRecord(); |
| 176 | |
| 177 | sum_length_ += length_; |
| 178 | max_length_ = std::max(max_length_, length_); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 179 | length_ = 0; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 180 | started_ = false; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 183 | void AddU1(uint8_t value) { |
| 184 | AddU1List(&value, 1); |
| 185 | } |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 186 | void AddU2(uint16_t value) { |
| 187 | AddU2List(&value, 1); |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 188 | } |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 189 | void AddU4(uint32_t value) { |
| 190 | AddU4List(&value, 1); |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 193 | void AddU8(uint64_t value) { |
| 194 | AddU8List(&value, 1); |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 197 | void AddObjectId(const mirror::Object* value) { |
| 198 | AddU4(PointerToLowMemUInt32(value)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 201 | void AddStackTraceSerialNumber(HprofStackTraceSerialNumber value) { |
| 202 | AddU4(value); |
| 203 | } |
| 204 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 205 | // The ID for the synthetic object generated to account for class static overhead. |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 206 | void AddClassStaticsId(const mirror::Class* value) { |
| 207 | AddU4(1 | PointerToLowMemUInt32(value)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 210 | void AddJniGlobalRefId(jobject value) { |
| 211 | AddU4(PointerToLowMemUInt32(value)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 214 | void AddClassId(HprofClassObjectId value) { |
| 215 | AddU4(value); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 218 | void AddStringId(HprofStringId value) { |
| 219 | AddU4(value); |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 222 | void AddU1List(const uint8_t* values, size_t count) { |
| 223 | HandleU1List(values, count); |
| 224 | length_ += count; |
| 225 | } |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 226 | void AddU1AsU2List(const uint8_t* values, size_t count) { |
| 227 | HandleU1AsU2List(values, count); |
| 228 | // Array of char from compressed String (8-bit) is added as 16-bit blocks |
| 229 | int ceil_count_to_even = count + ((count & 1) ? 1 : 0); |
| 230 | length_ += ceil_count_to_even * sizeof(uint8_t); |
| 231 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 232 | void AddU2List(const uint16_t* values, size_t count) { |
| 233 | HandleU2List(values, count); |
| 234 | length_ += count * sizeof(uint16_t); |
| 235 | } |
| 236 | void AddU4List(const uint32_t* values, size_t count) { |
| 237 | HandleU4List(values, count); |
| 238 | length_ += count * sizeof(uint32_t); |
| 239 | } |
Andreas Gampe | ca71458 | 2015-04-03 19:41:34 -0700 | [diff] [blame] | 240 | virtual void UpdateU4(size_t offset, uint32_t new_value ATTRIBUTE_UNUSED) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 241 | DCHECK_LE(offset, length_ - 4); |
| 242 | } |
| 243 | void AddU8List(const uint64_t* values, size_t count) { |
| 244 | HandleU8List(values, count); |
| 245 | length_ += count * sizeof(uint64_t); |
| 246 | } |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 247 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 248 | void AddIdList(mirror::ObjectArray<mirror::Object>* values) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 249 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 250 | const int32_t length = values->GetLength(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 251 | for (int32_t i = 0; i < length; ++i) { |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 252 | AddObjectId(values->GetWithoutChecks(i)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 253 | } |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 256 | void AddUtf8String(const char* str) { |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 257 | // The terminating NUL character is NOT written. |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 258 | AddU1List((const uint8_t*)str, strlen(str)); |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 261 | size_t Length() const { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 262 | return length_; |
| 263 | } |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 264 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 265 | size_t SumLength() const { |
| 266 | return sum_length_; |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 267 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 268 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 269 | size_t MaxLength() const { |
| 270 | return max_length_; |
| 271 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 272 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 273 | protected: |
| 274 | virtual void HandleU1List(const uint8_t* values ATTRIBUTE_UNUSED, |
| 275 | size_t count ATTRIBUTE_UNUSED) { |
| 276 | } |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 277 | virtual void HandleU1AsU2List(const uint8_t* values ATTRIBUTE_UNUSED, |
| 278 | size_t count ATTRIBUTE_UNUSED) { |
| 279 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 280 | virtual void HandleU2List(const uint16_t* values ATTRIBUTE_UNUSED, |
| 281 | size_t count ATTRIBUTE_UNUSED) { |
| 282 | } |
| 283 | virtual void HandleU4List(const uint32_t* values ATTRIBUTE_UNUSED, |
| 284 | size_t count ATTRIBUTE_UNUSED) { |
| 285 | } |
| 286 | virtual void HandleU8List(const uint64_t* values ATTRIBUTE_UNUSED, |
| 287 | size_t count ATTRIBUTE_UNUSED) { |
| 288 | } |
| 289 | virtual void HandleEndRecord() { |
| 290 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 291 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 292 | size_t length_; // Current record size. |
| 293 | size_t sum_length_; // Size of all data. |
| 294 | size_t max_length_; // Maximum seen length. |
| 295 | bool started_; // Was StartRecord called? |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 298 | // This keeps things buffered until flushed. |
| 299 | class EndianOutputBuffered : public EndianOutput { |
| 300 | public: |
| 301 | explicit EndianOutputBuffered(size_t reserve_size) { |
| 302 | buffer_.reserve(reserve_size); |
| 303 | } |
| 304 | virtual ~EndianOutputBuffered() {} |
| 305 | |
| 306 | void UpdateU4(size_t offset, uint32_t new_value) OVERRIDE { |
| 307 | DCHECK_LE(offset, length_ - 4); |
| 308 | buffer_[offset + 0] = static_cast<uint8_t>((new_value >> 24) & 0xFF); |
| 309 | buffer_[offset + 1] = static_cast<uint8_t>((new_value >> 16) & 0xFF); |
| 310 | buffer_[offset + 2] = static_cast<uint8_t>((new_value >> 8) & 0xFF); |
| 311 | buffer_[offset + 3] = static_cast<uint8_t>((new_value >> 0) & 0xFF); |
| 312 | } |
| 313 | |
| 314 | protected: |
| 315 | void HandleU1List(const uint8_t* values, size_t count) OVERRIDE { |
| 316 | DCHECK_EQ(length_, buffer_.size()); |
| 317 | buffer_.insert(buffer_.end(), values, values + count); |
| 318 | } |
| 319 | |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 320 | void HandleU1AsU2List(const uint8_t* values, size_t count) OVERRIDE { |
| 321 | DCHECK_EQ(length_, buffer_.size()); |
| 322 | // All 8-bits are grouped in 2 to make 16-bit block like Java Char |
| 323 | if (count & 1) { |
| 324 | buffer_.push_back(0); |
| 325 | } |
| 326 | for (size_t i = 0; i < count; ++i) { |
| 327 | uint8_t value = *values; |
| 328 | buffer_.push_back(value); |
| 329 | values++; |
| 330 | } |
| 331 | } |
| 332 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 333 | void HandleU2List(const uint16_t* values, size_t count) OVERRIDE { |
| 334 | DCHECK_EQ(length_, buffer_.size()); |
| 335 | for (size_t i = 0; i < count; ++i) { |
| 336 | uint16_t value = *values; |
| 337 | buffer_.push_back(static_cast<uint8_t>((value >> 8) & 0xFF)); |
| 338 | buffer_.push_back(static_cast<uint8_t>((value >> 0) & 0xFF)); |
| 339 | values++; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | void HandleU4List(const uint32_t* values, size_t count) OVERRIDE { |
| 344 | DCHECK_EQ(length_, buffer_.size()); |
| 345 | for (size_t i = 0; i < count; ++i) { |
| 346 | uint32_t value = *values; |
| 347 | buffer_.push_back(static_cast<uint8_t>((value >> 24) & 0xFF)); |
| 348 | buffer_.push_back(static_cast<uint8_t>((value >> 16) & 0xFF)); |
| 349 | buffer_.push_back(static_cast<uint8_t>((value >> 8) & 0xFF)); |
| 350 | buffer_.push_back(static_cast<uint8_t>((value >> 0) & 0xFF)); |
| 351 | values++; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | void HandleU8List(const uint64_t* values, size_t count) OVERRIDE { |
| 356 | DCHECK_EQ(length_, buffer_.size()); |
| 357 | for (size_t i = 0; i < count; ++i) { |
| 358 | uint64_t value = *values; |
| 359 | buffer_.push_back(static_cast<uint8_t>((value >> 56) & 0xFF)); |
| 360 | buffer_.push_back(static_cast<uint8_t>((value >> 48) & 0xFF)); |
| 361 | buffer_.push_back(static_cast<uint8_t>((value >> 40) & 0xFF)); |
| 362 | buffer_.push_back(static_cast<uint8_t>((value >> 32) & 0xFF)); |
| 363 | buffer_.push_back(static_cast<uint8_t>((value >> 24) & 0xFF)); |
| 364 | buffer_.push_back(static_cast<uint8_t>((value >> 16) & 0xFF)); |
| 365 | buffer_.push_back(static_cast<uint8_t>((value >> 8) & 0xFF)); |
| 366 | buffer_.push_back(static_cast<uint8_t>((value >> 0) & 0xFF)); |
| 367 | values++; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | void HandleEndRecord() OVERRIDE { |
| 372 | DCHECK_EQ(buffer_.size(), length_); |
| 373 | if (kIsDebugBuild && started_) { |
| 374 | uint32_t stored_length = |
| 375 | static_cast<uint32_t>(buffer_[5]) << 24 | |
| 376 | static_cast<uint32_t>(buffer_[6]) << 16 | |
| 377 | static_cast<uint32_t>(buffer_[7]) << 8 | |
| 378 | static_cast<uint32_t>(buffer_[8]); |
| 379 | DCHECK_EQ(stored_length, length_ - sizeof(uint8_t) - 2 * sizeof(uint32_t)); |
| 380 | } |
| 381 | HandleFlush(buffer_.data(), length_); |
| 382 | buffer_.clear(); |
| 383 | } |
| 384 | |
| 385 | virtual void HandleFlush(const uint8_t* buffer ATTRIBUTE_UNUSED, size_t length ATTRIBUTE_UNUSED) { |
| 386 | } |
| 387 | |
| 388 | std::vector<uint8_t> buffer_; |
| 389 | }; |
| 390 | |
| 391 | class FileEndianOutput FINAL : public EndianOutputBuffered { |
| 392 | public: |
| 393 | FileEndianOutput(File* fp, size_t reserved_size) |
| 394 | : EndianOutputBuffered(reserved_size), fp_(fp), errors_(false) { |
| 395 | DCHECK(fp != nullptr); |
| 396 | } |
| 397 | ~FileEndianOutput() { |
| 398 | } |
| 399 | |
| 400 | bool Errors() { |
| 401 | return errors_; |
| 402 | } |
| 403 | |
| 404 | protected: |
| 405 | void HandleFlush(const uint8_t* buffer, size_t length) OVERRIDE { |
| 406 | if (!errors_) { |
| 407 | errors_ = !fp_->WriteFully(buffer, length); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | private: |
| 412 | File* fp_; |
| 413 | bool errors_; |
| 414 | }; |
| 415 | |
| 416 | class NetStateEndianOutput FINAL : public EndianOutputBuffered { |
| 417 | public: |
| 418 | NetStateEndianOutput(JDWP::JdwpNetStateBase* net_state, size_t reserved_size) |
| 419 | : EndianOutputBuffered(reserved_size), net_state_(net_state) { |
| 420 | DCHECK(net_state != nullptr); |
| 421 | } |
| 422 | ~NetStateEndianOutput() {} |
| 423 | |
| 424 | protected: |
| 425 | void HandleFlush(const uint8_t* buffer, size_t length) OVERRIDE { |
| 426 | std::vector<iovec> iov; |
| 427 | iov.push_back(iovec()); |
| 428 | iov[0].iov_base = const_cast<void*>(reinterpret_cast<const void*>(buffer)); |
| 429 | iov[0].iov_len = length; |
| 430 | net_state_->WriteBufferedPacketLocked(iov); |
| 431 | } |
| 432 | |
| 433 | private: |
| 434 | JDWP::JdwpNetStateBase* net_state_; |
| 435 | }; |
| 436 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 437 | #define __ output_-> |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 438 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 439 | class Hprof : public SingleRootVisitor { |
Elliott Hughes | 622a698 | 2012-06-08 17:58:54 -0700 | [diff] [blame] | 440 | public: |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 441 | Hprof(const char* output_filename, int fd, bool direct_to_ddms) |
| 442 | : filename_(output_filename), |
| 443 | fd_(fd), |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 444 | direct_to_ddms_(direct_to_ddms) { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 445 | LOG(INFO) << "hprof: heap dump \"" << filename_ << "\" starting..."; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 446 | } |
| 447 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 448 | void Dump() |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 449 | REQUIRES(Locks::mutator_lock_) |
| 450 | REQUIRES(!Locks::heap_bitmap_lock_, !Locks::alloc_tracker_lock_) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 451 | { |
| 452 | MutexLock mu(Thread::Current(), *Locks::alloc_tracker_lock_); |
| 453 | if (Runtime::Current()->GetHeap()->IsAllocTrackingEnabled()) { |
| 454 | PopulateAllocationTrackingTraces(); |
| 455 | } |
| 456 | } |
| 457 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 458 | // First pass to measure the size of the dump. |
| 459 | size_t overall_size; |
| 460 | size_t max_length; |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 461 | { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 462 | EndianOutput count_output; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 463 | output_ = &count_output; |
| 464 | ProcessHeap(false); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 465 | overall_size = count_output.SumLength(); |
| 466 | max_length = count_output.MaxLength(); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 467 | output_ = nullptr; |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 468 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 469 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 470 | bool okay; |
| 471 | if (direct_to_ddms_) { |
| 472 | if (kDirectStream) { |
| 473 | okay = DumpToDdmsDirect(overall_size, max_length, CHUNK_TYPE("HPDS")); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 474 | } else { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 475 | okay = DumpToDdmsBuffered(overall_size, max_length); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 476 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 477 | } else { |
| 478 | okay = DumpToFile(overall_size, max_length); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 481 | if (okay) { |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 482 | const uint64_t duration = NanoTime() - start_ns_; |
| 483 | LOG(INFO) << "hprof: heap dump completed (" << PrettySize(RoundUp(overall_size, KB)) |
| 484 | << ") in " << PrettyDuration(duration) |
| 485 | << " objects " << total_objects_ |
| 486 | << " objects with stack traces " << total_objects_with_stack_trace_; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | private: |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 491 | static void VisitObjectCallback(mirror::Object* obj, void* arg) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 492 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 493 | DCHECK(obj != nullptr); |
| 494 | DCHECK(arg != nullptr); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 495 | reinterpret_cast<Hprof*>(arg)->DumpHeapObject(obj); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 498 | void DumpHeapObject(mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 499 | SHARED_REQUIRES(Locks::mutator_lock_); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 500 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 501 | void DumpHeapClass(mirror::Class* klass) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 502 | SHARED_REQUIRES(Locks::mutator_lock_); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 503 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 504 | void DumpHeapArray(mirror::Array* obj, mirror::Class* klass) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 505 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 506 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 507 | void DumpHeapInstanceObject(mirror::Object* obj, mirror::Class* klass) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 508 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 509 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 510 | void ProcessHeap(bool header_first) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 511 | REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 512 | // Reset current heap and object count. |
| 513 | current_heap_ = HPROF_HEAP_DEFAULT; |
| 514 | objects_in_segment_ = 0; |
| 515 | |
| 516 | if (header_first) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 517 | ProcessHeader(true); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 518 | ProcessBody(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 519 | } else { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 520 | ProcessBody(); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 521 | ProcessHeader(false); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 525 | void ProcessBody() REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 526 | Runtime* const runtime = Runtime::Current(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 527 | // Walk the roots and the heap. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 528 | output_->StartNewRecord(HPROF_TAG_HEAP_DUMP_SEGMENT, kHprofTime); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 529 | |
Richard Uhler | 4b76755 | 2016-04-26 13:28:59 -0700 | [diff] [blame] | 530 | simple_roots_.clear(); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 531 | runtime->VisitRoots(this); |
| 532 | runtime->VisitImageRoots(this); |
| 533 | runtime->GetHeap()->VisitObjectsPaused(VisitObjectCallback, this); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 534 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 535 | output_->StartNewRecord(HPROF_TAG_HEAP_DUMP_END, kHprofTime); |
| 536 | output_->EndRecord(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 539 | void ProcessHeader(bool string_first) REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 540 | // Write the header. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 541 | WriteFixedHeader(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 542 | // Write the string and class tables, and any stack traces, to the header. |
| 543 | // (jhat requires that these appear before any of the data in the body that refers to them.) |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 544 | // jhat also requires the string table appear before class table and stack traces. |
| 545 | // However, WriteStackTraces() can modify the string table, so it's necessary to call |
| 546 | // WriteStringTable() last in the first pass, to compute the correct length of the output. |
| 547 | if (string_first) { |
| 548 | WriteStringTable(); |
| 549 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 550 | WriteClassTable(); |
| 551 | WriteStackTraces(); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 552 | if (!string_first) { |
| 553 | WriteStringTable(); |
| 554 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 555 | output_->EndRecord(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 558 | void WriteClassTable() SHARED_REQUIRES(Locks::mutator_lock_) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 559 | for (const auto& p : classes_) { |
| 560 | mirror::Class* c = p.first; |
| 561 | HprofClassSerialNumber sn = p.second; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 562 | CHECK(c != nullptr); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 563 | output_->StartNewRecord(HPROF_TAG_LOAD_CLASS, kHprofTime); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 564 | // LOAD CLASS format: |
| 565 | // U4: class serial number (always > 0) |
| 566 | // ID: class object ID. We use the address of the class object structure as its ID. |
| 567 | // U4: stack trace serial number |
| 568 | // ID: class name string ID |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 569 | __ AddU4(sn); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 570 | __ AddObjectId(c); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 571 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(c)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 572 | __ AddStringId(LookupClassNameId(c)); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 573 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 576 | void WriteStringTable() { |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 577 | for (const std::pair<std::string, HprofStringId>& p : strings_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 578 | const std::string& string = p.first; |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 579 | const size_t id = p.second; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 580 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 581 | output_->StartNewRecord(HPROF_TAG_STRING, kHprofTime); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 582 | |
| 583 | // STRING format: |
| 584 | // ID: ID for this string |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 585 | // U1*: UTF8 characters for string (NOT null terminated) |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 586 | // (the record format encodes the length) |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 587 | __ AddU4(id); |
| 588 | __ AddUtf8String(string.c_str()); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 589 | } |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 592 | void StartNewHeapDumpSegment() { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 593 | // This flushes the old segment and starts a new one. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 594 | output_->StartNewRecord(HPROF_TAG_HEAP_DUMP_SEGMENT, kHprofTime); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 595 | objects_in_segment_ = 0; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 596 | // Starting a new HEAP_DUMP resets the heap to default. |
| 597 | current_heap_ = HPROF_HEAP_DEFAULT; |
| 598 | } |
| 599 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 600 | void CheckHeapSegmentConstraints() { |
| 601 | if (objects_in_segment_ >= kMaxObjectsPerSegment || output_->Length() >= kMaxBytesPerSegment) { |
| 602 | StartNewHeapDumpSegment(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 606 | void VisitRoot(mirror::Object* obj, const RootInfo& root_info) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 607 | OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 608 | void MarkRootObject(const mirror::Object* obj, jobject jni_obj, HprofHeapTag heap_tag, |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 609 | uint32_t thread_serial); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 610 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 611 | HprofClassObjectId LookupClassId(mirror::Class* c) SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 612 | if (c != nullptr) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 613 | auto it = classes_.find(c); |
| 614 | if (it == classes_.end()) { |
| 615 | // first time to see this class |
| 616 | HprofClassSerialNumber sn = next_class_serial_number_++; |
| 617 | classes_.Put(c, sn); |
| 618 | // Make sure that we've assigned a string ID for this class' name |
| 619 | LookupClassNameId(c); |
| 620 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 621 | } |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 622 | return PointerToLowMemUInt32(c); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 625 | HprofStackTraceSerialNumber LookupStackTraceSerialNumber(const mirror::Object* obj) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 626 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 627 | auto r = allocation_records_.find(obj); |
| 628 | if (r == allocation_records_.end()) { |
| 629 | return kHprofNullStackTrace; |
| 630 | } else { |
| 631 | const gc::AllocRecordStackTrace* trace = r->second; |
| 632 | auto result = traces_.find(trace); |
| 633 | CHECK(result != traces_.end()); |
| 634 | return result->second; |
| 635 | } |
| 636 | } |
| 637 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 638 | HprofStringId LookupStringId(mirror::String* string) SHARED_REQUIRES(Locks::mutator_lock_) { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 639 | return LookupStringId(string->ToModifiedUtf8()); |
| 640 | } |
| 641 | |
| 642 | HprofStringId LookupStringId(const char* string) { |
| 643 | return LookupStringId(std::string(string)); |
| 644 | } |
| 645 | |
| 646 | HprofStringId LookupStringId(const std::string& string) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 647 | auto it = strings_.find(string); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 648 | if (it != strings_.end()) { |
| 649 | return it->second; |
| 650 | } |
| 651 | HprofStringId id = next_string_id_++; |
| 652 | strings_.Put(string, id); |
| 653 | return id; |
| 654 | } |
| 655 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 656 | HprofStringId LookupClassNameId(mirror::Class* c) SHARED_REQUIRES(Locks::mutator_lock_) { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 657 | return LookupStringId(PrettyDescriptor(c)); |
| 658 | } |
| 659 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 660 | void WriteFixedHeader() { |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 661 | // Write the file header. |
| 662 | // U1: NUL-terminated magic string. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 663 | const char magic[] = "JAVA PROFILE 1.0.3"; |
| 664 | __ AddU1List(reinterpret_cast<const uint8_t*>(magic), sizeof(magic)); |
| 665 | |
Calin Juravle | 3280517 | 2014-07-04 16:24:03 +0100 | [diff] [blame] | 666 | // U4: size of identifiers. We're using addresses as IDs and our heap references are stored |
| 667 | // as uint32_t. |
| 668 | // Note of warning: hprof-conv hard-codes the size of identifiers to 4. |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 669 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(uint32_t), |
| 670 | "Unexpected HeapReference size"); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 671 | __ AddU4(sizeof(uint32_t)); |
| 672 | |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 673 | // The current time, in milliseconds since 0:00 GMT, 1/1/70. |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 674 | timeval now; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 675 | const uint64_t nowMs = (gettimeofday(&now, nullptr) < 0) ? 0 : |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 676 | (uint64_t)now.tv_sec * 1000 + now.tv_usec / 1000; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 677 | // TODO: It seems it would be correct to use U8. |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 678 | // U4: high word of the 64-bit time. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 679 | __ AddU4(static_cast<uint32_t>(nowMs >> 32)); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 680 | // U4: low word of the 64-bit time. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 681 | __ AddU4(static_cast<uint32_t>(nowMs & 0xFFFFFFFF)); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 682 | } |
| 683 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 684 | void WriteStackTraces() SHARED_REQUIRES(Locks::mutator_lock_) { |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 685 | // Write a dummy stack trace record so the analysis tools don't freak out. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 686 | output_->StartNewRecord(HPROF_TAG_STACK_TRACE, kHprofTime); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 687 | __ AddStackTraceSerialNumber(kHprofNullStackTrace); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 688 | __ AddU4(kHprofNullThread); |
| 689 | __ AddU4(0); // no frames |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 690 | |
| 691 | // TODO: jhat complains "WARNING: Stack trace not found for serial # -1", but no trace should |
| 692 | // have -1 as its serial number (as long as HprofStackTraceSerialNumber doesn't overflow). |
| 693 | for (const auto& it : traces_) { |
| 694 | const gc::AllocRecordStackTrace* trace = it.first; |
| 695 | HprofStackTraceSerialNumber trace_sn = it.second; |
| 696 | size_t depth = trace->GetDepth(); |
| 697 | |
| 698 | // First write stack frames of the trace |
| 699 | for (size_t i = 0; i < depth; ++i) { |
| 700 | const gc::AllocRecordStackTraceElement* frame = &trace->GetStackElement(i); |
| 701 | ArtMethod* method = frame->GetMethod(); |
| 702 | CHECK(method != nullptr); |
| 703 | output_->StartNewRecord(HPROF_TAG_STACK_FRAME, kHprofTime); |
| 704 | // STACK FRAME format: |
| 705 | // ID: stack frame ID. We use the address of the AllocRecordStackTraceElement object as its ID. |
| 706 | // ID: method name string ID |
| 707 | // ID: method signature string ID |
| 708 | // ID: source file name string ID |
| 709 | // U4: class serial number |
| 710 | // U4: >0, line number; 0, no line information available; -1, unknown location |
| 711 | auto frame_result = frames_.find(frame); |
| 712 | CHECK(frame_result != frames_.end()); |
| 713 | __ AddU4(frame_result->second); |
| 714 | __ AddStringId(LookupStringId(method->GetName())); |
| 715 | __ AddStringId(LookupStringId(method->GetSignature().ToString())); |
| 716 | const char* source_file = method->GetDeclaringClassSourceFile(); |
| 717 | if (source_file == nullptr) { |
| 718 | source_file = ""; |
| 719 | } |
| 720 | __ AddStringId(LookupStringId(source_file)); |
| 721 | auto class_result = classes_.find(method->GetDeclaringClass()); |
| 722 | CHECK(class_result != classes_.end()); |
| 723 | __ AddU4(class_result->second); |
| 724 | __ AddU4(frame->ComputeLineNumber()); |
| 725 | } |
| 726 | |
| 727 | // Then write the trace itself |
| 728 | output_->StartNewRecord(HPROF_TAG_STACK_TRACE, kHprofTime); |
| 729 | // STACK TRACE format: |
| 730 | // U4: stack trace serial number. We use the address of the AllocRecordStackTrace object as its serial number. |
| 731 | // U4: thread serial number. We use Thread::GetTid(). |
| 732 | // U4: number of frames |
| 733 | // [ID]*: series of stack frame ID's |
| 734 | __ AddStackTraceSerialNumber(trace_sn); |
| 735 | __ AddU4(trace->GetTid()); |
| 736 | __ AddU4(depth); |
| 737 | for (size_t i = 0; i < depth; ++i) { |
| 738 | const gc::AllocRecordStackTraceElement* frame = &trace->GetStackElement(i); |
| 739 | auto frame_result = frames_.find(frame); |
| 740 | CHECK(frame_result != frames_.end()); |
| 741 | __ AddU4(frame_result->second); |
| 742 | } |
| 743 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | bool DumpToDdmsBuffered(size_t overall_size ATTRIBUTE_UNUSED, size_t max_length ATTRIBUTE_UNUSED) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 747 | REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 748 | LOG(FATAL) << "Unimplemented"; |
| 749 | UNREACHABLE(); |
| 750 | // // Send the data off to DDMS. |
| 751 | // iovec iov[2]; |
| 752 | // iov[0].iov_base = header_data_ptr_; |
| 753 | // iov[0].iov_len = header_data_size_; |
| 754 | // iov[1].iov_base = body_data_ptr_; |
| 755 | // iov[1].iov_len = body_data_size_; |
| 756 | // Dbg::DdmSendChunkV(CHUNK_TYPE("HPDS"), iov, 2); |
| 757 | } |
| 758 | |
| 759 | bool DumpToFile(size_t overall_size, size_t max_length) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 760 | REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 761 | // Where exactly are we writing to? |
| 762 | int out_fd; |
| 763 | if (fd_ >= 0) { |
| 764 | out_fd = dup(fd_); |
| 765 | if (out_fd < 0) { |
| 766 | ThrowRuntimeException("Couldn't dump heap; dup(%d) failed: %s", fd_, strerror(errno)); |
| 767 | return false; |
| 768 | } |
| 769 | } else { |
| 770 | out_fd = open(filename_.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644); |
| 771 | if (out_fd < 0) { |
| 772 | ThrowRuntimeException("Couldn't dump heap; open(\"%s\") failed: %s", filename_.c_str(), |
| 773 | strerror(errno)); |
| 774 | return false; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | std::unique_ptr<File> file(new File(out_fd, filename_, true)); |
| 779 | bool okay; |
| 780 | { |
| 781 | FileEndianOutput file_output(file.get(), max_length); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 782 | output_ = &file_output; |
| 783 | ProcessHeap(true); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 784 | okay = !file_output.Errors(); |
| 785 | |
| 786 | if (okay) { |
Andreas Gampe | c515f21 | 2015-08-28 18:15:27 -0700 | [diff] [blame] | 787 | // Check for expected size. Output is expected to be less-or-equal than first phase, see |
| 788 | // b/23521263. |
| 789 | DCHECK_LE(file_output.SumLength(), overall_size); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 790 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 791 | output_ = nullptr; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | if (okay) { |
| 795 | okay = file->FlushCloseOrErase() == 0; |
| 796 | } else { |
| 797 | file->Erase(); |
| 798 | } |
| 799 | if (!okay) { |
| 800 | std::string msg(StringPrintf("Couldn't dump heap; writing \"%s\" failed: %s", |
| 801 | filename_.c_str(), strerror(errno))); |
| 802 | ThrowRuntimeException("%s", msg.c_str()); |
| 803 | LOG(ERROR) << msg; |
| 804 | } |
| 805 | |
| 806 | return okay; |
| 807 | } |
| 808 | |
| 809 | bool DumpToDdmsDirect(size_t overall_size, size_t max_length, uint32_t chunk_type) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 810 | REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 811 | CHECK(direct_to_ddms_); |
| 812 | JDWP::JdwpState* state = Dbg::GetJdwpState(); |
| 813 | CHECK(state != nullptr); |
| 814 | JDWP::JdwpNetStateBase* net_state = state->netState; |
| 815 | CHECK(net_state != nullptr); |
| 816 | |
| 817 | // Hold the socket lock for the whole time since we want this to be atomic. |
| 818 | MutexLock mu(Thread::Current(), *net_state->GetSocketLock()); |
| 819 | |
| 820 | // Prepare the Ddms chunk. |
| 821 | constexpr size_t kChunkHeaderSize = kJDWPHeaderLen + 8; |
| 822 | uint8_t chunk_header[kChunkHeaderSize] = { 0 }; |
| 823 | state->SetupChunkHeader(chunk_type, overall_size, kChunkHeaderSize, chunk_header); |
| 824 | |
| 825 | // Prepare the output and send the chunk header. |
| 826 | NetStateEndianOutput net_output(net_state, max_length); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 827 | output_ = &net_output; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 828 | net_output.AddU1List(chunk_header, kChunkHeaderSize); |
| 829 | |
| 830 | // Write the dump. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 831 | ProcessHeap(true); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 832 | |
Andreas Gampe | c515f21 | 2015-08-28 18:15:27 -0700 | [diff] [blame] | 833 | // Check for expected size. See DumpToFile for comment. |
| 834 | DCHECK_LE(net_output.SumLength(), overall_size + kChunkHeaderSize); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 835 | output_ = nullptr; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 836 | |
| 837 | return true; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 838 | } |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 839 | |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 840 | void PopulateAllocationTrackingTraces() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 841 | REQUIRES(Locks::mutator_lock_, Locks::alloc_tracker_lock_) { |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 842 | gc::AllocRecordObjectMap* records = Runtime::Current()->GetHeap()->GetAllocationRecords(); |
| 843 | CHECK(records != nullptr); |
| 844 | HprofStackTraceSerialNumber next_trace_sn = kHprofNullStackTrace + 1; |
| 845 | HprofStackFrameId next_frame_id = 0; |
Man Cao | 42c3c33 | 2015-06-23 16:38:25 -0700 | [diff] [blame] | 846 | size_t count = 0; |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 847 | |
| 848 | for (auto it = records->Begin(), end = records->End(); it != end; ++it) { |
| 849 | const mirror::Object* obj = it->first.Read(); |
Man Cao | 42c3c33 | 2015-06-23 16:38:25 -0700 | [diff] [blame] | 850 | if (obj == nullptr) { |
| 851 | continue; |
| 852 | } |
| 853 | ++count; |
Mathieu Chartier | 458b105 | 2016-03-29 14:02:55 -0700 | [diff] [blame] | 854 | const gc::AllocRecordStackTrace* trace = it->second.GetStackTrace(); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 855 | |
| 856 | // Copy the pair into a real hash map to speed up look up. |
| 857 | auto records_result = allocation_records_.emplace(obj, trace); |
| 858 | // The insertion should always succeed, i.e. no duplicate object pointers in "records" |
| 859 | CHECK(records_result.second); |
| 860 | |
| 861 | // Generate serial numbers for traces, and IDs for frames. |
| 862 | auto traces_result = traces_.find(trace); |
| 863 | if (traces_result == traces_.end()) { |
| 864 | traces_.emplace(trace, next_trace_sn++); |
| 865 | // only check frames if the trace is newly discovered |
| 866 | for (size_t i = 0, depth = trace->GetDepth(); i < depth; ++i) { |
| 867 | const gc::AllocRecordStackTraceElement* frame = &trace->GetStackElement(i); |
| 868 | auto frames_result = frames_.find(frame); |
| 869 | if (frames_result == frames_.end()) { |
| 870 | frames_.emplace(frame, next_frame_id++); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | CHECK_EQ(traces_.size(), next_trace_sn - kHprofNullStackTrace - 1); |
| 876 | CHECK_EQ(frames_.size(), next_frame_id); |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 877 | total_objects_with_stack_trace_ = count; |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 880 | // If direct_to_ddms_ is set, "filename_" and "fd" will be ignored. |
| 881 | // Otherwise, "filename_" must be valid, though if "fd" >= 0 it will |
| 882 | // only be used for debug messages. |
| 883 | std::string filename_; |
| 884 | int fd_; |
| 885 | bool direct_to_ddms_; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 886 | |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 887 | uint64_t start_ns_ = NanoTime(); |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 888 | |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 889 | EndianOutput* output_ = nullptr; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 890 | |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 891 | HprofHeapId current_heap_ = HPROF_HEAP_DEFAULT; // Which heap we're currently dumping. |
| 892 | size_t objects_in_segment_ = 0; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 893 | |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 894 | size_t total_objects_ = 0u; |
| 895 | size_t total_objects_with_stack_trace_ = 0u; |
| 896 | |
| 897 | HprofStringId next_string_id_ = 0x400000; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 898 | SafeMap<std::string, HprofStringId> strings_; |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 899 | HprofClassSerialNumber next_class_serial_number_ = 1; |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 900 | SafeMap<mirror::Class*, HprofClassSerialNumber> classes_; |
| 901 | |
| 902 | std::unordered_map<const gc::AllocRecordStackTrace*, HprofStackTraceSerialNumber, |
| 903 | gc::HashAllocRecordTypesPtr<gc::AllocRecordStackTrace>, |
| 904 | gc::EqAllocRecordTypesPtr<gc::AllocRecordStackTrace>> traces_; |
| 905 | std::unordered_map<const gc::AllocRecordStackTraceElement*, HprofStackFrameId, |
| 906 | gc::HashAllocRecordTypesPtr<gc::AllocRecordStackTraceElement>, |
| 907 | gc::EqAllocRecordTypesPtr<gc::AllocRecordStackTraceElement>> frames_; |
| 908 | std::unordered_map<const mirror::Object*, const gc::AllocRecordStackTrace*> allocation_records_; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 909 | |
Richard Uhler | 4b76755 | 2016-04-26 13:28:59 -0700 | [diff] [blame] | 910 | // Set used to keep track of what simple root records we have already |
| 911 | // emitted, to avoid emitting duplicate entries. The simple root records are |
| 912 | // those that contain no other information than the root type and the object |
| 913 | // id. A pair of root type and object id is packed into a uint64_t, with |
| 914 | // the root type in the upper 32 bits and the object id in the lower 32 |
| 915 | // bits. |
| 916 | std::unordered_set<uint64_t> simple_roots_; |
| 917 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 918 | friend class GcRootVisitor; |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 919 | DISALLOW_COPY_AND_ASSIGN(Hprof); |
| 920 | }; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 921 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 922 | static HprofBasicType SignatureToBasicTypeAndSize(const char* sig, size_t* size_out) { |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 923 | char c = sig[0]; |
| 924 | HprofBasicType ret; |
| 925 | size_t size; |
| 926 | |
| 927 | switch (c) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 928 | case '[': |
| 929 | case 'L': |
| 930 | ret = hprof_basic_object; |
| 931 | size = 4; |
| 932 | break; |
| 933 | case 'Z': |
| 934 | ret = hprof_basic_boolean; |
| 935 | size = 1; |
| 936 | break; |
| 937 | case 'C': |
| 938 | ret = hprof_basic_char; |
| 939 | size = 2; |
| 940 | break; |
| 941 | case 'F': |
| 942 | ret = hprof_basic_float; |
| 943 | size = 4; |
| 944 | break; |
| 945 | case 'D': |
| 946 | ret = hprof_basic_double; |
| 947 | size = 8; |
| 948 | break; |
| 949 | case 'B': |
| 950 | ret = hprof_basic_byte; |
| 951 | size = 1; |
| 952 | break; |
| 953 | case 'S': |
| 954 | ret = hprof_basic_short; |
| 955 | size = 2; |
| 956 | break; |
| 957 | case 'I': |
| 958 | ret = hprof_basic_int; |
| 959 | size = 4; |
| 960 | break; |
| 961 | case 'J': |
| 962 | ret = hprof_basic_long; |
| 963 | size = 8; |
| 964 | break; |
| 965 | default: |
| 966 | LOG(FATAL) << "UNREACHABLE"; |
| 967 | UNREACHABLE(); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 968 | } |
| 969 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 970 | if (size_out != nullptr) { |
| 971 | *size_out = size; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | return ret; |
| 975 | } |
| 976 | |
| 977 | // Always called when marking objects, but only does |
| 978 | // something when ctx->gc_scan_state_ is non-zero, which is usually |
| 979 | // only true when marking the root set or unreachable |
| 980 | // objects. Used to add rootset references to obj. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 981 | void Hprof::MarkRootObject(const mirror::Object* obj, jobject jni_obj, HprofHeapTag heap_tag, |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 982 | uint32_t thread_serial) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 983 | if (heap_tag == 0) { |
| 984 | return; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 985 | } |
| 986 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 987 | CheckHeapSegmentConstraints(); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 988 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 989 | switch (heap_tag) { |
| 990 | // ID: object ID |
| 991 | case HPROF_ROOT_UNKNOWN: |
| 992 | case HPROF_ROOT_STICKY_CLASS: |
| 993 | case HPROF_ROOT_MONITOR_USED: |
| 994 | case HPROF_ROOT_INTERNED_STRING: |
| 995 | case HPROF_ROOT_DEBUGGER: |
Richard Uhler | 4b76755 | 2016-04-26 13:28:59 -0700 | [diff] [blame] | 996 | case HPROF_ROOT_VM_INTERNAL: { |
| 997 | uint64_t key = (static_cast<uint64_t>(heap_tag) << 32) | PointerToLowMemUInt32(obj); |
| 998 | if (simple_roots_.insert(key).second) { |
| 999 | __ AddU1(heap_tag); |
| 1000 | __ AddObjectId(obj); |
| 1001 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1002 | break; |
Richard Uhler | 4b76755 | 2016-04-26 13:28:59 -0700 | [diff] [blame] | 1003 | } |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1004 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1005 | // ID: object ID |
| 1006 | // ID: JNI global ref ID |
| 1007 | case HPROF_ROOT_JNI_GLOBAL: |
| 1008 | __ AddU1(heap_tag); |
| 1009 | __ AddObjectId(obj); |
| 1010 | __ AddJniGlobalRefId(jni_obj); |
| 1011 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1012 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1013 | // ID: object ID |
| 1014 | // U4: thread serial number |
| 1015 | // U4: frame number in stack trace (-1 for empty) |
| 1016 | case HPROF_ROOT_JNI_LOCAL: |
| 1017 | case HPROF_ROOT_JNI_MONITOR: |
| 1018 | case HPROF_ROOT_JAVA_FRAME: |
| 1019 | __ AddU1(heap_tag); |
| 1020 | __ AddObjectId(obj); |
| 1021 | __ AddU4(thread_serial); |
| 1022 | __ AddU4((uint32_t)-1); |
| 1023 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1024 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1025 | // ID: object ID |
| 1026 | // U4: thread serial number |
| 1027 | case HPROF_ROOT_NATIVE_STACK: |
| 1028 | case HPROF_ROOT_THREAD_BLOCK: |
| 1029 | __ AddU1(heap_tag); |
| 1030 | __ AddObjectId(obj); |
| 1031 | __ AddU4(thread_serial); |
| 1032 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1033 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1034 | // ID: thread object ID |
| 1035 | // U4: thread serial number |
| 1036 | // U4: stack trace serial number |
| 1037 | case HPROF_ROOT_THREAD_OBJECT: |
| 1038 | __ AddU1(heap_tag); |
| 1039 | __ AddObjectId(obj); |
| 1040 | __ AddU4(thread_serial); |
| 1041 | __ AddU4((uint32_t)-1); // xxx |
| 1042 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1043 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1044 | case HPROF_CLASS_DUMP: |
| 1045 | case HPROF_INSTANCE_DUMP: |
| 1046 | case HPROF_OBJECT_ARRAY_DUMP: |
| 1047 | case HPROF_PRIMITIVE_ARRAY_DUMP: |
| 1048 | case HPROF_HEAP_DUMP_INFO: |
| 1049 | case HPROF_PRIMITIVE_ARRAY_NODATA_DUMP: |
| 1050 | // Ignored. |
| 1051 | break; |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 1052 | |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1053 | case HPROF_ROOT_FINALIZING: |
| 1054 | case HPROF_ROOT_REFERENCE_CLEANUP: |
| 1055 | case HPROF_UNREACHABLE: |
| 1056 | LOG(FATAL) << "obsolete tag " << static_cast<int>(heap_tag); |
| 1057 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1058 | } |
| 1059 | |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 1060 | ++objects_in_segment_; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1061 | } |
| 1062 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 1063 | // Use for visiting the GcRoots held live by ArtFields, ArtMethods, and ClassLoaders. |
| 1064 | class GcRootVisitor { |
| 1065 | public: |
| 1066 | explicit GcRootVisitor(Hprof* hprof) : hprof_(hprof) {} |
| 1067 | |
| 1068 | void operator()(mirror::Object* obj ATTRIBUTE_UNUSED, |
| 1069 | MemberOffset offset ATTRIBUTE_UNUSED, |
| 1070 | bool is_static ATTRIBUTE_UNUSED) const {} |
| 1071 | |
| 1072 | // Note that these don't have read barriers. Its OK however since the GC is guaranteed to not be |
| 1073 | // running during the hprof dumping process. |
| 1074 | void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const |
| 1075 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1076 | if (!root->IsNull()) { |
| 1077 | VisitRoot(root); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | void VisitRoot(mirror::CompressedReference<mirror::Object>* root) const |
| 1082 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1083 | mirror::Object* obj = root->AsMirrorPtr(); |
| 1084 | // The two cases are either classes or dex cache arrays. If it is a dex cache array, then use |
| 1085 | // VM internal. Otherwise the object is a declaring class of an ArtField or ArtMethod or a |
| 1086 | // class from a ClassLoader. |
| 1087 | hprof_->VisitRoot(obj, RootInfo(obj->IsClass() ? kRootStickyClass : kRootVMInternal)); |
| 1088 | } |
| 1089 | |
| 1090 | |
| 1091 | private: |
| 1092 | Hprof* const hprof_; |
| 1093 | }; |
| 1094 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1095 | void Hprof::DumpHeapObject(mirror::Object* obj) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1096 | // Ignore classes that are retired. |
| 1097 | if (obj->IsClass() && obj->AsClass()->IsRetired()) { |
| 1098 | return; |
| 1099 | } |
| 1100 | |
Mathieu Chartier | c9cd7ac | 2016-01-20 14:48:36 -0800 | [diff] [blame] | 1101 | ++total_objects_; |
| 1102 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 1103 | GcRootVisitor visitor(this); |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame] | 1104 | obj->VisitReferences(visitor, VoidFunctor()); |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 1105 | |
Mathieu Chartier | e715811 | 2015-06-03 13:32:15 -0700 | [diff] [blame] | 1106 | gc::Heap* const heap = Runtime::Current()->GetHeap(); |
| 1107 | const gc::space::ContinuousSpace* const space = heap->FindContinuousSpaceFromObject(obj, true); |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1108 | HprofHeapId heap_type = HPROF_HEAP_APP; |
| 1109 | if (space != nullptr) { |
| 1110 | if (space->IsZygoteSpace()) { |
| 1111 | heap_type = HPROF_HEAP_ZYGOTE; |
| 1112 | } else if (space->IsImageSpace()) { |
| 1113 | heap_type = HPROF_HEAP_IMAGE; |
| 1114 | } |
Mathieu Chartier | e715811 | 2015-06-03 13:32:15 -0700 | [diff] [blame] | 1115 | } else { |
| 1116 | const auto* los = heap->GetLargeObjectsSpace(); |
| 1117 | if (los->Contains(obj) && los->IsZygoteLargeObject(Thread::Current(), obj)) { |
| 1118 | heap_type = HPROF_HEAP_ZYGOTE; |
| 1119 | } |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1120 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1121 | CheckHeapSegmentConstraints(); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1122 | |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1123 | if (heap_type != current_heap_) { |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1124 | HprofStringId nameId; |
| 1125 | |
| 1126 | // This object is in a different heap than the current one. |
| 1127 | // Emit a HEAP_DUMP_INFO tag to change heaps. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1128 | __ AddU1(HPROF_HEAP_DUMP_INFO); |
| 1129 | __ AddU4(static_cast<uint32_t>(heap_type)); // uint32_t: heap type |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1130 | switch (heap_type) { |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1131 | case HPROF_HEAP_APP: |
| 1132 | nameId = LookupStringId("app"); |
| 1133 | break; |
| 1134 | case HPROF_HEAP_ZYGOTE: |
| 1135 | nameId = LookupStringId("zygote"); |
| 1136 | break; |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1137 | case HPROF_HEAP_IMAGE: |
| 1138 | nameId = LookupStringId("image"); |
| 1139 | break; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1140 | default: |
| 1141 | // Internal error |
| 1142 | LOG(ERROR) << "Unexpected desiredHeap"; |
| 1143 | nameId = LookupStringId("<ILLEGAL>"); |
| 1144 | break; |
| 1145 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1146 | __ AddStringId(nameId); |
Mathieu Chartier | ae1ad00 | 2014-07-18 17:58:22 -0700 | [diff] [blame] | 1147 | current_heap_ = heap_type; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1148 | } |
| 1149 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1150 | mirror::Class* c = obj->GetClass(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1151 | if (c == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1152 | // This object will bother HprofReader, because it has a null |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1153 | // class, so just don't dump it. It could be |
| 1154 | // gDvm.unlinkedJavaLangClass or it could be an object just |
| 1155 | // allocated which hasn't been initialized yet. |
| 1156 | } else { |
| 1157 | if (obj->IsClass()) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1158 | DumpHeapClass(obj->AsClass()); |
Elliott Hughes | e84278b | 2012-03-22 10:06:53 -0700 | [diff] [blame] | 1159 | } else if (c->IsArrayClass()) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1160 | DumpHeapArray(obj->AsArray(), c); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1161 | } else { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1162 | DumpHeapInstanceObject(obj, c); |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 1166 | ++objects_in_segment_; |
Jesse Wilson | 0c54ac1 | 2011-11-09 15:14:05 -0500 | [diff] [blame] | 1167 | } |
| 1168 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1169 | void Hprof::DumpHeapClass(mirror::Class* klass) { |
Sebastien Hertz | ca068b2 | 2015-04-07 10:28:53 +0200 | [diff] [blame] | 1170 | if (!klass->IsLoaded() && !klass->IsErroneous()) { |
| 1171 | // Class is allocated but not yet loaded: we cannot access its fields or super class. |
| 1172 | return; |
| 1173 | } |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1174 | const size_t num_static_fields = klass->NumStaticFields(); |
| 1175 | // Total class size including embedded IMT, embedded vtable, and static fields. |
| 1176 | const size_t class_size = klass->GetClassSize(); |
| 1177 | // Class size excluding static fields (relies on reference fields being the first static fields). |
| 1178 | const size_t class_size_without_overhead = sizeof(mirror::Class); |
| 1179 | CHECK_LE(class_size_without_overhead, class_size); |
| 1180 | const size_t overhead_size = class_size - class_size_without_overhead; |
| 1181 | |
| 1182 | if (overhead_size != 0) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1183 | // Create a byte array to reflect the allocation of the |
| 1184 | // StaticField array at the end of this class. |
| 1185 | __ AddU1(HPROF_PRIMITIVE_ARRAY_DUMP); |
| 1186 | __ AddClassStaticsId(klass); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1187 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(klass)); |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1188 | __ AddU4(overhead_size); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1189 | __ AddU1(hprof_basic_byte); |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1190 | for (size_t i = 0; i < overhead_size; ++i) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1191 | __ AddU1(0); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | __ AddU1(HPROF_CLASS_DUMP); |
| 1196 | __ AddClassId(LookupClassId(klass)); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1197 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(klass)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1198 | __ AddClassId(LookupClassId(klass->GetSuperClass())); |
| 1199 | __ AddObjectId(klass->GetClassLoader()); |
| 1200 | __ AddObjectId(nullptr); // no signer |
| 1201 | __ AddObjectId(nullptr); // no prot domain |
| 1202 | __ AddObjectId(nullptr); // reserved |
| 1203 | __ AddObjectId(nullptr); // reserved |
| 1204 | if (klass->IsClassClass()) { |
| 1205 | // ClassObjects have their static fields appended, so aren't all the same size. |
| 1206 | // But they're at least this size. |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1207 | __ AddU4(class_size_without_overhead); // instance size |
Jeff Hao | 0ce4353 | 2015-05-12 18:58:32 -0700 | [diff] [blame] | 1208 | } else if (klass->IsStringClass()) { |
| 1209 | // Strings are variable length with character data at the end like arrays. |
| 1210 | // This outputs the size of an empty string. |
| 1211 | __ AddU4(sizeof(mirror::String)); |
| 1212 | } else if (klass->IsArrayClass() || klass->IsPrimitive()) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1213 | __ AddU4(0); |
| 1214 | } else { |
| 1215 | __ AddU4(klass->GetObjectSize()); // instance size |
| 1216 | } |
| 1217 | |
| 1218 | __ AddU2(0); // empty const pool |
| 1219 | |
| 1220 | // Static fields |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1221 | if (overhead_size == 0) { |
| 1222 | __ AddU2(static_cast<uint16_t>(0)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1223 | } else { |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1224 | __ AddU2(static_cast<uint16_t>(num_static_fields + 1)); |
| 1225 | __ AddStringId(LookupStringId(kClassOverheadName)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1226 | __ AddU1(hprof_basic_object); |
| 1227 | __ AddClassStaticsId(klass); |
| 1228 | |
Mathieu Chartier | a6d3a7e | 2015-06-03 16:51:09 -0700 | [diff] [blame] | 1229 | for (size_t i = 0; i < num_static_fields; ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1230 | ArtField* f = klass->GetStaticField(i); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1231 | |
| 1232 | size_t size; |
| 1233 | HprofBasicType t = SignatureToBasicTypeAndSize(f->GetTypeDescriptor(), &size); |
| 1234 | __ AddStringId(LookupStringId(f->GetName())); |
| 1235 | __ AddU1(t); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1236 | switch (t) { |
| 1237 | case hprof_basic_byte: |
Mathieu Chartier | ff38c04 | 2015-03-06 11:33:36 -0800 | [diff] [blame] | 1238 | __ AddU1(f->GetByte(klass)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1239 | break; |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1240 | case hprof_basic_boolean: |
| 1241 | __ AddU1(f->GetBoolean(klass)); |
| 1242 | break; |
| 1243 | case hprof_basic_char: |
Mathieu Chartier | ff38c04 | 2015-03-06 11:33:36 -0800 | [diff] [blame] | 1244 | __ AddU2(f->GetChar(klass)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1245 | break; |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1246 | case hprof_basic_short: |
| 1247 | __ AddU2(f->GetShort(klass)); |
| 1248 | break; |
| 1249 | case hprof_basic_float: |
| 1250 | case hprof_basic_int: |
| 1251 | case hprof_basic_object: |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1252 | __ AddU4(f->Get32(klass)); |
| 1253 | break; |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1254 | case hprof_basic_double: |
| 1255 | case hprof_basic_long: |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1256 | __ AddU8(f->Get64(klass)); |
| 1257 | break; |
| 1258 | default: |
| 1259 | LOG(FATAL) << "Unexpected size " << size; |
| 1260 | UNREACHABLE(); |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | // Instance fields for this class (no superclass fields) |
Mathieu Chartier | 7c1f53e | 2015-06-03 10:51:13 -0700 | [diff] [blame] | 1266 | int iFieldCount = klass->NumInstanceFields(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1267 | if (klass->IsStringClass()) { |
| 1268 | __ AddU2((uint16_t)iFieldCount + 1); |
| 1269 | } else { |
| 1270 | __ AddU2((uint16_t)iFieldCount); |
| 1271 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1272 | for (int i = 0; i < iFieldCount; ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1273 | ArtField* f = klass->GetInstanceField(i); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1274 | __ AddStringId(LookupStringId(f->GetName())); |
| 1275 | HprofBasicType t = SignatureToBasicTypeAndSize(f->GetTypeDescriptor(), nullptr); |
| 1276 | __ AddU1(t); |
| 1277 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1278 | // Add native value character array for strings. |
| 1279 | if (klass->IsStringClass()) { |
| 1280 | __ AddStringId(LookupStringId("value")); |
| 1281 | __ AddU1(hprof_basic_object); |
| 1282 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1283 | } |
| 1284 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1285 | void Hprof::DumpHeapArray(mirror::Array* obj, mirror::Class* klass) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1286 | uint32_t length = obj->GetLength(); |
| 1287 | |
| 1288 | if (obj->IsObjectArray()) { |
| 1289 | // obj is an object array. |
| 1290 | __ AddU1(HPROF_OBJECT_ARRAY_DUMP); |
| 1291 | |
| 1292 | __ AddObjectId(obj); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1293 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(obj)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1294 | __ AddU4(length); |
| 1295 | __ AddClassId(LookupClassId(klass)); |
| 1296 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1297 | // Dump the elements, which are always objects or null. |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1298 | __ AddIdList(obj->AsObjectArray<mirror::Object>()); |
| 1299 | } else { |
| 1300 | size_t size; |
| 1301 | HprofBasicType t = SignatureToBasicTypeAndSize( |
| 1302 | Primitive::Descriptor(klass->GetComponentType()->GetPrimitiveType()), &size); |
| 1303 | |
| 1304 | // obj is a primitive array. |
| 1305 | __ AddU1(HPROF_PRIMITIVE_ARRAY_DUMP); |
| 1306 | |
| 1307 | __ AddObjectId(obj); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1308 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(obj)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1309 | __ AddU4(length); |
| 1310 | __ AddU1(t); |
| 1311 | |
| 1312 | // Dump the raw, packed element values. |
| 1313 | if (size == 1) { |
| 1314 | __ AddU1List(reinterpret_cast<const uint8_t*>(obj->GetRawData(sizeof(uint8_t), 0)), length); |
| 1315 | } else if (size == 2) { |
| 1316 | __ AddU2List(reinterpret_cast<const uint16_t*>(obj->GetRawData(sizeof(uint16_t), 0)), length); |
| 1317 | } else if (size == 4) { |
| 1318 | __ AddU4List(reinterpret_cast<const uint32_t*>(obj->GetRawData(sizeof(uint32_t), 0)), length); |
| 1319 | } else if (size == 8) { |
| 1320 | __ AddU8List(reinterpret_cast<const uint64_t*>(obj->GetRawData(sizeof(uint64_t), 0)), length); |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1325 | void Hprof::DumpHeapInstanceObject(mirror::Object* obj, mirror::Class* klass) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1326 | // obj is an instance object. |
| 1327 | __ AddU1(HPROF_INSTANCE_DUMP); |
| 1328 | __ AddObjectId(obj); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1329 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(obj)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1330 | __ AddClassId(LookupClassId(klass)); |
| 1331 | |
| 1332 | // Reserve some space for the length of the instance data, which we won't |
| 1333 | // know until we're done writing it. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1334 | size_t size_patch_offset = output_->Length(); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1335 | __ AddU4(0x77777777); |
| 1336 | |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1337 | // What we will use for the string value if the object is a string. |
| 1338 | mirror::Object* string_value = nullptr; |
| 1339 | |
| 1340 | // Write the instance data; fields for this class, followed by super class fields, and so on. |
Mathieu Chartier | 7c1f53e | 2015-06-03 10:51:13 -0700 | [diff] [blame] | 1341 | do { |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1342 | const size_t instance_fields = klass->NumInstanceFields(); |
| 1343 | for (size_t i = 0; i < instance_fields; ++i) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1344 | ArtField* f = klass->GetInstanceField(i); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1345 | size_t size; |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1346 | HprofBasicType t = SignatureToBasicTypeAndSize(f->GetTypeDescriptor(), &size); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1347 | switch (t) { |
| 1348 | case hprof_basic_byte: |
Mathieu Chartier | ff38c04 | 2015-03-06 11:33:36 -0800 | [diff] [blame] | 1349 | __ AddU1(f->GetByte(obj)); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | case hprof_basic_boolean: |
| 1352 | __ AddU1(f->GetBoolean(obj)); |
| 1353 | break; |
| 1354 | case hprof_basic_char: |
Mathieu Chartier | ff38c04 | 2015-03-06 11:33:36 -0800 | [diff] [blame] | 1355 | __ AddU2(f->GetChar(obj)); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1356 | break; |
| 1357 | case hprof_basic_short: |
| 1358 | __ AddU2(f->GetShort(obj)); |
| 1359 | break; |
| 1360 | case hprof_basic_float: |
| 1361 | case hprof_basic_int: |
| 1362 | case hprof_basic_object: |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1363 | __ AddU4(f->Get32(obj)); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1364 | break; |
| 1365 | case hprof_basic_double: |
| 1366 | case hprof_basic_long: |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1367 | __ AddU8(f->Get64(obj)); |
Mathieu Chartier | 15f345c | 2015-03-06 12:45:44 -0800 | [diff] [blame] | 1368 | break; |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1371 | // Add value field for String if necessary. |
| 1372 | if (klass->IsStringClass()) { |
| 1373 | mirror::String* s = obj->AsString(); |
| 1374 | if (s->GetLength() == 0) { |
| 1375 | // If string is empty, use an object-aligned address within the string for the value. |
| 1376 | string_value = reinterpret_cast<mirror::Object*>( |
| 1377 | reinterpret_cast<uintptr_t>(s) + kObjectAlignment); |
| 1378 | } else { |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 1379 | if (s->IsCompressed()) { |
| 1380 | string_value = reinterpret_cast<mirror::Object*>(s->GetValueCompressed()); |
| 1381 | } else { |
| 1382 | string_value = reinterpret_cast<mirror::Object*>(s->GetValue()); |
| 1383 | } |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1384 | } |
| 1385 | __ AddObjectId(string_value); |
| 1386 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1387 | |
| 1388 | klass = klass->GetSuperClass(); |
Mathieu Chartier | 7c1f53e | 2015-06-03 10:51:13 -0700 | [diff] [blame] | 1389 | } while (klass != nullptr); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1390 | |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1391 | // Patch the instance field length. |
| 1392 | __ UpdateU4(size_patch_offset, output_->Length() - (size_patch_offset + 4)); |
| 1393 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1394 | // Output native value character array for strings. |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1395 | CHECK_EQ(obj->IsString(), string_value != nullptr); |
| 1396 | if (string_value != nullptr) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1397 | mirror::String* s = obj->AsString(); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 1398 | // Compressed string's (8-bit) length is ceil(length/2) in 16-bit blocks |
| 1399 | int length_in_16_bit = (s->IsCompressed()) ? ((s->GetLength() + 1) / 2) : s->GetLength(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1400 | __ AddU1(HPROF_PRIMITIVE_ARRAY_DUMP); |
Mathieu Chartier | 07d7eab | 2015-06-23 15:45:15 -0700 | [diff] [blame] | 1401 | __ AddObjectId(string_value); |
Man Cao | 8c2ff64 | 2015-05-27 17:25:30 -0700 | [diff] [blame] | 1402 | __ AddStackTraceSerialNumber(LookupStackTraceSerialNumber(obj)); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 1403 | __ AddU4(length_in_16_bit); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1404 | __ AddU1(hprof_basic_char); |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame^] | 1405 | if (s->IsCompressed()) { |
| 1406 | __ AddU1AsU2List(s->GetValueCompressed(), s->GetLength()); |
| 1407 | } else { |
| 1408 | __ AddU2List(s->GetValue(), s->GetLength()); |
| 1409 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1410 | } |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1411 | } |
| 1412 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1413 | void Hprof::VisitRoot(mirror::Object* obj, const RootInfo& info) { |
Jesse Wilson | 0b075f1 | 2011-11-09 10:57:41 -0500 | [diff] [blame] | 1414 | static const HprofHeapTag xlate[] = { |
| 1415 | HPROF_ROOT_UNKNOWN, |
| 1416 | HPROF_ROOT_JNI_GLOBAL, |
| 1417 | HPROF_ROOT_JNI_LOCAL, |
| 1418 | HPROF_ROOT_JAVA_FRAME, |
| 1419 | HPROF_ROOT_NATIVE_STACK, |
| 1420 | HPROF_ROOT_STICKY_CLASS, |
| 1421 | HPROF_ROOT_THREAD_BLOCK, |
| 1422 | HPROF_ROOT_MONITOR_USED, |
| 1423 | HPROF_ROOT_THREAD_OBJECT, |
| 1424 | HPROF_ROOT_INTERNED_STRING, |
| 1425 | HPROF_ROOT_FINALIZING, |
| 1426 | HPROF_ROOT_DEBUGGER, |
| 1427 | HPROF_ROOT_REFERENCE_CLEANUP, |
| 1428 | HPROF_ROOT_VM_INTERNAL, |
| 1429 | HPROF_ROOT_JNI_MONITOR, |
| 1430 | }; |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 1431 | CHECK_LT(info.GetType(), sizeof(xlate) / sizeof(HprofHeapTag)); |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1432 | if (obj == nullptr) { |
Jesse Wilson | 0b075f1 | 2011-11-09 10:57:41 -0500 | [diff] [blame] | 1433 | return; |
| 1434 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 1435 | MarkRootObject(obj, 0, xlate[info.GetType()], info.GetThreadId()); |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 1436 | } |
| 1437 | |
Elliott Hughes | dcfdd2b | 2012-07-09 18:27:46 -0700 | [diff] [blame] | 1438 | // If "direct_to_ddms" is true, the other arguments are ignored, and data is |
| 1439 | // sent directly to DDMS. |
| 1440 | // If "fd" is >= 0, the output will be written to that file descriptor. |
| 1441 | // Otherwise, "filename" is used to create an output file. |
| 1442 | void DumpHeap(const char* filename, int fd, bool direct_to_ddms) { |
Andreas Gampe | 3a91309 | 2015-01-10 00:26:17 -0800 | [diff] [blame] | 1443 | CHECK(filename != nullptr); |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 1444 | |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 1445 | Thread* self = Thread::Current(); |
| 1446 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1447 | if (heap->IsGcConcurrentAndMoving()) { |
| 1448 | // Need to take a heap dump while GC isn't running. See the |
| 1449 | // comment in Heap::VisitObjects(). |
| 1450 | heap->IncrementDisableMovingGC(self); |
| 1451 | } |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 1452 | { |
| 1453 | ScopedSuspendAll ssa(__FUNCTION__, true /* long suspend */); |
| 1454 | Hprof hprof(filename, fd, direct_to_ddms); |
| 1455 | hprof.Dump(); |
| 1456 | } |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 1457 | if (heap->IsGcConcurrentAndMoving()) { |
| 1458 | heap->DecrementDisableMovingGC(self); |
| 1459 | } |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 1462 | } // namespace hprof |
Jesse Wilson | c4824e6 | 2011-11-01 14:39:04 -0400 | [diff] [blame] | 1463 | } // namespace art |