2 * Copyright (C) 2011, 2012 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include "HandleTypes.h"
30 #include "MarkStackInlines.h"
32 #include <wtf/text/StringHash.h>
36 class ConservativeRoots
;
37 class GCThreadSharedData
;
39 template<typename T
> class Weak
;
40 template<typename T
> class WriteBarrierBase
;
41 template<typename T
> class JITWriteBarrier
;
44 WTF_MAKE_NONCOPYABLE(SlotVisitor
);
45 friend class HeapRootVisitor
; // Allowed to mark a JSValue* or JSCell** directly.
48 SlotVisitor(GCThreadSharedData
&);
51 void append(ConservativeRoots
&);
53 template<typename T
> void append(JITWriteBarrier
<T
>*);
54 template<typename T
> void append(WriteBarrierBase
<T
>*);
55 void appendValues(WriteBarrierBase
<Unknown
>*, size_t count
);
58 void appendUnbarrieredPointer(T
**);
59 void appendUnbarrieredValue(JSValue
*);
61 void appendUnbarrieredWeak(Weak
<T
>*);
63 void addOpaqueRoot(void*);
64 bool containsOpaqueRoot(void*);
65 TriState
containsOpaqueRootTriState(void*);
66 int opaqueRootCount();
68 GCThreadSharedData
& sharedData() { return m_shared
; }
69 bool isEmpty() { return m_stack
.isEmpty(); }
74 size_t visitCount() const { return m_visitCount
; }
78 void donateAndDrain();
80 enum SharedDrainMode
{ SlaveDrain
, MasterDrain
};
81 void drainFromShared(SharedDrainMode
);
83 void harvestWeakReferences();
84 void finalizeUnconditionalFinalizers();
86 void copyLater(JSCell
*, void*, size_t);
88 #if ENABLE(SIMPLE_HEAP_PROFILING)
89 VTableSpectrum m_visitedTypeCounts
;
92 void addWeakReferenceHarvester(WeakReferenceHarvester
*);
93 void addUnconditionalFinalizer(UnconditionalFinalizer
*);
95 #if ENABLE(OBJECT_MARK_LOGGING)
96 inline void resetChildCount() { m_logChildCount
= 0; }
97 inline unsigned childCount() { return m_logChildCount
; }
98 inline void incrementChildCount() { m_logChildCount
++; }
102 friend class ParallelModeEnabler
;
104 JS_EXPORT_PRIVATE
static void validate(JSCell
*);
106 void append(JSValue
*);
107 void append(JSValue
*, size_t count
);
108 void append(JSCell
**);
110 void internalAppend(JSCell
*);
111 void internalAppend(JSValue
);
112 void internalAppend(JSValue
*);
114 JS_EXPORT_PRIVATE
void mergeOpaqueRoots();
115 void mergeOpaqueRootsIfNecessary();
116 void mergeOpaqueRootsIfProfitable();
118 void donateKnownParallel();
120 MarkStackArray m_stack
;
121 HashSet
<void*> m_opaqueRoots
; // Handle-owning data structures not visible to the garbage collector.
124 bool m_isInParallelMode
;
126 GCThreadSharedData
& m_shared
;
128 bool m_shouldHashCons
; // Local per-thread copy of shared flag for performance reasons
129 typedef HashMap
<StringImpl
*, JSValue
> UniqueStringMap
;
130 UniqueStringMap m_uniqueStrings
;
132 #if ENABLE(OBJECT_MARK_LOGGING)
133 unsigned m_logChildCount
;
138 bool m_isCheckingForDefaultMarkViolation
;
143 class ParallelModeEnabler
{
145 ParallelModeEnabler(SlotVisitor
& stack
)
148 ASSERT(!m_stack
.m_isInParallelMode
);
149 m_stack
.m_isInParallelMode
= true;
152 ~ParallelModeEnabler()
154 ASSERT(m_stack
.m_isInParallelMode
);
155 m_stack
.m_isInParallelMode
= false;
159 SlotVisitor
& m_stack
;
164 #endif // SlotVisitor_h