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