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