Diff
Modified: trunk/Source/WebCore/ChangeLog (124411 => 124412)
--- trunk/Source/WebCore/ChangeLog 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebCore/ChangeLog 2012-08-02 06:32:29 UTC (rev 124412)
@@ -1,3 +1,32 @@
+2012-08-01 Ilya Tikhonovsky <[email protected]>
+
+ Web Inspector: test native memory instrumentation code with help of unittests
+ https://bugs.webkit.org/show_bug.cgi?id=92743
+
+ Reviewed by Yury Semikhatsky.
+
+ Test a part of existing Native Memory Instrumentation code with help of unit tests.
+ 6 tests were added and two bugs were fixed.
+ a drive-by improvement: the method MemoryInstrumentation::addInstrumentedObject
+ was marked as private and addRootObject was introduced instead of it.
+ The new function also calls processDeferedPointers.
+
+ * bindings/v8/ScriptProfiler.cpp:
+ (WebCore::ScriptProfiler::collectBindingMemoryInfo):
+ * dom/MemoryInstrumentation.h:
+ (WebCore::MemoryInstrumentation::addRootObject):
+ (MemoryInstrumentation):
+ (WebCore::MemoryInstrumentation::addInstrumentedObject):
+ (WebCore::MemoryInstrumentation::addInstrumentedObjectImpl):
+ (WebCore):
+ (WebCore::MemoryInstrumentation::addObjectImpl):
+ * inspector/InspectorMemoryAgent.cpp:
+ (WebCore):
+ * inspector/MemoryInstrumentationImpl.h:
+ (MemoryInstrumentationImpl):
+ (WebCore::MemoryInstrumentationImpl::totalSize):
+ (WebCore::MemoryInstrumentationImpl::reportedSizeForAllTypes):
+
2012-08-01 Ryosuke Niwa <[email protected]>
Chromium Android build fix after r124402.
Modified: trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp (124411 => 124412)
--- trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp 2012-08-02 06:32:29 UTC (rev 124412)
@@ -223,7 +223,7 @@
void ScriptProfiler::collectBindingMemoryInfo(MemoryInstrumentation* instrumentation)
{
V8BindingPerIsolateData* data = ""
- instrumentation->addInstrumentedObject(data);
+ instrumentation->addRootObject(data);
}
size_t ScriptProfiler::profilerSnapshotsSize()
Modified: trunk/Source/WebCore/dom/MemoryInstrumentation.h (124411 => 124412)
--- trunk/Source/WebCore/dom/MemoryInstrumentation.h 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebCore/dom/MemoryInstrumentation.h 2012-08-02 06:32:29 UTC (rev 124412)
@@ -54,9 +54,10 @@
LastTypeEntry
};
- template <typename T> void addInstrumentedObject(const T& t)
+ template <typename T> void addRootObject(const T& t)
{
- OwningTraits<T>::addInstrumentedObject(this, t);
+ addInstrumentedObject(t);
+ processDeferredInstrumentedPointers();
}
template <typename Container> static size_t calculateContainerSize(const Container&, bool contentOnly = false);
@@ -68,11 +69,12 @@
virtual void process(MemoryInstrumentation*) = 0;
};
+private:
virtual void countObjectSize(ObjectType, size_t) = 0;
virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
virtual bool visited(const void*) = 0;
+ virtual void processDeferredInstrumentedPointers() = 0;
-private:
template <typename T> friend class MemoryClassInfo;
template <typename T> class InstrumentedPointer : public InstrumentedPointerBase {
public:
@@ -88,6 +90,7 @@
OwningTraits<T>::addObject(this, t, objectType);
}
void addString(const String&, ObjectType);
+ template <typename T> void addInstrumentedObject(const T& t) { OwningTraits<T>::addInstrumentedObject(this, t); }
template <typename HashMapType> void addHashMap(const HashMapType&, ObjectType, bool contentOnly = false);
template <typename HashSetType> void addHashSet(const HashSetType&, ObjectType, bool contentOnly = false);
template <typename CollectionType> void addInstrumentedCollection(const CollectionType&, ObjectType, bool contentOnly = false);
@@ -122,6 +125,8 @@
template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, OwningType);
template <typename T> void addObjectImpl(const T* const&, ObjectType, OwningType);
+ template <typename T> void addObjectImpl(const OwnPtr<T>* const&, ObjectType, OwningType);
+ template <typename T> void addObjectImpl(const RefPtr<T>* const&, ObjectType, OwningType);
};
class MemoryObjectInfo {
@@ -202,17 +207,29 @@
}
template <typename T>
-void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, OwningType owningType)
+void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, OwningType)
{
- addInstrumentedObjectImpl(object->get(), owningType);
+ addInstrumentedObjectImpl(object->get(), byPointer);
}
template <typename T>
-void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, OwningType owningType)
+void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, OwningType)
{
- addInstrumentedObjectImpl(object->get(), owningType);
+ addInstrumentedObjectImpl(object->get(), byPointer);
}
+template <typename T>
+void MemoryInstrumentation::addObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType)
+{
+ addObjectImpl(object->get(), objectType, byPointer);
+}
+
+template <typename T>
+void MemoryInstrumentation::addObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType)
+{
+ addObjectImpl(object->get(), objectType, byPointer);
+}
+
// Link time guard for string members. They produce link error is a string is reported via addObject.
template <> void MemoryInstrumentation::addObjectImpl<AtomicString>(const AtomicString* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
template <> void MemoryInstrumentation::addObjectImpl<String>(const String* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (124411 => 124412)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-08-02 06:32:29 UTC (rev 124412)
@@ -443,7 +443,6 @@
namespace {
-
class DOMTreesIterator : public NodeWrapperVisitor {
public:
DOMTreesIterator(Page* page, VisitedObjects& visitedObjects)
@@ -457,20 +456,17 @@
if (node->document() && node->document()->frame() && m_page != node->document()->frame()->page())
return;
- m_domMemoryUsage.addInstrumentedObject(node);
- m_domMemoryUsage.processDeferredInstrumentedPointers();
+ m_domMemoryUsage.addRootObject(node);
}
void visitFrame(Frame* frame)
{
- m_domMemoryUsage.addInstrumentedObject(frame);
- m_domMemoryUsage.processDeferredInstrumentedPointers();
+ m_domMemoryUsage.addRootObject(frame);
}
void visitBindings()
{
ScriptProfiler::collectBindingMemoryInfo(&m_domMemoryUsage);
- m_domMemoryUsage.processDeferredInstrumentedPointers();
}
PassRefPtr<InspectorMemoryBlock> dumpStatistics(InspectorDataCounter* inspectorData)
@@ -479,14 +475,14 @@
size_t totalSize = 0;
for (int i = MemoryInstrumentation::Other; i < MemoryInstrumentation::LastTypeEntry; ++i)
- totalSize += m_domMemoryUsage.totalTypeSize(static_cast<MemoryInstrumentation::ObjectType>(i));
+ totalSize += m_domMemoryUsage.totalSize(static_cast<MemoryInstrumentation::ObjectType>(i));
RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > domChildren = TypeBuilder::Array<InspectorMemoryBlock>::create();
- addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalTypeSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
- addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalTypeSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
- addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalTypeSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
- addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalTypeSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
- addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalTypeSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
+ addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
+ addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
+ addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
+ addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
+ addMemoryBlockFor(domChildren.get(), m_domMemoryUsage.totalSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
RefPtr<InspectorMemoryBlock> dom = InspectorMemoryBlock::create().setName(MemoryBlockName::dom);
dom->setSize(totalSize);
Modified: trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h (124411 => 124412)
--- trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h 2012-08-02 06:32:29 UTC (rev 124412)
@@ -44,18 +44,26 @@
public:
explicit MemoryInstrumentationImpl(VisitedObjects&);
- void processDeferredInstrumentedPointers();
size_t selfSize() const;
- size_t totalTypeSize(ObjectType objectType)
+ size_t totalSize(ObjectType objectType) const
{
ASSERT(objectType >= 0 && objectType < LastTypeEntry);
return m_totalSizes[objectType];
}
+ size_t reportedSizeForAllTypes() const
+ {
+ size_t size = 0;
+ for (int i = 0; i < LastTypeEntry; ++i)
+ size += m_totalSizes[i];
+ return size;
+ }
+
private:
virtual void countObjectSize(ObjectType, size_t) OVERRIDE;
virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) OVERRIDE;
virtual bool visited(const void*) OVERRIDE;
+ virtual void processDeferredInstrumentedPointers() OVERRIDE;
size_t m_totalSizes[LastTypeEntry];
VisitedObjects& m_visitedObjects;
Modified: trunk/Source/WebKit/chromium/ChangeLog (124411 => 124412)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-08-02 06:32:29 UTC (rev 124412)
@@ -1,3 +1,29 @@
+2012-08-01 Ilya Tikhonovsky <[email protected]>
+
+ Web Inspector: test native memory instrumentation code with help of unittests
+ https://bugs.webkit.org/show_bug.cgi?id=92743
+
+ Reviewed by Yury Semikhatsky.
+
+ Test a part of existing Native Memory Instrumentation code with help of unit tests.
+ 6 tests were added and two bugs were fixed.
+ a drive-by improvement: the method MemoryInstrumentation::addInstrumentedObject
+ was marked as private and addRootObject was introduced instead of it.
+ The new function also calls processDeferedPointers.
+
+ * WebKit.gypi:
+ * tests/MemoryInstrumentationTest.cpp: Added.
+ (WebCore):
+ (NotInstrumented):
+ (Instrumented):
+ (WebCore::Instrumented::Instrumented):
+ (WebCore::Instrumented::~Instrumented):
+ (WebCore::Instrumented::reportMemoryUsage):
+ (WebCore::TEST):
+ (InstrumentedWithOwnPtr):
+ (WebCore::InstrumentedWithOwnPtr::InstrumentedWithOwnPtr):
+ (WebCore::InstrumentedWithOwnPtr::reportMemoryUsage):
+
2012-08-01 Xingnan Wang <[email protected]>
IndexedDB: ObjectStoreMetaDataKey::m_metaDataType should use byte type
Modified: trunk/Source/WebKit/chromium/WebKit.gypi (124411 => 124412)
--- trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-02 05:57:42 UTC (rev 124411)
+++ trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-02 06:32:29 UTC (rev 124412)
@@ -127,6 +127,7 @@
'tests/LocalizedDateICUTest.cpp',
'tests/LocalizedNumberICUTest.cpp',
'tests/MemoryInfo.cpp',
+ 'tests/MemoryInstrumentationTest.cpp',
'tests/MockCCQuadCuller.h',
'tests/OpaqueRectTrackingContentLayerDelegateTest.cpp',
'tests/OpenTypeVerticalDataTest.cpp',
Added: trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp (0 => 124412)
--- trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp 2012-08-02 06:32:29 UTC (rev 124412)
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "MemoryInstrumentationImpl.h"
+
+#include <gtest/gtest.h>
+
+#include <wtf/HashSet.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+
+using namespace WebCore;
+
+namespace {
+
+class NotInstrumented {
+public:
+ char m_data[42];
+};
+
+class Instrumented {
+public:
+ Instrumented() : m_notInstrumented(new NotInstrumented) { }
+ virtual ~Instrumented() { delete m_notInstrumented; }
+
+ virtual void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ MemoryClassInfo<Instrumented> info(memoryObjectInfo, this, MemoryInstrumentation::DOM);
+ info.addMember(m_notInstrumented);
+ }
+ NotInstrumented* m_notInstrumented;
+};
+
+TEST(MemoryInstrumentationTest, sizeOf)
+{
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ Instrumented instrumented;
+ impl.addRootObject(instrumented);
+ EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(2, visitedObjects.size());
+}
+
+TEST(MemoryInstrumentationTest, nullCheck)
+{
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ Instrumented* instrumented = 0;
+ impl.addRootObject(instrumented);
+ EXPECT_EQ(0u, impl.reportedSizeForAllTypes());
+ EXPECT_EQ(0, visitedObjects.size());
+}
+
+TEST(MemoryInstrumentationTest, ptrVsRef)
+{
+ {
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ Instrumented instrumented;
+ impl.addRootObject(&instrumented);
+ EXPECT_EQ(sizeof(Instrumented) + sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(2, visitedObjects.size());
+ }
+ {
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ Instrumented instrumented;
+ impl.addRootObject(instrumented);
+ EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(2, visitedObjects.size());
+ }
+}
+
+TEST(MemoryInstrumentationTest, ownPtr)
+{
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ OwnPtr<Instrumented> instrumented(adoptPtr(new Instrumented));
+ impl.addRootObject(instrumented);
+ EXPECT_EQ(sizeof(Instrumented) + sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(2, visitedObjects.size());
+}
+
+class InstrumentedRefPtr : public RefCounted<InstrumentedRefPtr> {
+public:
+ InstrumentedRefPtr() : m_notInstrumented(new NotInstrumented) { }
+ virtual ~InstrumentedRefPtr() { delete m_notInstrumented; }
+
+ virtual void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ MemoryClassInfo<InstrumentedRefPtr> info(memoryObjectInfo, this, MemoryInstrumentation::DOM);
+ info.addMember(m_notInstrumented);
+ }
+ NotInstrumented* m_notInstrumented;
+};
+
+TEST(MemoryInstrumentationTest, refPtr)
+{
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ RefPtr<InstrumentedRefPtr> instrumentedRefPtr(adoptRef(new InstrumentedRefPtr));
+ impl.addRootObject(instrumentedRefPtr);
+ EXPECT_EQ(sizeof(InstrumentedRefPtr) + sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(2, visitedObjects.size());
+}
+
+class InstrumentedWithOwnPtr : public Instrumented {
+public:
+ InstrumentedWithOwnPtr() : m_notInstrumentedOwnPtr(adoptPtr(new NotInstrumented)) { }
+
+ virtual void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ MemoryClassInfo<InstrumentedWithOwnPtr> info(memoryObjectInfo, this, MemoryInstrumentation::CSS);
+ info.visitBaseClass<Instrumented>(this);
+ info.addMember(m_notInstrumentedOwnPtr);
+ }
+ OwnPtr<NotInstrumented> m_notInstrumentedOwnPtr;
+};
+
+TEST(MemoryInstrumentationTest, ownPtrNotInstrumented)
+{
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ InstrumentedWithOwnPtr instrumentedWithOwnPtr;
+ impl.addRootObject(instrumentedWithOwnPtr);
+ EXPECT_EQ(2 * sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(3, visitedObjects.size());
+}
+
+} // namespace
+
Property changes on: trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
___________________________________________________________________
Added: svn:eol-style