op_get_by_id_with_this should use inline caching
[WebKit-https.git] / Source / JavaScriptCore / jit / JITPropertyAccess.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 #include "JIT.h"
30
31 #include "CodeBlock.h"
32 #include "DirectArguments.h"
33 #include "GCAwareJITStubRoutine.h"
34 #include "GetterSetter.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 "ScopedArguments.h"
43 #include "ScopedArgumentsTable.h"
44 #include "SlowPathCall.h"
45 #include "StructureStubInfo.h"
46 #include <wtf/StringPrintStream.h>
47
48
49 namespace JSC {
50 #if USE(JSVALUE64)
51
52 JIT::CodeRef JIT::stringGetByValStubGenerator(VM* vm)
53 {
54     JSInterfaceJIT jit(vm);
55     JumpList failures;
56     failures.append(jit.branchStructure(
57         NotEqual, 
58         Address(regT0, JSCell::structureIDOffset()), 
59         vm->stringStructure.get()));
60
61     // Load string length to regT2, and start the process of loading the data pointer into regT0
62     jit.load32(Address(regT0, ThunkHelpers::jsStringLengthOffset()), regT2);
63     jit.loadPtr(Address(regT0, ThunkHelpers::jsStringValueOffset()), regT0);
64     failures.append(jit.branchTest32(Zero, regT0));
65
66     // Do an unsigned compare to simultaneously filter negative indices as well as indices that are too large
67     failures.append(jit.branch32(AboveOrEqual, regT1, regT2));
68     
69     // Load the character
70     JumpList is16Bit;
71     JumpList cont8Bit;
72     // Load the string flags
73     jit.loadPtr(Address(regT0, StringImpl::flagsOffset()), regT2);
74     jit.loadPtr(Address(regT0, StringImpl::dataOffset()), regT0);
75     is16Bit.append(jit.branchTest32(Zero, regT2, TrustedImm32(StringImpl::flagIs8Bit())));
76     jit.load8(BaseIndex(regT0, regT1, TimesOne, 0), regT0);
77     cont8Bit.append(jit.jump());
78     is16Bit.link(&jit);
79     jit.load16(BaseIndex(regT0, regT1, TimesTwo, 0), regT0);
80     cont8Bit.link(&jit);
81
82     failures.append(jit.branch32(AboveOrEqual, regT0, TrustedImm32(0x100)));
83     jit.move(TrustedImmPtr(vm->smallStrings.singleCharacterStrings()), regT1);
84     jit.loadPtr(BaseIndex(regT1, regT0, ScalePtr, 0), regT0);
85     jit.ret();
86     
87     failures.link(&jit);
88     jit.move(TrustedImm32(0), regT0);
89     jit.ret();
90     
91     LinkBuffer patchBuffer(*vm, jit, GLOBAL_THUNK_ID);
92     return FINALIZE_CODE(patchBuffer, ("String get_by_val stub"));
93 }
94
95 void JIT::emit_op_get_by_val(Instruction* currentInstruction)
96 {
97     int dst = currentInstruction[1].u.operand;
98     int base = currentInstruction[2].u.operand;
99     int property = currentInstruction[3].u.operand;
100     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
101     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
102
103     emitGetVirtualRegister(base, regT0);
104     bool propertyNameIsIntegerConstant = isOperandConstantInt(property);
105     if (propertyNameIsIntegerConstant)
106         move(Imm32(getOperandConstantInt(property)), regT1);
107     else
108         emitGetVirtualRegister(property, regT1);
109
110     emitJumpSlowCaseIfNotJSCell(regT0, base);
111
112     PatchableJump notIndex;
113     if (!propertyNameIsIntegerConstant) {
114         notIndex = emitPatchableJumpIfNotInt(regT1);
115         addSlowCase(notIndex);
116
117         // This is technically incorrect - we're zero-extending an int32. On the hot path this doesn't matter.
118         // We check the value as if it was a uint32 against the m_vectorLength - which will always fail if
119         // number was signed since m_vectorLength is always less than intmax (since the total allocation
120         // size is always less than 4Gb). As such zero extending will have been correct (and extending the value
121         // to 64-bits is necessary since it's used in the address calculation). We zero extend rather than sign
122         // extending since it makes it easier to re-tag the value in the slow case.
123         zeroExtend32ToPtr(regT1, regT1);
124     }
125
126     emitArrayProfilingSiteWithCell(regT0, regT2, profile);
127     and32(TrustedImm32(IndexingShapeMask), regT2);
128
129     PatchableJump badType;
130     JumpList slowCases;
131
132     JITArrayMode mode = chooseArrayMode(profile);
133     switch (mode) {
134     case JITInt32:
135         slowCases = emitInt32GetByVal(currentInstruction, badType);
136         break;
137     case JITDouble:
138         slowCases = emitDoubleGetByVal(currentInstruction, badType);
139         break;
140     case JITContiguous:
141         slowCases = emitContiguousGetByVal(currentInstruction, badType);
142         break;
143     case JITArrayStorage:
144         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
145         break;
146     default:
147         CRASH();
148         break;
149     }
150     
151     addSlowCase(badType);
152     addSlowCase(slowCases);
153     
154     Label done = label();
155     
156     if (!ASSERT_DISABLED) {
157         Jump resultOK = branchTest64(NonZero, regT0);
158         abortWithReason(JITGetByValResultIsNotEmpty);
159         resultOK.link(this);
160     }
161
162     emitValueProfilingSite();
163     emitPutVirtualRegister(dst);
164
165     Label nextHotPath = label();
166
167     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, nextHotPath));
168 }
169
170 JIT::JumpList JIT::emitDoubleLoad(Instruction*, PatchableJump& badType)
171 {
172     JumpList slowCases;
173     
174     badType = patchableBranch32(NotEqual, regT2, TrustedImm32(DoubleShape));
175     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
176     slowCases.append(branch32(AboveOrEqual, regT1, Address(regT2, Butterfly::offsetOfPublicLength())));
177     loadDouble(BaseIndex(regT2, regT1, TimesEight), fpRegT0);
178     slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
179     
180     return slowCases;
181 }
182
183 JIT::JumpList JIT::emitContiguousLoad(Instruction*, PatchableJump& badType, IndexingType expectedShape)
184 {
185     JumpList slowCases;
186     
187     badType = patchableBranch32(NotEqual, regT2, TrustedImm32(expectedShape));
188     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
189     slowCases.append(branch32(AboveOrEqual, regT1, Address(regT2, Butterfly::offsetOfPublicLength())));
190     load64(BaseIndex(regT2, regT1, TimesEight), regT0);
191     slowCases.append(branchTest64(Zero, regT0));
192     
193     return slowCases;
194 }
195
196 JIT::JumpList JIT::emitArrayStorageLoad(Instruction*, PatchableJump& badType)
197 {
198     JumpList slowCases;
199
200     add32(TrustedImm32(-ArrayStorageShape), regT2, regT3);
201     badType = patchableBranch32(Above, regT3, TrustedImm32(SlowPutArrayStorageShape - ArrayStorageShape));
202
203     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
204     slowCases.append(branch32(AboveOrEqual, regT1, Address(regT2, ArrayStorage::vectorLengthOffset())));
205
206     load64(BaseIndex(regT2, regT1, TimesEight, ArrayStorage::vectorOffset()), regT0);
207     slowCases.append(branchTest64(Zero, regT0));
208     
209     return slowCases;
210 }
211
212 JITGetByIdGenerator JIT::emitGetByValWithCachedId(ByValInfo* byValInfo, Instruction* currentInstruction, const Identifier& propertyName, Jump& fastDoneCase, Jump& slowDoneCase, JumpList& slowCases)
213 {
214     // base: regT0
215     // property: regT1
216     // scratch: regT3
217
218     int dst = currentInstruction[1].u.operand;
219
220     slowCases.append(emitJumpIfNotJSCell(regT1));
221     emitByValIdentifierCheck(byValInfo, regT1, regT3, propertyName, slowCases);
222
223     JITGetByIdGenerator gen(
224         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
225         propertyName.impl(), JSValueRegs(regT0), JSValueRegs(regT0), AccessType::Get);
226     gen.generateFastPath(*this);
227
228     fastDoneCase = jump();
229
230     Label coldPathBegin = label();
231     gen.slowPathJump().link(this);
232
233     Call call = callOperation(WithProfile, operationGetByIdOptimize, dst, gen.stubInfo(), regT0, propertyName.impl());
234     gen.reportSlowPathCall(coldPathBegin, call);
235     slowDoneCase = jump();
236
237     return gen;
238 }
239
240 void JIT::emitSlow_op_get_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
241 {
242     int dst = currentInstruction[1].u.operand;
243     int base = currentInstruction[2].u.operand;
244     int property = currentInstruction[3].u.operand;
245     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
246     
247     linkSlowCaseIfNotJSCell(iter, base); // base cell check
248
249     if (!isOperandConstantInt(property))
250         linkSlowCase(iter); // property int32 check
251     Jump nonCell = jump();
252     linkSlowCase(iter); // base array check
253     Jump notString = branchStructure(NotEqual, 
254         Address(regT0, JSCell::structureIDOffset()), 
255         m_vm->stringStructure.get());
256     emitNakedCall(CodeLocationLabel(m_vm->getCTIStub(stringGetByValStubGenerator).code()));
257     Jump failed = branchTest64(Zero, regT0);
258     emitPutVirtualRegister(dst, regT0);
259     emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_get_by_val));
260     failed.link(this);
261     notString.link(this);
262     nonCell.link(this);
263     
264     linkSlowCase(iter); // vector length check
265     linkSlowCase(iter); // empty value
266     
267     Label slowPath = label();
268     
269     emitGetVirtualRegister(base, regT0);
270     emitGetVirtualRegister(property, regT1);
271     Call call = callOperation(operationGetByValOptimize, dst, regT0, regT1, byValInfo);
272
273     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
274     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
275     m_byValInstructionIndex++;
276
277     emitValueProfilingSite();
278 }
279
280 void JIT::emit_op_put_by_val(Instruction* currentInstruction)
281 {
282     int base = currentInstruction[1].u.operand;
283     int property = currentInstruction[2].u.operand;
284     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
285     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
286
287     emitGetVirtualRegister(base, regT0);
288     bool propertyNameIsIntegerConstant = isOperandConstantInt(property);
289     if (propertyNameIsIntegerConstant)
290         move(Imm32(getOperandConstantInt(property)), regT1);
291     else
292         emitGetVirtualRegister(property, regT1);
293
294     emitJumpSlowCaseIfNotJSCell(regT0, base);
295     PatchableJump notIndex;
296     if (!propertyNameIsIntegerConstant) {
297         notIndex = emitPatchableJumpIfNotInt(regT1);
298         addSlowCase(notIndex);
299         // See comment in op_get_by_val.
300         zeroExtend32ToPtr(regT1, regT1);
301     }
302     emitArrayProfilingSiteWithCell(regT0, regT2, profile);
303     and32(TrustedImm32(IndexingShapeMask), regT2);
304     
305     PatchableJump badType;
306     JumpList slowCases;
307     
308     JITArrayMode mode = chooseArrayMode(profile);
309     switch (mode) {
310     case JITInt32:
311         slowCases = emitInt32PutByVal(currentInstruction, badType);
312         break;
313     case JITDouble:
314         slowCases = emitDoublePutByVal(currentInstruction, badType);
315         break;
316     case JITContiguous:
317         slowCases = emitContiguousPutByVal(currentInstruction, badType);
318         break;
319     case JITArrayStorage:
320         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
321         break;
322     default:
323         CRASH();
324         break;
325     }
326     
327     addSlowCase(badType);
328     addSlowCase(slowCases);
329     
330     Label done = label();
331     
332     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, done));
333 }
334
335 void JIT::emit_op_put_by_val_with_this(Instruction* currentInstruction)
336 {
337     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_put_by_val_with_this);
338     slowPathCall.call();
339 }
340
341 JIT::JumpList JIT::emitGenericContiguousPutByVal(Instruction* currentInstruction, PatchableJump& badType, IndexingType indexingShape)
342 {
343     int value = currentInstruction[3].u.operand;
344     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
345     
346     JumpList slowCases;
347
348     badType = patchableBranch32(NotEqual, regT2, TrustedImm32(indexingShape));
349     
350     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
351     Jump outOfBounds = branch32(AboveOrEqual, regT1, Address(regT2, Butterfly::offsetOfPublicLength()));
352
353     Label storeResult = label();
354     emitGetVirtualRegister(value, regT3);
355     switch (indexingShape) {
356     case Int32Shape:
357         slowCases.append(emitJumpIfNotInt(regT3));
358         store64(regT3, BaseIndex(regT2, regT1, TimesEight));
359         break;
360     case DoubleShape: {
361         Jump notInt = emitJumpIfNotInt(regT3);
362         convertInt32ToDouble(regT3, fpRegT0);
363         Jump ready = jump();
364         notInt.link(this);
365         add64(tagTypeNumberRegister, regT3);
366         move64ToDouble(regT3, fpRegT0);
367         slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
368         ready.link(this);
369         storeDouble(fpRegT0, BaseIndex(regT2, regT1, TimesEight));
370         break;
371     }
372     case ContiguousShape:
373         store64(regT3, BaseIndex(regT2, regT1, TimesEight));
374         emitWriteBarrier(currentInstruction[1].u.operand, value, ShouldFilterValue);
375         break;
376     default:
377         CRASH();
378         break;
379     }
380     
381     Jump done = jump();
382     outOfBounds.link(this);
383     
384     slowCases.append(branch32(AboveOrEqual, regT1, Address(regT2, Butterfly::offsetOfVectorLength())));
385     
386     emitArrayProfileStoreToHoleSpecialCase(profile);
387     
388     add32(TrustedImm32(1), regT1, regT3);
389     store32(regT3, Address(regT2, Butterfly::offsetOfPublicLength()));
390     jump().linkTo(storeResult, this);
391     
392     done.link(this);
393     
394     return slowCases;
395 }
396
397 JIT::JumpList JIT::emitArrayStoragePutByVal(Instruction* currentInstruction, PatchableJump& badType)
398 {
399     int value = currentInstruction[3].u.operand;
400     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
401     
402     JumpList slowCases;
403     
404     badType = patchableBranch32(NotEqual, regT2, TrustedImm32(ArrayStorageShape));
405     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
406     slowCases.append(branch32(AboveOrEqual, regT1, Address(regT2, ArrayStorage::vectorLengthOffset())));
407
408     Jump empty = branchTest64(Zero, BaseIndex(regT2, regT1, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])));
409
410     Label storeResult(this);
411     emitGetVirtualRegister(value, regT3);
412     store64(regT3, BaseIndex(regT2, regT1, TimesEight, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])));
413     emitWriteBarrier(currentInstruction[1].u.operand, value, ShouldFilterValue);
414     Jump end = jump();
415     
416     empty.link(this);
417     emitArrayProfileStoreToHoleSpecialCase(profile);
418     add32(TrustedImm32(1), Address(regT2, ArrayStorage::numValuesInVectorOffset()));
419     branch32(Below, regT1, Address(regT2, ArrayStorage::lengthOffset())).linkTo(storeResult, this);
420
421     add32(TrustedImm32(1), regT1);
422     store32(regT1, Address(regT2, ArrayStorage::lengthOffset()));
423     sub32(TrustedImm32(1), regT1);
424     jump().linkTo(storeResult, this);
425
426     end.link(this);
427     
428     return slowCases;
429 }
430
431 JITPutByIdGenerator JIT::emitPutByValWithCachedId(ByValInfo* byValInfo, Instruction* currentInstruction, PutKind putKind, const Identifier& propertyName, JumpList& doneCases, JumpList& slowCases)
432 {
433     // base: regT0
434     // property: regT1
435     // scratch: regT2
436
437     int base = currentInstruction[1].u.operand;
438     int value = currentInstruction[3].u.operand;
439
440     slowCases.append(emitJumpIfNotJSCell(regT1));
441     emitByValIdentifierCheck(byValInfo, regT1, regT1, propertyName, slowCases);
442
443     // Write barrier breaks the registers. So after issuing the write barrier,
444     // reload the registers.
445     emitGetVirtualRegisters(base, regT0, value, regT1);
446
447     JITPutByIdGenerator gen(
448         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
449         JSValueRegs(regT0), JSValueRegs(regT1), regT2, m_codeBlock->ecmaMode(), putKind);
450     gen.generateFastPath(*this);
451     emitWriteBarrier(base, value, ShouldFilterBase);
452     doneCases.append(jump());
453
454     Label coldPathBegin = label();
455     gen.slowPathJump().link(this);
456
457     Call call = callOperation(gen.slowPathFunction(), gen.stubInfo(), regT1, regT0, propertyName.impl());
458     gen.reportSlowPathCall(coldPathBegin, call);
459     doneCases.append(jump());
460
461     return gen;
462 }
463
464 void JIT::emitSlow_op_put_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
465 {
466     int base = currentInstruction[1].u.operand;
467     int property = currentInstruction[2].u.operand;
468     int value = currentInstruction[3].u.operand;
469     JITArrayMode mode = m_byValCompilationInfo[m_byValInstructionIndex].arrayMode;
470     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
471
472     linkSlowCaseIfNotJSCell(iter, base); // base cell check
473     if (!isOperandConstantInt(property))
474         linkSlowCase(iter); // property int32 check
475     linkSlowCase(iter); // base not array check
476     
477     linkSlowCase(iter); // out of bounds
478     
479     switch (mode) {
480     case JITInt32:
481     case JITDouble:
482         linkSlowCase(iter); // value type check
483         break;
484     default:
485         break;
486     }
487     
488     Label slowPath = label();
489
490     emitGetVirtualRegister(base, regT0);
491     emitGetVirtualRegister(property, regT1);
492     emitGetVirtualRegister(value, regT2);
493     bool isDirect = m_interpreter->getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
494     Call call = callOperation(isDirect ? operationDirectPutByValOptimize : operationPutByValOptimize, regT0, regT1, regT2, byValInfo);
495
496     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
497     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
498     m_byValInstructionIndex++;
499 }
500
501 void JIT::emit_op_put_by_index(Instruction* currentInstruction)
502 {
503     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
504     emitGetVirtualRegister(currentInstruction[3].u.operand, regT1);
505     callOperation(operationPutByIndex, regT0, currentInstruction[2].u.operand, regT1);
506 }
507
508 void JIT::emit_op_put_getter_by_id(Instruction* currentInstruction)
509 {
510     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
511     int32_t options = currentInstruction[3].u.operand;
512     emitGetVirtualRegister(currentInstruction[4].u.operand, regT1);
513     callOperation(operationPutGetterById, regT0, m_codeBlock->identifier(currentInstruction[2].u.operand).impl(), options, regT1);
514 }
515
516 void JIT::emit_op_put_setter_by_id(Instruction* currentInstruction)
517 {
518     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
519     int32_t options = currentInstruction[3].u.operand;
520     emitGetVirtualRegister(currentInstruction[4].u.operand, regT1);
521     callOperation(operationPutSetterById, regT0, m_codeBlock->identifier(currentInstruction[2].u.operand).impl(), options, regT1);
522 }
523
524 void JIT::emit_op_put_getter_setter_by_id(Instruction* currentInstruction)
525 {
526     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
527     int32_t attribute = currentInstruction[3].u.operand;
528     emitGetVirtualRegister(currentInstruction[4].u.operand, regT1);
529     emitGetVirtualRegister(currentInstruction[5].u.operand, regT2);
530     callOperation(operationPutGetterSetter, regT0, m_codeBlock->identifier(currentInstruction[2].u.operand).impl(), attribute, regT1, regT2);
531 }
532
533 void JIT::emit_op_put_getter_by_val(Instruction* currentInstruction)
534 {
535     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
536     emitGetVirtualRegister(currentInstruction[2].u.operand, regT1);
537     int32_t attributes = currentInstruction[3].u.operand;
538     emitGetVirtualRegister(currentInstruction[4].u.operand, regT2);
539     callOperation(operationPutGetterByVal, regT0, regT1, attributes, regT2);
540 }
541
542 void JIT::emit_op_put_setter_by_val(Instruction* currentInstruction)
543 {
544     emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
545     emitGetVirtualRegister(currentInstruction[2].u.operand, regT1);
546     int32_t attributes = currentInstruction[3].u.operand;
547     emitGetVirtualRegister(currentInstruction[4].u.operand, regT2);
548     callOperation(operationPutSetterByVal, regT0, regT1, attributes, regT2);
549 }
550
551 void JIT::emit_op_del_by_id(Instruction* currentInstruction)
552 {
553     int dst = currentInstruction[1].u.operand;
554     int base = currentInstruction[2].u.operand;
555     int property = currentInstruction[3].u.operand;
556     emitGetVirtualRegister(base, regT0);
557     callOperation(operationDeleteByIdJSResult, dst, regT0, m_codeBlock->identifier(property).impl());
558 }
559
560 void JIT::emit_op_del_by_val(Instruction* currentInstruction)
561 {
562     int dst = currentInstruction[1].u.operand;
563     int base = currentInstruction[2].u.operand;
564     int property = currentInstruction[3].u.operand;
565     emitGetVirtualRegister(base, regT0);
566     emitGetVirtualRegister(property, regT1);
567     callOperation(operationDeleteByValJSResult, dst, regT0, regT1);
568 }
569
570 void JIT::emit_op_try_get_by_id(Instruction* currentInstruction)
571 {
572     int resultVReg = currentInstruction[1].u.operand;
573     int baseVReg = currentInstruction[2].u.operand;
574     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
575
576     emitGetVirtualRegister(baseVReg, regT0);
577
578     emitJumpSlowCaseIfNotJSCell(regT0, baseVReg);
579
580     JITGetByIdGenerator gen(
581         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
582         ident->impl(), JSValueRegs(regT0), JSValueRegs(regT0), AccessType::TryGet);
583     gen.generateFastPath(*this);
584     addSlowCase(gen.slowPathJump());
585     m_getByIds.append(gen);
586     
587     emitValueProfilingSite();
588     emitPutVirtualRegister(resultVReg);
589 }
590
591 void JIT::emitSlow_op_try_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
592 {
593     int resultVReg = currentInstruction[1].u.operand;
594     int baseVReg = currentInstruction[2].u.operand;
595     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
596
597     linkSlowCaseIfNotJSCell(iter, baseVReg);
598     linkSlowCase(iter);
599
600     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
601
602     Label coldPathBegin = label();
603
604     Call call = callOperation(operationTryGetByIdOptimize, resultVReg, gen.stubInfo(), regT0, ident->impl());
605     
606     gen.reportSlowPathCall(coldPathBegin, call);
607 }
608
609 void JIT::emit_op_get_by_id(Instruction* currentInstruction)
610 {
611     int resultVReg = currentInstruction[1].u.operand;
612     int baseVReg = currentInstruction[2].u.operand;
613     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
614
615     emitGetVirtualRegister(baseVReg, regT0);
616     
617     emitJumpSlowCaseIfNotJSCell(regT0, baseVReg);
618     
619     if (*ident == m_vm->propertyNames->length && shouldEmitProfiling())
620         emitArrayProfilingSiteForBytecodeIndexWithCell(regT0, regT1, m_bytecodeOffset);
621
622     JITGetByIdGenerator gen(
623         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
624         ident->impl(), JSValueRegs(regT0), JSValueRegs(regT0), AccessType::Get);
625     gen.generateFastPath(*this);
626     addSlowCase(gen.slowPathJump());
627     m_getByIds.append(gen);
628
629     emitValueProfilingSite();
630     emitPutVirtualRegister(resultVReg);
631 }
632
633 void JIT::emit_op_get_by_id_with_this(Instruction* currentInstruction)
634 {
635     int resultVReg = currentInstruction[1].u.operand;
636     int baseVReg = currentInstruction[2].u.operand;
637     int thisVReg = currentInstruction[3].u.operand;
638     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[4].u.operand));
639
640     emitGetVirtualRegister(baseVReg, regT0);
641     emitGetVirtualRegister(thisVReg, regT1);
642     emitJumpSlowCaseIfNotJSCell(regT0, baseVReg);
643     emitJumpSlowCaseIfNotJSCell(regT1, thisVReg);
644
645     JITGetByIdWithThisGenerator gen(
646         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
647         ident->impl(), JSValueRegs(regT0), JSValueRegs(regT0), JSValueRegs(regT1), AccessType::GetWithThis);
648     gen.generateFastPath(*this);
649     addSlowCase(gen.slowPathJump());
650     m_getByIdsWithThis.append(gen);
651
652     emitValueProfilingSite();
653     emitPutVirtualRegister(resultVReg);
654 }
655
656 void JIT::emit_op_get_by_val_with_this(Instruction* currentInstruction)
657 {
658     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_get_by_val_with_this);
659     slowPathCall.call();
660 }
661
662 void JIT::emitSlow_op_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
663 {
664     int resultVReg = currentInstruction[1].u.operand;
665     int baseVReg = currentInstruction[2].u.operand;
666     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
667
668     linkSlowCaseIfNotJSCell(iter, baseVReg);
669     linkSlowCase(iter);
670
671     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
672     
673     Label coldPathBegin = label();
674     
675     Call call = callOperation(WithProfile, operationGetByIdOptimize, resultVReg, gen.stubInfo(), regT0, ident->impl());
676
677     gen.reportSlowPathCall(coldPathBegin, call);
678 }
679
680 void JIT::emitSlow_op_get_by_id_with_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
681 {
682     int resultVReg = currentInstruction[1].u.operand;
683     int baseVReg = currentInstruction[2].u.operand;
684     int thisVReg = currentInstruction[3].u.operand;
685     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[4].u.operand));
686
687     linkSlowCaseIfNotJSCell(iter, baseVReg);
688     linkSlowCaseIfNotJSCell(iter, thisVReg);
689     linkSlowCase(iter);
690
691     JITGetByIdWithThisGenerator& gen = m_getByIdsWithThis[m_getByIdWithThisIndex++];
692     
693     Label coldPathBegin = label();
694     
695     Call call = callOperation(WithProfile, operationGetByIdWithThisOptimize, resultVReg, gen.stubInfo(), regT0, regT1, ident->impl());
696
697     gen.reportSlowPathCall(coldPathBegin, call);
698 }
699
700 void JIT::emit_op_put_by_id(Instruction* currentInstruction)
701 {
702     int baseVReg = currentInstruction[1].u.operand;
703     int valueVReg = currentInstruction[3].u.operand;
704     unsigned direct = currentInstruction[8].u.putByIdFlags & PutByIdIsDirect;
705
706     // In order to be able to patch both the Structure, and the object offset, we store one pointer,
707     // to just after the arguments have been loaded into registers 'hotPathBegin', and we generate code
708     // such that the Structure & offset are always at the same distance from this.
709
710     emitGetVirtualRegisters(baseVReg, regT0, valueVReg, regT1);
711
712     emitJumpSlowCaseIfNotJSCell(regT0, baseVReg);
713
714     JITPutByIdGenerator gen(
715         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
716         JSValueRegs(regT0), JSValueRegs(regT1), regT2, m_codeBlock->ecmaMode(),
717         direct ? Direct : NotDirect);
718     
719     gen.generateFastPath(*this);
720     addSlowCase(gen.slowPathJump());
721     
722     emitWriteBarrier(baseVReg, valueVReg, ShouldFilterBase);
723
724     m_putByIds.append(gen);
725 }
726
727 void JIT::emit_op_put_by_id_with_this(Instruction* currentInstruction)
728 {
729     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_put_by_id_with_this);
730     slowPathCall.call();
731 }
732
733 void JIT::emitSlow_op_put_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
734 {
735     int baseVReg = currentInstruction[1].u.operand;
736     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[2].u.operand));
737
738     linkSlowCaseIfNotJSCell(iter, baseVReg);
739     linkSlowCase(iter);
740
741     Label coldPathBegin(this);
742     
743     JITPutByIdGenerator& gen = m_putByIds[m_putByIdIndex++];
744
745     Call call = callOperation(
746         gen.slowPathFunction(), gen.stubInfo(), regT1, regT0, ident->impl());
747
748     gen.reportSlowPathCall(coldPathBegin, call);
749 }
750
751 void JIT::emitVarInjectionCheck(bool needsVarInjectionChecks)
752 {
753     if (!needsVarInjectionChecks)
754         return;
755     addSlowCase(branch8(Equal, AbsoluteAddress(m_codeBlock->globalObject()->varInjectionWatchpoint()->addressOfState()), TrustedImm32(IsInvalidated)));
756 }
757
758 void JIT::emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth)
759 {
760     emitVarInjectionCheck(needsVarInjectionChecks);
761     emitGetVirtualRegister(scope, regT0);
762     for (unsigned i = 0; i < depth; ++i)
763         loadPtr(Address(regT0, JSScope::offsetOfNext()), regT0);
764     emitPutVirtualRegister(dst);
765 }
766
767 void JIT::emit_op_resolve_scope(Instruction* currentInstruction)
768 {
769     int dst = currentInstruction[1].u.operand;
770     int scope = currentInstruction[2].u.operand;
771     ResolveType resolveType = static_cast<ResolveType>(copiedInstruction(currentInstruction)[4].u.operand);
772     unsigned depth = currentInstruction[5].u.operand;
773
774     auto emitCode = [&] (ResolveType resolveType) {
775         switch (resolveType) {
776         case GlobalProperty:
777         case GlobalVar:
778         case GlobalPropertyWithVarInjectionChecks:
779         case GlobalVarWithVarInjectionChecks:
780         case GlobalLexicalVar:
781         case GlobalLexicalVarWithVarInjectionChecks: {
782             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
783             RELEASE_ASSERT(constantScope);
784             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
785             move(TrustedImmPtr(constantScope), regT0);
786             emitPutVirtualRegister(dst);
787             break;
788         }
789         case ClosureVar:
790         case ClosureVarWithVarInjectionChecks:
791             emitResolveClosure(dst, scope, needsVarInjectionChecks(resolveType), depth);
792             break;
793         case ModuleVar:
794             move(TrustedImmPtr(currentInstruction[6].u.jsCell.get()), regT0);
795             emitPutVirtualRegister(dst);
796             break;
797         case Dynamic:
798             addSlowCase(jump());
799             break;
800         case LocalClosureVar:
801         case UnresolvedProperty:
802         case UnresolvedPropertyWithVarInjectionChecks:
803             RELEASE_ASSERT_NOT_REACHED();
804         }
805     };
806
807     switch (resolveType) {
808     case UnresolvedProperty:
809     case UnresolvedPropertyWithVarInjectionChecks: {
810         JumpList skipToEnd;
811         load32(&currentInstruction[4], regT0);
812
813         Jump notGlobalProperty = branch32(NotEqual, regT0, TrustedImm32(GlobalProperty));
814         emitCode(GlobalProperty);
815         skipToEnd.append(jump());
816         notGlobalProperty.link(this);
817
818         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
819         emitCode(GlobalPropertyWithVarInjectionChecks);
820         skipToEnd.append(jump());
821         notGlobalPropertyWithVarInjections.link(this);
822
823         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
824         emitCode(GlobalLexicalVar);
825         skipToEnd.append(jump());
826         notGlobalLexicalVar.link(this);
827
828         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
829         emitCode(GlobalLexicalVarWithVarInjectionChecks);
830         skipToEnd.append(jump());
831         notGlobalLexicalVarWithVarInjections.link(this);
832
833         addSlowCase(jump());
834         skipToEnd.link(this);
835         break;
836     }
837
838     default:
839         emitCode(resolveType);
840         break;
841     }
842 }
843
844 void JIT::emitSlow_op_resolve_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
845 {
846     ResolveType resolveType = static_cast<ResolveType>(copiedInstruction(currentInstruction)[4].u.operand);
847     if (resolveType == GlobalProperty || resolveType == GlobalVar || resolveType == ClosureVar || resolveType == GlobalLexicalVar || resolveType == ModuleVar)
848         return;
849
850     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
851         linkSlowCase(iter); // var injections check for GlobalPropertyWithVarInjectionChecks.
852         linkSlowCase(iter); // var injections check for GlobalLexicalVarWithVarInjectionChecks.
853     }
854
855     linkSlowCase(iter);
856     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_resolve_scope);
857     slowPathCall.call();
858 }
859
860 void JIT::emitLoadWithStructureCheck(int scope, Structure** structureSlot)
861 {
862     loadPtr(structureSlot, regT1);
863     emitGetVirtualRegister(scope, regT0);
864     addSlowCase(branchTestPtr(Zero, regT1));
865     load32(Address(regT1, Structure::structureIDOffset()), regT1);
866     addSlowCase(branch32(NotEqual, Address(regT0, JSCell::structureIDOffset()), regT1));
867 }
868
869 void JIT::emitGetVarFromPointer(JSValue* operand, GPRReg reg)
870 {
871     loadPtr(operand, reg);
872 }
873
874 void JIT::emitGetVarFromIndirectPointer(JSValue** operand, GPRReg reg)
875 {
876     loadPtr(operand, reg);
877     loadPtr(reg, reg);
878 }
879
880 void JIT::emitGetClosureVar(int scope, uintptr_t operand)
881 {
882     emitGetVirtualRegister(scope, regT0);
883     loadPtr(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register)), regT0);
884 }
885
886 void JIT::emit_op_get_from_scope(Instruction* currentInstruction)
887 {
888     int dst = currentInstruction[1].u.operand;
889     int scope = currentInstruction[2].u.operand;
890     ResolveType resolveType = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand).resolveType();
891     Structure** structureSlot = currentInstruction[5].u.structure.slot();
892     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
893
894     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
895         switch (resolveType) {
896         case GlobalProperty:
897         case GlobalPropertyWithVarInjectionChecks: {
898             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
899             GPRReg base = regT0;
900             GPRReg result = regT0;
901             GPRReg offset = regT1;
902             GPRReg scratch = regT2;
903             
904             load32(operandSlot, offset);
905             if (!ASSERT_DISABLED) {
906                 Jump isOutOfLine = branch32(GreaterThanOrEqual, offset, TrustedImm32(firstOutOfLineOffset));
907                 abortWithReason(JITOffsetIsNotOutOfLine);
908                 isOutOfLine.link(this);
909             }
910             loadPtr(Address(base, JSObject::butterflyOffset()), scratch);
911             neg32(offset);
912             signExtend32ToPtr(offset, offset);
913             load64(BaseIndex(scratch, offset, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), result);
914             break;
915         }
916         case GlobalVar:
917         case GlobalVarWithVarInjectionChecks:
918         case GlobalLexicalVar:
919         case GlobalLexicalVarWithVarInjectionChecks:
920             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
921             if (indirectLoadForOperand)
922                 emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT0);
923             else
924                 emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT0);
925             if (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks) // TDZ check.
926                 addSlowCase(branchTest64(Zero, regT0));
927             break;
928         case ClosureVar:
929         case ClosureVarWithVarInjectionChecks:
930             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
931             emitGetClosureVar(scope, *operandSlot);
932             break;
933         case Dynamic:
934             addSlowCase(jump());
935             break;
936         case LocalClosureVar:
937         case ModuleVar:
938         case UnresolvedProperty:
939         case UnresolvedPropertyWithVarInjectionChecks:
940             RELEASE_ASSERT_NOT_REACHED();
941         }
942     };
943
944     switch (resolveType) {
945     case UnresolvedProperty:
946     case UnresolvedPropertyWithVarInjectionChecks: {
947         JumpList skipToEnd;
948         load32(&currentInstruction[4], regT0);
949         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
950
951         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
952         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
953         isGlobalProperty.link(this);
954         emitCode(GlobalProperty, false);
955         skipToEnd.append(jump());
956         notGlobalPropertyWithVarInjections.link(this);
957
958         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
959         emitCode(GlobalLexicalVar, true);
960         skipToEnd.append(jump());
961         notGlobalLexicalVar.link(this);
962
963         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
964         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
965         skipToEnd.append(jump());
966         notGlobalLexicalVarWithVarInjections.link(this);
967
968         addSlowCase(jump());
969
970         skipToEnd.link(this);
971         break;
972     }
973
974     default:
975         emitCode(resolveType, false);
976         break;
977     }
978     emitPutVirtualRegister(dst);
979     emitValueProfilingSite();
980 }
981
982 void JIT::emitSlow_op_get_from_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
983 {
984     int dst = currentInstruction[1].u.operand;
985     ResolveType resolveType = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand).resolveType();
986
987     if (resolveType == GlobalVar || resolveType == ClosureVar)
988         return;
989
990     if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
991         linkSlowCase(iter); // bad structure
992
993     if (resolveType == GlobalLexicalVarWithVarInjectionChecks) // Var injections check.
994         linkSlowCase(iter);
995
996     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
997         // GlobalProperty/GlobalPropertyWithVarInjectionChecks
998         linkSlowCase(iter); // emitLoadWithStructureCheck
999         linkSlowCase(iter); // emitLoadWithStructureCheck
1000         // GlobalLexicalVar
1001         linkSlowCase(iter); // TDZ check.
1002         // GlobalLexicalVarWithVarInjectionChecks.
1003         linkSlowCase(iter); // var injection check.
1004         linkSlowCase(iter); // TDZ check.
1005     }
1006
1007     linkSlowCase(iter);
1008
1009     callOperation(WithProfile, operationGetFromScope, dst, currentInstruction);
1010 }
1011
1012 void JIT::emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet* set)
1013 {
1014     emitGetVirtualRegister(value, regT0);
1015     emitNotifyWrite(set);
1016     storePtr(regT0, operand);
1017 }
1018 void JIT::emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet** indirectWatchpointSet)
1019 {
1020     emitGetVirtualRegister(value, regT0);
1021     loadPtr(indirectWatchpointSet, regT1);
1022     emitNotifyWrite(regT1);
1023     loadPtr(addressOfOperand, regT1);
1024     storePtr(regT0, regT1);
1025 }
1026
1027 void JIT::emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet* set)
1028 {
1029     emitGetVirtualRegister(value, regT1);
1030     emitGetVirtualRegister(scope, regT0);
1031     emitNotifyWrite(set);
1032     storePtr(regT1, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register)));
1033 }
1034
1035 void JIT::emit_op_put_to_scope(Instruction* currentInstruction)
1036 {
1037     int scope = currentInstruction[1].u.operand;
1038     int value = currentInstruction[3].u.operand;
1039     GetPutInfo getPutInfo = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand);
1040     ResolveType resolveType = getPutInfo.resolveType();
1041     Structure** structureSlot = currentInstruction[5].u.structure.slot();
1042     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
1043
1044     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
1045         switch (resolveType) {
1046         case GlobalProperty:
1047         case GlobalPropertyWithVarInjectionChecks: {
1048             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
1049             emitGetVirtualRegister(value, regT2);
1050             
1051             loadPtr(Address(regT0, JSObject::butterflyOffset()), regT0);
1052             loadPtr(operandSlot, regT1);
1053             negPtr(regT1);
1054             storePtr(regT2, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)));
1055             emitWriteBarrier(m_codeBlock->globalObject(), value, ShouldFilterValue);
1056             break;
1057         }
1058         case GlobalVar:
1059         case GlobalVarWithVarInjectionChecks:
1060         case GlobalLexicalVar:
1061         case GlobalLexicalVarWithVarInjectionChecks: {
1062             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
1063             RELEASE_ASSERT(constantScope);
1064             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1065             if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) {
1066                 // We need to do a TDZ check here because we can't always prove we need to emit TDZ checks statically.
1067                 if (indirectLoadForOperand)
1068                     emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT0);
1069                 else
1070                     emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT0);
1071                 addSlowCase(branchTest64(Zero, regT0));
1072             }
1073             if (indirectLoadForOperand)
1074                 emitPutGlobalVariableIndirect(bitwise_cast<JSValue**>(operandSlot), value, bitwise_cast<WatchpointSet**>(&currentInstruction[5]));
1075             else
1076                 emitPutGlobalVariable(bitwise_cast<JSValue*>(*operandSlot), value, currentInstruction[5].u.watchpointSet);
1077             emitWriteBarrier(constantScope, value, ShouldFilterValue);
1078             break;
1079         }
1080         case LocalClosureVar:
1081         case ClosureVar:
1082         case ClosureVarWithVarInjectionChecks:
1083             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1084             emitPutClosureVar(scope, *operandSlot, value, currentInstruction[5].u.watchpointSet);
1085             emitWriteBarrier(scope, value, ShouldFilterValue);
1086             break;
1087         case ModuleVar:
1088         case Dynamic:
1089             addSlowCase(jump());
1090             break;
1091         case UnresolvedProperty:
1092         case UnresolvedPropertyWithVarInjectionChecks:
1093             RELEASE_ASSERT_NOT_REACHED();
1094             break;
1095         }
1096     };
1097
1098     switch (resolveType) {
1099     case UnresolvedProperty:
1100     case UnresolvedPropertyWithVarInjectionChecks: {
1101         JumpList skipToEnd;
1102         load32(&currentInstruction[4], regT0);
1103         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
1104
1105         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
1106         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
1107         isGlobalProperty.link(this);
1108         emitCode(GlobalProperty, false);
1109         skipToEnd.append(jump());
1110         notGlobalPropertyWithVarInjections.link(this);
1111
1112         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
1113         emitCode(GlobalLexicalVar, true);
1114         skipToEnd.append(jump());
1115         notGlobalLexicalVar.link(this);
1116
1117         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
1118         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
1119         skipToEnd.append(jump());
1120         notGlobalLexicalVarWithVarInjections.link(this);
1121
1122         addSlowCase(jump());
1123
1124         skipToEnd.link(this);
1125         break;
1126     }
1127
1128     default:
1129         emitCode(resolveType, false);
1130         break;
1131     }
1132 }
1133
1134 void JIT::emitSlow_op_put_to_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1135 {
1136     GetPutInfo getPutInfo = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand);
1137     ResolveType resolveType = getPutInfo.resolveType();
1138     unsigned linkCount = 0;
1139     if (resolveType != GlobalVar && resolveType != ClosureVar && resolveType != LocalClosureVar && resolveType != GlobalLexicalVar)
1140         linkCount++;
1141     if (resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks 
1142         || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks 
1143         || resolveType == ClosureVar || resolveType == ClosureVarWithVarInjectionChecks
1144         || resolveType == LocalClosureVar)
1145         linkCount++;
1146     if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
1147         linkCount++; // bad structure
1148     if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) // TDZ check.
1149         linkCount++;
1150     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
1151         // GlobalProperty/GlobalPropertyWithVarInjectionsCheck
1152         linkCount++; // emitLoadWithStructureCheck
1153         linkCount++; // emitLoadWithStructureCheck
1154
1155         // GlobalLexicalVar
1156         bool needsTDZCheck = !isInitialization(getPutInfo.initializationMode());
1157         if (needsTDZCheck)
1158             linkCount++;
1159         linkCount++; // Notify write check.
1160
1161         // GlobalLexicalVarWithVarInjectionsCheck
1162         linkCount++; // var injection check.
1163         if (needsTDZCheck)
1164             linkCount++;
1165         linkCount++; // Notify write check.
1166     }
1167     if (!linkCount)
1168         return;
1169     while (linkCount--)
1170         linkSlowCase(iter);
1171
1172     if (resolveType == ModuleVar) {
1173         JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_throw_strict_mode_readonly_property_write_error);
1174         slowPathCall.call();
1175     } else
1176         callOperation(operationPutToScope, currentInstruction);
1177 }
1178
1179 void JIT::emit_op_get_from_arguments(Instruction* currentInstruction)
1180 {
1181     int dst = currentInstruction[1].u.operand;
1182     int arguments = currentInstruction[2].u.operand;
1183     int index = currentInstruction[3].u.operand;
1184     
1185     emitGetVirtualRegister(arguments, regT0);
1186     load64(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>)), regT0);
1187     emitValueProfilingSite();
1188     emitPutVirtualRegister(dst);
1189 }
1190
1191 void JIT::emit_op_put_to_arguments(Instruction* currentInstruction)
1192 {
1193     int arguments = currentInstruction[1].u.operand;
1194     int index = currentInstruction[2].u.operand;
1195     int value = currentInstruction[3].u.operand;
1196     
1197     emitGetVirtualRegister(arguments, regT0);
1198     emitGetVirtualRegister(value, regT1);
1199     store64(regT1, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>)));
1200
1201     emitWriteBarrier(arguments, value, ShouldFilterValue);
1202 }
1203
1204 #endif // USE(JSVALUE64)
1205
1206 #if USE(JSVALUE64)
1207 void JIT::emitWriteBarrier(unsigned owner, unsigned value, WriteBarrierMode mode)
1208 {
1209     Jump valueNotCell;
1210     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) {
1211         emitGetVirtualRegister(value, regT0);
1212         valueNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1213     }
1214     
1215     emitGetVirtualRegister(owner, regT0);
1216     Jump ownerNotCell;
1217     if (mode == ShouldFilterBaseAndValue || mode == ShouldFilterBase)
1218         ownerNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1219
1220     Jump ownerIsRememberedOrInEden = barrierBranch(regT0, regT1);
1221     callOperation(operationWriteBarrierSlowPath, regT0);
1222     ownerIsRememberedOrInEden.link(this);
1223
1224     if (mode == ShouldFilterBaseAndValue || mode == ShouldFilterBase)
1225         ownerNotCell.link(this);
1226     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) 
1227         valueNotCell.link(this);
1228 }
1229
1230 void JIT::emitWriteBarrier(JSCell* owner, unsigned value, WriteBarrierMode mode)
1231 {
1232     emitGetVirtualRegister(value, regT0);
1233     Jump valueNotCell;
1234     if (mode == ShouldFilterValue)
1235         valueNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1236
1237     emitWriteBarrier(owner);
1238
1239     if (mode == ShouldFilterValue) 
1240         valueNotCell.link(this);
1241 }
1242
1243 #else // USE(JSVALUE64)
1244
1245 void JIT::emitWriteBarrier(unsigned owner, unsigned value, WriteBarrierMode mode)
1246 {
1247     Jump valueNotCell;
1248     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) {
1249         emitLoadTag(value, regT0);
1250         valueNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1251     }
1252     
1253     emitLoad(owner, regT0, regT1);
1254     Jump ownerNotCell;
1255     if (mode == ShouldFilterBase || mode == ShouldFilterBaseAndValue)
1256         ownerNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1257
1258     Jump ownerIsRememberedOrInEden = barrierBranch(regT1, regT2);
1259     callOperation(operationWriteBarrierSlowPath, regT1);
1260     ownerIsRememberedOrInEden.link(this);
1261
1262     if (mode == ShouldFilterBase || mode == ShouldFilterBaseAndValue)
1263         ownerNotCell.link(this);
1264     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) 
1265         valueNotCell.link(this);
1266 }
1267
1268 void JIT::emitWriteBarrier(JSCell* owner, unsigned value, WriteBarrierMode mode)
1269 {
1270     Jump valueNotCell;
1271     if (mode == ShouldFilterValue) {
1272         emitLoadTag(value, regT0);
1273         valueNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1274     }
1275
1276     emitWriteBarrier(owner);
1277
1278     if (mode == ShouldFilterValue) 
1279         valueNotCell.link(this);
1280 }
1281
1282 #endif // USE(JSVALUE64)
1283
1284 void JIT::emitWriteBarrier(JSCell* owner)
1285 {
1286     Jump ownerIsRememberedOrInEden = barrierBranch(owner, regT0);
1287     callOperation(operationWriteBarrierSlowPath, owner);
1288     ownerIsRememberedOrInEden.link(this);
1289 }
1290
1291 void JIT::emitByValIdentifierCheck(ByValInfo* byValInfo, RegisterID cell, RegisterID scratch, const Identifier& propertyName, JumpList& slowCases)
1292 {
1293     if (propertyName.isSymbol())
1294         slowCases.append(branchPtr(NotEqual, cell, TrustedImmPtr(byValInfo->cachedSymbol.get())));
1295     else {
1296         slowCases.append(branchStructure(NotEqual, Address(cell, JSCell::structureIDOffset()), m_vm->stringStructure.get()));
1297         loadPtr(Address(cell, JSString::offsetOfValue()), scratch);
1298         slowCases.append(branchPtr(NotEqual, scratch, TrustedImmPtr(propertyName.impl())));
1299     }
1300 }
1301
1302 void JIT::privateCompileGetByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1303 {
1304     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1305     
1306     PatchableJump badType;
1307     JumpList slowCases;
1308     
1309     switch (arrayMode) {
1310     case JITInt32:
1311         slowCases = emitInt32GetByVal(currentInstruction, badType);
1312         break;
1313     case JITDouble:
1314         slowCases = emitDoubleGetByVal(currentInstruction, badType);
1315         break;
1316     case JITContiguous:
1317         slowCases = emitContiguousGetByVal(currentInstruction, badType);
1318         break;
1319     case JITArrayStorage:
1320         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
1321         break;
1322     case JITDirectArguments:
1323         slowCases = emitDirectArgumentsGetByVal(currentInstruction, badType);
1324         break;
1325     case JITScopedArguments:
1326         slowCases = emitScopedArgumentsGetByVal(currentInstruction, badType);
1327         break;
1328     default:
1329         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1330         if (isInt(type))
1331             slowCases = emitIntTypedArrayGetByVal(currentInstruction, badType, type);
1332         else 
1333             slowCases = emitFloatTypedArrayGetByVal(currentInstruction, badType, type);
1334         break;
1335     }
1336     
1337     Jump done = jump();
1338
1339     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1340     
1341     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1342     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1343     
1344     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1345     
1346     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1347         m_codeBlock, patchBuffer,
1348         ("Baseline get_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1349     
1350     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1351     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1352 }
1353
1354 void JIT::privateCompileGetByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName)
1355 {
1356     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1357
1358     Jump fastDoneCase;
1359     Jump slowDoneCase;
1360     JumpList slowCases;
1361
1362     JITGetByIdGenerator gen = emitGetByValWithCachedId(byValInfo, currentInstruction, propertyName, fastDoneCase, slowDoneCase, slowCases);
1363
1364     ConcurrentJSLocker locker(m_codeBlock->m_lock);
1365     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1366     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1367     patchBuffer.link(fastDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1368     patchBuffer.link(slowDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToNextHotPath));
1369     if (!m_exceptionChecks.empty())
1370         patchBuffer.link(m_exceptionChecks, byValInfo->exceptionHandler);
1371
1372     for (const auto& callSite : m_calls) {
1373         if (callSite.to)
1374             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1375     }
1376     gen.finalize(patchBuffer);
1377
1378     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1379         m_codeBlock, patchBuffer,
1380         ("Baseline get_by_val with cached property name '%s' stub for %s, return point %p", propertyName.impl()->utf8().data(), toCString(*m_codeBlock).data(), returnAddress.value()));
1381     byValInfo->stubInfo = gen.stubInfo();
1382
1383     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1384     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1385 }
1386
1387 void JIT::privateCompilePutByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1388 {
1389     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1390     
1391     PatchableJump badType;
1392     JumpList slowCases;
1393
1394     bool needsLinkForWriteBarrier = false;
1395
1396     switch (arrayMode) {
1397     case JITInt32:
1398         slowCases = emitInt32PutByVal(currentInstruction, badType);
1399         break;
1400     case JITDouble:
1401         slowCases = emitDoublePutByVal(currentInstruction, badType);
1402         break;
1403     case JITContiguous:
1404         slowCases = emitContiguousPutByVal(currentInstruction, badType);
1405         needsLinkForWriteBarrier = true;
1406         break;
1407     case JITArrayStorage:
1408         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
1409         needsLinkForWriteBarrier = true;
1410         break;
1411     default:
1412         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1413         if (isInt(type))
1414             slowCases = emitIntTypedArrayPutByVal(currentInstruction, badType, type);
1415         else 
1416             slowCases = emitFloatTypedArrayPutByVal(currentInstruction, badType, type);
1417         break;
1418     }
1419     
1420     Jump done = jump();
1421
1422     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1423     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1424     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1425     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1426     if (needsLinkForWriteBarrier) {
1427         ASSERT(m_calls.last().to == operationWriteBarrierSlowPath);
1428         patchBuffer.link(m_calls.last().from, operationWriteBarrierSlowPath);
1429     }
1430     
1431     bool isDirect = m_interpreter->getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
1432     if (!isDirect) {
1433         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1434             m_codeBlock, patchBuffer,
1435             ("Baseline put_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1436         
1437     } else {
1438         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1439             m_codeBlock, patchBuffer,
1440             ("Baseline put_by_val_direct stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1441     }
1442     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1443     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(isDirect ? operationDirectPutByValGeneric : operationPutByValGeneric));
1444 }
1445
1446 void JIT::privateCompilePutByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, PutKind putKind, const Identifier& propertyName)
1447 {
1448     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1449
1450     JumpList doneCases;
1451     JumpList slowCases;
1452
1453     JITPutByIdGenerator gen = emitPutByValWithCachedId(byValInfo, currentInstruction, putKind, propertyName, doneCases, slowCases);
1454
1455     ConcurrentJSLocker locker(m_codeBlock->m_lock);
1456     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1457     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1458     patchBuffer.link(doneCases, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1459     if (!m_exceptionChecks.empty())
1460         patchBuffer.link(m_exceptionChecks, byValInfo->exceptionHandler);
1461
1462     for (const auto& callSite : m_calls) {
1463         if (callSite.to)
1464             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1465     }
1466     gen.finalize(patchBuffer);
1467
1468     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1469         m_codeBlock, patchBuffer,
1470         ("Baseline put_by_val%s with cached property name '%s' stub for %s, return point %p", (putKind == Direct) ? "_direct" : "", propertyName.impl()->utf8().data(), toCString(*m_codeBlock).data(), returnAddress.value()));
1471     byValInfo->stubInfo = gen.stubInfo();
1472
1473     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1474     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(putKind == Direct ? operationDirectPutByValGeneric : operationPutByValGeneric));
1475 }
1476
1477
1478 JIT::JumpList JIT::emitDirectArgumentsGetByVal(Instruction*, PatchableJump& badType)
1479 {
1480     JumpList slowCases;
1481     
1482 #if USE(JSVALUE64)
1483     RegisterID base = regT0;
1484     RegisterID property = regT1;
1485     JSValueRegs result = JSValueRegs(regT0);
1486     RegisterID scratch = regT3;
1487 #else
1488     RegisterID base = regT0;
1489     RegisterID property = regT2;
1490     JSValueRegs result = JSValueRegs(regT1, regT0);
1491     RegisterID scratch = regT3;
1492 #endif
1493
1494     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1495     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(DirectArgumentsType));
1496     
1497     slowCases.append(branch32(AboveOrEqual, property, Address(base, DirectArguments::offsetOfLength())));
1498     slowCases.append(branchTestPtr(NonZero, Address(base, DirectArguments::offsetOfMappedArguments())));
1499     
1500     zeroExtend32ToPtr(property, scratch);
1501     loadValue(BaseIndex(base, scratch, TimesEight, DirectArguments::storageOffset()), result);
1502     
1503     return slowCases;
1504 }
1505
1506 JIT::JumpList JIT::emitScopedArgumentsGetByVal(Instruction*, PatchableJump& badType)
1507 {
1508     JumpList slowCases;
1509     
1510 #if USE(JSVALUE64)
1511     RegisterID base = regT0;
1512     RegisterID property = regT1;
1513     JSValueRegs result = JSValueRegs(regT0);
1514     RegisterID scratch = regT3;
1515     RegisterID scratch2 = regT4;
1516 #else
1517     RegisterID base = regT0;
1518     RegisterID property = regT2;
1519     JSValueRegs result = JSValueRegs(regT1, regT0);
1520     RegisterID scratch = regT3;
1521     RegisterID scratch2 = regT4;
1522 #endif
1523
1524     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1525     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(ScopedArgumentsType));
1526     slowCases.append(branch32(AboveOrEqual, property, Address(base, ScopedArguments::offsetOfTotalLength())));
1527     
1528     loadPtr(Address(base, ScopedArguments::offsetOfTable()), scratch);
1529     load32(Address(scratch, ScopedArgumentsTable::offsetOfLength()), scratch2);
1530     Jump overflowCase = branch32(AboveOrEqual, property, scratch2);
1531     loadPtr(Address(base, ScopedArguments::offsetOfScope()), scratch2);
1532     loadPtr(Address(scratch, ScopedArgumentsTable::offsetOfArguments()), scratch);
1533     load32(BaseIndex(scratch, property, TimesFour), scratch);
1534     slowCases.append(branch32(Equal, scratch, TrustedImm32(ScopeOffset::invalidOffset)));
1535     loadValue(BaseIndex(scratch2, scratch, TimesEight, JSEnvironmentRecord::offsetOfVariables()), result);
1536     Jump done = jump();
1537     overflowCase.link(this);
1538     sub32(property, scratch2);
1539     neg32(scratch2);
1540     loadValue(BaseIndex(base, scratch2, TimesEight, ScopedArguments::overflowStorageOffset()), result);
1541     slowCases.append(branchIfEmpty(result));
1542     done.link(this);
1543     
1544     return slowCases;
1545 }
1546
1547 JIT::JumpList JIT::emitIntTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1548 {
1549     ASSERT(isInt(type));
1550     
1551     // The best way to test the array type is to use the classInfo. We need to do so without
1552     // clobbering the register that holds the indexing type, base, and property.
1553
1554 #if USE(JSVALUE64)
1555     RegisterID base = regT0;
1556     RegisterID property = regT1;
1557     RegisterID resultPayload = regT0;
1558     RegisterID scratch = regT3;
1559 #else
1560     RegisterID base = regT0;
1561     RegisterID property = regT2;
1562     RegisterID resultPayload = regT0;
1563     RegisterID resultTag = regT1;
1564     RegisterID scratch = regT3;
1565 #endif
1566     
1567     JumpList slowCases;
1568     
1569     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1570     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1571     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1572     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1573     
1574     switch (elementSize(type)) {
1575     case 1:
1576         if (JSC::isSigned(type))
1577             load8SignedExtendTo32(BaseIndex(scratch, property, TimesOne), resultPayload);
1578         else
1579             load8(BaseIndex(scratch, property, TimesOne), resultPayload);
1580         break;
1581     case 2:
1582         if (JSC::isSigned(type))
1583             load16SignedExtendTo32(BaseIndex(scratch, property, TimesTwo), resultPayload);
1584         else
1585             load16(BaseIndex(scratch, property, TimesTwo), resultPayload);
1586         break;
1587     case 4:
1588         load32(BaseIndex(scratch, property, TimesFour), resultPayload);
1589         break;
1590     default:
1591         CRASH();
1592     }
1593     
1594     Jump done;
1595     if (type == TypeUint32) {
1596         Jump canBeInt = branch32(GreaterThanOrEqual, resultPayload, TrustedImm32(0));
1597         
1598         convertInt32ToDouble(resultPayload, fpRegT0);
1599         addDouble(AbsoluteAddress(&twoToThe32), fpRegT0);
1600 #if USE(JSVALUE64)
1601         moveDoubleTo64(fpRegT0, resultPayload);
1602         sub64(tagTypeNumberRegister, resultPayload);
1603 #else
1604         moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1605 #endif
1606         
1607         done = jump();
1608         canBeInt.link(this);
1609     }
1610
1611 #if USE(JSVALUE64)
1612     or64(tagTypeNumberRegister, resultPayload);
1613 #else
1614     move(TrustedImm32(JSValue::Int32Tag), resultTag);
1615 #endif
1616     if (done.isSet())
1617         done.link(this);
1618     return slowCases;
1619 }
1620
1621 JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1622 {
1623     ASSERT(isFloat(type));
1624     
1625 #if USE(JSVALUE64)
1626     RegisterID base = regT0;
1627     RegisterID property = regT1;
1628     RegisterID resultPayload = regT0;
1629     RegisterID scratch = regT3;
1630 #else
1631     RegisterID base = regT0;
1632     RegisterID property = regT2;
1633     RegisterID resultPayload = regT0;
1634     RegisterID resultTag = regT1;
1635     RegisterID scratch = regT3;
1636 #endif
1637     
1638     JumpList slowCases;
1639
1640     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1641     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1642     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1643     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1644     
1645     switch (elementSize(type)) {
1646     case 4:
1647         loadFloat(BaseIndex(scratch, property, TimesFour), fpRegT0);
1648         convertFloatToDouble(fpRegT0, fpRegT0);
1649         break;
1650     case 8: {
1651         loadDouble(BaseIndex(scratch, property, TimesEight), fpRegT0);
1652         break;
1653     }
1654     default:
1655         CRASH();
1656     }
1657     
1658     Jump notNaN = branchDouble(DoubleEqual, fpRegT0, fpRegT0);
1659     static const double NaN = PNaN;
1660     loadDouble(TrustedImmPtr(&NaN), fpRegT0);
1661     notNaN.link(this);
1662     
1663 #if USE(JSVALUE64)
1664     moveDoubleTo64(fpRegT0, resultPayload);
1665     sub64(tagTypeNumberRegister, resultPayload);
1666 #else
1667     moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1668 #endif
1669     return slowCases;    
1670 }
1671
1672 JIT::JumpList JIT::emitIntTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1673 {
1674     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1675     ASSERT(isInt(type));
1676     
1677     int value = currentInstruction[3].u.operand;
1678
1679 #if USE(JSVALUE64)
1680     RegisterID base = regT0;
1681     RegisterID property = regT1;
1682     RegisterID earlyScratch = regT3;
1683     RegisterID lateScratch = regT2;
1684 #else
1685     RegisterID base = regT0;
1686     RegisterID property = regT2;
1687     RegisterID earlyScratch = regT3;
1688     RegisterID lateScratch = regT1;
1689 #endif
1690     
1691     JumpList slowCases;
1692     
1693     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1694     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1695     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1696     emitArrayProfileOutOfBoundsSpecialCase(profile);
1697     slowCases.append(jump());
1698     inBounds.link(this);
1699     
1700 #if USE(JSVALUE64)
1701     emitGetVirtualRegister(value, earlyScratch);
1702     slowCases.append(emitJumpIfNotInt(earlyScratch));
1703 #else
1704     emitLoad(value, lateScratch, earlyScratch);
1705     slowCases.append(branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag)));
1706 #endif
1707     
1708     // We would be loading this into base as in get_by_val, except that the slow
1709     // path expects the base to be unclobbered.
1710     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1711     
1712     if (isClamped(type)) {
1713         ASSERT(elementSize(type) == 1);
1714         ASSERT(!JSC::isSigned(type));
1715         Jump inBounds = branch32(BelowOrEqual, earlyScratch, TrustedImm32(0xff));
1716         Jump tooBig = branch32(GreaterThan, earlyScratch, TrustedImm32(0xff));
1717         xor32(earlyScratch, earlyScratch);
1718         Jump clamped = jump();
1719         tooBig.link(this);
1720         move(TrustedImm32(0xff), earlyScratch);
1721         clamped.link(this);
1722         inBounds.link(this);
1723     }
1724     
1725     switch (elementSize(type)) {
1726     case 1:
1727         store8(earlyScratch, BaseIndex(lateScratch, property, TimesOne));
1728         break;
1729     case 2:
1730         store16(earlyScratch, BaseIndex(lateScratch, property, TimesTwo));
1731         break;
1732     case 4:
1733         store32(earlyScratch, BaseIndex(lateScratch, property, TimesFour));
1734         break;
1735     default:
1736         CRASH();
1737     }
1738     
1739     return slowCases;
1740 }
1741
1742 JIT::JumpList JIT::emitFloatTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1743 {
1744     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1745     ASSERT(isFloat(type));
1746     
1747     int value = currentInstruction[3].u.operand;
1748
1749 #if USE(JSVALUE64)
1750     RegisterID base = regT0;
1751     RegisterID property = regT1;
1752     RegisterID earlyScratch = regT3;
1753     RegisterID lateScratch = regT2;
1754 #else
1755     RegisterID base = regT0;
1756     RegisterID property = regT2;
1757     RegisterID earlyScratch = regT3;
1758     RegisterID lateScratch = regT1;
1759 #endif
1760     
1761     JumpList slowCases;
1762     
1763     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1764     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1765     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1766     emitArrayProfileOutOfBoundsSpecialCase(profile);
1767     slowCases.append(jump());
1768     inBounds.link(this);
1769     
1770 #if USE(JSVALUE64)
1771     emitGetVirtualRegister(value, earlyScratch);
1772     Jump doubleCase = emitJumpIfNotInt(earlyScratch);
1773     convertInt32ToDouble(earlyScratch, fpRegT0);
1774     Jump ready = jump();
1775     doubleCase.link(this);
1776     slowCases.append(emitJumpIfNotNumber(earlyScratch));
1777     add64(tagTypeNumberRegister, earlyScratch);
1778     move64ToDouble(earlyScratch, fpRegT0);
1779     ready.link(this);
1780 #else
1781     emitLoad(value, lateScratch, earlyScratch);
1782     Jump doubleCase = branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag));
1783     convertInt32ToDouble(earlyScratch, fpRegT0);
1784     Jump ready = jump();
1785     doubleCase.link(this);
1786     slowCases.append(branch32(Above, lateScratch, TrustedImm32(JSValue::LowestTag)));
1787     moveIntsToDouble(earlyScratch, lateScratch, fpRegT0, fpRegT1);
1788     ready.link(this);
1789 #endif
1790     
1791     // We would be loading this into base as in get_by_val, except that the slow
1792     // path expects the base to be unclobbered.
1793     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1794     
1795     switch (elementSize(type)) {
1796     case 4:
1797         convertDoubleToFloat(fpRegT0, fpRegT0);
1798         storeFloat(fpRegT0, BaseIndex(lateScratch, property, TimesFour));
1799         break;
1800     case 8:
1801         storeDouble(fpRegT0, BaseIndex(lateScratch, property, TimesEight));
1802         break;
1803     default:
1804         CRASH();
1805     }
1806     
1807     return slowCases;
1808 }
1809
1810 void JIT::emit_op_define_data_property(Instruction* currentInstruction)
1811 {
1812     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_define_data_property);
1813     slowPathCall.call();
1814 }
1815
1816 void JIT::emit_op_define_accessor_property(Instruction* currentInstruction)
1817 {
1818     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_define_accessor_property);
1819     slowPathCall.call();
1820 }
1821
1822 } // namespace JSC
1823
1824 #endif // ENABLE(JIT)