Home | History | Annotate | Download | only in src
      1 
      2 // Copyright 2011 the V8 project authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 
      6 #ifndef V8_BUILTINS_H_
      7 #define V8_BUILTINS_H_
      8 
      9 #include "src/base/flags.h"
     10 #include "src/handles.h"
     11 
     12 namespace v8 {
     13 namespace internal {
     14 
     15 // Forward declarations.
     16 class CodeStubAssembler;
     17 
     18 #define CODE_AGE_LIST_WITH_ARG(V, A)     \
     19   V(Quadragenarian, A)                   \
     20   V(Quinquagenarian, A)                  \
     21   V(Sexagenarian, A)                     \
     22   V(Septuagenarian, A)                   \
     23   V(Octogenarian, A)
     24 
     25 #define CODE_AGE_LIST_IGNORE_ARG(X, V) V(X)
     26 
     27 #define CODE_AGE_LIST(V) \
     28   CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
     29 
     30 #define CODE_AGE_LIST_COMPLETE(V)                  \
     31   V(ToBeExecutedOnce)                              \
     32   V(NotExecuted)                                   \
     33   V(ExecutedOnce)                                  \
     34   V(NoAge)                                         \
     35   CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)
     36 
     37 #define DECLARE_CODE_AGE_BUILTIN(C, V)                           \
     38   V(Make##C##CodeYoungAgainOddMarking, BUILTIN, kNoExtraICState) \
     39   V(Make##C##CodeYoungAgainEvenMarking, BUILTIN, kNoExtraICState)
     40 
     41 // Define list of builtins implemented in C++.
     42 #define BUILTIN_LIST_C(V)                 \
     43   V(Illegal)                              \
     44                                           \
     45   V(EmptyFunction)                        \
     46                                           \
     47   V(ArrayConcat)                          \
     48   V(ArrayPop)                             \
     49   V(ArrayPush)                            \
     50   V(ArrayShift)                           \
     51   V(ArraySlice)                           \
     52   V(ArraySplice)                          \
     53   V(ArrayUnshift)                         \
     54                                           \
     55   V(ArrayBufferConstructor)               \
     56   V(ArrayBufferConstructor_ConstructStub) \
     57   V(ArrayBufferIsView)                    \
     58                                           \
     59   V(BooleanConstructor)                   \
     60   V(BooleanConstructor_ConstructStub)     \
     61   V(BooleanPrototypeToString)             \
     62   V(BooleanPrototypeValueOf)              \
     63                                           \
     64   V(DataViewConstructor)                  \
     65   V(DataViewConstructor_ConstructStub)    \
     66   V(DataViewPrototypeGetBuffer)           \
     67   V(DataViewPrototypeGetByteLength)       \
     68   V(DataViewPrototypeGetByteOffset)       \
     69                                           \
     70   V(DateConstructor)                      \
     71   V(DateConstructor_ConstructStub)        \
     72   V(DateNow)                              \
     73   V(DateParse)                            \
     74   V(DateUTC)                              \
     75   V(DatePrototypeSetDate)                 \
     76   V(DatePrototypeSetFullYear)             \
     77   V(DatePrototypeSetHours)                \
     78   V(DatePrototypeSetMilliseconds)         \
     79   V(DatePrototypeSetMinutes)              \
     80   V(DatePrototypeSetMonth)                \
     81   V(DatePrototypeSetSeconds)              \
     82   V(DatePrototypeSetTime)                 \
     83   V(DatePrototypeSetUTCDate)              \
     84   V(DatePrototypeSetUTCFullYear)          \
     85   V(DatePrototypeSetUTCHours)             \
     86   V(DatePrototypeSetUTCMilliseconds)      \
     87   V(DatePrototypeSetUTCMinutes)           \
     88   V(DatePrototypeSetUTCMonth)             \
     89   V(DatePrototypeSetUTCSeconds)           \
     90   V(DatePrototypeToDateString)            \
     91   V(DatePrototypeToISOString)             \
     92   V(DatePrototypeToPrimitive)             \
     93   V(DatePrototypeToUTCString)             \
     94   V(DatePrototypeToString)                \
     95   V(DatePrototypeToTimeString)            \
     96   V(DatePrototypeValueOf)                 \
     97   V(DatePrototypeGetYear)                 \
     98   V(DatePrototypeSetYear)                 \
     99   V(DatePrototypeToJson)                  \
    100                                           \
    101   V(FunctionConstructor)                  \
    102   V(FunctionPrototypeBind)                \
    103   V(FunctionPrototypeToString)            \
    104                                           \
    105   V(GeneratorFunctionConstructor)         \
    106   V(AsyncFunctionConstructor)             \
    107                                           \
    108   V(GlobalDecodeURI)                      \
    109   V(GlobalDecodeURIComponent)             \
    110   V(GlobalEncodeURI)                      \
    111   V(GlobalEncodeURIComponent)             \
    112   V(GlobalEscape)                         \
    113   V(GlobalUnescape)                       \
    114                                           \
    115   V(GlobalEval)                           \
    116                                           \
    117   V(JsonParse)                            \
    118   V(JsonStringify)                        \
    119                                           \
    120   V(MathAcos)                             \
    121   V(MathAsin)                             \
    122   V(MathFround)                           \
    123   V(MathImul)                             \
    124                                           \
    125   V(ObjectAssign)                         \
    126   V(ObjectCreate)                         \
    127   V(ObjectDefineGetter)                   \
    128   V(ObjectDefineProperties)               \
    129   V(ObjectDefineProperty)                 \
    130   V(ObjectDefineSetter)                   \
    131   V(ObjectEntries)                        \
    132   V(ObjectFreeze)                         \
    133   V(ObjectGetOwnPropertyDescriptor)       \
    134   V(ObjectGetOwnPropertyDescriptors)      \
    135   V(ObjectGetOwnPropertyNames)            \
    136   V(ObjectGetOwnPropertySymbols)          \
    137   V(ObjectGetPrototypeOf)                 \
    138   V(ObjectIs)                             \
    139   V(ObjectIsExtensible)                   \
    140   V(ObjectIsFrozen)                       \
    141   V(ObjectIsSealed)                       \
    142   V(ObjectKeys)                           \
    143   V(ObjectLookupGetter)                   \
    144   V(ObjectLookupSetter)                   \
    145   V(ObjectPreventExtensions)              \
    146   V(ObjectProtoToString)                  \
    147   V(ObjectSeal)                           \
    148   V(ObjectValues)                         \
    149                                           \
    150   V(ProxyConstructor)                     \
    151   V(ProxyConstructor_ConstructStub)       \
    152                                           \
    153   V(ReflectDefineProperty)                \
    154   V(ReflectDeleteProperty)                \
    155   V(ReflectGet)                           \
    156   V(ReflectGetOwnPropertyDescriptor)      \
    157   V(ReflectGetPrototypeOf)                \
    158   V(ReflectHas)                           \
    159   V(ReflectIsExtensible)                  \
    160   V(ReflectOwnKeys)                       \
    161   V(ReflectPreventExtensions)             \
    162   V(ReflectSet)                           \
    163   V(ReflectSetPrototypeOf)                \
    164                                           \
    165   V(StringFromCodePoint)                  \
    166                                           \
    167   V(StringPrototypeTrim)                  \
    168   V(StringPrototypeTrimLeft)              \
    169   V(StringPrototypeTrimRight)             \
    170                                           \
    171   V(SymbolConstructor)                    \
    172   V(SymbolConstructor_ConstructStub)      \
    173                                           \
    174   V(TypedArrayPrototypeBuffer)            \
    175                                           \
    176   V(HandleApiCall)                        \
    177   V(HandleApiCallAsFunction)              \
    178   V(HandleApiCallAsConstructor)           \
    179                                           \
    180   V(RestrictedFunctionPropertiesThrower)  \
    181   V(RestrictedStrictArgumentsPropertiesThrower)
    182 
    183 // Define list of builtins implemented in assembly.
    184 #define BUILTIN_LIST_A(V)                                                    \
    185   V(AllocateInNewSpace, BUILTIN, kNoExtraICState)                            \
    186   V(AllocateInOldSpace, BUILTIN, kNoExtraICState)                            \
    187                                                                              \
    188   V(ArgumentsAdaptorTrampoline, BUILTIN, kNoExtraICState)                    \
    189                                                                              \
    190   V(ConstructedNonConstructable, BUILTIN, kNoExtraICState)                   \
    191                                                                              \
    192   V(CallFunction_ReceiverIsNullOrUndefined, BUILTIN, kNoExtraICState)        \
    193   V(CallFunction_ReceiverIsNotNullOrUndefined, BUILTIN, kNoExtraICState)     \
    194   V(CallFunction_ReceiverIsAny, BUILTIN, kNoExtraICState)                    \
    195   V(TailCallFunction_ReceiverIsNullOrUndefined, BUILTIN, kNoExtraICState)    \
    196   V(TailCallFunction_ReceiverIsNotNullOrUndefined, BUILTIN, kNoExtraICState) \
    197   V(TailCallFunction_ReceiverIsAny, BUILTIN, kNoExtraICState)                \
    198   V(CallBoundFunction, BUILTIN, kNoExtraICState)                             \
    199   V(TailCallBoundFunction, BUILTIN, kNoExtraICState)                         \
    200   V(Call_ReceiverIsNullOrUndefined, BUILTIN, kNoExtraICState)                \
    201   V(Call_ReceiverIsNotNullOrUndefined, BUILTIN, kNoExtraICState)             \
    202   V(Call_ReceiverIsAny, BUILTIN, kNoExtraICState)                            \
    203   V(TailCall_ReceiverIsNullOrUndefined, BUILTIN, kNoExtraICState)            \
    204   V(TailCall_ReceiverIsNotNullOrUndefined, BUILTIN, kNoExtraICState)         \
    205   V(TailCall_ReceiverIsAny, BUILTIN, kNoExtraICState)                        \
    206                                                                              \
    207   V(ConstructFunction, BUILTIN, kNoExtraICState)                             \
    208   V(ConstructBoundFunction, BUILTIN, kNoExtraICState)                        \
    209   V(ConstructProxy, BUILTIN, kNoExtraICState)                                \
    210   V(Construct, BUILTIN, kNoExtraICState)                                     \
    211                                                                              \
    212   V(StringToNumber, BUILTIN, kNoExtraICState)                                \
    213   V(NonNumberToNumber, BUILTIN, kNoExtraICState)                             \
    214   V(ToNumber, BUILTIN, kNoExtraICState)                                      \
    215                                                                              \
    216   V(Apply, BUILTIN, kNoExtraICState)                                         \
    217                                                                              \
    218   V(HandleFastApiCall, BUILTIN, kNoExtraICState)                             \
    219                                                                              \
    220   V(InOptimizationQueue, BUILTIN, kNoExtraICState)                           \
    221   V(JSConstructStubGeneric, BUILTIN, kNoExtraICState)                        \
    222   V(JSBuiltinsConstructStub, BUILTIN, kNoExtraICState)                       \
    223   V(JSBuiltinsConstructStubForDerived, BUILTIN, kNoExtraICState)             \
    224   V(JSConstructStubApi, BUILTIN, kNoExtraICState)                            \
    225   V(JSEntryTrampoline, BUILTIN, kNoExtraICState)                             \
    226   V(JSConstructEntryTrampoline, BUILTIN, kNoExtraICState)                    \
    227   V(ResumeGeneratorTrampoline, BUILTIN, kNoExtraICState)                     \
    228   V(CompileLazy, BUILTIN, kNoExtraICState)                                   \
    229   V(CompileBaseline, BUILTIN, kNoExtraICState)                               \
    230   V(CompileOptimized, BUILTIN, kNoExtraICState)                              \
    231   V(CompileOptimizedConcurrent, BUILTIN, kNoExtraICState)                    \
    232   V(NotifyDeoptimized, BUILTIN, kNoExtraICState)                             \
    233   V(NotifySoftDeoptimized, BUILTIN, kNoExtraICState)                         \
    234   V(NotifyLazyDeoptimized, BUILTIN, kNoExtraICState)                         \
    235   V(NotifyStubFailure, BUILTIN, kNoExtraICState)                             \
    236   V(NotifyStubFailureSaveDoubles, BUILTIN, kNoExtraICState)                  \
    237                                                                              \
    238   V(InterpreterEntryTrampoline, BUILTIN, kNoExtraICState)                    \
    239   V(InterpreterMarkBaselineOnReturn, BUILTIN, kNoExtraICState)               \
    240   V(InterpreterPushArgsAndCall, BUILTIN, kNoExtraICState)                    \
    241   V(InterpreterPushArgsAndTailCall, BUILTIN, kNoExtraICState)                \
    242   V(InterpreterPushArgsAndConstruct, BUILTIN, kNoExtraICState)               \
    243   V(InterpreterEnterBytecodeDispatch, BUILTIN, kNoExtraICState)              \
    244                                                                              \
    245   V(KeyedLoadIC_Miss, BUILTIN, kNoExtraICState)                              \
    246   V(StoreIC_Miss, BUILTIN, kNoExtraICState)                                  \
    247   V(KeyedStoreIC_Miss, BUILTIN, kNoExtraICState)                             \
    248   V(LoadIC_Getter_ForDeopt, LOAD_IC, kNoExtraICState)                        \
    249   V(KeyedLoadIC_Megamorphic, KEYED_LOAD_IC, kNoExtraICState)                 \
    250                                                                              \
    251   V(StoreIC_Setter_ForDeopt, STORE_IC, StoreICState::kStrictModeState)       \
    252                                                                              \
    253   V(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, kNoExtraICState)               \
    254   V(KeyedStoreIC_Megamorphic_Strict, KEYED_STORE_IC,                         \
    255     StoreICState::kStrictModeState)                                          \
    256                                                                              \
    257   V(DatePrototypeGetDate, BUILTIN, kNoExtraICState)                          \
    258   V(DatePrototypeGetDay, BUILTIN, kNoExtraICState)                           \
    259   V(DatePrototypeGetFullYear, BUILTIN, kNoExtraICState)                      \
    260   V(DatePrototypeGetHours, BUILTIN, kNoExtraICState)                         \
    261   V(DatePrototypeGetMilliseconds, BUILTIN, kNoExtraICState)                  \
    262   V(DatePrototypeGetMinutes, BUILTIN, kNoExtraICState)                       \
    263   V(DatePrototypeGetMonth, BUILTIN, kNoExtraICState)                         \
    264   V(DatePrototypeGetSeconds, BUILTIN, kNoExtraICState)                       \
    265   V(DatePrototypeGetTime, BUILTIN, kNoExtraICState)                          \
    266   V(DatePrototypeGetTimezoneOffset, BUILTIN, kNoExtraICState)                \
    267   V(DatePrototypeGetUTCDate, BUILTIN, kNoExtraICState)                       \
    268   V(DatePrototypeGetUTCDay, BUILTIN, kNoExtraICState)                        \
    269   V(DatePrototypeGetUTCFullYear, BUILTIN, kNoExtraICState)                   \
    270   V(DatePrototypeGetUTCHours, BUILTIN, kNoExtraICState)                      \
    271   V(DatePrototypeGetUTCMilliseconds, BUILTIN, kNoExtraICState)               \
    272   V(DatePrototypeGetUTCMinutes, BUILTIN, kNoExtraICState)                    \
    273   V(DatePrototypeGetUTCMonth, BUILTIN, kNoExtraICState)                      \
    274   V(DatePrototypeGetUTCSeconds, BUILTIN, kNoExtraICState)                    \
    275                                                                              \
    276   V(FunctionPrototypeApply, BUILTIN, kNoExtraICState)                        \
    277   V(FunctionPrototypeCall, BUILTIN, kNoExtraICState)                         \
    278                                                                              \
    279   V(ReflectApply, BUILTIN, kNoExtraICState)                                  \
    280   V(ReflectConstruct, BUILTIN, kNoExtraICState)                              \
    281                                                                              \
    282   V(InternalArrayCode, BUILTIN, kNoExtraICState)                             \
    283   V(ArrayCode, BUILTIN, kNoExtraICState)                                     \
    284                                                                              \
    285   V(MathMax, BUILTIN, kNoExtraICState)                                       \
    286   V(MathMin, BUILTIN, kNoExtraICState)                                       \
    287                                                                              \
    288   V(NumberConstructor, BUILTIN, kNoExtraICState)                             \
    289   V(NumberConstructor_ConstructStub, BUILTIN, kNoExtraICState)               \
    290                                                                              \
    291   V(StringConstructor, BUILTIN, kNoExtraICState)                             \
    292   V(StringConstructor_ConstructStub, BUILTIN, kNoExtraICState)               \
    293                                                                              \
    294   V(OnStackReplacement, BUILTIN, kNoExtraICState)                            \
    295   V(InterruptCheck, BUILTIN, kNoExtraICState)                                \
    296   V(StackCheck, BUILTIN, kNoExtraICState)                                    \
    297                                                                              \
    298   V(MarkCodeAsToBeExecutedOnce, BUILTIN, kNoExtraICState)                    \
    299   V(MarkCodeAsExecutedOnce, BUILTIN, kNoExtraICState)                        \
    300   V(MarkCodeAsExecutedTwice, BUILTIN, kNoExtraICState)                       \
    301   CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, V)
    302 
    303 // Define list of builtins implemented in TurboFan (with JS linkage).
    304 #define BUILTIN_LIST_T(V)             \
    305   V(FunctionPrototypeHasInstance, 2)  \
    306   V(GeneratorPrototypeNext, 2)        \
    307   V(GeneratorPrototypeReturn, 2)      \
    308   V(GeneratorPrototypeThrow, 2)       \
    309   V(MathAtan, 2)                      \
    310   V(MathAtan2, 3)                     \
    311   V(MathAtanh, 2)                     \
    312   V(MathCeil, 2)                      \
    313   V(MathCbrt, 2)                      \
    314   V(MathExpm1, 2)                     \
    315   V(MathClz32, 2)                     \
    316   V(MathCos, 2)                       \
    317   V(MathExp, 2)                       \
    318   V(MathFloor, 2)                     \
    319   V(MathLog, 2)                       \
    320   V(MathLog1p, 2)                     \
    321   V(MathLog2, 2)                      \
    322   V(MathLog10, 2)                     \
    323   V(MathRound, 2)                     \
    324   V(MathSin, 2)                       \
    325   V(MathTan, 2)                       \
    326   V(MathSqrt, 2)                      \
    327   V(MathTrunc, 2)                     \
    328   V(ObjectHasOwnProperty, 2)          \
    329   V(ArrayIsArray, 2)                  \
    330   V(StringFromCharCode, 2)            \
    331   V(StringPrototypeCharAt, 2)         \
    332   V(StringPrototypeCharCodeAt, 2)     \
    333   V(TypedArrayPrototypeByteLength, 1) \
    334   V(TypedArrayPrototypeByteOffset, 1) \
    335   V(TypedArrayPrototypeLength, 1)     \
    336   V(AtomicsLoad, 3)                   \
    337   V(AtomicsStore, 4)
    338 
    339 // Define list of builtins implemented in TurboFan (with CallStub linkage).
    340 #define BUILTIN_LIST_S(V)                                                   \
    341   V(LoadGlobalIC_Miss, BUILTIN, kNoExtraICState, LoadGlobalWithVector)      \
    342   V(LoadGlobalIC_Slow, HANDLER, Code::LOAD_GLOBAL_IC, LoadGlobalWithVector) \
    343   V(LoadIC_Miss, BUILTIN, kNoExtraICState, LoadWithVector)                  \
    344   V(LoadIC_Slow, HANDLER, Code::LOAD_IC, LoadWithVector)
    345 
    346 // Define list of builtin handlers implemented in assembly.
    347 #define BUILTIN_LIST_H(V)                    \
    348   V(KeyedLoadIC_Slow,        KEYED_LOAD_IC)  \
    349   V(StoreIC_Slow,            STORE_IC)       \
    350   V(KeyedStoreIC_Slow,       KEYED_STORE_IC) \
    351   V(LoadIC_Normal,           LOAD_IC)        \
    352   V(StoreIC_Normal,          STORE_IC)
    353 
    354 // Define list of builtins used by the debugger implemented in assembly.
    355 #define BUILTIN_LIST_DEBUG_A(V)                  \
    356   V(Return_DebugBreak, BUILTIN, kNoExtraICState) \
    357   V(Slot_DebugBreak, BUILTIN, kNoExtraICState)   \
    358   V(FrameDropper_LiveEdit, BUILTIN, kNoExtraICState)
    359 
    360 class BuiltinFunctionTable;
    361 class ObjectVisitor;
    362 
    363 
    364 class Builtins {
    365  public:
    366   ~Builtins();
    367 
    368   // Generate all builtin code objects. Should be called once during
    369   // isolate initialization.
    370   void SetUp(Isolate* isolate, bool create_heap_objects);
    371   void TearDown();
    372 
    373   // Garbage collection support.
    374   void IterateBuiltins(ObjectVisitor* v);
    375 
    376   // Disassembler support.
    377   const char* Lookup(byte* pc);
    378 
    379   enum Name {
    380 #define DEF_ENUM_C(name) k##name,
    381 #define DEF_ENUM_A(name, kind, extra) k##name,
    382 #define DEF_ENUM_T(name, argc) k##name,
    383 #define DEF_ENUM_S(name, kind, extra, interface_descriptor) k##name,
    384 #define DEF_ENUM_H(name, kind) k##name,
    385     BUILTIN_LIST_C(DEF_ENUM_C) BUILTIN_LIST_A(DEF_ENUM_A)
    386         BUILTIN_LIST_T(DEF_ENUM_T) BUILTIN_LIST_S(DEF_ENUM_S)
    387             BUILTIN_LIST_H(DEF_ENUM_H) BUILTIN_LIST_DEBUG_A(DEF_ENUM_A)
    388 #undef DEF_ENUM_C
    389 #undef DEF_ENUM_A
    390 #undef DEF_ENUM_T
    391 #undef DEF_ENUM_S
    392 #undef DEF_ENUM_H
    393                 builtin_count
    394   };
    395 
    396   enum CFunctionId {
    397 #define DEF_ENUM_C(name) c_##name,
    398     BUILTIN_LIST_C(DEF_ENUM_C)
    399 #undef DEF_ENUM_C
    400     cfunction_count
    401   };
    402 
    403 #define DECLARE_BUILTIN_ACCESSOR_C(name) Handle<Code> name();
    404 #define DECLARE_BUILTIN_ACCESSOR_A(name, kind, extra) Handle<Code> name();
    405 #define DECLARE_BUILTIN_ACCESSOR_T(name, argc) Handle<Code> name();
    406 #define DECLARE_BUILTIN_ACCESSOR_S(name, kind, extra, interface_descriptor) \
    407   Handle<Code> name();
    408 #define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name();
    409   BUILTIN_LIST_C(DECLARE_BUILTIN_ACCESSOR_C)
    410   BUILTIN_LIST_A(DECLARE_BUILTIN_ACCESSOR_A)
    411   BUILTIN_LIST_T(DECLARE_BUILTIN_ACCESSOR_T)
    412   BUILTIN_LIST_S(DECLARE_BUILTIN_ACCESSOR_S)
    413   BUILTIN_LIST_H(DECLARE_BUILTIN_ACCESSOR_H)
    414   BUILTIN_LIST_DEBUG_A(DECLARE_BUILTIN_ACCESSOR_A)
    415 #undef DECLARE_BUILTIN_ACCESSOR_C
    416 #undef DECLARE_BUILTIN_ACCESSOR_A
    417 #undef DECLARE_BUILTIN_ACCESSOR_T
    418 #undef DECLARE_BUILTIN_ACCESSOR_S
    419 #undef DECLARE_BUILTIN_ACCESSOR_H
    420 
    421   // Convenience wrappers.
    422   Handle<Code> CallFunction(
    423       ConvertReceiverMode = ConvertReceiverMode::kAny,
    424       TailCallMode tail_call_mode = TailCallMode::kDisallow);
    425   Handle<Code> Call(ConvertReceiverMode = ConvertReceiverMode::kAny,
    426                     TailCallMode tail_call_mode = TailCallMode::kDisallow);
    427   Handle<Code> CallBoundFunction(TailCallMode tail_call_mode);
    428   Handle<Code> InterpreterPushArgsAndCall(TailCallMode tail_call_mode);
    429 
    430   Code* builtin(Name name) {
    431     // Code::cast cannot be used here since we access builtins
    432     // during the marking phase of mark sweep. See IC::Clear.
    433     return reinterpret_cast<Code*>(builtins_[name]);
    434   }
    435 
    436   Address builtin_address(Name name) {
    437     return reinterpret_cast<Address>(&builtins_[name]);
    438   }
    439 
    440   static Address c_function_address(CFunctionId id) {
    441     return c_functions_[id];
    442   }
    443 
    444   const char* name(int index) {
    445     DCHECK(index >= 0);
    446     DCHECK(index < builtin_count);
    447     return names_[index];
    448   }
    449 
    450   bool is_initialized() const { return initialized_; }
    451 
    452   MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction(
    453       Isolate* isolate, Handle<HeapObject> function, Handle<Object> receiver,
    454       int argc, Handle<Object> args[]);
    455 
    456  private:
    457   Builtins();
    458 
    459   // The external C++ functions called from the code.
    460   static Address const c_functions_[cfunction_count];
    461 
    462   // Note: These are always Code objects, but to conform with
    463   // IterateBuiltins() above which assumes Object**'s for the callback
    464   // function f, we use an Object* array here.
    465   Object* builtins_[builtin_count];
    466   const char* names_[builtin_count];
    467 
    468   static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id);
    469   static void Generate_AllocateInNewSpace(MacroAssembler* masm);
    470   static void Generate_AllocateInOldSpace(MacroAssembler* masm);
    471   static void Generate_ConstructedNonConstructable(MacroAssembler* masm);
    472   static void Generate_CompileLazy(MacroAssembler* masm);
    473   static void Generate_CompileBaseline(MacroAssembler* masm);
    474   static void Generate_InOptimizationQueue(MacroAssembler* masm);
    475   static void Generate_CompileOptimized(MacroAssembler* masm);
    476   static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm);
    477   static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
    478   static void Generate_JSBuiltinsConstructStub(MacroAssembler* masm);
    479   static void Generate_JSBuiltinsConstructStubForDerived(MacroAssembler* masm);
    480   static void Generate_JSConstructStubApi(MacroAssembler* masm);
    481   static void Generate_JSEntryTrampoline(MacroAssembler* masm);
    482   static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
    483   static void Generate_ResumeGeneratorTrampoline(MacroAssembler* masm);
    484   static void Generate_NotifyDeoptimized(MacroAssembler* masm);
    485   static void Generate_NotifySoftDeoptimized(MacroAssembler* masm);
    486   static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm);
    487   static void Generate_NotifyStubFailure(MacroAssembler* masm);
    488   static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm);
    489   static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
    490   static void Generate_StringToNumber(MacroAssembler* masm);
    491   static void Generate_NonNumberToNumber(MacroAssembler* masm);
    492   static void Generate_ToNumber(MacroAssembler* masm);
    493 
    494   static void Generate_Apply(MacroAssembler* masm);
    495 
    496   // ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
    497   static void Generate_CallFunction(MacroAssembler* masm,
    498                                     ConvertReceiverMode mode,
    499                                     TailCallMode tail_call_mode);
    500   static void Generate_CallFunction_ReceiverIsNullOrUndefined(
    501       MacroAssembler* masm) {
    502     Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
    503                           TailCallMode::kDisallow);
    504   }
    505   static void Generate_CallFunction_ReceiverIsNotNullOrUndefined(
    506       MacroAssembler* masm) {
    507     Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
    508                           TailCallMode::kDisallow);
    509   }
    510   static void Generate_CallFunction_ReceiverIsAny(MacroAssembler* masm) {
    511     Generate_CallFunction(masm, ConvertReceiverMode::kAny,
    512                           TailCallMode::kDisallow);
    513   }
    514   static void Generate_TailCallFunction_ReceiverIsNullOrUndefined(
    515       MacroAssembler* masm) {
    516     Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
    517                           TailCallMode::kAllow);
    518   }
    519   static void Generate_TailCallFunction_ReceiverIsNotNullOrUndefined(
    520       MacroAssembler* masm) {
    521     Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
    522                           TailCallMode::kAllow);
    523   }
    524   static void Generate_TailCallFunction_ReceiverIsAny(MacroAssembler* masm) {
    525     Generate_CallFunction(masm, ConvertReceiverMode::kAny,
    526                           TailCallMode::kAllow);
    527   }
    528   // ES6 section 9.4.1.1 [[Call]] ( thisArgument, argumentsList)
    529   static void Generate_CallBoundFunctionImpl(MacroAssembler* masm,
    530                                              TailCallMode tail_call_mode);
    531   static void Generate_CallBoundFunction(MacroAssembler* masm) {
    532     Generate_CallBoundFunctionImpl(masm, TailCallMode::kDisallow);
    533   }
    534   static void Generate_TailCallBoundFunction(MacroAssembler* masm) {
    535     Generate_CallBoundFunctionImpl(masm, TailCallMode::kAllow);
    536   }
    537   // ES6 section 7.3.12 Call(F, V, [argumentsList])
    538   static void Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
    539                             TailCallMode tail_call_mode);
    540   static void Generate_Call_ReceiverIsNullOrUndefined(MacroAssembler* masm) {
    541     Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
    542                   TailCallMode::kDisallow);
    543   }
    544   static void Generate_Call_ReceiverIsNotNullOrUndefined(MacroAssembler* masm) {
    545     Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
    546                   TailCallMode::kDisallow);
    547   }
    548   static void Generate_Call_ReceiverIsAny(MacroAssembler* masm) {
    549     Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kDisallow);
    550   }
    551   static void Generate_TailCall_ReceiverIsNullOrUndefined(
    552       MacroAssembler* masm) {
    553     Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
    554                   TailCallMode::kAllow);
    555   }
    556   static void Generate_TailCall_ReceiverIsNotNullOrUndefined(
    557       MacroAssembler* masm) {
    558     Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
    559                   TailCallMode::kAllow);
    560   }
    561   static void Generate_TailCall_ReceiverIsAny(MacroAssembler* masm) {
    562     Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow);
    563   }
    564 
    565   // ES6 section 9.2.2 [[Construct]] ( argumentsList, newTarget)
    566   static void Generate_ConstructFunction(MacroAssembler* masm);
    567   // ES6 section 9.4.1.2 [[Construct]] (argumentsList, newTarget)
    568   static void Generate_ConstructBoundFunction(MacroAssembler* masm);
    569   // ES6 section 9.5.14 [[Construct]] ( argumentsList, newTarget)
    570   static void Generate_ConstructProxy(MacroAssembler* masm);
    571   // ES6 section 7.3.13 Construct (F, [argumentsList], [newTarget])
    572   static void Generate_Construct(MacroAssembler* masm);
    573 
    574   static void Generate_HandleFastApiCall(MacroAssembler* masm);
    575 
    576   static void Generate_DatePrototype_GetField(MacroAssembler* masm,
    577                                               int field_index);
    578   // ES6 section 20.3.4.2 Date.prototype.getDate ( )
    579   static void Generate_DatePrototypeGetDate(MacroAssembler* masm);
    580   // ES6 section 20.3.4.3 Date.prototype.getDay ( )
    581   static void Generate_DatePrototypeGetDay(MacroAssembler* masm);
    582   // ES6 section 20.3.4.4 Date.prototype.getFullYear ( )
    583   static void Generate_DatePrototypeGetFullYear(MacroAssembler* masm);
    584   // ES6 section 20.3.4.5 Date.prototype.getHours ( )
    585   static void Generate_DatePrototypeGetHours(MacroAssembler* masm);
    586   // ES6 section 20.3.4.6 Date.prototype.getMilliseconds ( )
    587   static void Generate_DatePrototypeGetMilliseconds(MacroAssembler* masm);
    588   // ES6 section 20.3.4.7 Date.prototype.getMinutes ( )
    589   static void Generate_DatePrototypeGetMinutes(MacroAssembler* masm);
    590   // ES6 section 20.3.4.8 Date.prototype.getMonth ( )
    591   static void Generate_DatePrototypeGetMonth(MacroAssembler* masm);
    592   // ES6 section 20.3.4.9 Date.prototype.getSeconds ( )
    593   static void Generate_DatePrototypeGetSeconds(MacroAssembler* masm);
    594   // ES6 section 20.3.4.10 Date.prototype.getTime ( )
    595   static void Generate_DatePrototypeGetTime(MacroAssembler* masm);
    596   // ES6 section 20.3.4.11 Date.prototype.getTimezoneOffset ( )
    597   static void Generate_DatePrototypeGetTimezoneOffset(MacroAssembler* masm);
    598   // ES6 section 20.3.4.12 Date.prototype.getUTCDate ( )
    599   static void Generate_DatePrototypeGetUTCDate(MacroAssembler* masm);
    600   // ES6 section 20.3.4.13 Date.prototype.getUTCDay ( )
    601   static void Generate_DatePrototypeGetUTCDay(MacroAssembler* masm);
    602   // ES6 section 20.3.4.14 Date.prototype.getUTCFullYear ( )
    603   static void Generate_DatePrototypeGetUTCFullYear(MacroAssembler* masm);
    604   // ES6 section 20.3.4.15 Date.prototype.getUTCHours ( )
    605   static void Generate_DatePrototypeGetUTCHours(MacroAssembler* masm);
    606   // ES6 section 20.3.4.16 Date.prototype.getUTCMilliseconds ( )
    607   static void Generate_DatePrototypeGetUTCMilliseconds(MacroAssembler* masm);
    608   // ES6 section 20.3.4.17 Date.prototype.getUTCMinutes ( )
    609   static void Generate_DatePrototypeGetUTCMinutes(MacroAssembler* masm);
    610   // ES6 section 20.3.4.18 Date.prototype.getUTCMonth ( )
    611   static void Generate_DatePrototypeGetUTCMonth(MacroAssembler* masm);
    612   // ES6 section 20.3.4.19 Date.prototype.getUTCSeconds ( )
    613   static void Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm);
    614 
    615   static void Generate_FunctionPrototypeApply(MacroAssembler* masm);
    616   static void Generate_FunctionPrototypeCall(MacroAssembler* masm);
    617 
    618   static void Generate_ReflectApply(MacroAssembler* masm);
    619   static void Generate_ReflectConstruct(MacroAssembler* masm);
    620 
    621   static void Generate_InternalArrayCode(MacroAssembler* masm);
    622   static void Generate_ArrayCode(MacroAssembler* masm);
    623 
    624   // ES6 section 20.2.2.6 Math.atan ( x )
    625   static void Generate_MathAtan(CodeStubAssembler* assembler);
    626   // ES6 section 20.2.2.8 Math.atan2 ( y, x )
    627   static void Generate_MathAtan2(CodeStubAssembler* assembler);
    628   // ES6 section 20.2.2.7 Math.atanh ( x )
    629   static void Generate_MathAtanh(CodeStubAssembler* assembler);
    630   // ES6 section 20.2.2.10 Math.ceil ( x )
    631   static void Generate_MathCeil(CodeStubAssembler* assembler);
    632   // ES6 section 20.2.2.9 Math.ceil ( x )
    633   static void Generate_MathCbrt(CodeStubAssembler* assembler);
    634   // ES6 section 20.2.2.15 Math.expm1 ( x )
    635   static void Generate_MathExpm1(CodeStubAssembler* assembler);
    636   // ES6 section 20.2.2.11 Math.clz32 ( x )
    637   static void Generate_MathClz32(CodeStubAssembler* assembler);
    638   // ES6 section 20.2.2.12 Math.cos ( x )
    639   static void Generate_MathCos(CodeStubAssembler* assembler);
    640   // ES6 section 20.2.2.14 Math.exp ( x )
    641   static void Generate_MathExp(CodeStubAssembler* assembler);
    642   // ES6 section 20.2.2.16 Math.floor ( x )
    643   static void Generate_MathFloor(CodeStubAssembler* assembler);
    644   // ES6 section 20.2.2.20 Math.log ( x )
    645   static void Generate_MathLog(CodeStubAssembler* assembler);
    646   // ES6 section 20.2.2.21 Math.log ( x )
    647   static void Generate_MathLog1p(CodeStubAssembler* assembler);
    648 
    649   static void Generate_MathLog2(CodeStubAssembler* assembler);
    650   static void Generate_MathLog10(CodeStubAssembler* assembler);
    651 
    652   enum class MathMaxMinKind { kMax, kMin };
    653   static void Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind);
    654   // ES6 section 20.2.2.24 Math.max ( value1, value2 , ...values )
    655   static void Generate_MathMax(MacroAssembler* masm) {
    656     Generate_MathMaxMin(masm, MathMaxMinKind::kMax);
    657   }
    658   // ES6 section 20.2.2.25 Math.min ( value1, value2 , ...values )
    659   static void Generate_MathMin(MacroAssembler* masm) {
    660     Generate_MathMaxMin(masm, MathMaxMinKind::kMin);
    661   }
    662   // ES6 section 20.2.2.28 Math.round ( x )
    663   static void Generate_MathRound(CodeStubAssembler* assembler);
    664   // ES6 section 20.2.2.20 Math.sin ( x )
    665   static void Generate_MathSin(CodeStubAssembler* assembler);
    666   // ES6 section 20.2.2.32 Math.sqrt ( x )
    667   static void Generate_MathSqrt(CodeStubAssembler* assembler);
    668   // ES6 section 20.2.2.33 Math.sin ( x )
    669   static void Generate_MathTan(CodeStubAssembler* assembler);
    670   // ES6 section 20.2.2.35 Math.trunc ( x )
    671   static void Generate_MathTrunc(CodeStubAssembler* assembler);
    672 
    673   // ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Call]] case.
    674   static void Generate_NumberConstructor(MacroAssembler* masm);
    675   // ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Construct]] case.
    676   static void Generate_NumberConstructor_ConstructStub(MacroAssembler* masm);
    677 
    678   // ES6 section 19.2.3.6 Function.prototype [ @@hasInstance ] ( V )
    679   static void Generate_FunctionPrototypeHasInstance(
    680       CodeStubAssembler* assembler);
    681 
    682   // ES6 section 25.3.1.2 Generator.prototype.next ( value )
    683   static void Generate_GeneratorPrototypeNext(CodeStubAssembler* assembler);
    684   // ES6 section 25.3.1.3 Generator.prototype.return ( value )
    685   static void Generate_GeneratorPrototypeReturn(CodeStubAssembler* assembler);
    686   // ES6 section 25.3.1.4 Generator.prototype.throw ( exception )
    687   static void Generate_GeneratorPrototypeThrow(CodeStubAssembler* assembler);
    688 
    689   // ES6 section 19.1.3.2 Object.prototype.hasOwnProperty
    690   static void Generate_ObjectHasOwnProperty(CodeStubAssembler* assembler);
    691 
    692   // ES6 section 22.1.2.2 Array.isArray
    693   static void Generate_ArrayIsArray(CodeStubAssembler* assembler);
    694 
    695   // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits )
    696   static void Generate_StringFromCharCode(CodeStubAssembler* assembler);
    697   // ES6 section 21.1.3.1 String.prototype.charAt ( pos )
    698   static void Generate_StringPrototypeCharAt(CodeStubAssembler* assembler);
    699   // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos )
    700   static void Generate_StringPrototypeCharCodeAt(CodeStubAssembler* assembler);
    701 
    702   static void Generate_StringConstructor(MacroAssembler* masm);
    703   static void Generate_StringConstructor_ConstructStub(MacroAssembler* masm);
    704 
    705   // ES6 section 22.2.3.2 get %TypedArray%.prototype.byteLength
    706   static void Generate_TypedArrayPrototypeByteLength(
    707       CodeStubAssembler* assembler);
    708   // ES6 section 22.2.3.3 get %TypedArray%.prototype.byteOffset
    709   static void Generate_TypedArrayPrototypeByteOffset(
    710       CodeStubAssembler* assembler);
    711   // ES6 section 22.2.3.18 get %TypedArray%.prototype.length
    712   static void Generate_TypedArrayPrototypeLength(CodeStubAssembler* assembler);
    713 
    714   static void Generate_OnStackReplacement(MacroAssembler* masm);
    715   static void Generate_InterruptCheck(MacroAssembler* masm);
    716   static void Generate_StackCheck(MacroAssembler* masm);
    717 
    718   static void Generate_InterpreterEntryTrampoline(MacroAssembler* masm);
    719   static void Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm);
    720   static void Generate_InterpreterMarkBaselineOnReturn(MacroAssembler* masm);
    721   static void Generate_InterpreterPushArgsAndCall(MacroAssembler* masm) {
    722     return Generate_InterpreterPushArgsAndCallImpl(masm,
    723                                                    TailCallMode::kDisallow);
    724   }
    725   static void Generate_InterpreterPushArgsAndTailCall(MacroAssembler* masm) {
    726     return Generate_InterpreterPushArgsAndCallImpl(masm, TailCallMode::kAllow);
    727   }
    728   static void Generate_InterpreterPushArgsAndCallImpl(
    729       MacroAssembler* masm, TailCallMode tail_call_mode);
    730   static void Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm);
    731 
    732 #define DECLARE_CODE_AGE_BUILTIN_GENERATOR(C)                \
    733   static void Generate_Make##C##CodeYoungAgainEvenMarking(   \
    734       MacroAssembler* masm);                                 \
    735   static void Generate_Make##C##CodeYoungAgainOddMarking(    \
    736       MacroAssembler* masm);
    737   CODE_AGE_LIST(DECLARE_CODE_AGE_BUILTIN_GENERATOR)
    738 #undef DECLARE_CODE_AGE_BUILTIN_GENERATOR
    739 
    740   static void Generate_MarkCodeAsToBeExecutedOnce(MacroAssembler* masm);
    741   static void Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm);
    742   static void Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm);
    743 
    744   static void Generate_AtomicsLoad(CodeStubAssembler* assembler);
    745   static void Generate_AtomicsStore(CodeStubAssembler* assembler);
    746 
    747   static void InitBuiltinFunctionTable();
    748 
    749   bool initialized_;
    750 
    751   friend class BuiltinFunctionTable;
    752   friend class Isolate;
    753 
    754   DISALLOW_COPY_AND_ASSIGN(Builtins);
    755 };
    756 
    757 }  // namespace internal
    758 }  // namespace v8
    759 
    760 #endif  // V8_BUILTINS_H_
    761