2 * Copyright (C) 2012, 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.
26 #ifndef PolymorphicPutByIdList_h
27 #define PolymorphicPutByIdList_h
31 #include "CodeOrigin.h"
32 #include "MacroAssembler.h"
35 #include "PutPropertySlot.h"
36 #include "Structure.h"
37 #include <wtf/Vector.h>
42 struct StructureStubInfo
;
56 , m_chainCount(UINT_MAX
)
60 static PutByIdAccess
transition(
63 Structure
* oldStructure
,
64 Structure
* newStructure
,
65 StructureChain
* chain
,
66 PassRefPtr
<JITStubRoutine
> stubRoutine
)
69 result
.m_type
= Transition
;
70 result
.m_oldStructure
.set(vm
, owner
, oldStructure
);
71 result
.m_newStructure
.set(vm
, owner
, newStructure
);
72 result
.m_chain
.set(vm
, owner
, chain
);
73 result
.m_customSetter
= 0;
74 result
.m_stubRoutine
= stubRoutine
;
78 static PutByIdAccess
replace(
82 PassRefPtr
<JITStubRoutine
> stubRoutine
)
85 result
.m_type
= Replace
;
86 result
.m_oldStructure
.set(vm
, owner
, structure
);
87 result
.m_customSetter
= 0;
88 result
.m_stubRoutine
= stubRoutine
;
93 static PutByIdAccess
setter(
96 AccessType accessType
,
98 StructureChain
* chain
,
100 PutPropertySlot::PutValueFunc customSetter
,
101 PassRefPtr
<JITStubRoutine
> stubRoutine
)
103 RELEASE_ASSERT(accessType
== Setter
|| accessType
== CustomSetter
);
104 PutByIdAccess result
;
105 result
.m_oldStructure
.set(vm
, owner
, structure
);
106 result
.m_type
= accessType
;
108 result
.m_chain
.set(vm
, owner
, chain
);
109 result
.m_chainCount
= chainCount
;
111 result
.m_customSetter
= customSetter
;
112 result
.m_stubRoutine
= stubRoutine
;
116 static PutByIdAccess
fromStructureStubInfo(StructureStubInfo
&);
118 bool isSet() const { return m_type
!= Invalid
; }
119 bool operator!() const { return !isSet(); }
121 AccessType
type() const { return m_type
; }
123 bool isTransition() const { return m_type
== Transition
; }
124 bool isReplace() const { return m_type
== Replace
; }
125 bool isSetter() const { return m_type
== Setter
; }
126 bool isCustom() const { return m_type
== CustomSetter
; }
128 Structure
* oldStructure() const
130 // Using this instead of isSet() to make this assertion robust against the possibility
131 // of additional access types being added.
132 ASSERT(isTransition() || isReplace() || isSetter() || isCustom());
134 return m_oldStructure
.get();
137 Structure
* structure() const
139 ASSERT(isReplace() || isSetter() || isCustom());
140 return m_oldStructure
.get();
143 Structure
* newStructure() const
145 ASSERT(isTransition());
146 return m_newStructure
.get();
149 StructureChain
* chain() const
151 ASSERT(isTransition() || isSetter() || isCustom());
152 return m_chain
.get();
155 unsigned chainCount() const
157 ASSERT(isSetter() || isCustom());
161 JITStubRoutine
* stubRoutine() const
163 ASSERT(isTransition() || isReplace() || isSetter() || isCustom());
164 return m_stubRoutine
.get();
167 PutPropertySlot::PutValueFunc
customSetter() const
170 return m_customSetter
;
173 bool visitWeak(RepatchBuffer
&) const;
176 friend class CodeBlock
;
179 WriteBarrier
<Structure
> m_oldStructure
;
180 WriteBarrier
<Structure
> m_newStructure
;
181 WriteBarrier
<StructureChain
> m_chain
;
182 unsigned m_chainCount
;
183 PutPropertySlot::PutValueFunc m_customSetter
;
184 RefPtr
<JITStubRoutine
> m_stubRoutine
;
187 class PolymorphicPutByIdList
{
188 WTF_MAKE_FAST_ALLOCATED
;
190 // Either creates a new polymorphic put list, or returns the one that is already
192 static PolymorphicPutByIdList
* from(PutKind
, StructureStubInfo
&);
194 ~PolymorphicPutByIdList();
196 MacroAssemblerCodePtr
currentSlowPathTarget() const
198 return m_list
.last().stubRoutine()->code().code();
201 void addAccess(const PutByIdAccess
&);
203 bool isEmpty() const { return m_list
.isEmpty(); }
204 unsigned size() const { return m_list
.size(); }
206 bool isAlmostFull() const; // True if adding an element would make isFull() true.
207 const PutByIdAccess
& at(unsigned i
) const { return m_list
[i
]; }
208 const PutByIdAccess
& operator[](unsigned i
) const { return m_list
[i
]; }
210 PutKind
kind() const { return m_kind
; }
212 bool visitWeak(RepatchBuffer
&) const;
215 friend class CodeBlock
;
217 // Initialize from a stub info; this will place one element in the list and it will
218 // be created by converting the stub info's put by id access information into our
220 PolymorphicPutByIdList(PutKind
, StructureStubInfo
&);
222 Vector
<PutByIdAccess
, 2> m_list
;
228 #endif // ENABLE(JIT)
230 #endif // PolymorphicPutByIdList_h