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