runtime.h 34 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_RUNTIME_RUNTIME_H_
#define V8_RUNTIME_RUNTIME_H_
7

8 9
#include <memory>

10
#include "include/v8.h"
11
#include "src/base/bit-field.h"
12
#include "src/base/platform/time.h"
13
#include "src/common/globals.h"
14
#include "src/objects/elements-kind.h"
15
#include "src/strings/unicode.h"
16
#include "src/utils/allocation.h"
17
#include "src/zone/zone.h"
18

19 20
namespace v8 {
namespace internal {
21

22
// * Each intrinsic is exposed in JavaScript via:
23
//    * %#name, which is always a runtime call.
24 25
//    * (optionally) %_#name, which can be inlined or just a runtime call, the
//      compiler in question decides.
26 27 28 29 30 31 32 33 34 35 36
//
// * IntrinsicTypes are Runtime::RUNTIME and Runtime::INLINE, respectively.
//
// * IDs are Runtime::k##name and Runtime::kInline##name, respectively.
//
// * All intrinsics have a C++ implementation Runtime_##name.
//
// * Each compiler has an explicit list of intrisics it supports, falling back
//   to a simple runtime call if necessary.

// Entries have the form F(name, number of arguments, number of values):
37
// A variable number of arguments is specified by a -1, additional restrictions
38 39 40
// are specified by inline comments. To declare only the runtime version (no
// inline), use the F macro below. To declare the runtime version and the inline
// version simultaneously, use the I macro below.
41

42 43 44 45 46 47 48 49 50 51 52
#define FOR_EACH_INTRINSIC_ARRAY(F, I) \
  F(ArrayIncludes_Slow, 3, 1)          \
  F(ArrayIndexOf, 3, 1)                \
  F(ArrayIsArray, 1, 1)                \
  F(ArraySpeciesConstructor, 1, 1)     \
  F(GrowArrayElements, 2, 1)           \
  I(IsArray, 1, 1)                     \
  F(NewArray, -1 /* >= 3 */, 1)        \
  F(NormalizeElements, 1, 1)           \
  F(TransitionElementsKind, 2, 1)      \
  F(TransitionElementsKindWithKind, 2, 1)
53

54 55 56 57 58 59 60 61 62 63 64
#define FOR_EACH_INTRINSIC_ATOMICS(F, I) \
  F(AtomicsLoad64, 2, 1)                 \
  F(AtomicsStore64, 3, 1)                \
  F(AtomicsAdd, 3, 1)                    \
  F(AtomicsAnd, 3, 1)                    \
  F(AtomicsCompareExchange, 4, 1)        \
  F(AtomicsExchange, 3, 1)               \
  F(AtomicsNumWaitersForTesting, 2, 1)   \
  F(AtomicsOr, 3, 1)                     \
  F(AtomicsSub, 3, 1)                    \
  F(AtomicsXor, 3, 1)                    \
65
  F(SetAllowAtomicsWait, 1, 1)
binji's avatar
binji committed
66

67 68 69 70 71 72 73 74 75 76 77
#define FOR_EACH_INTRINSIC_BIGINT(F, I) \
  F(BigIntBinaryOp, 3, 1)               \
  F(BigIntCompareToBigInt, 3, 1)        \
  F(BigIntCompareToNumber, 3, 1)        \
  F(BigIntCompareToString, 3, 1)        \
  F(BigIntEqualToBigInt, 2, 1)          \
  F(BigIntEqualToNumber, 2, 1)          \
  F(BigIntEqualToString, 2, 1)          \
  F(BigIntToBoolean, 1, 1)              \
  F(BigIntToNumber, 1, 1)               \
  F(BigIntUnaryOp, 2, 1)                \
78
  F(ToBigInt, 1, 1)
79

80
#define FOR_EACH_INTRINSIC_CLASSES(F, I)    \
81
  F(DefineClass, -1 /* >= 3 */, 1)          \
82
  F(HomeObjectSymbol, 0, 1)                 \
83 84
  F(LoadFromSuper, 3, 1)                    \
  F(LoadKeyedFromSuper, 3, 1)               \
85 86
  F(StoreKeyedToSuper, 4, 1)                \
  F(StoreToSuper, 4, 1)                     \
87 88 89 90 91 92
  F(ThrowConstructorNonCallableError, 1, 1) \
  F(ThrowNotSuperConstructor, 2, 1)         \
  F(ThrowStaticPrototypeError, 0, 1)        \
  F(ThrowSuperAlreadyCalledError, 0, 1)     \
  F(ThrowSuperNotCalled, 0, 1)              \
  F(ThrowUnsupportedSuperError, 0, 1)
93

94 95 96 97 98 99 100
#define FOR_EACH_INTRINSIC_COLLECTIONS(F, I) \
  F(MapGrow, 1, 1)                           \
  F(MapShrink, 1, 1)                         \
  F(SetGrow, 1, 1)                           \
  F(SetShrink, 1, 1)                         \
  F(TheHole, 0, 1)                           \
  F(WeakCollectionDelete, 3, 1)              \
101
  F(WeakCollectionSet, 4, 1)
102

103
#define FOR_EACH_INTRINSIC_COMPILER(F, I) \
104
  F(CompileForOnStackReplacement, 0, 1)   \
105 106 107
  F(CompileLazy, 1, 1)                    \
  F(CompileOptimized_Concurrent, 1, 1)    \
  F(CompileOptimized_NotConcurrent, 1, 1) \
108
  F(EvictOptimizedCodeSlot, 1, 1)         \
109 110
  F(FunctionFirstExecution, 1, 1)         \
  F(InstantiateAsmJs, 4, 1)               \
111
  F(NotifyDeoptimized, 0, 1)              \
112
  F(ResolvePossiblyDirectEval, 6, 1)
113

114
#define FOR_EACH_INTRINSIC_DATE(F, I) F(DateCurrentTime, 0, 1)
115

116
#define FOR_EACH_INTRINSIC_DEBUG(F, I)          \
117
  F(ClearStepping, 0, 1)                        \
118
  F(CollectGarbage, 1, 1)                       \
119 120
  F(DebugAsyncFunctionEntered, 1, 1)            \
  F(DebugAsyncFunctionSuspended, 1, 1)          \
121 122
  F(DebugAsyncFunctionResumed, 1, 1)            \
  F(DebugAsyncFunctionFinished, 2, 1)           \
123 124
  F(DebugBreakAtEntry, 1, 1)                    \
  F(DebugCollectCoverage, 0, 1)                 \
125
  F(DebugGetLoadedScriptIds, 0, 1)              \
126
  F(DebugOnFunctionCall, 2, 1)                  \
127 128 129 130 131 132 133 134 135
  F(DebugPopPromise, 0, 1)                      \
  F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
  F(DebugPushPromise, 1, 1)                     \
  F(DebugToggleBlockCoverage, 1, 1)             \
  F(DebugTogglePreciseCoverage, 1, 1)           \
  F(FunctionGetInferredName, 1, 1)              \
  F(GetBreakLocations, 1, 1)                    \
  F(GetGeneratorScopeCount, 1, 1)               \
  F(GetGeneratorScopeDetails, 2, 1)             \
136
  F(GetHeapUsage, 0, 1)                         \
137 138
  F(HandleDebuggerStatement, 0, 1)              \
  F(IsBreakOnException, 1, 1)                   \
139 140
  F(LiveEditPatchScript, 2, 1)                  \
  F(ProfileCreateSnapshotDataBlob, 0, 1)        \
141
  F(ScheduleBreak, 0, 1)                        \
142
  F(ScriptLocationFromLine2, 4, 1)              \
143
  F(SetGeneratorScopeVariableValue, 4, 1)       \
144
  I(IncBlockCounter, 2, 1)
145

146 147
#define FOR_EACH_INTRINSIC_FORIN(F, I) \
  F(ForInEnumerate, 1, 1)              \
148
  F(ForInHasProperty, 2, 1)
149

150
#ifdef V8_TRACE_IGNITION
151 152
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I) \
  F(InterpreterTraceBytecodeEntry, 3, 1)           \
153 154
  F(InterpreterTraceBytecodeExit, 3, 1)
#else
155
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I)
156 157
#endif

158
#ifdef V8_TRACE_FEEDBACK_UPDATES
159
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I) \
160 161
  F(InterpreterTraceUpdateFeedback, 3, 1)
#else
162
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I)
163 164
#endif

165 166 167
#define FOR_EACH_INTRINSIC_INTERPRETER(F, I) \
  FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F, I) \
  FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F, I)
168

169 170
#define FOR_EACH_INTRINSIC_FUNCTION(F, I)  \
  I(Call, -1 /* >= 2 */, 1)                \
171
  F(FunctionGetScriptSource, 1, 1)         \
172
  F(FunctionGetScriptId, 1, 1)             \
173
  F(FunctionGetScriptSourcePosition, 1, 1) \
174
  F(FunctionGetSourceCode, 1, 1)           \
175
  F(FunctionIsAPIFunction, 1, 1)           \
176
  F(IsFunction, 1, 1)
177

178
#define FOR_EACH_INTRINSIC_GENERATOR(F, I)    \
179 180
  I(AsyncFunctionAwaitCaught, 2, 1)           \
  I(AsyncFunctionAwaitUncaught, 2, 1)         \
181 182 183
  I(AsyncFunctionEnter, 2, 1)                 \
  I(AsyncFunctionReject, 3, 1)                \
  I(AsyncFunctionResolve, 3, 1)               \
184 185
  I(AsyncGeneratorAwaitCaught, 2, 1)          \
  I(AsyncGeneratorAwaitUncaught, 2, 1)        \
186
  F(AsyncGeneratorHasCatchHandlerForPC, 1, 1) \
187 188 189 190 191
  I(AsyncGeneratorReject, 2, 1)               \
  I(AsyncGeneratorResolve, 3, 1)              \
  I(AsyncGeneratorYield, 3, 1)                \
  I(CreateJSGeneratorObject, 2, 1)            \
  I(GeneratorClose, 1, 1)                     \
192
  F(GeneratorGetFunction, 1, 1)               \
193
  I(GeneratorGetResumeMode, 1, 1)
194

195
#ifdef V8_INTL_SUPPORT
196 197 198 199
#define FOR_EACH_INTRINSIC_INTL(F, I) \
  F(FormatList, 2, 1)                 \
  F(FormatListToParts, 2, 1)          \
  F(StringToLowerCaseIntl, 1, 1)      \
200
  F(StringToUpperCaseIntl, 1, 1)  // End of macro.
201
#else
202
#define FOR_EACH_INTRINSIC_INTL(F, I)
203
#endif  // V8_INTL_SUPPORT
204

205
#define FOR_EACH_INTRINSIC_INTERNAL(F, I)            \
206
  F(AccessCheck, 1, 1)                               \
207
  F(AllocateByteArray, 1, 1)                         \
208
  F(AllocateInYoungGeneration, 2, 1)                 \
209
  F(AllocateInOldGeneration, 2, 1)                   \
210 211 212 213 214
  F(AllocateSeqOneByteString, 1, 1)                  \
  F(AllocateSeqTwoByteString, 1, 1)                  \
  F(AllowDynamicFunction, 1, 1)                      \
  I(CreateAsyncFromSyncIterator, 1, 1)               \
  F(CreateListFromArrayLike, 1, 1)                   \
215
  F(DoubleToStringWithRadix, 2, 1)                   \
216 217 218
  F(FatalProcessOutOfMemoryInAllocateRaw, 0, 1)      \
  F(FatalProcessOutOfMemoryInvalidArrayLength, 0, 1) \
  F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1)   \
219
  F(GetTemplateObject, 3, 1)                         \
220
  F(IncrementUseCounter, 1, 1)                       \
221
  F(BytecodeBudgetInterrupt, 1, 1)                   \
222 223 224 225 226
  F(NewReferenceError, 2, 1)                         \
  F(NewSyntaxError, 2, 1)                            \
  F(NewTypeError, 2, 1)                              \
  F(OrdinaryHasInstance, 2, 1)                       \
  F(PromoteScheduledException, 0, 1)                 \
227
  F(ReportDetachedWindowAccess, 0, 1)                \
228 229 230 231 232
  F(ReportMessage, 1, 1)                             \
  F(ReThrow, 1, 1)                                   \
  F(RunMicrotaskCallback, 2, 1)                      \
  F(PerformMicrotaskCheckpoint, 0, 1)                \
  F(StackGuard, 0, 1)                                \
233
  F(StackGuardWithGap, 1, 1)                         \
234 235 236 237 238 239 240 241 242 243
  F(Throw, 1, 1)                                     \
  F(ThrowApplyNonFunction, 1, 1)                     \
  F(ThrowCalledNonCallable, 1, 1)                    \
  F(ThrowConstructedNonConstructable, 1, 1)          \
  F(ThrowConstructorReturnedNonObject, 0, 1)         \
  F(ThrowInvalidStringLength, 0, 1)                  \
  F(ThrowInvalidTypedArrayAlignment, 2, 1)           \
  F(ThrowIteratorError, 1, 1)                        \
  F(ThrowIteratorResultNotAnObject, 1, 1)            \
  F(ThrowNotConstructor, 1, 1)                       \
244
  F(ThrowPatternAssignmentNonCoercible, 1, 1)        \
245 246
  F(ThrowRangeError, -1 /* >= 1 */, 1)               \
  F(ThrowReferenceError, 1, 1)                       \
247
  F(ThrowAccessedUninitializedVariable, 1, 1)        \
248 249 250 251 252
  F(ThrowStackOverflow, 0, 1)                        \
  F(ThrowSymbolAsyncIteratorInvalid, 0, 1)           \
  F(ThrowSymbolIteratorInvalid, 0, 1)                \
  F(ThrowThrowMethodMissing, 0, 1)                   \
  F(ThrowTypeError, -1 /* >= 1 */, 1)                \
253
  F(ThrowTypeErrorIfStrict, -1 /* >= 1 */, 1)        \
254
  F(Typeof, 1, 1)                                    \
255
  F(UnwindAndFindExceptionHandler, 0, 1)
256

257
#define FOR_EACH_INTRINSIC_LITERALS(F, I)           \
258
  F(CreateArrayLiteral, 4, 1)                       \
259
  F(CreateArrayLiteralWithoutAllocationSite, 2, 1)  \
260 261
  F(CreateObjectLiteral, 4, 1)                      \
  F(CreateObjectLiteralWithoutAllocationSite, 2, 1) \
262
  F(CreateRegExpLiteral, 4, 1)
263

264 265 266
#define FOR_EACH_INTRINSIC_MODULE(F, I) \
  F(DynamicImportCall, 2, 1)            \
  I(GetImportMetaObject, 0, 1)          \
267
  F(GetModuleNamespace, 1, 1)
268

269
#define FOR_EACH_INTRINSIC_NUMBERS(F, I) \
270
  F(ArrayBufferMaxByteLength, 0, 1)      \
271 272 273 274 275 276 277 278
  F(GetHoleNaNLower, 0, 1)               \
  F(GetHoleNaNUpper, 0, 1)               \
  I(IsSmi, 1, 1)                         \
  F(IsValidSmi, 1, 1)                    \
  F(MaxSmi, 0, 1)                        \
  F(NumberToString, 1, 1)                \
  F(StringParseFloat, 1, 1)              \
  F(StringParseInt, 2, 1)                \
279 280
  F(StringToNumber, 1, 1)                \
  F(TypedArrayMaxLength, 0, 1)
281

282
#define FOR_EACH_INTRINSIC_OBJECT(F, I)                         \
283
  F(AddDictionaryProperty, 3, 1)                                \
284
  F(AddPrivateField, 3, 1)                                      \
285
  F(AddPrivateBrand, 2, 1)                                      \
286 287
  F(AllocateHeapNumber, 0, 1)                                   \
  F(ClassOf, 1, 1)                                              \
288 289
  F(CollectTypeProfile, 3, 1)                                   \
  F(CompleteInobjectSlackTrackingForMap, 1, 1)                  \
290
  I(CopyDataProperties, 2, 1)                                   \
291
  F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
292 293
  I(CreateDataProperty, 3, 1)                                   \
  I(CreateIterResultObject, 2, 1)                               \
294
  F(CreatePrivateAccessors, 2, 1)                               \
295 296
  F(DefineAccessorPropertyUnchecked, 5, 1)                      \
  F(DefineDataPropertyInLiteral, 6, 1)                          \
297
  F(DefineGetterPropertyUnchecked, 4, 1)                        \
298 299
  F(DefineSetterPropertyUnchecked, 4, 1)                        \
  F(DeleteProperty, 3, 1)                                       \
300
  F(GetDerivedMap, 2, 1)                                        \
301 302 303 304 305 306
  F(GetFunctionName, 1, 1)                                      \
  F(GetOwnPropertyDescriptor, 2, 1)                             \
  F(GetOwnPropertyKeys, 2, 1)                                   \
  F(GetProperty, 2, 1)                                          \
  F(HasFastPackedElements, 1, 1)                                \
  F(HasInPrototypeChain, 2, 1)                                  \
307
  I(HasProperty, 2, 1)                                          \
308
  F(InternalSetPrototype, 2, 1)                                 \
309
  I(IsJSReceiver, 1, 1)                                         \
310 311
  F(JSReceiverPreventExtensionsDontThrow, 1, 1)                 \
  F(JSReceiverPreventExtensionsThrow, 1, 1)                     \
312
  F(JSReceiverGetPrototypeOf, 1, 1)                             \
313 314
  F(JSReceiverSetPrototypeOfDontThrow, 2, 1)                    \
  F(JSReceiverSetPrototypeOfThrow, 2, 1)                        \
315 316
  F(LoadPrivateGetter, 1, 1)                                    \
  F(LoadPrivateSetter, 1, 1)                                    \
317 318 319 320
  F(NewObject, 2, 1)                                            \
  F(ObjectCreate, 2, 1)                                         \
  F(ObjectEntries, 1, 1)                                        \
  F(ObjectEntriesSkipFastPath, 1, 1)                            \
321
  F(ObjectGetOwnPropertyNames, 1, 1)                            \
322
  F(ObjectGetOwnPropertyNamesTryFast, 1, 1)                     \
323
  F(ObjectHasOwnProperty, 2, 1)                                 \
324
  F(ObjectIsExtensible, 1, 1)                                   \
325
  F(ObjectKeys, 1, 1)                                           \
326 327 328
  F(ObjectValues, 1, 1)                                         \
  F(ObjectValuesSkipFastPath, 1, 1)                             \
  F(OptimizeObjectForAddingMultipleProperties, 2, 1)            \
329
  F(SetDataProperties, 2, 1)                                    \
330 331
  F(SetKeyedProperty, 3, 1)                                     \
  F(SetNamedProperty, 3, 1)                                     \
332
  F(StoreDataPropertyInLiteral, 3, 1)                           \
333 334
  F(ShrinkPropertyDictionary, 1, 1)                             \
  F(ToFastProperties, 1, 1)                                     \
335
  I(ToLength, 1, 1)                                             \
336
  F(ToName, 1, 1)                                               \
337
  I(ToNumber, 1, 1)                                             \
338
  F(ToNumeric, 1, 1)                                            \
339
  I(ToObject, 1, 1)                                             \
Shiyu Zhang's avatar
Shiyu Zhang committed
340
  I(ToStringRT, 1, 1)                                           \
341
  F(TryMigrateInstance, 1, 1)
342

343 344 345 346 347 348 349 350 351
#define FOR_EACH_INTRINSIC_OPERATORS(F, I) \
  F(Add, 2, 1)                             \
  F(Equal, 2, 1)                           \
  F(GreaterThan, 2, 1)                     \
  F(GreaterThanOrEqual, 2, 1)              \
  F(LessThan, 2, 1)                        \
  F(LessThanOrEqual, 2, 1)                 \
  F(NotEqual, 2, 1)                        \
  F(StrictEqual, 2, 1)                     \
352
  F(StrictNotEqual, 2, 1)
353

354 355 356 357 358
#define FOR_EACH_INTRINSIC_PROMISE(F, I) \
  F(EnqueueMicrotask, 1, 1)              \
  F(PromiseHookAfter, 1, 1)              \
  F(PromiseHookBefore, 1, 1)             \
  F(PromiseHookInit, 2, 1)               \
359
  F(AwaitPromisesInit, 5, 1)             \
360
  F(AwaitPromisesInitOld, 5, 1)          \
361 362 363 364
  F(PromiseMarkAsHandled, 1, 1)          \
  F(PromiseRejectEventFromStack, 2, 1)   \
  F(PromiseRevokeReject, 1, 1)           \
  F(PromiseStatus, 1, 1)                 \
365 366
  F(RejectPromise, 3, 1)                 \
  F(ResolvePromise, 2, 1)                \
367
  F(PromiseRejectAfterResolved, 2, 1)    \
368
  F(PromiseResolveAfterResolved, 2, 1)
369

370 371
#define FOR_EACH_INTRINSIC_PROXY(F, I) \
  F(CheckProxyGetSetTrapResult, 2, 1)  \
372
  F(CheckProxyHasTrapResult, 2, 1)     \
373
  F(CheckProxyDeleteTrapResult, 2, 1)  \
374
  F(GetPropertyWithReceiver, 3, 1)     \
375
  F(SetPropertyWithReceiver, 4, 1)
376

377 378
#define FOR_EACH_INTRINSIC_REGEXP(F, I)             \
  I(IsRegExp, 1, 1)                                 \
379
  F(RegExpExec, 4, 1)                               \
380
  F(RegExpExecMultiple, 4, 1)                       \
381
  F(RegExpInitializeAndCompile, 3, 1)               \
382
  F(RegExpReplaceRT, 3, 1)                          \
383
  F(RegExpSplit, 3, 1)                              \
384 385
  F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
  F(StringSplit, 3, 1)
386

Simon Zünd's avatar
Simon Zünd committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
#define FOR_EACH_INTRINSIC_SCOPES(F, I)     \
  F(DeclareEvalFunction, 2, 1)              \
  F(DeclareEvalVar, 1, 1)                   \
  F(DeclareGlobals, 3, 1)                   \
  F(DeleteLookupSlot, 1, 1)                 \
  F(LoadLookupSlot, 1, 1)                   \
  F(LoadLookupSlotInsideTypeof, 1, 1)       \
  F(NewArgumentsElements, 3, 1)             \
                                            \
  F(NewClosure, 2, 1)                       \
  F(NewClosure_Tenured, 2, 1)               \
  F(NewFunctionContext, 1, 1)               \
  F(NewRestParameter, 1, 1)                 \
  F(NewScriptContext, 1, 1)                 \
  F(NewSloppyArguments, 3, 1)               \
  F(NewSloppyArguments_Generic, 1, 1)       \
  F(NewStrictArguments, 1, 1)               \
  F(PushBlockContext, 1, 1)                 \
  F(PushCatchContext, 2, 1)                 \
  F(PushModuleContext, 2, 1)                \
  F(PushWithContext, 2, 1)                  \
  F(StoreGlobalNoHoleCheckForReplLet, 2, 1) \
  F(StoreLookupSlot_Sloppy, 2, 1)           \
  F(StoreLookupSlot_SloppyHoisting, 2, 1)   \
  F(StoreLookupSlot_Strict, 2, 1)           \
412
  F(ThrowConstAssignError, 0, 1)
413

414
#define FOR_EACH_INTRINSIC_STRINGS(F, I)  \
415
  F(FlattenString, 1, 1)                  \
416
  F(GetSubstitution, 5, 1)                \
417 418 419 420 421
  F(InternalizeString, 1, 1)              \
  F(StringAdd, 2, 1)                      \
  F(StringBuilderConcat, 3, 1)            \
  F(StringCharCodeAt, 2, 1)               \
  F(StringEqual, 2, 1)                    \
422
  F(StringEscapeQuotes, 1, 1)             \
423 424
  F(StringGreaterThan, 2, 1)              \
  F(StringGreaterThanOrEqual, 2, 1)       \
425
  F(StringIncludes, 3, 1)                 \
426
  F(StringIndexOf, 3, 1)                  \
427
  F(StringIndexOfUnchecked, 3, 1)         \
428
  F(StringLastIndexOf, 2, 1)              \
429 430
  F(StringLessThan, 2, 1)                 \
  F(StringLessThanOrEqual, 2, 1)          \
431 432
  F(StringMaxLength, 0, 1)                \
  F(StringReplaceOneCharWithString, 3, 1) \
433
  F(StringCompareSequence, 3, 1)          \
434 435 436
  F(StringSubstring, 3, 1)                \
  F(StringToArray, 2, 1)                  \
  F(StringTrim, 2, 1)
437

438
#define FOR_EACH_INTRINSIC_SYMBOL(F, I)    \
439
  F(CreatePrivateNameSymbol, 1, 1)         \
440
  F(CreatePrivateBrandSymbol, 1, 1)        \
441
  F(CreatePrivateSymbol, -1 /* <= 1 */, 1) \
442
  F(SymbolDescriptiveString, 1, 1)         \
443 444
  F(SymbolIsPrivate, 1, 1)

445
#define FOR_EACH_INTRINSIC_TEST(F, I)         \
446 447
  F(Abort, 1, 1)                              \
  F(AbortJS, 1, 1)                            \
448
  F(AbortCSAAssert, 1, 1)                     \
449
  F(ArraySpeciesProtector, 0, 1)              \
450
  F(ClearFunctionFeedback, 1, 1)              \
451
  F(ClearMegamorphicStubCache, 0, 1)          \
452
  F(CloneWasmModule, 1, 1)                    \
453 454 455
  F(CompleteInobjectSlackTracking, 1, 1)      \
  F(ConstructConsString, 2, 1)                \
  F(ConstructDouble, 2, 1)                    \
456
  F(ConstructSlicedString, 2, 1)              \
457 458
  F(DebugPrint, 1, 1)                         \
  F(DebugTrace, 0, 1)                         \
459
  F(DebugTrackRetainingPath, -1, 1)           \
460 461 462 463 464
  F(DeoptimizeFunction, 1, 1)                 \
  F(DeserializeWasmModule, 2, 1)              \
  F(DisallowCodegenFromStrings, 1, 1)         \
  F(DisallowWasmCodegen, 1, 1)                \
  F(DisassembleFunction, 1, 1)                \
465 466
  F(EnableCodeLoggingForTesting, 0, 1)        \
  F(EnsureFeedbackVectorForFunction, 1, 1)    \
467 468
  F(FreezeWasmLazyCompilation, 1, 1)          \
  F(GetCallable, 0, 1)                        \
469
  F(GetInitializerFunction, 1, 1)             \
470 471
  F(GetOptimizationStatus, -1, 1)             \
  F(GetUndetectable, 0, 1)                    \
472
  F(GetWasmExceptionId, 2, 1)                 \
473
  F(GetWasmExceptionValues, 1, 1)             \
474
  F(GetWasmRecoveredTrapCount, 0, 1)          \
475 476
  F(GlobalPrint, 1, 1)                        \
  F(HasDictionaryElements, 1, 1)              \
477
  F(HasDoubleElements, 1, 1)                  \
478
  F(HasElementsInALargeObjectSpace, 1, 1)     \
479
  F(HasFastElements, 1, 1)                    \
480
  F(HasFastProperties, 1, 1)                  \
481 482
  F(HasFixedBigInt64Elements, 1, 1)           \
  F(HasFixedBigUint64Elements, 1, 1)          \
483 484 485 486
  F(HasFixedFloat32Elements, 1, 1)            \
  F(HasFixedFloat64Elements, 1, 1)            \
  F(HasFixedInt16Elements, 1, 1)              \
  F(HasFixedInt32Elements, 1, 1)              \
487 488 489
  F(HasFixedInt8Elements, 1, 1)               \
  F(HasFixedUint16Elements, 1, 1)             \
  F(HasFixedUint32Elements, 1, 1)             \
490
  F(HasFixedUint8ClampedElements, 1, 1)       \
491 492 493
  F(HasFixedUint8Elements, 1, 1)              \
  F(HasHoleyElements, 1, 1)                   \
  F(HasObjectElements, 1, 1)                  \
494
  F(HasPackedElements, 1, 1)                  \
495 496 497 498 499
  F(HasSloppyArgumentsElements, 1, 1)         \
  F(HasSmiElements, 1, 1)                     \
  F(HasSmiOrObjectElements, 1, 1)             \
  F(HaveSameMap, 2, 1)                        \
  F(HeapObjectVerify, 1, 1)                   \
500
  F(ICsAreEnabled, 0, 1)                      \
501
  F(InYoungGeneration, 1, 1)                  \
502
  F(IsAsmWasmCode, 1, 1)                      \
503 504
  F(IsConcurrentRecompilationSupported, 0, 1) \
  F(IsLiftoffFunction, 1, 1)                  \
505
  F(IsThreadInWasm, 0, 1)                     \
506
  F(IsWasmCode, 1, 1)                         \
507
  F(IsWasmTrapHandlerEnabled, 0, 1)           \
508 509
  F(RegexpHasBytecode, 2, 1)                  \
  F(RegexpHasNativeCode, 2, 1)                \
510
  F(MapIteratorProtector, 0, 1)               \
511 512 513 514
  F(NeverOptimizeFunction, 1, 1)              \
  F(NotifyContextDisposed, 0, 1)              \
  F(OptimizeFunctionOnNextCall, -1, 1)        \
  F(OptimizeOsr, -1, 1)                       \
515
  F(NewRegExpWithBacktrackLimit, 3, 1)        \
516
  F(PrepareFunctionForOptimization, -1, 1)    \
517 518 519
  F(PrintWithNameForAssert, 2, 1)             \
  F(RedirectToWasmInterpreter, 2, 1)          \
  F(RunningInSimulator, 0, 1)                 \
Simon Zünd's avatar
Simon Zünd committed
520
  F(RuntimeEvaluateREPL, 1, 1)                \
521 522 523
  F(SerializeWasmModule, 1, 1)                \
  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
  F(SetForceSlowPath, 1, 1)                   \
524
  F(SetIteratorProtector, 0, 1)               \
525 526
  F(SetWasmCompileControls, 2, 1)             \
  F(SetWasmInstantiateControls, 0, 1)         \
527
  F(SetWasmThreadsEnabled, 1, 1)              \
528
  F(SimulateNewspaceFull, 0, 1)               \
529
  F(StringIteratorProtector, 0, 1)            \
530 531 532
  F(SystemBreak, 0, 1)                        \
  F(TraceEnter, 0, 1)                         \
  F(TraceExit, 1, 1)                          \
533
  F(TurbofanStaticAssert, 1, 1)               \
534
  F(UnblockConcurrentRecompilation, 0, 1)     \
535
  F(WasmGetNumberOfInstances, 1, 1)           \
536
  F(WasmNumInterpretedCalls, 1, 1)            \
537
  F(WasmNumCodeSpaces, 1, 1)                  \
538
  F(WasmTierUpFunction, 2, 1)                 \
539
  F(WasmTraceMemory, 1, 1)                    \
540
  I(DeoptimizeNow, 0, 1)
541

542
#define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \
543
  F(ArrayBufferDetach, 1, 1)                \
544 545 546
  F(TypedArrayCopyElements, 3, 1)           \
  F(TypedArrayGetBuffer, 1, 1)              \
  F(TypedArraySet, 2, 1)                    \
547
  F(TypedArraySortFast, 1, 1)
548

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
#define FOR_EACH_INTRINSIC_WASM(F, I)   \
  F(ThrowWasmError, 1, 1)               \
  F(ThrowWasmStackOverflow, 0, 1)       \
  F(WasmI32AtomicWait, 4, 1)            \
  F(WasmI64AtomicWait, 5, 1)            \
  F(WasmAtomicNotify, 3, 1)             \
  F(WasmExceptionGetValues, 1, 1)       \
  F(WasmExceptionGetTag, 1, 1)          \
  F(WasmMemoryGrow, 2, 1)               \
  F(WasmRunInterpreter, 2, 1)           \
  F(WasmStackGuard, 0, 1)               \
  F(WasmThrowCreate, 2, 1)              \
  F(WasmThrowTypeError, 0, 1)           \
  F(WasmRefFunc, 1, 1)                  \
  F(WasmFunctionTableGet, 3, 1)         \
  F(WasmFunctionTableSet, 4, 1)         \
  F(WasmTableInit, 5, 1)                \
  F(WasmTableCopy, 5, 1)                \
  F(WasmTableGrow, 3, 1)                \
  F(WasmTableFill, 4, 1)                \
  F(WasmIsValidFuncRefValue, 1, 1)      \
  F(WasmCompileLazy, 2, 1)              \
  F(WasmNewMultiReturnFixedArray, 1, 1) \
572
  F(WasmNewMultiReturnJSArray, 1, 1)
573

574 575
#define FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
  F(DebugBreakOnBytecode, 1, 2)                   \
576
  F(LoadLookupSlotForCall, 1, 2)
577

578 579
// Most intrinsics are implemented in the runtime/ directory, but ICs are
// implemented in ic.cc for now.
580
#define FOR_EACH_INTRINSIC_IC(F, I)          \
581 582 583
  F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
  F(KeyedLoadIC_Miss, 4, 1)                  \
  F(KeyedStoreIC_Miss, 5, 1)                 \
584
  F(StoreInArrayLiteralIC_Miss, 5, 1)        \
585
  F(KeyedStoreIC_Slow, 3, 1)                 \
586
  F(LoadElementWithInterceptor, 2, 1)        \
587
  F(LoadGlobalIC_Miss, 4, 1)                 \
588
  F(LoadGlobalIC_Slow, 3, 1)                 \
589
  F(LoadIC_Miss, 4, 1)                       \
590
  F(LoadNoFeedbackIC_Miss, 4, 1)             \
591
  F(LoadPropertyWithInterceptor, 5, 1)       \
592
  F(StoreCallbackProperty, 5, 1)             \
593
  F(StoreGlobalIC_Miss, 4, 1)                \
594
  F(StoreGlobalICNoFeedback_Miss, 2, 1)      \
595
  F(StoreGlobalIC_Slow, 5, 1)                \
596
  F(StoreIC_Miss, 5, 1)                      \
597
  F(StoreInArrayLiteralIC_Slow, 5, 1)        \
598
  F(StorePropertyWithInterceptor, 5, 1)      \
599 600 601
  F(CloneObjectIC_Miss, 4, 1)                \
  F(KeyedHasIC_Miss, 4, 1)                   \
  F(HasElementWithInterceptor, 2, 1)
602

603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
#define FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I) \
  FOR_EACH_INTRINSIC_ARRAY(F, I)                    \
  FOR_EACH_INTRINSIC_ATOMICS(F, I)                  \
  FOR_EACH_INTRINSIC_BIGINT(F, I)                   \
  FOR_EACH_INTRINSIC_CLASSES(F, I)                  \
  FOR_EACH_INTRINSIC_COLLECTIONS(F, I)              \
  FOR_EACH_INTRINSIC_COMPILER(F, I)                 \
  FOR_EACH_INTRINSIC_DATE(F, I)                     \
  FOR_EACH_INTRINSIC_DEBUG(F, I)                    \
  FOR_EACH_INTRINSIC_FORIN(F, I)                    \
  FOR_EACH_INTRINSIC_FUNCTION(F, I)                 \
  FOR_EACH_INTRINSIC_GENERATOR(F, I)                \
  FOR_EACH_INTRINSIC_IC(F, I)                       \
  FOR_EACH_INTRINSIC_INTERNAL(F, I)                 \
  FOR_EACH_INTRINSIC_INTERPRETER(F, I)              \
  FOR_EACH_INTRINSIC_INTL(F, I)                     \
  FOR_EACH_INTRINSIC_LITERALS(F, I)                 \
  FOR_EACH_INTRINSIC_MODULE(F, I)                   \
  FOR_EACH_INTRINSIC_NUMBERS(F, I)                  \
  FOR_EACH_INTRINSIC_OBJECT(F, I)                   \
  FOR_EACH_INTRINSIC_OPERATORS(F, I)                \
  FOR_EACH_INTRINSIC_PROMISE(F, I)                  \
  FOR_EACH_INTRINSIC_PROXY(F, I)                    \
  FOR_EACH_INTRINSIC_REGEXP(F, I)                   \
  FOR_EACH_INTRINSIC_SCOPES(F, I)                   \
  FOR_EACH_INTRINSIC_STRINGS(F, I)                  \
  FOR_EACH_INTRINSIC_SYMBOL(F, I)                   \
  FOR_EACH_INTRINSIC_TEST(F, I)                     \
  FOR_EACH_INTRINSIC_TYPEDARRAY(F, I)               \
  FOR_EACH_INTRINSIC_WASM(F, I)

// Defines the list of all intrinsics, coming in 2 flavors, either returning an
// object or a pair.
#define FOR_EACH_INTRINSIC_IMPL(F, I)       \
  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, I) \
  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, I)

640
#define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
641
  FOR_EACH_INTRINSIC_RETURN_OBJECT_IMPL(F, F)
642

643 644 645 646 647 648 649 650 651
#define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
  FOR_EACH_INTRINSIC_RETURN_PAIR_IMPL(F, F)

// The list of all intrinsics, including those that have inline versions, but
// not the inline versions themselves.
#define FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC_IMPL(F, F)

// The list of all inline intrinsics only.
#define FOR_EACH_INLINE_INTRINSIC(I) FOR_EACH_INTRINSIC_IMPL(NOTHING, I)
652

653
#define F(name, nargs, ressize)                                 \
654
  Address Runtime_##name(int args_length, Address* args_object, \
655 656 657 658
                         Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
#undef F

659
//---------------------------------------------------------------------------
660 661 662 663
// Runtime provides access to all C++ runtime functions.

class Runtime : public AllStatic {
 public:
664
  enum FunctionId : int32_t {
665
#define F(name, nargs, ressize) k##name,
666
#define I(name, nargs, ressize) kInline##name,
667
    FOR_EACH_INTRINSIC(F) FOR_EACH_INLINE_INTRINSIC(I)
668
#undef I
669
#undef F
670
        kNumFunctions,
671 672
  };

673 674 675 676 677
  static constexpr int kNumInlineFunctions =
#define COUNT(...) +1
      FOR_EACH_INLINE_INTRINSIC(COUNT);
#undef COUNT

678
  enum IntrinsicType { RUNTIME, INLINE };
679

680
  // Intrinsic function descriptor.
681
  struct Function {
682 683
    FunctionId function_id;
    IntrinsicType intrinsic_type;
684 685 686
    // The JS name of the function.
    const char* name;

687 688 689
    // For RUNTIME functions, this is the C++ entry point.
    // For INLINE functions this is the C++ entry point of the fall back.
    Address entry;
690

691 692
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
693
    int8_t nargs;
694
    // Size of result.  Most functions return a single pointer, size 1.
695
    int8_t result_size;
696 697
  };

698 699
  static const int kNotFound = -1;

700 701 702 703 704
  // Checks whether the runtime function with the given {id} depends on the
  // "current context", i.e. because it does scoped lookups, or whether it's
  // fine to just pass any context within the same "native context".
  static bool NeedsExactContext(FunctionId id);

705 706 707 708 709 710
  // Checks whether the runtime function with the given {id} never returns
  // to it's caller normally, i.e. whether it'll always raise an exception.
  // More specifically: The C++ implementation returns the Heap::exception
  // sentinel, always.
  static bool IsNonReturning(FunctionId id);

711 712 713 714
  // Check if a runtime function with the given {id}  may trigger a heap
  // allocation.
  static bool MayAllocate(FunctionId id);

715 716
  // Get the intrinsic function with the given name.
  static const Function* FunctionForName(const unsigned char* name, int length);
717

718
  // Get the intrinsic function with the given FunctionId.
719
  V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
720

721 722 723
  // Get the intrinsic function with the given function entry address.
  static const Function* FunctionForEntry(Address ref);

724 725 726
  // Get the runtime intrinsic function table.
  static const Function* RuntimeFunctionTable(Isolate* isolate);

727
  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteObjectProperty(
728 729 730
      Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
      LanguageMode language_mode);

731 732 733 734 735 736 737 738
  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
  SetObjectProperty(Isolate* isolate, Handle<Object> object, Handle<Object> key,
                    Handle<Object> value, StoreOrigin store_origin,
                    Maybe<ShouldThrow> should_throw = Nothing<ShouldThrow>());

  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
  GetObjectProperty(Isolate* isolate, Handle<Object> object, Handle<Object> key,
                    bool* is_found_out = nullptr);
739

740 741 742
  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> HasProperty(
      Isolate* isolate, Handle<Object> object, Handle<Object> key);

743
  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetInternalProperties(
744
      Isolate* isolate, Handle<Object>);
745

746
  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ThrowIteratorError(
747
      Isolate* isolate, Handle<Object> object);
748 749
};

750 751
class RuntimeState {
 public:
752
#ifndef V8_INTL_SUPPORT
753 754 755 756 757 758
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }
759
#endif
760 761 762 763 764 765 766

  Runtime::Function* redirected_intrinsic_functions() {
    return redirected_intrinsic_functions_.get();
  }

  void set_redirected_intrinsic_functions(
      Runtime::Function* redirected_intrinsic_functions) {
767
    redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
768 769 770
  }

 private:
771
  RuntimeState() = default;
772
#ifndef V8_INTL_SUPPORT
773 774
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
775
#endif
776

777
  std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
778 779 780 781 782 783 784

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};

785
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
786

787 788 789
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.

790
using AllocateDoubleAlignFlag = base::BitField<bool, 0, 1>;
791

792
using AllowLargeObjectAllocationFlag = base::BitField<bool, 1, 1>;
793

794
using DeclareGlobalsEvalFlag = base::BitField<bool, 0, 1>;
795

796 797 798 799 800 801 802 803 804 805
// A set of bits returned by Runtime_GetOptimizationStatus.
// These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
enum class OptimizationStatus {
  kIsFunction = 1 << 0,
  kNeverOptimize = 1 << 1,
  kAlwaysOptimize = 1 << 2,
  kMaybeDeopted = 1 << 3,
  kOptimized = 1 << 4,
  kTurboFanned = 1 << 5,
  kInterpreted = 1 << 6,
806 807 808 809 810
  kMarkedForOptimization = 1 << 7,
  kMarkedForConcurrentOptimization = 1 << 8,
  kOptimizingConcurrently = 1 << 9,
  kIsExecuting = 1 << 10,
  kTopmostFrameIsTurboFanned = 1 << 11,
811
  kLiteMode = 1 << 12,
812
  kMarkedForDeoptimization = 1 << 13,
813 814
};

815 816
}  // namespace internal
}  // namespace v8
817

818
#endif  // V8_RUNTIME_RUNTIME_H_