Title: [105841] trunk/Source/_javascript_Core
Revision
105841
Author
[email protected]
Date
2012-01-24 18:02:50 -0800 (Tue, 24 Jan 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=76855
Implement a JIT-code aware sampling profiler for JSC

Reviewed by Oliver Hunt.

Add support to MetaAllocator.cpp to track all live handles in a map,
allowing lookup based on any address within the allocation.

* wtf/MetaAllocator.cpp:
(WTF::MetaAllocatorTracker::notify):
(WTF::MetaAllocatorTracker::release):
    - Track live handle objects in a map.
(WTF::MetaAllocator::release):
    - Removed support for handles with null m_allocator (no longer used).
    - Notify the tracker of handles being released.
(WTF::MetaAllocatorHandle::~MetaAllocatorHandle):
    - Moved functionality out into MetaAllocator::release.
(WTF::MetaAllocatorHandle::shrink):
    - Removed support for handles with null m_allocator (no longer used).
(WTF::MetaAllocator::MetaAllocator):
    - Initialize m_tracker.
(WTF::MetaAllocator::allocate):
    - Notify the tracker of new allocations.
* wtf/MetaAllocator.h:
(WTF::MetaAllocatorTracker::find):
    - Lookup a MetaAllocatorHandle based on an address inside the allocation.
(WTF::MetaAllocator::trackAllocations):
    - Register a callback object to track allocation state.
* wtf/MetaAllocatorHandle.h:
    - Remove unused createSelfManagedHandle/constructor.
(WTF::MetaAllocatorHandle::key):
    - Added, for use in RedBlackTree.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (105840 => 105841)


--- trunk/Source/_javascript_Core/ChangeLog	2012-01-25 01:44:57 UTC (rev 105840)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-01-25 02:02:50 UTC (rev 105841)
@@ -1,3 +1,38 @@
+2012-01-24  Gavin Barraclough  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=76855
+        Implement a JIT-code aware sampling profiler for JSC
+
+        Reviewed by Oliver Hunt.
+
+        Add support to MetaAllocator.cpp to track all live handles in a map,
+        allowing lookup based on any address within the allocation.
+
+        * wtf/MetaAllocator.cpp:
+        (WTF::MetaAllocatorTracker::notify):
+        (WTF::MetaAllocatorTracker::release):
+            - Track live handle objects in a map.
+        (WTF::MetaAllocator::release):
+            - Removed support for handles with null m_allocator (no longer used).
+            - Notify the tracker of handles being released.
+        (WTF::MetaAllocatorHandle::~MetaAllocatorHandle):
+            - Moved functionality out into MetaAllocator::release.
+        (WTF::MetaAllocatorHandle::shrink):
+            - Removed support for handles with null m_allocator (no longer used).
+        (WTF::MetaAllocator::MetaAllocator):
+            - Initialize m_tracker.
+        (WTF::MetaAllocator::allocate):
+            - Notify the tracker of new allocations.
+        * wtf/MetaAllocator.h:
+        (WTF::MetaAllocatorTracker::find):
+            - Lookup a MetaAllocatorHandle based on an address inside the allocation.
+        (WTF::MetaAllocator::trackAllocations):
+            - Register a callback object to track allocation state.
+        * wtf/MetaAllocatorHandle.h:
+            - Remove unused createSelfManagedHandle/constructor.
+        (WTF::MetaAllocatorHandle::key):
+            - Added, for use in RedBlackTree.
+
 2012-01-24  Mark Hahnenberg  <[email protected]>
 
         Use copying collector for out-of-line JSObject property storage

Modified: trunk/Source/_javascript_Core/wtf/MetaAllocator.cpp (105840 => 105841)


--- trunk/Source/_javascript_Core/wtf/MetaAllocator.cpp	2012-01-25 01:44:57 UTC (rev 105840)
+++ trunk/Source/_javascript_Core/wtf/MetaAllocator.cpp	2012-01-25 02:02:50 UTC (rev 105841)
@@ -33,6 +33,28 @@
 
 namespace WTF {
 
+void MetaAllocatorTracker::notify(MetaAllocatorHandle* handle)
+{
+    m_allocations.insert(handle);
+}
+
+void MetaAllocatorTracker::release(MetaAllocatorHandle* handle)
+{
+    m_allocations.remove(handle);
+}
+
+ALWAYS_INLINE void MetaAllocator::release(MetaAllocatorHandle* handle)
+{
+    SpinLockHolder locker(&m_lock);
+    if (handle->sizeInBytes()) {
+        decrementPageOccupancy(handle->start(), handle->sizeInBytes());
+        addFreeSpaceFromReleasedHandle(handle->start(), handle->sizeInBytes());
+    }
+
+    if (UNLIKELY(!!m_tracker))
+        m_tracker->release(handle);
+}
+
 MetaAllocatorHandle::MetaAllocatorHandle(MetaAllocator* allocator, void* start, size_t sizeInBytes)
     : m_allocator(allocator)
     , m_start(start)
@@ -45,24 +67,14 @@
 
 MetaAllocatorHandle::~MetaAllocatorHandle()
 {
-    if (!m_allocator)
-        return;
-    SpinLockHolder locker(&m_allocator->m_lock);
-    if (m_sizeInBytes) {
-        m_allocator->decrementPageOccupancy(m_start, m_sizeInBytes);
-        m_allocator->addFreeSpaceFromReleasedHandle(m_start, m_sizeInBytes);
-    }
+    ASSERT(m_allocator);
+    m_allocator->release(this);
 }
 
 void MetaAllocatorHandle::shrink(size_t newSizeInBytes)
 {
     ASSERT(newSizeInBytes <= m_sizeInBytes);
     
-    if (!m_allocator) {
-        m_sizeInBytes = newSizeInBytes;
-        return;
-    }
-    
     SpinLockHolder locker(&m_allocator->m_lock);
 
     newSizeInBytes = m_allocator->roundUp(newSizeInBytes);
@@ -91,6 +103,7 @@
     , m_bytesAllocated(0)
     , m_bytesReserved(0)
     , m_bytesCommitted(0)
+    , m_tracker(0)
 #ifndef NDEBUG
     , m_mallocBalance(0)
 #endif
@@ -158,6 +171,9 @@
     // FIXME: Implement a verifier scheme that groks MetaAllocatorHandles
     handle->deprecatedTurnOffVerifier();
 
+    if (UNLIKELY(!!m_tracker))
+        m_tracker->notify(handle);
+
     return adoptRef(handle);
 }
 

Modified: trunk/Source/_javascript_Core/wtf/MetaAllocator.h (105840 => 105841)


--- trunk/Source/_javascript_Core/wtf/MetaAllocator.h	2012-01-25 01:44:57 UTC (rev 105840)
+++ trunk/Source/_javascript_Core/wtf/MetaAllocator.h	2012-01-25 02:02:50 UTC (rev 105841)
@@ -43,6 +43,22 @@
 
 #define ENABLE_META_ALLOCATOR_PROFILE 0
 
+class MetaAllocatorTracker {
+public:
+    void notify(MetaAllocatorHandle*);
+    void release(MetaAllocatorHandle*);
+
+    MetaAllocatorHandle* find(void* address)
+    {
+        MetaAllocatorHandle* handle = m_allocations.findGreatestLessThanOrEqual(address);
+        if (handle && address < handle->end())
+            return handle;
+        return 0;
+    }
+
+    RedBlackTree<MetaAllocatorHandle, void*> m_allocations;
+};
+
 class MetaAllocator {
     WTF_MAKE_NONCOPYABLE(MetaAllocator);
 
@@ -52,6 +68,11 @@
     virtual ~MetaAllocator();
     
     WTF_EXPORT_PRIVATE PassRefPtr<MetaAllocatorHandle> allocate(size_t sizeInBytes);
+
+    void trackAllocations(MetaAllocatorTracker* tracker)
+    {
+        m_tracker = tracker;
+    }
     
     // Non-atomic methods for getting allocator statistics.
     size_t bytesAllocated() { return m_bytesAllocated; }
@@ -118,6 +139,9 @@
         size_t m_sizeInBytes;
     };
     typedef RedBlackTree<FreeSpaceNode, size_t> Tree;
+
+    // Release a MetaAllocatorHandle.
+    void release(MetaAllocatorHandle*);
     
     // Remove free space from the allocator. This is effectively
     // the allocate() function, except that it does not mark the
@@ -160,6 +184,8 @@
     
     SpinLock m_lock;
 
+    MetaAllocatorTracker* m_tracker;
+
 #ifndef NDEBUG
     size_t m_mallocBalance;
 #endif

Modified: trunk/Source/_javascript_Core/wtf/MetaAllocatorHandle.h (105840 => 105841)


--- trunk/Source/_javascript_Core/wtf/MetaAllocatorHandle.h	2012-01-25 01:44:57 UTC (rev 105840)
+++ trunk/Source/_javascript_Core/wtf/MetaAllocatorHandle.h	2012-01-25 02:02:50 UTC (rev 105841)
@@ -30,6 +30,7 @@
 #define WTF_MetaAllocatorHandle_h
 
 #include <wtf/Assertions.h>
+#include <wtf/RedBlackTree.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
@@ -37,26 +38,13 @@
 
 class MetaAllocator;
 
-class MetaAllocatorHandle : public RefCounted<MetaAllocatorHandle> {
+class MetaAllocatorHandle : public RefCounted<MetaAllocatorHandle>, public RedBlackTree<MetaAllocatorHandle, void*>::Node {
 private:
     MetaAllocatorHandle(MetaAllocator*, void* start, size_t sizeInBytes);
     
-    MetaAllocatorHandle(void* start, size_t sizeInBytes)
-        : m_allocator(0)
-        , m_start(start)
-        , m_sizeInBytes(sizeInBytes)
-    {
-        ASSERT(start);
-    }
-    
 public:
     WTF_EXPORT_PRIVATE ~MetaAllocatorHandle();
     
-    static PassRefPtr<MetaAllocatorHandle> createSelfManagedHandle(void* start, size_t sizeInBytes)
-    {
-        return adoptRef(new MetaAllocatorHandle(start, sizeInBytes));
-    }
-    
     void* start()
     {
         return m_start;
@@ -85,6 +73,11 @@
         return m_allocator;
     }
     
+    void* key()
+    {
+        return m_start;
+    }
+    
 private:
     friend class MetaAllocator;
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to