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