Title: [134906] trunk
Revision
134906
Author
yu...@chromium.org
Date
2012-11-15 23:30:01 -0800 (Thu, 15 Nov 2012)

Log Message

Memory instrumentation: add code for reporting stack traces of unknown instrumented objects
https://bugs.webkit.org/show_bug.cgi?id=102384

Reviewed by Pavel Feldman.

Source/WebCore:

* inspector/InspectorMemoryAgent.cpp:
(WebCore::MemoryInstrumentationClientImpl::checkCountedObject): return false
if the check fails.
* inspector/MemoryInstrumentationImpl.h:
(MemoryInstrumentationClientImpl):

Source/WTF:

Added an option to collect stack traces for instrumented pointers so that they
can be printed in case the check failed for the pointer. This code is hidden
behind a define.

* wtf/MemoryInstrumentation.h:
(MemoryInstrumentationClient):
(WTF::MemoryInstrumentation::checkCountedObject): the method now returns false
in case the check has failed.
(InstrumentedPointer):
(WTF::::InstrumentedPointer):
(WTF):
(WTF::::process):

Tools:

Updated return type in accord with the changes in MemoryInstrumentationClient.

* TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (134905 => 134906)


--- trunk/Source/WTF/ChangeLog	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Source/WTF/ChangeLog	2012-11-16 07:30:01 UTC (rev 134906)
@@ -1,3 +1,23 @@
+2012-11-15  Yury Semikhatsky  <yu...@chromium.org>
+
+        Memory instrumentation: add code for reporting stack traces of unknown instrumented objects
+        https://bugs.webkit.org/show_bug.cgi?id=102384
+
+        Reviewed by Pavel Feldman.
+
+        Added an option to collect stack traces for instrumented pointers so that they
+        can be printed in case the check failed for the pointer. This code is hidden
+        behind a define.
+
+        * wtf/MemoryInstrumentation.h:
+        (MemoryInstrumentationClient):
+        (WTF::MemoryInstrumentation::checkCountedObject): the method now returns false
+        in case the check has failed.
+        (InstrumentedPointer):
+        (WTF::::InstrumentedPointer):
+        (WTF):
+        (WTF::::process):
+
 2012-11-15  Mark Hahnenberg  <mhahnenb...@apple.com>
 
         Windows Fibers can corrupt the cached StackBounds

Modified: trunk/Source/WTF/wtf/MemoryInstrumentation.h (134905 => 134906)


--- trunk/Source/WTF/wtf/MemoryInstrumentation.h	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Source/WTF/wtf/MemoryInstrumentation.h	2012-11-16 07:30:01 UTC (rev 134906)
@@ -35,6 +35,13 @@
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
 
+#define DEBUG_POINTER_INSTRUMENTATION 0
+
+#if DEBUG_POINTER_INSTRUMENTATION
+#include <wtf/Assertions.h>
+#include <stdio.h>
+#endif
+
 namespace WTF {
 
 class MemoryClassInfo;
@@ -92,7 +99,7 @@
     virtual ~MemoryInstrumentationClient() { }
     virtual void countObjectSize(const void*, MemoryObjectType, size_t) = 0;
     virtual bool visited(const void*) = 0;
-    virtual void checkCountedObject(const void*) = 0;
+    virtual bool checkCountedObject(const void*) = 0;
 };
 
 class MemoryInstrumentation {
@@ -116,7 +123,7 @@
 private:
     void countObjectSize(const void* object, MemoryObjectType objectType, size_t size) { m_client->countObjectSize(object, objectType, size); }
     bool visited(const void* pointer) { return m_client->visited(pointer); }
-    void checkCountedObject(const void* pointer) { return m_client->checkCountedObject(pointer); }
+    bool checkCountedObject(const void* pointer) { return m_client->checkCountedObject(pointer); }
 
     virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
     virtual void processDeferredInstrumentedPointers() = 0;
@@ -149,12 +156,18 @@
 
     template<typename T> class InstrumentedPointer : public InstrumentedPointerBase {
     public:
-        explicit InstrumentedPointer(const T* pointer, MemoryObjectType ownerObjectType) : m_pointer(pointer), m_ownerObjectType(ownerObjectType) { }
+        InstrumentedPointer(const T* pointer, MemoryObjectType ownerObjectType);
         virtual void process(MemoryInstrumentation*) OVERRIDE;
 
     private:
         const T* m_pointer;
         const MemoryObjectType m_ownerObjectType;
+
+#if DEBUG_POINTER_INSTRUMENTATION
+        static const int s_maxCallStackSize = 32;
+        void* m_callStack[s_maxCallStackSize];
+        int m_callStackSize;
+#endif
     };
 
     template<typename T> void addObject(const T& t, MemoryObjectType ownerObjectType) { OwningTraits<T>::addObject(this, t, ownerObjectType); }
@@ -251,6 +264,17 @@
 }
 
 template<typename T>
+MemoryInstrumentation::InstrumentedPointer<T>::InstrumentedPointer(const T* pointer, MemoryObjectType ownerObjectType)
+    : m_pointer(pointer)
+    , m_ownerObjectType(ownerObjectType)
+{
+#if DEBUG_POINTER_INSTRUMENTATION
+    m_callStackSize = s_maxCallStackSize;
+    WTFGetBacktrace(m_callStack, &m_callStackSize);
+#endif
+}
+
+template<typename T>
 void MemoryInstrumentation::InstrumentedPointer<T>::process(MemoryInstrumentation* memoryInstrumentation)
 {
     MemoryObjectInfo memoryObjectInfo(memoryInstrumentation, m_ownerObjectType);
@@ -261,7 +285,12 @@
     if (pointer != m_pointer && memoryInstrumentation->visited(pointer))
         return;
     memoryInstrumentation->countObjectSize(pointer, memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
-    memoryInstrumentation->checkCountedObject(pointer);
+    if (!memoryInstrumentation->checkCountedObject(pointer)) {
+#if DEBUG_POINTER_INSTRUMENTATION
+        fputs("Unknown object counted:\n", stderr);
+        WTFPrintBacktrace(m_callStack, m_callStackSize);
+#endif
+    }
 }
 
 // Link time guard for classes with external memory instrumentation.
@@ -300,4 +329,6 @@
 
 } // namespace WTF
 
+#undef DEBUG_POINTER_INSTRUMENTATION
+
 #endif // !defined(MemoryInstrumentation_h)

Modified: trunk/Source/WebCore/ChangeLog (134905 => 134906)


--- trunk/Source/WebCore/ChangeLog	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Source/WebCore/ChangeLog	2012-11-16 07:30:01 UTC (rev 134906)
@@ -1,3 +1,16 @@
+2012-11-15  Yury Semikhatsky  <yu...@chromium.org>
+
+        Memory instrumentation: add code for reporting stack traces of unknown instrumented objects
+        https://bugs.webkit.org/show_bug.cgi?id=102384
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore::MemoryInstrumentationClientImpl::checkCountedObject): return false
+        if the check fails.
+        * inspector/MemoryInstrumentationImpl.h:
+        (MemoryInstrumentationClientImpl):
+
 2012-11-15  Jer Noble  <jer.no...@apple.com>
 
         Crash at WebCore::PluginData::pluginFileForMimeType const + 38

Modified: trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp (134905 => 134906)


--- trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp	2012-11-16 07:30:01 UTC (rev 134906)
@@ -79,17 +79,19 @@
     return !m_visitedObjects.add(object).isNewEntry;
 }
 
-void MemoryInstrumentationClientImpl::checkCountedObject(const void* object)
+bool MemoryInstrumentationClientImpl::checkCountedObject(const void* object)
 {
     if (!checkInstrumentedObjects())
-        return;
+        return true;
     if (!m_allocatedObjects.contains(object)) {
         ++m_totalObjectsNotInAllocatedSet;
+        return false;
 #if 0
         printf("Found unknown object referenced by pointer: %p\n", object);
         WTFReportBacktrace();
 #endif
     }
+    return true;
 }
 
 void MemoryInstrumentationClientImpl::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const

Modified: trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h (134905 => 134906)


--- trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h	2012-11-16 07:30:01 UTC (rev 134906)
@@ -80,7 +80,7 @@
 
     virtual void countObjectSize(const void*, MemoryObjectType, size_t) OVERRIDE;
     virtual bool visited(const void*) OVERRIDE;
-    virtual void checkCountedObject(const void*) OVERRIDE;
+    virtual bool checkCountedObject(const void*) OVERRIDE;
 
     void reportMemoryUsage(MemoryObjectInfo*) const;
 

Modified: trunk/Tools/ChangeLog (134905 => 134906)


--- trunk/Tools/ChangeLog	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Tools/ChangeLog	2012-11-16 07:30:01 UTC (rev 134906)
@@ -1,3 +1,14 @@
+2012-11-15  Yury Semikhatsky  <yu...@chromium.org>
+
+        Memory instrumentation: add code for reporting stack traces of unknown instrumented objects
+        https://bugs.webkit.org/show_bug.cgi?id=102384
+
+        Reviewed by Pavel Feldman.
+
+        Updated return type in accord with the changes in MemoryInstrumentationClient.
+
+        * TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp:
+
 2012-11-15  Gustavo Noronha Silva  <g...@gnome.org>
 
         [GTK] Split WebCore/platform into a separate library

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp (134905 => 134906)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp	2012-11-16 07:10:47 UTC (rev 134905)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp	2012-11-16 07:30:01 UTC (rev 134906)
@@ -90,7 +90,7 @@
             result.iterator->value += size;
     }
     virtual bool visited(const void* object) { return !m_visitedObjects.add(object).isNewEntry; }
-    virtual void checkCountedObject(const void*) { }
+    virtual bool checkCountedObject(const void*) { return true; }
 
     size_t visitedObjects() const { return m_visitedObjects.size(); }
     size_t totalSize(const MemoryObjectType objectType) const
@@ -816,10 +816,11 @@
 class CheckCountedObjectsClient : public MemoryInstrumentationTestClient {
 public:
     CheckCountedObjectsClient(const void* expectedPointer) : m_expectedPointer(expectedPointer), m_expectedPointerFound(false) { }
-    virtual void checkCountedObject(const void* pointer)
+    virtual bool checkCountedObject(const void* pointer)
     {
         EXPECT_EQ(pointer, m_expectedPointer);
         m_expectedPointerFound = true;
+        return true;
     }
     bool expectedPointerFound() { return m_expectedPointerFound; }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to