code-stubs.h 21.7 KB
Newer Older
1
// Copyright 2012 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_CODE_STUBS_H_
#define V8_CODE_STUBS_H_

8
#include "src/interface-descriptors.h"
9
#include "src/type-hints.h"
10

11 12
namespace v8 {
namespace internal {
13

14
// Forward declarations.
15
class Isolate;
16 17 18
namespace compiler {
class CodeAssemblerState;
}
19

20
// List of code stubs used on all platforms.
21 22 23 24 25 26 27
#define CODE_STUB_LIST_ALL_PLATFORMS(V)     \
  /* --- PlatformCodeStubs --- */           \
  V(CallApiCallback)                        \
  V(CallApiGetter)                          \
  V(JSEntry)                                \
  V(ProfileEntryHook)                       \
  /* --- TurboFanCodeStubs --- */           \
28 29
  V(StoreSlowElement)                       \
  V(StoreInArrayLiteralSlow)                \
30 31 32 33 34 35
  V(ElementsTransitionAndStore)             \
  V(KeyedLoadSloppyArguments)               \
  V(KeyedStoreSloppyArguments)              \
  V(StoreFastElement)                       \
  V(StoreInterceptor)                       \
  V(LoadIndexedInterceptor)
36

37 38
// List of code stubs only used on ARM 32 bits platforms.
#if V8_TARGET_ARCH_ARM
39
#define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
40

41 42 43 44
#else
#define CODE_STUB_LIST_ARM(V)
#endif

45 46
// List of code stubs only used on ARM 64 bits platforms.
#if V8_TARGET_ARCH_ARM64
47
#define CODE_STUB_LIST_ARM64(V) V(DirectCEntry)
48

49 50 51 52
#else
#define CODE_STUB_LIST_ARM64(V)
#endif

53 54
// List of code stubs only used on PPC platforms.
#ifdef V8_TARGET_ARCH_PPC
55
#define CODE_STUB_LIST_PPC(V) V(DirectCEntry)
56 57 58 59
#else
#define CODE_STUB_LIST_PPC(V)
#endif

60
// List of code stubs only used on MIPS platforms.
61
#if V8_TARGET_ARCH_MIPS
62
#define CODE_STUB_LIST_MIPS(V) V(DirectCEntry)
63
#elif V8_TARGET_ARCH_MIPS64
64
#define CODE_STUB_LIST_MIPS(V) V(DirectCEntry)
65 66 67 68
#else
#define CODE_STUB_LIST_MIPS(V)
#endif

69 70
// List of code stubs only used on S390 platforms.
#ifdef V8_TARGET_ARCH_S390
71
#define CODE_STUB_LIST_S390(V) V(DirectCEntry)
72 73 74 75
#else
#define CODE_STUB_LIST_S390(V)
#endif

76
// Combined list of code stubs.
77 78 79 80 81
#define CODE_STUB_LIST(V)         \
  CODE_STUB_LIST_ALL_PLATFORMS(V) \
  CODE_STUB_LIST_ARM(V)           \
  CODE_STUB_LIST_ARM64(V)         \
  CODE_STUB_LIST_PPC(V)           \
82 83
  CODE_STUB_LIST_MIPS(V)          \
  CODE_STUB_LIST_S390(V)
84

85 86
static const int kHasReturnedMinusZeroSentinel = 1;

87
class CodeStub : public ZoneObject {
88 89
 public:
  enum Major {
90 91 92
    // TODO(mvstanton): eliminate the NoCache key by getting rid
    //                  of the non-monomorphic-cache.
    NoCache = 0,  // marker for stubs that do custom caching]
93 94 95
#define DEF_ENUM(name) name,
    CODE_STUB_LIST(DEF_ENUM)
#undef DEF_ENUM
96 97 98 99
    NUMBER_OF_IDS
  };

  // Retrieve the code for the stub. Generate the code if needed.
100
  Handle<Code> GetCode();
101 102 103

  static Major MajorKeyFromKey(uint32_t key) {
    return static_cast<Major>(MajorKeyBits::decode(key));
104
  }
105
  static uint32_t MinorKeyFromKey(uint32_t key) {
106
    return MinorKeyBits::decode(key);
107
  }
108 109

  // Gets the major key from a code object that is a code stub or binary op IC.
110
  static Major GetMajorKey(const Code* code_stub);
111

112 113
  static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }

114
  static const char* MajorName(Major major_key);
115

116
  explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
117 118
  virtual ~CodeStub() {}

119
  static void GenerateStubsAheadOfTime(Isolate* isolate);
120

121 122 123 124 125 126 127 128
  // Some stubs put untagged junk on the stack that cannot be scanned by the
  // GC.  This means that we must be statically sure that no GC can occur while
  // they are running.  If that is the case they should override this to return
  // true, which will cause an assertion if we try to call something that can
  // GC or if we try to put a stack frame on top of the junk, which would not
  // result in a traversable stack.
  virtual bool SometimesSetsUpAFrame() { return true; }

129
  // Lookup the code in the (possibly custom) cache.
130
  bool FindCodeInCache(Code** code_out);
131

132
  virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
133

134 135 136
  virtual int GetStackParameterCount() const {
    return GetCallInterfaceDescriptor().GetStackParameterCount();
  }
137

138 139
  static void InitializeDescriptor(Isolate* isolate, uint32_t key,
                                   CodeStubDescriptor* desc);
140

141 142
  static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);

143
  // Returns information for computing the number key.
144
  virtual Major MajorKey() const = 0;
145
  uint32_t MinorKey() const { return minor_key_; }
146

147
  friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
148 149 150
    s.PrintName(os);
    return os;
  }
151

152
  Isolate* isolate() const { return isolate_; }
153 154 155 156 157
  void set_isolate(Isolate* isolate) {
    DCHECK_NOT_NULL(isolate);
    DCHECK(isolate_ == nullptr || isolate_ == isolate);
    isolate_ = isolate;
  }
158

159 160
  void DeleteStubFromCacheForTesting();

161
 protected:
162 163
  CodeStub(uint32_t key, Isolate* isolate)
      : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
164

165
  // Generates the assembler code for the stub.
166
  virtual Handle<Code> GenerateCode() = 0;
167

168 169
  // Returns whether the code generated for this stub needs to be allocated as
  // a fixed (non-moveable) code object.
170 171
  // TODO(jgruber): Only required by DirectCEntryStub. Can be removed when/if
  // that is ported to a builtin.
172
  virtual Movability NeedsImmovableCode() { return kMovable; }
173

174 175 176
  virtual void PrintName(std::ostream& os) const;        // NOLINT
  virtual void PrintBaseName(std::ostream& os) const;    // NOLINT
  virtual void PrintState(std::ostream& os) const { ; }  // NOLINT
177

178 179
  // Computes the key based on major and minor.
  uint32_t GetKey() {
180
    DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
181 182 183
    return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
  }

184 185
  uint32_t minor_key_;

186
 private:
187 188
  // Perform bookkeeping required after code generation when stub code is
  // initially generated.
189
  void RecordCodeGeneration(Handle<Code> code);
190

191 192 193 194
  // Activate newly generated stub. Is called after
  // registering stub in the stub cache.
  virtual void Activate(Code* code) { }

195 196 197 198 199 200
  // We use this dispatch to statically instantiate the correct code stub for
  // the given stub key and call the passed function with that code stub.
  typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
  static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
                       DispatchedCall call);

201 202
  static void GetCodeDispatchCall(CodeStub* stub, void** value_out);

203
  STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
204 205 206
  class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
  class MinorKeyBits: public BitField<uint32_t,
      kStubMajorKeyBits, kStubMinorKeyBits> {};  // NOLINT
207 208

  friend class BreakPointIterator;
209 210

  Isolate* isolate_;
211 212
};

213

214 215 216 217 218 219 220 221
#define DEFINE_CODE_STUB_BASE(NAME, SUPER)                      \
 public:                                                        \
  NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
                                                                \
 private:                                                       \
  DISALLOW_COPY_AND_ASSIGN(NAME)


222
#define DEFINE_CODE_STUB(NAME, SUPER)                      \
223
 public:                                                   \
224
  inline Major MajorKey() const override { return NAME; }; \
225
                                                           \
226 227 228
  DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)


229 230
#define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER)  \
 private:                                       \
231
  void Generate(MacroAssembler* masm) override; \
232 233 234
  DEFINE_CODE_STUB(NAME, SUPER)


235 236 237
#define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER)                               \
 public:                                                                     \
  void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \
238 239
  DEFINE_CODE_STUB(NAME, SUPER)

240 241
#define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME)                          \
 public:                                                                \
242
  typedef NAME##Descriptor Descriptor;                                  \
243
  CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
244
    return Descriptor();                                                \
245 246
  }

247 248 249
// There are some code stubs we just can't describe right now with a
// CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
// An attempt to retrieve a descriptor will fail.
250 251 252 253 254
#define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR()                         \
 public:                                                                \
  CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
    UNREACHABLE();                                                      \
    return CallInterfaceDescriptor();                                   \
255 256
  }

257

258 259 260
class PlatformCodeStub : public CodeStub {
 public:
  // Retrieve the code for the stub. Generate the code if needed.
261
  Handle<Code> GenerateCode() override;
262 263

 protected:
264 265
  explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}

266 267
  // Generates the assembler code for the stub.
  virtual void Generate(MacroAssembler* masm) = 0;
268

269
  // Generates the exception handler table for the stub.
270
  virtual int GenerateHandlerTable(MacroAssembler* masm);
271

272
  DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
273 274 275
};


276
enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
277

278

279
class CodeStubDescriptor {
280
 public:
281
  explicit CodeStubDescriptor(CodeStub* stub);
282

283
  CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
284

285
  void Initialize(Address deoptimization_handler = kNullAddress,
286 287
                  int hint_stack_parameter_count = -1,
                  StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
288
  void Initialize(Register stack_parameter_count,
289
                  Address deoptimization_handler = kNullAddress,
290
                  int hint_stack_parameter_count = -1,
291
                  StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
292

293 294
  void SetMissHandler(Runtime::FunctionId id) {
    miss_handler_id_ = id;
295
    miss_handler_ = ExternalReference::Create(Runtime::FunctionForId(id));
296
    has_miss_handler_ = true;
297 298
    // Our miss handler infrastructure doesn't currently support
    // variable stack parameter counts.
299
    DCHECK(!stack_parameter_count_.is_valid());
300 301
  }

302
  void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
303
  CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
304

305 306
  int GetRegisterParameterCount() const {
    return call_descriptor().GetRegisterParameterCount();
307 308
  }

309 310 311 312 313 314 315 316
  int GetStackParameterCount() const {
    return call_descriptor().GetStackParameterCount();
  }

  int GetParameterCount() const {
    return call_descriptor().GetParameterCount();
  }

317 318 319 320
  Register GetRegisterParameter(int index) const {
    return call_descriptor().GetRegisterParameter(index);
  }

321
  MachineType GetParameterType(int index) const {
322
    return call_descriptor().GetParameterType(index);
323 324
  }

325
  ExternalReference miss_handler() const {
326
    DCHECK(has_miss_handler_);
327 328 329
    return miss_handler_;
  }

330 331 332 333 334
  Runtime::FunctionId miss_handler_id() const {
    DCHECK(has_miss_handler_);
    return miss_handler_id_;
  }

335
  bool has_miss_handler() const {
336 337 338
    return has_miss_handler_;
  }

339
  int GetHandlerParameterCount() const {
340 341
    int params = GetParameterCount();
    if (PassesArgumentsToDeoptimizationHandler()) {
342 343 344 345 346
      params += 1;
    }
    return params;
  }

347 348 349 350 351
  int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
  Register stack_parameter_count() const { return stack_parameter_count_; }
  StubFunctionMode function_mode() const { return function_mode_; }
  Address deoptimization_handler() const { return deoptimization_handler_; }

352
 private:
353 354 355 356
  bool PassesArgumentsToDeoptimizationHandler() const {
    return stack_parameter_count_.is_valid();
  }

357
  Isolate* isolate_;
358
  CallInterfaceDescriptor call_descriptor_;
359 360 361 362 363 364 365 366
  Register stack_parameter_count_;
  // If hint_stack_parameter_count_ > 0, the code stub can optimize the
  // return sequence. Default value is -1, which means it is ignored.
  int hint_stack_parameter_count_;
  StubFunctionMode function_mode_;

  Address deoptimization_handler_;

367
  ExternalReference miss_handler_;
368
  Runtime::FunctionId miss_handler_id_;
369
  bool has_miss_handler_;
370 371 372
};


373 374 375 376 377
class TurboFanCodeStub : public CodeStub {
 public:
  // Retrieve the code for the stub. Generate the code if needed.
  Handle<Code> GenerateCode() override;

378
  int GetStackParameterCount() const override {
379 380 381
    return GetCallInterfaceDescriptor().GetStackParameterCount();
  }

382 383 384
 protected:
  explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}

385
  virtual void GenerateAssembly(compiler::CodeAssemblerState* state) const = 0;
386 387

 private:
388
  DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
389 390
};

391 392
}  // namespace internal
}  // namespace v8
393 394 395

#if V8_TARGET_ARCH_IA32
#elif V8_TARGET_ARCH_X64
396
#elif V8_TARGET_ARCH_ARM64
397
#include "src/arm64/code-stubs-arm64.h"
398
#elif V8_TARGET_ARCH_ARM
399
#include "src/arm/code-stubs-arm.h"
400 401
#elif V8_TARGET_ARCH_PPC
#include "src/ppc/code-stubs-ppc.h"
402
#elif V8_TARGET_ARCH_MIPS
403
#include "src/mips/code-stubs-mips.h"
404 405
#elif V8_TARGET_ARCH_MIPS64
#include "src/mips64/code-stubs-mips64.h"
406 407
#elif V8_TARGET_ARCH_S390
#include "src/s390/code-stubs-s390.h"
408 409 410 411 412 413 414
#else
#error Unsupported target architecture.
#endif

namespace v8 {
namespace internal {

415
// TODO(jgruber): Convert this stub into a builtin.
416 417 418 419
class StoreInterceptorStub : public TurboFanCodeStub {
 public:
  explicit StoreInterceptorStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}

420
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
421
  DEFINE_TURBOFAN_CODE_STUB(StoreInterceptor, TurboFanCodeStub);
422 423
};

424
// TODO(jgruber): Convert this stub into a builtin.
425 426 427 428 429 430 431 432 433
class LoadIndexedInterceptorStub : public TurboFanCodeStub {
 public:
  explicit LoadIndexedInterceptorStub(Isolate* isolate)
      : TurboFanCodeStub(isolate) {}

  DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
  DEFINE_TURBOFAN_CODE_STUB(LoadIndexedInterceptor, TurboFanCodeStub);
};

434
// TODO(jgruber): Convert this stub into a builtin.
435
class KeyedLoadSloppyArgumentsStub : public TurboFanCodeStub {
436 437
 public:
  explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
438
      : TurboFanCodeStub(isolate) {}
439

440
 protected:
441
  DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
442
  DEFINE_TURBOFAN_CODE_STUB(KeyedLoadSloppyArguments, TurboFanCodeStub);
443 444 445
};


446 447
class CommonStoreModeBits : public BitField<KeyedAccessStoreMode, 0, 3> {};

448
class KeyedStoreSloppyArgumentsStub : public TurboFanCodeStub {
449
 public:
450 451
  explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate,
                                         KeyedAccessStoreMode mode)
452 453
      : TurboFanCodeStub(isolate) {
    minor_key_ = CommonStoreModeBits::encode(mode);
454
  }
455

456
 protected:
457
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
458
  DEFINE_TURBOFAN_CODE_STUB(KeyedStoreSloppyArguments, TurboFanCodeStub);
459 460
};

vogelheim's avatar
vogelheim committed
461
class CallApiCallbackStub : public PlatformCodeStub {
462
 public:
463
  static const int kArgBits = 7;
vogelheim's avatar
vogelheim committed
464
  static const int kArgMax = (1 << kArgBits) - 1;
465

466
  CallApiCallbackStub(Isolate* isolate, int argc)
467
      : PlatformCodeStub(isolate) {
468
    CHECK_LE(0, argc);  // The argc in {0, 1} cases are covered by builtins.
469 470
    CHECK_LE(argc, kArgMax);
    minor_key_ = ArgumentBits::encode(argc);
471 472
  }

473
 private:
474
  int argc() const { return ArgumentBits::decode(minor_key_); }
475

476
  class ArgumentBits : public BitField<int, 0, kArgBits> {};
477

478 479
  friend class Builtins;  // For generating the related builtin.

480
  DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiCallback);
vogelheim's avatar
vogelheim committed
481
  DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub);
482 483
};

484 485 486
// TODO(jgruber): This stub only exists to avoid code duplication between
// code-stubs-<arch>.cc and builtins-<arch>.cc. If CallApiCallbackStub is ever
// completely removed, CallApiGetterStub can also be deleted.
dcarney@chromium.org's avatar
dcarney@chromium.org committed
487
class CallApiGetterStub : public PlatformCodeStub {
488 489
 private:
  // For generating the related builtin.
490
  explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
491
  friend class Builtins;
dcarney@chromium.org's avatar
dcarney@chromium.org committed
492

493
  DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
494
  DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
dcarney@chromium.org's avatar
dcarney@chromium.org committed
495
};
496

497
class JSEntryStub : public PlatformCodeStub {
498
 public:
499
  enum class SpecialTarget { kNone, kRunMicrotasks };
500 501
  JSEntryStub(Isolate* isolate, StackFrame::Type type)
      : PlatformCodeStub(isolate) {
502
    DCHECK(type == StackFrame::ENTRY || type == StackFrame::CONSTRUCT_ENTRY);
503 504 505 506 507 508 509 510
    minor_key_ = StackFrameTypeBits::encode(type) |
                 SpecialTargetBits::encode(SpecialTarget::kNone);
  }

  JSEntryStub(Isolate* isolate, SpecialTarget target)
      : PlatformCodeStub(isolate) {
    minor_key_ = StackFrameTypeBits::encode(StackFrame::ENTRY) |
                 SpecialTargetBits::encode(target);
511
  }
512 513

 private:
514
  int GenerateHandlerTable(MacroAssembler* masm) override;
515

516
  void PrintName(std::ostream& os) const override {  // NOLINT
517 518 519
    os << (type() == StackFrame::ENTRY ? "JSEntryStub"
                                       : "JSConstructEntryStub");
  }
520

521 522 523
  StackFrame::Type type() const {
    return StackFrameTypeBits::decode(minor_key_);
  }
524

525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
  SpecialTarget special_target() const {
    return SpecialTargetBits::decode(minor_key_);
  }

  Handle<Code> EntryTrampoline() {
    switch (special_target()) {
      case SpecialTarget::kNone:
        return (type() == StackFrame::CONSTRUCT_ENTRY)
                   ? BUILTIN_CODE(isolate(), JSConstructEntryTrampoline)
                   : BUILTIN_CODE(isolate(), JSEntryTrampoline);
      case SpecialTarget::kRunMicrotasks:
        return BUILTIN_CODE(isolate(), RunMicrotasks);
    }
    UNREACHABLE();
    return Handle<Code>();
  }

542
  class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
543 544
  class SpecialTargetBits
      : public BitField<SpecialTarget, StackFrameTypeBits::kNext, 1> {};
545

546
  int handler_offset_;
547

548
  DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
549
  DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
550 551
};

552
class StoreFastElementStub : public TurboFanCodeStub {
553
 public:
554 555
  StoreFastElementStub(Isolate* isolate, bool is_js_array,
                       ElementsKind elements_kind, KeyedAccessStoreMode mode)
556 557 558 559
      : TurboFanCodeStub(isolate) {
    minor_key_ = CommonStoreModeBits::encode(mode) |
                 ElementsKindBits::encode(elements_kind) |
                 IsJSArrayBits::encode(is_js_array);
560 561
  }

562 563
  static void GenerateAheadOfTime(Isolate* isolate);

564
  bool is_js_array() const { return IsJSArrayBits::decode(minor_key_); }
565 566

  ElementsKind elements_kind() const {
567
    return ElementsKindBits::decode(minor_key_);
568 569 570
  }

  KeyedAccessStoreMode store_mode() const {
571
    return CommonStoreModeBits::decode(minor_key_);
572 573 574
  }

 private:
575 576 577
  class ElementsKindBits
      : public BitField<ElementsKind, CommonStoreModeBits::kNext, 8> {};
  class IsJSArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
578

579
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
580
  DEFINE_TURBOFAN_CODE_STUB(StoreFastElement, TurboFanCodeStub);
581 582
};

583
class StoreSlowElementStub : public TurboFanCodeStub {
danno@chromium.org's avatar
danno@chromium.org committed
584
 public:
585 586 587
  StoreSlowElementStub(Isolate* isolate, KeyedAccessStoreMode mode)
      : TurboFanCodeStub(isolate) {
    minor_key_ = CommonStoreModeBits::encode(mode);
588
  }
danno@chromium.org's avatar
danno@chromium.org committed
589

590
 private:
591
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
592
  DEFINE_TURBOFAN_CODE_STUB(StoreSlowElement, TurboFanCodeStub);
danno@chromium.org's avatar
danno@chromium.org committed
593 594
};

595 596 597 598 599 600 601 602 603 604 605 606
class StoreInArrayLiteralSlowStub : public TurboFanCodeStub {
 public:
  StoreInArrayLiteralSlowStub(Isolate* isolate, KeyedAccessStoreMode mode)
      : TurboFanCodeStub(isolate) {
    minor_key_ = CommonStoreModeBits::encode(mode);
  }

 private:
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreWithVector);
  DEFINE_TURBOFAN_CODE_STUB(StoreInArrayLiteralSlow, TurboFanCodeStub);
};

607
class ElementsTransitionAndStoreStub : public TurboFanCodeStub {
608
 public:
609 610
  ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
                                 ElementsKind to_kind, bool is_jsarray,
611
                                 KeyedAccessStoreMode store_mode)
612 613 614 615
      : TurboFanCodeStub(isolate) {
    minor_key_ = CommonStoreModeBits::encode(store_mode) |
                 FromBits::encode(from_kind) | ToBits::encode(to_kind) |
                 IsJSArrayBits::encode(is_jsarray);
616
  }
617

618 619 620
  ElementsKind from_kind() const { return FromBits::decode(minor_key_); }
  ElementsKind to_kind() const { return ToBits::decode(minor_key_); }
  bool is_jsarray() const { return IsJSArrayBits::decode(minor_key_); }
621
  KeyedAccessStoreMode store_mode() const {
622
    return CommonStoreModeBits::decode(minor_key_);
623
  }
624 625

 private:
626 627
  class FromBits
      : public BitField<ElementsKind, CommonStoreModeBits::kNext, 8> {};
628 629
  class ToBits : public BitField<ElementsKind, 11, 8> {};
  class IsJSArrayBits : public BitField<bool, 19, 1> {};
630

631 632
  DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreTransition);
  DEFINE_TURBOFAN_CODE_STUB(ElementsTransitionAndStore, TurboFanCodeStub);
633 634
};

635
// TODO(jgruber): Convert this stub into a builtin.
636
class ProfileEntryHookStub : public PlatformCodeStub {
637
 public:
638
  explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
639 640

  // The profile entry hook function is not allowed to cause a GC.
641
  bool SometimesSetsUpAFrame() override { return false; }
642 643 644

  // Generates a call to the entry hook if it's enabled.
  static void MaybeCallEntryHook(MacroAssembler* masm);
645
  static void MaybeCallEntryHookDelayed(TurboAssembler* tasm, Zone* zone);
646 647 648

 private:
  static void EntryHookTrampoline(intptr_t function,
649 650
                                  intptr_t stack_pointer,
                                  Isolate* isolate);
651

652 653 654
  // ProfileEntryHookStub is called at the start of a function, so it has the
  // same register set.
  DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
655
  DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
656 657
};

658

659
#undef DEFINE_CALL_INTERFACE_DESCRIPTOR
660
#undef DEFINE_PLATFORM_CODE_STUB
661 662
#undef DEFINE_CODE_STUB
#undef DEFINE_CODE_STUB_BASE
663

664 665
}  // namespace internal
}  // namespace v8
666 667

#endif  // V8_CODE_STUBS_H_