Ignore:
Timestamp:
Aug 3, 2007, 9:21:44 AM (18 years ago)
Author:
bdash
Message:

2007-08-02 Mark Rowe <[email protected]>

Reviewed by Geoff Garen.

<rdar://problem/4212199> 'leaks' reports false leaks in WebKit (because the WTF allocator uses mmap?)

Implement malloc zone introspection routines to allow leaks, heap, and friends to request information
about specific memory regions that were allocated by FastMalloc or the JavaScriptCore collector.

This requires tool-side support before the regions will be displayed. The addition of that support is
tracked by <rdar://problems/5353057&5353060>.

  • JavaScriptCore.exp: Export the two variables that are used by leaks to introspect the allocators.
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/AllInOneFile.cpp:
  • kjs/CollectorZone.cpp: Added. (KJS::): (KJS::CollectorZone::registerZone): (KJS::CollectorZone::CollectorZone): Create and register our zone with the system. (KJS::CollectorZone::zoneEnumerator): Iterate over the CollectorBlocks that are in use and report them to the caller as being used.
  • kjs/CollectorZone.h: Added. (KJS::CollectorZone::zoneObjectSize): Return zero to indicate the specified pointer does not belong to this zone.
  • kjs/collector.cpp: (KJS::Collector::registerThread): Register the CollectorZone with the system when the first thread is registered with the collector.
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_PageHeap::GetDescriptorEnsureSafe): (WTF::TCMalloc_ThreadCache_FreeList::enumerateFreeObjects): Enumerate the objects on the free list. (WTF::TCMalloc_ThreadCache::enumerateFreeObjects): Ditto. (WTF::TCMalloc_Central_FreeList::enumerateFreeObjects): Ditto. (WTF::TCMalloc_ThreadCache::InitModule): Register the FastMallocZone with the system when initializing TCMalloc. (WTF::FreeObjectFinder::FreeObjectFinder): (WTF::FreeObjectFinder::visit): Add an object to the free list. (WTF::FreeObjectFinder::isFreeObject): (WTF::FreeObjectFinder::freeObjectCount): (WTF::FreeObjectFinder::findFreeObjects): Find the free objects within a thread cache or free list. (WTF::PageMapFreeObjectFinder::PageMapFreeObjectFinder): Find the free objects within a TC_PageMap. (WTF::PageMapFreeObjectFinder::visit): Called once per allocated span. Record whether the span or any subobjects are free. (WTF::PageMapMemoryUsageRecorder::PageMapMemoryUsageRecorder): (WTF::PageMapMemoryUsageRecorder::visit): Called once per allocated span. Report the range of memory as being allocated, and the span or it's subobjects as being used if they do not appear on the free list. (WTF::FastMallocZone::zoneEnumerator): Map the key remote TCMalloc data structures into our address space. We then locate all free memory ranges before reporting the other ranges as being in use. (WTF::FastMallocZone::zoneObjectSize): Determine whether the given pointer originates from within our allocation zone. If so, we return its allocation size. (WTF::FastMallocZone::zoneMalloc): (WTF::FastMallocZone::zoneCalloc): (WTF::FastMallocZone::zoneFree): (WTF::FastMallocZone::zoneRealloc): (WTF::): (WTF::FastMallocZone::FastMallocZone): Create and register our zone with the system. (WTF::FastMallocZone::registerZone):
  • wtf/MallocZoneSupport.h: Added. (WTF::RemoteMemoryReader::RemoteMemoryReader): A helper class to ease the process of mapping memory in a different process into our local address space (WTF::RemoteMemoryReader::operator()):
  • wtf/TCPageMap.h: (TCMalloc_PageMap2::visit): Walk over the heap and visit each allocated span. (TCMalloc_PageMap3::visit): Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/TCPageMap.h

    r24059 r24843  
    157157    return true;
    158158  }
     159
     160#ifdef WTF_CHANGES
     161  template<class Visitor, class MemoryReader>
     162  void visit(const Visitor& visitor, const MemoryReader& reader)
     163  {
     164    for (int i = 0; i < ROOT_LENGTH; i++) {
     165      if (!root_[i])
     166        continue;
     167
     168      Leaf* l = reader(reinterpret_cast<Leaf*>(root_[i]));
     169      for (int j = 0; j < LEAF_LENGTH; j += visitor.visit(l->values[j]))
     170        ;
     171    }
     172  }
     173#endif
    159174};
    160175
     
    241256    return true;
    242257  }
     258
     259#ifdef WTF_CHANGES
     260  template<class Visitor, class MemoryReader>
     261  void visit(const Visitor& visitor, const MemoryReader& reader) {
     262    Node* root = reader(root_);
     263    for (int i = 0; i < INTERIOR_LENGTH; i++) {
     264      if (!root->ptrs[i])
     265        continue;
     266
     267      Node* n = reader(root->ptrs[i]);
     268      for (int j = 0; j < INTERIOR_LENGTH; j++) {
     269        if (!n->ptrs[j])
     270          continue;
     271
     272        Leaf* l = reader(reinterpret_cast<Leaf*>(n->ptrs[j]));
     273        for (int k = 0; k < LEAF_LENGTH; k += visitor.visit(l->values[k]))
     274          ;
     275      }
     276    }
     277  }
     278#endif
    243279};
    244280
Note: See TracChangeset for help on using the changeset viewer.