9d1344e15cce6541ddc3e52aa957f68a21806e13
[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(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     emitIdentifierCheck(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(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     emitIdentifierCheck(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::emitIdentifierCheck(RegisterID cell, RegisterID scratch, const Identifier& propertyName, JumpList& slowCases)
1257 {
1258     if (propertyName.isSymbol()) {
1259         slowCases.append(branchStructure(NotEqual, Address(cell, JSCell::structureIDOffset()), m_vm->symbolStructure.get()));
1260         loadPtr(Address(cell, Symbol::offsetOfPrivateName()), scratch);
1261     } else {
1262         slowCases.append(branchStructure(NotEqual, Address(cell, JSCell::structureIDOffset()), m_vm->stringStructure.get()));
1263         loadPtr(Address(cell, JSString::offsetOfValue()), scratch);
1264     }
1265     slowCases.append(branchPtr(NotEqual, scratch, TrustedImmPtr(propertyName.impl())));
1266 }
1267
1268 void JIT::privateCompileGetByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1269 {
1270     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1271     
1272     PatchableJump badType;
1273     JumpList slowCases;
1274     
1275     switch (arrayMode) {
1276     case JITInt32:
1277         slowCases = emitInt32GetByVal(currentInstruction, badType);
1278         break;
1279     case JITDouble:
1280         slowCases = emitDoubleGetByVal(currentInstruction, badType);
1281         break;
1282     case JITContiguous:
1283         slowCases = emitContiguousGetByVal(currentInstruction, badType);
1284         break;
1285     case JITArrayStorage:
1286         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
1287         break;
1288     case JITDirectArguments:
1289         slowCases = emitDirectArgumentsGetByVal(currentInstruction, badType);
1290         break;
1291     case JITScopedArguments:
1292         slowCases = emitScopedArgumentsGetByVal(currentInstruction, badType);
1293         break;
1294     default:
1295         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1296         if (isInt(type))
1297             slowCases = emitIntTypedArrayGetByVal(currentInstruction, badType, type);
1298         else 
1299             slowCases = emitFloatTypedArrayGetByVal(currentInstruction, badType, type);
1300         break;
1301     }
1302     
1303     Jump done = jump();
1304
1305     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1306     
1307     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1308     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1309     
1310     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1311     
1312     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1313         m_codeBlock, patchBuffer,
1314         ("Baseline get_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1315     
1316     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1317     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1318 }
1319
1320 void JIT::privateCompileGetByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName)
1321 {
1322     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1323
1324     Jump fastDoneCase;
1325     Jump slowDoneCase;
1326     JumpList slowCases;
1327
1328     JITGetByIdGenerator gen = emitGetByValWithCachedId(currentInstruction, propertyName, fastDoneCase, slowDoneCase, slowCases);
1329
1330     ConcurrentJITLocker locker(m_codeBlock->m_lock);
1331     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1332     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1333     patchBuffer.link(fastDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1334     patchBuffer.link(slowDoneCase, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToNextHotPath));
1335
1336     for (const auto& callSite : m_calls) {
1337         if (callSite.to)
1338             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1339     }
1340     gen.finalize(patchBuffer);
1341
1342     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1343         m_codeBlock, patchBuffer,
1344         ("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()));
1345     byValInfo->stubInfo = gen.stubInfo();
1346
1347     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1348     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(operationGetByValGeneric));
1349 }
1350
1351 void JIT::privateCompilePutByVal(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
1352 {
1353     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1354     
1355     PatchableJump badType;
1356     JumpList slowCases;
1357
1358     bool needsLinkForWriteBarrier = false;
1359
1360     switch (arrayMode) {
1361     case JITInt32:
1362         slowCases = emitInt32PutByVal(currentInstruction, badType);
1363         break;
1364     case JITDouble:
1365         slowCases = emitDoublePutByVal(currentInstruction, badType);
1366         break;
1367     case JITContiguous:
1368         slowCases = emitContiguousPutByVal(currentInstruction, badType);
1369         needsLinkForWriteBarrier = true;
1370         break;
1371     case JITArrayStorage:
1372         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
1373         needsLinkForWriteBarrier = true;
1374         break;
1375     default:
1376         TypedArrayType type = typedArrayTypeForJITArrayMode(arrayMode);
1377         if (isInt(type))
1378             slowCases = emitIntTypedArrayPutByVal(currentInstruction, badType, type);
1379         else 
1380             slowCases = emitFloatTypedArrayPutByVal(currentInstruction, badType, type);
1381         break;
1382     }
1383     
1384     Jump done = jump();
1385
1386     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1387     patchBuffer.link(badType, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1388     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1389     patchBuffer.link(done, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1390     if (needsLinkForWriteBarrier) {
1391         ASSERT(m_calls.last().to == operationUnconditionalWriteBarrier);
1392         patchBuffer.link(m_calls.last().from, operationUnconditionalWriteBarrier);
1393     }
1394     
1395     bool isDirect = m_interpreter->getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
1396     if (!isDirect) {
1397         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1398             m_codeBlock, patchBuffer,
1399             ("Baseline put_by_val stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1400         
1401     } else {
1402         byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1403             m_codeBlock, patchBuffer,
1404             ("Baseline put_by_val_direct stub for %s, return point %p", toCString(*m_codeBlock).data(), returnAddress.value()));
1405     }
1406     MacroAssembler::repatchJump(byValInfo->badTypeJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1407     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(isDirect ? operationDirectPutByValGeneric : operationPutByValGeneric));
1408 }
1409
1410 void JIT::privateCompilePutByValWithCachedId(ByValInfo* byValInfo, ReturnAddressPtr returnAddress, PutKind putKind, const Identifier& propertyName)
1411 {
1412     Instruction* currentInstruction = m_codeBlock->instructions().begin() + byValInfo->bytecodeIndex;
1413
1414     JumpList doneCases;
1415     JumpList slowCases;
1416
1417     JITPutByIdGenerator gen = emitPutByValWithCachedId(currentInstruction, putKind, propertyName, doneCases, slowCases);
1418
1419     ConcurrentJITLocker locker(m_codeBlock->m_lock);
1420     LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock);
1421     patchBuffer.link(slowCases, CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(returnAddress.value())).labelAtOffset(byValInfo->returnAddressToSlowPath));
1422     patchBuffer.link(doneCases, byValInfo->badTypeJump.labelAtOffset(byValInfo->badTypeJumpToDone));
1423     for (const auto& callSite : m_calls) {
1424         if (callSite.to)
1425             patchBuffer.link(callSite.from, FunctionPtr(callSite.to));
1426     }
1427     gen.finalize(patchBuffer);
1428
1429     byValInfo->stubRoutine = FINALIZE_CODE_FOR_STUB(
1430         m_codeBlock, patchBuffer,
1431         ("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()));
1432     byValInfo->stubInfo = gen.stubInfo();
1433
1434     MacroAssembler::repatchJump(byValInfo->notIndexJump, CodeLocationLabel(byValInfo->stubRoutine->code().code()));
1435     MacroAssembler::repatchCall(CodeLocationCall(MacroAssemblerCodePtr(returnAddress)), FunctionPtr(putKind == Direct ? operationDirectPutByValGeneric : operationPutByValGeneric));
1436 }
1437
1438
1439 JIT::JumpList JIT::emitDirectArgumentsGetByVal(Instruction*, PatchableJump& badType)
1440 {
1441     JumpList slowCases;
1442     
1443 #if USE(JSVALUE64)
1444     RegisterID base = regT0;
1445     RegisterID property = regT1;
1446     JSValueRegs result = JSValueRegs(regT0);
1447     RegisterID scratch = regT3;
1448 #else
1449     RegisterID base = regT0;
1450     RegisterID property = regT2;
1451     JSValueRegs result = JSValueRegs(regT1, regT0);
1452     RegisterID scratch = regT3;
1453 #endif
1454
1455     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1456     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(DirectArgumentsType));
1457     
1458     slowCases.append(branch32(AboveOrEqual, property, Address(base, DirectArguments::offsetOfLength())));
1459     slowCases.append(branchTestPtr(NonZero, Address(base, DirectArguments::offsetOfOverrides())));
1460     
1461     zeroExtend32ToPtr(property, scratch);
1462     loadValue(BaseIndex(base, scratch, TimesEight, DirectArguments::storageOffset()), result);
1463     
1464     return slowCases;
1465 }
1466
1467 JIT::JumpList JIT::emitScopedArgumentsGetByVal(Instruction*, PatchableJump& badType)
1468 {
1469     JumpList slowCases;
1470     
1471 #if USE(JSVALUE64)
1472     RegisterID base = regT0;
1473     RegisterID property = regT1;
1474     JSValueRegs result = JSValueRegs(regT0);
1475     RegisterID scratch = regT3;
1476     RegisterID scratch2 = regT4;
1477 #else
1478     RegisterID base = regT0;
1479     RegisterID property = regT2;
1480     JSValueRegs result = JSValueRegs(regT1, regT0);
1481     RegisterID scratch = regT3;
1482     RegisterID scratch2 = regT4;
1483 #endif
1484
1485     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1486     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(ScopedArgumentsType));
1487     slowCases.append(branch32(AboveOrEqual, property, Address(base, ScopedArguments::offsetOfTotalLength())));
1488     
1489     loadPtr(Address(base, ScopedArguments::offsetOfTable()), scratch);
1490     load32(Address(scratch, ScopedArgumentsTable::offsetOfLength()), scratch2);
1491     Jump overflowCase = branch32(AboveOrEqual, property, scratch2);
1492     loadPtr(Address(base, ScopedArguments::offsetOfScope()), scratch2);
1493     loadPtr(Address(scratch, ScopedArgumentsTable::offsetOfArguments()), scratch);
1494     load32(BaseIndex(scratch, property, TimesFour), scratch);
1495     slowCases.append(branch32(Equal, scratch, TrustedImm32(ScopeOffset::invalidOffset)));
1496     loadValue(BaseIndex(scratch2, scratch, TimesEight, JSEnvironmentRecord::offsetOfVariables()), result);
1497     Jump done = jump();
1498     overflowCase.link(this);
1499     sub32(property, scratch2);
1500     neg32(scratch2);
1501     loadValue(BaseIndex(base, scratch2, TimesEight, ScopedArguments::overflowStorageOffset()), result);
1502     slowCases.append(branchIfEmpty(result));
1503     done.link(this);
1504     
1505     return slowCases;
1506 }
1507
1508 JIT::JumpList JIT::emitIntTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1509 {
1510     ASSERT(isInt(type));
1511     
1512     // The best way to test the array type is to use the classInfo. We need to do so without
1513     // clobbering the register that holds the indexing type, base, and property.
1514
1515 #if USE(JSVALUE64)
1516     RegisterID base = regT0;
1517     RegisterID property = regT1;
1518     RegisterID resultPayload = regT0;
1519     RegisterID scratch = regT3;
1520 #else
1521     RegisterID base = regT0;
1522     RegisterID property = regT2;
1523     RegisterID resultPayload = regT0;
1524     RegisterID resultTag = regT1;
1525     RegisterID scratch = regT3;
1526 #endif
1527     
1528     JumpList slowCases;
1529     
1530     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1531     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1532     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1533     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1534     
1535     switch (elementSize(type)) {
1536     case 1:
1537         if (JSC::isSigned(type))
1538             load8SignedExtendTo32(BaseIndex(scratch, property, TimesOne), resultPayload);
1539         else
1540             load8(BaseIndex(scratch, property, TimesOne), resultPayload);
1541         break;
1542     case 2:
1543         if (JSC::isSigned(type))
1544             load16SignedExtendTo32(BaseIndex(scratch, property, TimesTwo), resultPayload);
1545         else
1546             load16(BaseIndex(scratch, property, TimesTwo), resultPayload);
1547         break;
1548     case 4:
1549         load32(BaseIndex(scratch, property, TimesFour), resultPayload);
1550         break;
1551     default:
1552         CRASH();
1553     }
1554     
1555     Jump done;
1556     if (type == TypeUint32) {
1557         Jump canBeInt = branch32(GreaterThanOrEqual, resultPayload, TrustedImm32(0));
1558         
1559         convertInt32ToDouble(resultPayload, fpRegT0);
1560         addDouble(AbsoluteAddress(&twoToThe32), fpRegT0);
1561 #if USE(JSVALUE64)
1562         moveDoubleTo64(fpRegT0, resultPayload);
1563         sub64(tagTypeNumberRegister, resultPayload);
1564 #else
1565         moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1566 #endif
1567         
1568         done = jump();
1569         canBeInt.link(this);
1570     }
1571
1572 #if USE(JSVALUE64)
1573     or64(tagTypeNumberRegister, resultPayload);
1574 #else
1575     move(TrustedImm32(JSValue::Int32Tag), resultTag);
1576 #endif
1577     if (done.isSet())
1578         done.link(this);
1579     return slowCases;
1580 }
1581
1582 JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType type)
1583 {
1584     ASSERT(isFloat(type));
1585     
1586 #if USE(JSVALUE64)
1587     RegisterID base = regT0;
1588     RegisterID property = regT1;
1589     RegisterID resultPayload = regT0;
1590     RegisterID scratch = regT3;
1591 #else
1592     RegisterID base = regT0;
1593     RegisterID property = regT2;
1594     RegisterID resultPayload = regT0;
1595     RegisterID resultTag = regT1;
1596     RegisterID scratch = regT3;
1597 #endif
1598     
1599     JumpList slowCases;
1600
1601     load8(Address(base, JSCell::typeInfoTypeOffset()), scratch);
1602     badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type)));
1603     slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength())));
1604     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch);
1605     
1606     switch (elementSize(type)) {
1607     case 4:
1608         loadFloat(BaseIndex(scratch, property, TimesFour), fpRegT0);
1609         convertFloatToDouble(fpRegT0, fpRegT0);
1610         break;
1611     case 8: {
1612         loadDouble(BaseIndex(scratch, property, TimesEight), fpRegT0);
1613         break;
1614     }
1615     default:
1616         CRASH();
1617     }
1618     
1619     Jump notNaN = branchDouble(DoubleEqual, fpRegT0, fpRegT0);
1620     static const double NaN = PNaN;
1621     loadDouble(TrustedImmPtr(&NaN), fpRegT0);
1622     notNaN.link(this);
1623     
1624 #if USE(JSVALUE64)
1625     moveDoubleTo64(fpRegT0, resultPayload);
1626     sub64(tagTypeNumberRegister, resultPayload);
1627 #else
1628     moveDoubleToInts(fpRegT0, resultPayload, resultTag);
1629 #endif
1630     return slowCases;    
1631 }
1632
1633 JIT::JumpList JIT::emitIntTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1634 {
1635     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1636     ASSERT(isInt(type));
1637     
1638     int value = currentInstruction[3].u.operand;
1639
1640 #if USE(JSVALUE64)
1641     RegisterID base = regT0;
1642     RegisterID property = regT1;
1643     RegisterID earlyScratch = regT3;
1644     RegisterID lateScratch = regT2;
1645 #else
1646     RegisterID base = regT0;
1647     RegisterID property = regT2;
1648     RegisterID earlyScratch = regT3;
1649     RegisterID lateScratch = regT1;
1650 #endif
1651     
1652     JumpList slowCases;
1653     
1654     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1655     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1656     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1657     emitArrayProfileOutOfBoundsSpecialCase(profile);
1658     slowCases.append(jump());
1659     inBounds.link(this);
1660     
1661 #if USE(JSVALUE64)
1662     emitGetVirtualRegister(value, earlyScratch);
1663     slowCases.append(emitJumpIfNotInt(earlyScratch));
1664 #else
1665     emitLoad(value, lateScratch, earlyScratch);
1666     slowCases.append(branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag)));
1667 #endif
1668     
1669     // We would be loading this into base as in get_by_val, except that the slow
1670     // path expects the base to be unclobbered.
1671     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1672     
1673     if (isClamped(type)) {
1674         ASSERT(elementSize(type) == 1);
1675         ASSERT(!JSC::isSigned(type));
1676         Jump inBounds = branch32(BelowOrEqual, earlyScratch, TrustedImm32(0xff));
1677         Jump tooBig = branch32(GreaterThan, earlyScratch, TrustedImm32(0xff));
1678         xor32(earlyScratch, earlyScratch);
1679         Jump clamped = jump();
1680         tooBig.link(this);
1681         move(TrustedImm32(0xff), earlyScratch);
1682         clamped.link(this);
1683         inBounds.link(this);
1684     }
1685     
1686     switch (elementSize(type)) {
1687     case 1:
1688         store8(earlyScratch, BaseIndex(lateScratch, property, TimesOne));
1689         break;
1690     case 2:
1691         store16(earlyScratch, BaseIndex(lateScratch, property, TimesTwo));
1692         break;
1693     case 4:
1694         store32(earlyScratch, BaseIndex(lateScratch, property, TimesFour));
1695         break;
1696     default:
1697         CRASH();
1698     }
1699     
1700     return slowCases;
1701 }
1702
1703 JIT::JumpList JIT::emitFloatTypedArrayPutByVal(Instruction* currentInstruction, PatchableJump& badType, TypedArrayType type)
1704 {
1705     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
1706     ASSERT(isFloat(type));
1707     
1708     int value = currentInstruction[3].u.operand;
1709
1710 #if USE(JSVALUE64)
1711     RegisterID base = regT0;
1712     RegisterID property = regT1;
1713     RegisterID earlyScratch = regT3;
1714     RegisterID lateScratch = regT2;
1715 #else
1716     RegisterID base = regT0;
1717     RegisterID property = regT2;
1718     RegisterID earlyScratch = regT3;
1719     RegisterID lateScratch = regT1;
1720 #endif
1721     
1722     JumpList slowCases;
1723     
1724     load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch);
1725     badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type)));
1726     Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength()));
1727     emitArrayProfileOutOfBoundsSpecialCase(profile);
1728     slowCases.append(jump());
1729     inBounds.link(this);
1730     
1731 #if USE(JSVALUE64)
1732     emitGetVirtualRegister(value, earlyScratch);
1733     Jump doubleCase = emitJumpIfNotInt(earlyScratch);
1734     convertInt32ToDouble(earlyScratch, fpRegT0);
1735     Jump ready = jump();
1736     doubleCase.link(this);
1737     slowCases.append(emitJumpIfNotNumber(earlyScratch));
1738     add64(tagTypeNumberRegister, earlyScratch);
1739     move64ToDouble(earlyScratch, fpRegT0);
1740     ready.link(this);
1741 #else
1742     emitLoad(value, lateScratch, earlyScratch);
1743     Jump doubleCase = branch32(NotEqual, lateScratch, TrustedImm32(JSValue::Int32Tag));
1744     convertInt32ToDouble(earlyScratch, fpRegT0);
1745     Jump ready = jump();
1746     doubleCase.link(this);
1747     slowCases.append(branch32(Above, lateScratch, TrustedImm32(JSValue::LowestTag)));
1748     moveIntsToDouble(earlyScratch, lateScratch, fpRegT0, fpRegT1);
1749     ready.link(this);
1750 #endif
1751     
1752     // We would be loading this into base as in get_by_val, except that the slow
1753     // path expects the base to be unclobbered.
1754     loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), lateScratch);
1755     
1756     switch (elementSize(type)) {
1757     case 4:
1758         convertDoubleToFloat(fpRegT0, fpRegT0);
1759         storeFloat(fpRegT0, BaseIndex(lateScratch, property, TimesFour));
1760         break;
1761     case 8:
1762         storeDouble(fpRegT0, BaseIndex(lateScratch, property, TimesEight));
1763         break;
1764     default:
1765         CRASH();
1766     }
1767     
1768     return slowCases;
1769 }
1770
1771 } // namespace JSC
1772
1773 #endif // ENABLE(JIT)