builtins.h 32.3 KB
Newer Older
danno@chromium.org's avatar
danno@chromium.org committed
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5 6 7

#ifndef V8_BUILTINS_H_
#define V8_BUILTINS_H_

8
#include "src/base/flags.h"
9 10
#include "src/handles.h"

11 12
namespace v8 {
namespace internal {
13

14
// Specifies extra arguments required by a C++ builtin.
15 16 17 18 19
enum class BuiltinExtraArguments : uint8_t {
  kNone = 0u,
  kTarget = 1u << 0,
  kNewTarget = 1u << 1,
  kTargetAndNewTarget = kTarget | kNewTarget
20 21
};

22 23 24 25
inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
  return static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs);
}

26

27 28 29 30 31 32 33 34 35 36 37 38
#define CODE_AGE_LIST_WITH_ARG(V, A)     \
  V(Quadragenarian, A)                   \
  V(Quinquagenarian, A)                  \
  V(Sexagenarian, A)                     \
  V(Septuagenarian, A)                   \
  V(Octogenarian, A)

#define CODE_AGE_LIST_IGNORE_ARG(X, V) V(X)

#define CODE_AGE_LIST(V) \
  CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)

39
#define CODE_AGE_LIST_COMPLETE(V)                  \
40
  V(ToBeExecutedOnce)                              \
41 42
  V(NotExecuted)                                   \
  V(ExecutedOnce)                                  \
43 44 45
  V(NoAge)                                         \
  CODE_AGE_LIST_WITH_ARG(CODE_AGE_LIST_IGNORE_ARG, V)

46 47
#define DECLARE_CODE_AGE_BUILTIN(C, V)             \
  V(Make##C##CodeYoungAgainOddMarking, BUILTIN,    \
48
    UNINITIALIZED, kNoExtraICState)                \
49
  V(Make##C##CodeYoungAgainEvenMarking, BUILTIN,   \
50
    UNINITIALIZED, kNoExtraICState)
51 52


53
// Define list of builtins implemented in C++.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#define BUILTIN_LIST_C(V)                                      \
  V(Illegal, kNone)                                            \
                                                               \
  V(EmptyFunction, kNone)                                      \
                                                               \
  V(ArrayConcat, kNone)                                        \
  V(ArrayIsArray, kNone)                                       \
  V(ArrayPop, kNone)                                           \
  V(ArrayPush, kNone)                                          \
  V(ArrayShift, kNone)                                         \
  V(ArraySlice, kNone)                                         \
  V(ArraySplice, kNone)                                        \
  V(ArrayUnshift, kNone)                                       \
                                                               \
  V(ArrayBufferConstructor, kTarget)                           \
  V(ArrayBufferConstructor_ConstructStub, kTargetAndNewTarget) \
  V(ArrayBufferIsView, kNone)                                  \
                                                               \
72 73 74 75 76
  V(DateConstructor, kNone)                                    \
  V(DateConstructor_ConstructStub, kTargetAndNewTarget)        \
  V(DateNow, kNone)                                            \
  V(DateParse, kNone)                                          \
  V(DateUTC, kNone)                                            \
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  V(DatePrototypeSetDate, kNone)                               \
  V(DatePrototypeSetFullYear, kNone)                           \
  V(DatePrototypeSetHours, kNone)                              \
  V(DatePrototypeSetMilliseconds, kNone)                       \
  V(DatePrototypeSetMinutes, kNone)                            \
  V(DatePrototypeSetMonth, kNone)                              \
  V(DatePrototypeSetSeconds, kNone)                            \
  V(DatePrototypeSetTime, kNone)                               \
  V(DatePrototypeSetUTCDate, kNone)                            \
  V(DatePrototypeSetUTCFullYear, kNone)                        \
  V(DatePrototypeSetUTCHours, kNone)                           \
  V(DatePrototypeSetUTCMilliseconds, kNone)                    \
  V(DatePrototypeSetUTCMinutes, kNone)                         \
  V(DatePrototypeSetUTCMonth, kNone)                           \
  V(DatePrototypeSetUTCSeconds, kNone)                         \
  V(DatePrototypeToDateString, kNone)                          \
93 94
  V(DatePrototypeToISOString, kNone)                           \
  V(DatePrototypeToPrimitive, kNone)                           \
95 96 97
  V(DatePrototypeToUTCString, kNone)                           \
  V(DatePrototypeToString, kNone)                              \
  V(DatePrototypeToTimeString, kNone)                          \
98
  V(DatePrototypeValueOf, kNone)                               \
99 100
  V(DatePrototypeGetYear, kNone)                               \
  V(DatePrototypeSetYear, kNone)                               \
101 102 103 104 105 106 107 108 109 110 111
                                                               \
  V(FunctionConstructor, kTargetAndNewTarget)                  \
  V(FunctionPrototypeBind, kNone)                              \
  V(FunctionPrototypeToString, kNone)                          \
                                                               \
  V(GeneratorFunctionConstructor, kTargetAndNewTarget)         \
                                                               \
  V(GlobalEval, kTarget)                                       \
                                                               \
  V(ObjectAssign, kNone)                                       \
  V(ObjectCreate, kNone)                                       \
112
  V(ObjectFreeze, kNone)                                       \
113
  V(ObjectGetOwnPropertyNames, kNone)                          \
114
  V(ObjectGetOwnPropertySymbols, kNone)                        \
115 116 117
  V(ObjectIsExtensible, kNone)                                 \
  V(ObjectIsFrozen, kNone)                                     \
  V(ObjectIsSealed, kNone)                                     \
118
  V(ObjectKeys, kNone)                                         \
119 120
  V(ObjectValues, kNone)                                       \
  V(ObjectEntries, kNone)                                      \
121 122
  V(ObjectPreventExtensions, kNone)                            \
  V(ObjectSeal, kNone)                                         \
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  V(ObjectProtoToString, kNone)                                \
                                                               \
  V(ProxyConstructor, kNone)                                   \
  V(ProxyConstructor_ConstructStub, kTarget)                   \
                                                               \
  V(ReflectDefineProperty, kNone)                              \
  V(ReflectDeleteProperty, kNone)                              \
  V(ReflectGet, kNone)                                         \
  V(ReflectGetOwnPropertyDescriptor, kNone)                    \
  V(ReflectGetPrototypeOf, kNone)                              \
  V(ReflectHas, kNone)                                         \
  V(ReflectIsExtensible, kNone)                                \
  V(ReflectOwnKeys, kNone)                                     \
  V(ReflectPreventExtensions, kNone)                           \
  V(ReflectSet, kNone)                                         \
  V(ReflectSetPrototypeOf, kNone)                              \
                                                               \
  V(SymbolConstructor, kNone)                                  \
  V(SymbolConstructor_ConstructStub, kTarget)                  \
                                                               \
  V(HandleApiCall, kTarget)                                    \
  V(HandleApiCallConstruct, kTarget)                           \
  V(HandleApiCallAsFunction, kNone)                            \
  V(HandleApiCallAsConstructor, kNone)                         \
                                                               \
  V(RestrictedFunctionPropertiesThrower, kNone)                \
149
  V(RestrictedStrictArgumentsPropertiesThrower, kNone)
150 151

// Define list of builtins implemented in assembly.
152 153 154 155 156 157 158 159 160 161
#define BUILTIN_LIST_A(V)                                                      \
  V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
                                                                               \
  V(ConstructedNonConstructable, BUILTIN, UNINITIALIZED, kNoExtraICState)      \
                                                                               \
  V(CallFunction_ReceiverIsNullOrUndefined, BUILTIN, UNINITIALIZED,            \
    kNoExtraICState)                                                           \
  V(CallFunction_ReceiverIsNotNullOrUndefined, BUILTIN, UNINITIALIZED,         \
    kNoExtraICState)                                                           \
  V(CallFunction_ReceiverIsAny, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
ishell's avatar
ishell committed
162 163 164 165 166
  V(TailCallFunction_ReceiverIsNullOrUndefined, BUILTIN, UNINITIALIZED,        \
    kNoExtraICState)                                                           \
  V(TailCallFunction_ReceiverIsNotNullOrUndefined, BUILTIN, UNINITIALIZED,     \
    kNoExtraICState)                                                           \
  V(TailCallFunction_ReceiverIsAny, BUILTIN, UNINITIALIZED, kNoExtraICState)   \
167
  V(CallBoundFunction, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
ishell's avatar
ishell committed
168
  V(TailCallBoundFunction, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
169 170 171 172
  V(Call_ReceiverIsNullOrUndefined, BUILTIN, UNINITIALIZED, kNoExtraICState)   \
  V(Call_ReceiverIsNotNullOrUndefined, BUILTIN, UNINITIALIZED,                 \
    kNoExtraICState)                                                           \
  V(Call_ReceiverIsAny, BUILTIN, UNINITIALIZED, kNoExtraICState)               \
ishell's avatar
ishell committed
173 174 175 176 177
  V(TailCall_ReceiverIsNullOrUndefined, BUILTIN, UNINITIALIZED,                \
    kNoExtraICState)                                                           \
  V(TailCall_ReceiverIsNotNullOrUndefined, BUILTIN, UNINITIALIZED,             \
    kNoExtraICState)                                                           \
  V(TailCall_ReceiverIsAny, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
178 179
                                                                               \
  V(ConstructFunction, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
180
  V(ConstructBoundFunction, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
181 182 183 184 185 186 187 188 189 190
  V(ConstructProxy, BUILTIN, UNINITIALIZED, kNoExtraICState)                   \
  V(Construct, BUILTIN, UNINITIALIZED, kNoExtraICState)                        \
                                                                               \
  V(Apply, BUILTIN, UNINITIALIZED, kNoExtraICState)                            \
                                                                               \
  V(HandleFastApiCall, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
                                                                               \
  V(InOptimizationQueue, BUILTIN, UNINITIALIZED, kNoExtraICState)              \
  V(JSConstructStubGeneric, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
  V(JSBuiltinsConstructStub, BUILTIN, UNINITIALIZED, kNoExtraICState)          \
191 192
  V(JSBuiltinsConstructStubForDerived, BUILTIN, UNINITIALIZED,                 \
    kNoExtraICState)                                                           \
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  V(JSConstructStubApi, BUILTIN, UNINITIALIZED, kNoExtraICState)               \
  V(JSEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(CompileLazy, BUILTIN, UNINITIALIZED, kNoExtraICState)                      \
  V(CompileOptimized, BUILTIN, UNINITIALIZED, kNoExtraICState)                 \
  V(CompileOptimizedConcurrent, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(NotifyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(NotifySoftDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
  V(NotifyLazyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
  V(NotifyStubFailure, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(NotifyStubFailureSaveDoubles, BUILTIN, UNINITIALIZED, kNoExtraICState)     \
                                                                               \
  V(InterpreterEntryTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(InterpreterExitTrampoline, BUILTIN, UNINITIALIZED, kNoExtraICState)        \
  V(InterpreterPushArgsAndCall, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(InterpreterPushArgsAndConstruct, BUILTIN, UNINITIALIZED, kNoExtraICState)  \
  V(InterpreterNotifyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState)     \
  V(InterpreterNotifySoftDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
  V(InterpreterNotifyLazyDeoptimized, BUILTIN, UNINITIALIZED, kNoExtraICState) \
212
  V(InterpreterEnterBytecodeDispatch, BUILTIN, UNINITIALIZED, kNoExtraICState) \
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                                                                               \
  V(LoadIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState)                      \
  V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState)                 \
  V(StoreIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState)                     \
  V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(LoadIC_Getter_ForDeopt, LOAD_IC, MONOMORPHIC, kNoExtraICState)             \
  V(KeyedLoadIC_Megamorphic, KEYED_LOAD_IC, MEGAMORPHIC, kNoExtraICState)      \
                                                                               \
  V(KeyedLoadIC_Megamorphic_Strong, KEYED_LOAD_IC, MEGAMORPHIC,                \
    LoadICState::kStrongModeState)                                             \
                                                                               \
  V(StoreIC_Setter_ForDeopt, STORE_IC, MONOMORPHIC,                            \
    StoreICState::kStrictModeState)                                            \
                                                                               \
  V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED, kNoExtraICState)   \
  V(KeyedStoreIC_PreMonomorphic, KEYED_STORE_IC, PREMONOMORPHIC,               \
    kNoExtraICState)                                                           \
  V(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, MEGAMORPHIC, kNoExtraICState)    \
                                                                               \
  V(KeyedStoreIC_Initialize_Strict, KEYED_STORE_IC, UNINITIALIZED,             \
    StoreICState::kStrictModeState)                                            \
  V(KeyedStoreIC_PreMonomorphic_Strict, KEYED_STORE_IC, PREMONOMORPHIC,        \
    StoreICState::kStrictModeState)                                            \
  V(KeyedStoreIC_Megamorphic_Strict, KEYED_STORE_IC, MEGAMORPHIC,              \
    StoreICState::kStrictModeState)                                            \
                                                                               \
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
  V(DatePrototypeGetDate, BUILTIN, UNINITIALIZED, kNoExtraICState)             \
  V(DatePrototypeGetDay, BUILTIN, UNINITIALIZED, kNoExtraICState)              \
  V(DatePrototypeGetFullYear, BUILTIN, UNINITIALIZED, kNoExtraICState)         \
  V(DatePrototypeGetHours, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
  V(DatePrototypeGetMilliseconds, BUILTIN, UNINITIALIZED, kNoExtraICState)     \
  V(DatePrototypeGetMinutes, BUILTIN, UNINITIALIZED, kNoExtraICState)          \
  V(DatePrototypeGetMonth, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
  V(DatePrototypeGetSeconds, BUILTIN, UNINITIALIZED, kNoExtraICState)          \
  V(DatePrototypeGetTime, BUILTIN, UNINITIALIZED, kNoExtraICState)             \
  V(DatePrototypeGetTimezoneOffset, BUILTIN, UNINITIALIZED, kNoExtraICState)   \
  V(DatePrototypeGetUTCDate, BUILTIN, UNINITIALIZED, kNoExtraICState)          \
  V(DatePrototypeGetUTCDay, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
  V(DatePrototypeGetUTCFullYear, BUILTIN, UNINITIALIZED, kNoExtraICState)      \
  V(DatePrototypeGetUTCHours, BUILTIN, UNINITIALIZED, kNoExtraICState)         \
  V(DatePrototypeGetUTCMilliseconds, BUILTIN, UNINITIALIZED, kNoExtraICState)  \
  V(DatePrototypeGetUTCMinutes, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(DatePrototypeGetUTCMonth, BUILTIN, UNINITIALIZED, kNoExtraICState)         \
  V(DatePrototypeGetUTCSeconds, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
                                                                               \
258 259
  V(FunctionPrototypeApply, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
  V(FunctionPrototypeCall, BUILTIN, UNINITIALIZED, kNoExtraICState)            \
260
                                                                               \
261 262 263 264 265 266
  V(ReflectApply, BUILTIN, UNINITIALIZED, kNoExtraICState)                     \
  V(ReflectConstruct, BUILTIN, UNINITIALIZED, kNoExtraICState)                 \
                                                                               \
  V(InternalArrayCode, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(ArrayCode, BUILTIN, UNINITIALIZED, kNoExtraICState)                        \
                                                                               \
267 268 269
  V(MathMax, BUILTIN, UNINITIALIZED, kNoExtraICState)                          \
  V(MathMin, BUILTIN, UNINITIALIZED, kNoExtraICState)                          \
                                                                               \
270 271 272
  V(NumberConstructor, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(NumberConstructor_ConstructStub, BUILTIN, UNINITIALIZED, kNoExtraICState)  \
                                                                               \
273 274 275 276 277 278 279 280 281 282 283
  V(StringConstructor, BUILTIN, UNINITIALIZED, kNoExtraICState)                \
  V(StringConstructor_ConstructStub, BUILTIN, UNINITIALIZED, kNoExtraICState)  \
                                                                               \
  V(OnStackReplacement, BUILTIN, UNINITIALIZED, kNoExtraICState)               \
  V(InterruptCheck, BUILTIN, UNINITIALIZED, kNoExtraICState)                   \
  V(OsrAfterStackCheck, BUILTIN, UNINITIALIZED, kNoExtraICState)               \
  V(StackCheck, BUILTIN, UNINITIALIZED, kNoExtraICState)                       \
                                                                               \
  V(MarkCodeAsToBeExecutedOnce, BUILTIN, UNINITIALIZED, kNoExtraICState)       \
  V(MarkCodeAsExecutedOnce, BUILTIN, UNINITIALIZED, kNoExtraICState)           \
  V(MarkCodeAsExecutedTwice, BUILTIN, UNINITIALIZED, kNoExtraICState)          \
284
  CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, V)
285

286
// Define list of builtin handlers implemented in assembly.
287 288 289 290 291 292 293 294 295 296
#define BUILTIN_LIST_H(V)                    \
  V(LoadIC_Slow,             LOAD_IC)        \
  V(LoadIC_Slow_Strong,      LOAD_IC)        \
  V(KeyedLoadIC_Slow,        KEYED_LOAD_IC)  \
  V(KeyedLoadIC_Slow_Strong, KEYED_LOAD_IC)  \
  V(StoreIC_Slow,            STORE_IC)       \
  V(KeyedStoreIC_Slow,       KEYED_STORE_IC) \
  V(LoadIC_Normal,           LOAD_IC)        \
  V(LoadIC_Normal_Strong,    LOAD_IC)        \
  V(StoreIC_Normal,          STORE_IC)
297

298
// Define list of builtins used by the debugger implemented in assembly.
299 300 301 302
#define BUILTIN_LIST_DEBUG_A(V)                                 \
  V(Return_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState)    \
  V(Slot_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState)      \
  V(FrameDropper_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState)
303

304

305
class BuiltinFunctionTable;
306 307 308
class ObjectVisitor;


309
class Builtins {
310
 public:
311 312
  ~Builtins();

313
  // Generate all builtin code objects. Should be called once during
314
  // isolate initialization.
315
  void SetUp(Isolate* isolate, bool create_heap_objects);
316
  void TearDown();
317 318

  // Garbage collection support.
319
  void IterateBuiltins(ObjectVisitor* v);
320 321

  // Disassembler support.
322
  const char* Lookup(byte* pc);
323 324

  enum Name {
325 326
#define DEF_ENUM_C(name, ignore) k##name,
#define DEF_ENUM_A(name, kind, state, extra) k##name,
327
#define DEF_ENUM_H(name, kind) k##name,
328 329
    BUILTIN_LIST_C(DEF_ENUM_C)
    BUILTIN_LIST_A(DEF_ENUM_A)
330
    BUILTIN_LIST_H(DEF_ENUM_H)
331
    BUILTIN_LIST_DEBUG_A(DEF_ENUM_A)
332 333 334 335 336 337
#undef DEF_ENUM_C
#undef DEF_ENUM_A
    builtin_count
  };

  enum CFunctionId {
338
#define DEF_ENUM_C(name, ignore) c_##name,
339 340 341 342 343
    BUILTIN_LIST_C(DEF_ENUM_C)
#undef DEF_ENUM_C
    cfunction_count
  };

344 345 346
#define DECLARE_BUILTIN_ACCESSOR_C(name, ignore) Handle<Code> name();
#define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \
  Handle<Code> name();
347
#define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name();
348 349
  BUILTIN_LIST_C(DECLARE_BUILTIN_ACCESSOR_C)
  BUILTIN_LIST_A(DECLARE_BUILTIN_ACCESSOR_A)
350
  BUILTIN_LIST_H(DECLARE_BUILTIN_ACCESSOR_H)
351 352 353 354
  BUILTIN_LIST_DEBUG_A(DECLARE_BUILTIN_ACCESSOR_A)
#undef DECLARE_BUILTIN_ACCESSOR_C
#undef DECLARE_BUILTIN_ACCESSOR_A

355
  // Convenience wrappers.
ishell's avatar
ishell committed
356 357 358 359 360 361
  Handle<Code> CallFunction(
      ConvertReceiverMode = ConvertReceiverMode::kAny,
      TailCallMode tail_call_mode = TailCallMode::kDisallow);
  Handle<Code> Call(ConvertReceiverMode = ConvertReceiverMode::kAny,
                    TailCallMode tail_call_mode = TailCallMode::kDisallow);
  Handle<Code> CallBoundFunction(TailCallMode tail_call_mode);
362

363
  Code* builtin(Name name) {
364 365 366 367 368
    // Code::cast cannot be used here since we access builtins
    // during the marking phase of mark sweep. See IC::Clear.
    return reinterpret_cast<Code*>(builtins_[name]);
  }

369
  Address builtin_address(Name name) {
370 371 372 373 374 375 376
    return reinterpret_cast<Address>(&builtins_[name]);
  }

  static Address c_function_address(CFunctionId id) {
    return c_functions_[id];
  }

377
  const char* name(int index) {
378 379
    DCHECK(index >= 0);
    DCHECK(index < builtin_count);
380 381
    return names_[index];
  }
382

383 384
  bool is_initialized() const { return initialized_; }

385 386 387 388
  MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction(
      Handle<JSFunction> function, Handle<Object> receiver, int argc,
      Handle<Object> args[]);

389
 private:
390 391
  Builtins();

392
  // The external C++ functions called from the code.
393
  static Address const c_functions_[cfunction_count];
394 395 396 397

  // Note: These are always Code objects, but to conform with
  // IterateBuiltins() above which assumes Object**'s for the callback
  // function f, we use an Object* array here.
398 399
  Object* builtins_[builtin_count];
  const char* names_[builtin_count];
400

401 402 403
  static void Generate_Adaptor(MacroAssembler* masm,
                               CFunctionId id,
                               BuiltinExtraArguments extra_args);
404
  static void Generate_ConstructedNonConstructable(MacroAssembler* masm);
405
  static void Generate_CompileLazy(MacroAssembler* masm);
406 407 408
  static void Generate_InOptimizationQueue(MacroAssembler* masm);
  static void Generate_CompileOptimized(MacroAssembler* masm);
  static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm);
409
  static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
410
  static void Generate_JSBuiltinsConstructStub(MacroAssembler* masm);
411
  static void Generate_JSBuiltinsConstructStubForDerived(MacroAssembler* masm);
412
  static void Generate_JSConstructStubApi(MacroAssembler* masm);
413 414
  static void Generate_JSEntryTrampoline(MacroAssembler* masm);
  static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
415
  static void Generate_NotifyDeoptimized(MacroAssembler* masm);
416
  static void Generate_NotifySoftDeoptimized(MacroAssembler* masm);
417
  static void Generate_NotifyLazyDeoptimized(MacroAssembler* masm);
418
  static void Generate_NotifyStubFailure(MacroAssembler* masm);
419
  static void Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm);
420
  static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
421

422 423
  static void Generate_Apply(MacroAssembler* masm);

424
  // ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
425
  static void Generate_CallFunction(MacroAssembler* masm,
ishell's avatar
ishell committed
426 427
                                    ConvertReceiverMode mode,
                                    TailCallMode tail_call_mode);
428 429
  static void Generate_CallFunction_ReceiverIsNullOrUndefined(
      MacroAssembler* masm) {
ishell's avatar
ishell committed
430 431
    Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
                          TailCallMode::kDisallow);
432 433 434
  }
  static void Generate_CallFunction_ReceiverIsNotNullOrUndefined(
      MacroAssembler* masm) {
ishell's avatar
ishell committed
435 436
    Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
                          TailCallMode::kDisallow);
437 438
  }
  static void Generate_CallFunction_ReceiverIsAny(MacroAssembler* masm) {
ishell's avatar
ishell committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
    Generate_CallFunction(masm, ConvertReceiverMode::kAny,
                          TailCallMode::kDisallow);
  }
  static void Generate_TailCallFunction_ReceiverIsNullOrUndefined(
      MacroAssembler* masm) {
    Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
                          TailCallMode::kAllow);
  }
  static void Generate_TailCallFunction_ReceiverIsNotNullOrUndefined(
      MacroAssembler* masm) {
    Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
                          TailCallMode::kAllow);
  }
  static void Generate_TailCallFunction_ReceiverIsAny(MacroAssembler* masm) {
    Generate_CallFunction(masm, ConvertReceiverMode::kAny,
                          TailCallMode::kAllow);
455
  }
456
  // ES6 section 9.4.1.1 [[Call]] ( thisArgument, argumentsList)
ishell's avatar
ishell committed
457 458 459 460 461 462 463 464
  static void Generate_CallBoundFunctionImpl(MacroAssembler* masm,
                                             TailCallMode tail_call_mode);
  static void Generate_CallBoundFunction(MacroAssembler* masm) {
    Generate_CallBoundFunctionImpl(masm, TailCallMode::kDisallow);
  }
  static void Generate_TailCallBoundFunction(MacroAssembler* masm) {
    Generate_CallBoundFunctionImpl(masm, TailCallMode::kAllow);
  }
465
  // ES6 section 7.3.12 Call(F, V, [argumentsList])
ishell's avatar
ishell committed
466 467
  static void Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
                            TailCallMode tail_call_mode);
468
  static void Generate_Call_ReceiverIsNullOrUndefined(MacroAssembler* masm) {
ishell's avatar
ishell committed
469 470
    Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
                  TailCallMode::kDisallow);
471 472
  }
  static void Generate_Call_ReceiverIsNotNullOrUndefined(MacroAssembler* masm) {
ishell's avatar
ishell committed
473 474
    Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
                  TailCallMode::kDisallow);
475 476
  }
  static void Generate_Call_ReceiverIsAny(MacroAssembler* masm) {
ishell's avatar
ishell committed
477 478 479 480 481 482 483 484 485 486 487 488 489 490
    Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kDisallow);
  }
  static void Generate_TailCall_ReceiverIsNullOrUndefined(
      MacroAssembler* masm) {
    Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
                  TailCallMode::kAllow);
  }
  static void Generate_TailCall_ReceiverIsNotNullOrUndefined(
      MacroAssembler* masm) {
    Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
                  TailCallMode::kAllow);
  }
  static void Generate_TailCall_ReceiverIsAny(MacroAssembler* masm) {
    Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow);
491
  }
492

493 494
  // ES6 section 9.2.2 [[Construct]] ( argumentsList, newTarget)
  static void Generate_ConstructFunction(MacroAssembler* masm);
495 496
  // ES6 section 9.4.1.2 [[Construct]] (argumentsList, newTarget)
  static void Generate_ConstructBoundFunction(MacroAssembler* masm);
497 498
  // ES6 section 9.5.14 [[Construct]] ( argumentsList, newTarget)
  static void Generate_ConstructProxy(MacroAssembler* masm);
499 500 501
  // ES6 section 7.3.13 Construct (F, [argumentsList], [newTarget])
  static void Generate_Construct(MacroAssembler* masm);

502 503
  static void Generate_HandleFastApiCall(MacroAssembler* masm);

504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
  static void Generate_DatePrototype_GetField(MacroAssembler* masm,
                                              int field_index);
  // ES6 section 20.3.4.2 Date.prototype.getDate ( )
  static void Generate_DatePrototypeGetDate(MacroAssembler* masm);
  // ES6 section 20.3.4.3 Date.prototype.getDay ( )
  static void Generate_DatePrototypeGetDay(MacroAssembler* masm);
  // ES6 section 20.3.4.4 Date.prototype.getFullYear ( )
  static void Generate_DatePrototypeGetFullYear(MacroAssembler* masm);
  // ES6 section 20.3.4.5 Date.prototype.getHours ( )
  static void Generate_DatePrototypeGetHours(MacroAssembler* masm);
  // ES6 section 20.3.4.6 Date.prototype.getMilliseconds ( )
  static void Generate_DatePrototypeGetMilliseconds(MacroAssembler* masm);
  // ES6 section 20.3.4.7 Date.prototype.getMinutes ( )
  static void Generate_DatePrototypeGetMinutes(MacroAssembler* masm);
  // ES6 section 20.3.4.8 Date.prototype.getMonth ( )
  static void Generate_DatePrototypeGetMonth(MacroAssembler* masm);
  // ES6 section 20.3.4.9 Date.prototype.getSeconds ( )
  static void Generate_DatePrototypeGetSeconds(MacroAssembler* masm);
  // ES6 section 20.3.4.10 Date.prototype.getTime ( )
  static void Generate_DatePrototypeGetTime(MacroAssembler* masm);
  // ES6 section 20.3.4.11 Date.prototype.getTimezoneOffset ( )
  static void Generate_DatePrototypeGetTimezoneOffset(MacroAssembler* masm);
  // ES6 section 20.3.4.12 Date.prototype.getUTCDate ( )
  static void Generate_DatePrototypeGetUTCDate(MacroAssembler* masm);
  // ES6 section 20.3.4.13 Date.prototype.getUTCDay ( )
  static void Generate_DatePrototypeGetUTCDay(MacroAssembler* masm);
  // ES6 section 20.3.4.14 Date.prototype.getUTCFullYear ( )
  static void Generate_DatePrototypeGetUTCFullYear(MacroAssembler* masm);
  // ES6 section 20.3.4.15 Date.prototype.getUTCHours ( )
  static void Generate_DatePrototypeGetUTCHours(MacroAssembler* masm);
  // ES6 section 20.3.4.16 Date.prototype.getUTCMilliseconds ( )
  static void Generate_DatePrototypeGetUTCMilliseconds(MacroAssembler* masm);
  // ES6 section 20.3.4.17 Date.prototype.getUTCMinutes ( )
  static void Generate_DatePrototypeGetUTCMinutes(MacroAssembler* masm);
  // ES6 section 20.3.4.18 Date.prototype.getUTCMonth ( )
  static void Generate_DatePrototypeGetUTCMonth(MacroAssembler* masm);
  // ES6 section 20.3.4.19 Date.prototype.getUTCSeconds ( )
  static void Generate_DatePrototypeGetUTCSeconds(MacroAssembler* masm);

543 544
  static void Generate_FunctionPrototypeApply(MacroAssembler* masm);
  static void Generate_FunctionPrototypeCall(MacroAssembler* masm);
545

546 547
  static void Generate_ReflectApply(MacroAssembler* masm);
  static void Generate_ReflectConstruct(MacroAssembler* masm);
548

549
  static void Generate_InternalArrayCode(MacroAssembler* masm);
550
  static void Generate_ArrayCode(MacroAssembler* masm);
551

552 553 554 555 556 557 558 559 560 561 562
  enum class MathMaxMinKind { kMax, kMin };
  static void Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind);
  // ES6 section 20.2.2.24 Math.max ( value1, value2 , ...values )
  static void Generate_MathMax(MacroAssembler* masm) {
    Generate_MathMaxMin(masm, MathMaxMinKind::kMax);
  }
  // ES6 section 20.2.2.25 Math.min ( value1, value2 , ...values )
  static void Generate_MathMin(MacroAssembler* masm) {
    Generate_MathMaxMin(masm, MathMaxMinKind::kMin);
  }

563 564 565 566 567
  // ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Call]] case.
  static void Generate_NumberConstructor(MacroAssembler* masm);
  // ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Construct]] case.
  static void Generate_NumberConstructor_ConstructStub(MacroAssembler* masm);

568 569
  static void Generate_StringConstructor(MacroAssembler* masm);
  static void Generate_StringConstructor_ConstructStub(MacroAssembler* masm);
570
  static void Generate_OnStackReplacement(MacroAssembler* masm);
571
  static void Generate_OsrAfterStackCheck(MacroAssembler* masm);
572 573 574
  static void Generate_InterruptCheck(MacroAssembler* masm);
  static void Generate_StackCheck(MacroAssembler* masm);

575 576 577
  static void Generate_InterpreterEntryTrampoline(MacroAssembler* masm);
  static void Generate_InterpreterExitTrampoline(MacroAssembler* masm);
  static void Generate_InterpreterPushArgsAndCall(MacroAssembler* masm);
578
  static void Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm);
579 580 581
  static void Generate_InterpreterNotifyDeoptimized(MacroAssembler* masm);
  static void Generate_InterpreterNotifySoftDeoptimized(MacroAssembler* masm);
  static void Generate_InterpreterNotifyLazyDeoptimized(MacroAssembler* masm);
582
  static void Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm);
583

584 585 586 587 588 589 590 591
#define DECLARE_CODE_AGE_BUILTIN_GENERATOR(C)                \
  static void Generate_Make##C##CodeYoungAgainEvenMarking(   \
      MacroAssembler* masm);                                 \
  static void Generate_Make##C##CodeYoungAgainOddMarking(    \
      MacroAssembler* masm);
  CODE_AGE_LIST(DECLARE_CODE_AGE_BUILTIN_GENERATOR)
#undef DECLARE_CODE_AGE_BUILTIN_GENERATOR

592
  static void Generate_MarkCodeAsToBeExecutedOnce(MacroAssembler* masm);
593 594 595
  static void Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm);
  static void Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm);

596 597 598 599 600 601 602 603
  static void InitBuiltinFunctionTable();

  bool initialized_;

  friend class BuiltinFunctionTable;
  friend class Isolate;

  DISALLOW_COPY_AND_ASSIGN(Builtins);
604 605
};

606 607
}  // namespace internal
}  // namespace v8
608 609

#endif  // V8_BUILTINS_H_