WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
the patch
blah.patch (text/plain), 19.55 KB, created by
Filip Pizlo
on 2013-08-31 21:14:44 PDT
(
hide
)
Description:
the patch
Filename:
MIME Type:
Creator:
Filip Pizlo
Created:
2013-08-31 21:14:44 PDT
Size:
19.55 KB
patch
obsolete
>Index: Source/JavaScriptCore/ChangeLog >=================================================================== >--- Source/JavaScriptCore/ChangeLog (revision 154935) >+++ Source/JavaScriptCore/ChangeLog (working copy) >@@ -1,3 +1,13 @@ >+2013-08-31 Filip Pizlo <fpizlo@apple.com> >+ >+ DeferredRefCounted should have a thread-safe mode >+ https://bugs.webkit.org/show_bug.cgi?id=120568 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * heap/GCIncomingRefCounted.h: Turn off thread-safety because it causes perf regression. >+ * heap/MarkedBlock.h: Switch to using the AtomicMode enum. >+ > 2013-08-30 Filip Pizlo <fpizlo@apple.com> > > CodeBlock refactoring broke profile dumping >Index: Source/JavaScriptCore/heap/GCIncomingRefCounted.h >=================================================================== >--- Source/JavaScriptCore/heap/GCIncomingRefCounted.h (revision 154933) >+++ Source/JavaScriptCore/heap/GCIncomingRefCounted.h (working copy) >@@ -40,7 +40,7 @@ class JSCell; > // heap. > > template<typename T> >-class GCIncomingRefCounted : public DeferrableRefCounted<T> { >+class GCIncomingRefCounted : public DeferrableRefCounted<WTF::ModeNotAtomic, T> { > public: > GCIncomingRefCounted() > : m_encodedPointer(0) >Index: Source/JavaScriptCore/heap/MarkedBlock.h >=================================================================== >--- Source/JavaScriptCore/heap/MarkedBlock.h (revision 154933) >+++ Source/JavaScriptCore/heap/MarkedBlock.h (working copy) >@@ -178,9 +178,9 @@ namespace JSC { > size_t m_atomsPerCell; > size_t m_endAtom; // This is a fuzzy end. Always test for < m_endAtom. > #if ENABLE(PARALLEL_GC) >- WTF::Bitmap<atomsPerBlock, WTF::BitmapAtomic> m_marks; >+ WTF::Bitmap<atomsPerBlock, WTF::ModeAtomic> m_marks; > #else >- WTF::Bitmap<atomsPerBlock, WTF::BitmapNotAtomic> m_marks; >+ WTF::Bitmap<atomsPerBlock, WTF::ModeNotAtomic> m_marks; > #endif > OwnPtr<WTF::Bitmap<atomsPerBlock> > m_newlyAllocated; > >Index: Source/WTF/ChangeLog >=================================================================== >--- Source/WTF/ChangeLog (revision 154935) >+++ Source/WTF/ChangeLog (working copy) >@@ -1,3 +1,34 @@ >+2013-08-31 Filip Pizlo <fpizlo@apple.com> >+ >+ DeferredRefCounted should have a thread-safe mode >+ https://bugs.webkit.org/show_bug.cgi?id=120568 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This makes the class more general by allowing it to be thread-safe. This >+ mode is currently not yet used by the clients of this class, since those >+ clients appear to suffer just enough ref-count churn in some of the >+ JSRegress tests that you do see a performance effect. >+ >+ There was also already another class that was templatized according to >+ thread-safety so I added a new enum to unify how this works. >+ >+ * GNUmakefile.list.am: >+ * WTF.pro: >+ * WTF.vcxproj/WTF.vcxproj: >+ * WTF.xcodeproj/project.pbxproj: >+ * wtf/AtomicMode.h: Added. >+ * wtf/Bitmap.h: >+ (WTF::::concurrentTestAndSet): >+ (WTF::::concurrentTestAndClear): >+ * wtf/CMakeLists.txt: >+ * wtf/DeferrableRefCounted.h: >+ (WTF::DeferrableRefCountedBase::ref): >+ (WTF::DeferrableRefCountedBase::derefBase): >+ (WTF::DeferrableRefCountedBase::setIsDeferredBase): >+ (WTF::DeferrableRefCounted::deref): >+ (WTF::DeferrableRefCounted::setIsDeferred): >+ > 2013-08-30 Oliver Hunt <oliver@apple.com> > > Make JSValue bool conversion less dangerous >Index: Source/WTF/GNUmakefile.list.am >=================================================================== >--- Source/WTF/GNUmakefile.list.am (revision 154933) >+++ Source/WTF/GNUmakefile.list.am (working copy) >@@ -6,6 +6,7 @@ wtf_sources += \ > Source/WTF/wtf/Alignment.h \ > Source/WTF/wtf/Assertions.cpp \ > Source/WTF/wtf/Assertions.h \ >+ Source/WTF/wtf/AtomicMode.h \ > Source/WTF/wtf/Atomics.cpp \ > Source/WTF/wtf/Atomics.h \ > Source/WTF/wtf/AutodrainedPool.h \ >Index: Source/WTF/WTF.pro >=================================================================== >--- Source/WTF/WTF.pro (revision 154933) >+++ Source/WTF/WTF.pro (working copy) >@@ -23,6 +23,7 @@ HEADERS += \ > Alignment.h \ > ASCIICType.h \ > Assertions.h \ >+ AtomicMode.h \ > Atomics.h \ > AVLTree.h \ > Bitmap.h \ >Index: Source/WTF/WTF.vcxproj/WTF.vcxproj >=================================================================== >--- Source/WTF/WTF.vcxproj/WTF.vcxproj (revision 154933) >+++ Source/WTF/WTF.vcxproj/WTF.vcxproj (working copy) >@@ -123,6 +123,7 @@ > <ClInclude Include="..\wtf\Alignment.h" /> > <ClInclude Include="..\wtf\ASCIICType.h" /> > <ClInclude Include="..\wtf\Assertions.h" /> >+ <ClInclude Include="..\wtf\AtomicMode.h" /> > <ClInclude Include="..\wtf\Atomics.h" /> > <ClInclude Include="..\wtf\AutodrainedPool.h" /> > <ClInclude Include="..\wtf\AVLTree.h" /> >Index: Source/WTF/WTF.xcodeproj/project.pbxproj >=================================================================== >--- Source/WTF/WTF.xcodeproj/project.pbxproj (revision 154933) >+++ Source/WTF/WTF.xcodeproj/project.pbxproj (working copy) >@@ -35,6 +35,7 @@ > 0FC4488316FE9FE100844BE9 /* ProcessID.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4488216FE9FE100844BE9 /* ProcessID.h */; }; > 0FC4EDE61696149600F65041 /* CommaPrinter.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4EDE51696149600F65041 /* CommaPrinter.h */; }; > 0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AC4154FB22E00983E72 /* FastBitVector.h */; settings = {ATTRIBUTES = (); }; }; >+ 0FD8A31017D2F4C100CA2C40 /* AtomicMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */; }; > 0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */; }; > 0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */; }; > 143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; }; >@@ -299,6 +300,7 @@ > 0FC4488216FE9FE100844BE9 /* ProcessID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessID.h; sourceTree = "<group>"; }; > 0FC4EDE51696149600F65041 /* CommaPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommaPrinter.h; sourceTree = "<group>"; }; > 0FD81AC4154FB22E00983E72 /* FastBitVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastBitVector.h; sourceTree = "<group>"; }; >+ 0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicMode.h; sourceTree = "<group>"; }; > 0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringPrintStream.cpp; sourceTree = "<group>"; }; > 0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrintStream.h; sourceTree = "<group>"; }; > 0FEC3EE4171B834700FDAC8D /* ByteSpinLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteSpinLock.h; sourceTree = "<group>"; }; >@@ -621,6 +623,7 @@ > A8A4725A151A825A004123FF /* ASCIICType.h */, > A8A4725B151A825A004123FF /* Assertions.cpp */, > A8A4725C151A825A004123FF /* Assertions.h */, >+ 0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */, > A8A4725D151A825A004123FF /* Atomics.h */, > 1469419A16EAB10A0024E146 /* AutodrainedPool.h */, > 1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */, >@@ -1025,6 +1028,7 @@ > A8A473FB151A825B004123FF /* OwnArrayPtr.h in Headers */, > A8A473FC151A825B004123FF /* OwnPtr.h in Headers */, > A8A473FD151A825B004123FF /* OwnPtrCommon.h in Headers */, >+ 0FD8A31017D2F4C100CA2C40 /* AtomicMode.h in Headers */, > A8A473FE151A825B004123FF /* PackedIntVector.h in Headers */, > A8A473FF151A825B004123FF /* PageAllocation.h in Headers */, > A8A47401151A825B004123FF /* PageAllocationAligned.h in Headers */, >Index: Source/WTF/wtf/AtomicMode.h >=================================================================== >--- Source/WTF/wtf/AtomicMode.h (revision 0) >+++ Source/WTF/wtf/AtomicMode.h (working copy) >@@ -0,0 +1,47 @@ >+/* >+ * Copyright (C) 2013 Apple 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: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. 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. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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. >+ */ >+ >+#ifndef AtomicMode_h >+#define AtomicMode_h >+ >+namespace WTF { >+ >+// This is useful for templatizing data structures that could either be atomic >+// or not. >+enum AtomicMode { >+ // Assume that thread-safety is ensured through other means, like that the >+ // object is thread-local. >+ ModeNotAtomic, >+ >+ // The data structure must ensure that it is well-behaved when used by >+ // multiple threads. It's up to the data structure to decide what that >+ // means. >+ ModeAtomic >+}; >+ >+} // namespace WTF >+ >+#endif // AtomicMode_h >+ >Index: Source/WTF/wtf/Bitmap.h >=================================================================== >--- Source/WTF/wtf/Bitmap.h (revision 154933) >+++ Source/WTF/wtf/Bitmap.h (working copy) >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2010 Apple Inc. All rights reserved. >+ * Copyright (C) 2010, 2013 Apple Inc. All rights reserved. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public >@@ -19,6 +19,7 @@ > #ifndef Bitmap_h > #define Bitmap_h > >+#include <wtf/AtomicMode.h> > #include <wtf/Atomics.h> > #include <wtf/FixedArray.h> > #include <wtf/StdLibExtras.h> >@@ -27,16 +28,7 @@ > > namespace WTF { > >-enum BitmapAtomicMode { >- // This makes concurrentTestAndSet behave just like testAndSet. >- BitmapNotAtomic, >- >- // This makes concurrentTestAndSet use compareAndSwap, so that it's >- // atomic even when used concurrently. >- BitmapAtomic >-}; >- >-template<size_t size, BitmapAtomicMode atomicMode = BitmapNotAtomic> >+template<size_t size, AtomicMode atomicMode = ModeNotAtomic> > class Bitmap { > private: > typedef uint32_t WordType; >@@ -72,25 +64,25 @@ private: > FixedArray<WordType, words> bits; > }; > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline Bitmap<size, atomicMode>::Bitmap() > { > clearAll(); > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline bool Bitmap<size, atomicMode>::get(size_t n) const > { > return !!(bits[n / wordSize] & (one << (n % wordSize))); > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline void Bitmap<size, atomicMode>::set(size_t n) > { > bits[n / wordSize] |= (one << (n % wordSize)); > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline bool Bitmap<size, atomicMode>::testAndSet(size_t n) > { > WordType mask = one << (n % wordSize); >@@ -100,7 +92,7 @@ inline bool Bitmap<size, atomicMode>::te > return result; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline bool Bitmap<size, atomicMode>::testAndClear(size_t n) > { > WordType mask = one << (n % wordSize); >@@ -110,13 +102,13 @@ inline bool Bitmap<size, atomicMode>::te > return result; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline bool Bitmap<size, atomicMode>::concurrentTestAndSet(size_t n) > { >- if (atomicMode == BitmapNotAtomic) >+ if (atomicMode == ModeNotAtomic) > return testAndSet(n); > >- ASSERT(atomicMode == BitmapAtomic); >+ ASSERT(atomicMode == ModeAtomic); > > WordType mask = one << (n % wordSize); > size_t index = n / wordSize; >@@ -130,13 +122,13 @@ inline bool Bitmap<size, atomicMode>::co > return false; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline bool Bitmap<size, atomicMode>::concurrentTestAndClear(size_t n) > { >- if (atomicMode == BitmapNotAtomic) >+ if (atomicMode == ModeNotAtomic) > return testAndClear(n); > >- ASSERT(atomicMode == BitmapAtomic); >+ ASSERT(atomicMode == ModeAtomic); > > WordType mask = one << (n % wordSize); > size_t index = n / wordSize; >@@ -150,19 +142,19 @@ inline bool Bitmap<size, atomicMode>::co > return true; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline void Bitmap<size, atomicMode>::clear(size_t n) > { > bits[n / wordSize] &= ~(one << (n % wordSize)); > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline void Bitmap<size, atomicMode>::clearAll() > { > memset(bits.data(), 0, sizeof(bits)); > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline size_t Bitmap<size, atomicMode>::nextPossiblyUnset(size_t start) const > { > if (!~bits[start / wordSize]) >@@ -170,7 +162,7 @@ inline size_t Bitmap<size, atomicMode>:: > return start + 1; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline int64_t Bitmap<size, atomicMode>::findRunOfZeros(size_t runLength) const > { > if (!runLength) >@@ -190,7 +182,7 @@ inline int64_t Bitmap<size, atomicMode>: > return -1; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline size_t Bitmap<size, atomicMode>::count(size_t start) const > { > size_t result = 0; >@@ -203,7 +195,7 @@ inline size_t Bitmap<size, atomicMode>:: > return result; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline size_t Bitmap<size, atomicMode>::isEmpty() const > { > for (size_t i = 0; i < words; ++i) >@@ -212,7 +204,7 @@ inline size_t Bitmap<size, atomicMode>:: > return true; > } > >-template<size_t size, BitmapAtomicMode atomicMode> >+template<size_t size, AtomicMode atomicMode> > inline size_t Bitmap<size, atomicMode>::isFull() const > { > for (size_t i = 0; i < words; ++i) >Index: Source/WTF/wtf/CMakeLists.txt >=================================================================== >--- Source/WTF/wtf/CMakeLists.txt (revision 154933) >+++ Source/WTF/wtf/CMakeLists.txt (working copy) >@@ -3,6 +3,7 @@ set(WTF_HEADERS > AVLTree.h > Alignment.h > Assertions.h >+ AtomicMode.h > Atomics.h > BitArray.h > BitVector.h >Index: Source/WTF/wtf/DeferrableRefCounted.h >=================================================================== >--- Source/WTF/wtf/DeferrableRefCounted.h (revision 154933) >+++ Source/WTF/wtf/DeferrableRefCounted.h (working copy) >@@ -27,8 +27,11 @@ > #define DeferrableRefCounted_h > > #include <wtf/Assertions.h> >+#include <wtf/AtomicMode.h> >+#include <wtf/Atomics.h> > #include <wtf/FastAllocBase.h> > #include <wtf/Noncopyable.h> >+#include <wtf/ThreadingPrimitives.h> > > namespace WTF { > >@@ -38,6 +41,7 @@ namespace WTF { > // specifically happened - this can be useful either for debugging, or > // sometimes even for some additional functionality. > >+template<AtomicMode atomicMode> > class DeferrableRefCountedBase { > static const unsigned deferredFlag = 1; > static const unsigned normalIncrement = 2; >@@ -45,7 +49,19 @@ class DeferrableRefCountedBase { > public: > void ref() > { >+ if (atomicMode == ModeNotAtomic) { >+ m_refCount += normalIncrement; >+ return; >+ } >+#if ENABLE(COMPARE_AND_SWAP) >+ unsigned oldValue; >+ do { >+ oldValue = m_refCount; >+ } while (!weakCompareAndSwap(&m_refCount, oldValue, oldValue + normalIncrement)); >+#else // ENABLE(COMPARE_AND_SWAP) >+ MutexLocker locker(m_lock); > m_refCount += normalIncrement; >+#endif // ENABLE(COMPARE_AND_SWAP) > } > > bool hasOneRef() const >@@ -75,37 +91,82 @@ protected: > > bool derefBase() > { >+ if (atomicMode == ModeNotAtomic) { >+ m_refCount -= normalIncrement; >+ return !m_refCount; >+ } >+#if ENABLE(COMPARE_AND_SWAP) >+ unsigned oldValue; >+ unsigned newValue; >+ do { >+ oldValue = m_refCount; >+ newValue = oldValue - normalIncrement; >+ } while (!weakCompareAndSwap(&m_refCount, oldValue, newValue)); >+ return !newValue; >+#else // ENABLE(COMPARE_AND_SWAP) >+ MutexLocker locker(m_lock); > m_refCount -= normalIncrement; > return !m_refCount; >+#endif // ENABLE(COMPARE_AND_SWAP) > } > > bool setIsDeferredBase(bool value) > { >+ if (atomicMode == ModeNotAtomic) { >+ if (value) { >+ m_refCount |= deferredFlag; >+ return false; >+ } >+ m_refCount &= ~deferredFlag; >+ return !m_refCount; >+ } >+#if ENABLE(COMPARE_AND_SWAP) >+ unsigned oldValue; >+ unsigned newValue; >+ bool result; >+ do { >+ oldValue = m_refCount; >+ if (value) { >+ newValue = oldValue | deferredFlag; >+ result = false; >+ } else { >+ newValue = oldValue & ~deferredFlag; >+ result = !newValue; >+ } >+ } while (!weakCompareAndSwap(&m_refCount, oldValue, newValue)); >+ return result; >+#else // ENABLE(COMPARE_AND_SWAP) >+ MutexLocker locker(m_lock); > if (value) { > m_refCount |= deferredFlag; > return false; > } > m_refCount &= ~deferredFlag; > return !m_refCount; >+#endif // ENABLE(COMPARE_AND_SWAP) > } > > private: > unsigned m_refCount; >+ >+#if !ENABLE(COMPARE_AND_SWAP) >+ Mutex m_lock; >+#endif // !ENABLE(COMPARE_AND_SWAP) > }; > >-template<typename T> >-class DeferrableRefCounted : public DeferrableRefCountedBase { >+template<AtomicMode atomicMode, typename T> >+class DeferrableRefCounted : public DeferrableRefCountedBase<atomicMode> { > WTF_MAKE_NONCOPYABLE(DeferrableRefCounted); WTF_MAKE_FAST_ALLOCATED; > public: > void deref() > { >- if (derefBase()) >+ if (this->derefBase()) > delete static_cast<T*>(this); > } > > bool setIsDeferred(bool value) > { >- if (!setIsDeferredBase(value)) >+ if (!this->setIsDeferredBase(value)) > return false; > delete static_cast<T*>(this); > return true;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 120568
:
210221
| 210223