]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/PolymorphicGetByIdList.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / PolymorphicGetByIdList.cpp
CommitLineData
81345200
A
1/*
2 * Copyright (C) 2014 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#include "config.h"
27#include "PolymorphicGetByIdList.h"
28
29#if ENABLE(JIT)
30
31#include "CodeBlock.h"
32#include "Heap.h"
33#include "JSCInlines.h"
34#include "StructureStubInfo.h"
35
36namespace JSC {
37
38GetByIdAccess::GetByIdAccess(
39 VM& vm, JSCell* owner, AccessType type, PassRefPtr<JITStubRoutine> stubRoutine,
40 Structure* structure, StructureChain* chain, unsigned chainCount)
41 : m_type(type)
42 , m_chainCount(chainCount)
43 , m_structure(vm, owner, structure)
44 , m_stubRoutine(stubRoutine)
45{
46 if (chain)
47 m_chain.set(vm, owner, chain);
48}
49
50GetByIdAccess::~GetByIdAccess()
51{
52}
53
54GetByIdAccess GetByIdAccess::fromStructureStubInfo(StructureStubInfo& stubInfo)
55{
56 MacroAssemblerCodePtr initialSlowPath =
57 stubInfo.callReturnLocation.labelAtOffset(stubInfo.patch.deltaCallToSlowCase);
58
59 GetByIdAccess result;
60
ed1e77d3
A
61 RELEASE_ASSERT(stubInfo.accessType == access_get_by_id_self);
62
63 result.m_type = SimpleInline;
64 result.m_structure.copyFrom(stubInfo.u.getByIdSelf.baseObjectStructure);
65 result.m_stubRoutine = JITStubRoutine::createSelfManagedRoutine(initialSlowPath);
81345200
A
66
67 return result;
68}
69
70bool GetByIdAccess::visitWeak(RepatchBuffer& repatchBuffer) const
71{
72 if (m_structure && !Heap::isMarked(m_structure.get()))
73 return false;
74 if (m_chain && !Heap::isMarked(m_chain.get()))
75 return false;
76 if (!m_stubRoutine->visitWeak(repatchBuffer))
77 return false;
78 return true;
79}
80
81PolymorphicGetByIdList::PolymorphicGetByIdList(StructureStubInfo& stubInfo)
82{
83 if (stubInfo.accessType == access_unset)
84 return;
85
86 m_list.append(GetByIdAccess::fromStructureStubInfo(stubInfo));
87}
88
89PolymorphicGetByIdList* PolymorphicGetByIdList::from(StructureStubInfo& stubInfo)
90{
91 if (stubInfo.accessType == access_get_by_id_list)
92 return stubInfo.u.getByIdList.list;
93
94 ASSERT(
95 stubInfo.accessType == access_get_by_id_self
81345200
A
96 || stubInfo.accessType == access_unset);
97
98 PolymorphicGetByIdList* result = new PolymorphicGetByIdList(stubInfo);
99
100 stubInfo.initGetByIdList(result);
101
102 return result;
103}
104
105PolymorphicGetByIdList::~PolymorphicGetByIdList() { }
106
107MacroAssemblerCodePtr PolymorphicGetByIdList::currentSlowPathTarget(
108 StructureStubInfo& stubInfo) const
109{
110 if (isEmpty())
111 return stubInfo.callReturnLocation.labelAtOffset(stubInfo.patch.deltaCallToSlowCase);
112 return m_list.last().stubRoutine()->code().code();
113}
114
115void PolymorphicGetByIdList::addAccess(const GetByIdAccess& access)
116{
117 ASSERT(!isFull());
118 // Make sure that the resizing optimizes for space, not time.
ed1e77d3 119 m_list.resizeToFit(m_list.size() + 1);
81345200
A
120 m_list.last() = access;
121}
122
123bool PolymorphicGetByIdList::isFull() const
124{
125 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE);
126 return size() == POLYMORPHIC_LIST_CACHE_SIZE;
127}
128
129bool PolymorphicGetByIdList::isAlmostFull() const
130{
131 ASSERT(size() <= POLYMORPHIC_LIST_CACHE_SIZE);
132 return size() >= POLYMORPHIC_LIST_CACHE_SIZE - 1;
133}
134
135bool PolymorphicGetByIdList::didSelfPatching() const
136{
137 for (unsigned i = size(); i--;) {
138 if (at(i).type() == GetByIdAccess::SimpleInline)
139 return true;
140 }
141 return false;
142}
143
144bool PolymorphicGetByIdList::visitWeak(RepatchBuffer& repatchBuffer) const
145{
146 for (unsigned i = size(); i--;) {
147 if (!at(i).visitWeak(repatchBuffer))
148 return false;
149 }
150 return true;
151}
152
153} // namespace JSC
154
155#endif // ENABLE(JIT)
156
157