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
;
59 static PutByIdAccess
transition(
62 Structure
* oldStructure
,
63 Structure
* newStructure
,
64 StructureChain
* chain
,
65 PassRefPtr
<JITStubRoutine
> stubRoutine
)
68 result
.m_type
= Transition
;
69 result
.m_oldStructure
.set(vm
, owner
, oldStructure
);
70 result
.m_newStructure
.set(vm
, owner
, newStructure
);
71 result
.m_chain
.set(vm
, owner
, chain
);
72 result
.m_customSetter
= 0;
73 result
.m_stubRoutine
= stubRoutine
;
77 static PutByIdAccess
replace(
81 PassRefPtr
<JITStubRoutine
> stubRoutine
)
84 result
.m_type
= Replace
;
85 result
.m_oldStructure
.set(vm
, owner
, structure
);
86 result
.m_customSetter
= 0;
87 result
.m_stubRoutine
= stubRoutine
;
92 static PutByIdAccess
setter(
95 AccessType accessType
,
97 StructureChain
* chain
,
98 PutPropertySlot::PutValueFunc customSetter
,
99 PassRefPtr
<JITStubRoutine
> stubRoutine
)
101 RELEASE_ASSERT(accessType
== Setter
|| accessType
== CustomSetter
);
102 PutByIdAccess result
;
103 result
.m_oldStructure
.set(vm
, owner
, structure
);
104 result
.m_type
= accessType
;
106 result
.m_chain
.set(vm
, owner
, chain
);
107 result
.m_customSetter
= customSetter
;
108 result
.m_stubRoutine
= stubRoutine
;
112 static PutByIdAccess
fromStructureStubInfo(StructureStubInfo
&);
114 bool isSet() const { return m_type
!= Invalid
; }
115 bool operator!() const { return !isSet(); }
117 AccessType
type() const { return m_type
; }
119 bool isTransition() const { return m_type
== Transition
; }
120 bool isReplace() const { return m_type
== Replace
; }
121 bool isSetter() const { return m_type
== Setter
; }
122 bool isCustom() const { return m_type
== CustomSetter
; }
124 Structure
* oldStructure() const
126 // Using this instead of isSet() to make this assertion robust against the possibility
127 // of additional access types being added.
128 ASSERT(isTransition() || isReplace() || isSetter() || isCustom());
130 return m_oldStructure
.get();
133 Structure
* structure() const
136 return m_oldStructure
.get();
139 Structure
* newStructure() const
141 ASSERT(isTransition());
142 return m_newStructure
.get();
145 StructureChain
* chain() const
147 ASSERT(isTransition() || isSetter() || isCustom());
148 return m_chain
.get();
151 JITStubRoutine
* stubRoutine() const
153 ASSERT(isTransition() || isReplace() || isSetter() || isCustom());
154 return m_stubRoutine
.get();
157 PutPropertySlot::PutValueFunc
customSetter() const
160 return m_customSetter
;
163 bool visitWeak(RepatchBuffer
&) const;
166 friend class CodeBlock
;
169 WriteBarrier
<Structure
> m_oldStructure
;
170 WriteBarrier
<Structure
> m_newStructure
;
171 WriteBarrier
<StructureChain
> m_chain
;
172 PutPropertySlot::PutValueFunc m_customSetter
;
173 RefPtr
<JITStubRoutine
> m_stubRoutine
;
176 class PolymorphicPutByIdList
{
177 WTF_MAKE_FAST_ALLOCATED
;
179 // Either creates a new polymorphic put list, or returns the one that is already
181 static PolymorphicPutByIdList
* from(PutKind
, StructureStubInfo
&);
183 ~PolymorphicPutByIdList();
185 MacroAssemblerCodePtr
currentSlowPathTarget() const
187 return m_list
.last().stubRoutine()->code().code();
190 void addAccess(const PutByIdAccess
&);
192 bool isEmpty() const { return m_list
.isEmpty(); }
193 unsigned size() const { return m_list
.size(); }
195 bool isAlmostFull() const; // True if adding an element would make isFull() true.
196 const PutByIdAccess
& at(unsigned i
) const { return m_list
[i
]; }
197 const PutByIdAccess
& operator[](unsigned i
) const { return m_list
[i
]; }
199 PutKind
kind() const { return m_kind
; }
201 bool visitWeak(RepatchBuffer
&) const;
204 friend class CodeBlock
;
206 // Initialize from a stub info; this will place one element in the list and it will
207 // be created by converting the stub info's put by id access information into our
209 PolymorphicPutByIdList(PutKind
, StructureStubInfo
&);
211 Vector
<PutByIdAccess
, 2> m_list
;
217 #endif // ENABLE(JIT)
219 #endif // PolymorphicPutByIdList_h