Changeset 124570 in webkit
- Timestamp:
- Aug 3, 2012 12:33:45 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r124566 r124570 1 2012-08-02 Ilya Tikhonovsky <loislo@chromium.org> 2 3 Web Inspector: extend test coverage for nmi code and fix 2 bugs. 4 https://bugs.webkit.org/show_bug.cgi?id=92994 5 6 Reviewed by Yury Semikhatsky. 7 8 1) owner object type propagation. 9 If a class with object-type DOM has an instrumented member with object-type Other then it has to be recorded as DOM. 10 Sample: We have SharedBuffer class and we don't know the object-type for it but we know that it is owned by an object with object-type CachedResourceImage. 11 12 2) the first member of an instrumented non virtual class was skipped even if it was reported properly. 13 it happened because the first member has the same address as it's owner 14 15 * dom/MemoryInstrumentation.h: 16 (WebCore::MemoryInstrumentation::addRootObject): 17 (WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer): 18 (InstrumentedPointer): 19 (WebCore::MemoryInstrumentation::addInstrumentedObject): 20 (MemoryInstrumentation): 21 (WebCore::MemoryInstrumentation::OwningTraits::addInstrumentedObject): 22 (WebCore::MemoryObjectInfo::MemoryObjectInfo): 23 (WebCore::MemoryObjectInfo::reportObjectInfo): 24 (WebCore::MemoryClassInfo::addInstrumentedMember): 25 (WebCore::MemoryInstrumentation::addInstrumentedObjectImpl): 26 (WebCore::MemoryInstrumentation::addObjectImpl): 27 (WebCore::MemoryInstrumentation::addInstrumentedCollection): 28 (WebCore::::process): 29 1 30 2012-08-03 Kentaro Hara <haraken@chromium.org> 2 31 -
trunk/Source/WebCore/dom/MemoryInstrumentation.h
r124452 r124570 58 58 template <typename T> void addRootObject(const T& t) 59 59 { 60 addInstrumentedObject(t );60 addInstrumentedObject(t, Other); 61 61 processDeferredInstrumentedPointers(); 62 62 } … … 80 80 template <typename T> class InstrumentedPointer : public InstrumentedPointerBase { 81 81 public: 82 explicit InstrumentedPointer(const T* pointer ) : m_pointer(pointer) { }82 explicit InstrumentedPointer(const T* pointer, ObjectType objectType) : m_pointer(pointer), m_objectType(objectType) { } 83 83 virtual void process(MemoryInstrumentation*) OVERRIDE; 84 84 85 85 private: 86 86 const T* m_pointer; 87 const ObjectType m_objectType; 87 88 }; 88 89 … … 92 93 } 93 94 void addString(const String&, ObjectType); 94 template <typename T> void addInstrumentedObject(const T& t) { OwningTraits<T>::addInstrumentedObject(this, t); } 95 template <typename T> void addInstrumentedObject(const T& t, ObjectType objectType) { OwningTraits<T>::addInstrumentedObject(this, t, objectType); } 96 95 97 template <typename HashMapType> void addHashMap(const HashMapType&, ObjectType, bool contentOnly = false); 96 98 template <typename HashSetType> void addHashSet(const HashSetType&, ObjectType, bool contentOnly = false); … … 112 114 template <typename T> 113 115 struct OwningTraits { // Default byReference implementation. 114 static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T& t ) { instrumentation->addInstrumentedObjectImpl(&t, byReference); }116 static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T& t, ObjectType objectType) { instrumentation->addInstrumentedObjectImpl(&t, objectType, byReference); } 115 117 static void addObject(MemoryInstrumentation* instrumentation, const T& t, ObjectType objectType) { instrumentation->addObjectImpl(&t, objectType, byReference); } 116 118 }; … … 118 120 template <typename T> 119 121 struct OwningTraits<T*> { // Custom byPointer implementation. 120 static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T* const& t ) { instrumentation->addInstrumentedObjectImpl(t, byPointer); }122 static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T* const& t, ObjectType objectType) { instrumentation->addInstrumentedObjectImpl(t, objectType, byPointer); } 121 123 static void addObject(MemoryInstrumentation* instrumentation, const T* const& t, ObjectType objectType) { instrumentation->addObjectImpl(t, objectType, byPointer); } 122 124 }; 123 125 124 template <typename T> void addInstrumentedObjectImpl(const T* const&, O wningType);125 template <typename T> void addInstrumentedObjectImpl(const DataRef<T>* const&, O wningType);126 template <typename T> void addInstrumentedObjectImpl(const OwnPtr<T>* const&, O wningType);127 template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, O wningType);126 template <typename T> void addInstrumentedObjectImpl(const T* const&, ObjectType, OwningType); 127 template <typename T> void addInstrumentedObjectImpl(const DataRef<T>* const&, ObjectType, OwningType); 128 template <typename T> void addInstrumentedObjectImpl(const OwnPtr<T>* const&, ObjectType, OwningType); 129 template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, ObjectType, OwningType); 128 130 129 131 template <typename T> void addObjectImpl(const T* const&, ObjectType, OwningType); … … 135 137 class MemoryObjectInfo { 136 138 public: 137 explicit MemoryObjectInfo(MemoryInstrumentation* memoryInstrumentation)139 MemoryObjectInfo(MemoryInstrumentation* memoryInstrumentation, MemoryInstrumentation::ObjectType objectType) 138 140 : m_memoryInstrumentation(memoryInstrumentation) 139 , m_objectType( MemoryInstrumentation::Other)141 , m_objectType(objectType) 140 142 , m_objectSize(0) 141 143 { } 142 144 143 145 MemoryInstrumentation::ObjectType objectType() const { return m_objectType; } … … 151 153 template <typename T> void reportObjectInfo(const T*, MemoryInstrumentation::ObjectType objectType) 152 154 { 153 if (m_objectType != MemoryInstrumentation::Other) 154 return; 155 m_objectType = objectType; 156 m_objectSize = sizeof(T); 155 if (!m_objectSize) { 156 m_objectSize = sizeof(T); 157 if (objectType != MemoryInstrumentation::Other) 158 m_objectType = objectType; 159 } 157 160 } 158 161 … … 175 178 template <typename P> void visitBaseClass(const P* ptr) { ptr->P::reportMemoryUsage(m_memoryObjectInfo); } 176 179 177 template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedObject(member ); }180 template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedObject(member, m_objectType); } 178 181 template <typename M> void addMember(const M& member) { m_memoryInstrumentation->addObject(member, m_objectType); } 179 182 … … 199 202 200 203 template <typename T> 201 void MemoryInstrumentation::addInstrumentedObjectImpl(const T* const& object, OwningType owningType) 202 { 203 if (!object || visited(object)) 204 return; 204 void MemoryInstrumentation::addInstrumentedObjectImpl(const T* const& object, ObjectType objectType, OwningType owningType) 205 { 205 206 if (owningType == byReference) { 206 MemoryObjectInfo memoryObjectInfo(this );207 MemoryObjectInfo memoryObjectInfo(this, objectType); 207 208 object->reportMemoryUsage(&memoryObjectInfo); 208 } else 209 deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object))); 210 } 211 212 template <typename T> 213 void MemoryInstrumentation::addInstrumentedObjectImpl(const DataRef<T>* const& object, OwningType) 214 { 215 addInstrumentedObjectImpl(object->get(), byPointer); 216 } 217 218 template <typename T> 219 void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, OwningType) 220 { 221 addInstrumentedObjectImpl(object->get(), byPointer); 222 } 223 224 template <typename T> 225 void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, OwningType) 226 { 227 addInstrumentedObjectImpl(object->get(), byPointer); 228 } 229 230 template <typename T> 231 void MemoryInstrumentation::addObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType) 232 { 209 } else { 210 if (!object || visited(object)) 211 return; 212 deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object, objectType))); 213 } 214 } 215 216 template <typename T> 217 void MemoryInstrumentation::addInstrumentedObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType owningType) 218 { 219 if (owningType == byPointer) 220 countObjectSize(objectType, sizeof(DataRef<T>)); 221 addInstrumentedObjectImpl(object->get(), objectType, byPointer); 222 } 223 224 template <typename T> 225 void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType owningType) 226 { 227 if (owningType == byPointer) 228 countObjectSize(objectType, sizeof(OwnPtr<T>)); 229 addInstrumentedObjectImpl(object->get(), objectType, byPointer); 230 } 231 232 template <typename T> 233 void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType owningType) 234 { 235 if (owningType == byPointer) 236 countObjectSize(objectType, sizeof(RefPtr<T>)); 237 addInstrumentedObjectImpl(object->get(), objectType, byPointer); 238 } 239 240 template <typename T> 241 void MemoryInstrumentation::addObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType owningType) 242 { 243 if (owningType == byPointer) 244 countObjectSize(objectType, sizeof(DataRef<T>)); 233 245 addObjectImpl(object->get(), objectType, byPointer); 234 246 } 235 247 236 248 template <typename T> 237 void MemoryInstrumentation::addObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType) 238 { 249 void MemoryInstrumentation::addObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType owningType) 250 { 251 if (owningType == byPointer) 252 countObjectSize(objectType, sizeof(RefPtr<T>)); 239 253 addObjectImpl(object->get(), objectType, byPointer); 240 254 } 241 255 242 256 template <typename T> 243 void MemoryInstrumentation::addObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType) 244 { 257 void MemoryInstrumentation::addObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType owningType) 258 { 259 if (owningType == byPointer) 260 countObjectSize(objectType, sizeof(RefPtr<T>)); 245 261 addObjectImpl(object->get(), objectType, byPointer); 246 262 } … … 284 300 typename CollectionType::const_iterator end = collection.end(); 285 301 for (typename CollectionType::const_iterator i = collection.begin(); i != end; ++i) 286 addInstrumentedObject(*i );302 addInstrumentedObject(*i, objectType); 287 303 } 288 304 … … 313 329 void MemoryInstrumentation::InstrumentedPointer<T>::process(MemoryInstrumentation* memoryInstrumentation) 314 330 { 315 MemoryObjectInfo memoryObjectInfo(memoryInstrumentation );331 MemoryObjectInfo memoryObjectInfo(memoryInstrumentation, m_objectType); 316 332 m_pointer->reportMemoryUsage(&memoryObjectInfo); 317 333 memoryInstrumentation->countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize()); -
trunk/Source/WebKit/chromium/ChangeLog
r124561 r124570 1 2012-08-02 Ilya Tikhonovsky <loislo@chromium.org> 2 3 Web Inspector: extend test coverage for nmi code and fix 2 bugs. 4 https://bugs.webkit.org/show_bug.cgi?id=92994 5 6 Reviewed by Yury Semikhatsky. 7 8 1) owner object type propagation. 9 If a class with object-type DOM has an instrumented member with object-type Other then it has to be recorded as DOM. 10 Sample: We have SharedBuffer class and we don't know the object-type for it but we know that it is owned by an object with object-type CachedResourceImage. 11 12 2) the first member of an instrumented non virtual class was skipped even if it was reported properly. 13 it happened because the first member has the same address as it's owner 14 15 * tests/MemoryInstrumentationTest.cpp: 16 (WebCore::TEST): 17 (WebCore): 18 (InstrumentedOther): 19 (WebCore::InstrumentedOther::InstrumentedOther): 20 (WebCore::InstrumentedOther::reportMemoryUsage): 21 (InstrumentedDOM): 22 (WebCore::InstrumentedDOM::InstrumentedDOM): 23 (WebCore::InstrumentedDOM::reportMemoryUsage): 24 (NonVirtualInstrumented): 25 (WebCore::NonVirtualInstrumented::reportMemoryUsage): 26 1 27 2012-08-02 Alec Flett <alecflett@chromium.org> 2 28 -
trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
r124452 r124570 70 70 impl.addRootObject(instrumented); 71 71 EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes()); 72 EXPECT_EQ( 2, visitedObjects.size());72 EXPECT_EQ(1, visitedObjects.size()); 73 73 } 74 74 … … 99 99 impl.addRootObject(instrumented); 100 100 EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes()); 101 EXPECT_EQ( 2, visitedObjects.size());101 EXPECT_EQ(1, visitedObjects.size()); 102 102 } 103 103 } … … 168 168 impl.addRootObject(instrumentedWithOwnPtr); 169 169 EXPECT_EQ(2 * sizeof(NotInstrumented), impl.reportedSizeForAllTypes()); 170 EXPECT_EQ(3, visitedObjects.size()); 170 EXPECT_EQ(2, visitedObjects.size()); 171 } 172 173 class InstrumentedOther { 174 public: 175 InstrumentedOther() : m_data(0) { } 176 177 void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 178 { 179 MemoryClassInfo<InstrumentedOther> info(memoryObjectInfo, this, MemoryInstrumentation::Other); 180 } 181 int m_data; 182 }; 183 184 class InstrumentedDOM { 185 public: 186 InstrumentedDOM() : m_instrumentedOther(adoptPtr(new InstrumentedOther)) { } 187 188 void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 189 { 190 MemoryClassInfo<InstrumentedDOM> info(memoryObjectInfo, this, MemoryInstrumentation::DOM); 191 info.addInstrumentedMember(m_instrumentedOther); 192 } 193 OwnPtr<InstrumentedOther> m_instrumentedOther; 194 }; 195 196 TEST(MemoryInstrumentationTest, ownerTypePropagation) 197 { 198 VisitedObjects visitedObjects; 199 MemoryInstrumentationImpl impl(visitedObjects); 200 OwnPtr<InstrumentedDOM> instrumentedDOM(adoptPtr(new InstrumentedDOM)); 201 impl.addRootObject(instrumentedDOM); 202 EXPECT_EQ(sizeof(InstrumentedDOM) + sizeof(InstrumentedOther), impl.reportedSizeForAllTypes()); 203 EXPECT_EQ(sizeof(InstrumentedDOM) + sizeof(InstrumentedOther), impl.totalSize(MemoryInstrumentation::DOM)); 204 EXPECT_EQ(2, visitedObjects.size()); 205 } 206 207 class NonVirtualInstrumented { 208 public: 209 void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 210 { 211 MemoryClassInfo<NonVirtualInstrumented> info(memoryObjectInfo, this, MemoryInstrumentation::DOM); 212 info.addInstrumentedMember(m_instrumented); 213 } 214 215 Instrumented m_instrumented; 216 }; 217 218 TEST(MemoryInstrumentationTest, visitFirstMemberInNonVirtualClass) 219 { 220 VisitedObjects visitedObjects; 221 MemoryInstrumentationImpl impl(visitedObjects); 222 NonVirtualInstrumented nonVirtualInstrumented; 223 impl.addRootObject(&nonVirtualInstrumented); 224 EXPECT_EQ(sizeof(NonVirtualInstrumented) + sizeof(NotInstrumented), impl.reportedSizeForAllTypes()); 225 EXPECT_EQ(2, visitedObjects.size()); 171 226 } 172 227
Note: See TracChangeset
for help on using the changeset viewer.