Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: runtime/vm/heap_profiler.cc

Issue 14623015: Potentially fix the crash reported in Issue 10385 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/heap_profiler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/heap_profiler.h" 5 #include "vm/heap_profiler.h"
6 6
7 #include "vm/dart_api_state.h" 7 #include "vm/dart_api_state.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/raw_object.h" 9 #include "vm/raw_object.h"
10 #include "vm/stack_frame.h" 10 #include "vm/stack_frame.h"
(...skipping 12 matching lines...) Expand all
23 size_ += size; 23 size_ += size;
24 } 24 }
25 25
26 26
27 void HeapProfiler::Buffer::EnsureCapacity(intptr_t size) { 27 void HeapProfiler::Buffer::EnsureCapacity(intptr_t size) {
28 if ((size + size_) > capacity_) { 28 if ((size + size_) > capacity_) {
29 intptr_t new_capacity = Utils::RoundUpToPowerOfTwo(capacity_ + size); 29 intptr_t new_capacity = Utils::RoundUpToPowerOfTwo(capacity_ + size);
30 uint8_t* new_data = new uint8_t[new_capacity]; 30 uint8_t* new_data = new uint8_t[new_capacity];
31 memmove(new_data, data_, size_); 31 memmove(new_data, data_, size_);
32 capacity_ = new_capacity; 32 capacity_ = new_capacity;
33 delete[] data_;
33 data_ = new_data; 34 data_ = new_data;
34 } 35 }
35 } 36 }
36 37
37 38
38 void HeapProfiler::Record::Write(const uint8_t* value, intptr_t size) { 39 void HeapProfiler::Record::Write(const uint8_t* value, intptr_t size) {
39 body_.Write(value, size); 40 body_.Write(value, size);
40 } 41 }
41 42
42 43
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 case kArrayCid: 251 case kArrayCid:
251 case kImmutableArrayCid: { 252 case kImmutableArrayCid: {
252 WriteObjectArrayDump(reinterpret_cast<const RawArray*>(raw_obj)); 253 WriteObjectArrayDump(reinterpret_cast<const RawArray*>(raw_obj));
253 break; 254 break;
254 } 255 }
255 case kTypedDataInt8ArrayCid: 256 case kTypedDataInt8ArrayCid:
256 case kTypedDataUint8ArrayCid: 257 case kTypedDataUint8ArrayCid:
257 case kTypedDataUint8ClampedArrayCid: { 258 case kTypedDataUint8ClampedArrayCid: {
258 const RawTypedData* raw_int8_array = 259 const RawTypedData* raw_int8_array =
259 reinterpret_cast<const RawTypedData*>(raw_obj); 260 reinterpret_cast<const RawTypedData*>(raw_obj);
260 WritePrimitiveArrayDump(raw_int8_array, 261 WritePrimitiveArrayDump(raw_int8_array, kByte);
261 kByte,
262 &raw_int8_array->data_[0]);
263 break; 262 break;
264 } 263 }
265 case kTypedDataInt16ArrayCid: 264 case kTypedDataInt16ArrayCid:
266 case kTypedDataUint16ArrayCid: { 265 case kTypedDataUint16ArrayCid: {
267 const RawTypedData* raw_int16_array = 266 const RawTypedData* raw_int16_array =
268 reinterpret_cast<const RawTypedData*>(raw_obj); 267 reinterpret_cast<const RawTypedData*>(raw_obj);
269 WritePrimitiveArrayDump(raw_int16_array, 268 WritePrimitiveArrayDump(raw_int16_array, kShort);
270 kShort,
271 &raw_int16_array->data_[0]);
272 break; 269 break;
273 } 270 }
274 case kTypedDataInt32ArrayCid: 271 case kTypedDataInt32ArrayCid:
275 case kTypedDataUint32ArrayCid: { 272 case kTypedDataUint32ArrayCid: {
276 const RawTypedData* raw_int32_array = 273 const RawTypedData* raw_int32_array =
277 reinterpret_cast<const RawTypedData*>(raw_obj); 274 reinterpret_cast<const RawTypedData*>(raw_obj);
278 WritePrimitiveArrayDump(raw_int32_array, 275 WritePrimitiveArrayDump(raw_int32_array, kInt);
279 kInt,
280 &raw_int32_array->data_[0]);
281 break; 276 break;
282 } 277 }
283 case kTypedDataInt64ArrayCid: 278 case kTypedDataInt64ArrayCid:
284 case kTypedDataUint64ArrayCid: { 279 case kTypedDataUint64ArrayCid: {
285 const RawTypedData* raw_int64_array = 280 const RawTypedData* raw_int64_array =
286 reinterpret_cast<const RawTypedData*>(raw_obj); 281 reinterpret_cast<const RawTypedData*>(raw_obj);
287 WritePrimitiveArrayDump(raw_int64_array, 282 WritePrimitiveArrayDump(raw_int64_array, kLong);
288 kLong,
289 &raw_int64_array->data_[0]);
290 break; 283 break;
291 } 284 }
292 case kTypedDataFloat32ArrayCid: { 285 case kTypedDataFloat32ArrayCid: {
293 const RawTypedData* raw_float32_array = 286 const RawTypedData* raw_float32_array =
294 reinterpret_cast<const RawTypedData*>(raw_obj); 287 reinterpret_cast<const RawTypedData*>(raw_obj);
295 WritePrimitiveArrayDump(raw_float32_array, 288 WritePrimitiveArrayDump(raw_float32_array, kFloat);
296 kFloat,
297 &raw_float32_array->data_[0]);
298 break; 289 break;
299 } 290 }
300 case kTypedDataFloat64ArrayCid: { 291 case kTypedDataFloat64ArrayCid: {
301 const RawTypedData* raw_float64_array = 292 const RawTypedData* raw_float64_array =
302 reinterpret_cast<const RawTypedData*>(raw_obj); 293 reinterpret_cast<const RawTypedData*>(raw_obj);
303 WritePrimitiveArrayDump(raw_float64_array, 294 WritePrimitiveArrayDump(raw_float64_array, kDouble);
304 kDouble,
305 &raw_float64_array->data_[0]);
306 break; 295 break;
307 } 296 }
308 case kOneByteStringCid: 297 case kOneByteStringCid:
309 case kTwoByteStringCid: 298 case kTwoByteStringCid:
310 case kExternalOneByteStringCid: 299 case kExternalOneByteStringCid:
311 case kExternalTwoByteStringCid: { 300 case kExternalTwoByteStringCid: {
312 WriteInstanceDump(StringId(reinterpret_cast<const RawString*>(raw_obj))); 301 WriteInstanceDump(StringId(reinterpret_cast<const RawString*>(raw_obj)));
313 break; 302 break;
314 } 303 }
315 default: 304 default:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 734
746 // PRIMITIVE ARRAY DUMP - 0x23 735 // PRIMITIVE ARRAY DUMP - 0x23
747 // 736 //
748 // Format: 737 // Format:
749 // ID - array object ID 738 // ID - array object ID
750 // u4 - stack trace serial number 739 // u4 - stack trace serial number
751 // u4 - number of elements 740 // u4 - number of elements
752 // u1 - element type 741 // u1 - element type
753 // [u1]* - elements 742 // [u1]* - elements
754 void HeapProfiler::WritePrimitiveArrayDump(const RawTypedData* raw_byte_array, 743 void HeapProfiler::WritePrimitiveArrayDump(const RawTypedData* raw_byte_array,
755 uint8_t tag, 744 uint8_t tag) {
756 const void* data) {
757 SubRecord sub(kPrimitiveArrayDump, this); 745 SubRecord sub(kPrimitiveArrayDump, this);
758 // array object ID 746 // array object ID
759 sub.WriteObjectId(raw_byte_array); 747 sub.WriteObjectId(raw_byte_array);
760 // stack trace serial number 748 // stack trace serial number
761 sub.Write32(0); 749 sub.Write32(0);
762 // number of elements 750 // number of elements
763 intptr_t length = Smi::Value(raw_byte_array->ptr()->length_); 751 intptr_t length = Smi::Value(raw_byte_array->ptr()->length_);
752 const void* data = &(raw_byte_array->ptr()->data_[0]);
764 sub.Write32(length); 753 sub.Write32(length);
765 // element type 754 // element type
766 sub.Write8(tag); 755 sub.Write8(tag);
767 // elements (packed) 756 // elements (packed)
768 for (intptr_t i = 0; i < length; ++i) { 757 for (intptr_t i = 0; i < length; ++i) {
769 if (tag == kByte) { 758 if (tag == kByte) {
770 sub.Write8(reinterpret_cast<const int8_t*>(data)[i]); 759 sub.Write8(reinterpret_cast<const int8_t*>(data)[i]);
771 } else if (tag == kShort) { 760 } else if (tag == kShort) {
772 sub.Write16(reinterpret_cast<const int16_t*>(data)[i]); 761 sub.Write16(reinterpret_cast<const int16_t*>(data)[i]);
773 break; 762 break;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 RawObject* raw_obj = handle->raw(); 798 RawObject* raw_obj = handle->raw();
810 visitor_->VisitPointer(&raw_obj); 799 visitor_->VisitPointer(&raw_obj);
811 } 800 }
812 801
813 802
814 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { 803 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) {
815 profiler_->WriteObject(raw_obj); 804 profiler_->WriteObject(raw_obj);
816 } 805 }
817 806
818 } // namespace dart 807 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/heap_profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698