| Differences between
and this patch
- Source/JavaScriptCore/ChangeLog +10 lines
Lines 1-3 Source/JavaScriptCore/ChangeLog_sec1
1
2013-08-31  Filip Pizlo  <fpizlo@apple.com>
2
3
        DeferredRefCounted should have a thread-safe mode
4
        https://bugs.webkit.org/show_bug.cgi?id=120568
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * heap/GCIncomingRefCounted.h: Turn off thread-safety because it causes perf regression.
9
        * heap/MarkedBlock.h: Switch to using the AtomicMode enum.
10
1
2013-08-30  Filip Pizlo  <fpizlo@apple.com>
11
2013-08-30  Filip Pizlo  <fpizlo@apple.com>
2
12
3
        CodeBlock refactoring broke profile dumping
13
        CodeBlock refactoring broke profile dumping
- Source/JavaScriptCore/heap/GCIncomingRefCounted.h -1 / +1 lines
Lines 40-46 class JSCell; Source/JavaScriptCore/heap/GCIncomingRefCounted.h_sec1
40
// heap.
40
// heap.
41
41
42
template<typename T>
42
template<typename T>
43
class GCIncomingRefCounted : public DeferrableRefCounted<T> {
43
class GCIncomingRefCounted : public DeferrableRefCounted<WTF::ModeNotAtomic, T> {
44
public:
44
public:
45
    GCIncomingRefCounted()
45
    GCIncomingRefCounted()
46
        : m_encodedPointer(0)
46
        : m_encodedPointer(0)
- Source/JavaScriptCore/heap/MarkedBlock.h -2 / +2 lines
Lines 178-186 namespace JSC { Source/JavaScriptCore/heap/MarkedBlock.h_sec1
178
        size_t m_atomsPerCell;
178
        size_t m_atomsPerCell;
179
        size_t m_endAtom; // This is a fuzzy end. Always test for < m_endAtom.
179
        size_t m_endAtom; // This is a fuzzy end. Always test for < m_endAtom.
180
#if ENABLE(PARALLEL_GC)
180
#if ENABLE(PARALLEL_GC)
181
        WTF::Bitmap<atomsPerBlock, WTF::BitmapAtomic> m_marks;
181
        WTF::Bitmap<atomsPerBlock, WTF::ModeAtomic> m_marks;
182
#else
182
#else
183
        WTF::Bitmap<atomsPerBlock, WTF::BitmapNotAtomic> m_marks;
183
        WTF::Bitmap<atomsPerBlock, WTF::ModeNotAtomic> m_marks;
184
#endif
184
#endif
185
        OwnPtr<WTF::Bitmap<atomsPerBlock> > m_newlyAllocated;
185
        OwnPtr<WTF::Bitmap<atomsPerBlock> > m_newlyAllocated;
186
186
- Source/WTF/ChangeLog +31 lines
Lines 1-3 Source/WTF/ChangeLog_sec1
1
2013-08-31  Filip Pizlo  <fpizlo@apple.com>
2
3
        DeferredRefCounted should have a thread-safe mode
4
        https://bugs.webkit.org/show_bug.cgi?id=120568
5
6
        Reviewed by NOBODY (OOPS!).
7
        
8
        This makes the class more general by allowing it to be thread-safe. This
9
        mode is currently not yet used by the clients of this class, since those
10
        clients appear to suffer just enough ref-count churn in some of the
11
        JSRegress tests that you do see a performance effect.
12
        
13
        There was also already another class that was templatized according to
14
        thread-safety so I added a new enum to unify how this works.
15
16
        * GNUmakefile.list.am:
17
        * WTF.pro:
18
        * WTF.vcxproj/WTF.vcxproj:
19
        * WTF.xcodeproj/project.pbxproj:
20
        * wtf/AtomicMode.h: Added.
21
        * wtf/Bitmap.h:
22
        (WTF::::concurrentTestAndSet):
23
        (WTF::::concurrentTestAndClear):
24
        * wtf/CMakeLists.txt:
25
        * wtf/DeferrableRefCounted.h:
26
        (WTF::DeferrableRefCountedBase::ref):
27
        (WTF::DeferrableRefCountedBase::derefBase):
28
        (WTF::DeferrableRefCountedBase::setIsDeferredBase):
29
        (WTF::DeferrableRefCounted::deref):
30
        (WTF::DeferrableRefCounted::setIsDeferred):
31
1
2013-08-30  Oliver Hunt  <oliver@apple.com>
32
2013-08-30  Oliver Hunt  <oliver@apple.com>
2
33
3
        Make JSValue bool conversion less dangerous
34
        Make JSValue bool conversion less dangerous
- Source/WTF/GNUmakefile.list.am +1 lines
Lines 6-11 wtf_sources += \ Source/WTF/GNUmakefile.list.am_sec1
6
    Source/WTF/wtf/Alignment.h \
6
    Source/WTF/wtf/Alignment.h \
7
    Source/WTF/wtf/Assertions.cpp \
7
    Source/WTF/wtf/Assertions.cpp \
8
    Source/WTF/wtf/Assertions.h \
8
    Source/WTF/wtf/Assertions.h \
9
    Source/WTF/wtf/AtomicMode.h \
9
    Source/WTF/wtf/Atomics.cpp \
10
    Source/WTF/wtf/Atomics.cpp \
10
    Source/WTF/wtf/Atomics.h \
11
    Source/WTF/wtf/Atomics.h \
11
    Source/WTF/wtf/AutodrainedPool.h \
12
    Source/WTF/wtf/AutodrainedPool.h \
- Source/WTF/WTF.pro +1 lines
Lines 23-28 HEADERS += \ Source/WTF/WTF.pro_sec1
23
    Alignment.h \
23
    Alignment.h \
24
    ASCIICType.h \
24
    ASCIICType.h \
25
    Assertions.h \
25
    Assertions.h \
26
    AtomicMode.h \
26
    Atomics.h \
27
    Atomics.h \
27
    AVLTree.h \
28
    AVLTree.h \
28
    Bitmap.h \
29
    Bitmap.h \
- Source/WTF/WTF.vcxproj/WTF.vcxproj +1 lines
Lines 123-128 Source/WTF/WTF.vcxproj/WTF.vcxproj_sec1
123
    <ClInclude Include="..\wtf\Alignment.h" />
123
    <ClInclude Include="..\wtf\Alignment.h" />
124
    <ClInclude Include="..\wtf\ASCIICType.h" />
124
    <ClInclude Include="..\wtf\ASCIICType.h" />
125
    <ClInclude Include="..\wtf\Assertions.h" />
125
    <ClInclude Include="..\wtf\Assertions.h" />
126
    <ClInclude Include="..\wtf\AtomicMode.h" />
126
    <ClInclude Include="..\wtf\Atomics.h" />
127
    <ClInclude Include="..\wtf\Atomics.h" />
127
    <ClInclude Include="..\wtf\AutodrainedPool.h" />
128
    <ClInclude Include="..\wtf\AutodrainedPool.h" />
128
    <ClInclude Include="..\wtf\AVLTree.h" />
129
    <ClInclude Include="..\wtf\AVLTree.h" />
- Source/WTF/WTF.xcodeproj/project.pbxproj +4 lines
Lines 35-40 Source/WTF/WTF.xcodeproj/project.pbxproj_sec1
35
		0FC4488316FE9FE100844BE9 /* ProcessID.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4488216FE9FE100844BE9 /* ProcessID.h */; };
35
		0FC4488316FE9FE100844BE9 /* ProcessID.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4488216FE9FE100844BE9 /* ProcessID.h */; };
36
		0FC4EDE61696149600F65041 /* CommaPrinter.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4EDE51696149600F65041 /* CommaPrinter.h */; };
36
		0FC4EDE61696149600F65041 /* CommaPrinter.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FC4EDE51696149600F65041 /* CommaPrinter.h */; };
37
		0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AC4154FB22E00983E72 /* FastBitVector.h */; settings = {ATTRIBUTES = (); }; };
37
		0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AC4154FB22E00983E72 /* FastBitVector.h */; settings = {ATTRIBUTES = (); }; };
38
		0FD8A31017D2F4C100CA2C40 /* AtomicMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */; };
38
		0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */; };
39
		0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */; };
39
		0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */; };
40
		0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */; };
40
		143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; };
41
		143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; };
Lines 299-304 Source/WTF/WTF.xcodeproj/project.pbxproj_sec2
299
		0FC4488216FE9FE100844BE9 /* ProcessID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessID.h; sourceTree = "<group>"; };
300
		0FC4488216FE9FE100844BE9 /* ProcessID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessID.h; sourceTree = "<group>"; };
300
		0FC4EDE51696149600F65041 /* CommaPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommaPrinter.h; sourceTree = "<group>"; };
301
		0FC4EDE51696149600F65041 /* CommaPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommaPrinter.h; sourceTree = "<group>"; };
301
		0FD81AC4154FB22E00983E72 /* FastBitVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastBitVector.h; sourceTree = "<group>"; };
302
		0FD81AC4154FB22E00983E72 /* FastBitVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastBitVector.h; sourceTree = "<group>"; };
303
		0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicMode.h; sourceTree = "<group>"; };
302
		0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringPrintStream.cpp; sourceTree = "<group>"; };
304
		0FDDBFA51666DFA300C55FEF /* StringPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringPrintStream.cpp; sourceTree = "<group>"; };
303
		0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrintStream.h; sourceTree = "<group>"; };
305
		0FDDBFA61666DFA300C55FEF /* StringPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringPrintStream.h; sourceTree = "<group>"; };
304
		0FEC3EE4171B834700FDAC8D /* ByteSpinLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteSpinLock.h; sourceTree = "<group>"; };
306
		0FEC3EE4171B834700FDAC8D /* ByteSpinLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteSpinLock.h; sourceTree = "<group>"; };
Lines 621-626 Source/WTF/WTF.xcodeproj/project.pbxproj_sec3
621
				A8A4725A151A825A004123FF /* ASCIICType.h */,
623
				A8A4725A151A825A004123FF /* ASCIICType.h */,
622
				A8A4725B151A825A004123FF /* Assertions.cpp */,
624
				A8A4725B151A825A004123FF /* Assertions.cpp */,
623
				A8A4725C151A825A004123FF /* Assertions.h */,
625
				A8A4725C151A825A004123FF /* Assertions.h */,
626
				0FD8A30F17D2F4BE00CA2C40 /* AtomicMode.h */,
624
				A8A4725D151A825A004123FF /* Atomics.h */,
627
				A8A4725D151A825A004123FF /* Atomics.h */,
625
				1469419A16EAB10A0024E146 /* AutodrainedPool.h */,
628
				1469419A16EAB10A0024E146 /* AutodrainedPool.h */,
626
				1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */,
629
				1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */,
Lines 1025-1030 Source/WTF/WTF.xcodeproj/project.pbxproj_sec4
1025
				A8A473FB151A825B004123FF /* OwnArrayPtr.h in Headers */,
1028
				A8A473FB151A825B004123FF /* OwnArrayPtr.h in Headers */,
1026
				A8A473FC151A825B004123FF /* OwnPtr.h in Headers */,
1029
				A8A473FC151A825B004123FF /* OwnPtr.h in Headers */,
1027
				A8A473FD151A825B004123FF /* OwnPtrCommon.h in Headers */,
1030
				A8A473FD151A825B004123FF /* OwnPtrCommon.h in Headers */,
1031
				0FD8A31017D2F4C100CA2C40 /* AtomicMode.h in Headers */,
1028
				A8A473FE151A825B004123FF /* PackedIntVector.h in Headers */,
1032
				A8A473FE151A825B004123FF /* PackedIntVector.h in Headers */,
1029
				A8A473FF151A825B004123FF /* PageAllocation.h in Headers */,
1033
				A8A473FF151A825B004123FF /* PageAllocation.h in Headers */,
1030
				A8A47401151A825B004123FF /* PageAllocationAligned.h in Headers */,
1034
				A8A47401151A825B004123FF /* PageAllocationAligned.h in Headers */,
- Source/WTF/wtf/AtomicMode.h +47 lines
Line 0 Source/WTF/wtf/AtomicMode.h_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#ifndef AtomicMode_h
27
#define AtomicMode_h
28
29
namespace WTF {
30
31
// This is useful for templatizing data structures that could either be atomic
32
// or not.
33
enum AtomicMode {
34
    // Assume that thread-safety is ensured through other means, like that the
35
    // object is thread-local.
36
    ModeNotAtomic,
37
    
38
    // The data structure must ensure that it is well-behaved when used by
39
    // multiple threads. It's up to the data structure to decide what that
40
    // means.
41
    ModeAtomic
42
};
43
44
} // namespace WTF
45
46
#endif // AtomicMode_h
47
- Source/WTF/wtf/Bitmap.h -29 / +21 lines
Lines 1-5 Source/WTF/wtf/Bitmap.h_sec1
1
/*
1
/*
2
 *  Copyright (C) 2010 Apple Inc. All rights reserved.
2
 *  Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
3
 *
3
 *
4
 *  This library is free software; you can redistribute it and/or
4
 *  This library is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU Lesser General Public
5
 *  modify it under the terms of the GNU Lesser General Public
Lines 19-24 Source/WTF/wtf/Bitmap.h_sec2
19
#ifndef Bitmap_h
19
#ifndef Bitmap_h
20
#define Bitmap_h
20
#define Bitmap_h
21
21
22
#include <wtf/AtomicMode.h>
22
#include <wtf/Atomics.h>
23
#include <wtf/Atomics.h>
23
#include <wtf/FixedArray.h>
24
#include <wtf/FixedArray.h>
24
#include <wtf/StdLibExtras.h>
25
#include <wtf/StdLibExtras.h>
Lines 27-42 Source/WTF/wtf/Bitmap.h_sec3
27
28
28
namespace WTF {
29
namespace WTF {
29
30
30
enum BitmapAtomicMode {
31
template<size_t size, AtomicMode atomicMode = ModeNotAtomic>
31
    // This makes concurrentTestAndSet behave just like testAndSet.
32
    BitmapNotAtomic,
33
34
    // This makes concurrentTestAndSet use compareAndSwap, so that it's
35
    // atomic even when used concurrently.
36
    BitmapAtomic
37
};
38
39
template<size_t size, BitmapAtomicMode atomicMode = BitmapNotAtomic>
40
class Bitmap {
32
class Bitmap {
41
private:
33
private:
42
    typedef uint32_t WordType;
34
    typedef uint32_t WordType;
Lines 72-96 private: Source/WTF/wtf/Bitmap.h_sec4
72
    FixedArray<WordType, words> bits;
64
    FixedArray<WordType, words> bits;
73
};
65
};
74
66
75
template<size_t size, BitmapAtomicMode atomicMode>
67
template<size_t size, AtomicMode atomicMode>
76
inline Bitmap<size, atomicMode>::Bitmap()
68
inline Bitmap<size, atomicMode>::Bitmap()
77
{
69
{
78
    clearAll();
70
    clearAll();
79
}
71
}
80
72
81
template<size_t size, BitmapAtomicMode atomicMode>
73
template<size_t size, AtomicMode atomicMode>
82
inline bool Bitmap<size, atomicMode>::get(size_t n) const
74
inline bool Bitmap<size, atomicMode>::get(size_t n) const
83
{
75
{
84
    return !!(bits[n / wordSize] & (one << (n % wordSize)));
76
    return !!(bits[n / wordSize] & (one << (n % wordSize)));
85
}
77
}
86
78
87
template<size_t size, BitmapAtomicMode atomicMode>
79
template<size_t size, AtomicMode atomicMode>
88
inline void Bitmap<size, atomicMode>::set(size_t n)
80
inline void Bitmap<size, atomicMode>::set(size_t n)
89
{
81
{
90
    bits[n / wordSize] |= (one << (n % wordSize));
82
    bits[n / wordSize] |= (one << (n % wordSize));
91
}
83
}
92
84
93
template<size_t size, BitmapAtomicMode atomicMode>
85
template<size_t size, AtomicMode atomicMode>
94
inline bool Bitmap<size, atomicMode>::testAndSet(size_t n)
86
inline bool Bitmap<size, atomicMode>::testAndSet(size_t n)
95
{
87
{
96
    WordType mask = one << (n % wordSize);
88
    WordType mask = one << (n % wordSize);
Lines 100-106 inline bool Bitmap<size, atomicMode>::te Source/WTF/wtf/Bitmap.h_sec5
100
    return result;
92
    return result;
101
}
93
}
102
94
103
template<size_t size, BitmapAtomicMode atomicMode>
95
template<size_t size, AtomicMode atomicMode>
104
inline bool Bitmap<size, atomicMode>::testAndClear(size_t n)
96
inline bool Bitmap<size, atomicMode>::testAndClear(size_t n)
105
{
97
{
106
    WordType mask = one << (n % wordSize);
98
    WordType mask = one << (n % wordSize);
Lines 110-122 inline bool Bitmap<size, atomicMode>::te Source/WTF/wtf/Bitmap.h_sec6
110
    return result;
102
    return result;
111
}
103
}
112
104
113
template<size_t size, BitmapAtomicMode atomicMode>
105
template<size_t size, AtomicMode atomicMode>
114
inline bool Bitmap<size, atomicMode>::concurrentTestAndSet(size_t n)
106
inline bool Bitmap<size, atomicMode>::concurrentTestAndSet(size_t n)
115
{
107
{
116
    if (atomicMode == BitmapNotAtomic)
108
    if (atomicMode == ModeNotAtomic)
117
        return testAndSet(n);
109
        return testAndSet(n);
118
110
119
    ASSERT(atomicMode == BitmapAtomic);
111
    ASSERT(atomicMode == ModeAtomic);
120
    
112
    
121
    WordType mask = one << (n % wordSize);
113
    WordType mask = one << (n % wordSize);
122
    size_t index = n / wordSize;
114
    size_t index = n / wordSize;
Lines 130-142 inline bool Bitmap<size, atomicMode>::co Source/WTF/wtf/Bitmap.h_sec7
130
    return false;
122
    return false;
131
}
123
}
132
124
133
template<size_t size, BitmapAtomicMode atomicMode>
125
template<size_t size, AtomicMode atomicMode>
134
inline bool Bitmap<size, atomicMode>::concurrentTestAndClear(size_t n)
126
inline bool Bitmap<size, atomicMode>::concurrentTestAndClear(size_t n)
135
{
127
{
136
    if (atomicMode == BitmapNotAtomic)
128
    if (atomicMode == ModeNotAtomic)
137
        return testAndClear(n);
129
        return testAndClear(n);
138
130
139
    ASSERT(atomicMode == BitmapAtomic);
131
    ASSERT(atomicMode == ModeAtomic);
140
    
132
    
141
    WordType mask = one << (n % wordSize);
133
    WordType mask = one << (n % wordSize);
142
    size_t index = n / wordSize;
134
    size_t index = n / wordSize;
Lines 150-168 inline bool Bitmap<size, atomicMode>::co Source/WTF/wtf/Bitmap.h_sec8
150
    return true;
142
    return true;
151
}
143
}
152
144
153
template<size_t size, BitmapAtomicMode atomicMode>
145
template<size_t size, AtomicMode atomicMode>
154
inline void Bitmap<size, atomicMode>::clear(size_t n)
146
inline void Bitmap<size, atomicMode>::clear(size_t n)
155
{
147
{
156
    bits[n / wordSize] &= ~(one << (n % wordSize));
148
    bits[n / wordSize] &= ~(one << (n % wordSize));
157
}
149
}
158
150
159
template<size_t size, BitmapAtomicMode atomicMode>
151
template<size_t size, AtomicMode atomicMode>
160
inline void Bitmap<size, atomicMode>::clearAll()
152
inline void Bitmap<size, atomicMode>::clearAll()
161
{
153
{
162
    memset(bits.data(), 0, sizeof(bits));
154
    memset(bits.data(), 0, sizeof(bits));
163
}
155
}
164
156
165
template<size_t size, BitmapAtomicMode atomicMode>
157
template<size_t size, AtomicMode atomicMode>
166
inline size_t Bitmap<size, atomicMode>::nextPossiblyUnset(size_t start) const
158
inline size_t Bitmap<size, atomicMode>::nextPossiblyUnset(size_t start) const
167
{
159
{
168
    if (!~bits[start / wordSize])
160
    if (!~bits[start / wordSize])
Lines 170-176 inline size_t Bitmap<size, atomicMode>:: Source/WTF/wtf/Bitmap.h_sec9
170
    return start + 1;
162
    return start + 1;
171
}
163
}
172
164
173
template<size_t size, BitmapAtomicMode atomicMode>
165
template<size_t size, AtomicMode atomicMode>
174
inline int64_t Bitmap<size, atomicMode>::findRunOfZeros(size_t runLength) const
166
inline int64_t Bitmap<size, atomicMode>::findRunOfZeros(size_t runLength) const
175
{
167
{
176
    if (!runLength) 
168
    if (!runLength) 
Lines 190-196 inline int64_t Bitmap<size, atomicMode>: Source/WTF/wtf/Bitmap.h_sec10
190
    return -1;
182
    return -1;
191
}
183
}
192
184
193
template<size_t size, BitmapAtomicMode atomicMode>
185
template<size_t size, AtomicMode atomicMode>
194
inline size_t Bitmap<size, atomicMode>::count(size_t start) const
186
inline size_t Bitmap<size, atomicMode>::count(size_t start) const
195
{
187
{
196
    size_t result = 0;
188
    size_t result = 0;
Lines 203-209 inline size_t Bitmap<size, atomicMode>:: Source/WTF/wtf/Bitmap.h_sec11
203
    return result;
195
    return result;
204
}
196
}
205
197
206
template<size_t size, BitmapAtomicMode atomicMode>
198
template<size_t size, AtomicMode atomicMode>
207
inline size_t Bitmap<size, atomicMode>::isEmpty() const
199
inline size_t Bitmap<size, atomicMode>::isEmpty() const
208
{
200
{
209
    for (size_t i = 0; i < words; ++i)
201
    for (size_t i = 0; i < words; ++i)
Lines 212-218 inline size_t Bitmap<size, atomicMode>:: Source/WTF/wtf/Bitmap.h_sec12
212
    return true;
204
    return true;
213
}
205
}
214
206
215
template<size_t size, BitmapAtomicMode atomicMode>
207
template<size_t size, AtomicMode atomicMode>
216
inline size_t Bitmap<size, atomicMode>::isFull() const
208
inline size_t Bitmap<size, atomicMode>::isFull() const
217
{
209
{
218
    for (size_t i = 0; i < words; ++i)
210
    for (size_t i = 0; i < words; ++i)
- Source/WTF/wtf/CMakeLists.txt +1 lines
Lines 3-8 set(WTF_HEADERS Source/WTF/wtf/CMakeLists.txt_sec1
3
    AVLTree.h
3
    AVLTree.h
4
    Alignment.h
4
    Alignment.h
5
    Assertions.h
5
    Assertions.h
6
    AtomicMode.h
6
    Atomics.h
7
    Atomics.h
7
    BitArray.h
8
    BitArray.h
8
    BitVector.h
9
    BitVector.h
- Source/WTF/wtf/DeferrableRefCounted.h -4 / +65 lines
Lines 27-34 Source/WTF/wtf/DeferrableRefCounted.h_sec1
27
#define DeferrableRefCounted_h
27
#define DeferrableRefCounted_h
28
28
29
#include <wtf/Assertions.h>
29
#include <wtf/Assertions.h>
30
#include <wtf/AtomicMode.h>
31
#include <wtf/Atomics.h>
30
#include <wtf/FastAllocBase.h>
32
#include <wtf/FastAllocBase.h>
31
#include <wtf/Noncopyable.h>
33
#include <wtf/Noncopyable.h>
34
#include <wtf/ThreadingPrimitives.h>
32
35
33
namespace WTF {
36
namespace WTF {
34
37
Lines 38-43 namespace WTF { Source/WTF/wtf/DeferrableRefCounted.h_sec2
38
// specifically happened - this can be useful either for debugging, or
41
// specifically happened - this can be useful either for debugging, or
39
// sometimes even for some additional functionality.
42
// sometimes even for some additional functionality.
40
43
44
template<AtomicMode atomicMode>
41
class DeferrableRefCountedBase {
45
class DeferrableRefCountedBase {
42
    static const unsigned deferredFlag = 1;
46
    static const unsigned deferredFlag = 1;
43
    static const unsigned normalIncrement = 2;
47
    static const unsigned normalIncrement = 2;
Lines 45-51 class DeferrableRefCountedBase { Source/WTF/wtf/DeferrableRefCounted.h_sec3
45
public:
49
public:
46
    void ref()
50
    void ref()
47
    {
51
    {
52
        if (atomicMode == ModeNotAtomic) {
53
            m_refCount += normalIncrement;
54
            return;
55
        }
56
#if ENABLE(COMPARE_AND_SWAP)
57
        unsigned oldValue;
58
        do {
59
            oldValue = m_refCount;
60
        } while (!weakCompareAndSwap(&m_refCount, oldValue, oldValue + normalIncrement));
61
#else // ENABLE(COMPARE_AND_SWAP)
62
        MutexLocker locker(m_lock);
48
        m_refCount += normalIncrement;
63
        m_refCount += normalIncrement;
64
#endif // ENABLE(COMPARE_AND_SWAP)
49
    }
65
    }
50
    
66
    
51
    bool hasOneRef() const
67
    bool hasOneRef() const
Lines 75-111 protected: Source/WTF/wtf/DeferrableRefCounted.h_sec4
75
    
91
    
76
    bool derefBase()
92
    bool derefBase()
77
    {
93
    {
94
        if (atomicMode == ModeNotAtomic) {
95
            m_refCount -= normalIncrement;
96
            return !m_refCount;
97
        }
98
#if ENABLE(COMPARE_AND_SWAP)
99
        unsigned oldValue;
100
        unsigned newValue;
101
        do {
102
            oldValue = m_refCount;
103
            newValue = oldValue - normalIncrement;
104
        } while (!weakCompareAndSwap(&m_refCount, oldValue, newValue));
105
        return !newValue;
106
#else // ENABLE(COMPARE_AND_SWAP)
107
        MutexLocker locker(m_lock);
78
        m_refCount -= normalIncrement;
108
        m_refCount -= normalIncrement;
79
        return !m_refCount;
109
        return !m_refCount;
110
#endif // ENABLE(COMPARE_AND_SWAP)
80
    }
111
    }
81
112
82
    bool setIsDeferredBase(bool value)
113
    bool setIsDeferredBase(bool value)
83
    {
114
    {
115
        if (atomicMode == ModeNotAtomic) {
116
            if (value) {
117
                m_refCount |= deferredFlag;
118
                return false;
119
            }
120
            m_refCount &= ~deferredFlag;
121
            return !m_refCount;
122
        }
123
#if ENABLE(COMPARE_AND_SWAP)
124
        unsigned oldValue;
125
        unsigned newValue;
126
        bool result;
127
        do {
128
            oldValue = m_refCount;
129
            if (value) {
130
                newValue = oldValue | deferredFlag;
131
                result = false;
132
            } else {
133
                newValue = oldValue & ~deferredFlag;
134
                result = !newValue;
135
            }
136
        } while (!weakCompareAndSwap(&m_refCount, oldValue, newValue));
137
        return result;
138
#else // ENABLE(COMPARE_AND_SWAP)
139
        MutexLocker locker(m_lock);
84
        if (value) {
140
        if (value) {
85
            m_refCount |= deferredFlag;
141
            m_refCount |= deferredFlag;
86
            return false;
142
            return false;
87
        }
143
        }
88
        m_refCount &= ~deferredFlag;
144
        m_refCount &= ~deferredFlag;
89
        return !m_refCount;
145
        return !m_refCount;
146
#endif // ENABLE(COMPARE_AND_SWAP)
90
    }
147
    }
91
    
148
    
92
private:
149
private:
93
    unsigned m_refCount;
150
    unsigned m_refCount;
151
152
#if !ENABLE(COMPARE_AND_SWAP)
153
    Mutex m_lock;
154
#endif // !ENABLE(COMPARE_AND_SWAP)
94
};
155
};
95
156
96
template<typename T>
157
template<AtomicMode atomicMode, typename T>
97
class DeferrableRefCounted : public DeferrableRefCountedBase {
158
class DeferrableRefCounted : public DeferrableRefCountedBase<atomicMode> {
98
    WTF_MAKE_NONCOPYABLE(DeferrableRefCounted); WTF_MAKE_FAST_ALLOCATED;
159
    WTF_MAKE_NONCOPYABLE(DeferrableRefCounted); WTF_MAKE_FAST_ALLOCATED;
99
public:
160
public:
100
    void deref()
161
    void deref()
101
    {
162
    {
102
        if (derefBase())
163
        if (this->derefBase())
103
            delete static_cast<T*>(this);
164
            delete static_cast<T*>(this);
104
    }
165
    }
105
    
166
    
106
    bool setIsDeferred(bool value)
167
    bool setIsDeferred(bool value)
107
    {
168
    {
108
        if (!setIsDeferredBase(value))
169
        if (!this->setIsDeferredBase(value))
109
            return false;
170
            return false;
110
        delete static_cast<T*>(this);
171
        delete static_cast<T*>(this);
111
        return true;
172
        return true;

Return to Bug 120568