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