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

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

Issue 23441082: Fixed an overflow bug in the compare function used by the heap histogram sorting. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | « no previous file | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_histogram.h" 5 #include "vm/heap_histogram.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/json_stream.h" 10 #include "vm/json_stream.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 void ObjectHistogram::Add(RawObject* obj) { 72 void ObjectHistogram::Add(RawObject* obj) {
73 intptr_t class_id = obj->GetClassId(); 73 intptr_t class_id = obj->GetClassId();
74 if (class_id == kFreeListElement) return; 74 if (class_id == kFreeListElement) return;
75 ASSERT(class_id < table_length_); 75 ASSERT(class_id < table_length_);
76 table_[class_id].Add(obj->Size()); 76 table_[class_id].Add(obj->Size());
77 } 77 }
78 78
79 79
80 int ObjectHistogram::compare(const Element** a, const Element** b) { 80 int ObjectHistogram::compare(const Element** a, const Element** b) {
81 return (*b)->size_ - (*a)->size_; 81 // Be careful to return a 32bit integer.
82 intptr_t a_size = (*a)->size_;
83 intptr_t b_size = (*b)->size_;
84 if (a_size > b_size) return -1;
85 if (a_size < b_size) return 1;
86 return 0;
82 } 87 }
83 88
84 89
85 ObjectHistogram::Element** ObjectHistogram::GetSortedArray( 90 ObjectHistogram::Element** ObjectHistogram::GetSortedArray(
86 intptr_t* array_length) { 91 intptr_t* array_length) {
87 intptr_t length = 0; 92 intptr_t length = 0;
88 for (intptr_t index = 0; index < table_length_; index++) { 93 for (intptr_t index = 0; index < table_length_; index++) {
89 if (table_[index].count_ > 0) length++; 94 if (table_[index].count_ > 0) length++;
90 } 95 }
91 // Then add them to a new array and sort. 96 // Then add them to a new array and sort.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 JSONObject sums(&jsobj, "sums"); 204 JSONObject sums(&jsobj, "sums");
200 sums.AddProperty("size", size_sum); 205 sums.AddProperty("size", size_sum);
201 sums.AddProperty("count", count_sum); 206 sums.AddProperty("count", count_sum);
202 207
203 // Deallocate the array for sorting. 208 // Deallocate the array for sorting.
204 free(array); 209 free(array);
205 } 210 }
206 211
207 212
208 } // namespace dart 213 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698