blob: c5741b3373a0421e4df29b95b80fb5e555432e54 [file] [log] [blame]
barraclough@apple.com2302c042011-03-14 23:31:00 +00001/*
keith_miller@apple.com3793b132016-01-11 21:31:04 +00002 * Copyright (C) 2011, 2013-2016 Apple Inc. All rights reserved.
barraclough@apple.com2302c042011-03-14 23:31:00 +00003 *
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#include "DFGOperations.h"
28
mark.lam@apple.coma4fe7ab2012-11-09 03:03:44 +000029#include "ButterflyInlines.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000030#include "ClonedArguments.h"
barraclough@apple.com2302c042011-03-14 23:31:00 +000031#include "CodeBlock.h"
oliver@apple.comb3e5acb2013-07-25 04:02:53 +000032#include "CommonSlowPaths.h"
mark.lam@apple.coma4fe7ab2012-11-09 03:03:44 +000033#include "CopiedSpaceInlines.h"
fpizlo@apple.com532f1e52013-09-04 06:26:04 +000034#include "DFGDriver.h"
fpizlo@apple.comb426f862014-02-10 02:51:13 +000035#include "DFGJITCode.h"
fpizlo@apple.com0bef2a12014-02-10 19:26:29 +000036#include "DFGOSRExit.h"
fpizlo@apple.com5e135772012-07-12 00:12:03 +000037#include "DFGThunks.h"
fpizlo@apple.com532f1e52013-09-04 06:26:04 +000038#include "DFGToFTLDeferredCompilationCallback.h"
39#include "DFGToFTLForOSREntryDeferredCompilationCallback.h"
40#include "DFGWorklist.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000041#include "DirectArguments.h"
fpizlo@apple.com532f1e52013-09-04 06:26:04 +000042#include "FTLForOSREntryJITCode.h"
43#include "FTLOSREntry.h"
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000044#include "HostCallReturnValue.h"
fpizlo@apple.comdc03dc52012-01-17 00:53:40 +000045#include "GetterSetter.h"
barraclough@apple.com2302c042011-03-14 23:31:00 +000046#include "Interpreter.h"
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +000047#include "JIT.h"
oliver@apple.comc55314a2012-05-30 19:45:20 +000048#include "JITExceptions.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000049#include "JSCInlines.h"
oliver@apple.coma7dfb4d2014-09-11 18:18:14 +000050#include "JSLexicalEnvironment.h"
ggaren@apple.comc862eac2013-01-29 05:48:01 +000051#include "ObjectConstructor.h"
mark.lam@apple.com9df8b832013-09-26 20:27:14 +000052#include "Repatch.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000053#include "ScopedArguments.h"
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +000054#include "StringConstructor.h"
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000055#include "Symbol.h"
saambarati1@gmail.comdaf10202014-10-01 20:47:51 +000056#include "TypeProfilerLog.h"
fpizlo@apple.com372fa822013-08-21 19:43:47 +000057#include "TypedArrayInlines.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000058#include "VM.h"
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +000059#include <wtf/InlineASM.h>
barraclough@apple.com2302c042011-03-14 23:31:00 +000060
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +000061#if ENABLE(JIT)
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000062#if ENABLE(DFG_JIT)
63
barraclough@apple.com2302c042011-03-14 23:31:00 +000064namespace JSC { namespace DFG {
65
oliver@apple.come050d642013-10-19 00:09:28 +000066template<bool strict, bool direct>
weinig@apple.coma96509f2011-06-15 21:57:17 +000067static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value)
barraclough@apple.comc7af2d32011-05-26 21:37:05 +000068{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000069 VM& vm = exec->vm();
70 NativeCallFrameTracer tracer(&vm, exec);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +000071 ASSERT(isIndex(index));
oliver@apple.come050d642013-10-19 00:09:28 +000072 if (direct) {
73 RELEASE_ASSERT(baseValue.isObject());
74 asObject(baseValue)->putDirectIndex(exec, index, value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
75 return;
76 }
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +000077 if (baseValue.isObject()) {
78 JSObject* object = asObject(baseValue);
79 if (object->canSetIndexQuickly(index)) {
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000080 object->setIndexQuickly(vm, index, value);
weinig@apple.coma96509f2011-06-15 21:57:17 +000081 return;
82 }
83
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +000084 object->methodTable(vm)->putByIndex(object, exec, index, value, strict);
weinig@apple.coma96509f2011-06-15 21:57:17 +000085 return;
86 }
87
barraclough@apple.coma4d51f22012-03-06 01:18:42 +000088 baseValue.putByIndex(exec, index, value, strict);
weinig@apple.coma96509f2011-06-15 21:57:17 +000089}
90
oliver@apple.come050d642013-10-19 00:09:28 +000091template<bool strict, bool direct>
mark.lam@apple.com9df8b832013-09-26 20:27:14 +000092ALWAYS_INLINE static void JIT_OPERATION operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
weinig@apple.coma96509f2011-06-15 21:57:17 +000093{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000094 VM* vm = &exec->vm();
95 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +000096
barraclough@apple.comc7af2d32011-05-26 21:37:05 +000097 JSValue baseValue = JSValue::decode(encodedBase);
98 JSValue property = JSValue::decode(encodedProperty);
99 JSValue value = JSValue::decode(encodedValue);
100
101 if (LIKELY(property.isUInt32())) {
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000102 // Despite its name, JSValue::isUInt32 will return true only for positive boxed int32_t; all those values are valid array indices.
103 ASSERT(isIndex(property.asUInt32()));
commit-queue@webkit.orge3549c62015-01-22 19:34:34 +0000104 putByVal<strict, direct>(exec, baseValue, property.asUInt32(), value);
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000105 return;
106 }
107
weinig@apple.coma96509f2011-06-15 21:57:17 +0000108 if (property.isDouble()) {
109 double propertyAsDouble = property.asDouble();
110 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000111 if (propertyAsDouble == propertyAsUInt32 && isIndex(propertyAsUInt32)) {
oliver@apple.come050d642013-10-19 00:09:28 +0000112 putByVal<strict, direct>(exec, baseValue, propertyAsUInt32, value);
weinig@apple.coma96509f2011-06-15 21:57:17 +0000113 return;
114 }
115 }
116
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000117 // Don't put to an object if toString throws an exception.
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000118 auto propertyName = property.toPropertyKey(exec);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000119 if (vm->exception())
120 return;
121
122 PutPropertySlot slot(baseValue, strict);
123 if (direct) {
124 RELEASE_ASSERT(baseValue.isObject());
125 if (Optional<uint32_t> index = parseIndex(propertyName))
126 asObject(baseValue)->putDirectIndex(exec, index.value(), value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
127 else
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000128 asObject(baseValue)->putDirect(*vm, propertyName, value, slot);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000129 } else
130 baseValue.put(exec, propertyName, value, slot);
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000131}
132
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000133template<typename ViewClass>
134char* newTypedArrayWithSize(ExecState* exec, Structure* structure, int32_t size)
135{
136 VM& vm = exec->vm();
137 NativeCallFrameTracer tracer(&vm, exec);
138 if (size < 0) {
commit-queue@webkit.org29e710c2014-08-29 21:33:30 +0000139 vm.throwException(exec, createRangeError(exec, ASCIILiteral("Requested length is negative")));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000140 return 0;
141 }
142 return bitwise_cast<char*>(ViewClass::create(exec, structure, size));
143}
144
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000145extern "C" {
146
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000147EncodedJSValue JIT_OPERATION operationToThis(ExecState* exec, EncodedJSValue encodedOp)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000148{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000149 VM* vm = &exec->vm();
150 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000151
fpizlo@apple.com018818d2013-09-13 23:18:19 +0000152 return JSValue::encode(JSValue::decode(encodedOp).toThis(exec, NotStrictMode));
153}
154
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000155EncodedJSValue JIT_OPERATION operationToThisStrict(ExecState* exec, EncodedJSValue encodedOp)
fpizlo@apple.com018818d2013-09-13 23:18:19 +0000156{
157 VM* vm = &exec->vm();
158 NativeCallFrameTracer tracer(vm, exec);
159
160 return JSValue::encode(JSValue::decode(encodedOp).toThis(exec, StrictMode));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000161}
162
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000163JSCell* JIT_OPERATION operationCreateThis(ExecState* exec, JSObject* constructor, int32_t inlineCapacity)
fpizlo@apple.combb159ec2011-09-21 22:17:06 +0000164{
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000165 VM& vm = exec->vm();
166 NativeCallFrameTracer tracer(&vm, exec);
sbarati@apple.come5315aa2016-02-20 23:51:33 +0000167 if (constructor->type() == JSFunctionType)
168 return constructEmptyObject(exec, jsCast<JSFunction*>(constructor)->rareData(exec, inlineCapacity)->objectAllocationProfile()->structure());
barraclough@apple.comcef11dc2012-05-10 18:40:29 +0000169
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000170 JSValue proto = constructor->get(exec, exec->propertyNames().prototype);
171 if (vm.exception())
172 return nullptr;
173 if (proto.isObject())
174 return constructEmptyObject(exec, asObject(proto));
sbarati@apple.come5315aa2016-02-20 23:51:33 +0000175 return constructEmptyObject(exec);
fpizlo@apple.com133c9ac2011-11-08 00:37:33 +0000176}
177
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000178EncodedJSValue JIT_OPERATION operationValueBitAnd(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
179{
180 VM* vm = &exec->vm();
181 NativeCallFrameTracer tracer(vm, exec);
182
183 JSValue op1 = JSValue::decode(encodedOp1);
184 JSValue op2 = JSValue::decode(encodedOp2);
185
186 int32_t a = op1.toInt32(exec);
187 int32_t b = op2.toInt32(exec);
188 return JSValue::encode(jsNumber(a & b));
189}
190
191EncodedJSValue JIT_OPERATION operationValueBitOr(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
192{
193 VM* vm = &exec->vm();
194 NativeCallFrameTracer tracer(vm, exec);
195
196 JSValue op1 = JSValue::decode(encodedOp1);
197 JSValue op2 = JSValue::decode(encodedOp2);
198
199 int32_t a = op1.toInt32(exec);
200 int32_t b = op2.toInt32(exec);
201 return JSValue::encode(jsNumber(a | b));
202}
203
204EncodedJSValue JIT_OPERATION operationValueBitXor(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
205{
206 VM* vm = &exec->vm();
207 NativeCallFrameTracer tracer(vm, exec);
208
209 JSValue op1 = JSValue::decode(encodedOp1);
210 JSValue op2 = JSValue::decode(encodedOp2);
211
212 int32_t a = op1.toInt32(exec);
213 int32_t b = op2.toInt32(exec);
214 return JSValue::encode(jsNumber(a ^ b));
215}
216
217EncodedJSValue JIT_OPERATION operationValueBitLShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
218{
219 VM* vm = &exec->vm();
220 NativeCallFrameTracer tracer(vm, exec);
221
222 JSValue op1 = JSValue::decode(encodedOp1);
223 JSValue op2 = JSValue::decode(encodedOp2);
224
225 int32_t a = op1.toInt32(exec);
226 uint32_t b = op2.toUInt32(exec);
227 return JSValue::encode(jsNumber(a << (b & 0x1f)));
228}
229
230EncodedJSValue JIT_OPERATION operationValueBitRShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
231{
232 VM* vm = &exec->vm();
233 NativeCallFrameTracer tracer(vm, exec);
234
235 JSValue op1 = JSValue::decode(encodedOp1);
236 JSValue op2 = JSValue::decode(encodedOp2);
237
238 int32_t a = op1.toInt32(exec);
239 uint32_t b = op2.toUInt32(exec);
240 return JSValue::encode(jsNumber(a >> (b & 0x1f)));
241}
242
243EncodedJSValue JIT_OPERATION operationValueBitURShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
244{
245 VM* vm = &exec->vm();
246 NativeCallFrameTracer tracer(vm, exec);
247
248 JSValue op1 = JSValue::decode(encodedOp1);
249 JSValue op2 = JSValue::decode(encodedOp2);
250
251 uint32_t a = op1.toUInt32(exec);
252 uint32_t b = op2.toUInt32(exec);
253 return JSValue::encode(jsNumber(static_cast<int32_t>(a >> (b & 0x1f))));
254}
255
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000256EncodedJSValue JIT_OPERATION operationValueAdd(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000257{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000258 VM* vm = &exec->vm();
259 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000260
barraclough@apple.com2302c042011-03-14 23:31:00 +0000261 JSValue op1 = JSValue::decode(encodedOp1);
262 JSValue op2 = JSValue::decode(encodedOp2);
barraclough@apple.com2302c042011-03-14 23:31:00 +0000263
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000264 return JSValue::encode(jsAdd(exec, op1, op2));
265}
266
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000267EncodedJSValue JIT_OPERATION operationValueAddNotNumber(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000268{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000269 VM* vm = &exec->vm();
270 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000271
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000272 JSValue op1 = JSValue::decode(encodedOp1);
273 JSValue op2 = JSValue::decode(encodedOp2);
274
fpizlo@apple.com5df0cd82011-08-19 00:18:49 +0000275 ASSERT(!op1.isNumber() || !op2.isNumber());
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000276
ggaren@apple.com64be5e92012-01-24 07:34:10 +0000277 if (op1.isString() && !op2.isObject())
278 return JSValue::encode(jsString(exec, asString(op1), op2.toString(exec)));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000279
280 return JSValue::encode(jsAddSlowCase(exec, op1, op2));
281}
282
mark.lam@apple.com224ce4d2015-12-08 21:44:12 +0000283EncodedJSValue JIT_OPERATION operationValueDiv(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
284{
285 VM* vm = &exec->vm();
286 NativeCallFrameTracer tracer(vm, exec);
287
288 JSValue op1 = JSValue::decode(encodedOp1);
289 JSValue op2 = JSValue::decode(encodedOp2);
290
291 double a = op1.toNumber(exec);
292 double b = op2.toNumber(exec);
293 return JSValue::encode(jsNumber(a / b));
294}
295
mark.lam@apple.com1d936142015-12-03 05:42:56 +0000296EncodedJSValue JIT_OPERATION operationValueMul(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
297{
298 VM* vm = &exec->vm();
299 NativeCallFrameTracer tracer(vm, exec);
300
301 JSValue op1 = JSValue::decode(encodedOp1);
302 JSValue op2 = JSValue::decode(encodedOp2);
303
304 double a = op1.toNumber(exec);
305 double b = op2.toNumber(exec);
306 return JSValue::encode(jsNumber(a * b));
307}
308
mark.lam@apple.com75249092015-10-16 23:26:14 +0000309EncodedJSValue JIT_OPERATION operationValueSub(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
310{
311 VM* vm = &exec->vm();
312 NativeCallFrameTracer tracer(vm, exec);
313
314 JSValue op1 = JSValue::decode(encodedOp1);
315 JSValue op2 = JSValue::decode(encodedOp2);
316
317 double a = op1.toNumber(exec);
318 double b = op2.toNumber(exec);
319 return JSValue::encode(jsNumber(a - b));
320}
321
akling@apple.com6d3d1812014-04-26 06:00:43 +0000322static ALWAYS_INLINE EncodedJSValue getByVal(ExecState* exec, JSCell* base, uint32_t index)
weinig@apple.coma96509f2011-06-15 21:57:17 +0000323{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000324 VM& vm = exec->vm();
325 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000326
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000327 if (base->isObject()) {
328 JSObject* object = asObject(base);
329 if (object->canGetIndexQuickly(index))
330 return JSValue::encode(object->getIndexQuickly(index));
331 }
weinig@apple.coma96509f2011-06-15 21:57:17 +0000332
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000333 if (isJSString(base) && asString(base)->canGetIndex(index))
weinig@apple.coma96509f2011-06-15 21:57:17 +0000334 return JSValue::encode(asString(base)->getIndex(exec, index));
335
weinig@apple.coma96509f2011-06-15 21:57:17 +0000336 return JSValue::encode(JSValue(base).get(exec, index));
337}
338
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000339EncodedJSValue JIT_OPERATION operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000340{
akling@apple.comb6d91ab2014-02-09 21:33:17 +0000341 VM& vm = exec->vm();
342 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000343
barraclough@apple.com2302c042011-03-14 23:31:00 +0000344 JSValue baseValue = JSValue::decode(encodedBase);
345 JSValue property = JSValue::decode(encodedProperty);
346
347 if (LIKELY(baseValue.isCell())) {
348 JSCell* base = baseValue.asCell();
349
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000350 if (property.isUInt32()) {
weinig@apple.coma96509f2011-06-15 21:57:17 +0000351 return getByVal(exec, base, property.asUInt32());
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000352 } else if (property.isDouble()) {
weinig@apple.coma96509f2011-06-15 21:57:17 +0000353 double propertyAsDouble = property.asDouble();
354 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000355 if (propertyAsUInt32 == propertyAsDouble && isIndex(propertyAsUInt32))
weinig@apple.coma96509f2011-06-15 21:57:17 +0000356 return getByVal(exec, base, propertyAsUInt32);
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000357 } else if (property.isString()) {
akling@apple.combaca5e82014-05-06 00:53:29 +0000358 Structure& structure = *base->structure(vm);
359 if (JSCell::canUseFastGetOwnProperty(structure)) {
utatane.tea@gmail.come0741fb2015-06-02 17:36:16 +0000360 if (RefPtr<AtomicStringImpl> existingAtomicString = asString(property)->toExistingAtomicString(exec)) {
361 if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString.get()))
akling@apple.comcad89042014-09-02 22:29:59 +0000362 return JSValue::encode(result);
363 }
akling@apple.combaca5e82014-05-06 00:53:29 +0000364 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000365 }
barraclough@apple.com2302c042011-03-14 23:31:00 +0000366 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000367
utatane.tea@gmail.com9f61d132015-03-27 11:08:49 +0000368 baseValue.requireObjectCoercible(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000369 if (vm.exception())
utatane.tea@gmail.com9f61d132015-03-27 11:08:49 +0000370 return JSValue::encode(jsUndefined());
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000371 auto propertyName = property.toPropertyKey(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000372 if (vm.exception())
utatane.tea@gmail.com9f61d132015-03-27 11:08:49 +0000373 return JSValue::encode(jsUndefined());
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000374 return JSValue::encode(baseValue.get(exec, propertyName));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000375}
376
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000377EncodedJSValue JIT_OPERATION operationGetByValCell(ExecState* exec, JSCell* base, EncodedJSValue encodedProperty)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000378{
akling@apple.comb6d91ab2014-02-09 21:33:17 +0000379 VM& vm = exec->vm();
380 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000381
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000382 JSValue property = JSValue::decode(encodedProperty);
383
384 if (property.isUInt32())
385 return getByVal(exec, base, property.asUInt32());
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000386 if (property.isDouble()) {
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000387 double propertyAsDouble = property.asDouble();
388 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
389 if (propertyAsUInt32 == propertyAsDouble)
390 return getByVal(exec, base, propertyAsUInt32);
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000391 } else if (property.isString()) {
akling@apple.combaca5e82014-05-06 00:53:29 +0000392 Structure& structure = *base->structure(vm);
393 if (JSCell::canUseFastGetOwnProperty(structure)) {
utatane.tea@gmail.come0741fb2015-06-02 17:36:16 +0000394 if (RefPtr<AtomicStringImpl> existingAtomicString = asString(property)->toExistingAtomicString(exec)) {
395 if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString.get()))
akling@apple.comcad89042014-09-02 22:29:59 +0000396 return JSValue::encode(result);
397 }
akling@apple.combaca5e82014-05-06 00:53:29 +0000398 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000399 }
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000400
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000401 auto propertyName = property.toPropertyKey(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000402 if (vm.exception())
utatane.tea@gmail.com9f61d132015-03-27 11:08:49 +0000403 return JSValue::encode(jsUndefined());
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000404 return JSValue::encode(JSValue(base).get(exec, propertyName));
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000405}
406
oliver@apple.com211b3be2013-07-25 04:03:39 +0000407ALWAYS_INLINE EncodedJSValue getByValCellInt(ExecState* exec, JSCell* base, int32_t index)
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000408{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000409 VM* vm = &exec->vm();
410 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000411
412 if (index < 0) {
413 // Go the slowest way possible becase negative indices don't use indexed storage.
414 return JSValue::encode(JSValue(base).get(exec, Identifier::from(exec, index)));
415 }
416
417 // Use this since we know that the value is out of bounds.
sbarati@apple.com575aa2b2016-03-04 02:25:30 +0000418 return JSValue::encode(JSValue(base).get(exec, static_cast<unsigned>(index)));
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000419}
420
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000421EncodedJSValue JIT_OPERATION operationGetByValArrayInt(ExecState* exec, JSArray* base, int32_t index)
oliver@apple.com211b3be2013-07-25 04:03:39 +0000422{
423 return getByValCellInt(exec, base, index);
424}
425
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000426EncodedJSValue JIT_OPERATION operationGetByValStringInt(ExecState* exec, JSString* base, int32_t index)
oliver@apple.com211b3be2013-07-25 04:03:39 +0000427{
428 return getByValCellInt(exec, base, index);
429}
430
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000431void JIT_OPERATION operationPutByValStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000432{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000433 VM* vm = &exec->vm();
434 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000435
oliver@apple.come050d642013-10-19 00:09:28 +0000436 operationPutByValInternal<true, false>(exec, encodedBase, encodedProperty, encodedValue);
barraclough@apple.com2302c042011-03-14 23:31:00 +0000437}
438
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000439void JIT_OPERATION operationPutByValNonStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000440{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000441 VM* vm = &exec->vm();
442 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000443
oliver@apple.come050d642013-10-19 00:09:28 +0000444 operationPutByValInternal<false, false>(exec, encodedBase, encodedProperty, encodedValue);
barraclough@apple.com2302c042011-03-14 23:31:00 +0000445}
446
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000447void JIT_OPERATION operationPutByValCellStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000448{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000449 VM* vm = &exec->vm();
450 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000451
oliver@apple.come050d642013-10-19 00:09:28 +0000452 operationPutByValInternal<true, false>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000453}
454
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000455void JIT_OPERATION operationPutByValCellNonStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000456{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000457 VM* vm = &exec->vm();
458 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000459
oliver@apple.come050d642013-10-19 00:09:28 +0000460 operationPutByValInternal<false, false>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000461}
462
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000463void JIT_OPERATION operationPutByValBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
barraclough@apple.come2130ff2011-06-07 23:03:32 +0000464{
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000465 VM& vm = exec->vm();
466 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000467
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000468 if (index >= 0) {
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000469 array->putByIndexInline(exec, index, JSValue::decode(encodedValue), true);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000470 return;
471 }
472
oliver@apple.com68848412014-01-02 20:56:20 +0000473 PutPropertySlot slot(array, true);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000474 array->methodTable()->put(
475 array, exec, Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000476}
477
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000478void JIT_OPERATION operationPutByValBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000479{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000480 VM* vm = &exec->vm();
481 NativeCallFrameTracer tracer(vm, exec);
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000482
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000483 if (index >= 0) {
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000484 array->putByIndexInline(exec, index, JSValue::decode(encodedValue), false);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000485 return;
486 }
487
oliver@apple.com68848412014-01-02 20:56:20 +0000488 PutPropertySlot slot(array, false);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000489 array->methodTable()->put(
490 array, exec, Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
barraclough@apple.come2130ff2011-06-07 23:03:32 +0000491}
492
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000493void JIT_OPERATION operationPutDoubleByValBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, double value)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000494{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000495 VM* vm = &exec->vm();
496 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000497
498 JSValue jsValue = JSValue(JSValue::EncodeAsDouble, value);
499
500 if (index >= 0) {
501 array->putByIndexInline(exec, index, jsValue, true);
502 return;
503 }
504
oliver@apple.com68848412014-01-02 20:56:20 +0000505 PutPropertySlot slot(array, true);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000506 array->methodTable()->put(
507 array, exec, Identifier::from(exec, index), jsValue, slot);
508}
509
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000510void JIT_OPERATION operationPutDoubleByValBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, double value)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000511{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000512 VM* vm = &exec->vm();
513 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000514
515 JSValue jsValue = JSValue(JSValue::EncodeAsDouble, value);
516
517 if (index >= 0) {
518 array->putByIndexInline(exec, index, jsValue, false);
519 return;
520 }
521
oliver@apple.com68848412014-01-02 20:56:20 +0000522 PutPropertySlot slot(array, false);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000523 array->methodTable()->put(
524 array, exec, Identifier::from(exec, index), jsValue, slot);
525}
526
oliver@apple.come050d642013-10-19 00:09:28 +0000527void JIT_OPERATION operationPutByValDirectStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
528{
529 VM* vm = &exec->vm();
530 NativeCallFrameTracer tracer(vm, exec);
531
532 operationPutByValInternal<true, true>(exec, encodedBase, encodedProperty, encodedValue);
533}
534
535void JIT_OPERATION operationPutByValDirectNonStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
536{
537 VM* vm = &exec->vm();
538 NativeCallFrameTracer tracer(vm, exec);
539
540 operationPutByValInternal<false, true>(exec, encodedBase, encodedProperty, encodedValue);
541}
542
543void JIT_OPERATION operationPutByValDirectCellStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
544{
545 VM* vm = &exec->vm();
546 NativeCallFrameTracer tracer(vm, exec);
547
548 operationPutByValInternal<true, true>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
549}
550
551void JIT_OPERATION operationPutByValDirectCellNonStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
552{
553 VM* vm = &exec->vm();
554 NativeCallFrameTracer tracer(vm, exec);
555
556 operationPutByValInternal<false, true>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
557}
558
559void JIT_OPERATION operationPutByValDirectBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
560{
561 VM* vm = &exec->vm();
562 NativeCallFrameTracer tracer(vm, exec);
563 if (index >= 0) {
564 array->putDirectIndex(exec, index, JSValue::decode(encodedValue), 0, PutDirectIndexShouldThrow);
565 return;
566 }
567
oliver@apple.com68848412014-01-02 20:56:20 +0000568 PutPropertySlot slot(array, true);
oliver@apple.come050d642013-10-19 00:09:28 +0000569 array->putDirect(exec->vm(), Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
570}
571
572void JIT_OPERATION operationPutByValDirectBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
573{
574 VM* vm = &exec->vm();
575 NativeCallFrameTracer tracer(vm, exec);
576
577 if (index >= 0) {
578 array->putDirectIndex(exec, index, JSValue::decode(encodedValue));
579 return;
580 }
581
oliver@apple.com68848412014-01-02 20:56:20 +0000582 PutPropertySlot slot(array, false);
oliver@apple.come050d642013-10-19 00:09:28 +0000583 array->putDirect(exec->vm(), Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
584}
585
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000586EncodedJSValue JIT_OPERATION operationArrayPush(ExecState* exec, EncodedJSValue encodedValue, JSArray* array)
fpizlo@apple.com24d24e52011-10-04 02:55:54 +0000587{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000588 VM* vm = &exec->vm();
589 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000590
fpizlo@apple.com24d24e52011-10-04 02:55:54 +0000591 array->push(exec, JSValue::decode(encodedValue));
592 return JSValue::encode(jsNumber(array->length()));
593}
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000594
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000595EncodedJSValue JIT_OPERATION operationArrayPushDouble(ExecState* exec, double value, JSArray* array)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000596{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000597 VM* vm = &exec->vm();
598 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000599
600 array->push(exec, JSValue(JSValue::EncodeAsDouble, value));
601 return JSValue::encode(jsNumber(array->length()));
602}
603
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000604EncodedJSValue JIT_OPERATION operationArrayPop(ExecState* exec, JSArray* array)
fpizlo@apple.com04c19742012-08-26 22:35:26 +0000605{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000606 VM* vm = &exec->vm();
607 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com04c19742012-08-26 22:35:26 +0000608
609 return JSValue::encode(array->pop(exec));
610}
611
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000612EncodedJSValue JIT_OPERATION operationArrayPopAndRecoverLength(ExecState* exec, JSArray* array)
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000613{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000614 VM* vm = &exec->vm();
615 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000616
617 array->butterfly()->setPublicLength(array->butterfly()->publicLength() + 1);
618
619 return JSValue::encode(array->pop(exec));
620}
621
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000622EncodedJSValue JIT_OPERATION operationRegExpExecString(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, JSString* argument)
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000623{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000624 VM& vm = globalObject->vm();
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000625 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000626
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000627 return JSValue::encode(regExpObject->execInline(exec, globalObject, argument));
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000628}
629
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000630EncodedJSValue JIT_OPERATION operationRegExpExec(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, EncodedJSValue encodedArgument)
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000631{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000632 VM& vm = globalObject->vm();
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000633 NativeCallFrameTracer tracer(&vm, exec);
634
635 JSValue argument = JSValue::decode(encodedArgument);
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000636
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000637 JSString* input = argument.toStringOrNull(exec);
638 if (!input)
639 return JSValue::encode(jsUndefined());
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000640 return JSValue::encode(regExpObject->execInline(exec, globalObject, input));
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000641}
642
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000643EncodedJSValue JIT_OPERATION operationRegExpExecGeneric(ExecState* exec, JSGlobalObject* globalObject, EncodedJSValue encodedBase, EncodedJSValue encodedArgument)
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000644{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000645 VM& vm = globalObject->vm();
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000646 NativeCallFrameTracer tracer(&vm, exec);
647
648 JSValue base = JSValue::decode(encodedBase);
649 JSValue argument = JSValue::decode(encodedArgument);
650
651 if (!base.inherits(RegExpObject::info()))
652 return throwVMTypeError(exec);
653
654 JSString* input = argument.toStringOrNull(exec);
655 if (!input)
656 return JSValue::encode(jsUndefined());
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000657 return JSValue::encode(asRegExpObject(base)->exec(exec, globalObject, input));
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000658}
659
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000660size_t JIT_OPERATION operationRegExpTestString(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, JSString* input)
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000661{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000662 VM& vm = globalObject->vm();
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000663 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000664
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000665 return regExpObject->testInline(exec, globalObject, input);
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000666}
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000667
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000668size_t JIT_OPERATION operationRegExpTest(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, EncodedJSValue encodedArgument)
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000669{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000670 VM& vm = globalObject->vm();
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000671 NativeCallFrameTracer tracer(&vm, exec);
672
673 JSValue argument = JSValue::decode(encodedArgument);
674
675 JSString* input = argument.toStringOrNull(exec);
676 if (!input)
677 return false;
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000678 return regExpObject->testInline(exec, globalObject, input);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000679}
680
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000681size_t JIT_OPERATION operationRegExpTestGeneric(ExecState* exec, JSGlobalObject* globalObject, EncodedJSValue encodedBase, EncodedJSValue encodedArgument)
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000682{
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000683 VM& vm = globalObject->vm();
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000684 NativeCallFrameTracer tracer(&vm, exec);
685
686 JSValue base = JSValue::decode(encodedBase);
687 JSValue argument = JSValue::decode(encodedArgument);
688
689 if (!base.inherits(RegExpObject::info())) {
690 throwTypeError(exec);
691 return false;
692 }
693
694 JSString* input = argument.toStringOrNull(exec);
695 if (!input)
696 return false;
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000697 return asRegExpObject(base)->test(exec, globalObject, input);
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000698}
fpizlo@apple.comee10e452013-04-09 00:10:16 +0000699
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000700size_t JIT_OPERATION operationCompareStrictEqCell(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
commit-queue@webkit.org6efa2ca2011-07-19 00:36:37 +0000701{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000702 VM* vm = &exec->vm();
703 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000704
commit-queue@webkit.org6efa2ca2011-07-19 00:36:37 +0000705 JSValue op1 = JSValue::decode(encodedOp1);
706 JSValue op2 = JSValue::decode(encodedOp2);
707
708 ASSERT(op1.isCell());
709 ASSERT(op2.isCell());
710
711 return JSValue::strictEqualSlowCaseInline(exec, op1, op2);
712}
713
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000714size_t JIT_OPERATION operationCompareStrictEq(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
barraclough@apple.com848a0cc2011-04-08 20:33:24 +0000715{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000716 VM* vm = &exec->vm();
717 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com82acbbf2012-02-28 00:37:58 +0000718
719 JSValue src1 = JSValue::decode(encodedOp1);
720 JSValue src2 = JSValue::decode(encodedOp2);
oliver@apple.come07a4592012-01-25 19:43:06 +0000721
fpizlo@apple.com82acbbf2012-02-28 00:37:58 +0000722 return JSValue::strictEqual(exec, src1, src2);
barraclough@apple.com848a0cc2011-04-08 20:33:24 +0000723}
724
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000725EncodedJSValue JIT_OPERATION operationToPrimitive(ExecState* exec, EncodedJSValue value)
fpizlo@apple.com90e5f0e2011-09-22 22:42:54 +0000726{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000727 VM* vm = &exec->vm();
728 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000729
fpizlo@apple.com90e5f0e2011-09-22 22:42:54 +0000730 return JSValue::encode(JSValue::decode(value).toPrimitive(exec));
731}
732
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000733char* JIT_OPERATION operationNewArray(ExecState* exec, Structure* arrayStructure, void* buffer, size_t size)
fpizlo@apple.com98a693c2011-09-28 05:33:21 +0000734{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000735 VM* vm = &exec->vm();
736 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000737
fpizlo@apple.com59d1ddb2013-11-05 00:05:02 +0000738 return bitwise_cast<char*>(constructArray(exec, arrayStructure, static_cast<JSValue*>(buffer), size));
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000739}
740
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000741char* JIT_OPERATION operationNewEmptyArray(ExecState* exec, Structure* arrayStructure)
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000742{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000743 VM* vm = &exec->vm();
744 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000745
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000746 return bitwise_cast<char*>(JSArray::create(*vm, arrayStructure));
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000747}
748
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000749char* JIT_OPERATION operationNewArrayWithSize(ExecState* exec, Structure* arrayStructure, int32_t size)
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000750{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000751 VM* vm = &exec->vm();
752 NativeCallFrameTracer tracer(vm, exec);
msaboff@apple.com51d65f22013-04-10 20:01:14 +0000753
msaboff@apple.com6ebf3b82013-04-11 16:19:35 +0000754 if (UNLIKELY(size < 0))
commit-queue@webkit.org3f922f92013-08-29 00:28:42 +0000755 return bitwise_cast<char*>(exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))));
msaboff@apple.com51d65f22013-04-10 20:01:14 +0000756
fpizlo@apple.com8dde06b2015-10-12 22:41:01 +0000757 JSArray* result = JSArray::create(*vm, arrayStructure, size);
758 result->butterfly(); // Ensure that the backing store is in to-space.
759 return bitwise_cast<char*>(result);
fpizlo@apple.com98a693c2011-09-28 05:33:21 +0000760}
761
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000762char* JIT_OPERATION operationNewArrayBuffer(ExecState* exec, Structure* arrayStructure, size_t start, size_t size)
fpizlo@apple.com98a693c2011-09-28 05:33:21 +0000763{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000764 VM& vm = exec->vm();
765 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com59d1ddb2013-11-05 00:05:02 +0000766 return bitwise_cast<char*>(constructArray(exec, arrayStructure, exec->codeBlock()->constantBuffer(start), size));
fpizlo@apple.com98a693c2011-09-28 05:33:21 +0000767}
768
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000769char* JIT_OPERATION operationNewInt8ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000770 ExecState* exec, Structure* structure, int32_t length)
771{
772 return newTypedArrayWithSize<JSInt8Array>(exec, structure, length);
773}
774
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000775char* JIT_OPERATION operationNewInt8ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000776 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
777{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000778 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt8Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000779}
780
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000781char* JIT_OPERATION operationNewInt16ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000782 ExecState* exec, Structure* structure, int32_t length)
783{
784 return newTypedArrayWithSize<JSInt16Array>(exec, structure, length);
785}
786
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000787char* JIT_OPERATION operationNewInt16ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000788 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
789{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000790 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt16Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000791}
792
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000793char* JIT_OPERATION operationNewInt32ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000794 ExecState* exec, Structure* structure, int32_t length)
795{
796 return newTypedArrayWithSize<JSInt32Array>(exec, structure, length);
797}
798
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000799char* JIT_OPERATION operationNewInt32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000800 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
801{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000802 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000803}
804
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000805char* JIT_OPERATION operationNewUint8ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000806 ExecState* exec, Structure* structure, int32_t length)
807{
808 return newTypedArrayWithSize<JSUint8Array>(exec, structure, length);
809}
810
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000811char* JIT_OPERATION operationNewUint8ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000812 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
813{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000814 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint8Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000815}
816
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000817char* JIT_OPERATION operationNewUint8ClampedArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000818 ExecState* exec, Structure* structure, int32_t length)
819{
820 return newTypedArrayWithSize<JSUint8ClampedArray>(exec, structure, length);
821}
822
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000823char* JIT_OPERATION operationNewUint8ClampedArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000824 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
825{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000826 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint8ClampedArray>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000827}
828
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000829char* JIT_OPERATION operationNewUint16ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000830 ExecState* exec, Structure* structure, int32_t length)
831{
832 return newTypedArrayWithSize<JSUint16Array>(exec, structure, length);
833}
834
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000835char* JIT_OPERATION operationNewUint16ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000836 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
837{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000838 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint16Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000839}
840
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000841char* JIT_OPERATION operationNewUint32ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000842 ExecState* exec, Structure* structure, int32_t length)
843{
844 return newTypedArrayWithSize<JSUint32Array>(exec, structure, length);
845}
846
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000847char* JIT_OPERATION operationNewUint32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000848 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
849{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000850 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000851}
852
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000853char* JIT_OPERATION operationNewFloat32ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000854 ExecState* exec, Structure* structure, int32_t length)
855{
856 return newTypedArrayWithSize<JSFloat32Array>(exec, structure, length);
857}
858
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000859char* JIT_OPERATION operationNewFloat32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000860 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
861{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000862 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSFloat32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000863}
864
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000865char* JIT_OPERATION operationNewFloat64ArrayWithSize(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000866 ExecState* exec, Structure* structure, int32_t length)
867{
868 return newTypedArrayWithSize<JSFloat64Array>(exec, structure, length);
869}
870
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000871char* JIT_OPERATION operationNewFloat64ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000872 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
873{
keith_miller@apple.coma646a262015-10-16 21:40:21 +0000874 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSFloat64Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000875}
876
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +0000877JSCell* JIT_OPERATION operationCreateActivationDirect(ExecState* exec, Structure* structure, JSScope* scope, SymbolTable* table, EncodedJSValue initialValueEncoded)
fpizlo@apple.comc6446112012-05-23 20:52:42 +0000878{
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +0000879 JSValue initialValue = JSValue::decode(initialValueEncoded);
880 ASSERT(initialValue == jsUndefined() || initialValue == jsTDZValue());
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000881 VM& vm = exec->vm();
882 NativeCallFrameTracer tracer(&vm, exec);
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +0000883 return JSLexicalEnvironment::create(vm, structure, scope, table, initialValue);
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000884}
885
886JSCell* JIT_OPERATION operationCreateDirectArguments(ExecState* exec, Structure* structure, int32_t length, int32_t minCapacity)
887{
888 VM& vm = exec->vm();
889 NativeCallFrameTracer target(&vm, exec);
890 DirectArguments* result = DirectArguments::create(
891 vm, structure, length, std::max(length, minCapacity));
892 // The caller will store to this object without barriers. Most likely, at this point, this is
893 // still a young object and so no barriers are needed. But it's good to be careful anyway,
894 // since the GC should be allowed to do crazy (like pretenuring, for example).
895 vm.heap.writeBarrier(result);
fpizlo@apple.com9a548f12012-05-24 05:33:09 +0000896 return result;
fpizlo@apple.comc6446112012-05-23 20:52:42 +0000897}
898
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000899JSCell* JIT_OPERATION operationCreateScopedArguments(ExecState* exec, Structure* structure, Register* argumentStart, int32_t length, JSFunction* callee, JSLexicalEnvironment* scope)
fpizlo@apple.com6d4456e2012-05-23 03:48:52 +0000900{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000901 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000902 NativeCallFrameTracer target(&vm, exec);
fpizlo@apple.comd5547492012-06-07 00:23:36 +0000903
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000904 // We could pass the ScopedArgumentsTable* as an argument. We currently don't because I
905 // didn't feel like changing the max number of arguments for a slow path call from 6 to 7.
906 ScopedArgumentsTable* table = scope->symbolTable()->arguments();
fpizlo@apple.comd5547492012-06-07 00:23:36 +0000907
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000908 return ScopedArguments::createByCopyingFrom(
909 vm, structure, argumentStart, length, callee, table, scope);
fpizlo@apple.comd5547492012-06-07 00:23:36 +0000910}
911
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000912JSCell* JIT_OPERATION operationCreateClonedArguments(ExecState* exec, Structure* structure, Register* argumentStart, int32_t length, JSFunction* callee)
fpizlo@apple.comd5547492012-06-07 00:23:36 +0000913{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000914 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000915 NativeCallFrameTracer target(&vm, exec);
916 return ClonedArguments::createByCopyingFrom(
917 exec, structure, argumentStart, length, callee);
fpizlo@apple.com6d4456e2012-05-23 03:48:52 +0000918}
919
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000920JSCell* JIT_OPERATION operationCreateDirectArgumentsDuringExit(ExecState* exec, InlineCallFrame* inlineCallFrame, JSFunction* callee, int32_t argumentCount)
fpizlo@apple.com17da7f32012-02-25 23:05:38 +0000921{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000922 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000923 NativeCallFrameTracer target(&vm, exec);
924
925 DeferGCForAWhile deferGC(vm.heap);
926
927 CodeBlock* codeBlock;
928 if (inlineCallFrame)
929 codeBlock = baselineCodeBlockForInlineCallFrame(inlineCallFrame);
930 else
931 codeBlock = exec->codeBlock();
932
933 unsigned length = argumentCount - 1;
934 unsigned capacity = std::max(length, static_cast<unsigned>(codeBlock->numParameters() - 1));
935 DirectArguments* result = DirectArguments::create(
936 vm, codeBlock->globalObject()->directArgumentsStructure(), length, capacity);
937
938 result->callee().set(vm, result, callee);
939
940 Register* arguments =
941 exec->registers() + (inlineCallFrame ? inlineCallFrame->stackOffset : 0) +
942 CallFrame::argumentOffset(0);
943 for (unsigned i = length; i--;)
944 result->setIndexQuickly(vm, i, arguments[i].jsValue());
945
946 return result;
947}
948
949JSCell* JIT_OPERATION operationCreateClonedArgumentsDuringExit(ExecState* exec, InlineCallFrame* inlineCallFrame, JSFunction* callee, int32_t argumentCount)
950{
951 VM& vm = exec->vm();
952 NativeCallFrameTracer target(&vm, exec);
953
954 DeferGCForAWhile deferGC(vm.heap);
955
956 CodeBlock* codeBlock;
957 if (inlineCallFrame)
958 codeBlock = baselineCodeBlockForInlineCallFrame(inlineCallFrame);
959 else
960 codeBlock = exec->codeBlock();
961
962 unsigned length = argumentCount - 1;
963 ClonedArguments* result = ClonedArguments::createEmpty(
964 vm, codeBlock->globalObject()->outOfBandArgumentsStructure(), callee);
965
966 Register* arguments =
967 exec->registers() + (inlineCallFrame ? inlineCallFrame->stackOffset : 0) +
968 CallFrame::argumentOffset(0);
969 for (unsigned i = length; i--;)
970 result->putDirectIndex(exec, i, arguments[i].jsValue());
971
972 result->putDirect(vm, vm.propertyNames->length, jsNumber(length));
973
974 return result;
fpizlo@apple.com17da7f32012-02-25 23:05:38 +0000975}
976
sbarati@apple.com855d5602015-11-30 20:36:54 +0000977void JIT_OPERATION operationCopyRest(ExecState* exec, JSCell* arrayAsCell, Register* argumentStart, unsigned numberOfParamsToSkip, unsigned arraySize)
sbarati@apple.comc0722da2015-11-20 02:37:47 +0000978{
sbarati@apple.com855d5602015-11-30 20:36:54 +0000979 ASSERT(arraySize);
sbarati@apple.comc0722da2015-11-20 02:37:47 +0000980 JSArray* array = jsCast<JSArray*>(arrayAsCell);
sbarati@apple.com855d5602015-11-30 20:36:54 +0000981 ASSERT(arraySize == array->length());
sbarati@apple.comc0722da2015-11-20 02:37:47 +0000982 array->setLength(exec, arraySize);
983 for (unsigned i = 0; i < arraySize; i++)
984 array->putDirectIndex(exec, i, argumentStart[i + numberOfParamsToSkip].jsValue());
985}
986
fpizlo@apple.comb8823d52015-05-03 00:15:27 +0000987size_t JIT_OPERATION operationObjectIsObject(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
oliver@apple.come722ad02013-01-09 02:37:29 +0000988{
mark.lam@apple.com87a5b6f2014-02-05 04:22:43 +0000989 VM& vm = exec->vm();
990 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comb8823d52015-05-03 00:15:27 +0000991
992 ASSERT(jsDynamicCast<JSObject*>(object));
993
994 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
995 return false;
996 if (object->type() == JSFunctionType)
997 return false;
998 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
999 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001000 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001001 return false;
1002 }
1003
1004 return true;
1005}
1006
1007size_t JIT_OPERATION operationObjectIsFunction(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1008{
1009 VM& vm = exec->vm();
1010 NativeCallFrameTracer tracer(&vm, exec);
1011
1012 ASSERT(jsDynamicCast<JSObject*>(object));
1013
1014 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1015 return false;
1016 if (object->type() == JSFunctionType)
1017 return true;
1018 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1019 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001020 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001021 return true;
1022 }
1023
1024 return false;
1025}
1026
1027JSCell* JIT_OPERATION operationTypeOfObject(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1028{
1029 VM& vm = exec->vm();
1030 NativeCallFrameTracer tracer(&vm, exec);
1031
1032 ASSERT(jsDynamicCast<JSObject*>(object));
1033
1034 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1035 return vm.smallStrings.undefinedString();
1036 if (object->type() == JSFunctionType)
1037 return vm.smallStrings.functionString();
1038 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1039 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001040 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001041 return vm.smallStrings.functionString();
1042 }
1043
1044 return vm.smallStrings.objectString();
1045}
1046
1047int32_t JIT_OPERATION operationTypeOfObjectAsTypeofType(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1048{
1049 VM& vm = exec->vm();
1050 NativeCallFrameTracer tracer(&vm, exec);
1051
1052 ASSERT(jsDynamicCast<JSObject*>(object));
1053
1054 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1055 return static_cast<int32_t>(TypeofType::Undefined);
1056 if (object->type() == JSFunctionType)
1057 return static_cast<int32_t>(TypeofType::Function);
1058 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1059 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001060 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001061 return static_cast<int32_t>(TypeofType::Function);
1062 }
1063
1064 return static_cast<int32_t>(TypeofType::Object);
oliver@apple.come722ad02013-01-09 02:37:29 +00001065}
1066
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001067char* JIT_OPERATION operationAllocatePropertyStorageWithInitialCapacity(ExecState* exec)
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001068{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001069 VM& vm = exec->vm();
1070 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001071
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001072 return reinterpret_cast<char*>(
oliver@apple.coma03796a2013-07-25 04:01:20 +00001073 Butterfly::createUninitialized(vm, 0, 0, initialOutOfLineCapacity, false, 0));
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001074}
1075
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001076char* JIT_OPERATION operationAllocatePropertyStorage(ExecState* exec, size_t newSize)
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001077{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001078 VM& vm = exec->vm();
1079 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001080
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001081 return reinterpret_cast<char*>(
oliver@apple.coma03796a2013-07-25 04:01:20 +00001082 Butterfly::createUninitialized(vm, 0, 0, newSize, false, 0));
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001083}
1084
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001085char* JIT_OPERATION operationReallocateButterflyToHavePropertyStorageWithInitialCapacity(ExecState* exec, JSObject* object)
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001086{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001087 VM& vm = exec->vm();
1088 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001089
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001090 ASSERT(!object->structure()->outOfLineCapacity());
mhahnenberg@apple.com3ddd7ac2014-01-10 02:28:27 +00001091 DeferGC deferGC(vm.heap);
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001092 Butterfly* result = object->growOutOfLineStorage(vm, 0, initialOutOfLineCapacity);
mhahnenberg@apple.comebf01912014-01-02 22:57:14 +00001093 object->setButterflyWithoutChangingStructure(vm, result);
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001094 return reinterpret_cast<char*>(result);
1095}
1096
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001097char* JIT_OPERATION operationReallocateButterflyToGrowPropertyStorage(ExecState* exec, JSObject* object, size_t newSize)
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001098{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001099 VM& vm = exec->vm();
1100 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001101
mhahnenberg@apple.com3ddd7ac2014-01-10 02:28:27 +00001102 DeferGC deferGC(vm.heap);
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001103 Butterfly* result = object->growOutOfLineStorage(vm, object->structure()->outOfLineCapacity(), newSize);
mhahnenberg@apple.comebf01912014-01-02 22:57:14 +00001104 object->setButterflyWithoutChangingStructure(vm, result);
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001105 return reinterpret_cast<char*>(result);
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001106}
1107
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001108char* JIT_OPERATION operationEnsureInt32(ExecState* exec, JSCell* cell)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001109{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001110 VM& vm = exec->vm();
1111 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001112
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001113 if (!cell->isObject())
1114 return 0;
1115
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001116 return reinterpret_cast<char*>(asObject(cell)->ensureInt32(vm).data());
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001117}
1118
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001119char* JIT_OPERATION operationEnsureDouble(ExecState* exec, JSCell* cell)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001120{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001121 VM& vm = exec->vm();
1122 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001123
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001124 if (!cell->isObject())
1125 return 0;
1126
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001127 return reinterpret_cast<char*>(asObject(cell)->ensureDouble(vm).data());
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001128}
1129
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001130char* JIT_OPERATION operationEnsureContiguous(ExecState* exec, JSCell* cell)
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001131{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001132 VM& vm = exec->vm();
1133 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001134
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001135 if (!cell->isObject())
1136 return 0;
1137
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001138 return reinterpret_cast<char*>(asObject(cell)->ensureContiguous(vm).data());
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001139}
1140
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001141char* JIT_OPERATION operationEnsureArrayStorage(ExecState* exec, JSCell* cell)
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001142{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001143 VM& vm = exec->vm();
1144 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001145
1146 if (!cell->isObject())
1147 return 0;
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001148
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001149 return reinterpret_cast<char*>(asObject(cell)->ensureArrayStorage(vm));
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001150}
1151
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001152StringImpl* JIT_OPERATION operationResolveRope(ExecState* exec, JSString* string)
fpizlo@apple.com70bb5c52012-12-11 05:22:49 +00001153{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001154 VM& vm = exec->vm();
1155 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com70bb5c52012-12-11 05:22:49 +00001156
1157 return string->value(exec).impl();
1158}
1159
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001160JSString* JIT_OPERATION operationSingleCharacterString(ExecState* exec, int32_t character)
oliver@apple.com63af2d42013-07-25 04:03:33 +00001161{
1162 VM& vm = exec->vm();
1163 NativeCallFrameTracer tracer(&vm, exec);
1164
1165 return jsSingleCharacterString(exec, static_cast<UChar>(character));
1166}
1167
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001168JSCell* JIT_OPERATION operationNewStringObject(ExecState* exec, JSString* string, Structure* structure)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001169{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001170 VM& vm = exec->vm();
1171 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001172
akling@apple.com019809c2013-10-06 18:16:48 +00001173 return StringObject::create(vm, structure, string);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001174}
1175
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001176JSCell* JIT_OPERATION operationToStringOnCell(ExecState* exec, JSCell* cell)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001177{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001178 VM& vm = exec->vm();
1179 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001180
1181 return JSValue(cell).toString(exec);
1182}
1183
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001184JSCell* JIT_OPERATION operationToString(ExecState* exec, EncodedJSValue value)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001185{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001186 VM& vm = exec->vm();
1187 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001188
1189 return JSValue::decode(value).toString(exec);
1190}
1191
utatane.tea@gmail.com153559e2015-04-06 19:07:12 +00001192JSCell* JIT_OPERATION operationCallStringConstructorOnCell(ExecState* exec, JSCell* cell)
1193{
1194 VM& vm = exec->vm();
1195 NativeCallFrameTracer tracer(&vm, exec);
1196
1197 return stringConstructor(exec, cell);
1198}
1199
1200JSCell* JIT_OPERATION operationCallStringConstructor(ExecState* exec, EncodedJSValue value)
1201{
1202 VM& vm = exec->vm();
1203 NativeCallFrameTracer tracer(&vm, exec);
1204
1205 return stringConstructor(exec, JSValue::decode(value));
1206}
1207
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001208JSCell* JIT_OPERATION operationMakeRope2(ExecState* exec, JSString* left, JSString* right)
fpizlo@apple.com8d225912013-03-19 00:44:57 +00001209{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001210 VM& vm = exec->vm();
1211 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com24c49992014-04-19 21:13:46 +00001212
1213 if (sumOverflows<int32_t>(left->length(), right->length())) {
fpizlo@apple.com75104a32014-04-15 23:33:11 +00001214 throwOutOfMemoryError(exec);
fpizlo@apple.come28731c2014-04-19 20:36:58 +00001215 return nullptr;
fpizlo@apple.com75104a32014-04-15 23:33:11 +00001216 }
fpizlo@apple.com8d225912013-03-19 00:44:57 +00001217
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001218 return JSRopeString::create(vm, left, right);
fpizlo@apple.com8d225912013-03-19 00:44:57 +00001219}
1220
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001221JSCell* JIT_OPERATION operationMakeRope3(ExecState* exec, JSString* a, JSString* b, JSString* c)
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001222{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001223 VM& vm = exec->vm();
1224 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001225
fpizlo@apple.com24c49992014-04-19 21:13:46 +00001226 if (sumOverflows<int32_t>(a->length(), b->length(), c->length())) {
fpizlo@apple.com75104a32014-04-15 23:33:11 +00001227 throwOutOfMemoryError(exec);
fpizlo@apple.come28731c2014-04-19 20:36:58 +00001228 return nullptr;
fpizlo@apple.com75104a32014-04-15 23:33:11 +00001229 }
1230
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001231 return JSRopeString::create(vm, a, b, c);
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001232}
1233
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001234JSCell* JIT_OPERATION operationStrCat2(ExecState* exec, EncodedJSValue a, EncodedJSValue b)
1235{
1236 VM& vm = exec->vm();
1237 NativeCallFrameTracer tracer(&vm, exec);
1238
1239 JSString* str1 = JSValue::decode(a).toString(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001240 ASSERT(!vm.exception()); // Impossible, since we must have been given primitives.
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001241 JSString* str2 = JSValue::decode(b).toString(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001242 ASSERT(!vm.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001243
1244 if (sumOverflows<int32_t>(str1->length(), str2->length())) {
1245 throwOutOfMemoryError(exec);
1246 return nullptr;
1247 }
1248
1249 return JSRopeString::create(vm, str1, str2);
1250}
1251
1252JSCell* JIT_OPERATION operationStrCat3(ExecState* exec, EncodedJSValue a, EncodedJSValue b, EncodedJSValue c)
1253{
1254 VM& vm = exec->vm();
1255 NativeCallFrameTracer tracer(&vm, exec);
1256
1257 JSString* str1 = JSValue::decode(a).toString(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001258 ASSERT(!vm.exception()); // Impossible, since we must have been given primitives.
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001259 JSString* str2 = JSValue::decode(b).toString(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001260 ASSERT(!vm.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001261 JSString* str3 = JSValue::decode(c).toString(exec);
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001262 ASSERT(!vm.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001263
1264 if (sumOverflows<int32_t>(str1->length(), str2->length(), str3->length())) {
1265 throwOutOfMemoryError(exec);
1266 return nullptr;
1267 }
1268
1269 return JSRopeString::create(vm, str1, str2, str3);
1270}
1271
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001272char* JIT_OPERATION operationFindSwitchImmTargetForDouble(
oliver@apple.com9b7647b2013-07-25 04:03:00 +00001273 ExecState* exec, EncodedJSValue encodedValue, size_t tableIndex)
1274{
1275 CodeBlock* codeBlock = exec->codeBlock();
oliver@apple.coma14cea52013-07-25 04:03:23 +00001276 SimpleJumpTable& table = codeBlock->switchJumpTable(tableIndex);
oliver@apple.com9b7647b2013-07-25 04:03:00 +00001277 JSValue value = JSValue::decode(encodedValue);
1278 ASSERT(value.isDouble());
1279 double asDouble = value.asDouble();
1280 int32_t asInt32 = static_cast<int32_t>(asDouble);
1281 if (asDouble == asInt32)
1282 return static_cast<char*>(table.ctiForValue(asInt32).executableAddress());
1283 return static_cast<char*>(table.ctiDefault.executableAddress());
1284}
1285
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001286char* JIT_OPERATION operationSwitchString(ExecState* exec, size_t tableIndex, JSString* string)
oliver@apple.com5c826c02013-07-25 04:03:51 +00001287{
1288 VM& vm = exec->vm();
1289 NativeCallFrameTracer tracer(&vm, exec);
1290
1291 return static_cast<char*>(exec->codeBlock()->stringSwitchJumpTable(tableIndex).ctiForValue(string->value(exec).impl()).executableAddress());
1292}
1293
fpizlo@apple.com5a3036b2015-04-29 03:34:43 +00001294int32_t JIT_OPERATION operationSwitchStringAndGetBranchOffset(ExecState* exec, size_t tableIndex, JSString* string)
1295{
1296 VM& vm = exec->vm();
1297 NativeCallFrameTracer tracer(&vm, exec);
1298
1299 return exec->codeBlock()->stringSwitchJumpTable(tableIndex).offsetForValue(string->value(exec).impl(), std::numeric_limits<int32_t>::min());
1300}
1301
fpizlo@apple.com8dde06b2015-10-12 22:41:01 +00001302char* JIT_OPERATION operationGetButterfly(ExecState* exec, JSCell* cell)
1303{
1304 VM& vm = exec->vm();
1305 NativeCallFrameTracer tracer(&vm, exec);
1306
fpizlo@apple.com8dde06b2015-10-12 22:41:01 +00001307 return bitwise_cast<char*>(jsCast<JSObject*>(cell)->butterfly());
1308}
1309
1310char* JIT_OPERATION operationGetArrayBufferVector(ExecState* exec, JSCell* cell)
1311{
1312 VM& vm = exec->vm();
1313 NativeCallFrameTracer tracer(&vm, exec);
1314
1315 return bitwise_cast<char*>(jsCast<JSArrayBufferView*>(cell)->vector());
1316}
1317
fpizlo@apple.com3a2fa4c2015-04-13 22:13:12 +00001318void JIT_OPERATION operationNotifyWrite(ExecState* exec, WatchpointSet* set)
fpizlo@apple.com33961712013-11-20 05:49:05 +00001319{
1320 VM& vm = exec->vm();
1321 NativeCallFrameTracer tracer(&vm, exec);
1322
fpizlo@apple.com3a2fa4c2015-04-13 22:13:12 +00001323 set->touch("Executed NotifyWrite");
fpizlo@apple.com33961712013-11-20 05:49:05 +00001324}
1325
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001326void JIT_OPERATION operationThrowStackOverflowForVarargs(ExecState* exec)
1327{
1328 VM& vm = exec->vm();
1329 NativeCallFrameTracer tracer(&vm, exec);
1330 throwStackOverflowError(exec);
1331}
1332
fpizlo@apple.com8fefdd32015-02-18 19:55:47 +00001333int32_t JIT_OPERATION operationSizeOfVarargs(ExecState* exec, EncodedJSValue encodedArguments, int32_t firstVarArgOffset)
1334{
1335 VM& vm = exec->vm();
1336 NativeCallFrameTracer tracer(&vm, exec);
1337 JSValue arguments = JSValue::decode(encodedArguments);
1338
1339 return sizeOfVarargs(exec, arguments, firstVarArgOffset);
1340}
1341
1342void JIT_OPERATION operationLoadVarargs(ExecState* exec, int32_t firstElementDest, EncodedJSValue encodedArguments, int32_t offset, int32_t length, int32_t mandatoryMinimum)
1343{
1344 VM& vm = exec->vm();
1345 NativeCallFrameTracer tracer(&vm, exec);
1346 JSValue arguments = JSValue::decode(encodedArguments);
1347
1348 loadVarargs(exec, VirtualRegister(firstElementDest), arguments, offset, length);
1349
1350 for (int32_t i = length; i < mandatoryMinimum; ++i)
1351 exec->r(firstElementDest + i) = jsUndefined();
1352}
1353
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001354double JIT_OPERATION operationFModOnInts(int32_t a, int32_t b)
fpizlo@apple.com2c2536e2012-03-21 01:29:28 +00001355{
1356 return fmod(a, b);
1357}
1358
utatane.tea@gmail.comd2fca0a2015-12-15 03:51:42 +00001359#if USE(JSVALUE32_64)
1360double JIT_OPERATION operationRandom(JSGlobalObject* globalObject)
1361{
1362 return globalObject->weakRandomNumber();
1363}
1364#endif
1365
mark.lam@apple.com03a3e382016-01-08 18:44:36 +00001366JSCell* JIT_OPERATION operationStringFromCharCode(ExecState* exec, int32_t op1)
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +00001367{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001368 VM* vm = &exec->vm();
1369 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com03a3e382016-01-08 18:44:36 +00001370 return JSC::stringFromCharCode(exec, op1);
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +00001371}
1372
mark.lam@apple.com151fe102016-01-13 23:28:38 +00001373EncodedJSValue JIT_OPERATION operationStringFromCharCodeUntyped(ExecState* exec, EncodedJSValue encodedValue)
1374{
1375 VM* vm = &exec->vm();
1376 NativeCallFrameTracer tracer(vm, exec);
1377 JSValue charValue = JSValue::decode(encodedValue);
1378 int32_t chInt = charValue.toUInt32(exec);
1379 return JSValue::encode(JSC::stringFromCharCode(exec, chInt));
1380}
1381
fpizlo@apple.comf2999932014-07-15 00:41:39 +00001382int64_t JIT_OPERATION operationConvertBoxedDoubleToInt52(EncodedJSValue encodedValue)
1383{
1384 JSValue value = JSValue::decode(encodedValue);
1385 if (!value.isDouble())
1386 return JSValue::notInt52;
1387 return tryConvertToInt52(value.asDouble());
1388}
1389
1390int64_t JIT_OPERATION operationConvertDoubleToInt52(double value)
1391{
1392 return tryConvertToInt52(value);
1393}
1394
sbarati@apple.comfa857522016-03-07 01:00:33 +00001395size_t JIT_OPERATION operationDefaultHasInstance(ExecState* exec, JSCell* value, JSCell* proto) // Returns jsBoolean(True|False) on 64-bit.
1396{
1397 VM* vm = &exec->vm();
1398 NativeCallFrameTracer tracer(vm, exec);
1399 if (JSObject::defaultHasInstance(exec, value, proto))
1400 return 1;
1401 return 0;
1402}
1403
saambarati1@gmail.comdaf10202014-10-01 20:47:51 +00001404void JIT_OPERATION operationProcessTypeProfilerLogDFG(ExecState* exec)
1405{
1406 exec->vm().typeProfilerLog()->processLogEntries(ASCIILiteral("Log Full, called from inside DFG."));
1407}
1408
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001409void JIT_OPERATION debugOperationPrintSpeculationFailure(ExecState* exec, void* debugInfoRaw, void* scratch)
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001410{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001411 VM* vm = &exec->vm();
1412 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +00001413
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001414 SpeculationFailureDebugInfo* debugInfo = static_cast<SpeculationFailureDebugInfo*>(debugInfoRaw);
fpizlo@apple.comf2bf0dd2011-09-26 04:05:28 +00001415 CodeBlock* codeBlock = debugInfo->codeBlock;
fpizlo@apple.com47d3b642011-10-05 21:36:23 +00001416 CodeBlock* alternative = codeBlock->alternative();
mark.lam@apple.come7ecf832014-04-02 20:49:27 +00001417 dataLog("Speculation failure in ", *codeBlock);
1418 dataLog(" @ exit #", vm->osrExitIndex, " (bc#", debugInfo->bytecodeOffset, ", ", exitKindToString(debugInfo->kind), ") with ");
fpizlo@apple.com0bfcc382012-11-30 03:42:29 +00001419 if (alternative) {
1420 dataLog(
1421 "executeCounter = ", alternative->jitExecuteCounter(),
1422 ", reoptimizationRetryCounter = ", alternative->reoptimizationRetryCounter(),
1423 ", optimizationDelayCounter = ", alternative->optimizationDelayCounter());
1424 } else
1425 dataLog("no alternative code block (i.e. we've been jettisoned)");
1426 dataLog(", osrExitCounter = ", codeBlock->osrExitCounter(), "\n");
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001427 dataLog(" GPRs at time of exit:");
1428 char* scratchPointer = static_cast<char*>(scratch);
1429 for (unsigned i = 0; i < GPRInfo::numberOfRegisters; ++i) {
1430 GPRReg gpr = GPRInfo::toRegister(i);
commit-queue@webkit.org94ea8122013-02-25 13:13:43 +00001431 dataLog(" ", GPRInfo::debugName(gpr), ":", RawPointer(*reinterpret_cast_ptr<void**>(scratchPointer)));
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001432 scratchPointer += sizeof(EncodedJSValue);
1433 }
1434 dataLog("\n");
1435 dataLog(" FPRs at time of exit:");
1436 for (unsigned i = 0; i < FPRInfo::numberOfRegisters; ++i) {
1437 FPRReg fpr = FPRInfo::toRegister(i);
1438 dataLog(" ", FPRInfo::debugName(fpr), ":");
commit-queue@webkit.org94ea8122013-02-25 13:13:43 +00001439 uint64_t bits = *reinterpret_cast_ptr<uint64_t*>(scratchPointer);
1440 double value = *reinterpret_cast_ptr<double*>(scratchPointer);
ossy@webkit.org71aebd72013-01-12 09:33:01 +00001441 dataLogF("%llx:%lf", static_cast<long long>(bits), value);
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001442 scratchPointer += sizeof(EncodedJSValue);
1443 }
1444 dataLog("\n");
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001445}
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001446
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00001447extern "C" void JIT_OPERATION triggerReoptimizationNow(CodeBlock* codeBlock, OSRExitBase* exit)
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001448{
fpizlo@apple.com98225492013-09-10 18:29:45 +00001449 // It's sort of preferable that we don't GC while in here. Anyways, doing so wouldn't
1450 // really be profitable.
1451 DeferGCForAWhile deferGC(codeBlock->vm()->heap);
1452
oliver@apple.com284cc3d2013-07-25 04:00:33 +00001453 if (Options::verboseOSR())
1454 dataLog(*codeBlock, ": Entered reoptimize\n");
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001455 // We must be called with the baseline code block.
oliver@apple.com5a24fdd2013-07-25 04:00:54 +00001456 ASSERT(JITCode::isBaselineCode(codeBlock->jitType()));
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001457
1458 // If I am my own replacement, then reoptimization has already been triggered.
1459 // This can happen in recursive functions.
oliver@apple.comd2a16382013-07-25 04:04:18 +00001460 if (codeBlock->replacement() == codeBlock) {
1461 if (Options::verboseOSR())
1462 dataLog(*codeBlock, ": Not reoptimizing because we've already been jettisoned.\n");
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001463 return;
oliver@apple.comd2a16382013-07-25 04:04:18 +00001464 }
1465
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001466 // Otherwise, the replacement must be optimized code. Use this as an opportunity
1467 // to check our logic.
1468 ASSERT(codeBlock->hasOptimizedReplacement());
oliver@apple.comd2a16382013-07-25 04:04:18 +00001469 CodeBlock* optimizedCodeBlock = codeBlock->replacement();
1470 ASSERT(JITCode::isOptimizingJIT(optimizedCodeBlock->jitType()));
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00001471
1472 bool didTryToEnterIntoInlinedLoops = false;
msaboff@apple.coma3dc7532015-09-24 21:42:59 +00001473 for (InlineCallFrame* inlineCallFrame = exit->m_codeOrigin.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->directCaller.inlineCallFrame) {
ggaren@apple.com81def5f2015-10-09 23:10:16 +00001474 if (inlineCallFrame->baselineCodeBlock->ownerScriptExecutable()->didTryToEnterInLoop()) {
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00001475 didTryToEnterIntoInlinedLoops = true;
1476 break;
1477 }
1478 }
oliver@apple.comd2a16382013-07-25 04:04:18 +00001479
1480 // In order to trigger reoptimization, one of two things must have happened:
1481 // 1) We exited more than some number of times.
1482 // 2) We exited and got stuck in a loop, and now we're exiting again.
1483 bool didExitABunch = optimizedCodeBlock->shouldReoptimizeNow();
1484 bool didGetStuckInLoop =
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00001485 (codeBlock->checkIfOptimizationThresholdReached() || didTryToEnterIntoInlinedLoops)
oliver@apple.comd2a16382013-07-25 04:04:18 +00001486 && optimizedCodeBlock->shouldReoptimizeFromLoopNow();
1487
1488 if (!didExitABunch && !didGetStuckInLoop) {
1489 if (Options::verboseOSR())
1490 dataLog(*codeBlock, ": Not reoptimizing ", *optimizedCodeBlock, " because it either didn't exit enough or didn't loop enough after exit.\n");
1491 codeBlock->optimizeAfterLongWarmUp();
1492 return;
1493 }
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001494
fpizlo@apple.com0dda6d72014-02-02 02:25:13 +00001495 optimizedCodeBlock->jettison(Profiler::JettisonDueToOSRExit, CountReoptimization);
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00001496}
1497
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001498#if ENABLE(FTL_JIT)
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001499static bool shouldTriggerFTLCompile(CodeBlock* codeBlock, JITCode* jitCode)
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001500{
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001501 if (codeBlock->baselineVersion()->m_didFailFTLCompilation) {
1502 if (Options::verboseOSR())
1503 dataLog("Deferring FTL-optimization of ", *codeBlock, " indefinitely because there was an FTL failure.\n");
1504 jitCode->dontOptimizeAnytimeSoon(codeBlock);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001505 return false;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001506 }
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001507
1508 if (!codeBlock->hasOptimizedReplacement()
1509 && !jitCode->checkIfOptimizationThresholdReached(codeBlock)) {
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001510 if (Options::verboseOSR())
1511 dataLog("Choosing not to FTL-optimize ", *codeBlock, " yet.\n");
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001512 return false;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001513 }
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001514 return true;
1515}
1516
1517static void triggerFTLReplacementCompile(VM* vm, CodeBlock* codeBlock, JITCode* jitCode)
1518{
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001519 Worklist::State worklistState;
msaboff@apple.com95894332014-01-29 19:18:54 +00001520 if (Worklist* worklist = existingGlobalFTLWorklistOrNull()) {
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001521 worklistState = worklist->completeAllReadyPlansForVM(
1522 *vm, CompilationKey(codeBlock->baselineVersion(), FTLMode));
1523 } else
1524 worklistState = Worklist::NotKnown;
1525
1526 if (worklistState == Worklist::Compiling) {
1527 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1528 codeBlock, CompilationDeferred);
1529 return;
1530 }
1531
1532 if (codeBlock->hasOptimizedReplacement()) {
1533 // That's great, we've compiled the code - next time we call this function,
1534 // we'll enter that replacement.
1535 jitCode->optimizeSoon(codeBlock);
1536 return;
1537 }
1538
1539 if (worklistState == Worklist::Compiled) {
1540 // This means that we finished compiling, but failed somehow; in that case the
1541 // thresholds will be set appropriately.
1542 if (Options::verboseOSR())
1543 dataLog("Code block ", *codeBlock, " was compiled but it doesn't have an optimized replacement.\n");
1544 return;
1545 }
1546
1547 // We need to compile the code.
1548 compile(
ggaren@apple.com81def5f2015-10-09 23:10:16 +00001549 *vm, codeBlock->newReplacement(), codeBlock, FTLMode, UINT_MAX,
1550 Operands<JSValue>(), ToFTLDeferredCompilationCallback::create());
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001551
1552 // If we reached here, the counter has not be reset. Do that now.
1553 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1554 codeBlock, CompilationDeferred);
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001555}
1556
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001557void JIT_OPERATION triggerTierUpNow(ExecState* exec)
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001558{
1559 VM* vm = &exec->vm();
1560 NativeCallFrameTracer tracer(vm, exec);
1561 DeferGC deferGC(vm->heap);
1562 CodeBlock* codeBlock = exec->codeBlock();
1563
fpizlo@apple.com8a5fd182015-02-02 18:38:08 +00001564 if (codeBlock->jitType() != JITCode::DFGJIT) {
1565 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
1566 RELEASE_ASSERT_NOT_REACHED();
1567 }
1568
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001569 JITCode* jitCode = codeBlock->jitCode()->dfg();
1570
1571 if (Options::verboseOSR()) {
1572 dataLog(
1573 *codeBlock, ": Entered triggerTierUpNow with executeCounter = ",
1574 jitCode->tierUpCounter, "\n");
1575 }
benjamin@webkit.org8f625992015-05-18 20:45:34 +00001576
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001577 if (shouldTriggerFTLCompile(codeBlock, jitCode))
1578 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001579
1580 if (codeBlock->hasOptimizedReplacement()) {
1581 if (jitCode->tierUpEntryTriggers.isEmpty()) {
1582 // There is nothing more we can do, the only way this will be entered
1583 // is through the function entry point.
1584 jitCode->dontOptimizeAnytimeSoon(codeBlock);
1585 return;
1586 }
1587 if (jitCode->osrEntryBlock() && jitCode->tierUpEntryTriggers.size() == 1) {
1588 // There is only one outer loop and its trigger must have been set
1589 // when the plan completed.
1590 // Exiting the inner loop is useless, we can ignore the counter and leave
1591 // the trigger do its job.
1592 jitCode->dontOptimizeAnytimeSoon(codeBlock);
1593 return;
1594 }
1595 }
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001596}
1597
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001598static char* tierUpCommon(ExecState* exec, unsigned originBytecodeIndex, unsigned osrEntryBytecodeIndex)
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001599{
1600 VM* vm = &exec->vm();
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001601 CodeBlock* codeBlock = exec->codeBlock();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001602
1603 // Resolve any pending plan for OSR Enter on this function.
1604 Worklist::State worklistState;
1605 if (Worklist* worklist = existingGlobalFTLWorklistOrNull()) {
1606 worklistState = worklist->completeAllReadyPlansForVM(
1607 *vm, CompilationKey(codeBlock->baselineVersion(), FTLForOSREntryMode));
1608 } else
1609 worklistState = Worklist::NotKnown;
1610
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001611 JITCode* jitCode = codeBlock->jitCode()->dfg();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001612 if (worklistState == Worklist::Compiling) {
1613 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1614 codeBlock, CompilationDeferred);
1615 return nullptr;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001616 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001617
1618 if (worklistState == Worklist::Compiled) {
1619 // This means that compilation failed and we already set the thresholds.
1620 if (Options::verboseOSR())
1621 dataLog("Code block ", *codeBlock, " was compiled but it doesn't have an optimized replacement.\n");
1622 return nullptr;
1623 }
1624
1625 // If we can OSR Enter, do it right away.
1626 if (originBytecodeIndex == osrEntryBytecodeIndex) {
1627 unsigned streamIndex = jitCode->bytecodeIndexToStreamIndex.get(originBytecodeIndex);
1628 if (CodeBlock* entryBlock = jitCode->osrEntryBlock()) {
1629 if (void* address = FTL::prepareOSREntry(exec, codeBlock, entryBlock, originBytecodeIndex, streamIndex))
1630 return static_cast<char*>(address);
1631 }
1632 }
1633
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001634 // - If we don't have an FTL code block, then try to compile one.
1635 // - If we do have an FTL code block, then try to enter for a while.
1636 // - If we couldn't enter for a while, then trigger OSR entry.
msaboff@apple.com95894332014-01-29 19:18:54 +00001637
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001638 if (!shouldTriggerFTLCompile(codeBlock, jitCode))
1639 return nullptr;
1640
1641 if (!jitCode->neverExecutedEntry) {
1642 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
1643
1644 if (!codeBlock->hasOptimizedReplacement())
1645 return nullptr;
fpizlo@apple.com239b0782016-03-03 05:58:59 +00001646
1647 if (jitCode->osrEntryRetry < Options::ftlOSREntryRetryThreshold()) {
1648 jitCode->osrEntryRetry++;
1649 return nullptr;
1650 }
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001651 }
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001652
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001653 // It's time to try to compile code for OSR entry.
1654 if (CodeBlock* entryBlock = jitCode->osrEntryBlock()) {
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001655 if (jitCode->osrEntryRetry < Options::ftlOSREntryRetryThreshold()) {
1656 jitCode->osrEntryRetry++;
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001657 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1658 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001659 return nullptr;
1660 }
1661
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001662 FTL::ForOSREntryJITCode* entryCode = entryBlock->jitCode()->ftlForOSREntry();
1663 entryCode->countEntryFailure();
1664 if (entryCode->entryFailureCount() <
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001665 Options::ftlOSREntryFailureCountForReoptimization()) {
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001666 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1667 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001668 return nullptr;
1669 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001670
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001671 // OSR entry failed. Oh no! This implies that we need to retry. We retry
1672 // without exponential backoff and we only do this for the entry code block.
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001673 unsigned osrEntryBytecode = entryBlock->jitCode()->ftlForOSREntry()->bytecodeIndex();
ggaren@apple.com81def5f2015-10-09 23:10:16 +00001674 jitCode->clearOSREntryBlock();
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001675 jitCode->osrEntryRetry = 0;
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001676 jitCode->tierUpEntryTriggers.set(osrEntryBytecode, 0);
1677 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1678 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001679 return nullptr;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001680 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001681
1682 unsigned streamIndex = jitCode->bytecodeIndexToStreamIndex.get(osrEntryBytecodeIndex);
1683 auto tierUpHierarchyEntry = jitCode->tierUpInLoopHierarchy.find(osrEntryBytecodeIndex);
1684 if (tierUpHierarchyEntry != jitCode->tierUpInLoopHierarchy.end()) {
1685 for (unsigned osrEntryCandidate : tierUpHierarchyEntry->value) {
1686 if (jitCode->tierUpEntrySeen.contains(osrEntryCandidate)) {
1687 osrEntryBytecodeIndex = osrEntryCandidate;
1688 streamIndex = jitCode->bytecodeIndexToStreamIndex.get(osrEntryBytecodeIndex);
1689 }
1690 }
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001691 }
1692
fpizlo@apple.com0c606702014-02-06 07:11:48 +00001693 // We aren't compiling and haven't compiled anything for OSR entry. So, try to compile
1694 // something.
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001695 auto triggerIterator = jitCode->tierUpEntryTriggers.find(osrEntryBytecodeIndex);
1696 RELEASE_ASSERT(triggerIterator != jitCode->tierUpEntryTriggers.end());
1697 uint8_t* triggerAddress = &(triggerIterator->value);
1698
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001699 Operands<JSValue> mustHandleValues;
1700 jitCode->reconstruct(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001701 exec, codeBlock, CodeOrigin(osrEntryBytecodeIndex), streamIndex, mustHandleValues);
ggaren@apple.com81def5f2015-10-09 23:10:16 +00001702 CodeBlock* replacementCodeBlock = codeBlock->newReplacement();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001703
msaboff@apple.com95894332014-01-29 19:18:54 +00001704 CompilationResult forEntryResult = compile(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001705 *vm, replacementCodeBlock, codeBlock, FTLForOSREntryMode, osrEntryBytecodeIndex,
1706 mustHandleValues, ToFTLForOSREntryDeferredCompilationCallback::create(triggerAddress));
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001707
1708 if (jitCode->neverExecutedEntry)
1709 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
1710
1711 if (forEntryResult != CompilationSuccessful) {
1712 jitCode->setOptimizationThresholdBasedOnCompilationResult(
1713 codeBlock, CompilationDeferred);
1714 return nullptr;
1715 }
mark.lam@apple.comaebf6852014-03-03 21:39:21 +00001716
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001717 // It's possible that the for-entry compile already succeeded. In that case OSR
1718 // entry will succeed unless we ran out of stack. It's not clear what we should do.
1719 // We signal to try again after a while if that happens.
1720 void* address = FTL::prepareOSREntry(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001721 exec, codeBlock, jitCode->osrEntryBlock(), originBytecodeIndex, streamIndex);
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001722 return static_cast<char*>(address);
1723}
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00001724
benjamin@webkit.org31527f52016-03-09 17:51:38 +00001725void JIT_OPERATION triggerTierUpNowInLoop(ExecState* exec, unsigned bytecodeIndex)
1726{
1727 VM* vm = &exec->vm();
1728 NativeCallFrameTracer tracer(vm, exec);
1729 DeferGC deferGC(vm->heap);
1730 CodeBlock* codeBlock = exec->codeBlock();
1731
1732 if (codeBlock->jitType() != JITCode::DFGJIT) {
1733 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
1734 RELEASE_ASSERT_NOT_REACHED();
1735 }
1736
1737 JITCode* jitCode = codeBlock->jitCode()->dfg();
1738
1739 if (Options::verboseOSR()) {
1740 dataLog(
1741 *codeBlock, ": Entered triggerTierUpNowInLoop with executeCounter = ",
1742 jitCode->tierUpCounter, "\n");
1743 }
1744
1745 auto tierUpHierarchyEntry = jitCode->tierUpInLoopHierarchy.find(bytecodeIndex);
1746 if (tierUpHierarchyEntry != jitCode->tierUpInLoopHierarchy.end()
1747 && !tierUpHierarchyEntry->value.isEmpty()) {
1748 tierUpCommon(exec, bytecodeIndex, tierUpHierarchyEntry->value.first());
1749 } else if (shouldTriggerFTLCompile(codeBlock, jitCode))
1750 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
1751
1752 // Since we cannot OSR Enter here, the default "optimizeSoon()" is not useful.
1753 if (codeBlock->hasOptimizedReplacement())
1754 jitCode->setOptimizationThresholdBasedOnCompilationResult(codeBlock, CompilationDeferred);
1755}
1756
1757char* JIT_OPERATION triggerOSREntryNow(ExecState* exec, unsigned bytecodeIndex)
1758{
1759 VM* vm = &exec->vm();
1760 NativeCallFrameTracer tracer(vm, exec);
1761 DeferGC deferGC(vm->heap);
1762 CodeBlock* codeBlock = exec->codeBlock();
1763
1764 if (codeBlock->jitType() != JITCode::DFGJIT) {
1765 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
1766 RELEASE_ASSERT_NOT_REACHED();
1767 }
1768
1769 JITCode* jitCode = codeBlock->jitCode()->dfg();
1770 jitCode->tierUpEntrySeen.add(bytecodeIndex);
1771
1772 if (Options::verboseOSR()) {
1773 dataLog(
1774 *codeBlock, ": Entered triggerOSREntryNow with executeCounter = ",
1775 jitCode->tierUpCounter, "\n");
1776 }
1777
1778 return tierUpCommon(exec, bytecodeIndex, bytecodeIndex);
1779}
1780
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00001781#endif // ENABLE(FTL_JIT)
1782
barraclough@apple.comc7af2d32011-05-26 21:37:05 +00001783} // extern "C"
fpizlo@apple.com04659ba2012-02-21 09:49:22 +00001784} } // namespace JSC::DFG
1785
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +00001786#endif // ENABLE(DFG_JIT)
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +00001787
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +00001788#endif // ENABLE(JIT)