1d656247dd3da4082edff4ce303b9e827b4cdb2f
[WebKit-https.git] / Source / JavaScriptCore / jit / JITPropertyAccess32_64.cpp
1 /*
2  * Copyright (C) 2008, 2009, 2014, 2015 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
28 #if ENABLE(JIT)
29 #if USE(JSVALUE32_64)
30 #include "JIT.h"
31
32 #include "CodeBlock.h"
33 #include "DirectArguments.h"
34 #include "GCAwareJITStubRoutine.h"
35 #include "Interpreter.h"
36 #include "JITInlines.h"
37 #include "JSArray.h"
38 #include "JSEnvironmentRecord.h"
39 #include "JSFunction.h"
40 #include "LinkBuffer.h"
41 #include "ResultType.h"
42 #include "SlowPathCall.h"
43 #include "StructureStubInfo.h"
44 #include <wtf/StringPrintStream.h>
45
46
47 namespace JSC {
48     
49 void JIT::emit_op_put_by_index(Instruction* currentInstruction)
50 {
51     int base = currentInstruction[1].u.operand;
52     int property = currentInstruction[2].u.operand;
53     int value = currentInstruction[3].u.operand;
54
55     emitLoad(base, regT1, regT0);
56     emitLoad(value, regT3, regT2);
57     callOperation(operationPutByIndex, regT1, regT0, property, regT3, regT2);
58 }
59
60 void JIT::emit_op_put_getter_by_id(Instruction* currentInstruction)
61 {
62     int base = currentInstruction[1].u.operand;
63     int property = currentInstruction[2].u.operand;
64     int options = currentInstruction[3].u.operand;
65     int getter = currentInstruction[4].u.operand;
66
67     emitLoadPayload(base, regT1);
68     emitLoadPayload(getter, regT3);
69     callOperation(operationPutGetterById, regT1, m_codeBlock->identifier(property).impl(), options, regT3);
70 }
71
72 void JIT::emit_op_put_setter_by_id(Instruction* currentInstruction)
73 {
74     int base = currentInstruction[1].u.operand;
75     int property = currentInstruction[2].u.operand;
76     unsigned options = currentInstruction[3].u.operand;
77     int setter = currentInstruction[4].u.operand;
78
79     emitLoadPayload(base, regT1);
80     emitLoadPayload(setter, regT3);
81     callOperation(operationPutSetterById, regT1, m_codeBlock->identifier(property).impl(), options, regT3);
82 }
83
84 void JIT::emit_op_put_getter_setter_by_id(Instruction* currentInstruction)
85 {
86     int base = currentInstruction[1].u.operand;
87     int property = currentInstruction[2].u.operand;
88     unsigned attribute = currentInstruction[3].u.operand;
89     int getter = currentInstruction[4].u.operand;
90     int setter = currentInstruction[5].u.operand;
91
92     emitLoadPayload(base, regT1);
93     emitLoadPayload(getter, regT3);
94     emitLoadPayload(setter, regT4);
95     callOperation(operationPutGetterSetter, regT1, m_codeBlock->identifier(property).impl(), attribute, regT3, regT4);
96 }
97
98 void JIT::emit_op_put_getter_by_val(Instruction* currentInstruction)
99 {
100     int base = currentInstruction[1].u.operand;
101     int property = currentInstruction[2].u.operand;
102     int32_t attributes = currentInstruction[3].u.operand;
103     int getter = currentInstruction[4].u.operand;
104
105     emitLoadPayload(base, regT2);
106     emitLoad(property, regT1, regT0);
107     emitLoadPayload(getter, regT3);
108     callOperation(operationPutGetterByVal, regT2, regT1, regT0, attributes, regT3);
109 }
110
111 void JIT::emit_op_put_setter_by_val(Instruction* currentInstruction)
112 {
113     int base = currentInstruction[1].u.operand;
114     int property = currentInstruction[2].u.operand;
115     int32_t attributes = currentInstruction[3].u.operand;
116     int getter = currentInstruction[4].u.operand;
117
118     emitLoadPayload(base, regT2);
119     emitLoad(property, regT1, regT0);
120     emitLoadPayload(getter, regT3);
121     callOperation(operationPutSetterByVal, regT2, regT1, regT0, attributes, regT3);
122 }
123
124 void JIT::emit_op_del_by_id(Instruction* currentInstruction)
125 {
126     int dst = currentInstruction[1].u.operand;
127     int base = currentInstruction[2].u.operand;
128     int property = currentInstruction[3].u.operand;
129     emitLoad(base, regT1, regT0);
130     callOperation(operationDeleteByIdJSResult, dst, regT1, regT0, m_codeBlock->identifier(property).impl());
131 }
132
133 void JIT::emit_op_del_by_val(Instruction* currentInstruction)
134 {
135     int dst = currentInstruction[1].u.operand;
136     int base = currentInstruction[2].u.operand;
137     int property = currentInstruction[3].u.operand;
138     emitLoad2(base, regT1, regT0, property, regT3, regT2);
139     callOperation(operationDeleteByValJSResult, dst, regT1, regT0, regT3, regT2);
140 }
141
142 JIT::CodeRef JIT::stringGetByValStubGenerator(VM* vm)
143 {
144     JSInterfaceJIT jit(vm);
145     JumpList failures;
146     failures.append(jit.branchStructure(NotEqual, Address(regT0, JSCell::structureIDOffset()), vm->stringStructure.get()));
147     
148     // Load string length to regT1, and start the process of loading the data pointer into regT0
149     jit.load32(Address(regT0, ThunkHelpers::jsStringLengthOffset()), regT1);
150     jit.loadPtr(Address(regT0, ThunkHelpers::jsStringValueOffset()), regT0);
151     failures.append(jit.branchTest32(Zero, regT0));
152     
153     // Do an unsigned compare to simultaneously filter negative indices as well as indices that are too large
154     failures.append(jit.branch32(AboveOrEqual, regT2, regT1));
155     
156     // Load the character
157     JumpList is16Bit;
158     JumpList cont8Bit;
159     // Load the string flags
160     jit.loadPtr(Address(regT0, StringImpl::flagsOffset()), regT1);
161     jit.loadPtr(Address(regT0, StringImpl::dataOffset()), regT0);
162     is16Bit.append(jit.branchTest32(Zero, regT1, TrustedImm32(StringImpl::flagIs8Bit())));
163     jit.load8(BaseIndex(regT0, regT2, TimesOne, 0), regT0);
164     cont8Bit.append(jit.jump());
165     is16Bit.link(&jit);
166     jit.load16(BaseIndex(regT0, regT2, TimesTwo, 0), regT0);
167
168     cont8Bit.link(&jit);
169     
170     failures.append(jit.branch32(AboveOrEqual, regT0, TrustedImm32(0x100)));
171     jit.move(TrustedImmPtr(vm->smallStrings.singleCharacterStrings()), regT1);
172     jit.loadPtr(BaseIndex(regT1, regT0, ScalePtr, 0), regT0);
173     jit.move(TrustedImm32(JSValue::CellTag), regT1); // We null check regT0 on return so this is safe
174     jit.ret();
175
176     failures.link(&jit);
177     jit.move(TrustedImm32(0), regT0);
178     jit.ret();
179     
180     LinkBuffer patchBuffer(*vm, jit, GLOBAL_THUNK_ID);
181     return FINALIZE_CODE(patchBuffer, ("String get_by_val stub"));
182 }
183
184 void JIT::emit_op_get_by_val(Instruction* currentInstruction)
185 {
186     int dst = currentInstruction[1].u.operand;
187     int base = currentInstruction[2].u.operand;
188     int property = currentInstruction[3].u.operand;
189     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
190     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
191     
192     emitLoad2(base, regT1, regT0, property, regT3, regT2);
193     
194     emitJumpSlowCaseIfNotJSCell(base, regT1);
195     PatchableJump notIndex = patchableBranch32(NotEqual, regT3, TrustedImm32(JSValue::Int32Tag));
196     addSlowCase(notIndex);
197     emitArrayProfilingSiteWithCell(regT0, regT1, profile);
198     and32(TrustedImm32(IndexingShapeMask), regT1);
199
200     PatchableJump badType;
201     JumpList slowCases;
202     
203     JITArrayMode mode = chooseArrayMode(profile);
204     switch (mode) {
205     case JITInt32:
206         slowCases = emitInt32GetByVal(currentInstruction, badType);
207         break;
208     case JITDouble:
209         slowCases = emitDoubleGetByVal(currentInstruction, badType);
210         break;
211     case JITContiguous:
212         slowCases = emitContiguousGetByVal(currentInstruction, badType);
213         break;
214     case JITArrayStorage:
215         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
216         break;
217     default:
218         CRASH();
219     }
220     
221     addSlowCase(badType);
222     addSlowCase(slowCases);
223     
224     Label done = label();
225
226     if (!ASSERT_DISABLED) {
227         Jump resultOK = branch32(NotEqual, regT1, TrustedImm32(JSValue::EmptyValueTag));
228         abortWithReason(JITGetByValResultIsNotEmpty);
229         resultOK.link(this);
230     }
231
232     emitValueProfilingSite();
233     emitStore(dst, regT1, regT0);
234
235     Label nextHotPath = label();
236     
237     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, nextHotPath));
238 }
239
240 JIT::JumpList JIT::emitContiguousLoad(Instruction*, PatchableJump& badType, IndexingType expectedShape)
241 {
242     JumpList slowCases;
243     
244     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(expectedShape));
245     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
246     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength())));
247     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag
248     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload
249     slowCases.append(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
250     
251     return slowCases;
252 }
253
254 JIT::JumpList JIT::emitDoubleLoad(Instruction*, PatchableJump& badType)
255 {
256     JumpList slowCases;
257     
258     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(DoubleShape));
259     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
260     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength())));
261     loadDouble(BaseIndex(regT3, regT2, TimesEight), fpRegT0);
262     slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
263     
264     return slowCases;
265 }
266
267 JIT::JumpList JIT::emitArrayStorageLoad(Instruction*, PatchableJump& badType)
268 {
269     JumpList slowCases;
270     
271     add32(TrustedImm32(-ArrayStorageShape), regT1, regT3);
272     badType = patchableBranch32(Above, regT3, TrustedImm32(SlowPutArrayStorageShape - ArrayStorageShape));
273     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
274     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, ArrayStorage::vectorLengthOffset())));
275     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag
276     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload
277     slowCases.append(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
278     
279     return slowCases;
280 }
281
282 JITGetByIdGenerator JIT::emitGetByValWithCachedId(Instruction* currentInstruction, const Identifier& propertyName, Jump& fastDoneCase, Jump& slowDoneCase, JumpList& slowCases)
283 {
284     int dst = currentInstruction[1].u.operand;
285
286     // base: tag(regT1), payload(regT0)
287     // property: tag(regT3), payload(regT2)
288     // scratch: regT4
289
290     slowCases.append(branch32(NotEqual, regT3, TrustedImm32(JSValue::CellTag)));
291     emitIdentifierCheck(regT2, regT4, propertyName, slowCases);
292
293     JITGetByIdGenerator gen(
294         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
295         propertyName.impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::Get);
296     gen.generateFastPath(*this);
297
298     fastDoneCase = jump();
299
300     Label coldPathBegin = label();
301     gen.slowPathJump().link(this);
302
303     Call call = callOperation(WithProfile, operationGetByIdOptimize, dst, gen.stubInfo(), regT1, regT0, propertyName.impl());
304     gen.reportSlowPathCall(coldPathBegin, call);
305     slowDoneCase = jump();
306
307     return gen;
308 }
309
310 void JIT::emitSlow_op_get_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
311 {
312     int dst = currentInstruction[1].u.operand;
313     int base = currentInstruction[2].u.operand;
314     int property = currentInstruction[3].u.operand;
315     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
316
317     linkSlowCaseIfNotJSCell(iter, base); // base cell check
318     linkSlowCase(iter); // property int32 check
319
320     Jump nonCell = jump();
321     linkSlowCase(iter); // base array check
322     Jump notString = branchStructure(NotEqual, Address(regT0, JSCell::structureIDOffset()), m_vm->stringStructure.get());
323     emitNakedCall(m_vm->getCTIStub(stringGetByValStubGenerator).code());
324     Jump failed = branchTestPtr(Zero, regT0);
325     emitStore(dst, regT1, regT0);
326     emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_get_by_val));
327     failed.link(this);
328     notString.link(this);
329     nonCell.link(this);
330
331     linkSlowCase(iter); // vector length check
332     linkSlowCase(iter); // empty value
333     
334     Label slowPath = label();
335     
336     emitLoad(base, regT1, regT0);
337     emitLoad(property, regT3, regT2);
338     Call call = callOperation(operationGetByValOptimize, dst, regT1, regT0, regT3, regT2, byValInfo);
339
340     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
341     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
342     m_byValInstructionIndex++;
343
344     emitValueProfilingSite();
345 }
346
347 void JIT::emit_op_put_by_val(Instruction* currentInstruction)
348 {
349     int base = currentInstruction[1].u.operand;
350     int property = currentInstruction[2].u.operand;
351     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
352     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
353     
354     emitLoad2(base, regT1, regT0, property, regT3, regT2);
355     
356     emitJumpSlowCaseIfNotJSCell(base, regT1);
357     PatchableJump notIndex = patchableBranch32(NotEqual, regT3, TrustedImm32(JSValue::Int32Tag));
358     addSlowCase(notIndex);
359     emitArrayProfilingSiteWithCell(regT0, regT1, profile);
360     and32(TrustedImm32(IndexingShapeMask), regT1);
361     
362     PatchableJump badType;
363     JumpList slowCases;
364     
365     JITArrayMode mode = chooseArrayMode(profile);
366     switch (mode) {
367     case JITInt32:
368         slowCases = emitInt32PutByVal(currentInstruction, badType);
369         break;
370     case JITDouble:
371         slowCases = emitDoublePutByVal(currentInstruction, badType);
372         break;
373     case JITContiguous:
374         slowCases = emitContiguousPutByVal(currentInstruction, badType);
375         break;
376     case JITArrayStorage:
377         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
378         break;
379     default:
380         CRASH();
381         break;
382     }
383     
384     addSlowCase(badType);
385     addSlowCase(slowCases);
386     
387     Label done = label();
388     
389     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, done));
390 }
391
392 JIT::JumpList JIT::emitGenericContiguousPutByVal(Instruction* currentInstruction, PatchableJump& badType, IndexingType indexingShape)
393 {
394     int base = currentInstruction[1].u.operand;
395     int value = currentInstruction[3].u.operand;
396     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
397     
398     JumpList slowCases;
399     
400     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(ContiguousShape));
401     
402     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
403     Jump outOfBounds = branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength()));
404     
405     Label storeResult = label();
406     emitLoad(value, regT1, regT0);
407     switch (indexingShape) {
408     case Int32Shape:
409         slowCases.append(branch32(NotEqual, regT1, TrustedImm32(JSValue::Int32Tag)));
410         store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
411         store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
412         break;
413     case ContiguousShape:
414         store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
415         store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
416         emitLoad(base, regT2, regT3);
417         emitWriteBarrier(base, value, ShouldFilterValue);
418         break;
419     case DoubleShape: {
420         Jump notInt = branch32(NotEqual, regT1, TrustedImm32(JSValue::Int32Tag));
421         convertInt32ToDouble(regT0, fpRegT0);
422         Jump ready = jump();
423         notInt.link(this);
424         moveIntsToDouble(regT0, regT1, fpRegT0, fpRegT1);
425         slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
426         ready.link(this);
427         storeDouble(fpRegT0, BaseIndex(regT3, regT2, TimesEight));
428         break;
429     }
430     default:
431         CRASH();
432         break;
433     }
434         
435     Jump done = jump();
436     
437     outOfBounds.link(this);
438     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfVectorLength())));
439     
440     emitArrayProfileStoreToHoleSpecialCase(profile);
441     
442     add32(TrustedImm32(1), regT2, regT1);
443     store32(regT1, Address(regT3, Butterfly::offsetOfPublicLength()));
444     jump().linkTo(storeResult, this);
445     
446     done.link(this);
447     
448     return slowCases;
449 }
450
451 JIT::JumpList JIT::emitArrayStoragePutByVal(Instruction* currentInstruction, PatchableJump& badType)
452 {
453     int base = currentInstruction[1].u.operand;
454     int value = currentInstruction[3].u.operand;
455     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
456     
457     JumpList slowCases;
458     
459     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(ArrayStorageShape));
460     
461     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
462     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, ArrayStorage::vectorLengthOffset())));
463
464     Jump empty = branch32(Equal, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), TrustedImm32(JSValue::EmptyValueTag));
465     
466     Label storeResult(this);
467     emitLoad(value, regT1, regT0);
468     store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.payload))); // payload
469     store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0]) + OBJECT_OFFSETOF(JSValue, u.asBits.tag))); // tag
470     Jump end = jump();
471     
472     empty.link(this);
473     emitArrayProfileStoreToHoleSpecialCase(profile);
474     add32(TrustedImm32(1), Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector)));
475     branch32(Below, regT2, Address(regT3, ArrayStorage::lengthOffset())).linkTo(storeResult, this);
476     
477     add32(TrustedImm32(1), regT2, regT0);
478     store32(regT0, Address(regT3, ArrayStorage::lengthOffset()));
479     jump().linkTo(storeResult, this);
480     
481     end.link(this);
482     
483     emitWriteBarrier(base, value, ShouldFilterValue);
484     
485     return slowCases;
486 }
487
488 JITPutByIdGenerator JIT::emitPutByValWithCachedId(Instruction* currentInstruction, PutKind putKind, const Identifier& propertyName, JumpList& doneCases, JumpList& slowCases)
489 {
490     // base: tag(regT1), payload(regT0)
491     // property: tag(regT3), payload(regT2)
492
493     int base = currentInstruction[1].u.operand;
494     int value = currentInstruction[3].u.operand;
495
496     slowCases.append(branch32(NotEqual, regT3, TrustedImm32(JSValue::CellTag)));
497     emitIdentifierCheck(regT2, regT2, propertyName, slowCases);
498
499     // Write barrier breaks the registers. So after issuing the write barrier,
500     // reload the registers.
501     emitWriteBarrier(base, value, ShouldFilterBase);
502     emitLoadPayload(base, regT0);
503     emitLoad(value, regT3, regT2);
504
505     JITPutByIdGenerator gen(
506         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
507         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT3, regT2), regT1, m_codeBlock->ecmaMode(), putKind);
508     gen.generateFastPath(*this);
509     doneCases.append(jump());
510
511     Label coldPathBegin = label();
512     gen.slowPathJump().link(this);
513
514     // JITPutByIdGenerator only preserve the value and the base's payload, we have to reload the tag.
515     emitLoadTag(base, regT1);
516
517     Call call = callOperation(gen.slowPathFunction(), gen.stubInfo(), regT3, regT2, regT1, regT0, propertyName.impl());
518     gen.reportSlowPathCall(coldPathBegin, call);
519     doneCases.append(jump());
520
521     return gen;
522 }
523
524 void JIT::emitSlow_op_put_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
525 {
526     int base = currentInstruction[1].u.operand;
527     int property = currentInstruction[2].u.operand;
528     int value = currentInstruction[3].u.operand;
529     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
530     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
531     
532     linkSlowCaseIfNotJSCell(iter, base); // base cell check
533     linkSlowCase(iter); // property int32 check
534     linkSlowCase(iter); // base not array check
535     
536     JITArrayMode mode = chooseArrayMode(profile);
537     switch (mode) {
538     case JITInt32:
539     case JITDouble:
540         linkSlowCase(iter); // value type check
541         break;
542     default:
543         break;
544     }
545     
546     Jump skipProfiling = jump();
547     linkSlowCase(iter); // out of bounds
548     emitArrayProfileOutOfBoundsSpecialCase(profile);
549     skipProfiling.link(this);
550
551     Label slowPath = label();
552     
553     bool isDirect = m_interpreter->getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
554
555 #if CPU(X86)
556     // FIXME: We only have 5 temp registers, but need 6 to make this call, therefore we materialize
557     // our own call. When we finish moving JSC to the C call stack, we'll get another register so
558     // we can use the normal case.
559     resetCallArguments();
560     addCallArgument(GPRInfo::callFrameRegister);
561     emitLoad(base, regT0, regT1);
562     addCallArgument(regT1);
563     addCallArgument(regT0);
564     emitLoad(property, regT0, regT1);
565     addCallArgument(regT1);
566     addCallArgument(regT0);
567     emitLoad(value, regT0, regT1);
568     addCallArgument(regT1);
569     addCallArgument(regT0);
570     addCallArgument(TrustedImmPtr(byValInfo));
571     Call call = appendCallWithExceptionCheck(isDirect ? operationDirectPutByValOptimize : operationPutByValOptimize);
572 #else
573     // The register selection below is chosen to reduce register swapping on ARM.
574     // Swapping shouldn't happen on other platforms.
575     emitLoad(base, regT2, regT1);
576     emitLoad(property, regT3, regT0);
577     emitLoad(value, regT5, regT4);
578     Call call = callOperation(isDirect ? operationDirectPutByValOptimize : operationPutByValOptimize, regT2, regT1, regT3, regT0, regT5, regT4, byValInfo);
579 #endif
580
581     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
582     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
583     m_byValInstructionIndex++;
584 }
585
586 void JIT::emit_op_try_get_by_id(Instruction* currentInstruction)
587 {
588     int dst = currentInstruction[1].u.operand;
589     int base = currentInstruction[2].u.operand;
590     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
591
592     emitLoad(base, regT1, regT0);
593     emitJumpSlowCaseIfNotJSCell(base, regT1);
594
595     JITGetByIdGenerator gen(
596         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
597         ident->impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::GetPure);
598     gen.generateFastPath(*this);
599     addSlowCase(gen.slowPathJump());
600     m_getByIds.append(gen);
601     
602     emitStore(dst, regT1, regT0);
603 }
604
605 void JIT::emitSlow_op_try_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
606 {
607     int resultVReg = currentInstruction[1].u.operand;
608     int baseVReg = currentInstruction[2].u.operand;
609     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
610
611     linkSlowCaseIfNotJSCell(iter, baseVReg);
612     linkSlowCase(iter);
613
614     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
615
616     Label coldPathBegin = label();
617
618     Call call = callOperation(operationTryGetByIdOptimize, resultVReg, gen.stubInfo(), regT1, regT0, ident->impl());
619     
620     gen.reportSlowPathCall(coldPathBegin, call);
621 }
622
623
624 void JIT::emit_op_get_by_id(Instruction* currentInstruction)
625 {
626     int dst = currentInstruction[1].u.operand;
627     int base = currentInstruction[2].u.operand;
628     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
629     
630     emitLoad(base, regT1, regT0);
631     emitJumpSlowCaseIfNotJSCell(base, regT1);
632
633     if (*ident == m_vm->propertyNames->length && shouldEmitProfiling())
634         emitArrayProfilingSiteForBytecodeIndexWithCell(regT0, regT2, m_bytecodeOffset);
635
636     JITGetByIdGenerator gen(
637         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
638         ident->impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::Get);
639     gen.generateFastPath(*this);
640     addSlowCase(gen.slowPathJump());
641     m_getByIds.append(gen);
642
643     emitValueProfilingSite();
644     emitStore(dst, regT1, regT0);
645 }
646
647 void JIT::emitSlow_op_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
648 {
649     int resultVReg = currentInstruction[1].u.operand;
650     int baseVReg = currentInstruction[2].u.operand;
651     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
652
653     linkSlowCaseIfNotJSCell(iter, baseVReg);
654     linkSlowCase(iter);
655
656     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
657     
658     Label coldPathBegin = label();
659     
660     Call call = callOperation(WithProfile, operationGetByIdOptimize, resultVReg, gen.stubInfo(), regT1, regT0, ident->impl());
661     
662     gen.reportSlowPathCall(coldPathBegin, call);
663 }
664
665 void JIT::emit_op_put_by_id(Instruction* currentInstruction)
666 {
667     // In order to be able to patch both the Structure, and the object offset, we store one pointer,
668     // to just after the arguments have been loaded into registers 'hotPathBegin', and we generate code
669     // such that the Structure & offset are always at the same distance from this.
670     
671     int base = currentInstruction[1].u.operand;
672     int value = currentInstruction[3].u.operand;
673     int direct = currentInstruction[8].u.putByIdFlags & PutByIdIsDirect;
674     
675     emitWriteBarrier(base, value, ShouldFilterBase);
676
677     emitLoad2(base, regT1, regT0, value, regT3, regT2);
678     
679     emitJumpSlowCaseIfNotJSCell(base, regT1);
680
681     JITPutByIdGenerator gen(
682         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
683         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT3, regT2),
684         regT1, m_codeBlock->ecmaMode(), direct ? Direct : NotDirect);
685     
686     gen.generateFastPath(*this);
687     addSlowCase(gen.slowPathJump());
688     
689     m_putByIds.append(gen);
690 }
691
692 void JIT::emitSlow_op_put_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
693 {
694     int base = currentInstruction[1].u.operand;
695     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[2].u.operand));
696
697     linkSlowCaseIfNotJSCell(iter, base);
698     linkSlowCase(iter);
699     
700     Label coldPathBegin(this);
701
702     // JITPutByIdGenerator only preserve the value and the base's payload, we have to reload the tag.
703     emitLoadTag(base, regT1);
704
705     JITPutByIdGenerator& gen = m_putByIds[m_putByIdIndex++];
706     
707     Call call = callOperation(
708         gen.slowPathFunction(), gen.stubInfo(), regT3, regT2, regT1, regT0, ident->impl());
709     
710     gen.reportSlowPathCall(coldPathBegin, call);
711 }
712
713 void JIT::emitVarInjectionCheck(bool needsVarInjectionChecks)
714 {
715     if (!needsVarInjectionChecks)
716         return;
717     addSlowCase(branch8(Equal, AbsoluteAddress(m_codeBlock->globalObject()->varInjectionWatchpoint()->addressOfState()), TrustedImm32(IsInvalidated)));
718 }
719
720 void JIT::emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth)
721 {
722     emitVarInjectionCheck(needsVarInjectionChecks);
723     move(TrustedImm32(JSValue::CellTag), regT1);
724     emitLoadPayload(scope, regT0);
725     for (unsigned i = 0; i < depth; ++i)
726         loadPtr(Address(regT0, JSScope::offsetOfNext()), regT0);
727     emitStore(dst, regT1, regT0);
728 }
729
730 void JIT::emit_op_resolve_scope(Instruction* currentInstruction)
731 {
732     int dst = currentInstruction[1].u.operand;
733     int scope = currentInstruction[2].u.operand;
734     ResolveType resolveType = static_cast<ResolveType>(currentInstruction[4].u.operand);
735     unsigned depth = currentInstruction[5].u.operand;
736     auto emitCode = [&] (ResolveType resolveType) {
737         switch (resolveType) {
738         case GlobalProperty:
739         case GlobalVar:
740         case GlobalLexicalVar:
741         case GlobalPropertyWithVarInjectionChecks:
742         case GlobalVarWithVarInjectionChecks: 
743         case GlobalLexicalVarWithVarInjectionChecks: {
744             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
745             RELEASE_ASSERT(constantScope);
746             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
747             move(TrustedImm32(JSValue::CellTag), regT1);
748             move(TrustedImmPtr(constantScope), regT0);
749             emitStore(dst, regT1, regT0);
750             break;
751         }
752         case ClosureVar:
753         case ClosureVarWithVarInjectionChecks:
754             emitResolveClosure(dst, scope, needsVarInjectionChecks(resolveType), depth);
755             break;
756         case ModuleVar:
757             move(TrustedImm32(JSValue::CellTag), regT1);
758             move(TrustedImmPtr(currentInstruction[6].u.jsCell.get()), regT0);
759             emitStore(dst, regT1, regT0);
760             break;
761         case Dynamic:
762             addSlowCase(jump());
763             break;
764         case LocalClosureVar:
765         case UnresolvedProperty:
766         case UnresolvedPropertyWithVarInjectionChecks:
767             RELEASE_ASSERT_NOT_REACHED();
768         }
769     };
770     switch (resolveType) {
771     case UnresolvedProperty:
772     case UnresolvedPropertyWithVarInjectionChecks: {
773         JumpList skipToEnd;
774         load32(&currentInstruction[4], regT0);
775
776         Jump notGlobalProperty = branch32(NotEqual, regT0, TrustedImm32(GlobalProperty));
777         emitCode(GlobalProperty);
778         skipToEnd.append(jump());
779         notGlobalProperty.link(this);
780
781         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
782         emitCode(GlobalPropertyWithVarInjectionChecks);
783         skipToEnd.append(jump());
784         notGlobalPropertyWithVarInjections.link(this);
785
786         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
787         emitCode(GlobalLexicalVar);
788         skipToEnd.append(jump());
789         notGlobalLexicalVar.link(this);
790
791         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
792         emitCode(GlobalLexicalVarWithVarInjectionChecks);
793         skipToEnd.append(jump());
794         notGlobalLexicalVarWithVarInjections.link(this);
795
796         addSlowCase(jump());
797         skipToEnd.link(this);
798         break;
799     }
800
801     default:
802         emitCode(resolveType);
803         break;
804     }
805 }
806
807 void JIT::emitSlow_op_resolve_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
808 {
809     ResolveType resolveType = static_cast<ResolveType>(currentInstruction[4].u.operand);
810
811     if (resolveType == GlobalProperty || resolveType == GlobalVar || resolveType == ClosureVar || resolveType == GlobalLexicalVar || resolveType == ModuleVar)
812         return;
813     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
814         linkSlowCase(iter); // Var injections check for GlobalPropertyWithVarInjectionChecks.
815         linkSlowCase(iter); // Var injections check for GlobalLexicalVarWithVarInjectionChecks.
816     }
817
818     linkSlowCase(iter);
819     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_resolve_scope);
820     slowPathCall.call();
821 }
822
823 void JIT::emitLoadWithStructureCheck(int scope, Structure** structureSlot)
824 {
825     emitLoad(scope, regT1, regT0);
826     loadPtr(structureSlot, regT2);
827     addSlowCase(branchPtr(NotEqual, Address(regT0, JSCell::structureIDOffset()), regT2));
828 }
829
830 void JIT::emitGetVarFromPointer(JSValue* operand, GPRReg tag, GPRReg payload)
831 {
832     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
833     load32(bitwise_cast<void*>(rawAddress + TagOffset), tag);
834     load32(bitwise_cast<void*>(rawAddress + PayloadOffset), payload);
835 }
836 void JIT::emitGetVarFromIndirectPointer(JSValue** operand, GPRReg tag, GPRReg payload)
837 {
838     loadPtr(operand, payload);
839     load32(Address(payload, TagOffset), tag);
840     load32(Address(payload, PayloadOffset), payload);
841 }
842
843 void JIT::emitGetClosureVar(int scope, uintptr_t operand)
844 {
845     emitLoad(scope, regT1, regT0);
846     load32(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + TagOffset), regT1);
847     load32(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset), regT0);
848 }
849
850 void JIT::emit_op_get_from_scope(Instruction* currentInstruction)
851 {
852     int dst = currentInstruction[1].u.operand;
853     int scope = currentInstruction[2].u.operand;
854     ResolveType resolveType = GetPutInfo(currentInstruction[4].u.operand).resolveType();
855     Structure** structureSlot = currentInstruction[5].u.structure.slot();
856     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
857     
858     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
859         switch (resolveType) {
860         case GlobalProperty:
861         case GlobalPropertyWithVarInjectionChecks: {
862             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
863             GPRReg base = regT2;
864             GPRReg resultTag = regT1;
865             GPRReg resultPayload = regT0;
866             GPRReg offset = regT3;
867             
868             move(regT0, base);
869             load32(operandSlot, offset);
870             if (!ASSERT_DISABLED) {
871                 Jump isOutOfLine = branch32(GreaterThanOrEqual, offset, TrustedImm32(firstOutOfLineOffset));
872                 abortWithReason(JITOffsetIsNotOutOfLine);
873                 isOutOfLine.link(this);
874             }
875             loadPtr(Address(base, JSObject::butterflyOffset()), base);
876             neg32(offset);
877             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultPayload);
878             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultTag);
879             break;
880         }
881         case GlobalVar:
882         case GlobalVarWithVarInjectionChecks:
883         case GlobalLexicalVar:
884         case GlobalLexicalVarWithVarInjectionChecks:
885             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
886             if (indirectLoadForOperand)
887                 emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
888             else
889                 emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
890             if (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks) // TDZ check.
891                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
892             break;
893         case ClosureVar:
894         case ClosureVarWithVarInjectionChecks:
895             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
896             emitGetClosureVar(scope, *operandSlot);
897             break;
898         case Dynamic:
899             addSlowCase(jump());
900             break;
901         case ModuleVar:
902         case LocalClosureVar:
903         case UnresolvedProperty:
904         case UnresolvedPropertyWithVarInjectionChecks:
905             RELEASE_ASSERT_NOT_REACHED();
906         }
907     };
908
909     switch (resolveType) {
910     case UnresolvedProperty:
911     case UnresolvedPropertyWithVarInjectionChecks: {
912         JumpList skipToEnd;
913         load32(&currentInstruction[4], regT0);
914         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
915
916         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
917         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
918         isGlobalProperty.link(this);
919         emitCode(GlobalProperty, false);
920         skipToEnd.append(jump());
921         notGlobalPropertyWithVarInjections.link(this);
922
923         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
924         emitCode(GlobalLexicalVar, true);
925         skipToEnd.append(jump());
926         notGlobalLexicalVar.link(this);
927
928         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
929         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
930         skipToEnd.append(jump());
931         notGlobalLexicalVarWithVarInjections.link(this);
932
933         addSlowCase(jump());
934
935         skipToEnd.link(this);
936         break;
937     }
938
939     default:
940         emitCode(resolveType, false);
941         break;
942     }
943     emitValueProfilingSite();
944     emitStore(dst, regT1, regT0);
945 }
946
947 void JIT::emitSlow_op_get_from_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
948 {
949     int dst = currentInstruction[1].u.operand;
950     ResolveType resolveType = GetPutInfo(currentInstruction[4].u.operand).resolveType();
951
952     if (resolveType == GlobalVar || resolveType == ClosureVar)
953         return;
954
955     if (resolveType == GlobalLexicalVarWithVarInjectionChecks) // Var Injections check.
956         linkSlowCase(iter);
957
958     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
959         // GlobalProperty/GlobalPropertyWithVarInjectionChecks
960         linkSlowCase(iter); // emitLoadWithStructureCheck
961         // GlobalLexicalVar
962         linkSlowCase(iter); // TDZ check.
963         // GlobalLexicalVarWithVarInjectionChecks.
964         linkSlowCase(iter); // var injection check.
965         linkSlowCase(iter); // TDZ check.
966     }
967
968     linkSlowCase(iter);
969     callOperation(WithProfile, operationGetFromScope, dst, currentInstruction);
970 }
971
972 void JIT::emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet* set)
973 {
974     emitLoad(value, regT1, regT0);
975     emitNotifyWrite(set);
976     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
977     store32(regT1, bitwise_cast<void*>(rawAddress + TagOffset));
978     store32(regT0, bitwise_cast<void*>(rawAddress + PayloadOffset));
979 }
980
981 void JIT::emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet** indirectWatchpointSet)
982 {
983     emitLoad(value, regT1, regT0);
984     loadPtr(indirectWatchpointSet, regT2);
985     emitNotifyWrite(regT2);
986     loadPtr(addressOfOperand, regT2);
987     store32(regT1, Address(regT2, TagOffset));
988     store32(regT0, Address(regT2, PayloadOffset));
989 }
990
991 void JIT::emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet* set)
992 {
993     emitLoad(value, regT3, regT2);
994     emitLoad(scope, regT1, regT0);
995     emitNotifyWrite(set);
996     store32(regT3, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + TagOffset));
997     store32(regT2, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset));
998 }
999
1000 void JIT::emit_op_put_to_scope(Instruction* currentInstruction)
1001 {
1002     int scope = currentInstruction[1].u.operand;
1003     int value = currentInstruction[3].u.operand;
1004     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
1005     ResolveType resolveType = getPutInfo.resolveType();
1006     Structure** structureSlot = currentInstruction[5].u.structure.slot();
1007     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
1008     
1009     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
1010         switch (resolveType) {
1011         case GlobalProperty:
1012         case GlobalPropertyWithVarInjectionChecks: {
1013             emitWriteBarrier(m_codeBlock->globalObject(), value, ShouldFilterValue);
1014             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
1015             emitLoad(value, regT3, regT2);
1016             
1017             loadPtr(Address(regT0, JSObject::butterflyOffset()), regT0);
1018             loadPtr(operandSlot, regT1);
1019             negPtr(regT1);
1020             store32(regT3, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag)));
1021             store32(regT2, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload)));
1022             break;
1023         }
1024         case GlobalVar:
1025         case GlobalVarWithVarInjectionChecks:
1026         case GlobalLexicalVar:
1027         case GlobalLexicalVarWithVarInjectionChecks: {
1028             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
1029             RELEASE_ASSERT(constantScope);
1030             emitWriteBarrier(constantScope, value, ShouldFilterValue);
1031             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1032             if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) {
1033                 // We need to do a TDZ check here because we can't always prove we need to emit TDZ checks statically.
1034                 if (indirectLoadForOperand)
1035                     emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
1036                 else
1037                     emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
1038                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
1039             }
1040             if (indirectLoadForOperand)
1041                 emitPutGlobalVariableIndirect(bitwise_cast<JSValue**>(operandSlot), value, bitwise_cast<WatchpointSet**>(&currentInstruction[5]));
1042             else
1043                 emitPutGlobalVariable(bitwise_cast<JSValue*>(*operandSlot), value, currentInstruction[5].u.watchpointSet);
1044             break;
1045         }
1046         case LocalClosureVar:
1047         case ClosureVar:
1048         case ClosureVarWithVarInjectionChecks:
1049             emitWriteBarrier(scope, value, ShouldFilterValue);
1050             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1051             emitPutClosureVar(scope, *operandSlot, value, currentInstruction[5].u.watchpointSet);
1052             break;
1053         case ModuleVar:
1054         case Dynamic:
1055             addSlowCase(jump());
1056             break;
1057         case UnresolvedProperty:
1058         case UnresolvedPropertyWithVarInjectionChecks:
1059             RELEASE_ASSERT_NOT_REACHED();
1060         }
1061     };
1062
1063     switch (resolveType) {
1064     case UnresolvedProperty:
1065     case UnresolvedPropertyWithVarInjectionChecks: {
1066         JumpList skipToEnd;
1067         load32(&currentInstruction[4], regT0);
1068         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
1069
1070         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
1071         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
1072         isGlobalProperty.link(this);
1073         emitCode(GlobalProperty, false);
1074         skipToEnd.append(jump());
1075         notGlobalPropertyWithVarInjections.link(this);
1076
1077         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
1078         emitCode(GlobalLexicalVar, true);
1079         skipToEnd.append(jump());
1080         notGlobalLexicalVar.link(this);
1081
1082         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
1083         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
1084         skipToEnd.append(jump());
1085         notGlobalLexicalVarWithVarInjections.link(this);
1086
1087         addSlowCase(jump());
1088
1089         skipToEnd.link(this);
1090         break;
1091     }
1092
1093     default:
1094         emitCode(resolveType, false);
1095         break;
1096     }
1097 }
1098
1099 void JIT::emitSlow_op_put_to_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1100 {
1101     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
1102     ResolveType resolveType = getPutInfo.resolveType();
1103     unsigned linkCount = 0;
1104     if (resolveType != GlobalVar && resolveType != ClosureVar && resolveType != LocalClosureVar && resolveType != GlobalLexicalVar)
1105         linkCount++;
1106     if (resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks 
1107         || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks 
1108         || resolveType == ClosureVar || resolveType == ClosureVarWithVarInjectionChecks
1109         || resolveType == LocalClosureVar)
1110         linkCount++;
1111     if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) // TDZ check.
1112         linkCount++;
1113     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
1114         // GlobalProperty/GlobalPropertyWithVarInjectionsCheck
1115         linkCount++; // emitLoadWithStructureCheck
1116
1117         // GlobalLexicalVar
1118         bool needsTDZCheck = !isInitialization(getPutInfo.initializationMode());
1119         if (needsTDZCheck)
1120             linkCount++;
1121         linkCount++; // Notify write check.
1122
1123         // GlobalLexicalVarWithVarInjectionsCheck
1124         linkCount++; // var injection check.
1125         if (needsTDZCheck)
1126             linkCount++;
1127         linkCount++; // Notify write check.
1128     }
1129     if (!linkCount)
1130         return;
1131     while (linkCount--)
1132         linkSlowCase(iter);
1133
1134     if (resolveType == ModuleVar) {
1135         JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_throw_strict_mode_readonly_property_write_error);
1136         slowPathCall.call();
1137     } else
1138         callOperation(operationPutToScope, currentInstruction);
1139 }
1140
1141 void JIT::emit_op_get_from_arguments(Instruction* currentInstruction)
1142 {
1143     int dst = currentInstruction[1].u.operand;
1144     int arguments = currentInstruction[2].u.operand;
1145     int index = currentInstruction[3].u.operand;
1146     
1147     emitLoadPayload(arguments, regT0);
1148     load32(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + TagOffset), regT1);
1149     load32(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + PayloadOffset), regT0);
1150     emitValueProfilingSite();
1151     emitStore(dst, regT1, regT0);
1152 }
1153
1154 void JIT::emit_op_put_to_arguments(Instruction* currentInstruction)
1155 {
1156     int arguments = currentInstruction[1].u.operand;
1157     int index = currentInstruction[2].u.operand;
1158     int value = currentInstruction[3].u.operand;
1159     
1160     emitWriteBarrier(arguments, value, ShouldFilterValue);
1161     
1162     emitLoadPayload(arguments, regT0);
1163     emitLoad(value, regT1, regT2);
1164     store32(regT1, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + TagOffset));
1165     store32(regT2, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + PayloadOffset));
1166 }
1167
1168 void JIT::emit_op_get_by_id_with_this(Instruction* currentInstruction)
1169 {
1170     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_get_by_id_with_this);
1171     slowPathCall.call();
1172 }
1173
1174 void JIT::emit_op_get_by_val_with_this(Instruction* currentInstruction)
1175 {
1176     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_get_by_val_with_this);
1177     slowPathCall.call();
1178 }
1179
1180 void JIT::emit_op_put_by_id_with_this(Instruction* currentInstruction)
1181 {
1182     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_put_by_id_with_this);
1183     slowPathCall.call();
1184 }
1185
1186 void JIT::emit_op_put_by_val_with_this(Instruction* currentInstruction)
1187 {
1188     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_put_by_val_with_this);
1189     slowPathCall.call();
1190 }
1191
1192 } // namespace JSC
1193
1194 #endif // USE(JSVALUE32_64)
1195 #endif // ENABLE(JIT)