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