c8810ee6478b8080b3db40d955112dac1cae815e
[WebKit-https.git] / Source / JavaScriptCore / jit / JITPropertyAccess32_64.cpp
1 /*
2  * Copyright (C) 2008-2018 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 #if USE(JSVALUE32_64)
30 #include "JIT.h"
31
32 #include "CodeBlock.h"
33 #include "DirectArguments.h"
34 #include "GCAwareJITStubRoutine.h"
35 #include "InterpreterInlines.h"
36 #include "JITInlines.h"
37 #include "JSArray.h"
38 #include "JSFunction.h"
39 #include "JSLexicalEnvironment.h"
40 #include "LinkBuffer.h"
41 #include "ResultType.h"
42 #include "SlowPathCall.h"
43 #include "StructureStubInfo.h"
44 #include <wtf/StringPrintStream.h>
45
46
47 namespace JSC {
48     
49 void JIT::emit_op_put_by_index(Instruction* currentInstruction)
50 {
51     int base = currentInstruction[1].u.operand;
52     int property = currentInstruction[2].u.operand;
53     int value = currentInstruction[3].u.operand;
54
55     emitLoad(base, regT1, regT0);
56     emitLoad(value, regT3, regT2);
57     callOperation(operationPutByIndex, JSValueRegs(regT1, regT0), property, JSValueRegs(regT3, regT2));
58 }
59
60 void JIT::emit_op_put_getter_by_id(Instruction* currentInstruction)
61 {
62     int base = currentInstruction[1].u.operand;
63     int property = currentInstruction[2].u.operand;
64     int options = currentInstruction[3].u.operand;
65     int getter = currentInstruction[4].u.operand;
66
67     emitLoadPayload(base, regT1);
68     emitLoadPayload(getter, regT3);
69     callOperation(operationPutGetterById, regT1, m_codeBlock->identifier(property).impl(), options, regT3);
70 }
71
72 void JIT::emit_op_put_setter_by_id(Instruction* currentInstruction)
73 {
74     int base = currentInstruction[1].u.operand;
75     int property = currentInstruction[2].u.operand;
76     int options = currentInstruction[3].u.operand;
77     int setter = currentInstruction[4].u.operand;
78
79     emitLoadPayload(base, regT1);
80     emitLoadPayload(setter, regT3);
81     callOperation(operationPutSetterById, regT1, m_codeBlock->identifier(property).impl(), options, regT3);
82 }
83
84 void JIT::emit_op_put_getter_setter_by_id(Instruction* currentInstruction)
85 {
86     int base = currentInstruction[1].u.operand;
87     int property = currentInstruction[2].u.operand;
88     int attribute = currentInstruction[3].u.operand;
89     int getter = currentInstruction[4].u.operand;
90     int setter = currentInstruction[5].u.operand;
91
92     emitLoadPayload(base, regT1);
93     emitLoadPayload(getter, regT3);
94     emitLoadPayload(setter, regT4);
95     callOperation(operationPutGetterSetter, regT1, m_codeBlock->identifier(property).impl(), attribute, regT3, regT4);
96 }
97
98 void JIT::emit_op_put_getter_by_val(Instruction* currentInstruction)
99 {
100     int base = currentInstruction[1].u.operand;
101     int property = currentInstruction[2].u.operand;
102     int32_t attributes = currentInstruction[3].u.operand;
103     int getter = currentInstruction[4].u.operand;
104
105     emitLoadPayload(base, regT2);
106     emitLoad(property, regT1, regT0);
107     emitLoadPayload(getter, regT3);
108     callOperation(operationPutGetterByVal, regT2, JSValueRegs(regT1, regT0), attributes, regT3);
109 }
110
111 void JIT::emit_op_put_setter_by_val(Instruction* currentInstruction)
112 {
113     int base = currentInstruction[1].u.operand;
114     int property = currentInstruction[2].u.operand;
115     int32_t attributes = currentInstruction[3].u.operand;
116     int getter = currentInstruction[4].u.operand;
117
118     emitLoadPayload(base, regT2);
119     emitLoad(property, regT1, regT0);
120     emitLoadPayload(getter, regT3);
121     callOperation(operationPutSetterByVal, regT2, JSValueRegs(regT1, regT0), attributes, regT3);
122 }
123
124 void JIT::emit_op_del_by_id(Instruction* currentInstruction)
125 {
126     int dst = currentInstruction[1].u.operand;
127     int base = currentInstruction[2].u.operand;
128     int property = currentInstruction[3].u.operand;
129     emitLoad(base, regT1, regT0);
130     callOperation(operationDeleteByIdJSResult, dst, JSValueRegs(regT1, regT0), m_codeBlock->identifier(property).impl());
131 }
132
133 void JIT::emit_op_del_by_val(Instruction* currentInstruction)
134 {
135     int dst = currentInstruction[1].u.operand;
136     int base = currentInstruction[2].u.operand;
137     int property = currentInstruction[3].u.operand;
138     emitLoad2(base, regT1, regT0, property, regT3, regT2);
139     callOperation(operationDeleteByValJSResult, dst, JSValueRegs(regT1, regT0), JSValueRegs(regT3, regT2));
140 }
141
142 JIT::CodeRef JIT::stringGetByValStubGenerator(VM* vm)
143 {
144     JSInterfaceJIT jit(vm);
145     JumpList failures;
146     failures.append(jit.branchStructure(NotEqual, Address(regT0, JSCell::structureIDOffset()), vm->stringStructure.get()));
147     
148     // Load string length to regT1, and start the process of loading the data pointer into regT0
149     jit.load32(Address(regT0, ThunkHelpers::jsStringLengthOffset()), regT1);
150     jit.loadPtr(Address(regT0, ThunkHelpers::jsStringValueOffset()), regT0);
151     failures.append(jit.branchTest32(Zero, regT0));
152     
153     // Do an unsigned compare to simultaneously filter negative indices as well as indices that are too large
154     failures.append(jit.branch32(AboveOrEqual, regT2, regT1));
155     
156     // Load the character
157     JumpList is16Bit;
158     JumpList cont8Bit;
159     // Load the string flags
160     jit.loadPtr(Address(regT0, StringImpl::flagsOffset()), regT1);
161     jit.loadPtr(Address(regT0, StringImpl::dataOffset()), regT0);
162     is16Bit.append(jit.branchTest32(Zero, regT1, TrustedImm32(StringImpl::flagIs8Bit())));
163     jit.load8(BaseIndex(regT0, regT2, TimesOne, 0), regT0);
164     cont8Bit.append(jit.jump());
165     is16Bit.link(&jit);
166     jit.load16(BaseIndex(regT0, regT2, TimesTwo, 0), regT0);
167
168     cont8Bit.link(&jit);
169     
170     failures.append(jit.branch32(AboveOrEqual, regT0, TrustedImm32(0x100)));
171     jit.move(TrustedImmPtr(vm->smallStrings.singleCharacterStrings()), regT1);
172     jit.loadPtr(BaseIndex(regT1, regT0, ScalePtr, 0), regT0);
173     jit.move(TrustedImm32(JSValue::CellTag), regT1); // We null check regT0 on return so this is safe
174     jit.ret();
175
176     failures.link(&jit);
177     jit.move(TrustedImm32(0), regT0);
178     jit.ret();
179     
180     LinkBuffer patchBuffer(jit, GLOBAL_THUNK_ID);
181     return FINALIZE_CODE(patchBuffer, "String get_by_val stub");
182 }
183
184 void JIT::emit_op_get_by_val(Instruction* currentInstruction)
185 {
186     int dst = currentInstruction[1].u.operand;
187     int base = currentInstruction[2].u.operand;
188     int property = currentInstruction[3].u.operand;
189     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
190     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
191     
192     emitLoad2(base, regT1, regT0, property, regT3, regT2);
193     
194     emitJumpSlowCaseIfNotJSCell(base, regT1);
195     PatchableJump notIndex = patchableBranch32(NotEqual, regT3, TrustedImm32(JSValue::Int32Tag));
196     addSlowCase(notIndex);
197     emitArrayProfilingSiteWithCell(regT0, regT1, profile);
198     and32(TrustedImm32(IndexingShapeMask), regT1);
199
200     PatchableJump badType;
201     JumpList slowCases;
202     
203     JITArrayMode mode = chooseArrayMode(profile);
204     switch (mode) {
205     case JITInt32:
206         slowCases = emitInt32GetByVal(currentInstruction, badType);
207         break;
208     case JITDouble:
209         slowCases = emitDoubleGetByVal(currentInstruction, badType);
210         break;
211     case JITContiguous:
212         slowCases = emitContiguousGetByVal(currentInstruction, badType);
213         break;
214     case JITArrayStorage:
215         slowCases = emitArrayStorageGetByVal(currentInstruction, badType);
216         break;
217     default:
218         CRASH();
219     }
220     
221     addSlowCase(badType);
222     addSlowCase(slowCases);
223     
224     Label done = label();
225
226     if (!ASSERT_DISABLED) {
227         Jump resultOK = branch32(NotEqual, regT1, TrustedImm32(JSValue::EmptyValueTag));
228         abortWithReason(JITGetByValResultIsNotEmpty);
229         resultOK.link(this);
230     }
231
232     emitValueProfilingSite();
233     emitStore(dst, regT1, regT0);
234
235     Label nextHotPath = label();
236     
237     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, nextHotPath));
238 }
239
240 JIT::JumpList JIT::emitContiguousLoad(Instruction*, PatchableJump& badType, IndexingType expectedShape)
241 {
242     JumpList slowCases;
243     
244     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(expectedShape));
245     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
246     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength())));
247     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag
248     load32(BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload
249     slowCases.append(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
250     
251     return slowCases;
252 }
253
254 JIT::JumpList JIT::emitDoubleLoad(Instruction*, PatchableJump& badType)
255 {
256     JumpList slowCases;
257     
258     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(DoubleShape));
259     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
260     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength())));
261     loadDouble(BaseIndex(regT3, regT2, TimesEight), fpRegT0);
262     slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
263     
264     return slowCases;
265 }
266
267 JIT::JumpList JIT::emitArrayStorageLoad(Instruction*, PatchableJump& badType)
268 {
269     JumpList slowCases;
270     
271     add32(TrustedImm32(-ArrayStorageShape), regT1, regT3);
272     badType = patchableBranch32(Above, regT3, TrustedImm32(SlowPutArrayStorageShape - ArrayStorageShape));
273     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
274     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, ArrayStorage::vectorLengthOffset())));
275     load32(BaseIndex(regT3, regT2, TimesEight, ArrayStorage::vectorOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1); // tag
276     load32(BaseIndex(regT3, regT2, TimesEight, ArrayStorage::vectorOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0); // payload
277     slowCases.append(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
278     
279     return slowCases;
280 }
281
282 JITGetByIdGenerator JIT::emitGetByValWithCachedId(ByValInfo* byValInfo, Instruction* currentInstruction, const Identifier& propertyName, Jump& fastDoneCase, Jump& slowDoneCase, JumpList& slowCases)
283 {
284     int dst = currentInstruction[1].u.operand;
285
286     // base: tag(regT1), payload(regT0)
287     // property: tag(regT3), payload(regT2)
288     // scratch: regT4
289
290     slowCases.append(branch32(NotEqual, regT3, TrustedImm32(JSValue::CellTag)));
291     emitByValIdentifierCheck(byValInfo, regT2, regT4, propertyName, slowCases);
292
293     JITGetByIdGenerator gen(
294         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
295         propertyName.impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::Get);
296     gen.generateFastPath(*this);
297
298     fastDoneCase = jump();
299
300     Label coldPathBegin = label();
301     gen.slowPathJump().link(this);
302
303     Call call = callOperationWithProfile(operationGetByIdOptimize, dst, gen.stubInfo(), JSValueRegs(regT1, regT0), propertyName.impl());
304     gen.reportSlowPathCall(coldPathBegin, call);
305     slowDoneCase = jump();
306
307     return gen;
308 }
309
310 void JIT::emitSlow_op_get_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
311 {
312     int dst = currentInstruction[1].u.operand;
313     int base = currentInstruction[2].u.operand;
314     int property = currentInstruction[3].u.operand;
315     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
316
317     linkSlowCaseIfNotJSCell(iter, base); // base cell check
318     linkSlowCase(iter); // property int32 check
319
320     Jump nonCell = jump();
321     linkSlowCase(iter); // base array check
322     Jump notString = branchStructure(NotEqual, Address(regT0, JSCell::structureIDOffset()), m_vm->stringStructure.get());
323     emitNakedCall(m_vm->getCTIStub(stringGetByValStubGenerator).code());
324     Jump failed = branchTestPtr(Zero, regT0);
325     emitStore(dst, regT1, regT0);
326     emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_get_by_val));
327     failed.link(this);
328     notString.link(this);
329     nonCell.link(this);
330
331     linkSlowCase(iter); // vector length check
332     linkSlowCase(iter); // empty value
333     
334     Label slowPath = label();
335     
336     emitLoad(base, regT1, regT0);
337     emitLoad(property, regT3, regT2);
338     Call call = callOperation(operationGetByValOptimize, dst, JSValueRegs(regT1, regT0), JSValueRegs(regT3, regT2), byValInfo);
339
340     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
341     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
342     m_byValInstructionIndex++;
343
344     emitValueProfilingSite();
345 }
346
347 void JIT::emit_op_put_by_val(Instruction* currentInstruction)
348 {
349     int base = currentInstruction[1].u.operand;
350     int property = currentInstruction[2].u.operand;
351     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
352     ByValInfo* byValInfo = m_codeBlock->addByValInfo();
353     
354     emitLoad2(base, regT1, regT0, property, regT3, regT2);
355     
356     emitJumpSlowCaseIfNotJSCell(base, regT1);
357     PatchableJump notIndex = patchableBranch32(NotEqual, regT3, TrustedImm32(JSValue::Int32Tag));
358     addSlowCase(notIndex);
359     emitArrayProfilingSiteWithCell(regT0, regT1, profile);
360     and32(TrustedImm32(IndexingShapeMask), regT1);
361     
362     PatchableJump badType;
363     JumpList slowCases;
364     
365     JITArrayMode mode = chooseArrayMode(profile);
366     switch (mode) {
367     case JITInt32:
368         slowCases = emitInt32PutByVal(currentInstruction, badType);
369         break;
370     case JITDouble:
371         slowCases = emitDoublePutByVal(currentInstruction, badType);
372         break;
373     case JITContiguous:
374         slowCases = emitContiguousPutByVal(currentInstruction, badType);
375         break;
376     case JITArrayStorage:
377         slowCases = emitArrayStoragePutByVal(currentInstruction, badType);
378         break;
379     default:
380         CRASH();
381         break;
382     }
383     
384     addSlowCase(badType);
385     addSlowCase(slowCases);
386     
387     Label done = label();
388     
389     m_byValCompilationInfo.append(ByValCompilationInfo(byValInfo, m_bytecodeOffset, notIndex, badType, mode, profile, done, done));
390 }
391
392 JIT::JumpList JIT::emitGenericContiguousPutByVal(Instruction* currentInstruction, PatchableJump& badType, IndexingType indexingShape)
393 {
394     int base = currentInstruction[1].u.operand;
395     int value = currentInstruction[3].u.operand;
396     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
397     
398     JumpList slowCases;
399     
400     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(ContiguousShape));
401     
402     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
403     Jump outOfBounds = branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfPublicLength()));
404     
405     Label storeResult = label();
406     emitLoad(value, regT1, regT0);
407     switch (indexingShape) {
408     case Int32Shape:
409         slowCases.append(branch32(NotEqual, regT1, TrustedImm32(JSValue::Int32Tag)));
410         store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
411         store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
412         break;
413     case ContiguousShape:
414         store32(regT0, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload)));
415         store32(regT1, BaseIndex(regT3, regT2, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag)));
416         emitLoad(base, regT2, regT3);
417         emitWriteBarrier(base, value, ShouldFilterValue);
418         break;
419     case DoubleShape: {
420         Jump notInt = branch32(NotEqual, regT1, TrustedImm32(JSValue::Int32Tag));
421         convertInt32ToDouble(regT0, fpRegT0);
422         Jump ready = jump();
423         notInt.link(this);
424         moveIntsToDouble(regT0, regT1, fpRegT0, fpRegT1);
425         slowCases.append(branchDouble(DoubleNotEqualOrUnordered, fpRegT0, fpRegT0));
426         ready.link(this);
427         storeDouble(fpRegT0, BaseIndex(regT3, regT2, TimesEight));
428         break;
429     }
430     default:
431         CRASH();
432         break;
433     }
434         
435     Jump done = jump();
436     
437     outOfBounds.link(this);
438     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, Butterfly::offsetOfVectorLength())));
439     
440     emitArrayProfileStoreToHoleSpecialCase(profile);
441     
442     add32(TrustedImm32(1), regT2, regT1);
443     store32(regT1, Address(regT3, Butterfly::offsetOfPublicLength()));
444     jump().linkTo(storeResult, this);
445     
446     done.link(this);
447     
448     return slowCases;
449 }
450
451 JIT::JumpList JIT::emitArrayStoragePutByVal(Instruction* currentInstruction, PatchableJump& badType)
452 {
453     int base = currentInstruction[1].u.operand;
454     int value = currentInstruction[3].u.operand;
455     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
456     
457     JumpList slowCases;
458     
459     badType = patchableBranch32(NotEqual, regT1, TrustedImm32(ArrayStorageShape));
460     
461     loadPtr(Address(regT0, JSObject::butterflyOffset()), regT3);
462     slowCases.append(branch32(AboveOrEqual, regT2, Address(regT3, ArrayStorage::vectorLengthOffset())));
463
464     Jump empty = branch32(Equal, BaseIndex(regT3, regT2, TimesEight, ArrayStorage::vectorOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), TrustedImm32(JSValue::EmptyValueTag));
465     
466     Label storeResult(this);
467     emitLoad(value, regT1, regT0);
468     store32(regT0, BaseIndex(regT3, regT2, TimesEight, ArrayStorage::vectorOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.payload))); // payload
469     store32(regT1, BaseIndex(regT3, regT2, TimesEight, ArrayStorage::vectorOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.tag))); // tag
470     Jump end = jump();
471     
472     empty.link(this);
473     emitArrayProfileStoreToHoleSpecialCase(profile);
474     add32(TrustedImm32(1), Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_numValuesInVector)));
475     branch32(Below, regT2, Address(regT3, ArrayStorage::lengthOffset())).linkTo(storeResult, this);
476     
477     add32(TrustedImm32(1), regT2, regT0);
478     store32(regT0, Address(regT3, ArrayStorage::lengthOffset()));
479     jump().linkTo(storeResult, this);
480     
481     end.link(this);
482     
483     emitWriteBarrier(base, value, ShouldFilterValue);
484     
485     return slowCases;
486 }
487
488 JITPutByIdGenerator JIT::emitPutByValWithCachedId(ByValInfo* byValInfo, Instruction* currentInstruction, PutKind putKind, const Identifier& propertyName, JumpList& doneCases, JumpList& slowCases)
489 {
490     // base: tag(regT1), payload(regT0)
491     // property: tag(regT3), payload(regT2)
492
493     int base = currentInstruction[1].u.operand;
494     int value = currentInstruction[3].u.operand;
495
496     slowCases.append(branch32(NotEqual, regT3, TrustedImm32(JSValue::CellTag)));
497     emitByValIdentifierCheck(byValInfo, regT2, regT2, propertyName, slowCases);
498
499     // Write barrier breaks the registers. So after issuing the write barrier,
500     // reload the registers.
501     emitWriteBarrier(base, value, ShouldFilterBase);
502     emitLoadPayload(base, regT0);
503     emitLoad(value, regT3, regT2);
504
505     JITPutByIdGenerator gen(
506         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
507         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT3, regT2), regT1, m_codeBlock->ecmaMode(), putKind);
508     gen.generateFastPath(*this);
509     doneCases.append(jump());
510
511     Label coldPathBegin = label();
512     gen.slowPathJump().link(this);
513
514     // JITPutByIdGenerator only preserve the value and the base's payload, we have to reload the tag.
515     emitLoadTag(base, regT1);
516
517     Call call = callOperation(gen.slowPathFunction(), gen.stubInfo(), JSValueRegs(regT3, regT2), JSValueRegs(regT1, regT0), propertyName.impl());
518     gen.reportSlowPathCall(coldPathBegin, call);
519     doneCases.append(jump());
520
521     return gen;
522 }
523
524 void JIT::emitSlow_op_put_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
525 {
526     int base = currentInstruction[1].u.operand;
527     int property = currentInstruction[2].u.operand;
528     int value = currentInstruction[3].u.operand;
529     ArrayProfile* profile = currentInstruction[4].u.arrayProfile;
530     ByValInfo* byValInfo = m_byValCompilationInfo[m_byValInstructionIndex].byValInfo;
531     
532     linkSlowCaseIfNotJSCell(iter, base); // base cell check
533     linkSlowCase(iter); // property int32 check
534     linkSlowCase(iter); // base not array check
535     
536     JITArrayMode mode = chooseArrayMode(profile);
537     switch (mode) {
538     case JITInt32:
539     case JITDouble:
540         linkSlowCase(iter); // value type check
541         break;
542     default:
543         break;
544     }
545     
546     Jump skipProfiling = jump();
547     linkSlowCase(iter); // out of bounds
548     emitArrayProfileOutOfBoundsSpecialCase(profile);
549     skipProfiling.link(this);
550
551     Label slowPath = label();
552     
553     bool isDirect = Interpreter::getOpcodeID(currentInstruction->u.opcode) == op_put_by_val_direct;
554
555 #if CPU(X86)
556     // FIXME: We only have 5 temp registers, but need 6 to make this call, therefore we materialize
557     // our own call. When we finish moving JSC to the C call stack, we'll get another register so
558     // we can use the normal case.
559     unsigned pokeOffset = 0;
560     poke(GPRInfo::callFrameRegister, pokeOffset++);
561     emitLoad(base, regT0, regT1);
562     poke(regT1, pokeOffset++);
563     poke(regT0, pokeOffset++);
564     emitLoad(property, regT0, regT1);
565     poke(regT1, pokeOffset++);
566     poke(regT0, pokeOffset++);
567     emitLoad(value, regT0, regT1);
568     poke(regT1, pokeOffset++);
569     poke(regT0, pokeOffset++);
570     poke(TrustedImmPtr(byValInfo), pokeOffset++);
571     Call call = appendCallWithExceptionCheck(isDirect ? operationDirectPutByValOptimize : operationPutByValOptimize);
572 #else
573     // The register selection below is chosen to reduce register swapping on ARM.
574     // Swapping shouldn't happen on other platforms.
575     emitLoad(base, regT2, regT1);
576     emitLoad(property, regT3, regT0);
577     emitLoad(value, regT5, regT4);
578     Call call = callOperation(isDirect ? operationDirectPutByValOptimize : operationPutByValOptimize, JSValueRegs(regT2, regT1), JSValueRegs(regT3, regT0), JSValueRegs(regT5, regT4), byValInfo);
579 #endif
580
581     m_byValCompilationInfo[m_byValInstructionIndex].slowPathTarget = slowPath;
582     m_byValCompilationInfo[m_byValInstructionIndex].returnAddress = call;
583     m_byValInstructionIndex++;
584 }
585
586 void JIT::emit_op_try_get_by_id(Instruction* currentInstruction)
587 {
588     int dst = currentInstruction[1].u.operand;
589     int base = currentInstruction[2].u.operand;
590     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
591
592     emitLoad(base, regT1, regT0);
593     emitJumpSlowCaseIfNotJSCell(base, regT1);
594
595     JITGetByIdGenerator gen(
596         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
597         ident->impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::TryGet);
598     gen.generateFastPath(*this);
599     addSlowCase(gen.slowPathJump());
600     m_getByIds.append(gen);
601     
602     emitValueProfilingSite();
603     emitStore(dst, regT1, regT0);
604 }
605
606 void JIT::emitSlow_op_try_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
607 {
608     linkAllSlowCases(iter);
609
610     int resultVReg = currentInstruction[1].u.operand;
611     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
612
613     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
614
615     Label coldPathBegin = label();
616
617     Call call = callOperation(operationTryGetByIdOptimize, resultVReg, gen.stubInfo(), JSValueRegs(regT1, regT0), ident->impl());
618     
619     gen.reportSlowPathCall(coldPathBegin, call);
620 }
621
622
623 void JIT::emit_op_get_by_id(Instruction* currentInstruction)
624 {
625     int dst = currentInstruction[1].u.operand;
626     int base = currentInstruction[2].u.operand;
627     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
628     
629     emitLoad(base, regT1, regT0);
630     emitJumpSlowCaseIfNotJSCell(base, regT1);
631
632     if (*ident == m_vm->propertyNames->length && shouldEmitProfiling())
633         emitArrayProfilingSiteForBytecodeIndexWithCell(regT0, regT2, m_bytecodeOffset);
634
635     JITGetByIdGenerator gen(
636         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
637         ident->impl(), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT1, regT0), AccessType::Get);
638     gen.generateFastPath(*this);
639     addSlowCase(gen.slowPathJump());
640     m_getByIds.append(gen);
641
642     emitValueProfilingSite();
643     emitStore(dst, regT1, regT0);
644 }
645
646 void JIT::emitSlow_op_get_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
647 {
648     linkAllSlowCases(iter);
649
650     int resultVReg = currentInstruction[1].u.operand;
651     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
652
653     JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++];
654     
655     Label coldPathBegin = label();
656     
657     Call call = callOperationWithProfile(operationGetByIdOptimize, resultVReg, gen.stubInfo(), JSValueRegs(regT1, regT0), ident->impl());
658     
659     gen.reportSlowPathCall(coldPathBegin, call);
660 }
661
662 void JIT::emit_op_get_by_id_with_this(Instruction* currentInstruction)
663 {
664     int dst = currentInstruction[1].u.operand;
665     int base = currentInstruction[2].u.operand;
666     int thisVReg = currentInstruction[3].u.operand;
667     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[4].u.operand));
668     
669     emitLoad(base, regT1, regT0);
670     emitLoad(thisVReg, regT4, regT3);
671     emitJumpSlowCaseIfNotJSCell(base, regT1);
672     emitJumpSlowCaseIfNotJSCell(thisVReg, regT4);
673
674     JITGetByIdWithThisGenerator gen(
675         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
676         ident->impl(), JSValueRegs(regT1, regT0), JSValueRegs::payloadOnly(regT0), JSValueRegs(regT4, regT3), AccessType::GetWithThis);
677     gen.generateFastPath(*this);
678     addSlowCase(gen.slowPathJump());
679     m_getByIdsWithThis.append(gen);
680
681     emitValueProfilingSite();
682     emitStore(dst, regT1, regT0);
683 }
684
685 void JIT::emitSlow_op_get_by_id_with_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
686 {
687     linkAllSlowCases(iter);
688
689     int resultVReg = currentInstruction[1].u.operand;
690     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[4].u.operand));
691
692     JITGetByIdWithThisGenerator& gen = m_getByIdsWithThis[m_getByIdWithThisIndex++];
693     
694     Label coldPathBegin = label();
695     
696     Call call = callOperationWithProfile(operationGetByIdWithThisOptimize, resultVReg, gen.stubInfo(), JSValueRegs(regT1, regT0), JSValueRegs(regT4, regT3), ident->impl());
697     
698     gen.reportSlowPathCall(coldPathBegin, call);
699 }
700
701 void JIT::emit_op_put_by_id(Instruction* currentInstruction)
702 {
703     // In order to be able to patch both the Structure, and the object offset, we store one pointer,
704     // to just after the arguments have been loaded into registers 'hotPathBegin', and we generate code
705     // such that the Structure & offset are always at the same distance from this.
706     
707     int base = currentInstruction[1].u.operand;
708     int value = currentInstruction[3].u.operand;
709     int direct = currentInstruction[8].u.putByIdFlags & PutByIdIsDirect;
710     
711     emitLoad2(base, regT1, regT0, value, regT3, regT2);
712     
713     emitJumpSlowCaseIfNotJSCell(base, regT1);
714
715     JITPutByIdGenerator gen(
716         m_codeBlock, CodeOrigin(m_bytecodeOffset), CallSiteIndex(currentInstruction), RegisterSet::stubUnavailableRegisters(),
717         JSValueRegs::payloadOnly(regT0), JSValueRegs(regT3, regT2),
718         regT1, m_codeBlock->ecmaMode(), direct ? Direct : NotDirect);
719     
720     gen.generateFastPath(*this);
721     addSlowCase(gen.slowPathJump());
722     
723     emitWriteBarrier(base, value, ShouldFilterBase);
724
725     m_putByIds.append(gen);
726 }
727
728 void JIT::emitSlow_op_put_by_id(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
729 {
730     linkAllSlowCases(iter);
731
732     int base = currentInstruction[1].u.operand;
733     const Identifier* ident = &(m_codeBlock->identifier(currentInstruction[2].u.operand));
734
735     Label coldPathBegin(this);
736
737     // JITPutByIdGenerator only preserve the value and the base's payload, we have to reload the tag.
738     emitLoadTag(base, regT1);
739
740     JITPutByIdGenerator& gen = m_putByIds[m_putByIdIndex++];
741     
742     Call call = callOperation(
743         gen.slowPathFunction(), gen.stubInfo(), JSValueRegs(regT3, regT2), JSValueRegs(regT1, regT0), ident->impl());
744     
745     gen.reportSlowPathCall(coldPathBegin, call);
746 }
747
748 void JIT::emitVarInjectionCheck(bool needsVarInjectionChecks)
749 {
750     if (!needsVarInjectionChecks)
751         return;
752     addSlowCase(branch8(Equal, AbsoluteAddress(m_codeBlock->globalObject()->varInjectionWatchpoint()->addressOfState()), TrustedImm32(IsInvalidated)));
753 }
754
755 void JIT::emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth)
756 {
757     emitVarInjectionCheck(needsVarInjectionChecks);
758     move(TrustedImm32(JSValue::CellTag), regT1);
759     emitLoadPayload(scope, regT0);
760     for (unsigned i = 0; i < depth; ++i)
761         loadPtr(Address(regT0, JSScope::offsetOfNext()), regT0);
762     emitStore(dst, regT1, regT0);
763 }
764
765 void JIT::emit_op_resolve_scope(Instruction* currentInstruction)
766 {
767     int dst = currentInstruction[1].u.operand;
768     int scope = currentInstruction[2].u.operand;
769     ResolveType resolveType = static_cast<ResolveType>(currentInstruction[4].u.operand);
770     unsigned depth = currentInstruction[5].u.operand;
771     auto emitCode = [&] (ResolveType resolveType) {
772         switch (resolveType) {
773         case GlobalProperty:
774         case GlobalVar:
775         case GlobalLexicalVar:
776         case GlobalPropertyWithVarInjectionChecks:
777         case GlobalVarWithVarInjectionChecks: 
778         case GlobalLexicalVarWithVarInjectionChecks: {
779             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
780             RELEASE_ASSERT(constantScope);
781             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
782             move(TrustedImm32(JSValue::CellTag), regT1);
783             move(TrustedImmPtr(constantScope), regT0);
784             emitStore(dst, regT1, regT0);
785             break;
786         }
787         case ClosureVar:
788         case ClosureVarWithVarInjectionChecks:
789             emitResolveClosure(dst, scope, needsVarInjectionChecks(resolveType), depth);
790             break;
791         case ModuleVar:
792             move(TrustedImm32(JSValue::CellTag), regT1);
793             move(TrustedImmPtr(currentInstruction[6].u.jsCell.get()), regT0);
794             emitStore(dst, regT1, regT0);
795             break;
796         case Dynamic:
797             addSlowCase(jump());
798             break;
799         case LocalClosureVar:
800         case UnresolvedProperty:
801         case UnresolvedPropertyWithVarInjectionChecks:
802             RELEASE_ASSERT_NOT_REACHED();
803         }
804     };
805     switch (resolveType) {
806     case UnresolvedProperty:
807     case UnresolvedPropertyWithVarInjectionChecks: {
808         JumpList skipToEnd;
809         load32(&currentInstruction[4], regT0);
810
811         Jump notGlobalProperty = branch32(NotEqual, regT0, TrustedImm32(GlobalProperty));
812         emitCode(GlobalProperty);
813         skipToEnd.append(jump());
814         notGlobalProperty.link(this);
815
816         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
817         emitCode(GlobalPropertyWithVarInjectionChecks);
818         skipToEnd.append(jump());
819         notGlobalPropertyWithVarInjections.link(this);
820
821         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
822         emitCode(GlobalLexicalVar);
823         skipToEnd.append(jump());
824         notGlobalLexicalVar.link(this);
825
826         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
827         emitCode(GlobalLexicalVarWithVarInjectionChecks);
828         skipToEnd.append(jump());
829         notGlobalLexicalVarWithVarInjections.link(this);
830
831         addSlowCase(jump());
832         skipToEnd.link(this);
833         break;
834     }
835
836     default:
837         emitCode(resolveType);
838         break;
839     }
840 }
841
842 void JIT::emitLoadWithStructureCheck(int scope, Structure** structureSlot)
843 {
844     emitLoad(scope, regT1, regT0);
845     loadPtr(structureSlot, regT2);
846     addSlowCase(branchPtr(NotEqual, Address(regT0, JSCell::structureIDOffset()), regT2));
847 }
848
849 void JIT::emitGetVarFromPointer(JSValue* operand, GPRReg tag, GPRReg payload)
850 {
851     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
852     load32(bitwise_cast<void*>(rawAddress + TagOffset), tag);
853     load32(bitwise_cast<void*>(rawAddress + PayloadOffset), payload);
854 }
855 void JIT::emitGetVarFromIndirectPointer(JSValue** operand, GPRReg tag, GPRReg payload)
856 {
857     loadPtr(operand, payload);
858     load32(Address(payload, TagOffset), tag);
859     load32(Address(payload, PayloadOffset), payload);
860 }
861
862 void JIT::emitGetClosureVar(int scope, uintptr_t operand)
863 {
864     emitLoad(scope, regT1, regT0);
865     load32(Address(regT0, JSLexicalEnvironment::offsetOfVariables() + operand * sizeof(Register) + TagOffset), regT1);
866     load32(Address(regT0, JSLexicalEnvironment::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset), regT0);
867 }
868
869 void JIT::emit_op_get_from_scope(Instruction* currentInstruction)
870 {
871     int dst = currentInstruction[1].u.operand;
872     int scope = currentInstruction[2].u.operand;
873     ResolveType resolveType = GetPutInfo(currentInstruction[4].u.operand).resolveType();
874     Structure** structureSlot = currentInstruction[5].u.structure.slot();
875     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
876     
877     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
878         switch (resolveType) {
879         case GlobalProperty:
880         case GlobalPropertyWithVarInjectionChecks: {
881             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
882             GPRReg base = regT2;
883             GPRReg resultTag = regT1;
884             GPRReg resultPayload = regT0;
885             GPRReg offset = regT3;
886             
887             move(regT0, base);
888             load32(operandSlot, offset);
889             if (!ASSERT_DISABLED) {
890                 Jump isOutOfLine = branch32(GreaterThanOrEqual, offset, TrustedImm32(firstOutOfLineOffset));
891                 abortWithReason(JITOffsetIsNotOutOfLine);
892                 isOutOfLine.link(this);
893             }
894             loadPtr(Address(base, JSObject::butterflyOffset()), base);
895             neg32(offset);
896             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.payload) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultPayload);
897             load32(BaseIndex(base, offset, TimesEight, OBJECT_OFFSETOF(JSValue, u.asBits.tag) + (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue)), resultTag);
898             break;
899         }
900         case GlobalVar:
901         case GlobalVarWithVarInjectionChecks:
902         case GlobalLexicalVar:
903         case GlobalLexicalVarWithVarInjectionChecks:
904             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
905             if (indirectLoadForOperand)
906                 emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
907             else
908                 emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
909             if (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks) // TDZ check.
910                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
911             break;
912         case ClosureVar:
913         case ClosureVarWithVarInjectionChecks:
914             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
915             emitGetClosureVar(scope, *operandSlot);
916             break;
917         case Dynamic:
918             addSlowCase(jump());
919             break;
920         case ModuleVar:
921         case LocalClosureVar:
922         case UnresolvedProperty:
923         case UnresolvedPropertyWithVarInjectionChecks:
924             RELEASE_ASSERT_NOT_REACHED();
925         }
926     };
927
928     switch (resolveType) {
929     case UnresolvedProperty:
930     case UnresolvedPropertyWithVarInjectionChecks: {
931         JumpList skipToEnd;
932         load32(&currentInstruction[4], regT0);
933         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
934
935         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
936         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
937         isGlobalProperty.link(this);
938         emitCode(GlobalProperty, false);
939         skipToEnd.append(jump());
940         notGlobalPropertyWithVarInjections.link(this);
941
942         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
943         emitCode(GlobalLexicalVar, true);
944         skipToEnd.append(jump());
945         notGlobalLexicalVar.link(this);
946
947         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
948         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
949         skipToEnd.append(jump());
950         notGlobalLexicalVarWithVarInjections.link(this);
951
952         addSlowCase(jump());
953
954         skipToEnd.link(this);
955         break;
956     }
957
958     default:
959         emitCode(resolveType, false);
960         break;
961     }
962     emitValueProfilingSite();
963     emitStore(dst, regT1, regT0);
964 }
965
966 void JIT::emitSlow_op_get_from_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
967 {
968     linkAllSlowCases(iter);
969
970     int dst = currentInstruction[1].u.operand;
971     callOperationWithProfile(operationGetFromScope, dst, currentInstruction);
972 }
973
974 void JIT::emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet* set)
975 {
976     emitLoad(value, regT1, regT0);
977     emitNotifyWrite(set);
978     uintptr_t rawAddress = bitwise_cast<uintptr_t>(operand);
979     store32(regT1, bitwise_cast<void*>(rawAddress + TagOffset));
980     store32(regT0, bitwise_cast<void*>(rawAddress + PayloadOffset));
981 }
982
983 void JIT::emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet** indirectWatchpointSet)
984 {
985     emitLoad(value, regT1, regT0);
986     loadPtr(indirectWatchpointSet, regT2);
987     emitNotifyWrite(regT2);
988     loadPtr(addressOfOperand, regT2);
989     store32(regT1, Address(regT2, TagOffset));
990     store32(regT0, Address(regT2, PayloadOffset));
991 }
992
993 void JIT::emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet* set)
994 {
995     emitLoad(value, regT3, regT2);
996     emitLoad(scope, regT1, regT0);
997     emitNotifyWrite(set);
998     store32(regT3, Address(regT0, JSLexicalEnvironment::offsetOfVariables() + operand * sizeof(Register) + TagOffset));
999     store32(regT2, Address(regT0, JSLexicalEnvironment::offsetOfVariables() + operand * sizeof(Register) + PayloadOffset));
1000 }
1001
1002 void JIT::emit_op_put_to_scope(Instruction* currentInstruction)
1003 {
1004     int scope = currentInstruction[1].u.operand;
1005     int value = currentInstruction[3].u.operand;
1006     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
1007     ResolveType resolveType = getPutInfo.resolveType();
1008     Structure** structureSlot = currentInstruction[5].u.structure.slot();
1009     uintptr_t* operandSlot = reinterpret_cast<uintptr_t*>(&currentInstruction[6].u.pointer);
1010     
1011     auto emitCode = [&] (ResolveType resolveType, bool indirectLoadForOperand) {
1012         switch (resolveType) {
1013         case GlobalProperty:
1014         case GlobalPropertyWithVarInjectionChecks: {
1015             emitWriteBarrier(m_codeBlock->globalObject(), value, ShouldFilterValue);
1016             emitLoadWithStructureCheck(scope, structureSlot); // Structure check covers var injection.
1017             emitLoad(value, regT3, regT2);
1018             
1019             loadPtr(Address(regT0, JSObject::butterflyOffset()), regT0);
1020             loadPtr(operandSlot, regT1);
1021             negPtr(regT1);
1022             store32(regT3, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag)));
1023             store32(regT2, BaseIndex(regT0, regT1, TimesEight, (firstOutOfLineOffset - 2) * sizeof(EncodedJSValue) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload)));
1024             break;
1025         }
1026         case GlobalVar:
1027         case GlobalVarWithVarInjectionChecks:
1028         case GlobalLexicalVar:
1029         case GlobalLexicalVarWithVarInjectionChecks: {
1030             JSScope* constantScope = JSScope::constantScopeForCodeBlock(resolveType, m_codeBlock);
1031             RELEASE_ASSERT(constantScope);
1032             emitWriteBarrier(constantScope, value, ShouldFilterValue);
1033             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1034             if (!isInitialization(getPutInfo.initializationMode()) && (resolveType == GlobalLexicalVar || resolveType == GlobalLexicalVarWithVarInjectionChecks)) {
1035                 // We need to do a TDZ check here because we can't always prove we need to emit TDZ checks statically.
1036                 if (indirectLoadForOperand)
1037                     emitGetVarFromIndirectPointer(bitwise_cast<JSValue**>(operandSlot), regT1, regT0);
1038                 else
1039                     emitGetVarFromPointer(bitwise_cast<JSValue*>(*operandSlot), regT1, regT0);
1040                 addSlowCase(branch32(Equal, regT1, TrustedImm32(JSValue::EmptyValueTag)));
1041             }
1042             if (indirectLoadForOperand)
1043                 emitPutGlobalVariableIndirect(bitwise_cast<JSValue**>(operandSlot), value, bitwise_cast<WatchpointSet**>(&currentInstruction[5]));
1044             else
1045                 emitPutGlobalVariable(bitwise_cast<JSValue*>(*operandSlot), value, currentInstruction[5].u.watchpointSet);
1046             break;
1047         }
1048         case LocalClosureVar:
1049         case ClosureVar:
1050         case ClosureVarWithVarInjectionChecks:
1051             emitWriteBarrier(scope, value, ShouldFilterValue);
1052             emitVarInjectionCheck(needsVarInjectionChecks(resolveType));
1053             emitPutClosureVar(scope, *operandSlot, value, currentInstruction[5].u.watchpointSet);
1054             break;
1055         case ModuleVar:
1056         case Dynamic:
1057             addSlowCase(jump());
1058             break;
1059         case UnresolvedProperty:
1060         case UnresolvedPropertyWithVarInjectionChecks:
1061             RELEASE_ASSERT_NOT_REACHED();
1062         }
1063     };
1064
1065     switch (resolveType) {
1066     case UnresolvedProperty:
1067     case UnresolvedPropertyWithVarInjectionChecks: {
1068         JumpList skipToEnd;
1069         load32(&currentInstruction[4], regT0);
1070         and32(TrustedImm32(GetPutInfo::typeBits), regT0); // Load ResolveType into T0
1071
1072         Jump isGlobalProperty = branch32(Equal, regT0, TrustedImm32(GlobalProperty));
1073         Jump notGlobalPropertyWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalPropertyWithVarInjectionChecks));
1074         isGlobalProperty.link(this);
1075         emitCode(GlobalProperty, false);
1076         skipToEnd.append(jump());
1077         notGlobalPropertyWithVarInjections.link(this);
1078
1079         Jump notGlobalLexicalVar = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVar));
1080         emitCode(GlobalLexicalVar, true);
1081         skipToEnd.append(jump());
1082         notGlobalLexicalVar.link(this);
1083
1084         Jump notGlobalLexicalVarWithVarInjections = branch32(NotEqual, regT0, TrustedImm32(GlobalLexicalVarWithVarInjectionChecks));
1085         emitCode(GlobalLexicalVarWithVarInjectionChecks, true);
1086         skipToEnd.append(jump());
1087         notGlobalLexicalVarWithVarInjections.link(this);
1088
1089         addSlowCase(jump());
1090
1091         skipToEnd.link(this);
1092         break;
1093     }
1094
1095     default:
1096         emitCode(resolveType, false);
1097         break;
1098     }
1099 }
1100
1101 void JIT::emitSlow_op_put_to_scope(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1102 {
1103     linkAllSlowCases(iter);
1104
1105     GetPutInfo getPutInfo = GetPutInfo(currentInstruction[4].u.operand);
1106     ResolveType resolveType = getPutInfo.resolveType();
1107     if (resolveType == ModuleVar) {
1108         JITSlowPathCall slowPathCall(this, currentInstruction, slow_path_throw_strict_mode_readonly_property_write_error);
1109         slowPathCall.call();
1110     } else
1111         callOperation(operationPutToScope, currentInstruction);
1112 }
1113
1114 void JIT::emit_op_get_from_arguments(Instruction* currentInstruction)
1115 {
1116     int dst = currentInstruction[1].u.operand;
1117     int arguments = currentInstruction[2].u.operand;
1118     int index = currentInstruction[3].u.operand;
1119     
1120     emitLoadPayload(arguments, regT0);
1121     loadPtr(Address(regT0, DirectArguments::offsetOfStorage()), regT0);
1122     load32(Address(regT0, index * sizeof(WriteBarrier<Unknown>) + TagOffset), regT1);
1123     load32(Address(regT0, index * sizeof(WriteBarrier<Unknown>) + PayloadOffset), regT0);
1124     emitValueProfilingSite();
1125     emitStore(dst, regT1, regT0);
1126 }
1127
1128 void JIT::emit_op_put_to_arguments(Instruction* currentInstruction)
1129 {
1130     int arguments = currentInstruction[1].u.operand;
1131     int index = currentInstruction[2].u.operand;
1132     int value = currentInstruction[3].u.operand;
1133     
1134     emitWriteBarrier(arguments, value, ShouldFilterValue);
1135     
1136     emitLoadPayload(arguments, regT0);
1137     loadPtr(Address(regT0, DirectArguments::offsetOfStorage()), regT0);
1138     emitLoad(value, regT1, regT2);
1139     store32(regT1, Address(regT0, index * sizeof(WriteBarrier<Unknown>) + TagOffset));
1140     store32(regT2, Address(regT0, index * sizeof(WriteBarrier<Unknown>) + PayloadOffset));
1141 }
1142
1143 } // namespace JSC
1144
1145 #endif // USE(JSVALUE32_64)
1146 #endif // ENABLE(JIT)