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