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