Butterflies should be allocated in Auxiliary MarkedSpace instead of CopiedSpace and...
[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     emitWriteBarrier(base, value, ShouldFilterValue);
446     emitGetVirtualRegisters(base, regT0, value, regT1);
447
448     JITPutByIdGenerator gen(
449         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
450         JSValueRegs(regT0), JSValueRegs(regT1), regT2, m_codeBlock->ecmaMode(), putKind);
451     gen.generateFastPath(*this);
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::GetPure);
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     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_get_by_id_with_this);
636     slowPathCall.call();
637 }
638
639 void JIT::emit_op_get_by_val_with_this(Instruction* currentInstruction)
640 {
641     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_get_by_val_with_this);
642     slowPathCall.call();
643 }
644
645 void JIT::emitSlow_op_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
646 {
647     int resultVReg = currentInstruction[1].u.operand;
648     int baseVReg = currentInstruction[2].u.operand;
649     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
650
651     linkSlowCaseIfNotJSCell(iter, baseVReg);
652     linkSlowCase(iter);
653
654     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
655     
656     Label coldPathBegin = label();
657     
658     Call call = callOperation(WithProfile, operationGetByIdOptimize, resultVReg, gen.stubInfo(), regT0, ident->impl());
659
660     gen.reportSlowPathCall(coldPathBegin, call);
661 }
662
663 void JIT::emit_op_put_by_id(Instruction* currentInstruction)
664 {
665     int baseVReg = currentInstruction[1].u.operand;
666     int valueVReg = currentInstruction[3].u.operand;
667     unsigned direct = currentInstruction[8].u.putByIdFlags & PutByIdIsDirect;
668
669     emitWriteBarrier(baseVReg, valueVReg, ShouldFilterBase);
670
671     // In order to be able to patch both the Structure, and the object offset, we store one pointer,
672     // to just after the arguments have been loaded into registers 'hotPathBegin', and we generate code
673     // such that the Structure & offset are always at the same distance from this.
674
675     emitGetVirtualRegisters(baseVReg, regT0, valueVReg, regT1);
676
677     emitJumpSlowCaseIfNotJSCell(regT0, baseVReg);
678
679     JITPutByIdGenerator gen(
680         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(m_bytecodeOffset), RegisterSet::stubUnavailableRegisters(),
681         JSValueRegs(regT0), JSValueRegs(regT1), regT2, m_codeBlock->ecmaMode(),
682         direct ? Direct : NotDirect);
683     
684     gen.generateFastPath(*this);
685     addSlowCase(gen.slowPathJump());
686     
687     m_putByIds.append(gen);
688 }
689
690 void JIT::emit_op_put_by_id_with_this(Instruction* currentInstruction)
691 {
692     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_put_by_id_with_this);
693     slowPathCall.call();
694 }
695
696 void JIT::emitSlow_op_put_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
697 {
698     int baseVReg = currentInstruction[1].u.operand;
699     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[2].u.operand));
700
701     linkSlowCaseIfNotJSCell(iter, baseVReg);
702     linkSlowCase(iter);
703
704     Label coldPathBegin(this);
705     
706     JITPutByIdGenerator& gen = m_putByIds[m_putByIdIndex++];
707
708     Call call = callOperation(
709         gen.slowPathFunction(), gen.stubInfo(), regT1, regT0, ident->impl());
710
711     gen.reportSlowPathCall(coldPathBegin, call);
712 }
713
714 void JIT::emitVarInjectionCheck(bool needsVarInjectionChecks)
715 {
716     if (!needsVarInjectionChecks)
717         return;
718     addSlowCase(branch8(Equal, AbsoluteAddress(m_codeBlock->globalObject()->varInjectionWatchpoint()->addressOfState()), TrustedImm32(IsInvalidated)));
719 }
720
721 void JIT::emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth)
722 {
723     emitVarInjectionCheck(needsVarInjectionChecks);
724     emitGetVirtualRegister(scope, regT0);
725     for (unsigned i = 0; i < depth; ++i)
726         loadPtr(Address(regT0, JSScope::offsetOfNext()), regT0);
727     emitPutVirtualRegister(dst);
728 }
729
730 void JIT::emit_op_resolve_scope(Instruction* currentInstruction)
731 {
732     int dst = currentInstruction[1].u.operand;
733     int scope = currentInstruction[2].u.operand;
734     ResolveType resolveType = static_cast<ResolveType>(copiedInstruction(currentInstruction)[4].u.operand);
735     unsigned depth = currentInstruction[5].u.operand;
736
737     auto emitCode = [&] (ResolveType resolveType) {
738         switch (resolveType) {
739         case GlobalProperty:
740         case GlobalVar:
741         case GlobalPropertyWithVarInjectionChecks:
742         case GlobalVarWithVarInjectionChecks:
743         case GlobalLexicalVar:
744         case GlobalLexicalVarWithVarInjectionChecks: {
745             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
746             RELEASE_ASSERT(constantScope);
747             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
748             move(TrustedImmPtr(constantScope), regT0);
749             emitPutVirtualRegister(dst);
750             break;
751         }
752         case ClosureVar:
753         case ClosureVarWithVarInjectionChecks:
754             emitResolveClosure(dst, scope, needsVarInjectionChecks(resolveType), depth);
755             break;
756         case ModuleVar:
757             move(TrustedImmPtr(currentInstruction[6].u.jsCell.get()), regT0);
758             emitPutVirtualRegister(dst);
759             break;
760         case Dynamic:
761             addSlowCase(jump());
762             break;
763         case LocalClosureVar:
764         case UnresolvedProperty:
765         case UnresolvedPropertyWithVarInjectionChecks:
766             RELEASE_ASSERT_NOT_REACHED();
767         }
768     };
769
770     switch (resolveType) {
771     case UnresolvedProperty:
772     case UnresolvedPropertyWithVarInjectionChecks: {
773         JumpList skipToEnd;
774         load32(&currentInstruction[4], regT0);
775
776         Jump notGlobalProperty = branch32(NotEqual, regT0, TrustedImm32(GlobalProperty));
777         emitCode(GlobalProperty);
778         skipToEnd.append(jump());
779         notGlobalProperty.link(this);
780
781         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
782         emitCode(GlobalPropertyWithVarInjectionChecks);
783         skipToEnd.append(jump());
784         notGlobalPropertyWithVarInjections.link(this);
785
786         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
787         emitCode(GlobalLexicalVar);
788         skipToEnd.append(jump());
789         notGlobalLexicalVar.link(this);
790
791         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
792         emitCode(GlobalLexicalVarWithVarInjectionChecks);
793         skipToEnd.append(jump());
794         notGlobalLexicalVarWithVarInjections.link(this);
795
796         addSlowCase(jump());
797         skipToEnd.link(this);
798         break;
799     }
800
801     default:
802         emitCode(resolveType);
803         break;
804     }
805 }
806
807 void JIT::emitSlow_op_resolve_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
808 {
809     ResolveType resolveType = static_cast<ResolveType>(copiedInstruction(currentInstruction)[4].u.operand);
810     if (resolveType == GlobalProperty || resolveType == GlobalVar || resolveType == ClosureVar || resolveType == GlobalLexicalVar || resolveType == ModuleVar)
811         return;
812
813     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
814         linkSlowCase(iter); // var injections check for GlobalPropertyWithVarInjectionChecks.
815         linkSlowCase(iter); // var injections check for GlobalLexicalVarWithVarInjectionChecks.
816     }
817
818     linkSlowCase(iter);
819     JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_resolve_scope);
820     slowPathCall.call();
821 }
822
823 void JIT::emitLoadWithStructureCheck(int scope, Structure** structureSlot)
824 {
825     loadPtr(structureSlot, regT1);
826     emitGetVirtualRegister(scope, regT0);
827     addSlowCase(branchTestPtr(Zero, regT1));
828     load32(Address(regT1, Structure::structureIDOffset()), regT1);
829     addSlowCase(branch32(NotEqual, Address(regT0, JSCell::structureIDOffset()), regT1));
830 }
831
832 void JIT::emitGetVarFromPointer(JSValue* operand, GPRReg reg)
833 {
834     loadPtr(operand, reg);
835 }
836
837 void JIT::emitGetVarFromIndirectPointer(JSValue** operand, GPRReg reg)
838 {
839     loadPtr(operand, reg);
840     loadPtr(reg, reg);
841 }
842
843 void JIT::emitGetClosureVar(int scope, uintptr_t operand)
844 {
845     emitGetVirtualRegister(scope, regT0);
846     loadPtr(Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register)), regT0);
847 }
848
849 void JIT::emit_op_get_from_scope(Instruction* currentInstruction)
850 {
851     int dst = currentInstruction[1].u.operand;
852     int scope = currentInstruction[2].u.operand;
853     ResolveType resolveType = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand).resolveType();
854     Structure** structureSlot = currentInstruction[5].u.structure.slot();
855     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
856
857     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
858         switch (resolveType) {
859         case GlobalProperty:
860         case GlobalPropertyWithVarInjectionChecks: {
861             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
862             GPRReg base = regT0;
863             GPRReg result = regT0;
864             GPRReg offset = regT1;
865             GPRReg scratch = regT2;
866             
867             load32(operandSlot, offset);
868             if (!ASSERT_DISABLED) {
869                 Jump isOutOfLine = branch32(GreaterThanOrEqual, offset, TrustedImm32(firstOutOfLineOffset));
870                 abortWithReason(JITOffsetIsNotOutOfLine);
871                 isOutOfLine.link(this);
872             }
873             loadPtr(Address(base, JSObject::butterflyOffset()), scratch);
874             neg32(offset);
875             signExtend32ToPtr(offset, offset);
876             load64(BaseIndex(scratch, offset, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), result);
877             break;
878         }
879         case GlobalVar:
880         case GlobalVarWithVarInjectionChecks:
881         case GlobalLexicalVar:
882         case GlobalLexicalVarWithVarInjectionChecks:
883             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
884             if (indirectLoadForOperand)
885                 emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT0);
886             else
887                 emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT0);
888             if (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks) // TDZ check.
889                 addSlowCase(branchTest64(Zero, regT0));
890             break;
891         case ClosureVar:
892         case ClosureVarWithVarInjectionChecks:
893             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
894             emitGetClosureVar(scope, *operandSlot);
895             break;
896         case Dynamic:
897             addSlowCase(jump());
898             break;
899         case LocalClosureVar:
900         case ModuleVar:
901         case UnresolvedProperty:
902         case UnresolvedPropertyWithVarInjectionChecks:
903             RELEASE_ASSERT_NOT_REACHED();
904         }
905     };
906
907     switch (resolveType) {
908     case UnresolvedProperty:
909     case UnresolvedPropertyWithVarInjectionChecks: {
910         JumpList skipToEnd;
911         load32(&currentInstruction[4], regT0);
912         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
913
914         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
915         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
916         isGlobalProperty.link(this);
917         emitCode(GlobalProperty, false);
918         skipToEnd.append(jump());
919         notGlobalPropertyWithVarInjections.link(this);
920
921         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
922         emitCode(GlobalLexicalVar, true);
923         skipToEnd.append(jump());
924         notGlobalLexicalVar.link(this);
925
926         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
927         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
928         skipToEnd.append(jump());
929         notGlobalLexicalVarWithVarInjections.link(this);
930
931         addSlowCase(jump());
932
933         skipToEnd.link(this);
934         break;
935     }
936
937     default:
938         emitCode(resolveType, false);
939         break;
940     }
941     emitPutVirtualRegister(dst);
942     emitValueProfilingSite();
943 }
944
945 void JIT::emitSlow_op_get_from_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
946 {
947     int dst = currentInstruction[1].u.operand;
948     ResolveType resolveType = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand).resolveType();
949
950     if (resolveType == GlobalVar || resolveType == ClosureVar)
951         return;
952
953     if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
954         linkSlowCase(iter); // bad structure
955
956     if (resolveType == GlobalLexicalVarWithVarInjectionChecks) // Var injections check.
957         linkSlowCase(iter);
958
959     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
960         // GlobalProperty/GlobalPropertyWithVarInjectionChecks
961         linkSlowCase(iter); // emitLoadWithStructureCheck
962         linkSlowCase(iter); // emitLoadWithStructureCheck
963         // GlobalLexicalVar
964         linkSlowCase(iter); // TDZ check.
965         // GlobalLexicalVarWithVarInjectionChecks.
966         linkSlowCase(iter); // var injection check.
967         linkSlowCase(iter); // TDZ check.
968     }
969
970     linkSlowCase(iter);
971
972     callOperation(WithProfile, operationGetFromScope, dst, currentInstruction);
973 }
974
975 void JIT::emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet* set)
976 {
977     emitGetVirtualRegister(value, regT0);
978     emitNotifyWrite(set);
979     storePtr(regT0, operand);
980 }
981 void JIT::emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet** indirectWatchpointSet)
982 {
983     emitGetVirtualRegister(value, regT0);
984     loadPtr(indirectWatchpointSet, regT1);
985     emitNotifyWrite(regT1);
986     loadPtr(addressOfOperand, regT1);
987     storePtr(regT0, regT1);
988 }
989
990 void JIT::emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet* set)
991 {
992     emitGetVirtualRegister(value, regT1);
993     emitGetVirtualRegister(scope, regT0);
994     emitNotifyWrite(set);
995     storePtr(regT1, Address(regT0, JSEnvironmentRecord::offsetOfVariables() + operand * sizeof(Register)));
996 }
997
998 void JIT::emit_op_put_to_scope(Instruction* currentInstruction)
999 {
1000     int scope = currentInstruction[1].u.operand;
1001     int value = currentInstruction[3].u.operand;
1002     GetPutInfo getPutInfo = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand);
1003     ResolveType resolveType = getPutInfo.resolveType();
1004     Structure** structureSlot = currentInstruction[5].u.structure.slot();
1005     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
1006
1007     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
1008         switch (resolveType) {
1009         case GlobalProperty:
1010         case GlobalPropertyWithVarInjectionChecks: {
1011             emitWriteBarrier(m_codeBlock->globalObject(), value, ShouldFilterValue);
1012             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
1013             emitGetVirtualRegister(value, regT2);
1014             
1015             loadPtr(Address(regT0, JSObject::butterflyOffset()), regT0);
1016             loadPtr(operandSlot, regT1);
1017             negPtr(regT1);
1018             storePtr(regT2, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)));
1019             break;
1020         }
1021         case GlobalVar:
1022         case GlobalVarWithVarInjectionChecks:
1023         case GlobalLexicalVar:
1024         case GlobalLexicalVarWithVarInjectionChecks: {
1025             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
1026             RELEASE_ASSERT(constantScope);
1027             emitWriteBarrier(constantScope, value, ShouldFilterValue);
1028             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1029             if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) {
1030                 // We need to do a TDZ check here because we can't always prove we need to emit TDZ checks statically.
1031                 if (indirectLoadForOperand)
1032                     emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT0);
1033                 else
1034                     emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT0);
1035                 addSlowCase(branchTest64(Zero, regT0));
1036             }
1037             if (indirectLoadForOperand)
1038                 emitPutGlobalVariableIndirect(bitwise_cast<JSValue**>(operandSlot), value, bitwise_cast<WatchpointSet**>(&currentInstruction[5]));
1039             else
1040                 emitPutGlobalVariable(bitwise_cast<JSValue*>(*operandSlot), value, currentInstruction[5].u.watchpointSet);
1041             break;
1042         }
1043         case LocalClosureVar:
1044         case ClosureVar:
1045         case ClosureVarWithVarInjectionChecks:
1046             emitWriteBarrier(scope, value, ShouldFilterValue);
1047             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1048             emitPutClosureVar(scope, *operandSlot, value, currentInstruction[5].u.watchpointSet);
1049             break;
1050         case ModuleVar:
1051         case Dynamic:
1052             addSlowCase(jump());
1053             break;
1054         case UnresolvedProperty:
1055         case UnresolvedPropertyWithVarInjectionChecks:
1056             RELEASE_ASSERT_NOT_REACHED();
1057             break;
1058         }
1059     };
1060
1061     switch (resolveType) {
1062     case UnresolvedProperty:
1063     case UnresolvedPropertyWithVarInjectionChecks: {
1064         JumpList skipToEnd;
1065         load32(&currentInstruction[4], regT0);
1066         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
1067
1068         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
1069         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
1070         isGlobalProperty.link(this);
1071         emitCode(GlobalProperty, false);
1072         skipToEnd.append(jump());
1073         notGlobalPropertyWithVarInjections.link(this);
1074
1075         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
1076         emitCode(GlobalLexicalVar, true);
1077         skipToEnd.append(jump());
1078         notGlobalLexicalVar.link(this);
1079
1080         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
1081         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
1082         skipToEnd.append(jump());
1083         notGlobalLexicalVarWithVarInjections.link(this);
1084
1085         addSlowCase(jump());
1086
1087         skipToEnd.link(this);
1088         break;
1089     }
1090
1091     default:
1092         emitCode(resolveType, false);
1093         break;
1094     }
1095 }
1096
1097 void JIT::emitSlow_op_put_to_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1098 {
1099     GetPutInfo getPutInfo = GetPutInfo(copiedInstruction(currentInstruction)[4].u.operand);
1100     ResolveType resolveType = getPutInfo.resolveType();
1101     unsigned linkCount = 0;
1102     if (resolveType != GlobalVar && resolveType != ClosureVar && resolveType != LocalClosureVar && resolveType != GlobalLexicalVar)
1103         linkCount++;
1104     if (resolveType == GlobalVar || resolveType == GlobalVarWithVarInjectionChecks 
1105         || resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks 
1106         || resolveType == ClosureVar || resolveType == ClosureVarWithVarInjectionChecks
1107         || resolveType == LocalClosureVar)
1108         linkCount++;
1109     if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks)
1110         linkCount++; // bad structure
1111     if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) // TDZ check.
1112         linkCount++;
1113     if (resolveType == UnresolvedProperty || resolveType == UnresolvedPropertyWithVarInjectionChecks) {
1114         // GlobalProperty/GlobalPropertyWithVarInjectionsCheck
1115         linkCount++; // emitLoadWithStructureCheck
1116         linkCount++; // emitLoadWithStructureCheck
1117
1118         // GlobalLexicalVar
1119         bool needsTDZCheck = !isInitialization(getPutInfo.initializationMode());
1120         if (needsTDZCheck)
1121             linkCount++;
1122         linkCount++; // Notify write check.
1123
1124         // GlobalLexicalVarWithVarInjectionsCheck
1125         linkCount++; // var injection check.
1126         if (needsTDZCheck)
1127             linkCount++;
1128         linkCount++; // Notify write check.
1129     }
1130     if (!linkCount)
1131         return;
1132     while (linkCount--)
1133         linkSlowCase(iter);
1134
1135     if (resolveType == ModuleVar) {
1136         JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_throw_strict_mode_readonly_property_write_error);
1137         slowPathCall.call();
1138     } else
1139         callOperation(operationPutToScope, currentInstruction);
1140 }
1141
1142 void JIT::emit_op_get_from_arguments(Instruction* currentInstruction)
1143 {
1144     int dst = currentInstruction[1].u.operand;
1145     int arguments = currentInstruction[2].u.operand;
1146     int index = currentInstruction[3].u.operand;
1147     
1148     emitGetVirtualRegister(arguments, regT0);
1149     load64(Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>)), regT0);
1150     emitValueProfilingSite();
1151     emitPutVirtualRegister(dst);
1152 }
1153
1154 void JIT::emit_op_put_to_arguments(Instruction* currentInstruction)
1155 {
1156     int arguments = currentInstruction[1].u.operand;
1157     int index = currentInstruction[2].u.operand;
1158     int value = currentInstruction[3].u.operand;
1159     
1160     emitWriteBarrier(arguments, value, ShouldFilterValue);
1161     
1162     emitGetVirtualRegister(arguments, regT0);
1163     emitGetVirtualRegister(value, regT1);
1164     store64(regT1, Address(regT0, DirectArguments::storageOffset() + index * sizeof(WriteBarrier<Unknown>)));
1165 }
1166
1167 #endif // USE(JSVALUE64)
1168
1169 #if USE(JSVALUE64)
1170 void JIT::emitWriteBarrier(unsigned owner, unsigned value, WriteBarrierMode mode)
1171 {
1172     Jump valueNotCell;
1173     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) {
1174         emitGetVirtualRegister(value, regT0);
1175         valueNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1176     }
1177     
1178     emitGetVirtualRegister(owner, regT0);
1179     Jump ownerNotCell;
1180     if (mode == ShouldFilterBaseAndValue || mode == ShouldFilterBase)
1181         ownerNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1182
1183     Jump ownerIsRememberedOrInEden = jumpIfIsRememberedOrInEden(regT0);
1184     callOperation(operationUnconditionalWriteBarrier, regT0);
1185     ownerIsRememberedOrInEden.link(this);
1186
1187     if (mode == ShouldFilterBaseAndValue || mode == ShouldFilterBase)
1188         ownerNotCell.link(this);
1189     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) 
1190         valueNotCell.link(this);
1191 }
1192
1193 void JIT::emitWriteBarrier(JSCell* owner, unsigned value, WriteBarrierMode mode)
1194 {
1195     emitGetVirtualRegister(value, regT0);
1196     Jump valueNotCell;
1197     if (mode == ShouldFilterValue)
1198         valueNotCell = branchTest64(NonZero, regT0, tagMaskRegister);
1199
1200     emitWriteBarrier(owner);
1201
1202     if (mode == ShouldFilterValue) 
1203         valueNotCell.link(this);
1204 }
1205
1206 #else // USE(JSVALUE64)
1207
1208 void JIT::emitWriteBarrier(unsigned owner, unsigned value, WriteBarrierMode mode)
1209 {
1210     Jump valueNotCell;
1211     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) {
1212         emitLoadTag(value, regT0);
1213         valueNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1214     }
1215     
1216     emitLoad(owner, regT0, regT1);
1217     Jump ownerNotCell;
1218     if (mode == ShouldFilterBase || mode == ShouldFilterBaseAndValue)
1219         ownerNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1220
1221     Jump ownerIsRememberedOrInEden = jumpIfIsRememberedOrInEden(regT1);
1222     callOperation(operationUnconditionalWriteBarrier, regT1);
1223     ownerIsRememberedOrInEden.link(this);
1224
1225     if (mode == ShouldFilterBase || mode == ShouldFilterBaseAndValue)
1226         ownerNotCell.link(this);
1227     if (mode == ShouldFilterValue || mode == ShouldFilterBaseAndValue) 
1228         valueNotCell.link(this);
1229 }
1230
1231 void JIT::emitWriteBarrier(JSCell* owner, unsigned value, WriteBarrierMode mode)
1232 {
1233     Jump valueNotCell;
1234     if (mode == ShouldFilterValue) {
1235         emitLoadTag(value, regT0);
1236         valueNotCell = branch32(NotEqual, regT0, TrustedImm32(JSValue::CellTag));
1237     }
1238
1239     emitWriteBarrier(owner);
1240
1241     if (mode == ShouldFilterValue) 
1242         valueNotCell.link(this);
1243 }
1244
1245 #endif // USE(JSVALUE64)
1246
1247 void JIT::emitWriteBarrier(JSCell* owner)
1248 {
1249     if (!owner->cellContainer().isMarked(owner)) {
1250         Jump ownerIsRememberedOrInEden = jumpIfIsRememberedOrInEden(owner);
1251         callOperation(operationUnconditionalWriteBarrier, owner);
1252         ownerIsRememberedOrInEden.link(this);
1253     } else
1254         callOperation(operationUnconditionalWriteBarrier, owner);
1255 }
1256
1257 void JIT::emitByValIdentifierCheck(ByValInfo* byValInfo, RegisterID cell, RegisterID scratch, const Identifier& propertyName, JumpList& slowCases)
1258 {
1259     if (propertyName.isSymbol())
1260         slowCases.append(branchPtr(NotEqual, cell, TrustedImmPtr(byValInfo->cachedSymbol.get())));
1261     else {
1262         slowCases.append(branchStructure(NotEqual, Address(cell, JSCell::structureIDOffset()), m_vm->stringStructure.get()));
1263         loadPtr(Address(cell, JSString::offsetOfValue()), scratch);
1264         slowCases.append(branchPtr(NotEqual, scratch, TrustedImmPtr(propertyName.impl())));
1265     }
1266 }
1267
1268 void JIT::privateCompileGetByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1269 {
1270     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1271     
1272     PatchableJump badType;
1273     JumpList slowCases;
1274     
1275     switch (arrayMode) {
1276     case JITInt32:
1277         slowCases = emitInt32GetByVal(currentInstruction, badType);
1278         break;
1279     case JITDouble:
1280         slowCases = emitDoubleGetByVal(currentInstruction, badType);
1281         break;
1282     case JITContiguous:
1283         slowCases = emitContiguousGetByVal(currentInstruction, badType);
1284         break;
1285     case JITArrayStorage:
1286         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
1287         break;
1288     case JITDirectArguments:
1289         slowCases = emitDirectArgumentsGetByVal(currentInstruction, badType);
1290         break;
1291     case JITScopedArguments:
1292         slowCases = emitScopedArgumentsGetByVal(currentInstruction, badType);
1293         break;
1294     default:
1295         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1296         if (isInt(type))
1297             slowCases = emitIntTypedArrayGetByVal(currentInstruction, badType, type);
1298         else 
1299             slowCases = emitFloatTypedArrayGetByVal(currentInstruction, badType, type);
1300         break;
1301     }
1302     
1303     Jump done = jump();
1304
1305     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1306     
1307     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1308     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1309     
1310     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1311     
1312     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1313         m_codeBlock, patchBuffer,
1314         ("Baseline get_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1315     
1316     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1317     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1318 }
1319
1320 void JIT::privateCompileGetByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName)
1321 {
1322     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1323
1324     Jump fastDoneCase;
1325     Jump slowDoneCase;
1326     JumpList slowCases;
1327
1328     JITGetByIdGenerator gen = emitGetByValWithCachedId(byValInfo, currentInstruction, propertyName, fastDoneCase, slowDoneCase, slowCases);
1329
1330     ConcurrentJITLocker locker(m_codeBlock->m_lock);
1331     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1332     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1333     patchBuffer.link(fastDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1334     patchBuffer.link(slowDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToNextHotPath));
1335     if (!m_exceptionChecks.empty())
1336         patchBuffer.link(m_exceptionChecks, byValInfo->exceptionHandler);
1337
1338     for (const auto& callSite : m_calls) {
1339         if (callSite.to)
1340             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1341     }
1342     gen.finalize(patchBuffer);
1343
1344     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1345         m_codeBlock, patchBuffer,
1346         ("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()));
1347     byValInfo->stubInfo = gen.stubInfo();
1348
1349     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1350     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1351 }
1352
1353 void JIT::privateCompilePutByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1354 {
1355     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1356     
1357     PatchableJump badType;
1358     JumpList slowCases;
1359
1360     bool needsLinkForWriteBarrier = false;
1361
1362     switch (arrayMode) {
1363     case JITInt32:
1364         slowCases = emitInt32PutByVal(currentInstruction, badType);
1365         break;
1366     case JITDouble:
1367         slowCases = emitDoublePutByVal(currentInstruction, badType);
1368         break;
1369     case JITContiguous:
1370         slowCases = emitContiguousPutByVal(currentInstruction, badType);
1371         needsLinkForWriteBarrier = true;
1372         break;
1373     case JITArrayStorage:
1374         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
1375         needsLinkForWriteBarrier = true;
1376         break;
1377     default:
1378         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1379         if (isInt(type))
1380             slowCases = emitIntTypedArrayPutByVal(currentInstruction, badType, type);
1381         else 
1382             slowCases = emitFloatTypedArrayPutByVal(currentInstruction, badType, type);
1383         break;
1384     }
1385     
1386     Jump done = jump();
1387
1388     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1389     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1390     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1391     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1392     if (needsLinkForWriteBarrier) {
1393         ASSERT(m_calls.last().to == operationUnconditionalWriteBarrier);
1394         patchBuffer.link(m_calls.last().from, operationUnconditionalWriteBarrier);
1395     }
1396     
1397     bool isDirect = m_interpreter->getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
1398     if (!isDirect) {
1399         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1400             m_codeBlock, patchBuffer,
1401             ("Baseline put_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1402         
1403     } else {
1404         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1405             m_codeBlock, patchBuffer,
1406             ("Baseline put_by_val_direct stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1407     }
1408     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1409     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(isDirect ? operationDirectPutByValGeneric : operationPutByValGeneric));
1410 }
1411
1412 void JIT::privateCompilePutByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, PutKind putKind, const Identifier& propertyName)
1413 {
1414     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1415
1416     JumpList doneCases;
1417     JumpList slowCases;
1418
1419     JITPutByIdGenerator gen = emitPutByValWithCachedId(byValInfo, currentInstruction, putKind, propertyName, doneCases, slowCases);
1420
1421     ConcurrentJITLocker locker(m_codeBlock->m_lock);
1422     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1423     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1424     patchBuffer.link(doneCases, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1425     if (!m_exceptionChecks.empty())
1426         patchBuffer.link(m_exceptionChecks, byValInfo->exceptionHandler);
1427
1428     for (const auto& callSite : m_calls) {
1429         if (callSite.to)
1430             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1431     }
1432     gen.finalize(patchBuffer);
1433
1434     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1435         m_codeBlock, patchBuffer,
1436         ("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()));
1437     byValInfo->stubInfo = gen.stubInfo();
1438
1439     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1440     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(putKind == Direct ? operationDirectPutByValGeneric : operationPutByValGeneric));
1441 }
1442
1443
1444 JIT::JumpList JIT::emitDirectArgumentsGetByVal(Instruction*, PatchableJump& badType)
1445 {
1446     JumpList slowCases;
1447     
1448 #if USE(JSVALUE64)
1449     RegisterID base = regT0;
1450     RegisterID property = regT1;
1451     JSValueRegs result = JSValueRegs(regT0);
1452     RegisterID scratch = regT3;
1453 #else
1454     RegisterID base = regT0;
1455     RegisterID property = regT2;
1456     JSValueRegs result = JSValueRegs(regT1, regT0);
1457     RegisterID scratch = regT3;
1458 #endif
1459
1460     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1461     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(DirectArgumentsType));
1462     
1463     slowCases.append(branch32(AboveOrEqual, property, Address(base, DirectArguments::offsetOfLength())));
1464     slowCases.append(branchTestPtr(NonZero, Address(base, DirectArguments::offsetOfOverrides())));
1465     
1466     zeroExtend32ToPtr(property, scratch);
1467     loadValue(BaseIndex(base, scratch, TimesEight, DirectArguments::storageOffset()), result);
1468     
1469     return slowCases;
1470 }
1471
1472 JIT::JumpList JIT::emitScopedArgumentsGetByVal(Instruction*, PatchableJump& badType)
1473 {
1474     JumpList slowCases;
1475     
1476 #if USE(JSVALUE64)
1477     RegisterID base = regT0;
1478     RegisterID property = regT1;
1479     JSValueRegs result = JSValueRegs(regT0);
1480     RegisterID scratch = regT3;
1481     RegisterID scratch2 = regT4;
1482 #else
1483     RegisterID base = regT0;
1484     RegisterID property = regT2;
1485     JSValueRegs result = JSValueRegs(regT1, regT0);
1486     RegisterID scratch = regT3;
1487     RegisterID scratch2 = regT4;
1488 #endif
1489
1490     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1491     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(ScopedArgumentsType));
1492     slowCases.append(branch32(AboveOrEqual, property, Address(base, ScopedArguments::offsetOfTotalLength())));
1493     
1494     loadPtr(Address(base, ScopedArguments::offsetOfTable()), scratch);
1495     load32(Address(scratch, ScopedArgumentsTable::offsetOfLength()), scratch2);
1496     Jump overflowCase = branch32(AboveOrEqual, property, scratch2);
1497     loadPtr(Address(base, ScopedArguments::offsetOfScope()), scratch2);
1498     loadPtr(Address(scratch, ScopedArgumentsTable::offsetOfArguments()), scratch);
1499     load32(BaseIndex(scratch, property, TimesFour), scratch);
1500     slowCases.append(branch32(Equal, scratch, TrustedImm32(ScopeOffset::invalidOffset)));
1501     loadValue(BaseIndex(scratch2, scratch, TimesEight, JSEnvironmentRecord::offsetOfVariables()), result);
1502     Jump done = jump();
1503     overflowCase.link(this);
1504     sub32(property, scratch2);
1505     neg32(scratch2);
1506     loadValue(BaseIndex(base, scratch2, TimesEight, ScopedArguments::overflowStorageOffset()), result);
1507     slowCases.append(branchIfEmpty(result));
1508     done.link(this);
1509     
1510     return slowCases;
1511 }
1512
1513 JIT::JumpList JIT::emitIntTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1514 {
1515     ASSERT(isInt(type));
1516     
1517     // The best way to test the array type is to use the classInfo. We need to do so without
1518     // clobbering the register that holds the indexing type, base, and property.
1519
1520 #if USE(JSVALUE64)
1521     RegisterID base = regT0;
1522     RegisterID property = regT1;
1523     RegisterID resultPayload = regT0;
1524     RegisterID scratch = regT3;
1525 #else
1526     RegisterID base = regT0;
1527     RegisterID property = regT2;
1528     RegisterID resultPayload = regT0;
1529     RegisterID resultTag = regT1;
1530     RegisterID scratch = regT3;
1531 #endif
1532     
1533     JumpList slowCases;
1534     
1535     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1536     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1537     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1538     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1539     
1540     switch (elementSize(type)) {
1541     case 1:
1542         if (JSC::isSigned(type))
1543             load8SignedExtendTo32(BaseIndex(scratch, property, TimesOne), resultPayload);
1544         else
1545             load8(BaseIndex(scratch, property, TimesOne), resultPayload);
1546         break;
1547     case 2:
1548         if (JSC::isSigned(type))
1549             load16SignedExtendTo32(BaseIndex(scratch, property, TimesTwo), resultPayload);
1550         else
1551             load16(BaseIndex(scratch, property, TimesTwo), resultPayload);
1552         break;
1553     case 4:
1554         load32(BaseIndex(scratch, property, TimesFour), resultPayload);
1555         break;
1556     default:
1557         CRASH();
1558     }
1559     
1560     Jump done;
1561     if (type == TypeUint32) {
1562         Jump canBeInt = branch32(GreaterThanOrEqual, resultPayload, TrustedImm32(0));
1563         
1564         convertInt32ToDouble(resultPayload, fpRegT0);
1565         addDouble(AbsoluteAddress(&twoToThe32), fpRegT0);
1566 #if USE(JSVALUE64)
1567         moveDoubleTo64(fpRegT0, resultPayload);
1568         sub64(tagTypeNumberRegister, resultPayload);
1569 #else
1570         moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1571 #endif
1572         
1573         done = jump();
1574         canBeInt.link(this);
1575     }
1576
1577 #if USE(JSVALUE64)
1578     or64(tagTypeNumberRegister, resultPayload);
1579 #else
1580     move(TrustedImm32(JSValue::Int32Tag), resultTag);
1581 #endif
1582     if (done.isSet())
1583         done.link(this);
1584     return slowCases;
1585 }
1586
1587 JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1588 {
1589     ASSERT(isFloat(type));
1590     
1591 #if USE(JSVALUE64)
1592     RegisterID base = regT0;
1593     RegisterID property = regT1;
1594     RegisterID resultPayload = regT0;
1595     RegisterID scratch = regT3;
1596 #else
1597     RegisterID base = regT0;
1598     RegisterID property = regT2;
1599     RegisterID resultPayload = regT0;
1600     RegisterID resultTag = regT1;
1601     RegisterID scratch = regT3;
1602 #endif
1603     
1604     JumpList slowCases;
1605
1606     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1607     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1608     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1609     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1610     
1611     switch (elementSize(type)) {
1612     case 4:
1613         loadFloat(BaseIndex(scratch, property, TimesFour), fpRegT0);
1614         convertFloatToDouble(fpRegT0, fpRegT0);
1615         break;
1616     case 8: {
1617         loadDouble(BaseIndex(scratch, property, TimesEight), fpRegT0);
1618         break;
1619     }
1620     default:
1621         CRASH();
1622     }
1623     
1624     Jump notNaN = branchDouble(DoubleEqual, fpRegT0, fpRegT0);
1625     static const double NaN = PNaN;
1626     loadDouble(TrustedImmPtr(&NaN), fpRegT0);
1627     notNaN.link(this);
1628     
1629 #if USE(JSVALUE64)
1630     moveDoubleTo64(fpRegT0, resultPayload);
1631     sub64(tagTypeNumberRegister, resultPayload);
1632 #else
1633     moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1634 #endif
1635     return slowCases;    
1636 }
1637
1638 JIT::JumpList JIT::emitIntTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1639 {
1640     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1641     ASSERT(isInt(type));
1642     
1643     int value = currentInstruction[3].u.operand;
1644
1645 #if USE(JSVALUE64)
1646     RegisterID base = regT0;
1647     RegisterID property = regT1;
1648     RegisterID earlyScratch = regT3;
1649     RegisterID lateScratch = regT2;
1650 #else
1651     RegisterID base = regT0;
1652     RegisterID property = regT2;
1653     RegisterID earlyScratch = regT3;
1654     RegisterID lateScratch = regT1;
1655 #endif
1656     
1657     JumpList slowCases;
1658     
1659     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1660     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1661     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1662     emitArrayProfileOutOfBoundsSpecialCase(profile);
1663     slowCases.append(jump());
1664     inBounds.link(this);
1665     
1666 #if USE(JSVALUE64)
1667     emitGetVirtualRegister(value, earlyScratch);
1668     slowCases.append(emitJumpIfNotInt(earlyScratch));
1669 #else
1670     emitLoad(value, lateScratch, earlyScratch);
1671     slowCases.append(branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag)));
1672 #endif
1673     
1674     // We would be loading this into base as in get_by_val, except that the slow
1675     // path expects the base to be unclobbered.
1676     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1677     
1678     if (isClamped(type)) {
1679         ASSERT(elementSize(type) == 1);
1680         ASSERT(!JSC::isSigned(type));
1681         Jump inBounds = branch32(BelowOrEqual, earlyScratch, TrustedImm32(0xff));
1682         Jump tooBig = branch32(GreaterThan, earlyScratch, TrustedImm32(0xff));
1683         xor32(earlyScratch, earlyScratch);
1684         Jump clamped = jump();
1685         tooBig.link(this);
1686         move(TrustedImm32(0xff), earlyScratch);
1687         clamped.link(this);
1688         inBounds.link(this);
1689     }
1690     
1691     switch (elementSize(type)) {
1692     case 1:
1693         store8(earlyScratch, BaseIndex(lateScratch, property, TimesOne));
1694         break;
1695     case 2:
1696         store16(earlyScratch, BaseIndex(lateScratch, property, TimesTwo));
1697         break;
1698     case 4:
1699         store32(earlyScratch, BaseIndex(lateScratch, property, TimesFour));
1700         break;
1701     default:
1702         CRASH();
1703     }
1704     
1705     return slowCases;
1706 }
1707
1708 JIT::JumpList JIT::emitFloatTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1709 {
1710     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1711     ASSERT(isFloat(type));
1712     
1713     int value = currentInstruction[3].u.operand;
1714
1715 #if USE(JSVALUE64)
1716     RegisterID base = regT0;
1717     RegisterID property = regT1;
1718     RegisterID earlyScratch = regT3;
1719     RegisterID lateScratch = regT2;
1720 #else
1721     RegisterID base = regT0;
1722     RegisterID property = regT2;
1723     RegisterID earlyScratch = regT3;
1724     RegisterID lateScratch = regT1;
1725 #endif
1726     
1727     JumpList slowCases;
1728     
1729     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1730     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1731     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1732     emitArrayProfileOutOfBoundsSpecialCase(profile);
1733     slowCases.append(jump());
1734     inBounds.link(this);
1735     
1736 #if USE(JSVALUE64)
1737     emitGetVirtualRegister(value, earlyScratch);
1738     Jump doubleCase = emitJumpIfNotInt(earlyScratch);
1739     convertInt32ToDouble(earlyScratch, fpRegT0);
1740     Jump ready = jump();
1741     doubleCase.link(this);
1742     slowCases.append(emitJumpIfNotNumber(earlyScratch));
1743     add64(tagTypeNumberRegister, earlyScratch);
1744     move64ToDouble(earlyScratch, fpRegT0);
1745     ready.link(this);
1746 #else
1747     emitLoad(value, lateScratch, earlyScratch);
1748     Jump doubleCase = branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag));
1749     convertInt32ToDouble(earlyScratch, fpRegT0);
1750     Jump ready = jump();
1751     doubleCase.link(this);
1752     slowCases.append(branch32(Above, lateScratch, TrustedImm32(JSValue::LowestTag)));
1753     moveIntsToDouble(earlyScratch, lateScratch, fpRegT0, fpRegT1);
1754     ready.link(this);
1755 #endif
1756     
1757     // We would be loading this into base as in get_by_val, except that the slow
1758     // path expects the base to be unclobbered.
1759     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1760     
1761     switch (elementSize(type)) {
1762     case 4:
1763         convertDoubleToFloat(fpRegT0, fpRegT0);
1764         storeFloat(fpRegT0, BaseIndex(lateScratch, property, TimesFour));
1765         break;
1766     case 8:
1767         storeDouble(fpRegT0, BaseIndex(lateScratch, property, TimesEight));
1768         break;
1769     default:
1770         CRASH();
1771     }
1772     
1773     return slowCases;
1774 }
1775
1776 } // namespace JSC
1777
1778 #endif // ENABLE(JIT)