Unreviewed, rolling out r199073.
[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));
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_get_by_id(Instruction* currentInstruction)
577 {
578     int dst = currentInstruction[1].u.operand;
579     int base = currentInstruction[2].u.operand;
580     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
581     
582     emitLoad(base, regT1, regT0);
583     emitJumpSlowCaseIfNotJSCell(base, regT1);
584
585     if (*ident == m_vm->propertyNames->length && shouldEmitProfiling())
586         emitArrayProfilingSiteForBytecodeIndexWithCell(regT0, regT2, m_bytecodeOffset);
587
588     JITGetByIdGenerator gen(
589         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
590         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0));
591     gen.generateFastPath(*this);
592     addSlowCase(gen.slowPathJump());
593     m_getByIds.append(gen);
594
595     emitValueProfilingSite();
596     emitStore(dst, regT1, regT0);
597 }
598
599 void JIT::emitSlow_op_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
600 {
601     int resultVReg = currentInstruction[1].u.operand;
602     int baseVReg = currentInstruction[2].u.operand;
603     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
604
605     linkSlowCaseIfNotJSCell(iter, baseVReg);
606     linkSlowCase(iter);
607
608     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
609     
610     Label coldPathBegin = label();
611     
612     Call call = callOperation(WithProfile, operationGetByIdOptimize, resultVReg, gen.stubInfo(), regT1, regT0, ident->impl());
613     
614     gen.reportSlowPathCall(coldPathBegin, call);
615 }
616
617 void JIT::emit_op_put_by_id(Instruction* currentInstruction)
618 {
619     // In order to be able to patch both the Structure, and the object offset, we store one pointer,
620     // to just after the arguments have been loaded into registers 'hotPathBegin', and we generate code
621     // such that the Structure & offset are always at the same distance from this.
622     
623     int base = currentInstruction[1].u.operand;
624     int value = currentInstruction[3].u.operand;
625     int direct = currentInstruction[8].u.putByIdFlags & PutByIdIsDirect;
626     
627     emitWriteBarrier(base, value, ShouldFilterBase);
628
629     emitLoad2(base, regT1, regT0, value, regT3, regT2);
630     
631     emitJumpSlowCaseIfNotJSCell(base, regT1);
632
633     JITPutByIdGenerator gen(
634         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
635         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT3, regT2),
636         regT1, m_codeBlock->ecmaMode(), direct ? Direct : NotDirect);
637     
638     gen.generateFastPath(*this);
639     addSlowCase(gen.slowPathJump());
640     
641     m_putByIds.append(gen);
642 }
643
644 void JIT::emitSlow_op_put_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
645 {
646     int base = currentInstruction[1].u.operand;
647     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[2].u.operand));
648
649     linkSlowCaseIfNotJSCell(iter, base);
650     linkSlowCase(iter);
651     
652     Label coldPathBegin(this);
653
654     // JITPutByIdGenerator only preserve the value and the base's payload, we have to reload the tag.
655     emitLoadTag(base, regT1);
656
657     JITPutByIdGenerator& gen = m_putByIds[m_putByIdIndex++];
658     
659     Call call = callOperation(
660         gen.slowPathFunction(), gen.stubInfo(), regT3, regT2, regT1, regT0, ident->impl());
661     
662     gen.reportSlowPathCall(coldPathBegin, call);
663 }
664
665 void JIT::emitVarInjectionCheck(bool needsVarInjectionChecks)
666 {
667     if (!needsVarInjectionChecks)
668         return;
669     addSlowCase(branch8(Equal, AbsoluteAddress(m_codeBlock->globalObject()->varInjectionWatchpoint()->addressOfState()), TrustedImm32(IsInvalidated)));
670 }
671
672 void JIT::emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth)
673 {
674     emitVarInjectionCheck(needsVarInjectionChecks);
675     move(TrustedImm32(JSValue::CellTag), regT1);
676     emitLoadPayload(scope, regT0);
677     for (unsigned i = 0; i < depth; ++i)
678         loadPtr(Address(regT0, JSScope::offsetOfNext()), regT0);
679     emitStore(dst, regT1, regT0);
680 }
681
682 void JIT::emit_op_resolve_scope(Instruction* currentInstruction)
683 {
684     int dst = currentInstruction[1].u.operand;
685     int scope = currentInstruction[2].u.operand;
686     ResolveType resolveType = static_cast<ResolveType>(currentInstruction[4].u.operand);
687     unsigned depth = currentInstruction[5].u.operand;
688     auto emitCode = [&] (ResolveType resolveType) {
689         switch (resolveType) {
690         case GlobalProperty:
691         case GlobalVar:
692         case GlobalLexicalVar:
693         case GlobalPropertyWithVarInjectionChecks:
694         case GlobalVarWithVarInjectionChecks: 
695         case GlobalLexicalVarWithVarInjectionChecks: {
696             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
697             RELEASE_ASSERT(constantScope);
698             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
699             move(TrustedImm32(JSValue::CellTag), regT1);
700             move(TrustedImmPtr(constantScope), regT0);
701             emitStore(dst, regT1, regT0);
702             break;
703         }
704         case ClosureVar:
705         case ClosureVarWithVarInjectionChecks:
706             emitResolveClosure(dst, scope, needsVarInjectionChecks(resolveType), depth);
707             break;
708         case ModuleVar:
709             move(TrustedImm32(JSValue::CellTag), regT1);
710             move(TrustedImmPtr(currentInstruction[6].u.jsCell.get()), regT0);
711             emitStore(dst, regT1, regT0);
712             break;
713         case Dynamic:
714             addSlowCase(jump());
715             break;
716         case LocalClosureVar:
717         case UnresolvedProperty:
718         case UnresolvedPropertyWithVarInjectionChecks:
719             RELEASE_ASSERT_NOT_REACHED();
720         }
721     };
722     switch (resolveType) {
723     case UnresolvedProperty:
724     case UnresolvedPropertyWithVarInjectionChecks: {
725         JumpList skipToEnd;
726         load32(&currentInstruction[4], regT0);
727
728         Jump notGlobalProperty = branch32(NotEqual, regT0, TrustedImm32(GlobalProperty));
729         emitCode(GlobalProperty);
730         skipToEnd.append(jump());
731         notGlobalProperty.link(this);
732
733         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
734         emitCode(GlobalPropertyWithVarInjectionChecks);
735         skipToEnd.append(jump());
736         notGlobalPropertyWithVarInjections.link(this);
737
738         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
739         emitCode(GlobalLexicalVar);
740         skipToEnd.append(jump());
741         notGlobalLexicalVar.link(this);
742
743         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
744         emitCode(GlobalLexicalVarWithVarInjectionChecks);
745         skipToEnd.append(jump());
746         notGlobalLexicalVarWithVarInjections.link(this);
747
748         addSlowCase(jump());
749         skipToEnd.link(this);
750         break;
751     }
752
753     default:
754         emitCode(resolveType);
755         break;
756     }
757 }
758
759 void JIT::emitSlow_op_resolve_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
760 {
761     ResolveType resolveType = static_cast<ResolveType>(currentInstruction[4].u.operand);
762
763     if (resolveType == GlobalProperty || resolveType == GlobalVar || resolveType == ClosureVar || resolveType == GlobalLexicalVar || resolveType == ModuleVar)
764         return;
765     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
766         linkSlowCase(iter); // Var injections check for GlobalPropertyWithVarInjectionChecks.
767         linkSlowCase(iter); // Var injections check for GlobalLexicalVarWithVarInjectionChecks.
768     }
769
770     linkSlowCase(iter);
771     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_resolve_scope);
772     slowPathCall.call();
773 }
774
775 void JIT::emitLoadWithStructureCheck(int scope, Structure** structureSlot)
776 {
777     emitLoad(scope, regT1, regT0);
778     loadPtr(structureSlot, regT2);
779     addSlowCase(branchPtr(NotEqual, Address(regT0, JSCell::structureIDOffset()), regT2));
780 }
781
782 void JIT::emitGetVarFromPointer(JSValue* operand, GPRReg tag, GPRReg payload)
783 {
784     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
785     load32(bitwise_cast<void*>(rawAddress + TagOffset), tag);
786     load32(bitwise_cast<void*>(rawAddress + PayloadOffset), payload);
787 }
788 void JIT::emitGetVarFromIndirectPointer(JSValue** operand, GPRReg tag, GPRReg payload)
789 {
790     loadPtr(operand, payload);
791     load32(Address(payload, TagOffset), tag);
792     load32(Address(payload, PayloadOffset), payload);
793 }
794
795 void JIT::emitGetClosureVar(int scope, uintptr_t operand)
796 {
797     emitLoad(scope, regT1, regT0);
798     load32(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + TagOffset), regT1);
799     load32(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset), regT0);
800 }
801
802 void JIT::emit_op_get_from_scope(Instruction* currentInstruction)
803 {
804     int dst = currentInstruction[1].u.operand;
805     int scope = currentInstruction[2].u.operand;
806     ResolveType resolveType = GetPutInfo(currentInstruction[4].u.operand).resolveType();
807     Structure** structureSlot = currentInstruction[5].u.structure.slot();
808     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
809     
810     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
811         switch (resolveType) {
812         case GlobalProperty:
813         case GlobalPropertyWithVarInjectionChecks: {
814             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
815             GPRReg base = regT2;
816             GPRReg resultTag = regT1;
817             GPRReg resultPayload = regT0;
818             GPRReg offset = regT3;
819             
820             move(regT0, base);
821             load32(operandSlot, offset);
822             if (!ASSERT_DISABLED) {
823                 Jump isOutOfLine = branch32(GreaterThanOrEqual, offset, TrustedImm32(firstOutOfLineOffset));
824                 abortWithReason(JITOffsetIsNotOutOfLine);
825                 isOutOfLine.link(this);
826             }
827             loadPtr(Address(base, JSObject::butterflyOffset()), base);
828             neg32(offset);
829             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultPayload);
830             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultTag);
831             break;
832         }
833         case GlobalVar:
834         case GlobalVarWithVarInjectionChecks:
835         case GlobalLexicalVar:
836         case GlobalLexicalVarWithVarInjectionChecks:
837             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
838             if (indirectLoadForOperand)
839                 emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
840             else
841                 emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
842             if (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks) // TDZ check.
843                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
844             break;
845         case ClosureVar:
846         case ClosureVarWithVarInjectionChecks:
847             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
848             emitGetClosureVar(scope, *operandSlot);
849             break;
850         case Dynamic:
851             addSlowCase(jump());
852             break;
853         case ModuleVar:
854         case LocalClosureVar:
855         case UnresolvedProperty:
856         case UnresolvedPropertyWithVarInjectionChecks:
857             RELEASE_ASSERT_NOT_REACHED();
858         }
859     };
860
861     switch (resolveType) {
862     case UnresolvedProperty:
863     case UnresolvedPropertyWithVarInjectionChecks: {
864         JumpList skipToEnd;
865         load32(&currentInstruction[4], regT0);
866         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
867
868         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
869         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
870         isGlobalProperty.link(this);
871         emitCode(GlobalProperty, false);
872         skipToEnd.append(jump());
873         notGlobalPropertyWithVarInjections.link(this);
874
875         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
876         emitCode(GlobalLexicalVar, true);
877         skipToEnd.append(jump());
878         notGlobalLexicalVar.link(this);
879
880         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
881         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
882         skipToEnd.append(jump());
883         notGlobalLexicalVarWithVarInjections.link(this);
884
885         addSlowCase(jump());
886
887         skipToEnd.link(this);
888         break;
889     }
890
891     default:
892         emitCode(resolveType, false);
893         break;
894     }
895     emitValueProfilingSite();
896     emitStore(dst, regT1, regT0);
897 }
898
899 void JIT::emitSlow_op_get_from_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
900 {
901     int dst = currentInstruction[1].u.operand;
902     ResolveType resolveType = GetPutInfo(currentInstruction[4].u.operand).resolveType();
903
904     if (resolveType == GlobalVar || resolveType == ClosureVar)
905         return;
906
907     if (resolveType == GlobalLexicalVarWithVarInjectionChecks) // Var Injections check.
908         linkSlowCase(iter);
909
910     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
911         // GlobalProperty/GlobalPropertyWithVarInjectionChecks
912         linkSlowCase(iter); // emitLoadWithStructureCheck
913         // GlobalLexicalVar
914         linkSlowCase(iter); // TDZ check.
915         // GlobalLexicalVarWithVarInjectionChecks.
916         linkSlowCase(iter); // var injection check.
917         linkSlowCase(iter); // TDZ check.
918     }
919
920     linkSlowCase(iter);
921     callOperation(WithProfile, operationGetFromScope, dst, currentInstruction);
922 }
923
924 void JIT::emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet* set)
925 {
926     emitLoad(value, regT1, regT0);
927     emitNotifyWrite(set);
928     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
929     store32(regT1, bitwise_cast<void*>(rawAddress + TagOffset));
930     store32(regT0, bitwise_cast<void*>(rawAddress + PayloadOffset));
931 }
932
933 void JIT::emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet** indirectWatchpointSet)
934 {
935     emitLoad(value, regT1, regT0);
936     loadPtr(indirectWatchpointSet, regT2);
937     emitNotifyWrite(regT2);
938     loadPtr(addressOfOperand, regT2);
939     store32(regT1, Address(regT2, TagOffset));
940     store32(regT0, Address(regT2, PayloadOffset));
941 }
942
943 void JIT::emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet* set)
944 {
945     emitLoad(value, regT3, regT2);
946     emitLoad(scope, regT1, regT0);
947     emitNotifyWrite(set);
948     store32(regT3, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + TagOffset));
949     store32(regT2, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset));
950 }
951
952 void JIT::emit_op_put_to_scope(Instruction* currentInstruction)
953 {
954     int scope = currentInstruction[1].u.operand;
955     int value = currentInstruction[3].u.operand;
956     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
957     ResolveType resolveType = getPutInfo.resolveType();
958     Structure** structureSlot = currentInstruction[5].u.structure.slot();
959     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
960     
961     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
962         switch (resolveType) {
963         case GlobalProperty:
964         case GlobalPropertyWithVarInjectionChecks: {
965             emitWriteBarrier(m_codeBlock->globalObject(), value, ShouldFilterValue);
966             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
967             emitLoad(value, regT3, regT2);
968             
969             loadPtr(Address(regT0, JSObject::butterflyOffset()), regT0);
970             loadPtr(operandSlot, regT1);
971             negPtr(regT1);
972             store32(regT3, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag)));
973             store32(regT2, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload)));
974             break;
975         }
976         case GlobalVar:
977         case GlobalVarWithVarInjectionChecks:
978         case GlobalLexicalVar:
979         case GlobalLexicalVarWithVarInjectionChecks: {
980             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
981             RELEASE_ASSERT(constantScope);
982             emitWriteBarrier(constantScope, value, ShouldFilterValue);
983             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
984             if (getPutInfo.initializationMode() != Initialization && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) {
985                 // We need to do a TDZ check here because we can't always prove we need to emit TDZ checks statically.
986                 if (indirectLoadForOperand)
987                     emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
988                 else
989                     emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
990                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
991             }
992             if (indirectLoadForOperand)
993                 emitPutGlobalVariableIndirect(bitwise_cast<JSValue**>(operandSlot), value, bitwise_cast<WatchpointSet**>(&currentInstruction[5]));
994             else
995                 emitPutGlobalVariable(bitwise_cast<JSValue*>(*operandSlot), value, currentInstruction[5].u.watchpointSet);
996             break;
997         }
998         case LocalClosureVar:
999         case ClosureVar:
1000         case ClosureVarWithVarInjectionChecks:
1001             emitWriteBarrier(scope, value, ShouldFilterValue);
1002             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1003             emitPutClosureVar(scope, *operandSlot, value, currentInstruction[5].u.watchpointSet);
1004             break;
1005         case ModuleVar:
1006         case Dynamic:
1007             addSlowCase(jump());
1008             break;
1009         case UnresolvedProperty:
1010         case UnresolvedPropertyWithVarInjectionChecks:
1011             RELEASE_ASSERT_NOT_REACHED();
1012         }
1013     };
1014
1015     switch (resolveType) {
1016     case UnresolvedProperty:
1017     case UnresolvedPropertyWithVarInjectionChecks: {
1018         JumpList skipToEnd;
1019         load32(&currentInstruction[4], regT0);
1020         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
1021
1022         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
1023         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
1024         isGlobalProperty.link(this);
1025         emitCode(GlobalProperty, false);
1026         skipToEnd.append(jump());
1027         notGlobalPropertyWithVarInjections.link(this);
1028
1029         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
1030         emitCode(GlobalLexicalVar, true);
1031         skipToEnd.append(jump());
1032         notGlobalLexicalVar.link(this);
1033
1034         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
1035         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
1036         skipToEnd.append(jump());
1037         notGlobalLexicalVarWithVarInjections.link(this);
1038
1039         addSlowCase(jump());
1040
1041         skipToEnd.link(this);
1042         break;
1043     }
1044
1045     default:
1046         emitCode(resolveType, false);
1047         break;
1048     }
1049 }
1050
1051 void JIT::emitSlow_op_put_to_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1052 {
1053     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
1054     ResolveType resolveType = getPutInfo.resolveType();
1055     unsigned linkCount = 0;
1056     if (resolveType != GlobalVar && resolveType != ClosureVar && resolveType != LocalClosureVar && resolveType != GlobalLexicalVar)
1057         linkCount++;
1058     if ((resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks || resolveType == LocalClosureVar
1059         || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)
1060         && currentInstruction[5].u.watchpointSet->state() != IsInvalidated)
1061         linkCount++;
1062     if (getPutInfo.initializationMode() != Initialization && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) // TDZ check.
1063         linkCount++;
1064     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
1065         // GlobalProperty/GlobalPropertyWithVarInjectionsCheck
1066         linkCount++; // emitLoadWithStructureCheck
1067
1068         // GlobalLexicalVar
1069         bool needsTDZCheck = getPutInfo.initializationMode() != Initialization;
1070         if (needsTDZCheck)
1071             linkCount++;
1072         linkCount++; // Notify write check.
1073
1074         // GlobalLexicalVarWithVarInjectionsCheck
1075         linkCount++; // var injection check.
1076         if (needsTDZCheck)
1077             linkCount++;
1078         linkCount++; // Notify write check.
1079     }
1080     if (!linkCount)
1081         return;
1082     while (linkCount--)
1083         linkSlowCase(iter);
1084
1085     if (resolveType == ModuleVar) {
1086         JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_throw_strict_mode_readonly_property_write_error);
1087         slowPathCall.call();
1088     } else
1089         callOperation(operationPutToScope, currentInstruction);
1090 }
1091
1092 void JIT::emit_op_get_from_arguments(Instruction* currentInstruction)
1093 {
1094     int dst = currentInstruction[1].u.operand;
1095     int arguments = currentInstruction[2].u.operand;
1096     int index = currentInstruction[3].u.operand;
1097     
1098     emitLoadPayload(arguments, regT0);
1099     load32(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + TagOffset), regT1);
1100     load32(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + PayloadOffset), regT0);
1101     emitValueProfilingSite();
1102     emitStore(dst, regT1, regT0);
1103 }
1104
1105 void JIT::emit_op_put_to_arguments(Instruction* currentInstruction)
1106 {
1107     int arguments = currentInstruction[1].u.operand;
1108     int index = currentInstruction[2].u.operand;
1109     int value = currentInstruction[3].u.operand;
1110     
1111     emitWriteBarrier(arguments, value, ShouldFilterValue);
1112     
1113     emitLoadPayload(arguments, regT0);
1114     emitLoad(value, regT1, regT2);
1115     store32(regT1, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + TagOffset));
1116     store32(regT2, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>) + PayloadOffset));
1117 }
1118
1119 } // namespace JSC
1120
1121 #endif // USE(JSVALUE32_64)
1122 #endif // ENABLE(JIT)