2 * Copyright (C) 2013 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 GCIncomingRefCountedInlines_h
27 #define GCIncomingRefCountedInlines_h
29 #include "GCIncomingRefCounted.h"
35 bool GCIncomingRefCounted
<T
>::addIncomingReference(JSCell
* cell
)
37 if (!hasAnyIncoming()) {
38 m_encodedPointer
= bitwise_cast
<uintptr_t>(cell
) | singletonFlag();
39 this->setIsDeferred(true);
40 ASSERT(hasSingleton());
44 ASSERT(Heap::heap(incomingReferenceAt(0)) == Heap::heap(cell
));
47 Vector
<JSCell
*>* vector
= new Vector
<JSCell
*>();
48 vector
->append(singleton());
50 m_encodedPointer
= bitwise_cast
<uintptr_t>(vector
);
51 ASSERT(hasVectorOfCells());
55 vectorOfCells()->append(cell
);
60 template<typename FilterFunctionType
>
61 bool GCIncomingRefCounted
<T
>::filterIncomingReferences(FilterFunctionType
& filterFunction
)
63 const bool verbose
= false;
66 dataLog("Filtering incoming references.\n");
68 if (!hasAnyIncoming()) {
69 ASSERT(!this->isDeferred());
70 ASSERT(this->refCount());
72 dataLog(" Has no incoming.\n");
76 ASSERT(this->isDeferred());
79 if (filterFunction(singleton())) {
81 dataLog(" Singleton passed.\n");
86 dataLog(" Removing singleton.\n");
88 ASSERT(!hasAnyIncoming());
89 this->setIsDeferred(false);
94 dataLog(" Has ", vectorOfCells()->size(), " entries.\n");
95 for (size_t i
= 0; i
< vectorOfCells()->size(); ++i
) {
96 if (filterFunction(vectorOfCells()->at(i
)))
98 vectorOfCells()->at(i
--) = vectorOfCells()->last();
99 vectorOfCells()->removeLast();
102 if (vectorOfCells()->size() >= 2) {
104 dataLog(" Still has ", vectorOfCells()->size(), " entries.\n");
108 if (vectorOfCells()->isEmpty()) {
110 dataLog(" Removing.\n");
111 delete vectorOfCells();
112 m_encodedPointer
= 0;
113 ASSERT(!hasAnyIncoming());
114 this->setIsDeferred(false);
119 dataLog(" Shrinking to singleton.\n");
120 JSCell
* singleton
= vectorOfCells()->at(0);
121 delete vectorOfCells();
122 m_encodedPointer
= bitwise_cast
<uintptr_t>(singleton
) | singletonFlag();
123 ASSERT(hasSingleton());
129 #endif // GCIncomingRefCountedInlines_h