blob: 3aed72ccab60c43ec1c44f5970943678a55ddc7b [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
keith_miller@apple.com5bed6f62016-06-16 06:01:47 +000029#include "ArrayConstructor.h"
mark.lam@apple.coma4fe7ab2012-11-09 03:03:44 +000030#include "ButterflyInlines.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000031#include "ClonedArguments.h"
barraclough@apple.com2302c042011-03-14 23:31:00 +000032#include "CodeBlock.h"
oliver@apple.comb3e5acb2013-07-25 04:02:53 +000033#include "CommonSlowPaths.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"
utatane.tea@gmail.comf7db5592016-10-04 19:31:24 +000041#include "DefinePropertyAttributes.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000042#include "DirectArguments.h"
fpizlo@apple.com532f1e52013-09-04 06:26:04 +000043#include "FTLForOSREntryJITCode.h"
44#include "FTLOSREntry.h"
sbarati@apple.coma3db4652016-09-20 01:05:50 +000045#include "HasOwnPropertyCache.h"
utatane.tea@gmail.comc2585192016-08-25 22:55:10 +000046#include "HostCallReturnValue.h"
barraclough@apple.com2302c042011-03-14 23:31:00 +000047#include "Interpreter.h"
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +000048#include "JIT.h"
oliver@apple.comc55314a2012-05-30 19:45:20 +000049#include "JITExceptions.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000050#include "JSCInlines.h"
keith_miller@apple.com1ec869c2016-06-21 17:54:33 +000051#include "JSGenericTypedArrayViewConstructorInlines.h"
oliver@apple.coma7dfb4d2014-09-11 18:18:14 +000052#include "JSLexicalEnvironment.h"
sbarati@apple.com21fc86e2016-09-06 23:22:01 +000053#include "JSMap.h"
54#include "JSSet.h"
ggaren@apple.comc862eac2013-01-29 05:48:01 +000055#include "ObjectConstructor.h"
mark.lam@apple.com581437a2016-09-22 23:41:56 +000056#include "Operations.h"
joepeck@webkit.org7e07f392016-09-22 18:59:47 +000057#include "RegExpObject.h"
mark.lam@apple.com9df8b832013-09-26 20:27:14 +000058#include "Repatch.h"
fpizlo@apple.comda834ae2015-03-26 04:28:43 +000059#include "ScopedArguments.h"
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +000060#include "StringConstructor.h"
fpizlo@apple.com5e29b762016-03-18 00:53:24 +000061#include "SuperSampler.h"
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000062#include "Symbol.h"
saambarati1@gmail.comdaf10202014-10-01 20:47:51 +000063#include "TypeProfilerLog.h"
fpizlo@apple.com372fa822013-08-21 19:43:47 +000064#include "TypedArrayInlines.h"
fpizlo@apple.com4a528d02016-05-11 00:08:50 +000065#include "VMInlines.h"
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +000066#include <wtf/InlineASM.h>
barraclough@apple.com2302c042011-03-14 23:31:00 +000067
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +000068#if ENABLE(JIT)
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +000069#if ENABLE(DFG_JIT)
70
barraclough@apple.com2302c042011-03-14 23:31:00 +000071namespace JSC { namespace DFG {
72
oliver@apple.come050d642013-10-19 00:09:28 +000073template<bool strict, bool direct>
weinig@apple.coma96509f2011-06-15 21:57:17 +000074static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value)
barraclough@apple.comc7af2d32011-05-26 21:37:05 +000075{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000076 VM& vm = exec->vm();
77 NativeCallFrameTracer tracer(&vm, exec);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +000078 ASSERT(isIndex(index));
oliver@apple.come050d642013-10-19 00:09:28 +000079 if (direct) {
80 RELEASE_ASSERT(baseValue.isObject());
81 asObject(baseValue)->putDirectIndex(exec, index, value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
82 return;
83 }
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +000084 if (baseValue.isObject()) {
85 JSObject* object = asObject(baseValue);
86 if (object->canSetIndexQuickly(index)) {
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000087 object->setIndexQuickly(vm, index, value);
weinig@apple.coma96509f2011-06-15 21:57:17 +000088 return;
89 }
90
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +000091 object->methodTable(vm)->putByIndex(object, exec, index, value, strict);
weinig@apple.coma96509f2011-06-15 21:57:17 +000092 return;
93 }
94
barraclough@apple.coma4d51f22012-03-06 01:18:42 +000095 baseValue.putByIndex(exec, index, value, strict);
weinig@apple.coma96509f2011-06-15 21:57:17 +000096}
97
oliver@apple.come050d642013-10-19 00:09:28 +000098template<bool strict, bool direct>
mark.lam@apple.com9df8b832013-09-26 20:27:14 +000099ALWAYS_INLINE static void JIT_OPERATION operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
weinig@apple.coma96509f2011-06-15 21:57:17 +0000100{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000101 VM* vm = &exec->vm();
mark.lam@apple.com451de992016-09-07 22:10:50 +0000102 auto scope = DECLARE_THROW_SCOPE(*vm);
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000103 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000104
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000105 JSValue baseValue = JSValue::decode(encodedBase);
106 JSValue property = JSValue::decode(encodedProperty);
107 JSValue value = JSValue::decode(encodedValue);
108
109 if (LIKELY(property.isUInt32())) {
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000110 // Despite its name, JSValue::isUInt32 will return true only for positive boxed int32_t; all those values are valid array indices.
111 ASSERT(isIndex(property.asUInt32()));
commit-queue@webkit.orge3549c62015-01-22 19:34:34 +0000112 putByVal<strict, direct>(exec, baseValue, property.asUInt32(), value);
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000113 return;
114 }
115
weinig@apple.coma96509f2011-06-15 21:57:17 +0000116 if (property.isDouble()) {
117 double propertyAsDouble = property.asDouble();
118 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000119 if (propertyAsDouble == propertyAsUInt32 && isIndex(propertyAsUInt32)) {
oliver@apple.come050d642013-10-19 00:09:28 +0000120 putByVal<strict, direct>(exec, baseValue, propertyAsUInt32, value);
weinig@apple.coma96509f2011-06-15 21:57:17 +0000121 return;
122 }
123 }
124
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000125 // Don't put to an object if toString throws an exception.
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000126 auto propertyName = property.toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000127 RETURN_IF_EXCEPTION(scope, void());
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000128
129 PutPropertySlot slot(baseValue, strict);
130 if (direct) {
131 RELEASE_ASSERT(baseValue.isObject());
132 if (Optional<uint32_t> index = parseIndex(propertyName))
133 asObject(baseValue)->putDirectIndex(exec, index.value(), value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
134 else
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000135 asObject(baseValue)->putDirect(*vm, propertyName, value, slot);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000136 } else
137 baseValue.put(exec, propertyName, value, slot);
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000138}
139
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000140template<typename ViewClass>
fpizlo@apple.com30a72582016-09-08 16:47:34 +0000141char* newTypedArrayWithSize(ExecState* exec, Structure* structure, int32_t size, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000142{
143 VM& vm = exec->vm();
144 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000145 auto scope = DECLARE_THROW_SCOPE(vm);
146
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000147 if (size < 0) {
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000148 throwException(exec, scope, createRangeError(exec, ASCIILiteral("Requested length is negative")));
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000149 return 0;
150 }
fpizlo@apple.com30a72582016-09-08 16:47:34 +0000151
152 if (vector)
153 return bitwise_cast<char*>(ViewClass::createWithFastVector(exec, structure, size, vector));
154
fpizlo@apple.com372fa822013-08-21 19:43:47 +0000155 return bitwise_cast<char*>(ViewClass::create(exec, structure, size));
156}
157
sbarati@apple.com23315d62016-05-09 20:17:23 +0000158template <bool strict>
159static ALWAYS_INLINE void putWithThis(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedValue, const Identifier& ident)
160{
161 JSValue baseValue = JSValue::decode(encodedBase);
162 JSValue thisVal = JSValue::decode(encodedThis);
163 JSValue putValue = JSValue::decode(encodedValue);
164 PutPropertySlot slot(thisVal, strict);
165 baseValue.putInline(exec, ident, putValue, slot);
166}
167
barraclough@apple.comc7af2d32011-05-26 21:37:05 +0000168extern "C" {
169
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000170EncodedJSValue JIT_OPERATION operationToThis(ExecState* exec, EncodedJSValue encodedOp)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000171{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000172 VM* vm = &exec->vm();
173 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000174
fpizlo@apple.com018818d2013-09-13 23:18:19 +0000175 return JSValue::encode(JSValue::decode(encodedOp).toThis(exec, NotStrictMode));
176}
177
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000178EncodedJSValue JIT_OPERATION operationToThisStrict(ExecState* exec, EncodedJSValue encodedOp)
fpizlo@apple.com018818d2013-09-13 23:18:19 +0000179{
180 VM* vm = &exec->vm();
181 NativeCallFrameTracer tracer(vm, exec);
182
183 return JSValue::encode(JSValue::decode(encodedOp).toThis(exec, StrictMode));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000184}
185
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000186JSCell* JIT_OPERATION operationCreateThis(ExecState* exec, JSObject* constructor, int32_t inlineCapacity)
fpizlo@apple.combb159ec2011-09-21 22:17:06 +0000187{
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000188 VM& vm = exec->vm();
189 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000190 auto scope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.come5315aa2016-02-20 23:51:33 +0000191 if (constructor->type() == JSFunctionType)
192 return constructEmptyObject(exec, jsCast<JSFunction*>(constructor)->rareData(exec, inlineCapacity)->objectAllocationProfile()->structure());
barraclough@apple.comcef11dc2012-05-10 18:40:29 +0000193
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000194 JSValue proto = constructor->get(exec, exec->propertyNames().prototype);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000195 RETURN_IF_EXCEPTION(scope, nullptr);
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000196 if (proto.isObject())
197 return constructEmptyObject(exec, asObject(proto));
sbarati@apple.come5315aa2016-02-20 23:51:33 +0000198 return constructEmptyObject(exec);
fpizlo@apple.com133c9ac2011-11-08 00:37:33 +0000199}
200
keith_miller@apple.com5bed6f62016-06-16 06:01:47 +0000201JSCell* JIT_OPERATION operationObjectConstructor(ExecState* exec, JSGlobalObject* globalObject, EncodedJSValue encodedTarget)
202{
203 VM* vm = &exec->vm();
204 NativeCallFrameTracer tracer(vm, exec);
205
206 JSValue value = JSValue::decode(encodedTarget);
207 ASSERT(!value.isObject());
208
209 if (value.isUndefinedOrNull())
210 return constructEmptyObject(exec, globalObject->objectPrototype());
211 return value.toObject(exec, globalObject);
212}
213
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000214EncodedJSValue JIT_OPERATION operationValueBitAnd(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
215{
216 VM* vm = &exec->vm();
217 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000218 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000219
220 JSValue op1 = JSValue::decode(encodedOp1);
221 JSValue op2 = JSValue::decode(encodedOp2);
222
223 int32_t a = op1.toInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000224 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000225 int32_t b = op2.toInt32(exec);
226 return JSValue::encode(jsNumber(a & b));
227}
228
229EncodedJSValue JIT_OPERATION operationValueBitOr(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
230{
231 VM* vm = &exec->vm();
232 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000233 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000234
235 JSValue op1 = JSValue::decode(encodedOp1);
236 JSValue op2 = JSValue::decode(encodedOp2);
237
238 int32_t a = op1.toInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000239 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000240 int32_t b = op2.toInt32(exec);
241 return JSValue::encode(jsNumber(a | b));
242}
243
244EncodedJSValue JIT_OPERATION operationValueBitXor(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
245{
246 VM* vm = &exec->vm();
247 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000248 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000249
250 JSValue op1 = JSValue::decode(encodedOp1);
251 JSValue op2 = JSValue::decode(encodedOp2);
252
253 int32_t a = op1.toInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000254 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000255 int32_t b = op2.toInt32(exec);
256 return JSValue::encode(jsNumber(a ^ b));
257}
258
259EncodedJSValue JIT_OPERATION operationValueBitLShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
260{
261 VM* vm = &exec->vm();
262 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000263 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000264
265 JSValue op1 = JSValue::decode(encodedOp1);
266 JSValue op2 = JSValue::decode(encodedOp2);
267
268 int32_t a = op1.toInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000269 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000270 uint32_t b = op2.toUInt32(exec);
271 return JSValue::encode(jsNumber(a << (b & 0x1f)));
272}
273
274EncodedJSValue JIT_OPERATION operationValueBitRShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
275{
276 VM* vm = &exec->vm();
277 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000278 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000279
280 JSValue op1 = JSValue::decode(encodedOp1);
281 JSValue op2 = JSValue::decode(encodedOp2);
282
283 int32_t a = op1.toInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000284 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000285 uint32_t b = op2.toUInt32(exec);
286 return JSValue::encode(jsNumber(a >> (b & 0x1f)));
287}
288
289EncodedJSValue JIT_OPERATION operationValueBitURShift(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
290{
291 VM* vm = &exec->vm();
292 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000293 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000294
295 JSValue op1 = JSValue::decode(encodedOp1);
296 JSValue op2 = JSValue::decode(encodedOp2);
297
298 uint32_t a = op1.toUInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000299 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.comc0008652015-12-15 21:19:31 +0000300 uint32_t b = op2.toUInt32(exec);
301 return JSValue::encode(jsNumber(static_cast<int32_t>(a >> (b & 0x1f))));
302}
303
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000304EncodedJSValue JIT_OPERATION operationValueAddNotNumber(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000305{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000306 VM* vm = &exec->vm();
307 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000308
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000309 JSValue op1 = JSValue::decode(encodedOp1);
310 JSValue op2 = JSValue::decode(encodedOp2);
311
fpizlo@apple.com5df0cd82011-08-19 00:18:49 +0000312 ASSERT(!op1.isNumber() || !op2.isNumber());
fpizlo@apple.com5c907042011-09-15 01:24:39 +0000313
ggaren@apple.com64be5e92012-01-24 07:34:10 +0000314 if (op1.isString() && !op2.isObject())
315 return JSValue::encode(jsString(exec, asString(op1), op2.toString(exec)));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000316
317 return JSValue::encode(jsAddSlowCase(exec, op1, op2));
318}
319
mark.lam@apple.com224ce4d2015-12-08 21:44:12 +0000320EncodedJSValue JIT_OPERATION operationValueDiv(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
321{
322 VM* vm = &exec->vm();
323 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000324 auto scope = DECLARE_THROW_SCOPE(*vm);
mark.lam@apple.com224ce4d2015-12-08 21:44:12 +0000325
326 JSValue op1 = JSValue::decode(encodedOp1);
327 JSValue op2 = JSValue::decode(encodedOp2);
328
329 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000330 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.com224ce4d2015-12-08 21:44:12 +0000331 double b = op2.toNumber(exec);
332 return JSValue::encode(jsNumber(a / b));
333}
334
commit-queue@webkit.org0ec71072016-08-29 07:21:04 +0000335double JIT_OPERATION operationArithAbs(ExecState* exec, EncodedJSValue encodedOp1)
336{
337 VM* vm = &exec->vm();
338 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000339 auto scope = DECLARE_THROW_SCOPE(*vm);
commit-queue@webkit.org0ec71072016-08-29 07:21:04 +0000340
341 JSValue op1 = JSValue::decode(encodedOp1);
342 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000343 RETURN_IF_EXCEPTION(scope, PNaN);
commit-queue@webkit.org0ec71072016-08-29 07:21:04 +0000344 return fabs(a);
345}
346
commit-queue@webkit.org95f28be2016-09-06 21:54:11 +0000347int32_t JIT_OPERATION operationArithClz32(ExecState* exec, EncodedJSValue encodedOp1)
348{
349 VM* vm = &exec->vm();
350 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000351 auto scope = DECLARE_THROW_SCOPE(*vm);
commit-queue@webkit.org95f28be2016-09-06 21:54:11 +0000352
353 JSValue op1 = JSValue::decode(encodedOp1);
354 uint32_t value = op1.toUInt32(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000355 RETURN_IF_EXCEPTION(scope, 0);
commit-queue@webkit.org95f28be2016-09-06 21:54:11 +0000356 return clz32(value);
357}
358
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000359double JIT_OPERATION operationArithCos(ExecState* exec, EncodedJSValue encodedOp1)
360{
361 VM* vm = &exec->vm();
362 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000363 auto scope = DECLARE_THROW_SCOPE(*vm);
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000364
365 JSValue op1 = JSValue::decode(encodedOp1);
366 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000367 RETURN_IF_EXCEPTION(scope, encodedJSValue());
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000368 return cos(a);
369}
370
benjamin@webkit.org87238e92016-08-25 01:21:43 +0000371double JIT_OPERATION operationArithFRound(ExecState* exec, EncodedJSValue encodedOp1)
372{
373 VM* vm = &exec->vm();
374 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000375 auto scope = DECLARE_THROW_SCOPE(*vm);
benjamin@webkit.org87238e92016-08-25 01:21:43 +0000376
377 JSValue op1 = JSValue::decode(encodedOp1);
378 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000379 RETURN_IF_EXCEPTION(scope, PNaN);
benjamin@webkit.org87238e92016-08-25 01:21:43 +0000380 return static_cast<float>(a);
381}
382
benjamin@webkit.org770c27f2016-08-24 02:36:40 +0000383double JIT_OPERATION operationArithLog(ExecState* exec, EncodedJSValue encodedOp1)
384{
385 VM* vm = &exec->vm();
386 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000387 auto scope = DECLARE_THROW_SCOPE(*vm);
benjamin@webkit.org770c27f2016-08-24 02:36:40 +0000388
389 JSValue op1 = JSValue::decode(encodedOp1);
390 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000391 RETURN_IF_EXCEPTION(scope, PNaN);
benjamin@webkit.org770c27f2016-08-24 02:36:40 +0000392 return log(a);
393}
394
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000395double JIT_OPERATION operationArithSin(ExecState* exec, EncodedJSValue encodedOp1)
396{
397 VM* vm = &exec->vm();
398 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000399 auto scope = DECLARE_THROW_SCOPE(*vm);
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000400
401 JSValue op1 = JSValue::decode(encodedOp1);
402 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000403 RETURN_IF_EXCEPTION(scope, PNaN);
commit-queue@webkit.orgee8d5482016-08-23 19:09:50 +0000404 return sin(a);
405}
406
commit-queue@webkit.org91b902c2016-08-20 02:00:44 +0000407double JIT_OPERATION operationArithSqrt(ExecState* exec, EncodedJSValue encodedOp1)
408{
409 VM* vm = &exec->vm();
410 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000411 auto scope = DECLARE_THROW_SCOPE(*vm);
commit-queue@webkit.org91b902c2016-08-20 02:00:44 +0000412
413 JSValue op1 = JSValue::decode(encodedOp1);
414 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000415 RETURN_IF_EXCEPTION(scope, PNaN);
commit-queue@webkit.org91b902c2016-08-20 02:00:44 +0000416 return sqrt(a);
417}
418
utatane.tea@gmail.com9917d6a2016-09-12 22:01:13 +0000419double JIT_OPERATION operationArithTan(ExecState* exec, EncodedJSValue encodedOp1)
420{
421 VM* vm = &exec->vm();
422 NativeCallFrameTracer tracer(vm, exec);
423 auto scope = DECLARE_THROW_SCOPE(*vm);
424
425 JSValue op1 = JSValue::decode(encodedOp1);
426 double a = op1.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000427 RETURN_IF_EXCEPTION(scope, encodedJSValue());
utatane.tea@gmail.com9917d6a2016-09-12 22:01:13 +0000428 return tan(a);
429}
430
commit-queue@webkit.org2e9df642016-09-20 00:48:39 +0000431EncodedJSValue JIT_OPERATION operationArithRound(ExecState* exec, EncodedJSValue encodedArgument)
432{
433 VM* vm = &exec->vm();
434 NativeCallFrameTracer tracer(vm, exec);
435 auto scope = DECLARE_THROW_SCOPE(*vm);
436
437 JSValue argument = JSValue::decode(encodedArgument);
438 double valueOfArgument = argument.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000439 RETURN_IF_EXCEPTION(scope, encodedJSValue());
commit-queue@webkit.org2e9df642016-09-20 00:48:39 +0000440 return JSValue::encode(jsNumber(jsRound(valueOfArgument)));
441}
442
443EncodedJSValue JIT_OPERATION operationArithFloor(ExecState* exec, EncodedJSValue encodedArgument)
444{
445 VM* vm = &exec->vm();
446 NativeCallFrameTracer tracer(vm, exec);
447 auto scope = DECLARE_THROW_SCOPE(*vm);
448
449 JSValue argument = JSValue::decode(encodedArgument);
450 double valueOfArgument = argument.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000451 RETURN_IF_EXCEPTION(scope, encodedJSValue());
commit-queue@webkit.org2e9df642016-09-20 00:48:39 +0000452 return JSValue::encode(jsNumber(floor(valueOfArgument)));
453}
454
455EncodedJSValue JIT_OPERATION operationArithCeil(ExecState* exec, EncodedJSValue encodedArgument)
456{
457 VM* vm = &exec->vm();
458 NativeCallFrameTracer tracer(vm, exec);
459 auto scope = DECLARE_THROW_SCOPE(*vm);
460
461 JSValue argument = JSValue::decode(encodedArgument);
462 double valueOfArgument = argument.toNumber(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000463 RETURN_IF_EXCEPTION(scope, encodedJSValue());
commit-queue@webkit.org2e9df642016-09-20 00:48:39 +0000464 return JSValue::encode(jsNumber(ceil(valueOfArgument)));
465}
466
467EncodedJSValue JIT_OPERATION operationArithTrunc(ExecState* exec, EncodedJSValue encodedArgument)
468{
469 VM* vm = &exec->vm();
470 NativeCallFrameTracer tracer(vm, exec);
471 auto scope = DECLARE_THROW_SCOPE(*vm);
472
473 JSValue argument = JSValue::decode(encodedArgument);
474 double truncatedValueOfArgument = argument.toIntegerPreserveNaN(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000475 RETURN_IF_EXCEPTION(scope, encodedJSValue());
commit-queue@webkit.org2e9df642016-09-20 00:48:39 +0000476 return JSValue::encode(jsNumber(truncatedValueOfArgument));
477}
478
akling@apple.com6d3d1812014-04-26 06:00:43 +0000479static ALWAYS_INLINE EncodedJSValue getByVal(ExecState* exec, JSCell* base, uint32_t index)
weinig@apple.coma96509f2011-06-15 21:57:17 +0000480{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000481 VM& vm = exec->vm();
482 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000483
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000484 if (base->isObject()) {
485 JSObject* object = asObject(base);
486 if (object->canGetIndexQuickly(index))
487 return JSValue::encode(object->getIndexQuickly(index));
488 }
weinig@apple.coma96509f2011-06-15 21:57:17 +0000489
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000490 if (isJSString(base) && asString(base)->canGetIndex(index))
weinig@apple.coma96509f2011-06-15 21:57:17 +0000491 return JSValue::encode(asString(base)->getIndex(exec, index));
492
weinig@apple.coma96509f2011-06-15 21:57:17 +0000493 return JSValue::encode(JSValue(base).get(exec, index));
494}
495
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000496EncodedJSValue JIT_OPERATION operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000497{
akling@apple.comb6d91ab2014-02-09 21:33:17 +0000498 VM& vm = exec->vm();
499 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000500 auto scope = DECLARE_THROW_SCOPE(vm);
501
barraclough@apple.com2302c042011-03-14 23:31:00 +0000502 JSValue baseValue = JSValue::decode(encodedBase);
503 JSValue property = JSValue::decode(encodedProperty);
504
505 if (LIKELY(baseValue.isCell())) {
506 JSCell* base = baseValue.asCell();
507
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000508 if (property.isUInt32()) {
weinig@apple.coma96509f2011-06-15 21:57:17 +0000509 return getByVal(exec, base, property.asUInt32());
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000510 } else if (property.isDouble()) {
weinig@apple.coma96509f2011-06-15 21:57:17 +0000511 double propertyAsDouble = property.asDouble();
512 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
utatane.tea@gmail.com20b6e302015-04-07 07:26:08 +0000513 if (propertyAsUInt32 == propertyAsDouble && isIndex(propertyAsUInt32))
weinig@apple.coma96509f2011-06-15 21:57:17 +0000514 return getByVal(exec, base, propertyAsUInt32);
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000515 } else if (property.isString()) {
akling@apple.combaca5e82014-05-06 00:53:29 +0000516 Structure& structure = *base->structure(vm);
517 if (JSCell::canUseFastGetOwnProperty(structure)) {
utatane.tea@gmail.come0741fb2015-06-02 17:36:16 +0000518 if (RefPtr<AtomicStringImpl> existingAtomicString = asString(property)->toExistingAtomicString(exec)) {
519 if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString.get()))
akling@apple.comcad89042014-09-02 22:29:59 +0000520 return JSValue::encode(result);
521 }
akling@apple.combaca5e82014-05-06 00:53:29 +0000522 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000523 }
barraclough@apple.com2302c042011-03-14 23:31:00 +0000524 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000525
utatane.tea@gmail.com9f61d132015-03-27 11:08:49 +0000526 baseValue.requireObjectCoercible(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000527 RETURN_IF_EXCEPTION(scope, encodedJSValue());
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000528 auto propertyName = property.toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000529 RETURN_IF_EXCEPTION(scope, encodedJSValue());
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000530 return JSValue::encode(baseValue.get(exec, propertyName));
barraclough@apple.com2302c042011-03-14 23:31:00 +0000531}
532
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000533EncodedJSValue JIT_OPERATION operationGetByValCell(ExecState* exec, JSCell* base, EncodedJSValue encodedProperty)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000534{
akling@apple.comb6d91ab2014-02-09 21:33:17 +0000535 VM& vm = exec->vm();
536 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000537 auto scope = DECLARE_THROW_SCOPE(vm);
538
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000539 JSValue property = JSValue::decode(encodedProperty);
540
541 if (property.isUInt32())
542 return getByVal(exec, base, property.asUInt32());
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000543 if (property.isDouble()) {
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000544 double propertyAsDouble = property.asDouble();
545 uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
546 if (propertyAsUInt32 == propertyAsDouble)
547 return getByVal(exec, base, propertyAsUInt32);
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000548 } else if (property.isString()) {
akling@apple.combaca5e82014-05-06 00:53:29 +0000549 Structure& structure = *base->structure(vm);
550 if (JSCell::canUseFastGetOwnProperty(structure)) {
utatane.tea@gmail.come0741fb2015-06-02 17:36:16 +0000551 if (RefPtr<AtomicStringImpl> existingAtomicString = asString(property)->toExistingAtomicString(exec)) {
552 if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString.get()))
akling@apple.comcad89042014-09-02 22:29:59 +0000553 return JSValue::encode(result);
554 }
akling@apple.combaca5e82014-05-06 00:53:29 +0000555 }
mhahnenberg@apple.com871ffe62013-03-15 21:52:35 +0000556 }
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000557
utatane.tea@gmail.come16e15d2015-03-20 21:35:17 +0000558 auto propertyName = property.toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000559 RETURN_IF_EXCEPTION(scope, encodedJSValue());
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000560 return JSValue::encode(JSValue(base).get(exec, propertyName));
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000561}
562
oliver@apple.com211b3be2013-07-25 04:03:39 +0000563ALWAYS_INLINE EncodedJSValue getByValCellInt(ExecState* exec, JSCell* base, int32_t index)
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000564{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000565 VM* vm = &exec->vm();
566 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000567
568 if (index < 0) {
569 // Go the slowest way possible becase negative indices don't use indexed storage.
570 return JSValue::encode(JSValue(base).get(exec, Identifier::from(exec, index)));
571 }
572
573 // Use this since we know that the value is out of bounds.
sbarati@apple.com575aa2b2016-03-04 02:25:30 +0000574 return JSValue::encode(JSValue(base).get(exec, static_cast<unsigned>(index)));
fpizlo@apple.comfa34ff82012-09-05 01:27:50 +0000575}
576
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000577EncodedJSValue JIT_OPERATION operationGetByValArrayInt(ExecState* exec, JSArray* base, int32_t index)
oliver@apple.com211b3be2013-07-25 04:03:39 +0000578{
579 return getByValCellInt(exec, base, index);
580}
581
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000582EncodedJSValue JIT_OPERATION operationGetByValStringInt(ExecState* exec, JSString* base, int32_t index)
oliver@apple.com211b3be2013-07-25 04:03:39 +0000583{
584 return getByValCellInt(exec, base, index);
585}
586
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000587void JIT_OPERATION operationPutByValStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000588{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000589 VM* vm = &exec->vm();
590 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000591
oliver@apple.come050d642013-10-19 00:09:28 +0000592 operationPutByValInternal<true, false>(exec, encodedBase, encodedProperty, encodedValue);
barraclough@apple.com2302c042011-03-14 23:31:00 +0000593}
594
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000595void JIT_OPERATION operationPutByValNonStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
barraclough@apple.com2302c042011-03-14 23:31:00 +0000596{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000597 VM* vm = &exec->vm();
598 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000599
oliver@apple.come050d642013-10-19 00:09:28 +0000600 operationPutByValInternal<false, false>(exec, encodedBase, encodedProperty, encodedValue);
barraclough@apple.com2302c042011-03-14 23:31:00 +0000601}
602
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000603void JIT_OPERATION operationPutByValCellStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000604{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000605 VM* vm = &exec->vm();
606 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000607
oliver@apple.come050d642013-10-19 00:09:28 +0000608 operationPutByValInternal<true, false>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000609}
610
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000611void JIT_OPERATION operationPutByValCellNonStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000612{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000613 VM* vm = &exec->vm();
614 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000615
oliver@apple.come050d642013-10-19 00:09:28 +0000616 operationPutByValInternal<false, false>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
fpizlo@apple.comdc41f7f2011-10-09 20:07:36 +0000617}
618
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000619void JIT_OPERATION operationPutByValBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
barraclough@apple.come2130ff2011-06-07 23:03:32 +0000620{
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000621 VM& vm = exec->vm();
622 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000623
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000624 if (index >= 0) {
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000625 array->putByIndexInline(exec, index, JSValue::decode(encodedValue), true);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000626 return;
627 }
628
oliver@apple.com68848412014-01-02 20:56:20 +0000629 PutPropertySlot slot(array, true);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000630 array->methodTable()->put(
631 array, exec, Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000632}
633
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000634void JIT_OPERATION operationPutByValBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000635{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000636 VM* vm = &exec->vm();
637 NativeCallFrameTracer tracer(vm, exec);
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000638
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000639 if (index >= 0) {
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000640 array->putByIndexInline(exec, index, JSValue::decode(encodedValue), false);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000641 return;
642 }
643
oliver@apple.com68848412014-01-02 20:56:20 +0000644 PutPropertySlot slot(array, false);
fpizlo@apple.com73fbdf62012-05-18 01:34:01 +0000645 array->methodTable()->put(
646 array, exec, Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
barraclough@apple.come2130ff2011-06-07 23:03:32 +0000647}
648
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000649void JIT_OPERATION operationPutDoubleByValBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, double value)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000650{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000651 VM* vm = &exec->vm();
652 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000653
654 JSValue jsValue = JSValue(JSValue::EncodeAsDouble, value);
655
656 if (index >= 0) {
657 array->putByIndexInline(exec, index, jsValue, true);
658 return;
659 }
660
oliver@apple.com68848412014-01-02 20:56:20 +0000661 PutPropertySlot slot(array, true);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000662 array->methodTable()->put(
663 array, exec, Identifier::from(exec, index), jsValue, slot);
664}
665
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000666void JIT_OPERATION operationPutDoubleByValBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, double value)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000667{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000668 VM* vm = &exec->vm();
669 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000670
671 JSValue jsValue = JSValue(JSValue::EncodeAsDouble, value);
672
673 if (index >= 0) {
674 array->putByIndexInline(exec, index, jsValue, false);
675 return;
676 }
677
oliver@apple.com68848412014-01-02 20:56:20 +0000678 PutPropertySlot slot(array, false);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000679 array->methodTable()->put(
680 array, exec, Identifier::from(exec, index), jsValue, slot);
681}
682
oliver@apple.come050d642013-10-19 00:09:28 +0000683void JIT_OPERATION operationPutByValDirectStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
684{
685 VM* vm = &exec->vm();
686 NativeCallFrameTracer tracer(vm, exec);
687
688 operationPutByValInternal<true, true>(exec, encodedBase, encodedProperty, encodedValue);
689}
690
691void JIT_OPERATION operationPutByValDirectNonStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
692{
693 VM* vm = &exec->vm();
694 NativeCallFrameTracer tracer(vm, exec);
695
696 operationPutByValInternal<false, true>(exec, encodedBase, encodedProperty, encodedValue);
697}
698
699void JIT_OPERATION operationPutByValDirectCellStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
700{
701 VM* vm = &exec->vm();
702 NativeCallFrameTracer tracer(vm, exec);
703
704 operationPutByValInternal<true, true>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
705}
706
707void JIT_OPERATION operationPutByValDirectCellNonStrict(ExecState* exec, JSCell* cell, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
708{
709 VM* vm = &exec->vm();
710 NativeCallFrameTracer tracer(vm, exec);
711
712 operationPutByValInternal<false, true>(exec, JSValue::encode(cell), encodedProperty, encodedValue);
713}
714
715void JIT_OPERATION operationPutByValDirectBeyondArrayBoundsStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
716{
717 VM* vm = &exec->vm();
718 NativeCallFrameTracer tracer(vm, exec);
719 if (index >= 0) {
720 array->putDirectIndex(exec, index, JSValue::decode(encodedValue), 0, PutDirectIndexShouldThrow);
721 return;
722 }
723
oliver@apple.com68848412014-01-02 20:56:20 +0000724 PutPropertySlot slot(array, true);
oliver@apple.come050d642013-10-19 00:09:28 +0000725 array->putDirect(exec->vm(), Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
726}
727
728void JIT_OPERATION operationPutByValDirectBeyondArrayBoundsNonStrict(ExecState* exec, JSObject* array, int32_t index, EncodedJSValue encodedValue)
729{
730 VM* vm = &exec->vm();
731 NativeCallFrameTracer tracer(vm, exec);
732
733 if (index >= 0) {
734 array->putDirectIndex(exec, index, JSValue::decode(encodedValue));
735 return;
736 }
737
oliver@apple.com68848412014-01-02 20:56:20 +0000738 PutPropertySlot slot(array, false);
oliver@apple.come050d642013-10-19 00:09:28 +0000739 array->putDirect(exec->vm(), Identifier::from(exec, index), JSValue::decode(encodedValue), slot);
740}
741
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000742EncodedJSValue JIT_OPERATION operationArrayPush(ExecState* exec, EncodedJSValue encodedValue, JSArray* array)
fpizlo@apple.com24d24e52011-10-04 02:55:54 +0000743{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000744 VM* vm = &exec->vm();
745 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000746
fpizlo@apple.com24d24e52011-10-04 02:55:54 +0000747 array->push(exec, JSValue::decode(encodedValue));
748 return JSValue::encode(jsNumber(array->length()));
749}
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000750
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000751EncodedJSValue JIT_OPERATION operationArrayPushDouble(ExecState* exec, double value, JSArray* array)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000752{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000753 VM* vm = &exec->vm();
754 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000755
756 array->push(exec, JSValue(JSValue::EncodeAsDouble, value));
757 return JSValue::encode(jsNumber(array->length()));
758}
759
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000760EncodedJSValue JIT_OPERATION operationArrayPop(ExecState* exec, JSArray* array)
fpizlo@apple.com04c19742012-08-26 22:35:26 +0000761{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000762 VM* vm = &exec->vm();
763 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com04c19742012-08-26 22:35:26 +0000764
765 return JSValue::encode(array->pop(exec));
766}
767
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000768EncodedJSValue JIT_OPERATION operationArrayPopAndRecoverLength(ExecState* exec, JSArray* array)
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000769{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000770 VM* vm = &exec->vm();
771 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +0000772
773 array->butterfly()->setPublicLength(array->butterfly()->publicLength() + 1);
774
775 return JSValue::encode(array->pop(exec));
776}
777
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000778EncodedJSValue JIT_OPERATION operationRegExpExecString(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, JSString* argument)
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000779{
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000780 SuperSamplerScope superSamplerScope(false);
781
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000782 VM& vm = globalObject->vm();
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000783 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000784
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000785 return JSValue::encode(regExpObject->execInline(exec, globalObject, argument));
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000786}
787
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000788EncodedJSValue JIT_OPERATION operationRegExpExec(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, EncodedJSValue encodedArgument)
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000789{
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000790 SuperSamplerScope superSamplerScope(false);
791
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000792 VM& vm = globalObject->vm();
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000793 NativeCallFrameTracer tracer(&vm, exec);
794
795 JSValue argument = JSValue::decode(encodedArgument);
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000796
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000797 JSString* input = argument.toStringOrNull(exec);
798 if (!input)
799 return JSValue::encode(jsUndefined());
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000800 return JSValue::encode(regExpObject->execInline(exec, globalObject, input));
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000801}
802
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000803EncodedJSValue JIT_OPERATION operationRegExpExecGeneric(ExecState* exec, JSGlobalObject* globalObject, EncodedJSValue encodedBase, EncodedJSValue encodedArgument)
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000804{
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000805 SuperSamplerScope superSamplerScope(false);
806
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000807 VM& vm = globalObject->vm();
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000808 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000809 auto scope = DECLARE_THROW_SCOPE(vm);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000810
811 JSValue base = JSValue::decode(encodedBase);
812 JSValue argument = JSValue::decode(encodedArgument);
813
814 if (!base.inherits(RegExpObject::info()))
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000815 return throwVMTypeError(exec, scope);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000816
817 JSString* input = argument.toStringOrNull(exec);
818 if (!input)
819 return JSValue::encode(jsUndefined());
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000820 return JSValue::encode(asRegExpObject(base)->exec(exec, globalObject, input));
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000821}
822
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000823size_t JIT_OPERATION operationRegExpTestString(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, JSString* input)
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000824{
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000825 SuperSamplerScope superSamplerScope(false);
826
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000827 VM& vm = globalObject->vm();
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000828 NativeCallFrameTracer tracer(&vm, exec);
oliver@apple.com034a5e12012-05-01 21:34:53 +0000829
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000830 return regExpObject->testInline(exec, globalObject, input);
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000831}
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000832
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000833size_t JIT_OPERATION operationRegExpTest(ExecState* exec, JSGlobalObject* globalObject, RegExpObject* regExpObject, EncodedJSValue encodedArgument)
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000834{
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000835 SuperSamplerScope superSamplerScope(false);
836
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000837 VM& vm = globalObject->vm();
fpizlo@apple.com7fdfeed2016-03-06 00:48:11 +0000838 NativeCallFrameTracer tracer(&vm, exec);
839
840 JSValue argument = JSValue::decode(encodedArgument);
841
842 JSString* input = argument.toStringOrNull(exec);
843 if (!input)
844 return false;
fpizlo@apple.com6ea42db2016-03-08 21:15:07 +0000845 return regExpObject->testInline(exec, globalObject, input);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000846}
847
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000848size_t JIT_OPERATION operationRegExpTestGeneric(ExecState* exec, JSGlobalObject* globalObject, EncodedJSValue encodedBase, EncodedJSValue encodedArgument)
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000849{
fpizlo@apple.com57aea1c2016-04-11 18:20:59 +0000850 SuperSamplerScope superSamplerScope(false);
fpizlo@apple.com5e29b762016-03-18 00:53:24 +0000851
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000852 VM& vm = globalObject->vm();
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000853 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000854 auto scope = DECLARE_THROW_SCOPE(vm);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000855
856 JSValue base = JSValue::decode(encodedBase);
857 JSValue argument = JSValue::decode(encodedArgument);
858
859 if (!base.inherits(RegExpObject::info())) {
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000860 throwTypeError(exec, scope);
fpizlo@apple.com239b0782016-03-03 05:58:59 +0000861 return false;
862 }
863
864 JSString* input = argument.toStringOrNull(exec);
865 if (!input)
866 return false;
fpizlo@apple.com7518ba22016-03-06 20:11:09 +0000867 return asRegExpObject(base)->test(exec, globalObject, input);
barraclough@apple.com077fdd42012-03-18 01:08:16 +0000868}
fpizlo@apple.comee10e452013-04-09 00:10:16 +0000869
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000870size_t JIT_OPERATION operationCompareStrictEqCell(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
commit-queue@webkit.org6efa2ca2011-07-19 00:36:37 +0000871{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000872 VM* vm = &exec->vm();
873 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000874
commit-queue@webkit.org6efa2ca2011-07-19 00:36:37 +0000875 JSValue op1 = JSValue::decode(encodedOp1);
876 JSValue op2 = JSValue::decode(encodedOp2);
877
878 ASSERT(op1.isCell());
879 ASSERT(op2.isCell());
880
881 return JSValue::strictEqualSlowCaseInline(exec, op1, op2);
882}
883
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000884size_t JIT_OPERATION operationCompareStrictEq(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2)
barraclough@apple.com848a0cc2011-04-08 20:33:24 +0000885{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000886 VM* vm = &exec->vm();
887 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com82acbbf2012-02-28 00:37:58 +0000888
889 JSValue src1 = JSValue::decode(encodedOp1);
890 JSValue src2 = JSValue::decode(encodedOp2);
oliver@apple.come07a4592012-01-25 19:43:06 +0000891
fpizlo@apple.com82acbbf2012-02-28 00:37:58 +0000892 return JSValue::strictEqual(exec, src1, src2);
barraclough@apple.com848a0cc2011-04-08 20:33:24 +0000893}
894
mark.lam@apple.com9df8b832013-09-26 20:27:14 +0000895EncodedJSValue JIT_OPERATION operationToPrimitive(ExecState* exec, EncodedJSValue value)
fpizlo@apple.com90e5f0e2011-09-22 22:42:54 +0000896{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000897 VM* vm = &exec->vm();
898 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +0000899
fpizlo@apple.com90e5f0e2011-09-22 22:42:54 +0000900 return JSValue::encode(JSValue::decode(value).toPrimitive(exec));
901}
902
utatane.tea@gmail.comdb32c542016-06-30 15:26:47 +0000903EncodedJSValue JIT_OPERATION operationToNumber(ExecState* exec, EncodedJSValue value)
904{
905 VM* vm = &exec->vm();
906 NativeCallFrameTracer tracer(vm, exec);
907
908 return JSValue::encode(jsNumber(JSValue::decode(value).toNumber(exec)));
909}
910
sbarati@apple.com23315d62016-05-09 20:17:23 +0000911EncodedJSValue JIT_OPERATION operationGetByIdWithThis(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, UniquedStringImpl* impl)
912{
913 VM& vm = exec->vm();
914 NativeCallFrameTracer tracer(&vm, exec);
915
916 JSValue baseValue = JSValue::decode(encodedBase);
917 JSValue thisVal = JSValue::decode(encodedThis);
918 PropertySlot slot(thisVal, PropertySlot::PropertySlot::InternalMethodType::Get);
919 JSValue result = baseValue.get(exec, Identifier::fromUid(exec, impl), slot);
920 return JSValue::encode(result);
921}
922
923EncodedJSValue JIT_OPERATION operationGetByValWithThis(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedSubscript)
924{
925 VM& vm = exec->vm();
926 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000927 auto scope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.com23315d62016-05-09 20:17:23 +0000928
929 JSValue baseValue = JSValue::decode(encodedBase);
930 JSValue thisVal = JSValue::decode(encodedThis);
931 JSValue subscript = JSValue::decode(encodedSubscript);
932
933 if (LIKELY(baseValue.isCell() && subscript.isString())) {
934 Structure& structure = *baseValue.asCell()->structure(vm);
935 if (JSCell::canUseFastGetOwnProperty(structure)) {
936 if (RefPtr<AtomicStringImpl> existingAtomicString = asString(subscript)->toExistingAtomicString(exec)) {
937 if (JSValue result = baseValue.asCell()->fastGetOwnProperty(vm, structure, existingAtomicString.get()))
938 return JSValue::encode(result);
939 }
940 }
941 }
942
943 PropertySlot slot(thisVal, PropertySlot::PropertySlot::InternalMethodType::Get);
944 if (subscript.isUInt32()) {
945 uint32_t i = subscript.asUInt32();
946 if (isJSString(baseValue) && asString(baseValue)->canGetIndex(i))
947 return JSValue::encode(asString(baseValue)->getIndex(exec, i));
948
949 return JSValue::encode(baseValue.get(exec, i, slot));
950 }
951
952 baseValue.requireObjectCoercible(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000953 RETURN_IF_EXCEPTION(scope, encodedJSValue());
sbarati@apple.com23315d62016-05-09 20:17:23 +0000954
955 auto property = subscript.toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000956 RETURN_IF_EXCEPTION(scope, encodedJSValue());
sbarati@apple.com23315d62016-05-09 20:17:23 +0000957 return JSValue::encode(baseValue.get(exec, property, slot));
958}
959
960void JIT_OPERATION operationPutByIdWithThisStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedValue, UniquedStringImpl* impl)
961{
962 VM& vm = exec->vm();
963 NativeCallFrameTracer tracer(&vm, exec);
964
965 putWithThis<true>(exec, encodedBase, encodedThis, encodedValue, Identifier::fromUid(exec, impl));
966}
967
968void JIT_OPERATION operationPutByIdWithThis(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedValue, UniquedStringImpl* impl)
969{
970 VM& vm = exec->vm();
971 NativeCallFrameTracer tracer(&vm, exec);
972
973 putWithThis<false>(exec, encodedBase, encodedThis, encodedValue, Identifier::fromUid(exec, impl));
974}
975
976void JIT_OPERATION operationPutByValWithThisStrict(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedSubscript, EncodedJSValue encodedValue)
977{
978 VM& vm = exec->vm();
979 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000980 auto scope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.com23315d62016-05-09 20:17:23 +0000981
982 Identifier property = JSValue::decode(encodedSubscript).toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000983 RETURN_IF_EXCEPTION(scope, void());
sbarati@apple.com23315d62016-05-09 20:17:23 +0000984 putWithThis<true>(exec, encodedBase, encodedThis, encodedValue, property);
985}
986
987void JIT_OPERATION operationPutByValWithThis(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedThis, EncodedJSValue encodedSubscript, EncodedJSValue encodedValue)
988{
989 VM& vm = exec->vm();
990 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000991 auto scope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.com23315d62016-05-09 20:17:23 +0000992
993 Identifier property = JSValue::decode(encodedSubscript).toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000994 RETURN_IF_EXCEPTION(scope, void());
sbarati@apple.com23315d62016-05-09 20:17:23 +0000995 putWithThis<false>(exec, encodedBase, encodedThis, encodedValue, property);
996}
997
utatane.tea@gmail.comf7db5592016-10-04 19:31:24 +0000998ALWAYS_INLINE static void defineDataProperty(ExecState* exec, VM& vm, JSObject* base, const Identifier& propertyName, JSValue value, int32_t attributes)
999{
1000 PropertyDescriptor descriptor = toPropertyDescriptor(value, jsUndefined(), jsUndefined(), DefinePropertyAttributes(attributes));
1001 ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
1002 if (base->methodTable(vm)->defineOwnProperty == JSObject::defineOwnProperty)
1003 JSObject::defineOwnProperty(base, exec, propertyName, descriptor, true);
1004 else
1005 base->methodTable(vm)->defineOwnProperty(base, exec, propertyName, descriptor, true);
1006}
1007
1008void JIT_OPERATION operationDefineDataProperty(ExecState* exec, JSObject* base, EncodedJSValue encodedProperty, EncodedJSValue encodedValue, int32_t attributes)
1009{
1010 VM& vm = exec->vm();
1011 NativeCallFrameTracer tracer(&vm, exec);
1012 auto scope = DECLARE_THROW_SCOPE(vm);
1013
1014 Identifier propertyName = JSValue::decode(encodedProperty).toPropertyKey(exec);
1015 RETURN_IF_EXCEPTION(scope, void());
1016 defineDataProperty(exec, vm, base, propertyName, JSValue::decode(encodedValue), attributes);
1017}
1018
1019void JIT_OPERATION operationDefineDataPropertyString(ExecState* exec, JSObject* base, JSString* property, EncodedJSValue encodedValue, int32_t attributes)
1020{
1021 VM& vm = exec->vm();
1022 NativeCallFrameTracer tracer(&vm, exec);
1023 auto scope = DECLARE_THROW_SCOPE(vm);
1024
1025 Identifier propertyName = property->toIdentifier(exec);
1026 RETURN_IF_EXCEPTION(scope, void());
1027 defineDataProperty(exec, vm, base, propertyName, JSValue::decode(encodedValue), attributes);
1028}
1029
1030void JIT_OPERATION operationDefineDataPropertyStringIdent(ExecState* exec, JSObject* base, UniquedStringImpl* property, EncodedJSValue encodedValue, int32_t attributes)
1031{
1032 VM& vm = exec->vm();
1033 NativeCallFrameTracer tracer(&vm, exec);
1034 defineDataProperty(exec, vm, base, Identifier::fromUid(&vm, property), JSValue::decode(encodedValue), attributes);
1035}
1036
1037void JIT_OPERATION operationDefineDataPropertySymbol(ExecState* exec, JSObject* base, Symbol* property, EncodedJSValue encodedValue, int32_t attributes)
1038{
1039 VM& vm = exec->vm();
1040 NativeCallFrameTracer tracer(&vm, exec);
1041 defineDataProperty(exec, vm, base, Identifier::fromUid(property->privateName()), JSValue::decode(encodedValue), attributes);
1042}
1043
1044ALWAYS_INLINE static void defineAccessorProperty(ExecState* exec, VM& vm, JSObject* base, const Identifier& propertyName, JSObject* getter, JSObject* setter, int32_t attributes)
1045{
1046 PropertyDescriptor descriptor = toPropertyDescriptor(jsUndefined(), getter, setter, DefinePropertyAttributes(attributes));
1047 ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
1048 if (base->methodTable(vm)->defineOwnProperty == JSObject::defineOwnProperty)
1049 JSObject::defineOwnProperty(base, exec, propertyName, descriptor, true);
1050 else
1051 base->methodTable(vm)->defineOwnProperty(base, exec, propertyName, descriptor, true);
1052}
1053
1054void JIT_OPERATION operationDefineAccessorProperty(ExecState* exec, JSObject* base, EncodedJSValue encodedProperty, JSObject* getter, JSObject* setter, int32_t attributes)
1055{
1056 VM& vm = exec->vm();
1057 NativeCallFrameTracer tracer(&vm, exec);
1058 auto scope = DECLARE_THROW_SCOPE(vm);
1059
1060 Identifier propertyName = JSValue::decode(encodedProperty).toPropertyKey(exec);
1061 RETURN_IF_EXCEPTION(scope, void());
1062 defineAccessorProperty(exec, vm, base, propertyName, getter, setter, attributes);
1063}
1064
1065void JIT_OPERATION operationDefineAccessorPropertyString(ExecState* exec, JSObject* base, JSString* property, JSObject* getter, JSObject* setter, int32_t attributes)
1066{
1067 VM& vm = exec->vm();
1068 NativeCallFrameTracer tracer(&vm, exec);
1069 auto scope = DECLARE_THROW_SCOPE(vm);
1070
1071 Identifier propertyName = property->toIdentifier(exec);
1072 RETURN_IF_EXCEPTION(scope, void());
1073 defineAccessorProperty(exec, vm, base, propertyName, getter, setter, attributes);
1074}
1075
1076void JIT_OPERATION operationDefineAccessorPropertyStringIdent(ExecState* exec, JSObject* base, UniquedStringImpl* property, JSObject* getter, JSObject* setter, int32_t attributes)
1077{
1078 VM& vm = exec->vm();
1079 NativeCallFrameTracer tracer(&vm, exec);
1080 defineAccessorProperty(exec, vm, base, Identifier::fromUid(&vm, property), getter, setter, attributes);
1081}
1082
1083void JIT_OPERATION operationDefineAccessorPropertySymbol(ExecState* exec, JSObject* base, Symbol* property, JSObject* getter, JSObject* setter, int32_t attributes)
1084{
1085 VM& vm = exec->vm();
1086 NativeCallFrameTracer tracer(&vm, exec);
1087 defineAccessorProperty(exec, vm, base, Identifier::fromUid(property->privateName()), getter, setter, attributes);
1088}
1089
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001090char* JIT_OPERATION operationNewArray(ExecState* exec, Structure* arrayStructure, void* buffer, size_t size)
fpizlo@apple.com98a693c2011-09-28 05:33:21 +00001091{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001092 VM* vm = &exec->vm();
1093 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com1bc68482012-10-13 03:56:09 +00001094
fpizlo@apple.com59d1ddb2013-11-05 00:05:02 +00001095 return bitwise_cast<char*>(constructArray(exec, arrayStructure, static_cast<JSValue*>(buffer), size));
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +00001096}
1097
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001098char* JIT_OPERATION operationNewEmptyArray(ExecState* exec, Structure* arrayStructure)
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +00001099{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001100 VM* vm = &exec->vm();
1101 NativeCallFrameTracer tracer(vm, exec);
fpizlo@apple.com1bc68482012-10-13 03:56:09 +00001102
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001103 return bitwise_cast<char*>(JSArray::create(*vm, arrayStructure));
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +00001104}
1105
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001106char* JIT_OPERATION operationNewArrayWithSize(ExecState* exec, Structure* arrayStructure, int32_t size, Butterfly* butterfly)
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +00001107{
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001108 VM& vm = exec->vm();
1109 NativeCallFrameTracer tracer(&vm, exec);
1110 auto scope = DECLARE_THROW_SCOPE(vm);
msaboff@apple.com51d65f22013-04-10 20:01:14 +00001111
msaboff@apple.com6ebf3b82013-04-11 16:19:35 +00001112 if (UNLIKELY(size < 0))
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001113 return bitwise_cast<char*>(throwException(exec, scope, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))));
msaboff@apple.com51d65f22013-04-10 20:01:14 +00001114
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001115 JSArray* result;
1116 if (butterfly)
fpizlo@apple.com9a175952016-09-28 21:55:53 +00001117 result = JSArray::createWithButterfly(vm, nullptr, arrayStructure, butterfly);
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001118 else
1119 result = JSArray::create(vm, arrayStructure, size);
fpizlo@apple.com8dde06b2015-10-12 22:41:01 +00001120 return bitwise_cast<char*>(result);
fpizlo@apple.com98a693c2011-09-28 05:33:21 +00001121}
1122
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001123char* JIT_OPERATION operationNewArrayBuffer(ExecState* exec, Structure* arrayStructure, size_t start, size_t size)
fpizlo@apple.com98a693c2011-09-28 05:33:21 +00001124{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001125 VM& vm = exec->vm();
1126 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com59d1ddb2013-11-05 00:05:02 +00001127 return bitwise_cast<char*>(constructArray(exec, arrayStructure, exec->codeBlock()->constantBuffer(start), size));
fpizlo@apple.com98a693c2011-09-28 05:33:21 +00001128}
1129
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001130char* JIT_OPERATION operationNewInt8ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001131 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001132{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001133 return newTypedArrayWithSize<JSInt8Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001134}
1135
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001136char* JIT_OPERATION operationNewInt8ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001137 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1138{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001139 VM& vm = exec->vm();
1140 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001141 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt8Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001142}
1143
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001144char* JIT_OPERATION operationNewInt16ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001145 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001146{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001147 return newTypedArrayWithSize<JSInt16Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001148}
1149
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001150char* JIT_OPERATION operationNewInt16ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001151 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1152{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001153 VM& vm = exec->vm();
1154 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001155 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt16Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001156}
1157
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001158char* JIT_OPERATION operationNewInt32ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001159 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001160{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001161 return newTypedArrayWithSize<JSInt32Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001162}
1163
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001164char* JIT_OPERATION operationNewInt32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001165 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1166{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001167 VM& vm = exec->vm();
1168 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001169 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSInt32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001170}
1171
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001172char* JIT_OPERATION operationNewUint8ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001173 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001174{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001175 return newTypedArrayWithSize<JSUint8Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001176}
1177
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001178char* JIT_OPERATION operationNewUint8ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001179 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1180{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001181 VM& vm = exec->vm();
1182 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001183 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint8Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001184}
1185
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001186char* JIT_OPERATION operationNewUint8ClampedArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001187 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001188{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001189 return newTypedArrayWithSize<JSUint8ClampedArray>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001190}
1191
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001192char* JIT_OPERATION operationNewUint8ClampedArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001193 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1194{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001195 VM& vm = exec->vm();
1196 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001197 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint8ClampedArray>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001198}
1199
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001200char* JIT_OPERATION operationNewUint16ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001201 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001202{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001203 return newTypedArrayWithSize<JSUint16Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001204}
1205
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001206char* JIT_OPERATION operationNewUint16ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001207 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1208{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001209 VM& vm = exec->vm();
1210 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001211 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint16Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001212}
1213
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001214char* JIT_OPERATION operationNewUint32ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001215 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001216{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001217 return newTypedArrayWithSize<JSUint32Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001218}
1219
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001220char* JIT_OPERATION operationNewUint32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001221 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1222{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001223 VM& vm = exec->vm();
1224 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001225 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSUint32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001226}
1227
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001228char* JIT_OPERATION operationNewFloat32ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001229 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001230{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001231 return newTypedArrayWithSize<JSFloat32Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001232}
1233
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001234char* JIT_OPERATION operationNewFloat32ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001235 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1236{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001237 VM& vm = exec->vm();
1238 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001239 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSFloat32Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001240}
1241
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001242char* JIT_OPERATION operationNewFloat64ArrayWithSize(
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001243 ExecState* exec, Structure* structure, int32_t length, char* vector)
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001244{
fpizlo@apple.com30a72582016-09-08 16:47:34 +00001245 return newTypedArrayWithSize<JSFloat64Array>(exec, structure, length, vector);
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001246}
1247
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001248char* JIT_OPERATION operationNewFloat64ArrayWithOneArgument(
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001249 ExecState* exec, Structure* structure, EncodedJSValue encodedValue)
1250{
fpizlo@apple.com39303e02016-04-05 22:17:35 +00001251 VM& vm = exec->vm();
1252 NativeCallFrameTracer tracer(&vm, exec);
keith_miller@apple.coma646a262015-10-16 21:40:21 +00001253 return reinterpret_cast<char*>(constructGenericTypedArrayViewWithArguments<JSFloat64Array>(exec, structure, encodedValue, 0, Nullopt));
fpizlo@apple.com372fa822013-08-21 19:43:47 +00001254}
1255
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +00001256JSCell* JIT_OPERATION operationCreateActivationDirect(ExecState* exec, Structure* structure, JSScope* scope, SymbolTable* table, EncodedJSValue initialValueEncoded)
fpizlo@apple.comc6446112012-05-23 20:52:42 +00001257{
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +00001258 JSValue initialValue = JSValue::decode(initialValueEncoded);
1259 ASSERT(initialValue == jsUndefined() || initialValue == jsTDZValue());
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001260 VM& vm = exec->vm();
1261 NativeCallFrameTracer tracer(&vm, exec);
saambarati1@gmail.com144f17c2015-07-15 21:41:08 +00001262 return JSLexicalEnvironment::create(vm, structure, scope, table, initialValue);
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001263}
1264
1265JSCell* JIT_OPERATION operationCreateDirectArguments(ExecState* exec, Structure* structure, int32_t length, int32_t minCapacity)
1266{
1267 VM& vm = exec->vm();
1268 NativeCallFrameTracer target(&vm, exec);
1269 DirectArguments* result = DirectArguments::create(
1270 vm, structure, length, std::max(length, minCapacity));
1271 // The caller will store to this object without barriers. Most likely, at this point, this is
1272 // still a young object and so no barriers are needed. But it's good to be careful anyway,
1273 // since the GC should be allowed to do crazy (like pretenuring, for example).
1274 vm.heap.writeBarrier(result);
fpizlo@apple.com9a548f12012-05-24 05:33:09 +00001275 return result;
fpizlo@apple.comc6446112012-05-23 20:52:42 +00001276}
1277
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001278JSCell* JIT_OPERATION operationCreateScopedArguments(ExecState* exec, Structure* structure, Register* argumentStart, int32_t length, JSFunction* callee, JSLexicalEnvironment* scope)
fpizlo@apple.com6d4456e2012-05-23 03:48:52 +00001279{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001280 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001281 NativeCallFrameTracer target(&vm, exec);
fpizlo@apple.comd5547492012-06-07 00:23:36 +00001282
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001283 // We could pass the ScopedArgumentsTable* as an argument. We currently don't because I
1284 // didn't feel like changing the max number of arguments for a slow path call from 6 to 7.
1285 ScopedArgumentsTable* table = scope->symbolTable()->arguments();
fpizlo@apple.comd5547492012-06-07 00:23:36 +00001286
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001287 return ScopedArguments::createByCopyingFrom(
1288 vm, structure, argumentStart, length, callee, table, scope);
fpizlo@apple.comd5547492012-06-07 00:23:36 +00001289}
1290
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001291JSCell* JIT_OPERATION operationCreateClonedArguments(ExecState* exec, Structure* structure, Register* argumentStart, int32_t length, JSFunction* callee)
fpizlo@apple.comd5547492012-06-07 00:23:36 +00001292{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001293 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001294 NativeCallFrameTracer target(&vm, exec);
1295 return ClonedArguments::createByCopyingFrom(
1296 exec, structure, argumentStart, length, callee);
fpizlo@apple.com6d4456e2012-05-23 03:48:52 +00001297}
1298
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001299JSCell* JIT_OPERATION operationCreateDirectArgumentsDuringExit(ExecState* exec, InlineCallFrame* inlineCallFrame, JSFunction* callee, int32_t argumentCount)
fpizlo@apple.com17da7f32012-02-25 23:05:38 +00001300{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001301 VM& vm = exec->vm();
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001302 NativeCallFrameTracer target(&vm, exec);
1303
1304 DeferGCForAWhile deferGC(vm.heap);
1305
1306 CodeBlock* codeBlock;
1307 if (inlineCallFrame)
1308 codeBlock = baselineCodeBlockForInlineCallFrame(inlineCallFrame);
1309 else
1310 codeBlock = exec->codeBlock();
1311
1312 unsigned length = argumentCount - 1;
1313 unsigned capacity = std::max(length, static_cast<unsigned>(codeBlock->numParameters() - 1));
1314 DirectArguments* result = DirectArguments::create(
1315 vm, codeBlock->globalObject()->directArgumentsStructure(), length, capacity);
1316
1317 result->callee().set(vm, result, callee);
1318
1319 Register* arguments =
1320 exec->registers() + (inlineCallFrame ? inlineCallFrame->stackOffset : 0) +
1321 CallFrame::argumentOffset(0);
1322 for (unsigned i = length; i--;)
1323 result->setIndexQuickly(vm, i, arguments[i].jsValue());
1324
1325 return result;
1326}
1327
1328JSCell* JIT_OPERATION operationCreateClonedArgumentsDuringExit(ExecState* exec, InlineCallFrame* inlineCallFrame, JSFunction* callee, int32_t argumentCount)
1329{
1330 VM& vm = exec->vm();
1331 NativeCallFrameTracer target(&vm, exec);
1332
1333 DeferGCForAWhile deferGC(vm.heap);
1334
1335 CodeBlock* codeBlock;
1336 if (inlineCallFrame)
1337 codeBlock = baselineCodeBlockForInlineCallFrame(inlineCallFrame);
1338 else
1339 codeBlock = exec->codeBlock();
1340
1341 unsigned length = argumentCount - 1;
1342 ClonedArguments* result = ClonedArguments::createEmpty(
keith_miller@apple.com26367392016-03-14 20:55:15 +00001343 vm, codeBlock->globalObject()->clonedArgumentsStructure(), callee, length);
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001344
1345 Register* arguments =
1346 exec->registers() + (inlineCallFrame ? inlineCallFrame->stackOffset : 0) +
1347 CallFrame::argumentOffset(0);
1348 for (unsigned i = length; i--;)
keith_miller@apple.com26367392016-03-14 20:55:15 +00001349 result->initializeIndex(vm, i, arguments[i].jsValue());
1350
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001351
1352 return result;
fpizlo@apple.com17da7f32012-02-25 23:05:38 +00001353}
1354
sbarati@apple.com6cfefd82016-08-13 02:14:42 +00001355JSCell* JIT_OPERATION operationCreateRest(ExecState* exec, Register* argumentStart, unsigned numberOfParamsToSkip, unsigned arraySize)
sbarati@apple.comc0722da2015-11-20 02:37:47 +00001356{
keith_miller@apple.com1b8b0062016-04-16 01:26:10 +00001357 VM* vm = &exec->vm();
1358 NativeCallFrameTracer tracer(vm, exec);
1359
sbarati@apple.com6cfefd82016-08-13 02:14:42 +00001360 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
1361 Structure* structure = globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous);
1362 static_assert(sizeof(Register) == sizeof(JSValue), "This is a strong assumption here.");
1363 JSValue* argumentsToCopyRegion = bitwise_cast<JSValue*>(argumentStart) + numberOfParamsToSkip;
1364 return constructArray(exec, structure, argumentsToCopyRegion, arraySize);
sbarati@apple.comc0722da2015-11-20 02:37:47 +00001365}
1366
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001367size_t JIT_OPERATION operationObjectIsObject(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
oliver@apple.come722ad02013-01-09 02:37:29 +00001368{
mark.lam@apple.com87a5b6f2014-02-05 04:22:43 +00001369 VM& vm = exec->vm();
1370 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001371
1372 ASSERT(jsDynamicCast<JSObject*>(object));
1373
1374 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1375 return false;
1376 if (object->type() == JSFunctionType)
1377 return false;
1378 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1379 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001380 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001381 return false;
1382 }
1383
1384 return true;
1385}
1386
1387size_t JIT_OPERATION operationObjectIsFunction(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1388{
1389 VM& vm = exec->vm();
1390 NativeCallFrameTracer tracer(&vm, exec);
1391
1392 ASSERT(jsDynamicCast<JSObject*>(object));
1393
1394 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1395 return false;
1396 if (object->type() == JSFunctionType)
1397 return true;
1398 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1399 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001400 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001401 return true;
1402 }
1403
1404 return false;
1405}
1406
1407JSCell* JIT_OPERATION operationTypeOfObject(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1408{
1409 VM& vm = exec->vm();
1410 NativeCallFrameTracer tracer(&vm, exec);
1411
1412 ASSERT(jsDynamicCast<JSObject*>(object));
1413
1414 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1415 return vm.smallStrings.undefinedString();
1416 if (object->type() == JSFunctionType)
1417 return vm.smallStrings.functionString();
1418 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1419 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001420 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001421 return vm.smallStrings.functionString();
1422 }
1423
1424 return vm.smallStrings.objectString();
1425}
1426
1427int32_t JIT_OPERATION operationTypeOfObjectAsTypeofType(ExecState* exec, JSGlobalObject* globalObject, JSCell* object)
1428{
1429 VM& vm = exec->vm();
1430 NativeCallFrameTracer tracer(&vm, exec);
1431
1432 ASSERT(jsDynamicCast<JSObject*>(object));
1433
1434 if (object->structure(vm)->masqueradesAsUndefined(globalObject))
1435 return static_cast<int32_t>(TypeofType::Undefined);
1436 if (object->type() == JSFunctionType)
1437 return static_cast<int32_t>(TypeofType::Function);
1438 if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
1439 CallData callData;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +00001440 if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
fpizlo@apple.comb8823d52015-05-03 00:15:27 +00001441 return static_cast<int32_t>(TypeofType::Function);
1442 }
1443
1444 return static_cast<int32_t>(TypeofType::Object);
oliver@apple.come722ad02013-01-09 02:37:29 +00001445}
1446
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001447char* JIT_OPERATION operationAllocatePropertyStorageWithInitialCapacity(ExecState* exec)
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001448{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001449 VM& vm = exec->vm();
1450 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001451
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001452 return reinterpret_cast<char*>(
oliver@apple.coma03796a2013-07-25 04:01:20 +00001453 Butterfly::createUninitialized(vm, 0, 0, initialOutOfLineCapacity, false, 0));
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001454}
1455
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001456char* JIT_OPERATION operationAllocatePropertyStorage(ExecState* exec, size_t newSize)
fpizlo@apple.com1ffdcff2012-07-19 00:30:34 +00001457{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001458 VM& vm = exec->vm();
1459 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.comc17054c2012-09-18 15:22:29 +00001460
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001461 return reinterpret_cast<char*>(
oliver@apple.coma03796a2013-07-25 04:01:20 +00001462 Butterfly::createUninitialized(vm, 0, 0, newSize, false, 0));
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +00001463}
1464
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001465char* JIT_OPERATION operationEnsureInt32(ExecState* exec, JSCell* cell)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001466{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001467 VM& vm = exec->vm();
1468 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001469
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001470 if (!cell->isObject())
1471 return 0;
1472
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001473 return reinterpret_cast<char*>(asObject(cell)->ensureInt32(vm).data());
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001474}
1475
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001476char* JIT_OPERATION operationEnsureDouble(ExecState* exec, JSCell* cell)
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001477{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001478 VM& vm = exec->vm();
1479 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001480
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001481 if (!cell->isObject())
1482 return 0;
1483
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001484 return reinterpret_cast<char*>(asObject(cell)->ensureDouble(vm).data());
fpizlo@apple.com75c91a72012-11-08 22:28:25 +00001485}
1486
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001487char* JIT_OPERATION operationEnsureContiguous(ExecState* exec, JSCell* cell)
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001488{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001489 VM& vm = exec->vm();
1490 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001491
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001492 if (!cell->isObject())
1493 return 0;
1494
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001495 return reinterpret_cast<char*>(asObject(cell)->ensureContiguous(vm).data());
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +00001496}
1497
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001498char* JIT_OPERATION operationEnsureArrayStorage(ExecState* exec, JSCell* cell)
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001499{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001500 VM& vm = exec->vm();
1501 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com274b6f12012-12-20 00:19:03 +00001502
1503 if (!cell->isObject())
1504 return 0;
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001505
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001506 return reinterpret_cast<char*>(asObject(cell)->ensureArrayStorage(vm));
fpizlo@apple.com497c7512012-09-19 01:20:52 +00001507}
1508
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001509StringImpl* JIT_OPERATION operationResolveRope(ExecState* exec, JSString* string)
fpizlo@apple.com70bb5c52012-12-11 05:22:49 +00001510{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001511 VM& vm = exec->vm();
1512 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com70bb5c52012-12-11 05:22:49 +00001513
1514 return string->value(exec).impl();
1515}
1516
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001517JSString* JIT_OPERATION operationSingleCharacterString(ExecState* exec, int32_t character)
oliver@apple.com63af2d42013-07-25 04:03:33 +00001518{
1519 VM& vm = exec->vm();
1520 NativeCallFrameTracer tracer(&vm, exec);
1521
1522 return jsSingleCharacterString(exec, static_cast<UChar>(character));
1523}
1524
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001525JSCell* JIT_OPERATION operationNewStringObject(ExecState* exec, JSString* string, Structure* structure)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001526{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001527 VM& vm = exec->vm();
1528 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001529
akling@apple.com019809c2013-10-06 18:16:48 +00001530 return StringObject::create(vm, structure, string);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001531}
1532
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001533JSCell* JIT_OPERATION operationToStringOnCell(ExecState* exec, JSCell* cell)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001534{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001535 VM& vm = exec->vm();
1536 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001537
1538 return JSValue(cell).toString(exec);
1539}
1540
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001541JSCell* JIT_OPERATION operationToString(ExecState* exec, EncodedJSValue value)
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001542{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001543 VM& vm = exec->vm();
1544 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com0e6e1542013-03-18 18:09:22 +00001545
1546 return JSValue::decode(value).toString(exec);
1547}
1548
utatane.tea@gmail.com153559e2015-04-06 19:07:12 +00001549JSCell* JIT_OPERATION operationCallStringConstructorOnCell(ExecState* exec, JSCell* cell)
1550{
1551 VM& vm = exec->vm();
1552 NativeCallFrameTracer tracer(&vm, exec);
1553
1554 return stringConstructor(exec, cell);
1555}
1556
1557JSCell* JIT_OPERATION operationCallStringConstructor(ExecState* exec, EncodedJSValue value)
1558{
1559 VM& vm = exec->vm();
1560 NativeCallFrameTracer tracer(&vm, exec);
1561
1562 return stringConstructor(exec, JSValue::decode(value));
1563}
1564
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001565JSCell* JIT_OPERATION operationMakeRope2(ExecState* exec, JSString* left, JSString* right)
fpizlo@apple.com8d225912013-03-19 00:44:57 +00001566{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001567 VM& vm = exec->vm();
1568 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com24c49992014-04-19 21:13:46 +00001569
mark.lam@apple.com581437a2016-09-22 23:41:56 +00001570 return jsString(exec, left, right);
fpizlo@apple.com8d225912013-03-19 00:44:57 +00001571}
1572
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001573JSCell* JIT_OPERATION operationMakeRope3(ExecState* exec, JSString* a, JSString* b, JSString* c)
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001574{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001575 VM& vm = exec->vm();
1576 NativeCallFrameTracer tracer(&vm, exec);
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001577
mark.lam@apple.com581437a2016-09-22 23:41:56 +00001578 return jsString(exec, a, b, c);
fpizlo@apple.com4463e442013-03-20 20:29:37 +00001579}
1580
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001581JSCell* JIT_OPERATION operationStrCat2(ExecState* exec, EncodedJSValue a, EncodedJSValue b)
1582{
1583 VM& vm = exec->vm();
1584 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001585 auto scope = DECLARE_THROW_SCOPE(vm);
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001586
1587 JSString* str1 = JSValue::decode(a).toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +00001588 ASSERT(!scope.exception()); // Impossible, since we must have been given primitives.
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001589 JSString* str2 = JSValue::decode(b).toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +00001590 ASSERT(!scope.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001591
mark.lam@apple.com581437a2016-09-22 23:41:56 +00001592 scope.release();
1593 return jsString(exec, str1, str2);
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001594}
1595
1596JSCell* JIT_OPERATION operationStrCat3(ExecState* exec, EncodedJSValue a, EncodedJSValue b, EncodedJSValue c)
1597{
1598 VM& vm = exec->vm();
1599 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001600 auto scope = DECLARE_THROW_SCOPE(vm);
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001601
1602 JSString* str1 = JSValue::decode(a).toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +00001603 ASSERT(!scope.exception()); // Impossible, since we must have been given primitives.
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001604 JSString* str2 = JSValue::decode(b).toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +00001605 ASSERT(!scope.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001606 JSString* str3 = JSValue::decode(c).toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +00001607 ASSERT(!scope.exception());
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001608
mark.lam@apple.com581437a2016-09-22 23:41:56 +00001609 scope.release();
1610 return jsString(exec, str1, str2, str3);
fpizlo@apple.comb3b187c2015-08-22 18:35:47 +00001611}
1612
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001613char* JIT_OPERATION operationFindSwitchImmTargetForDouble(
oliver@apple.com9b7647b2013-07-25 04:03:00 +00001614 ExecState* exec, EncodedJSValue encodedValue, size_t tableIndex)
1615{
keith_miller@apple.com1b8b0062016-04-16 01:26:10 +00001616 VM& vm = exec->vm();
1617 NativeCallFrameTracer tracer(&vm, exec);
1618
oliver@apple.com9b7647b2013-07-25 04:03:00 +00001619 CodeBlock* codeBlock = exec->codeBlock();
oliver@apple.coma14cea52013-07-25 04:03:23 +00001620 SimpleJumpTable& table = codeBlock->switchJumpTable(tableIndex);
oliver@apple.com9b7647b2013-07-25 04:03:00 +00001621 JSValue value = JSValue::decode(encodedValue);
1622 ASSERT(value.isDouble());
1623 double asDouble = value.asDouble();
1624 int32_t asInt32 = static_cast<int32_t>(asDouble);
1625 if (asDouble == asInt32)
1626 return static_cast<char*>(table.ctiForValue(asInt32).executableAddress());
1627 return static_cast<char*>(table.ctiDefault.executableAddress());
1628}
1629
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001630char* JIT_OPERATION operationSwitchString(ExecState* exec, size_t tableIndex, JSString* string)
oliver@apple.com5c826c02013-07-25 04:03:51 +00001631{
1632 VM& vm = exec->vm();
1633 NativeCallFrameTracer tracer(&vm, exec);
1634
1635 return static_cast<char*>(exec->codeBlock()->stringSwitchJumpTable(tableIndex).ctiForValue(string->value(exec).impl()).executableAddress());
1636}
1637
fpizlo@apple.com5a3036b2015-04-29 03:34:43 +00001638int32_t JIT_OPERATION operationSwitchStringAndGetBranchOffset(ExecState* exec, size_t tableIndex, JSString* string)
1639{
1640 VM& vm = exec->vm();
1641 NativeCallFrameTracer tracer(&vm, exec);
1642
1643 return exec->codeBlock()->stringSwitchJumpTable(tableIndex).offsetForValue(string->value(exec).impl(), std::numeric_limits<int32_t>::min());
1644}
1645
commit-queue@webkit.org36c52882016-04-22 05:08:28 +00001646uintptr_t JIT_OPERATION operationCompareStringImplLess(StringImpl* a, StringImpl* b)
1647{
1648 return codePointCompare(a, b) < 0;
1649}
1650
1651uintptr_t JIT_OPERATION operationCompareStringImplLessEq(StringImpl* a, StringImpl* b)
1652{
1653 return codePointCompare(a, b) <= 0;
1654}
1655
1656uintptr_t JIT_OPERATION operationCompareStringImplGreater(StringImpl* a, StringImpl* b)
1657{
1658 return codePointCompare(a, b) > 0;
1659}
1660
1661uintptr_t JIT_OPERATION operationCompareStringImplGreaterEq(StringImpl* a, StringImpl* b)
1662{
1663 return codePointCompare(a, b) >= 0;
1664}
1665
1666uintptr_t JIT_OPERATION operationCompareStringLess(ExecState* exec, JSString* a, JSString* b)
1667{
1668 VM& vm = exec->vm();
1669 NativeCallFrameTracer tracer(&vm, exec);
1670
1671 return codePointCompareLessThan(asString(a)->value(exec), asString(b)->value(exec));
1672}
1673
1674uintptr_t JIT_OPERATION operationCompareStringLessEq(ExecState* exec, JSString* a, JSString* b)
1675{
1676 VM& vm = exec->vm();
1677 NativeCallFrameTracer tracer(&vm, exec);
1678
1679 return !codePointCompareLessThan(asString(b)->value(exec), asString(a)->value(exec));
1680}
1681
1682uintptr_t JIT_OPERATION operationCompareStringGreater(ExecState* exec, JSString* a, JSString* b)
1683{
1684 VM& vm = exec->vm();
1685 NativeCallFrameTracer tracer(&vm, exec);
1686
1687 return codePointCompareLessThan(asString(b)->value(exec), asString(a)->value(exec));
1688}
1689
1690uintptr_t JIT_OPERATION operationCompareStringGreaterEq(ExecState* exec, JSString* a, JSString* b)
1691{
1692 VM& vm = exec->vm();
1693 NativeCallFrameTracer tracer(&vm, exec);
1694
1695 return !codePointCompareLessThan(asString(a)->value(exec), asString(b)->value(exec));
1696}
1697
fpizlo@apple.com3a2fa4c2015-04-13 22:13:12 +00001698void JIT_OPERATION operationNotifyWrite(ExecState* exec, WatchpointSet* set)
fpizlo@apple.com33961712013-11-20 05:49:05 +00001699{
1700 VM& vm = exec->vm();
1701 NativeCallFrameTracer tracer(&vm, exec);
1702
sbarati@apple.com0c3609d2016-06-28 21:30:20 +00001703 set->touch(vm, "Executed NotifyWrite");
fpizlo@apple.com33961712013-11-20 05:49:05 +00001704}
1705
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001706void JIT_OPERATION operationThrowStackOverflowForVarargs(ExecState* exec)
1707{
1708 VM& vm = exec->vm();
1709 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001710 auto scope = DECLARE_THROW_SCOPE(vm);
1711 throwStackOverflowError(exec, scope);
fpizlo@apple.comda834ae2015-03-26 04:28:43 +00001712}
1713
fpizlo@apple.com8fefdd32015-02-18 19:55:47 +00001714int32_t JIT_OPERATION operationSizeOfVarargs(ExecState* exec, EncodedJSValue encodedArguments, int32_t firstVarArgOffset)
1715{
1716 VM& vm = exec->vm();
1717 NativeCallFrameTracer tracer(&vm, exec);
1718 JSValue arguments = JSValue::decode(encodedArguments);
1719
1720 return sizeOfVarargs(exec, arguments, firstVarArgOffset);
1721}
1722
sbarati@apple.coma3db4652016-09-20 01:05:50 +00001723int32_t JIT_OPERATION operationHasOwnProperty(ExecState* exec, JSObject* thisObject, EncodedJSValue encodedKey)
1724{
1725 VM& vm = exec->vm();
1726 NativeCallFrameTracer tracer(&vm, exec);
1727 auto scope = DECLARE_THROW_SCOPE(vm);
1728
1729 JSValue key = JSValue::decode(encodedKey);
1730 Identifier propertyName = key.toPropertyKey(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +00001731 RETURN_IF_EXCEPTION(scope, false);
sbarati@apple.coma3db4652016-09-20 01:05:50 +00001732
1733 PropertySlot slot(thisObject, PropertySlot::InternalMethodType::GetOwnProperty);
1734 bool result = thisObject->hasOwnProperty(exec, propertyName.impl(), slot);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +00001735 RETURN_IF_EXCEPTION(scope, false);
sbarati@apple.coma3db4652016-09-20 01:05:50 +00001736
1737 HasOwnPropertyCache* hasOwnPropertyCache = vm.hasOwnPropertyCache();
1738 ASSERT(hasOwnPropertyCache);
1739 hasOwnPropertyCache->tryAdd(vm, slot, thisObject, propertyName.impl(), result);
1740 return result;
1741}
1742
fpizlo@apple.com8fefdd32015-02-18 19:55:47 +00001743void JIT_OPERATION operationLoadVarargs(ExecState* exec, int32_t firstElementDest, EncodedJSValue encodedArguments, int32_t offset, int32_t length, int32_t mandatoryMinimum)
1744{
1745 VM& vm = exec->vm();
1746 NativeCallFrameTracer tracer(&vm, exec);
1747 JSValue arguments = JSValue::decode(encodedArguments);
1748
1749 loadVarargs(exec, VirtualRegister(firstElementDest), arguments, offset, length);
1750
1751 for (int32_t i = length; i < mandatoryMinimum; ++i)
1752 exec->r(firstElementDest + i) = jsUndefined();
1753}
1754
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001755double JIT_OPERATION operationFModOnInts(int32_t a, int32_t b)
fpizlo@apple.com2c2536e2012-03-21 01:29:28 +00001756{
1757 return fmod(a, b);
1758}
1759
utatane.tea@gmail.comd2fca0a2015-12-15 03:51:42 +00001760#if USE(JSVALUE32_64)
1761double JIT_OPERATION operationRandom(JSGlobalObject* globalObject)
1762{
1763 return globalObject->weakRandomNumber();
1764}
1765#endif
1766
mark.lam@apple.com03a3e382016-01-08 18:44:36 +00001767JSCell* JIT_OPERATION operationStringFromCharCode(ExecState* exec, int32_t op1)
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +00001768{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001769 VM* vm = &exec->vm();
1770 NativeCallFrameTracer tracer(vm, exec);
mark.lam@apple.com03a3e382016-01-08 18:44:36 +00001771 return JSC::stringFromCharCode(exec, op1);
commit-queue@webkit.orgaa31a5e2013-04-09 06:45:16 +00001772}
1773
mark.lam@apple.com151fe102016-01-13 23:28:38 +00001774EncodedJSValue JIT_OPERATION operationStringFromCharCodeUntyped(ExecState* exec, EncodedJSValue encodedValue)
1775{
1776 VM* vm = &exec->vm();
1777 NativeCallFrameTracer tracer(vm, exec);
1778 JSValue charValue = JSValue::decode(encodedValue);
1779 int32_t chInt = charValue.toUInt32(exec);
1780 return JSValue::encode(JSC::stringFromCharCode(exec, chInt));
1781}
1782
fpizlo@apple.comf2999932014-07-15 00:41:39 +00001783int64_t JIT_OPERATION operationConvertBoxedDoubleToInt52(EncodedJSValue encodedValue)
1784{
1785 JSValue value = JSValue::decode(encodedValue);
1786 if (!value.isDouble())
1787 return JSValue::notInt52;
1788 return tryConvertToInt52(value.asDouble());
1789}
1790
1791int64_t JIT_OPERATION operationConvertDoubleToInt52(double value)
1792{
1793 return tryConvertToInt52(value);
1794}
1795
sbarati@apple.comfa857522016-03-07 01:00:33 +00001796size_t JIT_OPERATION operationDefaultHasInstance(ExecState* exec, JSCell* value, JSCell* proto) // Returns jsBoolean(True|False) on 64-bit.
1797{
1798 VM* vm = &exec->vm();
1799 NativeCallFrameTracer tracer(vm, exec);
1800 if (JSObject::defaultHasInstance(exec, value, proto))
1801 return 1;
1802 return 0;
1803}
1804
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001805char* JIT_OPERATION operationNewRawObject(ExecState* exec, Structure* structure, int32_t length, Butterfly* butterfly)
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001806{
1807 VM& vm = exec->vm();
1808 NativeCallFrameTracer tracer(&vm, exec);
1809
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001810 if (!butterfly
1811 && (structure->outOfLineCapacity() || hasIndexedProperties(structure->indexingType()))) {
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001812 IndexingHeader header;
1813 header.setVectorLength(length);
1814 header.setPublicLength(0);
1815
1816 butterfly = Butterfly::create(
1817 vm, nullptr, 0, structure->outOfLineCapacity(),
1818 hasIndexedProperties(structure->indexingType()), header,
1819 length * sizeof(EncodedJSValue));
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001820 }
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001821
1822 JSObject* result = JSObject::createRawObject(exec, structure, butterfly);
1823 result->butterfly(); // Ensure that the butterfly is in to-space.
1824 return bitwise_cast<char*>(result);
1825}
1826
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001827JSCell* JIT_OPERATION operationNewObjectWithButterfly(ExecState* exec, Structure* structure, Butterfly* butterfly)
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001828{
1829 VM& vm = exec->vm();
1830 NativeCallFrameTracer tracer(&vm, exec);
1831
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001832 if (!butterfly) {
1833 butterfly = Butterfly::create(
1834 vm, nullptr, 0, structure->outOfLineCapacity(), false, IndexingHeader(), 0);
1835 }
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001836
1837 JSObject* result = JSObject::createRawObject(exec, structure, butterfly);
1838 result->butterfly(); // Ensure that the butterfly is in to-space.
1839 return result;
1840}
1841
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001842JSCell* JIT_OPERATION operationNewObjectWithButterflyWithIndexingHeaderAndVectorLength(ExecState* exec, Structure* structure, unsigned length, Butterfly* butterfly)
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001843{
1844 VM& vm = exec->vm();
1845 NativeCallFrameTracer tracer(&vm, exec);
1846
1847 IndexingHeader header;
1848 header.setVectorLength(length);
1849 header.setPublicLength(0);
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +00001850 if (butterfly)
1851 *butterfly->indexingHeader() = header;
1852 else {
1853 butterfly = Butterfly::create(
1854 vm, nullptr, 0, structure->outOfLineCapacity(), true, header,
1855 sizeof(EncodedJSValue) * length);
1856 }
1857
fpizlo@apple.com280ef002016-04-05 22:13:16 +00001858 // Paradoxically this may allocate a JSArray. That's totally cool.
1859 JSObject* result = JSObject::createRawObject(exec, structure, butterfly);
1860 result->butterfly(); // Ensure that the butterfly is in to-space.
1861 return result;
1862}
1863
saambarati1@gmail.comdaf10202014-10-01 20:47:51 +00001864void JIT_OPERATION operationProcessTypeProfilerLogDFG(ExecState* exec)
1865{
sbarati@apple.comc6fb7552016-06-07 20:07:56 +00001866 VM& vm = exec->vm();
1867 NativeCallFrameTracer tracer(&vm, exec);
1868
1869 vm.typeProfilerLog()->processLogEntries(ASCIILiteral("Log Full, called from inside DFG."));
saambarati1@gmail.comdaf10202014-10-01 20:47:51 +00001870}
1871
mark.lam@apple.com9df8b832013-09-26 20:27:14 +00001872void JIT_OPERATION debugOperationPrintSpeculationFailure(ExecState* exec, void* debugInfoRaw, void* scratch)
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001873{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +00001874 VM* vm = &exec->vm();
1875 NativeCallFrameTracer tracer(vm, exec);
oliver@apple.come07a4592012-01-25 19:43:06 +00001876
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001877 SpeculationFailureDebugInfo* debugInfo = static_cast<SpeculationFailureDebugInfo*>(debugInfoRaw);
fpizlo@apple.comf2bf0dd2011-09-26 04:05:28 +00001878 CodeBlock* codeBlock = debugInfo->codeBlock;
fpizlo@apple.com47d3b642011-10-05 21:36:23 +00001879 CodeBlock* alternative = codeBlock->alternative();
mark.lam@apple.come7ecf832014-04-02 20:49:27 +00001880 dataLog("Speculation failure in ", *codeBlock);
1881 dataLog(" @ exit #", vm->osrExitIndex, " (bc#", debugInfo->bytecodeOffset, ", ", exitKindToString(debugInfo->kind), ") with ");
fpizlo@apple.com0bfcc382012-11-30 03:42:29 +00001882 if (alternative) {
1883 dataLog(
1884 "executeCounter = ", alternative->jitExecuteCounter(),
1885 ", reoptimizationRetryCounter = ", alternative->reoptimizationRetryCounter(),
1886 ", optimizationDelayCounter = ", alternative->optimizationDelayCounter());
1887 } else
1888 dataLog("no alternative code block (i.e. we've been jettisoned)");
1889 dataLog(", osrExitCounter = ", codeBlock->osrExitCounter(), "\n");
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001890 dataLog(" GPRs at time of exit:");
1891 char* scratchPointer = static_cast<char*>(scratch);
1892 for (unsigned i = 0; i < GPRInfo::numberOfRegisters; ++i) {
1893 GPRReg gpr = GPRInfo::toRegister(i);
commit-queue@webkit.org94ea8122013-02-25 13:13:43 +00001894 dataLog(" ", GPRInfo::debugName(gpr), ":", RawPointer(*reinterpret_cast_ptr<void**>(scratchPointer)));
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001895 scratchPointer += sizeof(EncodedJSValue);
1896 }
1897 dataLog("\n");
1898 dataLog(" FPRs at time of exit:");
1899 for (unsigned i = 0; i < FPRInfo::numberOfRegisters; ++i) {
1900 FPRReg fpr = FPRInfo::toRegister(i);
1901 dataLog(" ", FPRInfo::debugName(fpr), ":");
commit-queue@webkit.org94ea8122013-02-25 13:13:43 +00001902 uint64_t bits = *reinterpret_cast_ptr<uint64_t*>(scratchPointer);
1903 double value = *reinterpret_cast_ptr<double*>(scratchPointer);
ossy@webkit.org71aebd72013-01-12 09:33:01 +00001904 dataLogF("%llx:%lf", static_cast<long long>(bits), value);
fpizlo@apple.com03e446e2013-01-11 22:18:27 +00001905 scratchPointer += sizeof(EncodedJSValue);
1906 }
1907 dataLog("\n");
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001908}
fpizlo@apple.com746c6d072011-09-07 02:47:51 +00001909
sbarati@apple.come67fd782016-04-19 01:38:30 +00001910JSCell* JIT_OPERATION operationResolveScope(ExecState* exec, JSScope* scope, UniquedStringImpl* impl)
1911{
1912 VM& vm = exec->vm();
1913 NativeCallFrameTracer tracer(&vm, exec);
1914
1915 JSObject* resolvedScope = JSScope::resolve(exec, scope, Identifier::fromUid(exec, impl));
1916 return resolvedScope;
1917}
1918
1919EncodedJSValue JIT_OPERATION operationGetDynamicVar(ExecState* exec, JSObject* scope, UniquedStringImpl* impl, unsigned getPutInfoBits)
1920{
1921 VM& vm = exec->vm();
1922 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001923 auto throwScope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.come67fd782016-04-19 01:38:30 +00001924
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +00001925 Identifier ident = Identifier::fromUid(exec, impl);
1926 return JSValue::encode(scope->getPropertySlot(exec, ident, [&] (bool found, PropertySlot& slot) -> JSValue {
1927 if (!found) {
1928 GetPutInfo getPutInfo(getPutInfoBits);
1929 if (getPutInfo.resolveMode() == ThrowIfNotFound)
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001930 throwException(exec, throwScope, createUndefinedVariableError(exec, ident));
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +00001931 return jsUndefined();
sbarati@apple.come67fd782016-04-19 01:38:30 +00001932 }
sbarati@apple.come67fd782016-04-19 01:38:30 +00001933
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +00001934 if (scope->isGlobalLexicalEnvironment()) {
1935 // When we can't statically prove we need a TDZ check, we must perform the check on the slow path.
1936 JSValue result = slot.getValue(exec, ident);
1937 if (result == jsTDZValue()) {
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001938 throwException(exec, throwScope, createTDZError(exec));
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +00001939 return jsUndefined();
1940 }
1941 return result;
1942 }
1943
1944 return slot.getValue(exec, ident);
1945 }));
sbarati@apple.come67fd782016-04-19 01:38:30 +00001946}
1947
1948void JIT_OPERATION operationPutDynamicVar(ExecState* exec, JSObject* scope, EncodedJSValue value, UniquedStringImpl* impl, unsigned getPutInfoBits)
1949{
1950 VM& vm = exec->vm();
1951 NativeCallFrameTracer tracer(&vm, exec);
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001952 auto throwScope = DECLARE_THROW_SCOPE(vm);
sbarati@apple.come67fd782016-04-19 01:38:30 +00001953
1954 const Identifier& ident = Identifier::fromUid(exec, impl);
1955 GetPutInfo getPutInfo(getPutInfoBits);
1956 bool hasProperty = scope->hasProperty(exec, ident);
1957 if (hasProperty
1958 && scope->isGlobalLexicalEnvironment()
1959 && !isInitialization(getPutInfo.initializationMode())) {
1960 // When we can't statically prove we need a TDZ check, we must perform the check on the slow path.
1961 PropertySlot slot(scope, PropertySlot::InternalMethodType::Get);
1962 JSGlobalLexicalEnvironment::getOwnPropertySlot(scope, exec, ident, slot);
1963 if (slot.getValue(exec, ident) == jsTDZValue()) {
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001964 throwException(exec, throwScope, createTDZError(exec));
sbarati@apple.come67fd782016-04-19 01:38:30 +00001965 return;
1966 }
1967 }
1968
1969 if (getPutInfo.resolveMode() == ThrowIfNotFound && !hasProperty) {
mark.lam@apple.com284f4562016-08-30 20:54:54 +00001970 throwException(exec, throwScope, createUndefinedVariableError(exec, ident));
sbarati@apple.come67fd782016-04-19 01:38:30 +00001971 return;
1972 }
1973
1974 CodeOrigin origin = exec->codeOrigin();
1975 bool strictMode;
1976 if (origin.inlineCallFrame)
1977 strictMode = origin.inlineCallFrame->baselineCodeBlock->isStrictMode();
1978 else
1979 strictMode = exec->codeBlock()->isStrictMode();
1980 PutPropertySlot slot(scope, strictMode, PutPropertySlot::UnknownContext, isInitialization(getPutInfo.initializationMode()));
1981 scope->methodTable()->put(scope, exec, ident, JSValue::decode(value), slot);
1982}
1983
sbarati@apple.com21fc86e2016-09-06 23:22:01 +00001984int32_t JIT_OPERATION operationMapHash(ExecState* exec, EncodedJSValue input)
1985{
1986 VM& vm = exec->vm();
1987 NativeCallFrameTracer tracer(&vm, exec);
1988
1989 return jsMapHash(exec, vm, normalizeMapKey(JSValue::decode(input)));
1990}
1991
1992JSCell* JIT_OPERATION operationJSMapFindBucket(ExecState* exec, JSCell* map, EncodedJSValue key, int32_t hash)
1993{
1994 VM& vm = exec->vm();
1995 NativeCallFrameTracer tracer(&vm, exec);
1996 JSMap::BucketType** bucket = jsCast<JSMap*>(map)->findBucket(exec, normalizeMapKey(JSValue::decode(key)), hash);
1997 if (!bucket)
1998 return nullptr;
1999 return *bucket;
2000}
2001
2002JSCell* JIT_OPERATION operationJSSetFindBucket(ExecState* exec, JSCell* map, EncodedJSValue key, int32_t hash)
2003{
2004 VM& vm = exec->vm();
2005 NativeCallFrameTracer tracer(&vm, exec);
2006 JSSet::BucketType** bucket = jsCast<JSSet*>(map)->findBucket(exec, normalizeMapKey(JSValue::decode(key)), hash);
2007 if (!bucket)
2008 return nullptr;
2009 return *bucket;
2010}
2011
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00002012extern "C" void JIT_OPERATION triggerReoptimizationNow(CodeBlock* codeBlock, OSRExitBase* exit)
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002013{
fpizlo@apple.com98225492013-09-10 18:29:45 +00002014 // It's sort of preferable that we don't GC while in here. Anyways, doing so wouldn't
2015 // really be profitable.
2016 DeferGCForAWhile deferGC(codeBlock->vm()->heap);
2017
oliver@apple.com284cc3d2013-07-25 04:00:33 +00002018 if (Options::verboseOSR())
2019 dataLog(*codeBlock, ": Entered reoptimize\n");
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002020 // We must be called with the baseline code block.
oliver@apple.com5a24fdd2013-07-25 04:00:54 +00002021 ASSERT(JITCode::isBaselineCode(codeBlock->jitType()));
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002022
2023 // If I am my own replacement, then reoptimization has already been triggered.
2024 // This can happen in recursive functions.
oliver@apple.comd2a16382013-07-25 04:04:18 +00002025 if (codeBlock->replacement() == codeBlock) {
2026 if (Options::verboseOSR())
2027 dataLog(*codeBlock, ": Not reoptimizing because we've already been jettisoned.\n");
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002028 return;
oliver@apple.comd2a16382013-07-25 04:04:18 +00002029 }
2030
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002031 // Otherwise, the replacement must be optimized code. Use this as an opportunity
2032 // to check our logic.
2033 ASSERT(codeBlock->hasOptimizedReplacement());
oliver@apple.comd2a16382013-07-25 04:04:18 +00002034 CodeBlock* optimizedCodeBlock = codeBlock->replacement();
2035 ASSERT(JITCode::isOptimizingJIT(optimizedCodeBlock->jitType()));
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00002036
2037 bool didTryToEnterIntoInlinedLoops = false;
msaboff@apple.coma3dc7532015-09-24 21:42:59 +00002038 for (InlineCallFrame* inlineCallFrame = exit->m_codeOrigin.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->directCaller.inlineCallFrame) {
ggaren@apple.com81def5f2015-10-09 23:10:16 +00002039 if (inlineCallFrame->baselineCodeBlock->ownerScriptExecutable()->didTryToEnterInLoop()) {
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00002040 didTryToEnterIntoInlinedLoops = true;
2041 break;
2042 }
2043 }
oliver@apple.comd2a16382013-07-25 04:04:18 +00002044
2045 // In order to trigger reoptimization, one of two things must have happened:
2046 // 1) We exited more than some number of times.
2047 // 2) We exited and got stuck in a loop, and now we're exiting again.
2048 bool didExitABunch = optimizedCodeBlock->shouldReoptimizeNow();
2049 bool didGetStuckInLoop =
fpizlo@apple.com2c4a7e92014-08-06 05:27:46 +00002050 (codeBlock->checkIfOptimizationThresholdReached() || didTryToEnterIntoInlinedLoops)
oliver@apple.comd2a16382013-07-25 04:04:18 +00002051 && optimizedCodeBlock->shouldReoptimizeFromLoopNow();
2052
2053 if (!didExitABunch && !didGetStuckInLoop) {
2054 if (Options::verboseOSR())
2055 dataLog(*codeBlock, ": Not reoptimizing ", *optimizedCodeBlock, " because it either didn't exit enough or didn't loop enough after exit.\n");
2056 codeBlock->optimizeAfterLongWarmUp();
2057 return;
2058 }
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002059
fpizlo@apple.com0dda6d72014-02-02 02:25:13 +00002060 optimizedCodeBlock->jettison(Profiler::JettisonDueToOSRExit, CountReoptimization);
fpizlo@apple.com16e2cbf2012-06-22 23:32:59 +00002061}
2062
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002063#if ENABLE(FTL_JIT)
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002064static bool shouldTriggerFTLCompile(CodeBlock* codeBlock, JITCode* jitCode)
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002065{
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002066 if (codeBlock->baselineVersion()->m_didFailFTLCompilation) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002067 CODEBLOCK_LOG_EVENT(codeBlock, "abortFTLCompile", ());
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002068 if (Options::verboseOSR())
2069 dataLog("Deferring FTL-optimization of ", *codeBlock, " indefinitely because there was an FTL failure.\n");
2070 jitCode->dontOptimizeAnytimeSoon(codeBlock);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002071 return false;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002072 }
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002073
2074 if (!codeBlock->hasOptimizedReplacement()
2075 && !jitCode->checkIfOptimizationThresholdReached(codeBlock)) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002076 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("counter = ", jitCode->tierUpCounter));
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002077 if (Options::verboseOSR())
2078 dataLog("Choosing not to FTL-optimize ", *codeBlock, " yet.\n");
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002079 return false;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002080 }
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002081 return true;
2082}
2083
2084static void triggerFTLReplacementCompile(VM* vm, CodeBlock* codeBlock, JITCode* jitCode)
2085{
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002086 Worklist::State worklistState;
msaboff@apple.com95894332014-01-29 19:18:54 +00002087 if (Worklist* worklist = existingGlobalFTLWorklistOrNull()) {
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002088 worklistState = worklist->completeAllReadyPlansForVM(
2089 *vm, CompilationKey(codeBlock->baselineVersion(), FTLMode));
2090 } else
2091 worklistState = Worklist::NotKnown;
2092
2093 if (worklistState == Worklist::Compiling) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002094 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("still compiling"));
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002095 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2096 codeBlock, CompilationDeferred);
2097 return;
2098 }
2099
2100 if (codeBlock->hasOptimizedReplacement()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002101 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("has replacement"));
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002102 // That's great, we've compiled the code - next time we call this function,
2103 // we'll enter that replacement.
2104 jitCode->optimizeSoon(codeBlock);
2105 return;
2106 }
2107
2108 if (worklistState == Worklist::Compiled) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002109 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("compiled and failed"));
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002110 // This means that we finished compiling, but failed somehow; in that case the
2111 // thresholds will be set appropriately.
2112 if (Options::verboseOSR())
2113 dataLog("Code block ", *codeBlock, " was compiled but it doesn't have an optimized replacement.\n");
2114 return;
2115 }
2116
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002117 CODEBLOCK_LOG_EVENT(codeBlock, "triggerFTLReplacement", ());
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002118 // We need to compile the code.
2119 compile(
ggaren@apple.com81def5f2015-10-09 23:10:16 +00002120 *vm, codeBlock->newReplacement(), codeBlock, FTLMode, UINT_MAX,
2121 Operands<JSValue>(), ToFTLDeferredCompilationCallback::create());
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002122
2123 // If we reached here, the counter has not be reset. Do that now.
2124 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2125 codeBlock, CompilationDeferred);
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002126}
2127
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002128void JIT_OPERATION triggerTierUpNow(ExecState* exec)
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002129{
2130 VM* vm = &exec->vm();
2131 NativeCallFrameTracer tracer(vm, exec);
sbarati@apple.comefcb30a2016-06-23 23:28:50 +00002132 DeferGCForAWhile deferGC(vm->heap);
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002133 CodeBlock* codeBlock = exec->codeBlock();
2134
fpizlo@apple.com8a5fd182015-02-02 18:38:08 +00002135 if (codeBlock->jitType() != JITCode::DFGJIT) {
2136 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
2137 RELEASE_ASSERT_NOT_REACHED();
2138 }
2139
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002140 JITCode* jitCode = codeBlock->jitCode()->dfg();
2141
2142 if (Options::verboseOSR()) {
2143 dataLog(
2144 *codeBlock, ": Entered triggerTierUpNow with executeCounter = ",
2145 jitCode->tierUpCounter, "\n");
2146 }
benjamin@webkit.org8f625992015-05-18 20:45:34 +00002147
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002148 if (shouldTriggerFTLCompile(codeBlock, jitCode))
2149 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002150
2151 if (codeBlock->hasOptimizedReplacement()) {
2152 if (jitCode->tierUpEntryTriggers.isEmpty()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002153 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("replacement in place, delaying indefinitely"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002154 // There is nothing more we can do, the only way this will be entered
2155 // is through the function entry point.
2156 jitCode->dontOptimizeAnytimeSoon(codeBlock);
2157 return;
2158 }
2159 if (jitCode->osrEntryBlock() && jitCode->tierUpEntryTriggers.size() == 1) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002160 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("trigger in place, delaying indefinitely"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002161 // There is only one outer loop and its trigger must have been set
2162 // when the plan completed.
2163 // Exiting the inner loop is useless, we can ignore the counter and leave
2164 // the trigger do its job.
2165 jitCode->dontOptimizeAnytimeSoon(codeBlock);
2166 return;
2167 }
2168 }
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002169}
2170
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002171static char* tierUpCommon(ExecState* exec, unsigned originBytecodeIndex, unsigned osrEntryBytecodeIndex)
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002172{
2173 VM* vm = &exec->vm();
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002174 CodeBlock* codeBlock = exec->codeBlock();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002175
2176 // Resolve any pending plan for OSR Enter on this function.
2177 Worklist::State worklistState;
2178 if (Worklist* worklist = existingGlobalFTLWorklistOrNull()) {
2179 worklistState = worklist->completeAllReadyPlansForVM(
2180 *vm, CompilationKey(codeBlock->baselineVersion(), FTLForOSREntryMode));
2181 } else
2182 worklistState = Worklist::NotKnown;
2183
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002184 JITCode* jitCode = codeBlock->jitCode()->dfg();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002185 if (worklistState == Worklist::Compiling) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002186 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("still compiling"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002187 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2188 codeBlock, CompilationDeferred);
2189 return nullptr;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002190 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002191
2192 if (worklistState == Worklist::Compiled) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002193 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("compiled and failed"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002194 // This means that compilation failed and we already set the thresholds.
2195 if (Options::verboseOSR())
2196 dataLog("Code block ", *codeBlock, " was compiled but it doesn't have an optimized replacement.\n");
2197 return nullptr;
2198 }
2199
2200 // If we can OSR Enter, do it right away.
2201 if (originBytecodeIndex == osrEntryBytecodeIndex) {
2202 unsigned streamIndex = jitCode->bytecodeIndexToStreamIndex.get(originBytecodeIndex);
2203 if (CodeBlock* entryBlock = jitCode->osrEntryBlock()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002204 if (void* address = FTL::prepareOSREntry(exec, codeBlock, entryBlock, originBytecodeIndex, streamIndex)) {
2205 CODEBLOCK_LOG_EVENT(entryBlock, "osrEntry", ("at bc#", originBytecodeIndex));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002206 return static_cast<char*>(address);
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002207 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002208 }
2209 }
2210
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002211 // - If we don't have an FTL code block, then try to compile one.
2212 // - If we do have an FTL code block, then try to enter for a while.
2213 // - If we couldn't enter for a while, then trigger OSR entry.
msaboff@apple.com95894332014-01-29 19:18:54 +00002214
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002215 if (!shouldTriggerFTLCompile(codeBlock, jitCode))
2216 return nullptr;
2217
2218 if (!jitCode->neverExecutedEntry) {
2219 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
2220
2221 if (!codeBlock->hasOptimizedReplacement())
2222 return nullptr;
fpizlo@apple.com239b0782016-03-03 05:58:59 +00002223
2224 if (jitCode->osrEntryRetry < Options::ftlOSREntryRetryThreshold()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002225 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("avoiding OSR entry compile"));
fpizlo@apple.com239b0782016-03-03 05:58:59 +00002226 jitCode->osrEntryRetry++;
2227 return nullptr;
2228 }
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002229 } else
2230 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("avoiding replacement compile"));
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002231
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002232 // It's time to try to compile code for OSR entry.
2233 if (CodeBlock* entryBlock = jitCode->osrEntryBlock()) {
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002234 if (jitCode->osrEntryRetry < Options::ftlOSREntryRetryThreshold()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002235 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("OSR entry failed, OSR entry threshold not met"));
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002236 jitCode->osrEntryRetry++;
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002237 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2238 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002239 return nullptr;
2240 }
2241
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002242 FTL::ForOSREntryJITCode* entryCode = entryBlock->jitCode()->ftlForOSREntry();
2243 entryCode->countEntryFailure();
2244 if (entryCode->entryFailureCount() <
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002245 Options::ftlOSREntryFailureCountForReoptimization()) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002246 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("OSR entry failed"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002247 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2248 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002249 return nullptr;
2250 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002251
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002252 // OSR entry failed. Oh no! This implies that we need to retry. We retry
2253 // without exponential backoff and we only do this for the entry code block.
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002254 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("OSR entry failed too many times"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002255 unsigned osrEntryBytecode = entryBlock->jitCode()->ftlForOSREntry()->bytecodeIndex();
ggaren@apple.com81def5f2015-10-09 23:10:16 +00002256 jitCode->clearOSREntryBlock();
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002257 jitCode->osrEntryRetry = 0;
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002258 jitCode->tierUpEntryTriggers.set(osrEntryBytecode, 0);
2259 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2260 codeBlock, CompilationDeferred);
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002261 return nullptr;
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002262 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002263
2264 unsigned streamIndex = jitCode->bytecodeIndexToStreamIndex.get(osrEntryBytecodeIndex);
2265 auto tierUpHierarchyEntry = jitCode->tierUpInLoopHierarchy.find(osrEntryBytecodeIndex);
2266 if (tierUpHierarchyEntry != jitCode->tierUpInLoopHierarchy.end()) {
2267 for (unsigned osrEntryCandidate : tierUpHierarchyEntry->value) {
2268 if (jitCode->tierUpEntrySeen.contains(osrEntryCandidate)) {
2269 osrEntryBytecodeIndex = osrEntryCandidate;
2270 streamIndex = jitCode->bytecodeIndexToStreamIndex.get(osrEntryBytecodeIndex);
2271 }
2272 }
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002273 }
2274
fpizlo@apple.com0c606702014-02-06 07:11:48 +00002275 // We aren't compiling and haven't compiled anything for OSR entry. So, try to compile
2276 // something.
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002277 auto triggerIterator = jitCode->tierUpEntryTriggers.find(osrEntryBytecodeIndex);
2278 RELEASE_ASSERT(triggerIterator != jitCode->tierUpEntryTriggers.end());
2279 uint8_t* triggerAddress = &(triggerIterator->value);
2280
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002281 Operands<JSValue> mustHandleValues;
2282 jitCode->reconstruct(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002283 exec, codeBlock, CodeOrigin(osrEntryBytecodeIndex), streamIndex, mustHandleValues);
ggaren@apple.com81def5f2015-10-09 23:10:16 +00002284 CodeBlock* replacementCodeBlock = codeBlock->newReplacement();
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002285
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002286 CODEBLOCK_LOG_EVENT(codeBlock, "triggerFTLOSR", ());
msaboff@apple.com95894332014-01-29 19:18:54 +00002287 CompilationResult forEntryResult = compile(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002288 *vm, replacementCodeBlock, codeBlock, FTLForOSREntryMode, osrEntryBytecodeIndex,
2289 mustHandleValues, ToFTLForOSREntryDeferredCompilationCallback::create(triggerAddress));
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002290
2291 if (jitCode->neverExecutedEntry)
2292 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
2293
2294 if (forEntryResult != CompilationSuccessful) {
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002295 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("OSR ecompilation not successful"));
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002296 jitCode->setOptimizationThresholdBasedOnCompilationResult(
2297 codeBlock, CompilationDeferred);
2298 return nullptr;
2299 }
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002300
2301 CODEBLOCK_LOG_EVENT(jitCode->osrEntryBlock(), "osrEntry", ("at bc#", originBytecodeIndex));
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002302 // It's possible that the for-entry compile already succeeded. In that case OSR
2303 // entry will succeed unless we ran out of stack. It's not clear what we should do.
2304 // We signal to try again after a while if that happens.
2305 void* address = FTL::prepareOSREntry(
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002306 exec, codeBlock, jitCode->osrEntryBlock(), originBytecodeIndex, streamIndex);
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002307 return static_cast<char*>(address);
2308}
commit-queue@webkit.org2ae563d2016-02-26 05:59:48 +00002309
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002310void JIT_OPERATION triggerTierUpNowInLoop(ExecState* exec, unsigned bytecodeIndex)
2311{
2312 VM* vm = &exec->vm();
2313 NativeCallFrameTracer tracer(vm, exec);
sbarati@apple.comefcb30a2016-06-23 23:28:50 +00002314 DeferGCForAWhile deferGC(vm->heap);
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002315 CodeBlock* codeBlock = exec->codeBlock();
2316
2317 if (codeBlock->jitType() != JITCode::DFGJIT) {
2318 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
2319 RELEASE_ASSERT_NOT_REACHED();
2320 }
2321
2322 JITCode* jitCode = codeBlock->jitCode()->dfg();
2323
2324 if (Options::verboseOSR()) {
2325 dataLog(
2326 *codeBlock, ": Entered triggerTierUpNowInLoop with executeCounter = ",
2327 jitCode->tierUpCounter, "\n");
2328 }
2329
2330 auto tierUpHierarchyEntry = jitCode->tierUpInLoopHierarchy.find(bytecodeIndex);
2331 if (tierUpHierarchyEntry != jitCode->tierUpInLoopHierarchy.end()
2332 && !tierUpHierarchyEntry->value.isEmpty()) {
2333 tierUpCommon(exec, bytecodeIndex, tierUpHierarchyEntry->value.first());
2334 } else if (shouldTriggerFTLCompile(codeBlock, jitCode))
2335 triggerFTLReplacementCompile(vm, codeBlock, jitCode);
2336
2337 // Since we cannot OSR Enter here, the default "optimizeSoon()" is not useful.
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002338 if (codeBlock->hasOptimizedReplacement()) {
2339 CODEBLOCK_LOG_EVENT(codeBlock, "delayFTLCompile", ("OSR in loop failed, deferring"));
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002340 jitCode->setOptimizationThresholdBasedOnCompilationResult(codeBlock, CompilationDeferred);
fpizlo@apple.com4a528d02016-05-11 00:08:50 +00002341 }
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002342}
2343
2344char* JIT_OPERATION triggerOSREntryNow(ExecState* exec, unsigned bytecodeIndex)
2345{
2346 VM* vm = &exec->vm();
2347 NativeCallFrameTracer tracer(vm, exec);
sbarati@apple.comefcb30a2016-06-23 23:28:50 +00002348 DeferGCForAWhile deferGC(vm->heap);
benjamin@webkit.org31527f52016-03-09 17:51:38 +00002349 CodeBlock* codeBlock = exec->codeBlock();
2350
2351 if (codeBlock->jitType() != JITCode::DFGJIT) {
2352 dataLog("Unexpected code block in DFG->FTL tier-up: ", *codeBlock, "\n");
2353 RELEASE_ASSERT_NOT_REACHED();
2354 }
2355
2356 JITCode* jitCode = codeBlock->jitCode()->dfg();
2357 jitCode->tierUpEntrySeen.add(bytecodeIndex);
2358
2359 if (Options::verboseOSR()) {
2360 dataLog(
2361 *codeBlock, ": Entered triggerOSREntryNow with executeCounter = ",
2362 jitCode->tierUpCounter, "\n");
2363 }
2364
2365 return tierUpCommon(exec, bytecodeIndex, bytecodeIndex);
2366}
2367
fpizlo@apple.com532f1e52013-09-04 06:26:04 +00002368#endif // ENABLE(FTL_JIT)
2369
barraclough@apple.comc7af2d32011-05-26 21:37:05 +00002370} // extern "C"
fpizlo@apple.com04659ba2012-02-21 09:49:22 +00002371} } // namespace JSC::DFG
2372
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +00002373#endif // ENABLE(DFG_JIT)
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +00002374
commit-queue@webkit.orgb8419482012-08-30 22:21:48 +00002375#endif // ENABLE(JIT)