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 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(SpecialArrayFunctions, 0, 1) \
41 : F(TransitionElementsKind, 2, 1) \
42 : F(RemoveArrayHoles, 2, 1) \
43 : F(MoveArrayContents, 2, 1) \
44 : F(EstimateNumberOfElements, 1, 1) \
45 : F(GetArrayKeys, 2, 1) \
46 : F(NewArray, -1 /* >= 3 */, 1) \
47 : F(FunctionBind, -1, 1) \
48 : F(NormalizeElements, 1, 1) \
49 : F(GrowArrayElements, 2, 1) \
50 : F(HasComplexElements, 1, 1) \
51 : F(IsArray, 1, 1) \
52 : F(ArrayIsArray, 1, 1) \
53 : F(FixedArrayGet, 2, 1) \
54 : F(FixedArraySet, 3, 1) \
55 : F(ArraySpeciesConstructor, 1, 1) \
56 : F(ArrayIncludes_Slow, 3, 1) \
57 : F(ArrayIndexOf, 3, 1) \
58 : F(SpreadIterablePrepare, 1, 1) \
59 : F(SpreadIterableFixed, 1, 1)
60 :
61 : #define FOR_EACH_INTRINSIC_ATOMICS(F) \
62 : F(ThrowNotIntegerSharedTypedArrayError, 1, 1) \
63 : F(ThrowNotInt32SharedTypedArrayError, 1, 1) \
64 : F(ThrowInvalidAtomicAccessIndexError, 0, 1) \
65 : F(AtomicsExchange, 3, 1) \
66 : F(AtomicsCompareExchange, 4, 1) \
67 : F(AtomicsAdd, 3, 1) \
68 : F(AtomicsSub, 3, 1) \
69 : F(AtomicsAnd, 3, 1) \
70 : F(AtomicsOr, 3, 1) \
71 : F(AtomicsXor, 3, 1) \
72 : F(AtomicsNumWaitersForTesting, 2, 1) \
73 : F(SetAllowAtomicsWait, 1, 1)
74 :
75 : #define FOR_EACH_INTRINSIC_CLASSES(F) \
76 : F(ThrowUnsupportedSuperError, 0, 1) \
77 : F(ThrowConstructorNonCallableError, 1, 1) \
78 : F(ThrowStaticPrototypeError, 0, 1) \
79 : F(ThrowSuperAlreadyCalledError, 0, 1) \
80 : F(ThrowSuperNotCalled, 0, 1) \
81 : F(ThrowNotSuperConstructor, 2, 1) \
82 : F(HomeObjectSymbol, 0, 1) \
83 : F(DefineClass, 4, 1) \
84 : F(InstallClassNameAccessor, 1, 1) \
85 : F(InstallClassNameAccessorWithCheck, 1, 1) \
86 : F(LoadFromSuper, 3, 1) \
87 : F(LoadKeyedFromSuper, 3, 1) \
88 : F(StoreToSuper_Strict, 4, 1) \
89 : F(StoreToSuper_Sloppy, 4, 1) \
90 : F(StoreKeyedToSuper_Strict, 4, 1) \
91 : F(StoreKeyedToSuper_Sloppy, 4, 1) \
92 : F(GetSuperConstructor, 1, 1)
93 :
94 : #define FOR_EACH_INTRINSIC_COLLECTIONS(F) \
95 : F(StringGetRawHashField, 1, 1) \
96 : F(TheHole, 0, 1) \
97 : F(JSCollectionGetTable, 1, 1) \
98 : F(GenericHash, 1, 1) \
99 : F(SetInitialize, 1, 1) \
100 : F(SetGrow, 1, 1) \
101 : F(SetShrink, 1, 1) \
102 : F(SetClear, 1, 1) \
103 : F(SetIteratorInitialize, 3, 1) \
104 : F(SetIteratorClone, 1, 1) \
105 : F(SetIteratorNext, 2, 1) \
106 : F(SetIteratorDetails, 1, 1) \
107 : F(MapInitialize, 1, 1) \
108 : F(MapShrink, 1, 1) \
109 : F(MapClear, 1, 1) \
110 : F(MapGrow, 1, 1) \
111 : F(MapIteratorInitialize, 3, 1) \
112 : F(MapIteratorClone, 1, 1) \
113 : F(MapIteratorDetails, 1, 1) \
114 : F(GetWeakMapEntries, 2, 1) \
115 : F(MapIteratorNext, 2, 1) \
116 : F(WeakCollectionInitialize, 1, 1) \
117 : F(WeakCollectionGet, 3, 1) \
118 : F(WeakCollectionHas, 3, 1) \
119 : F(WeakCollectionDelete, 3, 1) \
120 : F(WeakCollectionSet, 4, 1) \
121 : F(GetWeakSetValues, 2, 1)
122 :
123 : #define FOR_EACH_INTRINSIC_COMPILER(F) \
124 : F(CompileLazy, 1, 1) \
125 : F(CompileOptimized_Concurrent, 1, 1) \
126 : F(CompileOptimized_NotConcurrent, 1, 1) \
127 : F(NotifyStubFailure, 0, 1) \
128 : F(NotifyDeoptimized, 1, 1) \
129 : F(CompileForOnStackReplacement, 1, 1) \
130 : F(TryInstallOptimizedCode, 1, 1) \
131 : F(ResolvePossiblyDirectEval, 6, 1) \
132 : F(InstantiateAsmJs, 4, 1)
133 :
134 : #define FOR_EACH_INTRINSIC_DATE(F) \
135 : F(IsDate, 1, 1) \
136 : F(DateCurrentTime, 0, 1) \
137 : F(ThrowNotDateError, 0, 1)
138 :
139 : #define FOR_EACH_INTRINSIC_DEBUG(F) \
140 : F(HandleDebuggerStatement, 0, 1) \
141 : F(DebugBreak, 1, 1) \
142 : F(DebugBreakOnBytecode, 1, 1) \
143 : F(SetDebugEventListener, 2, 1) \
144 : F(ScheduleBreak, 0, 1) \
145 : F(DebugGetInternalProperties, 1, 1) \
146 : F(DebugGetPropertyDetails, 2, 1) \
147 : F(DebugGetProperty, 2, 1) \
148 : F(DebugPropertyKindFromDetails, 1, 1) \
149 : F(DebugPropertyAttributesFromDetails, 1, 1) \
150 : F(CheckExecutionState, 1, 1) \
151 : F(GetFrameCount, 1, 1) \
152 : F(GetFrameDetails, 2, 1) \
153 : F(GetScopeCount, 2, 1) \
154 : F(GetScopeDetails, 4, 1) \
155 : F(GetAllScopesDetails, 4, 1) \
156 : F(GetFunctionScopeCount, 1, 1) \
157 : F(GetFunctionScopeDetails, 2, 1) \
158 : F(GetGeneratorScopeCount, 1, 1) \
159 : F(GetGeneratorScopeDetails, 2, 1) \
160 : F(SetScopeVariableValue, 6, 1) \
161 : F(DebugPrintScopes, 0, 1) \
162 : F(SetBreakPointsActive, 1, 1) \
163 : F(GetBreakLocations, 2, 1) \
164 : F(SetFunctionBreakPoint, 3, 1) \
165 : F(SetScriptBreakPoint, 4, 1) \
166 : F(ClearBreakPoint, 1, 1) \
167 : F(ChangeBreakOnException, 2, 1) \
168 : F(IsBreakOnException, 1, 1) \
169 : F(PrepareStep, 2, 1) \
170 : F(ClearStepping, 0, 1) \
171 : F(DebugEvaluate, 5, 1) \
172 : F(DebugEvaluateGlobal, 2, 1) \
173 : F(DebugGetLoadedScripts, 0, 1) \
174 : F(DebugReferencedBy, 3, 1) \
175 : F(DebugConstructedBy, 2, 1) \
176 : F(DebugGetPrototype, 1, 1) \
177 : F(DebugSetScriptSource, 2, 1) \
178 : F(FunctionGetInferredName, 1, 1) \
179 : F(FunctionGetDebugName, 1, 1) \
180 : F(GetDebugContext, 0, 1) \
181 : F(CollectGarbage, 1, 1) \
182 : F(GetHeapUsage, 0, 1) \
183 : F(GetScript, 1, 1) \
184 : F(ScriptLineCount, 1, 1) \
185 : F(ScriptLineStartPosition, 2, 1) \
186 : F(ScriptLineEndPosition, 2, 1) \
187 : F(ScriptLocationFromLine, 4, 1) \
188 : F(ScriptLocationFromLine2, 4, 1) \
189 : F(ScriptPositionInfo, 3, 1) \
190 : F(ScriptPositionInfo2, 3, 1) \
191 : F(ScriptSourceLine, 2, 1) \
192 : F(DebugOnFunctionCall, 1, 1) \
193 : F(DebugPrepareStepInSuspendedGenerator, 0, 1) \
194 : F(DebugRecordGenerator, 1, 1) \
195 : F(DebugPushPromise, 1, 1) \
196 : F(DebugPopPromise, 0, 1) \
197 : F(DebugPromiseReject, 2, 1) \
198 : F(DebugAsyncEventEnqueueRecurring, 2, 1) \
199 : F(DebugAsyncFunctionPromiseCreated, 1, 1) \
200 : F(DebugIsActive, 0, 1) \
201 : F(DebugBreakInOptimizedCode, 0, 1) \
202 : F(DebugCollectCoverage, 0, 1) \
203 : F(DebugTogglePreciseCoverage, 1, 1)
204 :
205 : #define FOR_EACH_INTRINSIC_ERROR(F) F(ErrorToString, 1, 1)
206 :
207 : #define FOR_EACH_INTRINSIC_FORIN(F) \
208 : F(ForInEnumerate, 1, 1) \
209 : F(ForInFilter, 2, 1) \
210 : F(ForInHasProperty, 2, 1)
211 :
212 : #define FOR_EACH_INTRINSIC_INTERPRETER(F) \
213 : F(InterpreterNewClosure, 4, 1) \
214 : F(InterpreterTraceBytecodeEntry, 3, 1) \
215 : F(InterpreterTraceBytecodeExit, 3, 1) \
216 : F(InterpreterAdvanceBytecodeOffset, 2, 1)
217 :
218 : #define FOR_EACH_INTRINSIC_FUNCTION(F) \
219 : F(FunctionGetName, 1, 1) \
220 : F(FunctionSetName, 2, 1) \
221 : F(FunctionRemovePrototype, 1, 1) \
222 : F(FunctionGetScript, 1, 1) \
223 : F(FunctionGetScriptId, 1, 1) \
224 : F(FunctionGetSourceCode, 1, 1) \
225 : F(FunctionGetScriptSourcePosition, 1, 1) \
226 : F(FunctionGetContextData, 1, 1) \
227 : F(FunctionSetInstanceClassName, 2, 1) \
228 : F(FunctionSetLength, 2, 1) \
229 : F(FunctionSetPrototype, 2, 1) \
230 : F(FunctionIsAPIFunction, 1, 1) \
231 : F(SetCode, 2, 1) \
232 : F(SetNativeFlag, 1, 1) \
233 : F(IsConstructor, 1, 1) \
234 : F(SetForceInlineFlag, 1, 1) \
235 : F(Call, -1 /* >= 2 */, 1) \
236 : F(ConvertReceiver, 1, 1) \
237 : F(IsFunction, 1, 1) \
238 : F(FunctionToString, 1, 1)
239 :
240 : #define FOR_EACH_INTRINSIC_GENERATOR(F) \
241 : F(CreateJSGeneratorObject, 2, 1) \
242 : F(GeneratorClose, 1, 1) \
243 : F(GeneratorGetFunction, 1, 1) \
244 : F(GeneratorGetReceiver, 1, 1) \
245 : F(GeneratorGetContext, 1, 1) \
246 : F(GeneratorGetInputOrDebugPos, 1, 1) \
247 : F(AsyncGeneratorGetAwaitInputOrDebugPos, 1, 1) \
248 : F(AsyncGeneratorResolve, 3, 1) \
249 : F(AsyncGeneratorReject, 2, 1) \
250 : F(GeneratorGetContinuation, 1, 1) \
251 : F(GeneratorGetSourcePosition, 1, 1) \
252 : F(GeneratorGetResumeMode, 1, 1)
253 :
254 : #ifdef V8_INTL_SUPPORT
255 : #define FOR_EACH_INTRINSIC_INTL(F) \
256 : F(CanonicalizeLanguageTag, 1, 1) \
257 : F(AvailableLocalesOf, 1, 1) \
258 : F(GetDefaultICULocale, 0, 1) \
259 : F(GetLanguageTagVariants, 1, 1) \
260 : F(IsInitializedIntlObject, 1, 1) \
261 : F(IsInitializedIntlObjectOfType, 2, 1) \
262 : F(MarkAsInitializedIntlObjectOfType, 2, 1) \
263 : F(CreateDateTimeFormat, 3, 1) \
264 : F(InternalDateFormat, 2, 1) \
265 : F(InternalDateFormatToParts, 2, 1) \
266 : F(CreateNumberFormat, 3, 1) \
267 : F(InternalNumberFormat, 2, 1) \
268 : F(CurrencyDigits, 1, 1) \
269 : F(CreateCollator, 3, 1) \
270 : F(InternalCompare, 3, 1) \
271 : F(CreateBreakIterator, 3, 1) \
272 : F(BreakIteratorAdoptText, 2, 1) \
273 : F(BreakIteratorFirst, 1, 1) \
274 : F(BreakIteratorNext, 1, 1) \
275 : F(BreakIteratorCurrent, 1, 1) \
276 : F(BreakIteratorBreakType, 1, 1) \
277 : F(StringToLowerCaseIntl, 1, 1) \
278 : F(StringToUpperCaseIntl, 1, 1) \
279 : F(StringLocaleConvertCase, 3, 1) \
280 : F(DateCacheVersion, 0, 1)
281 : #else
282 : #define FOR_EACH_INTRINSIC_INTL(F)
283 : #endif
284 :
285 : #define FOR_EACH_INTRINSIC_INTERNAL(F) \
286 : F(AllocateInNewSpace, 1, 1) \
287 : F(AllocateInTargetSpace, 2, 1) \
288 : F(AllocateSeqOneByteString, 1, 1) \
289 : F(AllocateSeqTwoByteString, 1, 1) \
290 : F(CheckIsBootstrapping, 0, 1) \
291 : F(CreateAsyncFromSyncIterator, 1, 1) \
292 : F(CreateListFromArrayLike, 1, 1) \
293 : F(GetAndResetRuntimeCallStats, -1 /* <= 2 */, 1) \
294 : F(ExportFromRuntime, 1, 1) \
295 : F(IncrementUseCounter, 1, 1) \
296 : F(InstallToContext, 1, 1) \
297 : F(Interrupt, 0, 1) \
298 : F(IS_VAR, 1, 1) \
299 : F(NewReferenceError, 2, 1) \
300 : F(NewSyntaxError, 2, 1) \
301 : F(NewTypeError, 2, 1) \
302 : F(OrdinaryHasInstance, 2, 1) \
303 : F(PromoteScheduledException, 0, 1) \
304 : F(ReThrow, 1, 1) \
305 : F(RunMicrotasks, 0, 1) \
306 : F(StackGuard, 0, 1) \
307 : F(Throw, 1, 1) \
308 : F(ThrowApplyNonFunction, 1, 1) \
309 : F(ThrowCannotConvertToPrimitive, 0, 1) \
310 : F(ThrowCalledNonCallable, 1, 1) \
311 : F(ThrowCalledOnNullOrUndefined, 1, 1) \
312 : F(ThrowConstructedNonConstructable, 1, 1) \
313 : F(ThrowConstructorReturnedNonObject, 0, 1) \
314 : F(ThrowGeneratorRunning, 0, 1) \
315 : F(ThrowIllegalInvocation, 0, 1) \
316 : F(ThrowIncompatibleMethodReceiver, 2, 1) \
317 : F(ThrowInvalidHint, 1, 1) \
318 : F(ThrowInvalidStringLength, 0, 1) \
319 : F(ThrowInvalidTypedArrayAlignment, 2, 1) \
320 : F(ThrowIteratorResultNotAnObject, 1, 1) \
321 : F(ThrowSymbolIteratorInvalid, 0, 1) \
322 : F(ThrowNonCallableInInstanceOfCheck, 0, 1) \
323 : F(ThrowNonObjectInInstanceOfCheck, 0, 1) \
324 : F(ThrowNotConstructor, 1, 1) \
325 : F(ThrowRangeError, -1 /* >= 1 */, 1) \
326 : F(ThrowReferenceError, 1, 1) \
327 : F(ThrowStackOverflow, 0, 1) \
328 : F(ThrowSymbolAsyncIteratorInvalid, 0, 1) \
329 : F(ThrowTypeError, -1 /* >= 1 */, 1) \
330 : F(ThrowUndefinedOrNullToObject, 1, 1) \
331 : F(Typeof, 1, 1) \
332 : F(UnwindAndFindExceptionHandler, 0, 1) \
333 : F(AllowDynamicFunction, 1, 1)
334 :
335 : #define FOR_EACH_INTRINSIC_LITERALS(F) \
336 : F(CreateRegExpLiteral, 4, 1) \
337 : F(CreateObjectLiteral, 4, 1) \
338 : F(CreateArrayLiteral, 4, 1) \
339 : F(CreateArrayLiteralStubBailout, 3, 1)
340 :
341 : #define FOR_EACH_INTRINSIC_LIVEEDIT(F) \
342 : F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
343 : F(LiveEditGatherCompileInfo, 2, 1) \
344 : F(LiveEditReplaceScript, 3, 1) \
345 : F(LiveEditFunctionSourceUpdated, 2, 1) \
346 : F(LiveEditReplaceFunctionCode, 2, 1) \
347 : F(LiveEditFixupScript, 2, 1) \
348 : F(LiveEditFunctionSetScript, 2, 1) \
349 : F(LiveEditReplaceRefToNestedFunction, 3, 1) \
350 : F(LiveEditPatchFunctionPositions, 2, 1) \
351 : F(LiveEditCheckAndDropActivations, 3, 1) \
352 : F(LiveEditCompareStrings, 2, 1) \
353 : F(LiveEditRestartFrame, 2, 1)
354 :
355 : #define FOR_EACH_INTRINSIC_MATHS(F) F(GenerateRandomNumbers, 0, 1)
356 :
357 : #define FOR_EACH_INTRINSIC_MODULE(F) \
358 : F(DynamicImportCall, 2, 1) \
359 : F(GetModuleNamespace, 1, 1) \
360 : F(LoadModuleVariable, 1, 1) \
361 : F(StoreModuleVariable, 2, 1)
362 :
363 : #define FOR_EACH_INTRINSIC_NUMBERS(F) \
364 : F(IsValidSmi, 1, 1) \
365 : F(StringToNumber, 1, 1) \
366 : F(StringParseInt, 2, 1) \
367 : F(StringParseFloat, 1, 1) \
368 : F(NumberToString, 1, 1) \
369 : F(NumberToStringSkipCache, 1, 1) \
370 : F(NumberToSmi, 1, 1) \
371 : F(SmiLexicographicCompare, 2, 1) \
372 : F(MaxSmi, 0, 1) \
373 : F(IsSmi, 1, 1) \
374 : F(GetHoleNaNUpper, 0, 1) \
375 : F(GetHoleNaNLower, 0, 1)
376 :
377 : #define FOR_EACH_INTRINSIC_OBJECT(F) \
378 : F(AddDictionaryProperty, 3, 1) \
379 : F(GetPrototype, 1, 1) \
380 : F(ObjectHasOwnProperty, 2, 1) \
381 : F(ObjectCreate, 2, 1) \
382 : F(InternalSetPrototype, 2, 1) \
383 : F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
384 : F(GetProperty, 2, 1) \
385 : F(KeyedGetProperty, 2, 1) \
386 : F(AddNamedProperty, 4, 1) \
387 : F(SetProperty, 4, 1) \
388 : F(AddElement, 3, 1) \
389 : F(AppendElement, 2, 1) \
390 : F(DeleteProperty, 3, 1) \
391 : F(ShrinkPropertyDictionary, 2, 1) \
392 : F(HasProperty, 2, 1) \
393 : F(GetOwnPropertyKeys, 2, 1) \
394 : F(GetInterceptorInfo, 1, 1) \
395 : F(ToFastProperties, 1, 1) \
396 : F(AllocateHeapNumber, 0, 1) \
397 : F(NewObject, 2, 1) \
398 : F(FinalizeInstanceSize, 1, 1) \
399 : F(LoadMutableDouble, 2, 1) \
400 : F(TryMigrateInstance, 1, 1) \
401 : F(IsJSGlobalProxy, 1, 1) \
402 : F(DefineAccessorPropertyUnchecked, 5, 1) \
403 : F(DefineDataPropertyInLiteral, 6, 1) \
404 : F(CollectTypeProfile, 3, 1) \
405 : F(GetDataProperty, 2, 1) \
406 : F(GetConstructorName, 1, 1) \
407 : F(HasFastPackedElements, 1, 1) \
408 : F(ValueOf, 1, 1) \
409 : F(IsJSReceiver, 1, 1) \
410 : F(ClassOf, 1, 1) \
411 : F(CopyDataProperties, 2, 1) \
412 : F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
413 : F(DefineGetterPropertyUnchecked, 4, 1) \
414 : F(DefineSetterPropertyUnchecked, 4, 1) \
415 : F(ToObject, 1, 1) \
416 : F(ToPrimitive, 1, 1) \
417 : F(ToPrimitive_Number, 1, 1) \
418 : F(ToNumber, 1, 1) \
419 : F(ToInteger, 1, 1) \
420 : F(ToLength, 1, 1) \
421 : F(ToString, 1, 1) \
422 : F(ToName, 1, 1) \
423 : F(SameValue, 2, 1) \
424 : F(SameValueZero, 2, 1) \
425 : F(Compare, 3, 1) \
426 : F(HasInPrototypeChain, 2, 1) \
427 : F(CreateIterResultObject, 2, 1) \
428 : F(CreateKeyValueArray, 2, 1) \
429 : F(IsAccessCheckNeeded, 1, 1) \
430 : F(CreateDataProperty, 3, 1) \
431 : F(IterableToListCanBeElided, 1, 1)
432 :
433 : #define FOR_EACH_INTRINSIC_OPERATORS(F) \
434 : F(Multiply, 2, 1) \
435 : F(Divide, 2, 1) \
436 : F(Modulus, 2, 1) \
437 : F(Add, 2, 1) \
438 : F(Subtract, 2, 1) \
439 : F(ShiftLeft, 2, 1) \
440 : F(ShiftRight, 2, 1) \
441 : F(ShiftRightLogical, 2, 1) \
442 : F(BitwiseAnd, 2, 1) \
443 : F(BitwiseOr, 2, 1) \
444 : F(BitwiseXor, 2, 1) \
445 : F(Equal, 2, 1) \
446 : F(NotEqual, 2, 1) \
447 : F(StrictEqual, 2, 1) \
448 : F(StrictNotEqual, 2, 1) \
449 : F(LessThan, 2, 1) \
450 : F(GreaterThan, 2, 1) \
451 : F(LessThanOrEqual, 2, 1) \
452 : F(GreaterThanOrEqual, 2, 1) \
453 : F(InstanceOf, 2, 1)
454 :
455 : #define FOR_EACH_INTRINSIC_PROMISE(F) \
456 : F(EnqueueMicrotask, 1, 1) \
457 : F(EnqueuePromiseReactionJob, 1, 1) \
458 : F(EnqueuePromiseResolveThenableJob, 1, 1) \
459 : F(PromiseHookInit, 2, 1) \
460 : F(PromiseHookResolve, 1, 1) \
461 : F(PromiseHookBefore, 1, 1) \
462 : F(PromiseHookAfter, 1, 1) \
463 : F(PromiseMarkAsHandled, 1, 1) \
464 : F(PromiseRejectEventFromStack, 2, 1) \
465 : F(PromiseRevokeReject, 1, 1) \
466 : F(PromiseResult, 1, 1) \
467 : F(PromiseStatus, 1, 1) \
468 : F(ReportPromiseReject, 2, 1) \
469 : F(IncrementWaitCount, 0, 1) \
470 : F(DecrementWaitCount, 0, 1)
471 :
472 : #define FOR_EACH_INTRINSIC_PROXY(F) \
473 : F(IsJSProxy, 1, 1) \
474 : F(JSProxyCall, -1 /* >= 2 */, 1) \
475 : F(JSProxyConstruct, -1 /* >= 3 */, 1) \
476 : F(JSProxyGetTarget, 1, 1) \
477 : F(JSProxyGetHandler, 1, 1) \
478 : F(JSProxyRevoke, 1, 1)
479 :
480 : #define FOR_EACH_INTRINSIC_REGEXP(F) \
481 : F(IsRegExp, 1, 1) \
482 : F(RegExpCreate, 1, 1) \
483 : F(RegExpExec, 4, 1) \
484 : F(RegExpExecMultiple, 4, 1) \
485 : F(RegExpExecReThrow, 0, 1) \
486 : F(RegExpInitializeAndCompile, 3, 1) \
487 : F(RegExpInternalReplace, 3, 1) \
488 : F(RegExpReplace, 3, 1) \
489 : F(RegExpSplit, 3, 1) \
490 : F(StringReplaceGlobalRegExpWithString, 4, 1) \
491 : F(StringReplaceNonGlobalRegExpWithFunction, 3, 1) \
492 : F(StringSplit, 3, 1)
493 :
494 : #define FOR_EACH_INTRINSIC_SCOPES(F) \
495 : F(ThrowConstAssignError, 0, 1) \
496 : F(DeclareGlobals, 3, 1) \
497 : F(DeclareGlobalsForInterpreter, 3, 1) \
498 : F(InitializeVarGlobal, 3, 1) \
499 : F(DeclareEvalFunction, 2, 1) \
500 : F(DeclareEvalVar, 1, 1) \
501 : F(NewSloppyArguments_Generic, 1, 1) \
502 : F(NewStrictArguments, 1, 1) \
503 : F(NewRestParameter, 1, 1) \
504 : F(NewSloppyArguments, 3, 1) \
505 : F(NewArgumentsElements, 2, 1) \
506 : F(NewClosure, 3, 1) \
507 : F(NewClosure_Tenured, 3, 1) \
508 : F(NewScriptContext, 2, 1) \
509 : F(NewFunctionContext, 2, 1) \
510 : F(PushModuleContext, 3, 1) \
511 : F(PushWithContext, 3, 1) \
512 : F(PushCatchContext, 4, 1) \
513 : F(PushBlockContext, 2, 1) \
514 : F(DeleteLookupSlot, 1, 1) \
515 : F(LoadLookupSlot, 1, 1) \
516 : F(LoadLookupSlotInsideTypeof, 1, 1) \
517 : F(StoreLookupSlot_Sloppy, 2, 1) \
518 : F(StoreLookupSlot_Strict, 2, 1)
519 :
520 : #define FOR_EACH_INTRINSIC_STRINGS(F) \
521 : F(GetSubstitution, 5, 1) \
522 : F(StringReplaceOneCharWithString, 3, 1) \
523 : F(StringIndexOf, 3, 1) \
524 : F(StringIndexOfUnchecked, 3, 1) \
525 : F(StringLastIndexOf, 2, 1) \
526 : F(SubString, 3, 1) \
527 : F(StringAdd, 2, 1) \
528 : F(InternalizeString, 1, 1) \
529 : F(StringCharCodeAtRT, 2, 1) \
530 : F(StringCompare, 2, 1) \
531 : F(StringBuilderConcat, 3, 1) \
532 : F(StringBuilderJoin, 3, 1) \
533 : F(SparseJoinWithSeparator, 3, 1) \
534 : F(StringToArray, 2, 1) \
535 : F(StringLessThan, 2, 1) \
536 : F(StringLessThanOrEqual, 2, 1) \
537 : F(StringGreaterThan, 2, 1) \
538 : F(StringGreaterThanOrEqual, 2, 1) \
539 : F(StringEqual, 2, 1) \
540 : F(StringNotEqual, 2, 1) \
541 : F(FlattenString, 1, 1) \
542 : F(StringCharFromCode, 1, 1) \
543 : F(ExternalStringGetChar, 2, 1) \
544 : F(StringCharCodeAt, 2, 1)
545 :
546 : #define FOR_EACH_INTRINSIC_SYMBOL(F) \
547 : F(CreateSymbol, 1, 1) \
548 : F(CreatePrivateSymbol, 1, 1) \
549 : F(SymbolDescription, 1, 1) \
550 : F(SymbolDescriptiveString, 1, 1) \
551 : F(SymbolIsPrivate, 1, 1)
552 :
553 : #define FOR_EACH_INTRINSIC_TEST(F) \
554 : F(ConstructDouble, 2, 1) \
555 : F(ConstructConsString, 2, 1) \
556 : F(DeoptimizeFunction, 1, 1) \
557 : F(DeoptimizeNow, 0, 1) \
558 : F(RunningInSimulator, 0, 1) \
559 : F(IsConcurrentRecompilationSupported, 0, 1) \
560 : F(OptimizeFunctionOnNextCall, -1, 1) \
561 : F(TypeProfile, 1, 1) \
562 : F(OptimizeOsr, -1, 1) \
563 : F(NeverOptimizeFunction, 1, 1) \
564 : F(GetOptimizationStatus, -1, 1) \
565 : F(UnblockConcurrentRecompilation, 0, 1) \
566 : F(GetOptimizationCount, 1, 1) \
567 : F(GetDeoptCount, 1, 1) \
568 : F(GetUndetectable, 0, 1) \
569 : F(GetCallable, 0, 1) \
570 : F(ClearFunctionFeedback, 1, 1) \
571 : F(CheckWasmWrapperElision, 2, 1) \
572 : F(NotifyContextDisposed, 0, 1) \
573 : F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
574 : F(DebugPrint, 1, 1) \
575 : F(DebugTrace, 0, 1) \
576 : F(GetExceptionDetails, 1, 1) \
577 : F(GlobalPrint, 1, 1) \
578 : F(SystemBreak, 0, 1) \
579 : F(SetFlags, 1, 1) \
580 : F(Abort, 1, 1) \
581 : F(AbortJS, 1, 1) \
582 : F(NativeScriptsCount, 0, 1) \
583 : F(GetV8Version, 0, 1) \
584 : F(DisassembleFunction, 1, 1) \
585 : F(TraceEnter, 0, 1) \
586 : F(TraceExit, 1, 1) \
587 : F(TraceTailCall, 0, 1) \
588 : F(HaveSameMap, 2, 1) \
589 : F(InNewSpace, 1, 1) \
590 : F(HasFastSmiElements, 1, 1) \
591 : F(HasFastObjectElements, 1, 1) \
592 : F(HasFastSmiOrObjectElements, 1, 1) \
593 : F(HasFastDoubleElements, 1, 1) \
594 : F(HasFastHoleyElements, 1, 1) \
595 : F(HasDictionaryElements, 1, 1) \
596 : F(HasSloppyArgumentsElements, 1, 1) \
597 : F(HasFixedTypedArrayElements, 1, 1) \
598 : F(HasFastProperties, 1, 1) \
599 : F(HasFixedUint8Elements, 1, 1) \
600 : F(HasFixedInt8Elements, 1, 1) \
601 : F(HasFixedUint16Elements, 1, 1) \
602 : F(HasFixedInt16Elements, 1, 1) \
603 : F(HasFixedUint32Elements, 1, 1) \
604 : F(HasFixedInt32Elements, 1, 1) \
605 : F(HasFixedFloat32Elements, 1, 1) \
606 : F(HasFixedFloat64Elements, 1, 1) \
607 : F(HasFixedUint8ClampedElements, 1, 1) \
608 : F(SpeciesProtector, 0, 1) \
609 : F(SerializeWasmModule, 1, 1) \
610 : F(DeserializeWasmModule, 2, 1) \
611 : F(IsAsmWasmCode, 1, 1) \
612 : F(IsWasmCode, 1, 1) \
613 : F(DisallowCodegenFromStrings, 0, 1) \
614 : F(ValidateWasmInstancesChain, 2, 1) \
615 : F(ValidateWasmModuleState, 1, 1) \
616 : F(ValidateWasmOrphanedInstance, 1, 1) \
617 : F(SetWasmCompileControls, 2, 1) \
618 : F(SetWasmInstantiateControls, 0, 1) \
619 : F(SetWasmCompileFromPromiseOverload, 0, 1) \
620 : F(ResetWasmOverloads, 0, 1) \
621 : F(HeapObjectVerify, 1, 1) \
622 : F(WasmNumInterpretedCalls, 1, 1) \
623 : F(RedirectToWasmInterpreter, 2, 1)
624 :
625 : #define FOR_EACH_INTRINSIC_TYPEDARRAY(F) \
626 : F(ArrayBufferGetByteLength, 1, 1) \
627 : F(ArrayBufferNeuter, 1, 1) \
628 : F(TypedArrayCopyElements, 3, 1) \
629 : F(ArrayBufferViewGetByteLength, 1, 1) \
630 : F(ArrayBufferViewGetByteOffset, 1, 1) \
631 : F(ArrayBufferViewWasNeutered, 1, 1) \
632 : F(TypedArrayGetLength, 1, 1) \
633 : F(TypedArrayGetBuffer, 1, 1) \
634 : F(TypedArraySetFastCases, 3, 1) \
635 : F(TypedArraySortFast, 1, 1) \
636 : F(TypedArrayMaxSizeInHeap, 0, 1) \
637 : F(IsTypedArray, 1, 1) \
638 : F(IsSharedTypedArray, 1, 1) \
639 : F(IsSharedIntegerTypedArray, 1, 1) \
640 : F(IsSharedInteger32TypedArray, 1, 1)
641 :
642 : #define FOR_EACH_INTRINSIC_WASM(F) \
643 : F(WasmGrowMemory, 1, 1) \
644 : F(WasmMemorySize, 0, 1) \
645 : F(ThrowWasmError, 2, 1) \
646 : F(ThrowWasmErrorFromTrapIf, 1, 1) \
647 : F(ThrowWasmStackOverflow, 0, 1) \
648 : F(WasmThrowTypeError, 0, 1) \
649 : F(WasmThrow, 2, 1) \
650 : F(WasmGetCaughtExceptionValue, 1, 1) \
651 : F(WasmRunInterpreter, 3, 1) \
652 : F(WasmStackGuard, 0, 1) \
653 : F(SetThreadInWasm, 0, 1) \
654 : F(ClearThreadInWasm, 0, 1) \
655 : F(WasmCompileLazy, 0, 1)
656 :
657 : #define FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
658 : F(LoadLookupSlotForCall, 1, 2)
659 :
660 : #define FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
661 : F(ForInPrepare, 1, 3)
662 :
663 : // Most intrinsics are implemented in the runtime/ directory, but ICs are
664 : // implemented in ic.cc for now.
665 : #define FOR_EACH_INTRINSIC_IC(F) \
666 : F(BinaryOpIC_Miss, 2, 1) \
667 : F(BinaryOpIC_MissWithAllocationSite, 3, 1) \
668 : F(CompareIC_Miss, 3, 1) \
669 : F(ElementsTransitionAndStoreIC_Miss, 6, 1) \
670 : F(KeyedLoadIC_Miss, 4, 1) \
671 : F(KeyedStoreIC_Miss, 5, 1) \
672 : F(KeyedStoreIC_Slow, 5, 1) \
673 : F(LoadElementWithInterceptor, 2, 1) \
674 : F(LoadGlobalIC_Miss, 3, 1) \
675 : F(LoadGlobalIC_Slow, 3, 1) \
676 : F(LoadIC_Miss, 4, 1) \
677 : F(LoadPropertyWithInterceptor, 5, 1) \
678 : F(StoreCallbackProperty, 6, 1) \
679 : F(StoreIC_Miss, 5, 1) \
680 : F(StorePropertyWithInterceptor, 5, 1) \
681 : F(ToBooleanIC_Miss, 1, 1) \
682 : F(Unreachable, 0, 1)
683 :
684 : #define FOR_EACH_INTRINSIC_RETURN_OBJECT(F) \
685 : FOR_EACH_INTRINSIC_IC(F) \
686 : FOR_EACH_INTRINSIC_ARRAY(F) \
687 : FOR_EACH_INTRINSIC_ATOMICS(F) \
688 : FOR_EACH_INTRINSIC_CLASSES(F) \
689 : FOR_EACH_INTRINSIC_COLLECTIONS(F) \
690 : FOR_EACH_INTRINSIC_COMPILER(F) \
691 : FOR_EACH_INTRINSIC_DATE(F) \
692 : FOR_EACH_INTRINSIC_DEBUG(F) \
693 : FOR_EACH_INTRINSIC_ERROR(F) \
694 : FOR_EACH_INTRINSIC_FORIN(F) \
695 : FOR_EACH_INTRINSIC_INTERPRETER(F) \
696 : FOR_EACH_INTRINSIC_FUNCTION(F) \
697 : FOR_EACH_INTRINSIC_GENERATOR(F) \
698 : FOR_EACH_INTRINSIC_INTL(F) \
699 : FOR_EACH_INTRINSIC_INTERNAL(F) \
700 : FOR_EACH_INTRINSIC_LITERALS(F) \
701 : FOR_EACH_INTRINSIC_LIVEEDIT(F) \
702 : FOR_EACH_INTRINSIC_MATHS(F) \
703 : FOR_EACH_INTRINSIC_MODULE(F) \
704 : FOR_EACH_INTRINSIC_NUMBERS(F) \
705 : FOR_EACH_INTRINSIC_OBJECT(F) \
706 : FOR_EACH_INTRINSIC_OPERATORS(F) \
707 : FOR_EACH_INTRINSIC_PROMISE(F) \
708 : FOR_EACH_INTRINSIC_PROXY(F) \
709 : FOR_EACH_INTRINSIC_REGEXP(F) \
710 : FOR_EACH_INTRINSIC_SCOPES(F) \
711 : FOR_EACH_INTRINSIC_STRINGS(F) \
712 : FOR_EACH_INTRINSIC_SYMBOL(F) \
713 : FOR_EACH_INTRINSIC_TEST(F) \
714 : FOR_EACH_INTRINSIC_TYPEDARRAY(F) \
715 : FOR_EACH_INTRINSIC_WASM(F)
716 :
717 : // FOR_EACH_INTRINSIC defines the list of all intrinsics, coming in 2 flavors,
718 : // either returning an object or a pair.
719 : #define FOR_EACH_INTRINSIC(F) \
720 : FOR_EACH_INTRINSIC_RETURN_TRIPLE(F) \
721 : FOR_EACH_INTRINSIC_RETURN_PAIR(F) \
722 : FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
723 :
724 :
725 : #define F(name, nargs, ressize) \
726 : Object* Runtime_##name(int args_length, Object** args_object, \
727 : Isolate* isolate);
728 : FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
729 : #undef F
730 :
731 : //---------------------------------------------------------------------------
732 : // Runtime provides access to all C++ runtime functions.
733 :
734 : class Runtime : public AllStatic {
735 : public:
736 : enum FunctionId : int32_t {
737 : #define F(name, nargs, ressize) k##name,
738 : #define I(name, nargs, ressize) kInline##name,
739 : FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)
740 : #undef I
741 : #undef F
742 : kNumFunctions,
743 : };
744 :
745 : enum IntrinsicType { RUNTIME, INLINE };
746 :
747 : // Intrinsic function descriptor.
748 : struct Function {
749 : FunctionId function_id;
750 : IntrinsicType intrinsic_type;
751 : // The JS name of the function.
752 : const char* name;
753 :
754 : // For RUNTIME functions, this is the C++ entry point.
755 : // For INLINE functions this is the C++ entry point of the fall back.
756 : Address entry;
757 :
758 : // The number of arguments expected. nargs is -1 if the function takes
759 : // a variable number of arguments.
760 : int8_t nargs;
761 : // Size of result. Most functions return a single pointer, size 1.
762 : int8_t result_size;
763 : };
764 :
765 : static const int kNotFound = -1;
766 :
767 : // Get the intrinsic function with the given name.
768 : static const Function* FunctionForName(const unsigned char* name, int length);
769 :
770 : // Get the intrinsic function with the given FunctionId.
771 : V8_EXPORT_PRIVATE static const Function* FunctionForId(FunctionId id);
772 :
773 : // Get the intrinsic function with the given function entry address.
774 : static const Function* FunctionForEntry(Address ref);
775 :
776 : // Get the runtime intrinsic function table.
777 : static const Function* RuntimeFunctionTable(Isolate* isolate);
778 :
779 : MUST_USE_RESULT static Maybe<bool> DeleteObjectProperty(
780 : Isolate* isolate, Handle<JSReceiver> receiver, Handle<Object> key,
781 : LanguageMode language_mode);
782 :
783 : MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
784 : Isolate* isolate, Handle<Object> object, Handle<Object> key,
785 : Handle<Object> value, LanguageMode language_mode);
786 :
787 : MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
788 : Isolate* isolate, Handle<Object> object, Handle<Object> key,
789 : bool* is_found_out = nullptr);
790 :
791 : MUST_USE_RESULT static MaybeHandle<JSArray> GetInternalProperties(
792 : Isolate* isolate, Handle<Object>);
793 : };
794 :
795 :
796 : class RuntimeState {
797 : public:
798 : unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
799 : return &to_upper_mapping_;
800 : }
801 : unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
802 : return &to_lower_mapping_;
803 : }
804 :
805 : Runtime::Function* redirected_intrinsic_functions() {
806 : return redirected_intrinsic_functions_.get();
807 : }
808 :
809 : void set_redirected_intrinsic_functions(
810 : Runtime::Function* redirected_intrinsic_functions) {
811 : redirected_intrinsic_functions_.reset(redirected_intrinsic_functions);
812 : }
813 :
814 : private:
815 60782 : RuntimeState() {}
816 : unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
817 : unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
818 :
819 : std::unique_ptr<Runtime::Function[]> redirected_intrinsic_functions_;
820 :
821 : friend class Isolate;
822 : friend class Runtime;
823 :
824 : DISALLOW_COPY_AND_ASSIGN(RuntimeState);
825 : };
826 :
827 : V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
828 :
829 : //---------------------------------------------------------------------------
830 : // Constants used by interface to runtime functions.
831 :
832 : class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
833 : class AllocateTargetSpace : public BitField<AllocationSpace, 1, 3> {};
834 :
835 : class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
836 : class DeclareGlobalsNativeFlag : public BitField<bool, 1, 1> {};
837 : STATIC_ASSERT(LANGUAGE_END == 2);
838 : class DeclareGlobalsLanguageMode : public BitField<LanguageMode, 2, 1> {};
839 :
840 : // A set of bits returned by Runtime_GetOptimizationStatus.
841 : // These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
842 : enum class OptimizationStatus {
843 : kIsFunction = 1 << 0,
844 : kNeverOptimize = 1 << 1,
845 : kAlwaysOptimize = 1 << 2,
846 : kMaybeDeopted = 1 << 3,
847 : kOptimized = 1 << 4,
848 : kTurboFanned = 1 << 5,
849 : kInterpreted = 1 << 6,
850 : };
851 :
852 : } // namespace internal
853 : } // namespace v8
854 :
855 : #endif // V8_RUNTIME_RUNTIME_H_
|