OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 buflen += printed; | 294 buflen += printed; |
295 } | 295 } |
296 printed = snprintf(buf + buflen, bufsize - buflen, "\n"); | 296 printed = snprintf(buf + buflen, bufsize - buflen, "\n"); |
297 if (printed < 0 || printed >= bufsize - buflen) return buflen; | 297 if (printed < 0 || printed >= bufsize - buflen) return buflen; |
298 buflen += printed; | 298 buflen += printed; |
299 return buflen; | 299 return buflen; |
300 } | 300 } |
301 | 301 |
302 HeapProfileTable::Bucket** | 302 HeapProfileTable::Bucket** |
303 HeapProfileTable::MakeSortedBucketList() const { | 303 HeapProfileTable::MakeSortedBucketList() const { |
| 304 // We allocate memory for (num_buckets_ + 1) buckets |
| 305 // because this allocations itself could create a new bucket. |
| 306 // There is no harm even if it doesn't create a new bucket. |
304 Bucket** list = | 307 Bucket** list = |
305 reinterpret_cast<Bucket**>(alloc_(sizeof(Bucket) * num_buckets_)); | 308 reinterpret_cast<Bucket**>(alloc_(sizeof(Bucket) * (num_buckets_ + 1))); |
306 | 309 |
307 int n = 0; | 310 int n = 0; |
308 for (int b = 0; b < kHashTableSize; b++) { | 311 for (int b = 0; b < kHashTableSize; b++) { |
309 for (Bucket* x = table_[b]; x != 0; x = x->next) { | 312 for (Bucket* x = table_[b]; x != 0; x = x->next) { |
310 list[n++] = x; | 313 list[n++] = x; |
311 } | 314 } |
312 } | 315 } |
313 RAW_DCHECK(n == num_buckets_, ""); | 316 RAW_DCHECK(n == num_buckets_, ""); |
314 | 317 |
315 sort(list, list + num_buckets_, ByAllocatedSpace); | 318 sort(list, list + num_buckets_, ByAllocatedSpace); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 char* unused) { | 595 char* unused) { |
593 // Perhaps also log the allocation stack trace (unsymbolized) | 596 // Perhaps also log the allocation stack trace (unsymbolized) |
594 // on this line in case somebody finds it useful. | 597 // on this line in case somebody finds it useful. |
595 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr); | 598 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr); |
596 } | 599 } |
597 | 600 |
598 void HeapProfileTable::Snapshot::ReportIndividualObjects() { | 601 void HeapProfileTable::Snapshot::ReportIndividualObjects() { |
599 char unused; | 602 char unused; |
600 map_.Iterate(ReportObject, &unused); | 603 map_.Iterate(ReportObject, &unused); |
601 } | 604 } |
OLD | NEW |