Changeset 219460 in webkit
- Timestamp:
- Jul 13, 2017, 12:16:54 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 13 edited
-
ChangeLog (modified) (1 diff)
-
Modules/webaudio/AudioBuffer.cpp (modified) (3 diffs)
-
Modules/webaudio/AudioBuffer.h (modified) (3 diffs)
-
dom/ChildNodeList.h (modified) (2 diffs)
-
dom/CollectionIndexCache.h (modified) (2 diffs)
-
dom/LiveNodeList.h (modified) (2 diffs)
-
html/CachedHTMLCollection.h (modified) (2 diffs)
-
html/HTMLCanvasElement.cpp (modified) (4 diffs)
-
html/HTMLCanvasElement.h (modified) (2 diffs)
-
html/HTMLCollection.cpp (modified) (2 diffs)
-
html/HTMLCollection.h (modified) (5 diffs)
-
platform/graphics/ImageBuffer.cpp (modified) (2 diffs)
-
platform/graphics/cg/ImageBufferCG.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r219459 r219460 1 2017-07-13 Mark Lam <mark.lam@apple.com> 2 3 Implementors of memoryCost() need to be thread-safe. 4 https://bugs.webkit.org/show_bug.cgi?id=172738 5 <rdar://problem/32474881> 6 7 Reviewed by Keith Miller. 8 9 No new tests. This patch fixes a race condition bug that can result in random 10 crashes (and other unpredictable behavior), and is very difficult to test for. 11 12 * Modules/webaudio/AudioBuffer.cpp: 13 (WebCore::AudioBuffer::releaseMemory): 14 (WebCore::AudioBuffer::memoryCost): 15 * Modules/webaudio/AudioBuffer.h: 16 * dom/ChildNodeList.h: 17 * dom/CollectionIndexCache.h: 18 (WebCore::CollectionIndexCache::memoryCost): 19 * dom/LiveNodeList.h: 20 * html/CachedHTMLCollection.h: 21 * html/HTMLCanvasElement.cpp: 22 (WebCore::HTMLCanvasElement::memoryCost): 23 (WebCore::HTMLCanvasElement::externalMemoryCost): 24 (WebCore::HTMLCanvasElement::setImageBuffer): 25 * html/HTMLCanvasElement.h: 26 * html/HTMLCollection.cpp: 27 (WebCore::HTMLCollection::invalidateNamedElementCache): 28 * html/HTMLCollection.h: 29 (WebCore::CollectionNamedElementCache::memoryCost): 30 (WebCore::HTMLCollection::memoryCost): 31 (WebCore::HTMLCollection::setNamedItemCache): 32 * platform/graphics/ImageBuffer.cpp: 33 (WebCore::ImageBuffer::memoryCost): 34 * platform/graphics/cg/ImageBufferCG.cpp: 35 (WebCore::ImageBuffer::memoryCost): 36 (WebCore::ImageBuffer::externalMemoryCost): 37 1 38 2017-07-13 Jeremy Jones <jeremyj@apple.com> 2 39 -
trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp
r214618 r219460 1 1 /* 2 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 106 107 void AudioBuffer::releaseMemory() 107 108 { 109 auto locker = holdLock(m_channelsLock); 108 110 m_channels.clear(); 109 111 } … … 134 136 size_t AudioBuffer::memoryCost() const 135 137 { 138 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful 139 // about what data we access here and how. We need to hold a lock to prevent m_channels 140 // from being changed while we iterate it, but calling channel->byteLength() is safe 141 // because it doesn't involve chasing any pointers that can be nullified while the 142 // AudioBuffer is alive. 143 auto locker = holdLock(m_channelsLock); 136 144 size_t cost = 0; 137 145 for (auto& channel : m_channels) -
trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h
r214618 r219460 1 1 /* 2 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 31 32 #include "ExceptionOr.h" 32 33 #include <runtime/Float32Array.h> 34 #include <wtf/Lock.h> 33 35 #include <wtf/Vector.h> 34 36 … … 74 76 double m_gain { 1.0 }; // scalar gain 75 77 float m_sampleRate; 78 mutable Lock m_channelsLock; 76 79 size_t m_length; 77 80 Vector<RefPtr<Float32Array>> m_channels; -
trunk/Source/WebCore/dom/ChildNodeList.h
r208179 r219460 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2004 , 2007, 2013Apple Inc. All rights reserved.5 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 81 81 unsigned length() const override; 82 82 Node* item(unsigned index) const override; 83 size_t memoryCost() const override { return m_indexCache.memoryCost(); } 83 size_t memoryCost() const override 84 { 85 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful 86 // about what data we access here and how. Accessing m_indexCache is safe because 87 // because it doesn't involve any pointer chasing. 88 return m_indexCache.memoryCost(); 89 } 84 90 85 91 bool isChildNodeList() const override { return true; } -
trunk/Source/WebCore/dom/CollectionIndexCache.h
r204717 r219460 1 1 /* 2 * Copyright (C) 2013-201 6Apple Inc. All rights reserved.2 * Copyright (C) 2013-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 44 44 bool hasValidCache(const Collection& collection) const { return m_current != collection.collectionEnd() || m_nodeCountValid || m_listValid; } 45 45 void invalidate(const Collection&); 46 size_t memoryCost() { return m_cachedList.capacity() * sizeof(NodeType*); } 46 size_t memoryCost() 47 { 48 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful 49 // about what data we access here and how. Accessing m_cachedList.capacity() is safe 50 // because it doesn't involve any pointer chasing. 51 return m_cachedList.capacity() * sizeof(NodeType*); 52 } 47 53 48 54 private: -
trunk/Source/WebCore/dom/LiveNodeList.h
r218593 r219460 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2004 , 2006-2007, 2013-2014Apple Inc. All rights reserved.5 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 91 91 92 92 void invalidateCacheForDocument(Document&) const final; 93 size_t memoryCost() const final { return m_indexCache.memoryCost(); } 93 size_t memoryCost() const final 94 { 95 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful 96 // about what data we access here and how. Accessing m_indexCache is safe because 97 // because it doesn't involve any pointer chasing. 98 return m_indexCache.memoryCost(); 99 } 94 100 95 101 protected: -
trunk/Source/WebCore/html/CachedHTMLCollection.h
r216851 r219460 1 1 /* 2 * Copyright (C) 2015 Apple Inc. All rights reserved.2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 42 42 Element* item(unsigned offset) const override { return m_indexCache.nodeAt(collection(), offset); } 43 43 Element* namedItem(const AtomicString& name) const override; 44 size_t memoryCost() const final { return m_indexCache.memoryCost() + HTMLCollection::memoryCost(); } 44 size_t memoryCost() const final 45 { 46 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 47 // Accessing m_indexCache.memoryCost() is safe because because it doesn't involve any pointer chasing. 48 // HTMLCollection::memoryCost() ensures its own thread safety. 49 return m_indexCache.memoryCost() + HTMLCollection::memoryCost(); 50 } 45 51 46 52 // For CollectionIndexCache; do not use elsewhere. -
trunk/Source/WebCore/html/HTMLCanvasElement.cpp
r219268 r219460 1 1 /* 2 * Copyright (C) 2004 , 2006, 2007,2017 Apple Inc. All rights reserved.2 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. … … 678 678 size_t HTMLCanvasElement::memoryCost() const 679 679 { 680 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful 681 // about what data we access here and how. We need to hold a lock to prevent m_imageBuffer 682 // from being changed while we access it. 683 auto locker = holdLock(m_imageBufferAssignmentLock); 680 684 if (!m_imageBuffer) 681 685 return 0; … … 685 689 size_t HTMLCanvasElement::externalMemoryCost() const 686 690 { 691 // externalMemoryCost() may be invoked concurrently from a GC thread, and we need to be careful 692 // about what data we access here and how. We need to hold a lock to prevent m_imageBuffer 693 // from being changed while we access it. 694 auto locker = holdLock(m_imageBufferAssignmentLock); 687 695 if (!m_imageBuffer) 688 696 return 0; … … 784 792 removeFromActivePixelMemory(previousMemoryCost); 785 793 786 m_imageBuffer = WTFMove(buffer); 794 { 795 auto locker = holdLock(m_imageBufferAssignmentLock); 796 m_imageBuffer = WTFMove(buffer); 797 } 787 798 788 799 size_t currentMemoryCost = memoryCost(); -
trunk/Source/WebCore/html/HTMLCanvasElement.h
r219268 r219460 1 1 /* 2 * Copyright (C) 2004 , 2006, 2009, 2010,2017 Apple Inc. All rights reserved.2 * Copyright (C) 2004-2017 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. … … 191 191 bool m_tracksDisplayListReplay { false }; 192 192 193 mutable Lock m_imageBufferAssignmentLock; 194 193 195 // m_createdImageBuffer means we tried to malloc the buffer. We didn't necessarily get it. 194 196 mutable bool m_hasCreatedImageBuffer { false }; -
trunk/Source/WebCore/html/HTMLCollection.cpp
r217773 r219460 2 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * Copyright (C) 2003 , 2004, 2005, 2006, 2007, 2008, 2011, 2012Apple Inc. All rights reserved.4 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 149 149 ASSERT(hasNamedElementCache()); 150 150 document.collectionWillClearIdNameMap(*this); 151 m_namedElementCache = nullptr; 151 { 152 auto locker = holdLock(m_namedElementCacheAssignmentLock); 153 m_namedElementCache = nullptr; 154 } 152 155 } 153 156 -
trunk/Source/WebCore/html/HTMLCollection.h
r218748 r219460 2 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * Copyright (C) 2003 , 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2013, 2014Apple Inc. All rights reserved.4 * Copyright (C) 2003-2017 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 105 105 106 106 mutable std::unique_ptr<CollectionNamedElementCache> m_namedElementCache; 107 107 mutable Lock m_namedElementCacheAssignmentLock; 108 108 109 const unsigned m_collectionType : 5; 109 110 const unsigned m_invalidationType : 4; … … 141 142 inline size_t CollectionNamedElementCache::memoryCost() const 142 143 { 144 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 145 // It is safe to access m_idMap.size(), m_nameMap.size(), and m_propertyNames.size() because they don't chase pointers. 143 146 return (m_idMap.size() + m_nameMap.size()) * sizeof(Element*) + m_propertyNames.size() * sizeof(AtomicString); 144 147 } … … 169 172 inline size_t HTMLCollection::memoryCost() const 170 173 { 174 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 175 // Hence, we need to guard m_namedElementCache from being replaced while accessing it. 176 auto locker = holdLock(m_namedElementCacheAssignmentLock); 171 177 return m_namedElementCache ? m_namedElementCache->memoryCost() : 0; 172 178 } … … 215 221 ASSERT(!m_namedElementCache); 216 222 cache->didPopulate(); 217 m_namedElementCache = WTFMove(cache); 223 { 224 auto locker = holdLock(m_namedElementCacheAssignmentLock); 225 m_namedElementCache = WTFMove(cache); 226 } 218 227 document().collectionCachedIdNameMap(*this); 219 228 } -
trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp
r213598 r219460 2 2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 * Copyright (C) 2016 Apple Inc. All rights reserved.4 * Copyright (C) 2016-2017 Apple Inc. All rights reserved. 5 5 * 6 6 * Redistribution and use in source and binary forms, with or without … … 234 234 size_t ImageBuffer::memoryCost() const 235 235 { 236 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 237 // It's safe to access internalSize() because it doesn't do any pointer chasing. 236 238 return 4 * internalSize().width() * internalSize().height(); 237 239 } -
trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r215069 r219460 1 1 /* 2 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2008 , 2015Apple Inc. All rights reserved.3 * Copyright (C) 2008-2017 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 5 5 * … … 213 213 size_t ImageBuffer::memoryCost() const 214 214 { 215 // memoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 216 // It's safe to access internalSize() because it doesn't do any pointer chasing. 217 // It's safe to access m_data.surface because the surface can only be assigned during construction of this ImageBuffer. 218 // It's safe to access m_data.surface->totalBytes() because totalBytes() doesn't chase pointers. 215 219 if (m_data.surface) 216 220 return m_data.surface->totalBytes(); … … 220 224 size_t ImageBuffer::externalMemoryCost() const 221 225 { 226 // externalMemoryCost() may be invoked concurrently from a GC thread, and we need to be careful about what data we access here and how. 227 // It's safe to access m_data.surface because the surface can only be assigned during construction of this ImageBuffer. 228 // It's safe to access m_data.surface->totalBytes() because totalBytes() doesn't chase pointers. 222 229 if (m_data.surface) 223 230 return m_data.surface->totalBytes();
Note:
See TracChangeset
for help on using the changeset viewer.