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 switch (stubInfo
.accessType
) {
62 case 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
);
68 case access_get_by_id_chain
:
69 result
.m_structure
.copyFrom(stubInfo
.u
.getByIdChain
.baseObjectStructure
);
70 result
.m_chain
.copyFrom(stubInfo
.u
.getByIdChain
.chain
);
71 result
.m_chainCount
= stubInfo
.u
.getByIdChain
.count
;
72 result
.m_stubRoutine
= stubInfo
.stubRoutine
;
73 if (stubInfo
.u
.getByIdChain
.isDirect
)
74 result
.m_type
= SimpleStub
;
76 result
.m_type
= Getter
;
80 RELEASE_ASSERT_NOT_REACHED();
86 bool GetByIdAccess::visitWeak(RepatchBuffer
& repatchBuffer
) const
88 if (m_structure
&& !Heap::isMarked(m_structure
.get()))
90 if (m_chain
&& !Heap::isMarked(m_chain
.get()))
92 if (!m_stubRoutine
->visitWeak(repatchBuffer
))
97 PolymorphicGetByIdList::PolymorphicGetByIdList(StructureStubInfo
& stubInfo
)
99 if (stubInfo
.accessType
== access_unset
)
102 m_list
.append(GetByIdAccess::fromStructureStubInfo(stubInfo
));
105 PolymorphicGetByIdList
* PolymorphicGetByIdList::from(StructureStubInfo
& stubInfo
)
107 if (stubInfo
.accessType
== access_get_by_id_list
)
108 return stubInfo
.u
.getByIdList
.list
;
111 stubInfo
.accessType
== access_get_by_id_self
112 || stubInfo
.accessType
== access_get_by_id_chain
113 || stubInfo
.accessType
== access_unset
);
115 PolymorphicGetByIdList
* result
= new PolymorphicGetByIdList(stubInfo
);
117 stubInfo
.initGetByIdList(result
);
122 PolymorphicGetByIdList::~PolymorphicGetByIdList() { }
124 MacroAssemblerCodePtr
PolymorphicGetByIdList::currentSlowPathTarget(
125 StructureStubInfo
& stubInfo
) const
128 return stubInfo
.callReturnLocation
.labelAtOffset(stubInfo
.patch
.deltaCallToSlowCase
);
129 return m_list
.last().stubRoutine()->code().code();
132 void PolymorphicGetByIdList::addAccess(const GetByIdAccess
& access
)
135 // Make sure that the resizing optimizes for space, not time.
136 m_list
.resize(m_list
.size() + 1);
137 m_list
.last() = access
;
140 bool PolymorphicGetByIdList::isFull() const
142 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE
);
143 return size() == POLYMORPHIC_LIST_CACHE_SIZE
;
146 bool PolymorphicGetByIdList::isAlmostFull() const
148 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE
);
149 return size() >= POLYMORPHIC_LIST_CACHE_SIZE
- 1;
152 bool PolymorphicGetByIdList::didSelfPatching() const
154 for (unsigned i
= size(); i
--;) {
155 if (at(i
).type() == GetByIdAccess::SimpleInline
)
161 bool PolymorphicGetByIdList::visitWeak(RepatchBuffer
& repatchBuffer
) const
163 for (unsigned i
= size(); i
--;) {
164 if (!at(i
).visitWeak(repatchBuffer
))
172 #endif // ENABLE(JIT)