• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_RUNTIME_RUNTIME_H_
6 #define V8_RUNTIME_RUNTIME_H_
7 
8 #include <memory>
9 
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 namespace v8 {
18 namespace internal {
19 
20 // * Each intrinsic is consistently exposed in JavaScript via 2 names:
21 //    * %#name, which is always a runtime call.
22 //    * %_#name, which can be inlined or just a runtime call, the compiler in
23 //      question decides.
24 //
25 // * IntrinsicTypes are Runtime::RUNTIME and Runtime::INLINE, respectively.
26 //
27 // * IDs are Runtime::k##name and Runtime::kInline##name, respectively.
28 //
29 // * All intrinsics have a C++ implementation Runtime_##name.
30 //
31 // * Each compiler has an explicit list of intrisics it supports, falling back
32 //   to a simple runtime call if necessary.
33 
34 
35 // Entries have the form F(name, number of arguments, number of values):
36 // A variable number of arguments is specified by a -1, additional restrictions
37 // are specified by inline comments
38 
39 #define FOR_EACH_INTRINSIC_ARRAY(F) \
40   F(ArrayIncludes_Slow, 3, 1)       \
41   F(ArrayIndexOf, 3, 1)             \
42   F(ArrayIsArray, 1, 1)             \
43   F(ArraySpeciesConstructor, 1, 1)  \
44   F(EstimateNumberOfElements, 1, 1) \
45   F(GetArrayKeys, 2, 1)             \
46   F(GrowArrayElements, 2, 1)        \
47   F(HasComplexElements, 1, 1)       \
48   F(IsArray, 1, 1)                  \
49   F(MoveArrayContents, 2, 1)        \
50   F(NewArray, -1 /* >= 3 */, 1)     \
51   F(NormalizeElements, 1, 1)        \
52   F(PrepareElementsForSort, 2, 1)   \
53   F(TransitionElementsKind, 2, 1)   \
54   F(TrySliceSimpleNonFastElements, 3, 1)
55 
56 #define FOR_EACH_INTRINSIC_ATOMICS(F)  \
57   F(AtomicsAdd, 3, 1)                  \
58   F(AtomicsAnd, 3, 1)                  \
59   F(AtomicsCompareExchange, 4, 1)      \
60   F(AtomicsExchange, 3, 1)             \
61   F(AtomicsNumWaitersForTesting, 2, 1) \
62   F(AtomicsOr, 3, 1)                   \
63   F(AtomicsSub, 3, 1)                  \
64   F(AtomicsXor, 3, 1)                  \
65   F(SetAllowAtomicsWait, 1, 1)
66 
67 #define FOR_EACH_INTRINSIC_BIGINT(F) \
68   F(BigIntBinaryOp, 3, 1)            \
69   F(BigIntCompareToBigInt, 3, 1)     \
70   F(BigIntCompareToNumber, 3, 1)     \
71   F(BigIntCompareToString, 3, 1)     \
72   F(BigIntEqualToBigInt, 2, 1)       \
73   F(BigIntEqualToNumber, 2, 1)       \
74   F(BigIntEqualToString, 2, 1)       \
75   F(BigIntToBoolean, 1, 1)           \
76   F(BigIntToNumber, 1, 1)            \
77   F(BigIntUnaryOp, 2, 1)             \
78   F(ToBigInt, 1, 1)
79 
80 #define FOR_EACH_INTRINSIC_CLASSES(F)       \
81   F(DefineClass, -1 /* >= 3 */, 1)          \
82   F(HomeObjectSymbol, 0, 1)                 \
83   F(LoadFromSuper, 3, 1)                    \
84   F(LoadKeyedFromSuper, 3, 1)               \
85   F(StoreKeyedToSuper_Sloppy, 4, 1)         \
86   F(StoreKeyedToSuper_Strict, 4, 1)         \
87   F(StoreToSuper_Sloppy, 4, 1)              \
88   F(StoreToSuper_Strict, 4, 1)              \
89   F(ThrowConstructorNonCallableError, 1, 1) \
90   F(ThrowNotSuperConstructor, 2, 1)         \
91   F(ThrowStaticPrototypeError, 0, 1)        \
92   F(ThrowSuperAlreadyCalledError, 0, 1)     \
93   F(ThrowSuperNotCalled, 0, 1)              \
94   F(ThrowUnsupportedSuperError, 0, 1)
95 
96 #define FOR_EACH_INTRINSIC_COLLECTIONS(F) \
97   F(GetWeakMapEntries, 2, 1)              \
98   F(GetWeakSetValues, 2, 1)               \
99   F(MapGrow, 1, 1)                        \
100   F(MapIteratorClone, 1, 1)               \
101   F(MapShrink, 1, 1)                      \
102   F(SetGrow, 1, 1)                        \
103   F(SetIteratorClone, 1, 1)               \
104   F(SetShrink, 1, 1)                      \
105   F(TheHole, 0, 1)                        \
106   F(WeakCollectionDelete, 3, 1)           \
107   F(WeakCollectionSet, 4, 1)
108 
109 #define FOR_EACH_INTRINSIC_COMPILER(F)    \
110   F(CompileForOnStackReplacement, 1, 1)   \
111   F(CompileLazy, 1, 1)                    \
112   F(CompileOptimized_Concurrent, 1, 1)    \
113   F(CompileOptimized_NotConcurrent, 1, 1) \
114   F(EvictOptimizedCodeSlot, 1, 1)         \
115   F(FunctionFirstExecution, 1, 1)         \
116   F(InstantiateAsmJs, 4, 1)               \
117   F(NotifyDeoptimized, 0, 1)              \
118   F(ResolvePossiblyDirectEval, 6, 1)
119 
120 #define FOR_EACH_INTRINSIC_DATE(F) \
121   F(DateCurrentTime, 0, 1)         \
122   F(IsDate, 1, 1)
123 
124 #define FOR_EACH_INTRINSIC_DEBUG(F)             \
125   F(ClearStepping, 0, 1)                        \
126   F(CollectGarbage, 1, 1)                       \
127   F(DebugBreakAtEntry, 1, 1)                    \
128   F(DebugCollectCoverage, 0, 1)                 \
129   F(DebugGetLoadedScriptIds, 0, 1)              \
130   F(DebugIsActive, 0, 1)                        \
131   F(DebugOnFunctionCall, 2, 1)                  \
132   F(DebugPopPromise, 0, 1)                      \
133   F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
134   F(DebugPushPromise, 1, 1)                     \
135   F(DebugAsyncFunctionSuspended, 1, 1)          \
136   F(DebugAsyncFunctionFinished, 2, 1)           \
137   F(DebugToggleBlockCoverage, 1, 1)             \
138   F(DebugTogglePreciseCoverage, 1, 1)           \
139   F(FunctionGetInferredName, 1, 1)              \
140   F(GetBreakLocations, 1, 1)                    \
141   F(GetGeneratorScopeCount, 1, 1)               \
142   F(GetGeneratorScopeDetails, 2, 1)             \
143   F(GetHeapUsage, 0, 1)                         \
144   F(HandleDebuggerStatement, 0, 1)              \
145   F(IncBlockCounter, 2, 1)                      \
146   F(IsBreakOnException, 1, 1)                   \
147   F(ScheduleBreak, 0, 1)                        \
148   F(ScriptLocationFromLine2, 4, 1)              \
149   F(SetGeneratorScopeVariableValue, 4, 1)       \
150   F(LiveEditPatchScript, 2, 1)
151 
152 #define FOR_EACH_INTRINSIC_FORIN(F) \
153   F(ForInEnumerate, 1, 1)           \
154   F(ForInHasProperty, 2, 1)
155 
156 #ifdef V8_TRACE_IGNITION
157 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F) \
158   F(InterpreterTraceBytecodeEntry, 3, 1)        \
159   F(InterpreterTraceBytecodeExit, 3, 1)
160 #else
161 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F)
162 #endif
163 
164 #ifdef V8_TRACE_FEEDBACK_UPDATES
165 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F) \
166   F(InterpreterTraceUpdateFeedback, 3, 1)
167 #else
168 #define FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F)
169 #endif
170 
171 #define FOR_EACH_INTRINSIC_INTERPRETER(F)          \
172   FOR_EACH_INTRINSIC_INTERPRETER_TRACE(F)          \
173   FOR_EACH_INTRINSIC_INTERPRETER_TRACE_FEEDBACK(F) \
174   F(InterpreterDeserializeLazy, 2, 1)
175 
176 #define FOR_EACH_INTRINSIC_FUNCTION(F)     \
177   F(Call, -1 /* >= 2 */, 1)                \
178   F(FunctionGetName, 1, 1)                 \
179   F(FunctionGetScriptSource, 1, 1)         \
180   F(FunctionGetScriptId, 1, 1)             \
181   F(FunctionGetScriptSourcePosition, 1, 1) \
182   F(FunctionGetSourceCode, 1, 1)           \
183   F(FunctionIsAPIFunction, 1, 1)           \
184   F(IsConstructor, 1, 1)                   \
185   F(IsFunction, 1, 1)                      \
186   F(SetCode, 2, 1)                         \
187   F(SetNativeFlag, 1, 1)
188 
189 #define FOR_EACH_INTRINSIC_GENERATOR(F)       \
190   F(AsyncGeneratorHasCatchHandlerForPC, 1, 1) \
191   F(AsyncGeneratorReject, 2, 1)               \
192   F(AsyncGeneratorResolve, 3, 1)              \
193   F(AsyncGeneratorYield, 3, 1)                \
194   F(CreateJSGeneratorObject, 2, 1)            \
195   F(GeneratorClose, 1, 1)                     \
196   F(GeneratorGetFunction, 1, 1)               \
197   F(GeneratorGetInputOrDebugPos, 1, 1)        \
198   F(GeneratorGetResumeMode, 1, 1)
199 
200 #ifdef V8_INTL_SUPPORT
201 #define FOR_EACH_INTRINSIC_INTL(F)           \
202   F(AvailableLocalesOf, 1, 1)                \
203   F(BreakIteratorBreakType, 1, 1)            \
204   F(BreakIteratorCurrent, 1, 1)              \
205   F(BreakIteratorFirst, 1, 1)                \
206   F(BreakIteratorNext, 1, 1)                 \
207   F(CanonicalizeLanguageTag, 1, 1)           \
208   F(CollatorResolvedOptions, 1, 1)           \
209   F(CreateBreakIterator, 3, 1)               \
210   F(CreateDateTimeFormat, 3, 1)              \
211   F(CreateNumberFormat, 3, 1)                \
212   F(CurrencyDigits, 1, 1)                    \
213   F(DateCacheVersion, 0, 1)                  \
214   F(DefaultNumberOption, 5, 1)               \
215   F(DefineWEProperty, 3, 1)                  \
216   F(FormatList, 2, 1)                        \
217   F(FormatListToParts, 2, 1)                 \
218   F(GetDefaultICULocale, 0, 1)               \
219   F(GetNumberOption, 5, 1)                   \
220   F(IntlUnwrapReceiver, 5, 1)                \
221   F(IsInitializedIntlObjectOfType, 2, 1)     \
222   F(IsWellFormedCurrencyCode, 1, 1)          \
223   F(MarkAsInitializedIntlObjectOfType, 2, 1) \
224   F(ParseExtension, 1, 1)                    \
225   F(PluralRulesResolvedOptions, 1, 1)        \
226   F(PluralRulesSelect, 2, 1)                 \
227   F(ToDateTimeOptions, 3, 1)                 \
228   F(ToLocaleDateTime, 6, 1)                  \
229   F(StringToLowerCaseIntl, 1, 1)             \
230   F(StringToUpperCaseIntl, 1, 1)             \
231   F(SupportedLocalesOf, 3, 1)                \
232 // End of macro.
233 #else
234 #define FOR_EACH_INTRINSIC_INTL(F)
235 #endif  // V8_INTL_SUPPORT
236 
237 #define FOR_EACH_INTRINSIC_INTERNAL(F)                               \
238   F(AllocateInNewSpace, 1, 1)                                        \
239   F(AllocateInTargetSpace, 2, 1)                                     \
240   F(AllocateSeqOneByteString, 1, 1)                                  \
241   F(AllocateSeqTwoByteString, 1, 1)                                  \
242   F(AllowDynamicFunction, 1, 1)                                      \
243   F(CheckIsBootstrapping, 0, 1)                                      \
244   F(CreateAsyncFromSyncIterator, 1, 1)                               \
245   F(CreateListFromArrayLike, 1, 1)                                   \
246   F(CreateTemplateObject, 1, 1)                                      \
247   F(DeserializeLazy, 1, 1)                                           \
248   F(ExportFromRuntime, 1, 1)                                         \
249   F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1)                   \
250   F(IncrementUseCounter, 1, 1)                                       \
251   F(InstallToContext, 1, 1)                                          \
252   F(Interrupt, 0, 1)                                                 \
253   F(IS_VAR, 1, 1)                                                    \
254   F(NewReferenceError, 2, 1)                                         \
255   F(NewSyntaxError, 2, 1)                                            \
256   F(NewTypeError, 2, 1)                                              \
257   F(OrdinaryHasInstance, 2, 1)                                       \
258   F(PromoteScheduledException, 0, 1)                                 \
259   F(ReportMessage, 1, 1)                                             \
260   F(ReThrow, 1, 1)                                                   \
261   F(RunMicrotaskCallback, 2, 1)                                      \
262   F(RunMicrotasks, 0, 1)                                             \
263   F(StackGuard, 0, 1)                                                \
264   F(Throw, 1, 1)                                                     \
265   F(ThrowApplyNonFunction, 1, 1)                                     \
266   F(ThrowCalledNonCallable, 1, 1)                                    \
267   F(ThrowConstructedNonConstructable, 1, 1)                          \
268   F(ThrowConstructorReturnedNonObject, 0, 1)                         \
269   F(ThrowInvalidStringLength, 0, 1)                                  \
270   F(ThrowInvalidTypedArrayAlignment, 2, 1)                           \
271   F(ThrowIteratorResultNotAnObject, 1, 1)                            \
272   F(ThrowNotConstructor, 1, 1)                                       \
273   F(ThrowRangeError, -1 /* >= 1 */, 1)                               \
274   F(ThrowReferenceError, 1, 1)                                       \
275   F(ThrowStackOverflow, 0, 1)                                        \
276   F(ThrowSymbolAsyncIteratorInvalid, 0, 1)                           \
277   F(ThrowSymbolIteratorInvalid, 0, 1)                                \
278   F(ThrowThrowMethodMissing, 0, 1)                                   \
279   F(ThrowTypeError, -1 /* >= 1 */, 1)                                \
280   F(Typeof, 1, 1)                                                    \
281   F(UnwindAndFindExceptionHandler, 0, 1)
282 
283 #define FOR_EACH_INTRINSIC_LITERALS(F)              \
284   F(CreateArrayLiteral, 4, 1)                       \
285   F(CreateArrayLiteralWithoutAllocationSite, 2, 1)  \
286   F(CreateObjectLiteral, 4, 1)                      \
287   F(CreateObjectLiteralWithoutAllocationSite, 2, 1) \
288   F(CreateRegExpLiteral, 4, 1)
289 
290 #define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1)
291 
292 #define FOR_EACH_INTRINSIC_MODULE(F) \
293   F(DynamicImportCall, 2, 1)         \
294   F(GetImportMetaObject, 0, 1)       \
295   F(GetModuleNamespace, 1, 1)
296 
297 #define FOR_EACH_INTRINSIC_NUMBERS(F) \
298   F(GetHoleNaNLower, 0, 1)            \
299   F(GetHoleNaNUpper, 0, 1)            \
300   F(IsSmi, 1, 1)                      \
301   F(IsValidSmi, 1, 1)                 \
302   F(MaxSmi, 0, 1)                     \
303   F(NumberToString, 1, 1)             \
304   F(SmiLexicographicCompare, 2, 1)    \
305   F(StringParseFloat, 1, 1)           \
306   F(StringParseInt, 2, 1)             \
307   F(StringToNumber, 1, 1)
308 
309 #define FOR_EACH_INTRINSIC_OBJECT(F)                            \
310   F(AddDictionaryProperty, 3, 1)                                \
311   F(AddElement, 3, 1)                                           \
312   F(AddNamedProperty, 4, 1)                                     \
313   F(AddPrivateField, 3, 1)                                      \
314   F(AllocateHeapNumber, 0, 1)                                   \
315   F(ClassOf, 1, 1)                                              \
316   F(CollectTypeProfile, 3, 1)                                   \
317   F(CompleteInobjectSlackTrackingForMap, 1, 1)                  \
318   F(CopyDataProperties, 2, 1)                                   \
319   F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
320   F(CreateDataProperty, 3, 1)                                   \
321   F(CreateIterResultObject, 2, 1)                               \
322   F(DefineAccessorPropertyUnchecked, 5, 1)                      \
323   F(DefineDataPropertyInLiteral, 6, 1)                          \
324   F(DefineGetterPropertyUnchecked, 4, 1)                        \
325   F(DefineMethodsInternal, 3, 1)                                \
326   F(DefineSetterPropertyUnchecked, 4, 1)                        \
327   F(DeleteProperty, 3, 1)                                       \
328   F(GetFunctionName, 1, 1)                                      \
329   F(GetOwnPropertyDescriptor, 2, 1)                             \
330   F(GetOwnPropertyKeys, 2, 1)                                   \
331   F(GetProperty, 2, 1)                                          \
332   F(GetPrototype, 1, 1)                                         \
333   F(HasFastPackedElements, 1, 1)                                \
334   F(HasInPrototypeChain, 2, 1)                                  \
335   F(HasProperty, 2, 1)                                          \
336   F(InternalSetPrototype, 2, 1)                                 \
337   F(IsJSReceiver, 1, 1)                                         \
338   F(KeyedGetProperty, 2, 1)                                     \
339   F(NewObject, 2, 1)                                            \
340   F(ObjectCreate, 2, 1)                                         \
341   F(ObjectEntries, 1, 1)                                        \
342   F(ObjectEntriesSkipFastPath, 1, 1)                            \
343   F(ObjectHasOwnProperty, 2, 1)                                 \
344   F(ObjectKeys, 1, 1)                                           \
345   F(ObjectGetOwnPropertyNames, 1, 1)                            \
346   F(ObjectGetOwnPropertyNamesTryFast, 1, 1)                     \
347   F(ObjectValues, 1, 1)                                         \
348   F(ObjectValuesSkipFastPath, 1, 1)                             \
349   F(OptimizeObjectForAddingMultipleProperties, 2, 1)            \
350   F(SameValue, 2, 1)                                            \
351   F(SameValueZero, 2, 1)                                        \
352   F(SetDataProperties, 2, 1)                                    \
353   F(SetProperty, 4, 1)                                          \
354   F(ShrinkPropertyDictionary, 1, 1)                             \
355   F(ToFastProperties, 1, 1)                                     \
356   F(ToInteger, 1, 1)                                            \
357   F(ToLength, 1, 1)                                             \
358   F(ToName, 1, 1)                                               \
359   F(ToNumber, 1, 1)                                             \
360   F(ToNumeric, 1, 1)                                            \
361   F(ToObject, 1, 1)                                             \
362   F(ToPrimitive, 1, 1)                                          \
363   F(ToPrimitive_Number, 1, 1)                                   \
364   F(ToString, 1, 1)                                             \
365   F(TryMigrateInstance, 1, 1)                                   \
366   F(ValueOf, 1, 1)
367 
368 #define FOR_EACH_INTRINSIC_OPERATORS(F) \
369   F(Add, 2, 1)                          \
370   F(Equal, 2, 1)                        \
371   F(GreaterThan, 2, 1)                  \
372   F(GreaterThanOrEqual, 2, 1)           \
373   F(LessThan, 2, 1)                     \
374   F(LessThanOrEqual, 2, 1)              \
375   F(NotEqual, 2, 1)                     \
376   F(StrictEqual, 2, 1)                  \
377   F(StrictNotEqual, 2, 1)
378 
379 #define FOR_EACH_INTRINSIC_PROMISE(F)  \
380   F(EnqueueMicrotask, 1, 1)            \
381   F(PromiseHookAfter, 1, 1)            \
382   F(PromiseHookBefore, 1, 1)           \
383   F(PromiseHookInit, 2, 1)             \
384   F(AwaitPromisesInit, 3, 1)           \
385   F(PromiseMarkAsHandled, 1, 1)        \
386   F(PromiseRejectEventFromStack, 2, 1) \
387   F(PromiseResult, 1, 1)               \
388   F(PromiseRevokeReject, 1, 1)         \
389   F(PromiseStatus, 1, 1)               \
390   F(RejectPromise, 3, 1)               \
391   F(ResolvePromise, 2, 1)              \
392   F(PromiseRejectAfterResolved, 2, 1)  \
393   F(PromiseResolveAfterResolved, 2, 1)
394 
395 #define FOR_EACH_INTRINSIC_PROXY(F)   \
396   F(CheckProxyGetSetTrapResult, 2, 1) \
397   F(CheckProxyHasTrap, 2, 1)          \
398   F(GetPropertyWithReceiver, 3, 1)    \
399   F(IsJSProxy, 1, 1)                  \
400   F(JSProxyGetHandler, 1, 1)          \
401   F(JSProxyGetTarget, 1, 1)           \
402   F(SetPropertyWithReceiver, 5, 1)
403 
404 #define FOR_EACH_INTRINSIC_REGEXP(F)                \
405   F(IsRegExp, 1, 1)                                 \
406   F(RegExpExec, 4, 1)                               \
407   F(RegExpExecMultiple, 4, 1)                       \
408   F(RegExpInitializeAndCompile, 3, 1)               \
409   F(RegExpInternalReplace, 3, 1)                    \
410   F(RegExpReplace, 3, 1)                            \
411   F(RegExpSplit, 3, 1)                              \
412   F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
413   F(StringSplit, 3, 1)
414 
415 #define FOR_EACH_INTRINSIC_SCOPES(F)      \
416   F(DeclareEvalFunction, 2, 1)            \
417   F(DeclareEvalVar, 1, 1)                 \
418   F(DeclareGlobals, 3, 1)                 \
419   F(DeleteLookupSlot, 1, 1)               \
420   F(LoadLookupSlot, 1, 1)                 \
421   F(LoadLookupSlotInsideTypeof, 1, 1)     \
422   F(NewArgumentsElements, 3, 1)           \
423                                           \
424   F(NewClosure, 2, 1)                     \
425   F(NewClosure_Tenured, 2, 1)             \
426   F(NewFunctionContext, 1, 1)             \
427   F(NewRestParameter, 1, 1)               \
428   F(NewScriptContext, 1, 1)               \
429   F(NewSloppyArguments, 3, 1)             \
430   F(NewSloppyArguments_Generic, 1, 1)     \
431   F(NewStrictArguments, 1, 1)             \
432   F(PushBlockContext, 1, 1)               \
433   F(PushCatchContext, 2, 1)               \
434   F(PushModuleContext, 2, 1)              \
435   F(PushWithContext, 2, 1)                \
436   F(StoreLookupSlot_Sloppy, 2, 1)         \
437   F(StoreLookupSlot_SloppyHoisting, 2, 1) \
438   F(StoreLookupSlot_Strict, 2, 1)         \
439   F(ThrowConstAssignError, 0, 1)
440 
441 #define FOR_EACH_INTRINSIC_STRINGS(F)     \
442   F(FlattenString, 1, 1)                  \
443   F(GetSubstitution, 5, 1)                \
444   F(InternalizeString, 1, 1)              \
445   F(SparseJoinWithSeparator, 3, 1)        \
446   F(StringAdd, 2, 1)                      \
447   F(StringBuilderConcat, 3, 1)            \
448   F(StringBuilderJoin, 3, 1)              \
449   F(StringCharCodeAt, 2, 1)               \
450   F(StringCharFromCode, 1, 1)             \
451   F(StringEqual, 2, 1)                    \
452   F(StringGreaterThan, 2, 1)              \
453   F(StringGreaterThanOrEqual, 2, 1)       \
454   F(StringIncludes, 3, 1)                 \
455   F(StringIndexOf, 3, 1)                  \
456   F(StringIndexOfUnchecked, 3, 1)         \
457   F(StringLastIndexOf, 2, 1)              \
458   F(StringLessThan, 2, 1)                 \
459   F(StringLessThanOrEqual, 2, 1)          \
460   F(StringMaxLength, 0, 1)                \
461   F(StringNotEqual, 2, 1)                 \
462   F(StringReplaceOneCharWithString, 3, 1) \
463   F(StringSubstring, 3, 1)                \
464   F(StringToArray, 2, 1)                  \
465   F(StringTrim, 2, 1)
466 
467 #define FOR_EACH_INTRINSIC_SYMBOL(F)       \
468   F(CreatePrivateFieldSymbol, 0, 1)        \
469   F(CreatePrivateSymbol, -1 /* <= 1 */, 1) \
470   F(SymbolDescriptiveString, 1, 1)         \
471   F(SymbolIsPrivate, 1, 1)
472 
473 #define FOR_EACH_INTRINSIC_TEST(F)            \
474   F(Abort, 1, 1)                              \
475   F(AbortJS, 1, 1)                            \
476   F(ClearFunctionFeedback, 1, 1)              \
477   F(CompleteInobjectSlackTracking, 1, 1)      \
478   F(ConstructConsString, 2, 1)                \
479   F(ConstructSlicedString, 2, 1)              \
480   F(ConstructDouble, 2, 1)                    \
481   F(DebugPrint, 1, 1)                         \
482   F(DebugTrace, 0, 1)                         \
483   F(DebugTrackRetainingPath, -1, 1)           \
484   F(DeoptimizeFunction, 1, 1)                 \
485   F(DeoptimizeNow, 0, 1)                      \
486   F(DeserializeWasmModule, 2, 1)              \
487   F(DisallowCodegenFromStrings, 1, 1)         \
488   F(DisallowWasmCodegen, 1, 1)                \
489   F(DisassembleFunction, 1, 1)                \
490   F(FreezeWasmLazyCompilation, 1, 1)          \
491   F(GetCallable, 0, 1)                        \
492   F(GetDeoptCount, 1, 1)                      \
493   F(GetOptimizationStatus, -1, 1)             \
494   F(GetUndetectable, 0, 1)                    \
495   F(GetWasmRecoveredTrapCount, 0, 1)          \
496   F(GlobalPrint, 1, 1)                        \
497   F(HasDictionaryElements, 1, 1)              \
498   F(HasDoubleElements, 1, 1)                  \
499   F(HasFastElements, 1, 1)                    \
500   F(HasFastProperties, 1, 1)                  \
501   F(HasFixedBigInt64Elements, 1, 1)           \
502   F(HasFixedBigUint64Elements, 1, 1)          \
503   F(HasFixedFloat32Elements, 1, 1)            \
504   F(HasFixedFloat64Elements, 1, 1)            \
505   F(HasFixedInt16Elements, 1, 1)              \
506   F(HasFixedInt32Elements, 1, 1)              \
507   F(HasFixedInt8Elements, 1, 1)               \
508   F(HasFixedUint16Elements, 1, 1)             \
509   F(HasFixedUint32Elements, 1, 1)             \
510   F(HasFixedUint8ClampedElements, 1, 1)       \
511   F(HasFixedUint8Elements, 1, 1)              \
512   F(HasHoleyElements, 1, 1)                   \
513   F(HasObjectElements, 1, 1)                  \
514   F(HasSloppyArgumentsElements, 1, 1)         \
515   F(HasSmiElements, 1, 1)                     \
516   F(HasSmiOrObjectElements, 1, 1)             \
517   F(HaveSameMap, 2, 1)                        \
518   F(HeapObjectVerify, 1, 1)                   \
519   F(InNewSpace, 1, 1)                         \
520   F(IsAsmWasmCode, 1, 1)                      \
521   F(IsConcurrentRecompilationSupported, 0, 1) \
522   F(WasmTierUpFunction, 2, 1)                 \
523   F(IsLiftoffFunction, 1, 1)                  \
524   F(IsWasmCode, 1, 1)                         \
525   F(IsWasmTrapHandlerEnabled, 0, 1)           \
526   F(NeverOptimizeFunction, 1, 1)              \
527   F(NotifyContextDisposed, 0, 1)              \
528   F(OptimizeFunctionOnNextCall, -1, 1)        \
529   F(OptimizeOsr, -1, 1)                       \
530   F(PrintWithNameForAssert, 2, 1)             \
531   F(RedirectToWasmInterpreter, 2, 1)          \
532   F(RunningInSimulator, 0, 1)                 \
533   F(SerializeWasmModule, 1, 1)                \
534   F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
535   F(SetForceSlowPath, 1, 1)                   \
536   F(SetWasmCompileControls, 2, 1)             \
537   F(SetWasmInstantiateControls, 0, 1)         \
538   F(ArraySpeciesProtector, 0, 1)              \
539   F(TypedArraySpeciesProtector, 0, 1)         \
540   F(PromiseSpeciesProtector, 0, 1)            \
541   F(SystemBreak, 0, 1)                        \
542   F(TraceEnter, 0, 1)                         \
543   F(TraceExit, 1, 1)                          \
544   F(UnblockConcurrentRecompilation, 0, 1)     \
545   F(WasmGetNumberOfInstances, 1, 1)           \
546   F(WasmNumInterpretedCalls, 1, 1)            \
547   F(WasmTraceMemory, 1, 1)                    \
548   F(WasmMemoryHasFullGuardRegion, 1, 1)       \
549   F(SetWasmThreadsEnabled, 1, 1)
550 
551 #define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \
552   F(ArrayBufferNeuter, 1, 1)             \
553   F(ArrayBufferViewWasNeutered, 1, 1)    \
554   F(IsTypedArray, 1, 1)                  \
555   F(TypedArrayCopyElements, 3, 1)        \
556   F(TypedArrayGetBuffer, 1, 1)           \
557   F(TypedArrayGetLength, 1, 1)           \
558   F(TypedArraySet, 2, 1)                 \
559   F(TypedArraySortFast, 1, 1)
560 
561 #define FOR_EACH_INTRINSIC_WASM(F)   \
562   F(ThrowWasmError, 1, 1)            \
563   F(ThrowWasmStackOverflow, 0, 1)    \
564   F(WasmExceptionGetElement, 1, 1)   \
565   F(WasmExceptionSetElement, 2, 1)   \
566   F(WasmGetExceptionRuntimeId, 0, 1) \
567   F(WasmGrowMemory, 2, 1)            \
568   F(WasmRunInterpreter, 2, 1)        \
569   F(WasmStackGuard, 0, 1)            \
570   F(WasmThrow, 0, 1)                 \
571   F(WasmThrowCreate, 2, 1)           \
572   F(WasmThrowTypeError, 0, 1)        \
573   F(WasmCompileLazy, 2, 1)
574 
575 #define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
576   F(DebugBreakOnBytecode, 1, 2)           \
577   F(LoadLookupSlotForCall, 1, 2)
578 
579 // Most intrinsics are implemented in the runtime/ directory, but ICs are
580 // implemented in ic.cc for now.
581 #define FOR_EACH_INTRINSIC_IC(F)             \
582   F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
583   F(KeyedLoadIC_Miss, 4, 1)                  \
584   F(KeyedStoreIC_Miss, 5, 1)                 \
585   F(KeyedStoreIC_Slow, 5, 1)                 \
586   F(LoadAccessorProperty, 4, 1)              \
587   F(LoadCallbackProperty, 4, 1)              \
588   F(LoadElementWithInterceptor, 2, 1)        \
589   F(LoadGlobalIC_Miss, 3, 1)                 \
590   F(LoadGlobalIC_Slow, 3, 1)                 \
591   F(LoadIC_Miss, 4, 1)                       \
592   F(LoadPropertyWithInterceptor, 5, 1)       \
593   F(StoreCallbackProperty, 6, 1)             \
594   F(StoreGlobalIC_Miss, 4, 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   F(CloneObjectIC_Miss, 4, 1)                \
600   F(CloneObjectIC_Slow, 2, 1)
601 
602 #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
603   FOR_EACH_INTRINSIC_ARRAY(F)               \
604   FOR_EACH_INTRINSIC_ATOMICS(F)             \
605   FOR_EACH_INTRINSIC_BIGINT(F)              \
606   FOR_EACH_INTRINSIC_CLASSES(F)             \
607   FOR_EACH_INTRINSIC_COLLECTIONS(F)         \
608   FOR_EACH_INTRINSIC_COMPILER(F)            \
609   FOR_EACH_INTRINSIC_DATE(F)                \
610   FOR_EACH_INTRINSIC_DEBUG(F)               \
611   FOR_EACH_INTRINSIC_FORIN(F)               \
612   FOR_EACH_INTRINSIC_FUNCTION(F)            \
613   FOR_EACH_INTRINSIC_GENERATOR(F)           \
614   FOR_EACH_INTRINSIC_IC(F)                  \
615   FOR_EACH_INTRINSIC_INTERNAL(F)            \
616   FOR_EACH_INTRINSIC_INTERPRETER(F)         \
617   FOR_EACH_INTRINSIC_INTL(F)                \
618   FOR_EACH_INTRINSIC_LITERALS(F)            \
619   FOR_EACH_INTRINSIC_MATHS(F)               \
620   FOR_EACH_INTRINSIC_MODULE(F)              \
621   FOR_EACH_INTRINSIC_NUMBERS(F)             \
622   FOR_EACH_INTRINSIC_OBJECT(F)              \
623   FOR_EACH_INTRINSIC_OPERATORS(F)           \
624   FOR_EACH_INTRINSIC_PROMISE(F)             \
625   FOR_EACH_INTRINSIC_PROXY(F)               \
626   FOR_EACH_INTRINSIC_REGEXP(F)              \
627   FOR_EACH_INTRINSIC_SCOPES(F)              \
628   FOR_EACH_INTRINSIC_STRINGS(F)             \
629   FOR_EACH_INTRINSIC_SYMBOL(F)              \
630   FOR_EACH_INTRINSIC_TEST(F)                \
631   FOR_EACH_INTRINSIC_TYPEDARRAY(F)          \
632   FOR_EACH_INTRINSIC_WASM(F)
633 
634 // FOR_EACH_INTRINSIC defines the list of all intrinsics, coming in 2 flavors,
635 // either returning an object or a pair.
636 #define FOR_EACH_INTRINSIC(F)         \
637   FOR_EACH_INTRINSIC_RETURN_PAIR(F)   \
638   FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
639 
640 
641 #define F(name, nargs, ressize)                                 \
642   Object* Runtime_##name(int args_length, Object** args_object, \
643                          Isolate* isolate);
FOR_EACH_INTRINSIC_RETURN_OBJECT(F)644 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
645 #undef F
646 
647 //---------------------------------------------------------------------------
648 // Runtime provides access to all C++ runtime functions.
649 
650 class Runtime : public AllStatic {
651  public:
652   enum FunctionId : int32_t {
653 #define F(name, nargs, ressize) k##name,
654 #define I(name, nargs, ressize) kInline##name,
655     FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)
656 #undef I
657 #undef F
658         kNumFunctions,
659   };
660 
661   enum IntrinsicType { RUNTIME, INLINE };
662 
663   // Intrinsic function descriptor.
664   struct Function {
665     FunctionId function_id;
666     IntrinsicType intrinsic_type;
667     // The JS name of the function.
668     const char* name;
669 
670     // For RUNTIME functions, this is the C++ entry point.
671     // For INLINE functions this is the C++ entry point of the fall back.
672     Address entry;
673 
674     // The number of arguments expected. nargs is -1 if the function takes
675     // a variable number of arguments.
676     int8_t nargs;
677     // Size of result.  Most functions return a single pointer, size 1.
678     int8_t result_size;
679   };
680 
681   static const int kNotFound = -1;
682 
683   // Checks whether the runtime function with the given {id} never returns
684   // to it's caller normally, i.e. whether it'll always raise an exception.
685   // More specifically: The C++ implementation returns the Heap::exception
686   // sentinel, always.
687   static bool IsNonReturning(FunctionId id);
688 
689   // Get the intrinsic function with the given name.
690   static const Function* FunctionForName(const unsigned char* name, int length);
691 
692   // Get the intrinsic function with the given FunctionId.
693   V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
694 
695   // Get the intrinsic function with the given function entry address.
696   static const Function* FunctionForEntry(Address ref);
697 
698   // Get the runtime intrinsic function table.
699   static const Function* RuntimeFunctionTable(Isolate* isolate);
700 
701   V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteObjectProperty(
702       Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
703       LanguageMode language_mode);
704 
705   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SetObjectProperty(
706       Isolate* isolate, Handle<Object> object, Handle<Object> key,
707       Handle<Object> value, LanguageMode language_mode);
708 
709   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetObjectProperty(
710       Isolate* isolate, Handle<Object> object, Handle<Object> key,
711       bool* is_found_out = nullptr);
712 
713   V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetInternalProperties(
714       Isolate* isolate, Handle<Object>);
715 
716   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ThrowIteratorError(
717       Isolate* isolate, Handle<Object> object);
718 };
719 
720 
721 class RuntimeState {
722  public:
723 #ifndef V8_INTL_SUPPORT
to_upper_mapping()724   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
725     return &to_upper_mapping_;
726   }
to_lower_mapping()727   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
728     return &to_lower_mapping_;
729   }
730 #endif
731 
redirected_intrinsic_functions()732   Runtime::Function* redirected_intrinsic_functions() {
733     return redirected_intrinsic_functions_.get();
734   }
735 
set_redirected_intrinsic_functions(Runtime::Function * redirected_intrinsic_functions)736   void set_redirected_intrinsic_functions(
737       Runtime::Function* redirected_intrinsic_functions) {
738     redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
739   }
740 
741  private:
RuntimeState()742   RuntimeState() {}
743 #ifndef V8_INTL_SUPPORT
744   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
745   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
746 #endif
747 
748   std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
749 
750   friend class Isolate;
751   friend class Runtime;
752 
753   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
754 };
755 
756 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
757 
758 //---------------------------------------------------------------------------
759 // Constants used by interface to runtime functions.
760 
761 class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
762 class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
763 
764 class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
765 class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
766 
767 // A set of bits returned by Runtime_GetOptimizationStatus.
768 // These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
769 enum class OptimizationStatus {
770   kIsFunction = 1 << 0,
771   kNeverOptimize = 1 << 1,
772   kAlwaysOptimize = 1 << 2,
773   kMaybeDeopted = 1 << 3,
774   kOptimized = 1 << 4,
775   kTurboFanned = 1 << 5,
776   kInterpreted = 1 << 6,
777   kMarkedForOptimization = 1 << 7,
778   kMarkedForConcurrentOptimization = 1 << 8,
779   kOptimizingConcurrently = 1 << 9,
780   kIsExecuting = 1 << 10,
781   kTopmostFrameIsTurboFanned = 1 << 11,
782 };
783 
784 }  // namespace internal
785 }  // namespace v8
786 
787 #endif  // V8_RUNTIME_RUNTIME_H_
788