runtime.h 36.3 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 "src/allocation.h"
11
#include "src/base/platform/time.h"
12
#include "src/elements-kind.h"
13
#include "src/globals.h"
14
#include "src/unicode.h"
15
#include "src/zone/zone.h"
16

17 18
namespace v8 {
namespace internal {
19

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// * Each intrinsic is consistently exposed in JavaScript via 2 names:
//    * %#name, which is always a runtime call.
//    * %_#name, which can be inlined or just a runtime call, the compiler in
//      question decides.
//
// * 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):
36 37
// A variable number of arguments is specified by a -1, additional restrictions
// are specified by inline comments
38

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#define FOR_EACH_INTRINSIC_ARRAY(F)      \
  F(TransitionElementsKind, 2, 1)        \
  F(RemoveArrayHoles, 2, 1)              \
  F(MoveArrayContents, 2, 1)             \
  F(EstimateNumberOfElements, 1, 1)      \
  F(GetArrayKeys, 2, 1)                  \
  F(TrySliceSimpleNonFastElements, 3, 1) \
  F(NewArray, -1 /* >= 3 */, 1)          \
  F(FunctionBind, -1, 1)                 \
  F(NormalizeElements, 1, 1)             \
  F(GrowArrayElements, 2, 1)             \
  F(HasComplexElements, 1, 1)            \
  F(IsArray, 1, 1)                       \
  F(ArrayIsArray, 1, 1)                  \
  F(ArraySpeciesConstructor, 1, 1)       \
  F(ArrayIncludes_Slow, 3, 1)            \
  F(ArrayIndexOf, 3, 1)                  \
56
  F(SpreadIterablePrepare, 1, 1)
57

58 59 60 61
#define FOR_EACH_INTRINSIC_ATOMICS(F)           \
  F(ThrowNotIntegerSharedTypedArrayError, 1, 1) \
  F(ThrowNotInt32SharedTypedArrayError, 1, 1)   \
  F(ThrowInvalidAtomicAccessIndexError, 0, 1)   \
62
  F(AtomicsExchange, 3, 1)                      \
63
  F(AtomicsCompareExchange, 4, 1)               \
64 65 66 67 68
  F(AtomicsAdd, 3, 1)                           \
  F(AtomicsSub, 3, 1)                           \
  F(AtomicsAnd, 3, 1)                           \
  F(AtomicsOr, 3, 1)                            \
  F(AtomicsXor, 3, 1)                           \
69 70
  F(AtomicsNumWaitersForTesting, 2, 1)          \
  F(SetAllowAtomicsWait, 1, 1)
binji's avatar
binji committed
71

72
#define FOR_EACH_INTRINSIC_BIGINT(F) \
73
  F(BigIntBinaryOp, 3, 1)            \
74
  F(BigIntEqual, 2, 1)               \
75 76
  F(BigIntEqualToNumber, 2, 1)       \
  F(BigIntEqualToString, 2, 1)       \
77 78
  F(BigIntToBoolean, 1, 1)           \
  F(BigIntUnaryOp, 2, 1)
79

80 81 82 83
#define FOR_EACH_INTRINSIC_CLASSES(F)        \
  F(ThrowUnsupportedSuperError, 0, 1)        \
  F(ThrowConstructorNonCallableError, 1, 1)  \
  F(ThrowStaticPrototypeError, 0, 1)         \
84
  F(ThrowSuperAlreadyCalledError, 0, 1)      \
85
  F(ThrowSuperNotCalled, 0, 1)               \
86
  F(ThrowNotSuperConstructor, 2, 1)          \
87 88 89 90 91 92 93 94 95 96
  F(HomeObjectSymbol, 0, 1)                  \
  F(DefineClass, 4, 1)                       \
  F(InstallClassNameAccessor, 1, 1)          \
  F(InstallClassNameAccessorWithCheck, 1, 1) \
  F(LoadFromSuper, 3, 1)                     \
  F(LoadKeyedFromSuper, 3, 1)                \
  F(StoreToSuper_Strict, 4, 1)               \
  F(StoreToSuper_Sloppy, 4, 1)               \
  F(StoreKeyedToSuper_Strict, 4, 1)          \
  F(StoreKeyedToSuper_Sloppy, 4, 1)          \
97
  F(GetSuperConstructor, 1, 1)
98 99 100 101

#define FOR_EACH_INTRINSIC_COLLECTIONS(F) \
  F(TheHole, 0, 1)                        \
  F(GenericHash, 1, 1)                    \
102
  F(GetExistingHash, 1, 1)                \
103 104 105 106 107 108 109 110
  F(SetGrow, 1, 1)                        \
  F(SetShrink, 1, 1)                      \
  F(SetIteratorClone, 1, 1)               \
  F(MapShrink, 1, 1)                      \
  F(MapGrow, 1, 1)                        \
  F(MapIteratorClone, 1, 1)               \
  F(GetWeakMapEntries, 2, 1)              \
  F(WeakCollectionInitialize, 1, 1)       \
111 112
  F(WeakCollectionDelete, 3, 1)           \
  F(WeakCollectionSet, 4, 1)              \
113 114 115 116 117
  F(GetWeakSetValues, 2, 1)               \
  F(IsJSMap, 1, 1)                        \
  F(IsJSSet, 1, 1)                        \
  F(IsJSWeakMap, 1, 1)                    \
  F(IsJSWeakSet, 1, 1)
118

119 120 121 122
#define FOR_EACH_INTRINSIC_COMPILER(F)    \
  F(CompileLazy, 1, 1)                    \
  F(CompileOptimized_Concurrent, 1, 1)    \
  F(CompileOptimized_NotConcurrent, 1, 1) \
123
  F(EvictOptimizedCodeSlot, 1, 1)         \
124
  F(NotifyDeoptimized, 0, 1)              \
125
  F(CompileForOnStackReplacement, 1, 1)   \
126 127
  F(ResolvePossiblyDirectEval, 6, 1)      \
  F(InstantiateAsmJs, 4, 1)
128 129

#define FOR_EACH_INTRINSIC_DATE(F) \
130
  F(IsDate, 1, 1)                  \
131
  F(DateCurrentTime, 0, 1)         \
132
  F(ThrowNotDateError, 0, 1)
133

134 135 136 137 138 139 140 141
#define FOR_EACH_INTRINSIC_DEBUG(F)             \
  F(HandleDebuggerStatement, 0, 1)              \
  F(DebugBreakOnBytecode, 1, 1)                 \
  F(SetDebugEventListener, 2, 1)                \
  F(ScheduleBreak, 0, 1)                        \
  F(DebugGetInternalProperties, 1, 1)           \
  F(DebugGetPropertyDetails, 2, 1)              \
  F(DebugGetProperty, 2, 1)                     \
142
  F(DebugPropertyKindFromDetails, 1, 1)         \
143 144 145 146 147 148 149 150 151
  F(DebugPropertyAttributesFromDetails, 1, 1)   \
  F(CheckExecutionState, 1, 1)                  \
  F(GetFrameCount, 1, 1)                        \
  F(GetFrameDetails, 2, 1)                      \
  F(GetScopeCount, 2, 1)                        \
  F(GetScopeDetails, 4, 1)                      \
  F(GetAllScopesDetails, 4, 1)                  \
  F(GetFunctionScopeCount, 1, 1)                \
  F(GetFunctionScopeDetails, 2, 1)              \
152 153
  F(GetGeneratorScopeCount, 1, 1)               \
  F(GetGeneratorScopeDetails, 2, 1)             \
154 155 156
  F(SetScopeVariableValue, 6, 1)                \
  F(DebugPrintScopes, 0, 1)                     \
  F(SetBreakPointsActive, 1, 1)                 \
157
  F(GetBreakLocations, 1, 1)                    \
158
  F(SetFunctionBreakPoint, 3, 1)                \
159
  F(SetScriptBreakPoint, 3, 1)                  \
160 161 162 163 164
  F(ClearBreakPoint, 1, 1)                      \
  F(ChangeBreakOnException, 2, 1)               \
  F(IsBreakOnException, 1, 1)                   \
  F(PrepareStep, 2, 1)                          \
  F(ClearStepping, 0, 1)                        \
165
  F(DebugEvaluate, 5, 1)                        \
166
  F(DebugEvaluateGlobal, 2, 1)                  \
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  F(DebugGetLoadedScripts, 0, 1)                \
  F(DebugReferencedBy, 3, 1)                    \
  F(DebugConstructedBy, 2, 1)                   \
  F(DebugGetPrototype, 1, 1)                    \
  F(DebugSetScriptSource, 2, 1)                 \
  F(FunctionGetInferredName, 1, 1)              \
  F(FunctionGetDebugName, 1, 1)                 \
  F(GetDebugContext, 0, 1)                      \
  F(CollectGarbage, 1, 1)                       \
  F(GetHeapUsage, 0, 1)                         \
  F(GetScript, 1, 1)                            \
  F(ScriptLineCount, 1, 1)                      \
  F(ScriptLineStartPosition, 2, 1)              \
  F(ScriptLineEndPosition, 2, 1)                \
  F(ScriptLocationFromLine, 4, 1)               \
182
  F(ScriptLocationFromLine2, 4, 1)              \
183
  F(ScriptPositionInfo, 3, 1)                   \
184
  F(ScriptPositionInfo2, 3, 1)                  \
185
  F(ScriptSourceLine, 2, 1)                     \
186
  F(DebugOnFunctionCall, 1, 1)                  \
187
  F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
188
  F(DebugRecordGenerator, 1, 1)                 \
189
  F(DebugPushPromise, 1, 1)                     \
190
  F(DebugPopPromise, 0, 1)                      \
191
  F(DebugPromiseReject, 2, 1)                   \
192 193
  F(DebugAsyncEventEnqueueRecurring, 2, 1)      \
  F(DebugAsyncFunctionPromiseCreated, 1, 1)     \
194
  F(DebugIsActive, 0, 1)                        \
195
  F(DebugBreakInOptimizedCode, 0, 1)            \
196
  F(DebugCollectCoverage, 0, 1)                 \
197 198 199
  F(DebugTogglePreciseCoverage, 1, 1)           \
  F(DebugToggleBlockCoverage, 1, 1)             \
  F(IncBlockCounter, 2, 1)
200

201 202
#define FOR_EACH_INTRINSIC_ERROR(F) F(ErrorToString, 1, 1)

203
#define FOR_EACH_INTRINSIC_FORIN(F) \
204
  F(ForInEnumerate, 1, 1)           \
205
  F(ForInHasProperty, 2, 1)
206

207 208 209 210 211 212 213 214
#ifdef V8_TRACE_IGNITION
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F) \
  F(InterpreterTraceBytecodeEntry, 3, 1)        \
  F(InterpreterTraceBytecodeExit, 3, 1)
#else
#define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F)
#endif

215 216
#define FOR_EACH_INTRINSIC_INTERPRETER(F) \
  FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F) \
217
  F(InterpreterNewClosure, 4, 1)
218

219 220 221
#define FOR_EACH_INTRINSIC_FUNCTION(F)     \
  F(FunctionGetName, 1, 1)                 \
  F(FunctionGetScript, 1, 1)               \
222
  F(FunctionGetScriptId, 1, 1)             \
223 224
  F(FunctionGetSourceCode, 1, 1)           \
  F(FunctionGetScriptSourcePosition, 1, 1) \
225
  F(FunctionGetContextData, 1, 1)          \
226 227 228 229 230 231 232 233 234 235
  F(FunctionSetLength, 2, 1)               \
  F(FunctionSetPrototype, 2, 1)            \
  F(FunctionIsAPIFunction, 1, 1)           \
  F(SetCode, 2, 1)                         \
  F(SetNativeFlag, 1, 1)                   \
  F(IsConstructor, 1, 1)                   \
  F(Call, -1 /* >= 2 */, 1)                \
  F(ConvertReceiver, 1, 1)                 \
  F(IsFunction, 1, 1)                      \
  F(FunctionToString, 1, 1)
236

237 238 239 240 241 242 243 244 245 246 247 248
#define FOR_EACH_INTRINSIC_GENERATOR(F) \
  F(CreateJSGeneratorObject, 2, 1)      \
  F(GeneratorClose, 1, 1)               \
  F(GeneratorGetFunction, 1, 1)         \
  F(GeneratorGetReceiver, 1, 1)         \
  F(GeneratorGetContext, 1, 1)          \
  F(GeneratorGetInputOrDebugPos, 1, 1)  \
  F(AsyncGeneratorResolve, 3, 1)        \
  F(AsyncGeneratorReject, 2, 1)         \
  F(AsyncGeneratorYield, 3, 1)          \
  F(GeneratorGetContinuation, 1, 1)     \
  F(GeneratorGetSourcePosition, 1, 1)   \
249 250
  F(GeneratorGetResumeMode, 1, 1)       \
  F(AsyncGeneratorHasCatchHandlerForPC, 1, 1)
251

252 253
#ifdef V8_INTL_SUPPORT
#define FOR_EACH_INTRINSIC_INTL(F)           \
254 255 256 257 258
  F(CanonicalizeLanguageTag, 1, 1)           \
  F(AvailableLocalesOf, 1, 1)                \
  F(GetDefaultICULocale, 0, 1)               \
  F(IsInitializedIntlObject, 1, 1)           \
  F(IsInitializedIntlObjectOfType, 2, 1)     \
259
  F(MarkAsInitializedIntlObjectOfType, 2, 1) \
260 261
  F(CreateDateTimeFormat, 3, 1)              \
  F(InternalDateFormat, 2, 1)                \
262
  F(InternalDateFormatToParts, 2, 1)         \
263 264
  F(CreateNumberFormat, 3, 1)                \
  F(InternalNumberFormat, 2, 1)              \
265
  F(CurrencyDigits, 1, 1)                    \
266 267
  F(CreateCollator, 3, 1)                    \
  F(InternalCompare, 3, 1)                   \
268 269
  F(CreatePluralRules, 3, 1)                 \
  F(PluralRulesSelect, 2, 1)                 \
270 271 272 273 274
  F(CreateBreakIterator, 3, 1)               \
  F(BreakIteratorAdoptText, 2, 1)            \
  F(BreakIteratorFirst, 1, 1)                \
  F(BreakIteratorNext, 1, 1)                 \
  F(BreakIteratorCurrent, 1, 1)              \
275
  F(BreakIteratorBreakType, 1, 1)            \
276 277
  F(StringToLowerCaseIntl, 1, 1)             \
  F(StringToUpperCaseIntl, 1, 1)             \
278 279
  F(StringLocaleConvertCase, 3, 1)           \
  F(DateCacheVersion, 0, 1)
280
#else
281
#define FOR_EACH_INTRINSIC_INTL(F)
282 283
#endif

284 285 286
#define FOR_EACH_INTRINSIC_INTERNAL(F)                               \
  F(AllocateInNewSpace, 1, 1)                                        \
  F(AllocateInTargetSpace, 2, 1)                                     \
287 288
  F(AllocateSeqOneByteString, 1, 1)                                  \
  F(AllocateSeqTwoByteString, 1, 1)                                  \
289 290 291
  F(CheckIsBootstrapping, 0, 1)                                      \
  F(CreateAsyncFromSyncIterator, 1, 1)                               \
  F(CreateListFromArrayLike, 1, 1)                                   \
292
  F(DeserializeLazy, 1, 1)                                           \
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
  F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1)                   \
  F(ExportFromRuntime, 1, 1)                                         \
  F(IncrementUseCounter, 1, 1)                                       \
  F(IncrementUseCounterConstructorReturnNonUndefinedPrimitive, 0, 1) \
  F(InstallToContext, 1, 1)                                          \
  F(Interrupt, 0, 1)                                                 \
  F(IS_VAR, 1, 1)                                                    \
  F(NewReferenceError, 2, 1)                                         \
  F(NewSyntaxError, 2, 1)                                            \
  F(NewTypeError, 2, 1)                                              \
  F(OrdinaryHasInstance, 2, 1)                                       \
  F(PromoteScheduledException, 0, 1)                                 \
  F(ReThrow, 1, 1)                                                   \
  F(RunMicrotasks, 0, 1)                                             \
  F(StackGuard, 0, 1)                                                \
  F(Throw, 1, 1)                                                     \
  F(ThrowApplyNonFunction, 1, 1)                                     \
  F(ThrowCannotConvertToPrimitive, 0, 1)                             \
  F(ThrowCalledNonCallable, 1, 1)                                    \
  F(ThrowCalledOnNullOrUndefined, 1, 1)                              \
  F(ThrowConstructedNonConstructable, 1, 1)                          \
  F(ThrowConstructorReturnedNonObject, 0, 1)                         \
  F(ThrowGeneratorRunning, 0, 1)                                     \
  F(ThrowIncompatibleMethodReceiver, 2, 1)                           \
  F(ThrowInvalidHint, 1, 1)                                          \
  F(ThrowInvalidStringLength, 0, 1)                                  \
  F(ThrowInvalidTypedArrayAlignment, 2, 1)                           \
  F(ThrowIteratorResultNotAnObject, 1, 1)                            \
  F(ThrowThrowMethodMissing, 0, 1)                                   \
  F(ThrowSymbolIteratorInvalid, 0, 1)                                \
  F(ThrowNonCallableInInstanceOfCheck, 0, 1)                         \
  F(ThrowNonObjectInInstanceOfCheck, 0, 1)                           \
  F(ThrowNotConstructor, 1, 1)                                       \
  F(ThrowRangeError, -1 /* >= 1 */, 1)                               \
  F(ThrowReferenceError, 1, 1)                                       \
  F(ThrowStackOverflow, 0, 1)                                        \
  F(ThrowSymbolAsyncIteratorInvalid, 0, 1)                           \
  F(ThrowTypeError, -1 /* >= 1 */, 1)                                \
  F(ThrowUndefinedOrNullToObject, 1, 1)                              \
  F(Typeof, 1, 1)                                                    \
  F(UnwindAndFindExceptionHandler, 0, 1)                             \
334 335
  F(AllowDynamicFunction, 1, 1)                                      \
  F(GetTemplateObject, 1, 1)
336

337 338 339
#define FOR_EACH_INTRINSIC_LITERALS(F) \
  F(CreateRegExpLiteral, 4, 1)         \
  F(CreateObjectLiteral, 4, 1)         \
340
  F(CreateArrayLiteral, 4, 1)
341 342 343 344 345

#define FOR_EACH_INTRINSIC_LIVEEDIT(F)              \
  F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
  F(LiveEditGatherCompileInfo, 2, 1)                \
  F(LiveEditReplaceScript, 3, 1)                    \
346
  F(LiveEditFunctionSourceUpdated, 2, 1)            \
347
  F(LiveEditReplaceFunctionCode, 2, 1)              \
348
  F(LiveEditFixupScript, 2, 1)                      \
349 350 351
  F(LiveEditFunctionSetScript, 2, 1)                \
  F(LiveEditReplaceRefToNestedFunction, 3, 1)       \
  F(LiveEditPatchFunctionPositions, 2, 1)           \
352
  F(LiveEditCheckAndDropActivations, 3, 1)          \
353 354 355
  F(LiveEditCompareStrings, 2, 1)                   \
  F(LiveEditRestartFrame, 2, 1)

356
#define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1)
357

358
#define FOR_EACH_INTRINSIC_MODULE(F) \
359
  F(DynamicImportCall, 2, 1)         \
360
  F(GetImportMetaObject, 0, 1)       \
361
  F(GetModuleNamespace, 1, 1)        \
362 363
  F(LoadModuleVariable, 1, 1)        \
  F(StoreModuleVariable, 2, 1)
364

365 366 367 368 369
#define FOR_EACH_INTRINSIC_NUMBERS(F)  \
  F(IsValidSmi, 1, 1)                  \
  F(StringToNumber, 1, 1)              \
  F(StringParseInt, 2, 1)              \
  F(StringParseFloat, 1, 1)            \
370
  F(NumberToString, 1, 1)              \
371 372 373 374 375
  F(NumberToStringSkipCache, 1, 1)     \
  F(NumberToSmi, 1, 1)                 \
  F(SmiLexicographicCompare, 2, 1)     \
  F(MaxSmi, 0, 1)                      \
  F(IsSmi, 1, 1)                       \
balazs.kilvady's avatar
balazs.kilvady committed
376 377
  F(GetHoleNaNUpper, 0, 1)             \
  F(GetHoleNaNLower, 0, 1)
378

379
#define FOR_EACH_INTRINSIC_OBJECT(F)                            \
380
  F(AddDictionaryProperty, 3, 1)                                \
381
  F(GetPrototype, 1, 1)                                         \
382
  F(ObjectKeys, 1, 1)                                           \
383 384 385 386 387 388 389 390 391 392
  F(ObjectHasOwnProperty, 2, 1)                                 \
  F(ObjectCreate, 2, 1)                                         \
  F(InternalSetPrototype, 2, 1)                                 \
  F(OptimizeObjectForAddingMultipleProperties, 2, 1)            \
  F(GetProperty, 2, 1)                                          \
  F(KeyedGetProperty, 2, 1)                                     \
  F(AddNamedProperty, 4, 1)                                     \
  F(SetProperty, 4, 1)                                          \
  F(AddElement, 3, 1)                                           \
  F(AppendElement, 2, 1)                                        \
393
  F(DeleteProperty, 3, 1)                                       \
394
  F(ShrinkPropertyDictionary, 1, 1)                             \
395 396 397 398 399 400 401 402 403 404 405 406
  F(HasProperty, 2, 1)                                          \
  F(GetOwnPropertyKeys, 2, 1)                                   \
  F(GetInterceptorInfo, 1, 1)                                   \
  F(ToFastProperties, 1, 1)                                     \
  F(AllocateHeapNumber, 0, 1)                                   \
  F(NewObject, 2, 1)                                            \
  F(FinalizeInstanceSize, 1, 1)                                 \
  F(LoadMutableDouble, 2, 1)                                    \
  F(TryMigrateInstance, 1, 1)                                   \
  F(IsJSGlobalProxy, 1, 1)                                      \
  F(DefineAccessorPropertyUnchecked, 5, 1)                      \
  F(DefineDataPropertyInLiteral, 6, 1)                          \
407
  F(CollectTypeProfile, 3, 1)                                   \
408 409 410 411 412 413 414 415 416 417
  F(GetDataProperty, 2, 1)                                      \
  F(GetConstructorName, 1, 1)                                   \
  F(HasFastPackedElements, 1, 1)                                \
  F(ValueOf, 1, 1)                                              \
  F(IsJSReceiver, 1, 1)                                         \
  F(ClassOf, 1, 1)                                              \
  F(CopyDataProperties, 2, 1)                                   \
  F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
  F(DefineGetterPropertyUnchecked, 4, 1)                        \
  F(DefineSetterPropertyUnchecked, 4, 1)                        \
418
  F(DefineMethodsInternal, 3, 1)                                \
419 420 421 422
  F(ToObject, 1, 1)                                             \
  F(ToPrimitive, 1, 1)                                          \
  F(ToPrimitive_Number, 1, 1)                                   \
  F(ToNumber, 1, 1)                                             \
423
  F(ToNumeric, 1, 1)                                            \
424 425 426 427 428 429 430 431 432
  F(ToInteger, 1, 1)                                            \
  F(ToLength, 1, 1)                                             \
  F(ToString, 1, 1)                                             \
  F(ToName, 1, 1)                                               \
  F(SameValue, 2, 1)                                            \
  F(SameValueZero, 2, 1)                                        \
  F(Compare, 3, 1)                                              \
  F(HasInPrototypeChain, 2, 1)                                  \
  F(CreateIterResultObject, 2, 1)                               \
433
  F(CreateDataProperty, 3, 1)                                   \
434 435
  F(IterableToListCanBeElided, 1, 1)                            \
  F(GetOwnPropertyDescriptor, 2, 1)
436

437 438 439 440 441 442 443 444 445 446 447
#define FOR_EACH_INTRINSIC_OPERATORS(F) \
  F(Multiply, 2, 1)                     \
  F(Divide, 2, 1)                       \
  F(Modulus, 2, 1)                      \
  F(Add, 2, 1)                          \
  F(Subtract, 2, 1)                     \
  F(ShiftLeft, 2, 1)                    \
  F(ShiftRight, 2, 1)                   \
  F(ShiftRightLogical, 2, 1)            \
  F(BitwiseAnd, 2, 1)                   \
  F(BitwiseOr, 2, 1)                    \
448
  F(BitwiseXor, 2, 1)                   \
449 450 451 452 453 454 455
  F(Equal, 2, 1)                        \
  F(NotEqual, 2, 1)                     \
  F(StrictEqual, 2, 1)                  \
  F(StrictNotEqual, 2, 1)               \
  F(LessThan, 2, 1)                     \
  F(GreaterThan, 2, 1)                  \
  F(LessThanOrEqual, 2, 1)              \
456 457
  F(GreaterThanOrEqual, 2, 1)           \
  F(InstanceOf, 2, 1)
458

459 460 461 462 463 464 465 466 467 468 469 470 471
#define FOR_EACH_INTRINSIC_PROMISE(F)       \
  F(EnqueueMicrotask, 1, 1)                 \
  F(EnqueuePromiseReactionJob, 1, 1)        \
  F(EnqueuePromiseResolveThenableJob, 1, 1) \
  F(PromiseHookInit, 2, 1)                  \
  F(PromiseHookResolve, 1, 1)               \
  F(PromiseHookBefore, 1, 1)                \
  F(PromiseHookAfter, 1, 1)                 \
  F(PromiseMarkAsHandled, 1, 1)             \
  F(PromiseRejectEventFromStack, 2, 1)      \
  F(PromiseRevokeReject, 1, 1)              \
  F(PromiseResult, 1, 1)                    \
  F(PromiseStatus, 1, 1)                    \
472
  F(ReportPromiseReject, 2, 1)
473

474 475 476 477 478 479
#define FOR_EACH_INTRINSIC_PROXY(F) \
  F(IsJSProxy, 1, 1)                \
  F(JSProxyGetTarget, 1, 1)         \
  F(JSProxyGetHandler, 1, 1)        \
  F(JSProxyRevoke, 1, 1)            \
  F(GetPropertyWithReceiver, 2, 1)  \
480 481 482
  F(CheckProxyHasTrap, 2, 1)        \
  F(SetPropertyWithReceiver, 5, 1)  \
  F(CheckProxyGetSetTrapResult, 2, 1)
483

484 485 486
#define FOR_EACH_INTRINSIC_REGEXP(F)                \
  F(IsRegExp, 1, 1)                                 \
  F(RegExpExec, 4, 1)                               \
487
  F(RegExpExecMultiple, 4, 1)                       \
488
  F(RegExpExecReThrow, 0, 1)                        \
489
  F(RegExpInitializeAndCompile, 3, 1)               \
490 491
  F(RegExpInternalReplace, 3, 1)                    \
  F(RegExpReplace, 3, 1)                            \
492
  F(RegExpSplit, 3, 1)                              \
493 494 495
  F(StringReplaceGlobalRegExpWithString, 4, 1)      \
  F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
  F(StringSplit, 3, 1)
496

497 498 499 500 501 502 503 504 505 506
#define FOR_EACH_INTRINSIC_SCOPES(F)      \
  F(ThrowConstAssignError, 0, 1)          \
  F(DeclareGlobals, 3, 1)                 \
  F(DeclareGlobalsForInterpreter, 3, 1)   \
  F(DeclareEvalFunction, 2, 1)            \
  F(DeclareEvalVar, 1, 1)                 \
  F(NewSloppyArguments_Generic, 1, 1)     \
  F(NewStrictArguments, 1, 1)             \
  F(NewRestParameter, 1, 1)               \
  F(NewSloppyArguments, 3, 1)             \
507
  F(NewArgumentsElements, 3, 1)           \
508 509 510 511 512 513 514 515 516 517 518 519 520
  F(NewClosure, 3, 1)                     \
  F(NewClosure_Tenured, 3, 1)             \
  F(NewScriptContext, 2, 1)               \
  F(NewFunctionContext, 2, 1)             \
  F(PushModuleContext, 3, 1)              \
  F(PushWithContext, 3, 1)                \
  F(PushCatchContext, 4, 1)               \
  F(PushBlockContext, 2, 1)               \
  F(DeleteLookupSlot, 1, 1)               \
  F(LoadLookupSlot, 1, 1)                 \
  F(LoadLookupSlotInsideTypeof, 1, 1)     \
  F(StoreLookupSlot_Sloppy, 2, 1)         \
  F(StoreLookupSlot_SloppyHoisting, 2, 1) \
521
  F(StoreLookupSlot_Strict, 2, 1)
522

523
#define FOR_EACH_INTRINSIC_STRINGS(F)     \
524
  F(GetSubstitution, 5, 1)                \
525
  F(StringReplaceOneCharWithString, 3, 1) \
526
  F(StringIncludes, 3, 1)                 \
527
  F(StringTrim, 2, 1)                     \
528
  F(StringIndexOf, 3, 1)                  \
529
  F(StringIndexOfUnchecked, 3, 1)         \
530
  F(StringLastIndexOf, 2, 1)              \
531 532 533
  F(SubString, 3, 1)                      \
  F(StringAdd, 2, 1)                      \
  F(InternalizeString, 1, 1)              \
534
  F(StringCharCodeAt, 2, 1)               \
535 536
  F(StringCompare, 2, 1)                  \
  F(StringBuilderConcat, 3, 1)            \
537
  F(StringBuilderJoin, 3, 1)              \
538 539
  F(SparseJoinWithSeparator, 3, 1)        \
  F(StringToArray, 2, 1)                  \
540 541 542 543
  F(StringLessThan, 2, 1)                 \
  F(StringLessThanOrEqual, 2, 1)          \
  F(StringGreaterThan, 2, 1)              \
  F(StringGreaterThanOrEqual, 2, 1)       \
544
  F(StringEqual, 2, 1)                    \
545
  F(StringNotEqual, 2, 1)                 \
546 547
  F(FlattenString, 1, 1)                  \
  F(StringCharFromCode, 1, 1)             \
548
  F(StringMaxLength, 0, 1)
549

550 551 552 553
#define FOR_EACH_INTRINSIC_SYMBOL(F) \
  F(CreateSymbol, 1, 1)              \
  F(CreatePrivateSymbol, 1, 1)       \
  F(SymbolDescription, 1, 1)         \
554
  F(SymbolDescriptiveString, 1, 1)   \
555 556 557
  F(SymbolIsPrivate, 1, 1)

#define FOR_EACH_INTRINSIC_TEST(F)            \
558
  F(ConstructDouble, 2, 1)                    \
559
  F(ConstructConsString, 2, 1)                \
560 561 562 563 564
  F(DeoptimizeFunction, 1, 1)                 \
  F(DeoptimizeNow, 0, 1)                      \
  F(RunningInSimulator, 0, 1)                 \
  F(IsConcurrentRecompilationSupported, 0, 1) \
  F(OptimizeFunctionOnNextCall, -1, 1)        \
565
  F(TypeProfile, 1, 1)                        \
566 567 568 569
  F(OptimizeOsr, -1, 1)                       \
  F(NeverOptimizeFunction, 1, 1)              \
  F(GetOptimizationStatus, -1, 1)             \
  F(UnblockConcurrentRecompilation, 0, 1)     \
570
  F(GetDeoptCount, 1, 1)                      \
571
  F(GetUndetectable, 0, 1)                    \
572
  F(GetCallable, 0, 1)                        \
573
  F(ClearFunctionFeedback, 1, 1)              \
574
  F(CheckWasmWrapperElision, 2, 1)            \
575 576 577 578
  F(NotifyContextDisposed, 0, 1)              \
  F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
  F(DebugPrint, 1, 1)                         \
  F(DebugTrace, 0, 1)                         \
579
  F(DebugTrackRetainingPath, 1, 1)            \
580
  F(PrintWithNameForAssert, 2, 1)             \
581
  F(GetExceptionDetails, 1, 1)                \
582 583 584 585 586 587 588 589 590 591
  F(GlobalPrint, 1, 1)                        \
  F(SystemBreak, 0, 1)                        \
  F(SetFlags, 1, 1)                           \
  F(Abort, 1, 1)                              \
  F(AbortJS, 1, 1)                            \
  F(NativeScriptsCount, 0, 1)                 \
  F(DisassembleFunction, 1, 1)                \
  F(TraceEnter, 0, 1)                         \
  F(TraceExit, 1, 1)                          \
  F(HaveSameMap, 2, 1)                        \
ben's avatar
ben committed
592
  F(InNewSpace, 1, 1)                         \
593 594 595 596 597
  F(HasSmiElements, 1, 1)                     \
  F(HasObjectElements, 1, 1)                  \
  F(HasSmiOrObjectElements, 1, 1)             \
  F(HasDoubleElements, 1, 1)                  \
  F(HasHoleyElements, 1, 1)                   \
598 599
  F(HasDictionaryElements, 1, 1)              \
  F(HasSloppyArgumentsElements, 1, 1)         \
600
  F(HasFixedTypedArrayElements, 1, 1)         \
601 602 603 604 605 606 607 608 609
  F(HasFastProperties, 1, 1)                  \
  F(HasFixedUint8Elements, 1, 1)              \
  F(HasFixedInt8Elements, 1, 1)               \
  F(HasFixedUint16Elements, 1, 1)             \
  F(HasFixedInt16Elements, 1, 1)              \
  F(HasFixedUint32Elements, 1, 1)             \
  F(HasFixedInt32Elements, 1, 1)              \
  F(HasFixedFloat32Elements, 1, 1)            \
  F(HasFixedFloat64Elements, 1, 1)            \
610
  F(HasFixedUint8ClampedElements, 1, 1)       \
611 612
  F(SpeciesProtector, 0, 1)                   \
  F(SerializeWasmModule, 1, 1)                \
613
  F(DeserializeWasmModule, 2, 1)              \
614
  F(IsAsmWasmCode, 1, 1)                      \
615
  F(IsWasmCode, 1, 1)                         \
616 617
  F(IsWasmTrapHandlerEnabled, 0, 1)           \
  F(GetWasmRecoveredTrapCount, 0, 1)          \
618
  F(DisallowCodegenFromStrings, 1, 1)         \
619 620
  F(ValidateWasmInstancesChain, 2, 1)         \
  F(ValidateWasmModuleState, 1, 1)            \
621
  F(ValidateWasmOrphanedInstance, 1, 1)       \
622 623
  F(SetWasmCompileControls, 2, 1)             \
  F(SetWasmInstantiateControls, 0, 1)         \
624
  F(HeapObjectVerify, 1, 1)                   \
625
  F(WasmNumInterpretedCalls, 1, 1)            \
626 627
  F(RedirectToWasmInterpreter, 2, 1)          \
  F(WasmTraceMemory, 4, 1)
628

629 630 631 632 633 634
#define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \
  F(ArrayBufferGetByteLength, 1, 1)      \
  F(ArrayBufferNeuter, 1, 1)             \
  F(TypedArrayCopyElements, 3, 1)        \
  F(ArrayBufferViewGetByteLength, 1, 1)  \
  F(ArrayBufferViewGetByteOffset, 1, 1)  \
635
  F(ArrayBufferViewWasNeutered, 1, 1)    \
636 637 638 639 640 641
  F(TypedArrayGetLength, 1, 1)           \
  F(TypedArrayGetBuffer, 1, 1)           \
  F(TypedArraySortFast, 1, 1)            \
  F(IsTypedArray, 1, 1)                  \
  F(IsSharedTypedArray, 1, 1)            \
  F(IsSharedIntegerTypedArray, 1, 1)     \
642 643
  F(IsSharedInteger32TypedArray, 1, 1)   \
  F(TypedArraySpeciesCreateByLength, 2, 1)
644

645 646 647 648 649 650 651 652 653 654 655 656 657
#define FOR_EACH_INTRINSIC_WASM(F)   \
  F(WasmGrowMemory, 1, 1)            \
  F(ThrowWasmError, 2, 1)            \
  F(ThrowWasmErrorFromTrapIf, 1, 1)  \
  F(ThrowWasmStackOverflow, 0, 1)    \
  F(WasmThrowTypeError, 0, 1)        \
  F(WasmThrowCreate, 2, 1)           \
  F(WasmThrow, 0, 1)                 \
  F(WasmGetExceptionRuntimeId, 0, 1) \
  F(WasmExceptionSetElement, 2, 1)   \
  F(WasmExceptionGetElement, 1, 1)   \
  F(WasmRunInterpreter, 3, 1)        \
  F(WasmStackGuard, 0, 1)            \
658
  F(WasmCompileLazy, 0, 1)
659

660
#define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
661
  F(LoadLookupSlotForCall, 1, 2)
662

663 664
// Most intrinsics are implemented in the runtime/ directory, but ICs are
// implemented in ic.cc for now.
665 666 667 668 669 670
#define FOR_EACH_INTRINSIC_IC(F)             \
  F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
  F(KeyedLoadIC_Miss, 4, 1)                  \
  F(KeyedStoreIC_Miss, 5, 1)                 \
  F(KeyedStoreIC_Slow, 5, 1)                 \
  F(LoadElementWithInterceptor, 2, 1)        \
671
  F(LoadGlobalIC_Miss, 3, 1)                 \
672
  F(LoadGlobalIC_Slow, 3, 1)                 \
673
  F(LoadIC_Miss, 4, 1)                       \
674
  F(LoadPropertyWithInterceptor, 5, 1)       \
675
  F(StoreCallbackProperty, 6, 1)             \
676
  F(StoreGlobalIC_Slow, 5, 1)                \
677
  F(StoreIC_Miss, 5, 1)                      \
678
  F(StorePropertyWithInterceptor, 5, 1)      \
679
  F(Unreachable, 0, 1)
680

681
#define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
682
  FOR_EACH_INTRINSIC_IC(F)                  \
683
  FOR_EACH_INTRINSIC_ARRAY(F)               \
binji's avatar
binji committed
684
  FOR_EACH_INTRINSIC_ATOMICS(F)             \
685
  FOR_EACH_INTRINSIC_BIGINT(F)              \
686 687 688 689 690
  FOR_EACH_INTRINSIC_CLASSES(F)             \
  FOR_EACH_INTRINSIC_COLLECTIONS(F)         \
  FOR_EACH_INTRINSIC_COMPILER(F)            \
  FOR_EACH_INTRINSIC_DATE(F)                \
  FOR_EACH_INTRINSIC_DEBUG(F)               \
691
  FOR_EACH_INTRINSIC_ERROR(F)               \
692
  FOR_EACH_INTRINSIC_FORIN(F)               \
693
  FOR_EACH_INTRINSIC_INTERPRETER(F)         \
694 695
  FOR_EACH_INTRINSIC_FUNCTION(F)            \
  FOR_EACH_INTRINSIC_GENERATOR(F)           \
696
  FOR_EACH_INTRINSIC_INTL(F)                \
697 698 699 700
  FOR_EACH_INTRINSIC_INTERNAL(F)            \
  FOR_EACH_INTRINSIC_LITERALS(F)            \
  FOR_EACH_INTRINSIC_LIVEEDIT(F)            \
  FOR_EACH_INTRINSIC_MATHS(F)               \
701
  FOR_EACH_INTRINSIC_MODULE(F)              \
702 703
  FOR_EACH_INTRINSIC_NUMBERS(F)             \
  FOR_EACH_INTRINSIC_OBJECT(F)              \
704
  FOR_EACH_INTRINSIC_OPERATORS(F)           \
705
  FOR_EACH_INTRINSIC_PROMISE(F)             \
706 707 708 709 710 711
  FOR_EACH_INTRINSIC_PROXY(F)               \
  FOR_EACH_INTRINSIC_REGEXP(F)              \
  FOR_EACH_INTRINSIC_SCOPES(F)              \
  FOR_EACH_INTRINSIC_STRINGS(F)             \
  FOR_EACH_INTRINSIC_SYMBOL(F)              \
  FOR_EACH_INTRINSIC_TEST(F)                \
712 713
  FOR_EACH_INTRINSIC_TYPEDARRAY(F)          \
  FOR_EACH_INTRINSIC_WASM(F)
714 715 716

// FOR_EACH_INTRINSIC defines the list of all intrinsics, coming in 2 flavors,
// either returning an object or a pair.
717 718
#define FOR_EACH_INTRINSIC(F)         \
  FOR_EACH_INTRINSIC_RETURN_PAIR(F)   \
719 720 721
  FOR_EACH_INTRINSIC_RETURN_OBJECT(F)


722 723 724 725 726 727
#define F(name, nargs, ressize)                                 \
  Object* Runtime_##name(int args_length, Object** args_object, \
                         Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
#undef F

728
//---------------------------------------------------------------------------
729 730 731 732
// Runtime provides access to all C++ runtime functions.

class Runtime : public AllStatic {
 public:
733
  enum FunctionId : int32_t {
734
#define F(name, nargs, ressize) k##name,
735
#define I(name, nargs, ressize) kInline##name,
736
    FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)
737
#undef I
738
#undef F
739
        kNumFunctions,
740 741
  };

742
  enum IntrinsicType { RUNTIME, INLINE };
743

744
  // Intrinsic function descriptor.
745
  struct Function {
746 747
    FunctionId function_id;
    IntrinsicType intrinsic_type;
748 749 750
    // The JS name of the function.
    const char* name;

751 752 753
    // For RUNTIME functions, this is the C++ entry point.
    // For INLINE functions this is the C++ entry point of the fall back.
    Address entry;
754

755 756
    // The number of arguments expected. nargs is -1 if the function takes
    // a variable number of arguments.
757
    int8_t nargs;
758
    // Size of result.  Most functions return a single pointer, size 1.
759
    int8_t result_size;
760 761
  };

762 763
  static const int kNotFound = -1;

764 765
  // Get the intrinsic function with the given name.
  static const Function* FunctionForName(const unsigned char* name, int length);
766

767
  // Get the intrinsic function with the given FunctionId.
768
  V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
769

770 771 772
  // Get the intrinsic function with the given function entry address.
  static const Function* FunctionForEntry(Address ref);

773 774 775
  // Get the runtime intrinsic function table.
  static const Function* RuntimeFunctionTable(Isolate* isolate);

neis's avatar
neis committed
776
  MUST_USE_RESULT static Maybe<bool> DeleteObjectProperty(
777 778 779
      Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
      LanguageMode language_mode);

780
  MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
781
      Isolate* isolate, Handle<Object> object, Handle<Object> key,
782
      Handle<Object> value, LanguageMode language_mode);
783

784
  MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
785
      Isolate* isolate, Handle<Object> object, Handle<Object> key,
786
      bool* is_found_out = nullptr);
787

788 789
  MUST_USE_RESULT static MaybeHandle<JSArray> GetInternalProperties(
      Isolate* isolate, Handle<Object>);
790 791 792

  MUST_USE_RESULT static MaybeHandle<Object> ThrowIteratorError(
      Isolate* isolate, Handle<Object> object);
793 794
};

795

796 797
class RuntimeState {
 public:
798
#ifndef V8_INTL_SUPPORT
799 800 801 802 803 804
  unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
    return &to_upper_mapping_;
  }
  unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
    return &to_lower_mapping_;
  }
805
#endif
806 807 808 809 810 811 812

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

  void set_redirected_intrinsic_functions(
      Runtime::Function* redirected_intrinsic_functions) {
813
    redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
814 815 816 817
  }

 private:
  RuntimeState() {}
818
#ifndef V8_INTL_SUPPORT
819 820
  unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
  unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
821
#endif
822

823
  std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
824 825 826 827 828 829 830

  friend class Isolate;
  friend class Runtime;

  DISALLOW_COPY_AND_ASSIGN(RuntimeState);
};

831
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
832

833 834 835
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.

836 837
class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
838

839 840
class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
841

842 843 844 845 846 847 848 849 850 851
// 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,
852 853 854 855 856
  kMarkedForOptimization = 1 << 7,
  kMarkedForConcurrentOptimization = 1 << 8,
  kOptimizingConcurrently = 1 << 9,
  kIsExecuting = 1 << 10,
  kTopmostFrameIsTurboFanned = 1 << 11,
857 858
};

859 860
}  // namespace internal
}  // namespace v8
861

862
#endif  // V8_RUNTIME_RUNTIME_H_