2 * Copyright (C) 2014 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.
27 #include "PolymorphicGetByIdList.h"
31 #include "CodeBlock.h"
33 #include "JSCInlines.h"
34 #include "StructureStubInfo.h"
38 GetByIdAccess::GetByIdAccess(
39 VM
& vm
, JSCell
* owner
, AccessType type
, PassRefPtr
<JITStubRoutine
> stubRoutine
,
40 Structure
* structure
, StructureChain
* chain
, unsigned chainCount
)
42 , m_chainCount(chainCount
)
43 , m_structure(vm
, owner
, structure
)
44 , m_stubRoutine(stubRoutine
)
47 m_chain
.set(vm
, owner
, chain
);
50 GetByIdAccess::~GetByIdAccess()
54 GetByIdAccess
GetByIdAccess::fromStructureStubInfo(StructureStubInfo
& stubInfo
)
56 MacroAssemblerCodePtr initialSlowPath
=
57 stubInfo
.callReturnLocation
.labelAtOffset(stubInfo
.patch
.deltaCallToSlowCase
);
61 RELEASE_ASSERT(stubInfo
.accessType
== access_get_by_id_self
);
63 result
.m_type
= SimpleInline
;
64 result
.m_structure
.copyFrom(stubInfo
.u
.getByIdSelf
.baseObjectStructure
);
65 result
.m_stubRoutine
= JITStubRoutine::createSelfManagedRoutine(initialSlowPath
);
70 bool GetByIdAccess::visitWeak(RepatchBuffer
& repatchBuffer
) const
72 if (m_structure
&& !Heap::isMarked(m_structure
.get()))
74 if (m_chain
&& !Heap::isMarked(m_chain
.get()))
76 if (!m_stubRoutine
->visitWeak(repatchBuffer
))
81 PolymorphicGetByIdList::PolymorphicGetByIdList(StructureStubInfo
& stubInfo
)
83 if (stubInfo
.accessType
== access_unset
)
86 m_list
.append(GetByIdAccess::fromStructureStubInfo(stubInfo
));
89 PolymorphicGetByIdList
* PolymorphicGetByIdList::from(StructureStubInfo
& stubInfo
)
91 if (stubInfo
.accessType
== access_get_by_id_list
)
92 return stubInfo
.u
.getByIdList
.list
;
95 stubInfo
.accessType
== access_get_by_id_self
96 || stubInfo
.accessType
== access_unset
);
98 PolymorphicGetByIdList
* result
= new PolymorphicGetByIdList(stubInfo
);
100 stubInfo
.initGetByIdList(result
);
105 PolymorphicGetByIdList::~PolymorphicGetByIdList() { }
107 MacroAssemblerCodePtr
PolymorphicGetByIdList::currentSlowPathTarget(
108 StructureStubInfo
& stubInfo
) const
111 return stubInfo
.callReturnLocation
.labelAtOffset(stubInfo
.patch
.deltaCallToSlowCase
);
112 return m_list
.last().stubRoutine()->code().code();
115 void PolymorphicGetByIdList::addAccess(const GetByIdAccess
& access
)
118 // Make sure that the resizing optimizes for space, not time.
119 m_list
.resizeToFit(m_list
.size() + 1);
120 m_list
.last() = access
;
123 bool PolymorphicGetByIdList::isFull() const
125 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE
);
126 return size() == POLYMORPHIC_LIST_CACHE_SIZE
;
129 bool PolymorphicGetByIdList::isAlmostFull() const
131 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE
);
132 return size() >= POLYMORPHIC_LIST_CACHE_SIZE
- 1;
135 bool PolymorphicGetByIdList::didSelfPatching() const
137 for (unsigned i
= size(); i
--;) {
138 if (at(i
).type() == GetByIdAccess::SimpleInline
)
144 bool PolymorphicGetByIdList::visitWeak(RepatchBuffer
& repatchBuffer
) const
146 for (unsigned i
= size(); i
--;) {
147 if (!at(i
).visitWeak(repatchBuffer
))
155 #endif // ENABLE(JIT)