]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2009, 2011 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 GCThreadSharedData_h | |
27 | #define GCThreadSharedData_h | |
28 | ||
29 | #include "ListableHandler.h" | |
30 | #include "MarkStack.h" | |
31 | #include "MarkedBlock.h" | |
32 | #include "UnconditionalFinalizer.h" | |
33 | #include "WeakReferenceHarvester.h" | |
34 | #include <condition_variable> | |
35 | #include <wtf/HashSet.h> | |
36 | #include <wtf/SpinLock.h> | |
37 | #include <wtf/Vector.h> | |
38 | ||
39 | namespace JSC { | |
40 | ||
41 | class CopiedBlock; | |
42 | class CopiedSpace; | |
43 | class CopyVisitor; | |
44 | class GCThread; | |
45 | class VM; | |
46 | ||
47 | enum GCPhase { | |
48 | NoPhase, | |
49 | Mark, | |
50 | Copy, | |
51 | Exit | |
52 | }; | |
53 | ||
54 | class GCThreadSharedData { | |
55 | WTF_MAKE_FAST_ALLOCATED; | |
56 | public: | |
57 | GCThreadSharedData(VM*); | |
58 | ~GCThreadSharedData(); | |
59 | ||
60 | void reset(); | |
61 | ||
62 | void didStartMarking(); | |
63 | void didFinishMarking(); | |
64 | void didStartCopying(); | |
65 | void didFinishCopying(); | |
66 | ||
67 | #if ENABLE(PARALLEL_GC) | |
68 | void resetChildren(); | |
69 | size_t childVisitCount(); | |
70 | size_t childBytesVisited(); | |
71 | size_t childBytesCopied(); | |
72 | size_t childDupStrings(); | |
73 | #endif | |
74 | ||
75 | private: | |
76 | friend class GCThread; | |
77 | friend class SlotVisitor; | |
78 | friend class CopyVisitor; | |
79 | ||
80 | void getNextBlocksToCopy(size_t&, size_t&); | |
81 | void startNextPhase(GCPhase); | |
82 | void endCurrentPhase(); | |
83 | ||
84 | VM* m_vm; | |
85 | CopiedSpace* m_copiedSpace; | |
86 | ||
87 | bool m_shouldHashCons; | |
88 | ||
89 | Vector<GCThread*> m_gcThreads; | |
90 | ||
91 | std::mutex m_markingMutex; | |
92 | std::condition_variable m_markingConditionVariable; | |
93 | MarkStackArray m_sharedMarkStack; | |
94 | unsigned m_numberOfActiveParallelMarkers; | |
95 | bool m_parallelMarkersShouldExit; | |
96 | ||
97 | std::mutex m_opaqueRootsMutex; | |
98 | HashSet<void*> m_opaqueRoots; | |
99 | ||
100 | SpinLock m_copyLock; | |
101 | Vector<CopiedBlock*> m_blocksToCopy; | |
102 | size_t m_copyIndex; | |
103 | static const size_t s_blockFragmentLength = 32; | |
104 | ||
105 | std::mutex m_phaseMutex; | |
106 | std::condition_variable m_phaseConditionVariable; | |
107 | std::condition_variable m_activityConditionVariable; | |
108 | unsigned m_numberOfActiveGCThreads; | |
109 | bool m_gcThreadsShouldWait; | |
110 | GCPhase m_currentPhase; | |
111 | ||
112 | ListableHandler<WeakReferenceHarvester>::List m_weakReferenceHarvesters; | |
113 | ListableHandler<UnconditionalFinalizer>::List m_unconditionalFinalizers; | |
114 | }; | |
115 | ||
116 | inline void GCThreadSharedData::getNextBlocksToCopy(size_t& start, size_t& end) | |
117 | { | |
118 | SpinLockHolder locker(&m_copyLock); | |
119 | start = m_copyIndex; | |
120 | end = std::min(m_blocksToCopy.size(), m_copyIndex + s_blockFragmentLength); | |
121 | m_copyIndex = end; | |
122 | } | |
123 | ||
124 | } // namespace JSC | |
125 | ||
126 | #endif |