Skip to content

Commit

Permalink
Fix mmap region iteration while no regions are recorded.
Browse files Browse the repository at this point in the history
If no mmap regions are recorded, iteration failed since the
RegionSet (std::set) object is not initialized.

BUG=162208
R=willchan@chromium.org

Review URL: https://codereview.chromium.org/14769008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198878 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dmikurube@chromium.org committed May 8, 2013
1 parent 02a7c27 commit 70f02ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions third_party/tcmalloc/chromium/src/deep-heap-profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,11 @@ void DeepHeapProfile::GlobalStats::SnapshotMaps(

MemoryRegionMap::RegionIterator mmap_iter =
MemoryRegionMap::BeginRegionLocked();
DeepBucket* deep_bucket = GetInformationOfMemoryRegion(
mmap_iter, memory_residence_info_getter, deep_profile);
DeepBucket* deep_bucket = NULL;
if (mmap_iter != MemoryRegionMap::EndRegionLocked()) {
deep_bucket = GetInformationOfMemoryRegion(
mmap_iter, memory_residence_info_getter, deep_profile);
}

while (procmaps_iter.Next(&vma_start_addr, &vma_last_addr,
&flags, &offset, &inode, &filename)) {
Expand Down
21 changes: 13 additions & 8 deletions third_party/tcmalloc/chromium/src/memory_region_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ void MemoryRegionMap::Init(int max_stack_depth, bool use_buckets) {
memset(bucket_table_, 0, table_bytes);
num_buckets_ = 0;
}
if (regions_ == NULL) // init regions_
InitRegionSetLocked();
Unlock();
RAW_VLOG(10, "MemoryRegionMap Init done");
}
Expand Down Expand Up @@ -533,6 +535,15 @@ void MemoryRegionMap::RestoreSavedBucketsLocked() {
}
}

inline void MemoryRegionMap::InitRegionSetLocked() {
RAW_VLOG(12, "Initializing region set");
regions_ = regions_rep.region_set();
recursive_insert = true;
new(regions_) RegionSet();
HandleSavedRegionsLocked(&DoInsertRegionLocked);
recursive_insert = false;
}

inline void MemoryRegionMap::InsertRegionLocked(const Region& region) {
RAW_CHECK(LockIsHeld(), "should be held (by this thread)");
// We can be called recursively, because RegionSet constructor
Expand All @@ -552,14 +563,8 @@ inline void MemoryRegionMap::InsertRegionLocked(const Region& region) {
// then increment saved_regions_count.
saved_regions[saved_regions_count++] = region;
} else { // not a recusrive call
if (regions_ == NULL) { // init regions_
RAW_VLOG(12, "Initializing region set");
regions_ = regions_rep.region_set();
recursive_insert = true;
new(regions_) RegionSet();
HandleSavedRegionsLocked(&DoInsertRegionLocked);
recursive_insert = false;
}
if (regions_ == NULL) // init regions_
InitRegionSetLocked();
recursive_insert = true;
// Do the actual insertion work to put new regions into regions_:
DoInsertRegionLocked(region);
Expand Down
3 changes: 3 additions & 0 deletions third_party/tcmalloc/chromium/src/memory_region_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ class MemoryRegionMap {
// table where all buckets eventually should be.
static void RestoreSavedBucketsLocked();

// Initialize RegionSet regions_.
inline static void InitRegionSetLocked();

// Wrapper around DoInsertRegionLocked
// that handles the case of recursive allocator calls.
inline static void InsertRegionLocked(const Region& region);
Expand Down

0 comments on commit 70f02ff

Please sign in to comment.