2 * Copyright (C) 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.
26 #ifndef SlotVisitorInlines_h
27 #define SlotVisitorInlines_h
29 #include "CopiedBlockInlines.h"
30 #include "CopiedSpaceInlines.h"
32 #include "SlotVisitor.h"
34 #include "WeakInlines.h"
38 ALWAYS_INLINE
void SlotVisitor::append(JSValue
* slot
, size_t count
)
40 for (size_t i
= 0; i
< count
; ++i
) {
41 JSValue
& value
= slot
[i
];
42 internalAppend(value
);
47 inline void SlotVisitor::appendUnbarrieredPointer(T
** slot
)
54 ALWAYS_INLINE
void SlotVisitor::append(JSValue
* slot
)
57 internalAppend(*slot
);
60 ALWAYS_INLINE
void SlotVisitor::appendUnbarrieredValue(JSValue
* slot
)
63 internalAppend(*slot
);
66 ALWAYS_INLINE
void SlotVisitor::append(JSCell
** slot
)
69 internalAppend(*slot
);
73 ALWAYS_INLINE
void SlotVisitor::appendUnbarrieredWeak(Weak
<T
>* weak
)
77 internalAppend(weak
->get());
80 ALWAYS_INLINE
void SlotVisitor::internalAppend(JSValue value
)
82 if (!value
|| !value
.isCell())
84 internalAppend(value
.asCell());
87 inline void SlotVisitor::addWeakReferenceHarvester(WeakReferenceHarvester
* weakReferenceHarvester
)
89 m_shared
.m_weakReferenceHarvesters
.addThreadSafe(weakReferenceHarvester
);
92 inline void SlotVisitor::addUnconditionalFinalizer(UnconditionalFinalizer
* unconditionalFinalizer
)
94 m_shared
.m_unconditionalFinalizers
.addThreadSafe(unconditionalFinalizer
);
97 inline void SlotVisitor::addOpaqueRoot(void* root
)
99 #if ENABLE(PARALLEL_GC)
100 if (Options::numberOfGCMarkers() == 1) {
101 // Put directly into the shared HashSet.
102 m_shared
.m_opaqueRoots
.add(root
);
105 // Put into the local set, but merge with the shared one every once in
106 // a while to make sure that the local sets don't grow too large.
107 mergeOpaqueRootsIfProfitable();
108 m_opaqueRoots
.add(root
);
110 m_opaqueRoots
.add(root
);
114 inline bool SlotVisitor::containsOpaqueRoot(void* root
)
116 ASSERT(!m_isInParallelMode
);
117 #if ENABLE(PARALLEL_GC)
118 ASSERT(m_opaqueRoots
.isEmpty());
119 return m_shared
.m_opaqueRoots
.contains(root
);
121 return m_opaqueRoots
.contains(root
);
125 inline TriState
SlotVisitor::containsOpaqueRootTriState(void* root
)
127 if (m_opaqueRoots
.contains(root
))
129 MutexLocker
locker(m_shared
.m_opaqueRootsLock
);
130 if (m_shared
.m_opaqueRoots
.contains(root
))
132 return MixedTriState
;
135 inline int SlotVisitor::opaqueRootCount()
137 ASSERT(!m_isInParallelMode
);
138 #if ENABLE(PARALLEL_GC)
139 ASSERT(m_opaqueRoots
.isEmpty());
140 return m_shared
.m_opaqueRoots
.size();
142 return m_opaqueRoots
.size();
146 inline void SlotVisitor::mergeOpaqueRootsIfNecessary()
148 if (m_opaqueRoots
.isEmpty())
153 inline void SlotVisitor::mergeOpaqueRootsIfProfitable()
155 if (static_cast<unsigned>(m_opaqueRoots
.size()) < Options::opaqueRootMergeThreshold())
160 inline void SlotVisitor::donate()
162 ASSERT(m_isInParallelMode
);
163 if (Options::numberOfGCMarkers() == 1)
166 donateKnownParallel();
169 inline void SlotVisitor::donateAndDrain()
175 inline void SlotVisitor::copyLater(JSCell
* owner
, void* ptr
, size_t bytes
)
178 CopiedBlock
* block
= CopiedSpace::blockFor(ptr
);
179 if (block
->isOversize()) {
180 m_shared
.m_copiedSpace
->pin(block
);
184 if (block
->isPinned())
187 block
->reportLiveBytes(owner
, bytes
);
192 #endif // SlotVisitorInlines_h