Fix indentation of JSGlobalObject.h and JSGlobalObjectFunctions.h
[WebKit-https.git] / Source / JavaScriptCore / bytecode / StructureStubInfo.h
1 /*
2  * Copyright (C) 2008, 2012 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 #ifndef StructureStubInfo_h
27 #define StructureStubInfo_h
28
29 #include <wtf/Platform.h>
30
31 #if ENABLE(JIT)
32
33 #include "CodeOrigin.h"
34 #include "DFGRegisterSet.h"
35 #include "Instruction.h"
36 #include "JITStubRoutine.h"
37 #include "MacroAssembler.h"
38 #include "Opcode.h"
39 #include "Structure.h"
40 #include "StructureStubClearingWatchpoint.h"
41 #include <wtf/OwnPtr.h>
42
43 namespace JSC {
44
45     class PolymorphicPutByIdList;
46
47     enum AccessType {
48         access_get_by_id_self,
49         access_get_by_id_proto,
50         access_get_by_id_chain,
51         access_get_by_id_self_list,
52         access_get_by_id_proto_list,
53         access_put_by_id_transition_normal,
54         access_put_by_id_transition_direct,
55         access_put_by_id_replace,
56         access_put_by_id_list,
57         access_unset,
58         access_get_by_id_generic,
59         access_put_by_id_generic,
60         access_get_array_length,
61         access_get_string_length,
62     };
63
64     inline bool isGetByIdAccess(AccessType accessType)
65     {
66         switch (accessType) {
67         case access_get_by_id_self:
68         case access_get_by_id_proto:
69         case access_get_by_id_chain:
70         case access_get_by_id_self_list:
71         case access_get_by_id_proto_list:
72         case access_get_by_id_generic:
73         case access_get_array_length:
74         case access_get_string_length:
75             return true;
76         default:
77             return false;
78         }
79     }
80     
81     inline bool isPutByIdAccess(AccessType accessType)
82     {
83         switch (accessType) {
84         case access_put_by_id_transition_normal:
85         case access_put_by_id_transition_direct:
86         case access_put_by_id_replace:
87         case access_put_by_id_list:
88         case access_put_by_id_generic:
89             return true;
90         default:
91             return false;
92         }
93     }
94
95     struct StructureStubInfo {
96         StructureStubInfo()
97             : accessType(access_unset)
98             , seen(false)
99         {
100         }
101
102         void initGetByIdSelf(JSGlobalData& globalData, JSCell* owner, Structure* baseObjectStructure)
103         {
104             accessType = access_get_by_id_self;
105
106             u.getByIdSelf.baseObjectStructure.set(globalData, owner, baseObjectStructure);
107         }
108
109         void initGetByIdProto(JSGlobalData& globalData, JSCell* owner, Structure* baseObjectStructure, Structure* prototypeStructure, bool isDirect)
110         {
111             accessType = access_get_by_id_proto;
112
113             u.getByIdProto.baseObjectStructure.set(globalData, owner, baseObjectStructure);
114             u.getByIdProto.prototypeStructure.set(globalData, owner, prototypeStructure);
115             u.getByIdProto.isDirect = isDirect;
116         }
117
118         void initGetByIdChain(JSGlobalData& globalData, JSCell* owner, Structure* baseObjectStructure, StructureChain* chain, unsigned count, bool isDirect)
119         {
120             accessType = access_get_by_id_chain;
121
122             u.getByIdChain.baseObjectStructure.set(globalData, owner, baseObjectStructure);
123             u.getByIdChain.chain.set(globalData, owner, chain);
124             u.getByIdChain.count = count;
125             u.getByIdChain.isDirect = isDirect;
126         }
127
128         void initGetByIdSelfList(PolymorphicAccessStructureList* structureList, int listSize)
129         {
130             accessType = access_get_by_id_self_list;
131
132             u.getByIdSelfList.structureList = structureList;
133             u.getByIdSelfList.listSize = listSize;
134         }
135
136         void initGetByIdProtoList(PolymorphicAccessStructureList* structureList, int listSize)
137         {
138             accessType = access_get_by_id_proto_list;
139
140             u.getByIdProtoList.structureList = structureList;
141             u.getByIdProtoList.listSize = listSize;
142         }
143
144         // PutById*
145
146         void initPutByIdTransition(JSGlobalData& globalData, JSCell* owner, Structure* previousStructure, Structure* structure, StructureChain* chain, bool isDirect)
147         {
148             if (isDirect)
149                 accessType = access_put_by_id_transition_direct;
150             else
151                 accessType = access_put_by_id_transition_normal;
152
153             u.putByIdTransition.previousStructure.set(globalData, owner, previousStructure);
154             u.putByIdTransition.structure.set(globalData, owner, structure);
155             u.putByIdTransition.chain.set(globalData, owner, chain);
156         }
157
158         void initPutByIdReplace(JSGlobalData& globalData, JSCell* owner, Structure* baseObjectStructure)
159         {
160             accessType = access_put_by_id_replace;
161     
162             u.putByIdReplace.baseObjectStructure.set(globalData, owner, baseObjectStructure);
163         }
164         
165         void initPutByIdList(PolymorphicPutByIdList* list)
166         {
167             accessType = access_put_by_id_list;
168             u.putByIdList.list = list;
169         }
170         
171         void reset()
172         {
173             deref();
174             accessType = access_unset;
175             stubRoutine.clear();
176             watchpoints.clear();
177         }
178
179         void deref();
180
181         bool visitWeakReferences();
182         
183         bool seenOnce()
184         {
185             return seen;
186         }
187
188         void setSeen()
189         {
190             seen = true;
191         }
192         
193         StructureStubClearingWatchpoint* addWatchpoint(CodeBlock* codeBlock)
194         {
195             return WatchpointsOnStructureStubInfo::ensureReferenceAndAddWatchpoint(
196                 watchpoints, codeBlock, this);
197         }
198         
199         unsigned bytecodeIndex;
200
201         int8_t accessType;
202         int8_t seen;
203
204 #if ENABLE(DFG_JIT)
205         CodeOrigin codeOrigin;
206 #endif // ENABLE(DFG_JIT)
207
208         union {
209             struct {
210                 int8_t registersFlushed;
211                 int8_t baseGPR;
212 #if USE(JSVALUE32_64)
213                 int8_t valueTagGPR;
214 #endif
215                 int8_t valueGPR;
216                 DFG::RegisterSetPOD usedRegisters;
217                 int32_t deltaCallToDone;
218                 int32_t deltaCallToStorageLoad;
219                 int32_t deltaCallToStructCheck;
220                 int32_t deltaCallToSlowCase;
221                 int32_t deltaCheckImmToCall;
222 #if USE(JSVALUE64)
223                 int32_t deltaCallToLoadOrStore;
224 #else
225                 int32_t deltaCallToTagLoadOrStore;
226                 int32_t deltaCallToPayloadLoadOrStore;
227 #endif
228             } dfg;
229             struct {
230                 union {
231                     struct {
232                         int16_t structureToCompare;
233                         int16_t structureCheck;
234                         int16_t propertyStorageLoad;
235 #if USE(JSVALUE64)
236                         int16_t displacementLabel;
237 #else
238                         int16_t displacementLabel1;
239                         int16_t displacementLabel2;
240 #endif
241                         int16_t putResult;
242                         int16_t coldPathBegin;
243                     } get;
244                     struct {
245                         int16_t structureToCompare;
246                         int16_t propertyStorageLoad;
247 #if USE(JSVALUE64)
248                         int16_t displacementLabel;
249 #else
250                         int16_t displacementLabel1;
251                         int16_t displacementLabel2;
252 #endif
253                     } put;
254                 } u;
255                 int16_t methodCheckProtoObj;
256                 int16_t methodCheckProtoStructureToCompare;
257                 int16_t methodCheckPutFunction;
258             } baseline;
259         } patch;
260
261         union {
262             struct {
263                 // It would be unwise to put anything here, as it will surely be overwritten.
264             } unset;
265             struct {
266                 WriteBarrierBase<Structure> baseObjectStructure;
267             } getByIdSelf;
268             struct {
269                 WriteBarrierBase<Structure> baseObjectStructure;
270                 WriteBarrierBase<Structure> prototypeStructure;
271                 bool isDirect;
272             } getByIdProto;
273             struct {
274                 WriteBarrierBase<Structure> baseObjectStructure;
275                 WriteBarrierBase<StructureChain> chain;
276                 unsigned count : 31;
277                 bool isDirect : 1;
278             } getByIdChain;
279             struct {
280                 PolymorphicAccessStructureList* structureList;
281                 int listSize;
282             } getByIdSelfList;
283             struct {
284                 PolymorphicAccessStructureList* structureList;
285                 int listSize;
286             } getByIdProtoList;
287             struct {
288                 WriteBarrierBase<Structure> previousStructure;
289                 WriteBarrierBase<Structure> structure;
290                 WriteBarrierBase<StructureChain> chain;
291             } putByIdTransition;
292             struct {
293                 WriteBarrierBase<Structure> baseObjectStructure;
294             } putByIdReplace;
295             struct {
296                 PolymorphicPutByIdList* list;
297             } putByIdList;
298         } u;
299
300         RefPtr<JITStubRoutine> stubRoutine;
301         CodeLocationCall callReturnLocation;
302         CodeLocationLabel hotPathBegin;
303         RefPtr<WatchpointsOnStructureStubInfo> watchpoints;
304     };
305
306     inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo)
307     {
308         return structureStubInfo->callReturnLocation.executableAddress();
309     }
310
311     inline unsigned getStructureStubInfoBytecodeIndex(StructureStubInfo* structureStubInfo)
312     {
313         return structureStubInfo->bytecodeIndex;
314     }
315
316 } // namespace JSC
317
318 #endif // ENABLE(JIT)
319
320 #endif // StructureStubInfo_h