2 * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef GCThreadSharedData_h
27 #define GCThreadSharedData_h
29 #include "ListableHandler.h"
30 #include "MarkStack.h"
31 #include "MarkedBlock.h"
32 #include "UnconditionalFinalizer.h"
33 #include "WeakReferenceHarvester.h"
34 #include <wtf/HashSet.h>
35 #include <wtf/TCSpinLock.h>
36 #include <wtf/Threading.h>
37 #include <wtf/Vector.h>
53 class GCThreadSharedData
{
55 GCThreadSharedData(VM
*);
56 ~GCThreadSharedData();
60 void didStartMarking();
61 void didFinishMarking();
62 void didStartCopying();
63 void didFinishCopying();
65 #if ENABLE(PARALLEL_GC)
67 size_t childVisitCount();
68 size_t childDupStrings();
72 friend class GCThread
;
73 friend class SlotVisitor
;
74 friend class CopyVisitor
;
76 void getNextBlocksToCopy(size_t&, size_t&);
77 void startNextPhase(GCPhase
);
78 void endCurrentPhase();
81 CopiedSpace
* m_copiedSpace
;
83 bool m_shouldHashCons
;
85 Vector
<GCThread
*> m_gcThreads
;
88 ThreadCondition m_markingCondition
;
89 MarkStackArray m_sharedMarkStack
;
90 unsigned m_numberOfActiveParallelMarkers
;
91 bool m_parallelMarkersShouldExit
;
93 Mutex m_opaqueRootsLock
;
94 HashSet
<void*> m_opaqueRoots
;
97 Vector
<CopiedBlock
*> m_blocksToCopy
;
99 static const size_t s_blockFragmentLength
= 32;
102 ThreadCondition m_phaseCondition
;
103 ThreadCondition m_activityCondition
;
104 unsigned m_numberOfActiveGCThreads
;
105 bool m_gcThreadsShouldWait
;
106 GCPhase m_currentPhase
;
108 ListableHandler
<WeakReferenceHarvester
>::List m_weakReferenceHarvesters
;
109 ListableHandler
<UnconditionalFinalizer
>::List m_unconditionalFinalizers
;
112 inline void GCThreadSharedData::getNextBlocksToCopy(size_t& start
, size_t& end
)
114 SpinLockHolder
locker(&m_copyLock
);
116 end
= std::min(m_blocksToCopy
.size(), m_copyIndex
+ s_blockFragmentLength
);