2 * Copyright (C) 2012 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
29 #include <wtf/Platform.h>
33 #include "CodeOrigin.h"
34 #include "MacroAssembler.h"
37 #include "Structure.h"
38 #include <wtf/Vector.h>
42 struct StructureStubInfo
;
57 static PutByIdAccess
transition(
58 JSGlobalData
& globalData
,
60 Structure
* oldStructure
,
61 Structure
* newStructure
,
62 StructureChain
* chain
,
63 MacroAssemblerCodeRef stubRoutine
)
66 result
.m_type
= Transition
;
67 result
.m_oldStructure
.set(globalData
, owner
, oldStructure
);
68 result
.m_newStructure
.set(globalData
, owner
, newStructure
);
69 result
.m_chain
.set(globalData
, owner
, chain
);
70 result
.m_stubRoutine
= stubRoutine
;
74 static PutByIdAccess
replace(
75 JSGlobalData
& globalData
,
78 MacroAssemblerCodeRef stubRoutine
)
81 result
.m_type
= Replace
;
82 result
.m_oldStructure
.set(globalData
, owner
, structure
);
83 result
.m_stubRoutine
= stubRoutine
;
87 static PutByIdAccess
fromStructureStubInfo(
89 MacroAssemblerCodePtr initialSlowPath
);
91 bool isSet() const { return m_type
!= Invalid
; }
92 bool operator!() const { return !isSet(); }
94 AccessType
type() const { return m_type
; }
96 bool isTransition() const { return m_type
== Transition
; }
97 bool isReplace() const { return m_type
== Replace
; }
99 Structure
* oldStructure() const
101 // Using this instead of isSet() to make this assertion robust against the possibility
102 // of additional access types being added.
103 ASSERT(isTransition() || isReplace());
105 return m_oldStructure
.get();
108 Structure
* structure() const
111 return m_oldStructure
.get();
114 Structure
* newStructure() const
116 ASSERT(isTransition());
117 return m_newStructure
.get();
120 StructureChain
* chain() const
122 ASSERT(isTransition());
123 return m_chain
.get();
126 MacroAssemblerCodeRef
stubRoutine() const
128 ASSERT(isTransition() || isReplace());
129 return m_stubRoutine
;
132 bool visitWeak() const;
136 WriteBarrier
<Structure
> m_oldStructure
;
137 WriteBarrier
<Structure
> m_newStructure
;
138 WriteBarrier
<StructureChain
> m_chain
;
139 MacroAssemblerCodeRef m_stubRoutine
;
142 class PolymorphicPutByIdList
{
143 WTF_MAKE_FAST_ALLOCATED
;
145 // Initialize from a stub info; this will place one element in the list and it will
146 // be created by converting the stub info's put by id access information into our
148 PolymorphicPutByIdList(
151 MacroAssemblerCodePtr initialSlowPath
);
153 // Either creates a new polymorphic put list, or returns the one that is already
155 static PolymorphicPutByIdList
* from(
158 MacroAssemblerCodePtr initialSlowPath
);
160 ~PolymorphicPutByIdList();
162 MacroAssemblerCodePtr
currentSlowPathTarget() const
164 return m_list
.last().stubRoutine().code();
167 void addAccess(const PutByIdAccess
&);
169 bool isEmpty() const { return m_list
.isEmpty(); }
170 unsigned size() const { return m_list
.size(); }
172 bool isAlmostFull() const; // True if adding an element would make isFull() true.
173 const PutByIdAccess
& at(unsigned i
) const { return m_list
[i
]; }
174 const PutByIdAccess
& operator[](unsigned i
) const { return m_list
[i
]; }
176 PutKind
kind() const { return m_kind
; }
178 bool visitWeak() const;
181 Vector
<PutByIdAccess
, 2> m_list
;
187 #endif // ENABLE(JIT)
189 #endif // PolymorphicPutByIdList_h