frames.h 46.6 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
#ifndef V8_EXECUTION_FRAMES_H_
#define V8_EXECUTION_FRAMES_H_
7

8
#include "src/codegen/safepoint-table.h"
9
#include "src/common/globals.h"
10
#include "src/handles/handles.h"
11
#include "src/objects/code.h"
12
#include "src/objects/objects.h"
13

14 15
namespace v8 {
namespace internal {
16 17 18
namespace wasm {
class WasmCode;
}
19

20
// Forward declarations.
21
class AbstractCode;
22
class Debug;
23
class ExternalCallbackScope;
24
class InnerPointerToCodeCache;
25
class Isolate;
26
class ObjectVisitor;
27
class Register;
28
class RootVisitor;
29
class StackFrameIteratorBase;
30
class StringStream;
31
class ThreadLocalTop;
32
class WasmDebugInfo;
33
class WasmInstanceObject;
34
class WasmModuleObject;
35

36 37
class StackHandlerConstants : public AllStatic {
 public:
38 39
  static const int kNextOffset = 0 * kSystemPointerSize;
  static const int kPaddingOffset = 1 * kSystemPointerSize;
40

41 42
  static const int kSize = kPaddingOffset + kSystemPointerSize;
  static const int kSlotCount = kSize >> kSystemPointerSizeLog2;
43 44
};

45
class StackHandler {
46 47 48 49 50 51 52
 public:
  // Get the address of this stack handler.
  inline Address address() const;

  // Get the next stack handler in the chain.
  inline StackHandler* next() const;

53 54 55 56
  // Get the next stack handler, as an Address. This is safe to use even
  // when the next handler is null.
  inline Address next_address() const;

57 58 59 60
  // Conversion support.
  static inline StackHandler* FromAddress(Address address);

 private:
61
  DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler);
62 63
};

64 65
#define STACK_FRAME_TYPE_LIST(V)                                          \
  V(ENTRY, EntryFrame)                                                    \
66
  V(CONSTRUCT_ENTRY, ConstructEntryFrame)                                 \
67 68
  V(EXIT, ExitFrame)                                                      \
  V(OPTIMIZED, OptimizedFrame)                                            \
69
  V(WASM, WasmFrame)                                                      \
70 71
  V(WASM_TO_JS, WasmToJsFrame)                                            \
  V(JS_TO_WASM, JsToWasmFrame)                                            \
72
  V(WASM_DEBUG_BREAK, WasmDebugBreakFrame)                                \
73
  V(C_WASM_ENTRY, CWasmEntryFrame)                                        \
74
  V(WASM_EXIT, WasmExitFrame)                                             \
75
  V(WASM_COMPILE_LAZY, WasmCompileLazyFrame)                              \
76 77 78 79
  V(INTERPRETED, InterpretedFrame)                                        \
  V(STUB, StubFrame)                                                      \
  V(BUILTIN_CONTINUATION, BuiltinContinuationFrame)                       \
  V(JAVA_SCRIPT_BUILTIN_CONTINUATION, JavaScriptBuiltinContinuationFrame) \
80 81
  V(JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH,                          \
    JavaScriptBuiltinContinuationWithCatchFrame)                          \
82 83 84 85
  V(INTERNAL, InternalFrame)                                              \
  V(CONSTRUCT, ConstructFrame)                                            \
  V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame)                             \
  V(BUILTIN, BuiltinFrame)                                                \
86 87
  V(BUILTIN_EXIT, BuiltinExitFrame)                                       \
  V(NATIVE, NativeFrame)
88 89

// Abstract base class for all stack frames.
90
class StackFrame {
91 92 93 94
 public:
#define DECLARE_TYPE(type, ignore) type,
  enum Type {
    NONE = 0,
95
    STACK_FRAME_TYPE_LIST(DECLARE_TYPE) NUMBER_OF_TYPES,
96 97 98
    // Used by FrameScope to indicate that the stack frame is constructed
    // manually and the FrameScope does not need to emit code.
    MANUAL
99 100 101
  };
#undef DECLARE_TYPE

102
  // Used to mark the outermost JS entry frame.
103 104 105
  //
  // The mark is an opaque value that should be pushed onto the stack directly,
  // carefully crafted to not be interpreted as a tagged pointer.
106
  enum JsFrameMarker {
107 108
    INNER_JSENTRY_FRAME = (0 << kSmiTagSize) | kSmiTag,
    OUTERMOST_JSENTRY_FRAME = (1 << kSmiTagSize) | kSmiTag
109
  };
110
  // NOLINTNEXTLINE(runtime/references) (false positive)
111
  STATIC_ASSERT((INNER_JSENTRY_FRAME & kHeapObjectTagMask) != kHeapObjectTag);
112
  // NOLINTNEXTLINE(runtime/references) (false positive)
113 114
  STATIC_ASSERT((OUTERMOST_JSENTRY_FRAME & kHeapObjectTagMask) !=
                kHeapObjectTag);
115

116
  struct State {
117 118
    Address sp = kNullAddress;
    Address fp = kNullAddress;
119
    Address* pc_address = nullptr;
120
    Address callee_fp = kNullAddress;
121 122
    Address* callee_pc_address = nullptr;
    Address* constant_pool_address = nullptr;
123 124
  };

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  // Convert a stack frame type to a marker that can be stored on the stack.
  //
  // The marker is an opaque value, not intended to be interpreted in any way
  // except being checked by IsTypeMarker or converted by MarkerToType.
  // It has the same tagging as Smis, so any marker value that does not pass
  // IsTypeMarker can instead be interpreted as a tagged pointer.
  //
  // Note that the marker is not a Smi: Smis on 64-bit architectures are stored
  // in the top 32 bits of a 64-bit value, which in turn makes them expensive
  // (in terms of code/instruction size) to push as immediates onto the stack.
  static int32_t TypeToMarker(Type type) {
    DCHECK_GE(type, 0);
    return (type << kSmiTagSize) | kSmiTag;
  }

  // Convert a marker back to a stack frame type.
  //
  // Unlike the return value of TypeToMarker, this takes an intptr_t, as that is
  // the type of the value on the stack.
  static Type MarkerToType(intptr_t marker) {
    DCHECK(IsTypeMarker(marker));
146
    intptr_t type = marker >> kSmiTagSize;
147
    // TODO(petermarshall): There is a bug in the arm simulators that causes
148
    // invalid frame markers.
149 150 151 152 153 154
#if defined(USE_SIMULATOR) && (V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM)
    if (static_cast<uintptr_t>(type) >= Type::NUMBER_OF_TYPES) {
      // Appease UBSan.
      return Type::NUMBER_OF_TYPES;
    }
#else
155 156 157
    DCHECK_LT(static_cast<uintptr_t>(type), Type::NUMBER_OF_TYPES);
#endif
    return static_cast<Type>(type);
158 159 160 161 162 163 164 165
  }

  // Check if a marker is a stack frame type marker or a tagged pointer.
  //
  // Returns true if the given marker is tagged as a stack frame type marker,
  // and should be converted back to a stack frame type using MarkerToType.
  // Otherwise, the value is a tagged function pointer.
  static bool IsTypeMarker(intptr_t function_or_marker) {
166
    return (function_or_marker & kSmiTagMask) == kSmiTag;
167 168
  }

169 170
  // Copy constructor; it breaks the connection to host iterator
  // (as an iterator usually lives on stack).
171
  StackFrame(const StackFrame& original) V8_NOEXCEPT {
172
    this->state_ = original.state_;
173
    this->iterator_ = nullptr;
174
    this->isolate_ = original.isolate_;
175 176
  }

177 178
  // Type testers.
  bool is_entry() const { return type() == ENTRY; }
179
  bool is_construct_entry() const { return type() == CONSTRUCT_ENTRY; }
180
  bool is_exit() const { return type() == EXIT; }
181
  bool is_optimized() const { return type() == OPTIMIZED; }
182
  bool is_interpreted() const { return type() == INTERPRETED; }
183
  bool is_wasm() const { return this->type() == WASM; }
184
  bool is_wasm_compile_lazy() const { return type() == WASM_COMPILE_LAZY; }
185
  bool is_wasm_debug_break() const { return type() == WASM_DEBUG_BREAK; }
186
  bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; }
187
  bool is_builtin() const { return type() == BUILTIN; }
188
  bool is_internal() const { return type() == INTERNAL; }
189 190 191 192 193 194
  bool is_builtin_continuation() const {
    return type() == BUILTIN_CONTINUATION;
  }
  bool is_java_script_builtin_continuation() const {
    return type() == JAVA_SCRIPT_BUILTIN_CONTINUATION;
  }
195 196 197
  bool is_java_script_builtin_with_catch_continuation() const {
    return type() == JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH;
  }
198
  bool is_construct() const { return type() == CONSTRUCT; }
199
  bool is_builtin_exit() const { return type() == BUILTIN_EXIT; }
200 201
  virtual bool is_standard() const { return false; }

202 203
  bool is_java_script() const {
    Type type = this->type();
204
    return (type == OPTIMIZED) || (type == INTERPRETED) || (type == BUILTIN) ||
205 206
           (type == JAVA_SCRIPT_BUILTIN_CONTINUATION) ||
           (type == JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH);
207
  }
208
  bool is_wasm_to_js() const { return type() == WASM_TO_JS; }
209

210 211 212
  // Accessors.
  Address sp() const { return state_.sp; }
  Address fp() const { return state_.fp; }
213
  Address callee_fp() const { return state_.callee_fp; }
214
  inline Address callee_pc() const;
215
  Address caller_sp() const { return GetCallerStackPointer(); }
216

217 218 219 220 221
  // If this frame is optimized and was dynamically aligned return its old
  // unaligned frame pointer.  When the frame is deoptimized its FP will shift
  // up one word and become unaligned.
  Address UnpaddedFP() const;

222
  inline Address pc() const;
223

224
  Address constant_pool() const { return *constant_pool_address(); }
225 226
  void set_constant_pool(Address constant_pool) {
    *constant_pool_address() = constant_pool;
227 228
  }

229 230
  Address* pc_address() const { return state_.pc_address; }

231 232 233 234
  Address* constant_pool_address() const {
    return state_.constant_pool_address;
  }

235
  // Get the id of this stack frame.
236
  StackFrameId id() const { return static_cast<StackFrameId>(caller_sp()); }
237

238 239 240
  // Get the top handler from the current stack iterator.
  inline StackHandler* top_handler() const;

241 242 243 244
  // Get the type of this frame.
  virtual Type type() const = 0;

  // Get the code associated with this frame.
245
  // This method could be called during marking phase of GC.
246
  virtual Code unchecked_code() const = 0;
247

248
  // Search for the code associated with this frame.
249
  V8_EXPORT_PRIVATE Code LookupCode() const;
250

251 252
  virtual void Iterate(RootVisitor* v) const = 0;
  static void IteratePc(RootVisitor* v, Address* pc_address,
253
                        Address* constant_pool_address, Code holder);
254

255 256 257 258 259
  // Sets a callback function for return-address rewriting profilers
  // to resolve the location of a return address to the location of the
  // profiler's stashed return address.
  static void SetReturnAddressLocationResolver(
      ReturnAddressLocationResolver resolver);
260

261 262
  static inline Address ReadPC(Address* pc_address);

263 264 265
  // Resolves pc_address through the resolution address function if one is set.
  static inline Address* ResolveReturnAddressLocation(Address* pc_address);

266 267
  // Printing support.
  enum PrintMode { OVERVIEW, DETAILS };
268 269
  virtual void Print(StringStream* accumulator, PrintMode mode,
                     int index) const;
270

271 272
  Isolate* isolate() const { return isolate_; }

273 274
  void operator=(const StackFrame& original) = delete;

275
 protected:
276
  inline explicit StackFrame(StackFrameIteratorBase* iterator);
277
  virtual ~StackFrame() = default;
278 279 280 281 282

  // Compute the stack pointer for the calling frame.
  virtual Address GetCallerStackPointer() const = 0;

  // Compute the stack frame type for the given state.
283
  static Type ComputeType(const StackFrameIteratorBase* iterator, State* state);
284 285 286 287

#ifdef DEBUG
  bool can_access_heap_objects() const;
#endif
288 289

 private:
290
  const StackFrameIteratorBase* iterator_;
291
  Isolate* isolate_;
292
  State state_;
293

294 295
  static ReturnAddressLocationResolver return_address_location_resolver_;

296 297 298
  // Fill in the state of the calling frame.
  virtual void ComputeCallerState(State* state) const = 0;

299
  // Get the type and the state of the calling frame.
300
  virtual Type GetCallerState(State* state) const;
301

302 303
  static const intptr_t kIsolateTag = 1;

304
  friend class StackFrameIterator;
305
  friend class StackFrameIteratorBase;
306
  friend class StackHandlerIterator;
307
  friend class SafeStackFrameIterator;
308 309
};

310 311 312 313
class NativeFrame : public StackFrame {
 public:
  Type type() const override { return NATIVE; }

314
  Code unchecked_code() const override;
315 316 317 318 319 320 321 322 323 324 325 326 327 328

  // Garbage collection support.
  void Iterate(RootVisitor* v) const override {}

 protected:
  inline explicit NativeFrame(StackFrameIteratorBase* iterator);

  Address GetCallerStackPointer() const override;

 private:
  void ComputeCallerState(State* state) const override;

  friend class StackFrameIteratorBase;
};
329 330

// Entry frames are used to enter JavaScript execution from C.
331
class EntryFrame : public StackFrame {
332
 public:
333
  Type type() const override { return ENTRY; }
334

335
  Code unchecked_code() const override;
336 337

  // Garbage collection support.
338
  void Iterate(RootVisitor* v) const override;
339 340

  static EntryFrame* cast(StackFrame* frame) {
341
    DCHECK(frame->is_entry());
342 343 344 345
    return static_cast<EntryFrame*>(frame);
  }

 protected:
346
  inline explicit EntryFrame(StackFrameIteratorBase* iterator);
347 348 349 350

  // The caller stack pointer for entry frames is always zero. The
  // real information about the caller frame is available through the
  // link to the top exit frame.
351
  Address GetCallerStackPointer() const override { return 0; }
352 353

 private:
354 355
  void ComputeCallerState(State* state) const override;
  Type GetCallerState(State* state) const override;
356

357
  friend class StackFrameIteratorBase;
358 359
};

360
class ConstructEntryFrame : public EntryFrame {
361
 public:
362
  Type type() const override { return CONSTRUCT_ENTRY; }
363

364
  Code unchecked_code() const override;
365

366 367 368
  static ConstructEntryFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_construct_entry());
    return static_cast<ConstructEntryFrame*>(frame);
369 370 371
  }

 protected:
372
  inline explicit ConstructEntryFrame(StackFrameIteratorBase* iterator);
373 374

 private:
375
  friend class StackFrameIteratorBase;
376 377 378
};

// Exit frames are used to exit JavaScript execution and go to C.
379
class ExitFrame : public StackFrame {
380
 public:
381
  Type type() const override { return EXIT; }
382

383
  Code unchecked_code() const override;
384

385
  // Garbage collection support.
386
  void Iterate(RootVisitor* v) const override;
387 388

  static ExitFrame* cast(StackFrame* frame) {
389
    DCHECK(frame->is_exit());
390 391 392 393 394 395 396
    return static_cast<ExitFrame*>(frame);
  }

  // Compute the state and type of an exit frame given a frame
  // pointer. Used when constructing the first stack frame seen by an
  // iterator and the frames following entry frames.
  static Type GetStateForFramePointer(Address fp, State* state);
397
  static Address ComputeStackPointer(Address fp);
398
  static StackFrame::Type ComputeFrameType(Address fp);
399
  static void FillState(Address fp, Address sp, State* state);
400 401

 protected:
402
  inline explicit ExitFrame(StackFrameIteratorBase* iterator);
403

404
  Address GetCallerStackPointer() const override;
405 406

 private:
407
  void ComputeCallerState(State* state) const override;
408

409
  friend class StackFrameIteratorBase;
410 411
};

412 413 414 415 416 417 418 419 420 421 422 423
// Builtin exit frames are a special case of exit frames, which are used
// whenever C++ builtins (e.g., Math.acos) are called. Their main purpose is
// to allow such builtins to appear in stack traces.
class BuiltinExitFrame : public ExitFrame {
 public:
  Type type() const override { return BUILTIN_EXIT; }

  static BuiltinExitFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_builtin_exit());
    return static_cast<BuiltinExitFrame*>(frame);
  }

424
  JSFunction function() const;
425
  Object receiver() const;
426 427

  bool IsConstructor() const;
428

429 430 431
  void Print(StringStream* accumulator, PrintMode mode,
             int index) const override;

432 433 434 435
 protected:
  inline explicit BuiltinExitFrame(StackFrameIteratorBase* iterator);

 private:
436
  Object GetParameter(int i) const;
437 438
  int ComputeParametersCount() const;

439 440 441 442
  inline Object receiver_slot_object() const;
  inline Object argc_slot_object() const;
  inline Object target_slot_object() const;
  inline Object new_target_slot_object() const;
443 444

  friend class StackFrameIteratorBase;
445
  friend class FrameArrayBuilder;
446 447
};

448
class StandardFrame;
449

450
class V8_EXPORT_PRIVATE FrameSummary {
451
 public:
452
// Subclasses for the different summary kinds:
453 454
#define FRAME_SUMMARY_VARIANTS(F)                                          \
  F(JAVA_SCRIPT, JavaScriptFrameSummary, java_script_summary_, JavaScript) \
455
  F(WASM, WasmFrameSummary, wasm_summary_, Wasm)
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474

#define FRAME_SUMMARY_KIND(kind, type, field, desc) kind,
  enum Kind { FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_KIND) };
#undef FRAME_SUMMARY_KIND

  class FrameSummaryBase {
   public:
    FrameSummaryBase(Isolate* isolate, Kind kind)
        : isolate_(isolate), kind_(kind) {}
    Isolate* isolate() const { return isolate_; }
    Kind kind() const { return kind_; }

   private:
    Isolate* isolate_;
    Kind kind_;
  };

  class JavaScriptFrameSummary : public FrameSummaryBase {
   public:
475
    JavaScriptFrameSummary(Isolate* isolate, Object receiver,
476
                           JSFunction function, AbstractCode abstract_code,
477 478
                           int code_offset, bool is_constructor,
                           FixedArray parameters);
479

480
    void EnsureSourcePositionsAvailable();
481
    bool AreSourcePositionsAvailable() const;
482

483 484 485 486 487
    Handle<Object> receiver() const { return receiver_; }
    Handle<JSFunction> function() const { return function_; }
    Handle<AbstractCode> abstract_code() const { return abstract_code_; }
    int code_offset() const { return code_offset_; }
    bool is_constructor() const { return is_constructor_; }
488
    Handle<FixedArray> parameters() const { return parameters_; }
489 490 491 492 493 494 495 496 497 498 499 500 501
    bool is_subject_to_debugging() const;
    int SourcePosition() const;
    int SourceStatementPosition() const;
    Handle<Object> script() const;
    Handle<String> FunctionName() const;
    Handle<Context> native_context() const;

   private:
    Handle<Object> receiver_;
    Handle<JSFunction> function_;
    Handle<AbstractCode> abstract_code_;
    int code_offset_;
    bool is_constructor_;
502
    Handle<FixedArray> parameters_;
503 504 505 506
  };

  class WasmFrameSummary : public FrameSummaryBase {
   public:
507 508 509
    WasmFrameSummary(Isolate*, Handle<WasmInstanceObject>, wasm::WasmCode*,
                     int code_offset, bool at_to_number_conversion);

510 511
    Handle<Object> receiver() const;
    uint32_t function_index() const;
512 513 514
    wasm::WasmCode* code() const { return code_; }
    int code_offset() const { return code_offset_; }
    V8_EXPORT_PRIVATE int byte_offset() const;
515 516 517 518 519 520 521 522 523 524 525 526 527
    bool is_constructor() const { return false; }
    bool is_subject_to_debugging() const { return true; }
    int SourcePosition() const;
    int SourceStatementPosition() const { return SourcePosition(); }
    Handle<Script> script() const;
    Handle<WasmInstanceObject> wasm_instance() const { return wasm_instance_; }
    Handle<String> FunctionName() const;
    Handle<Context> native_context() const;
    bool at_to_number_conversion() const { return at_to_number_conversion_; }

   private:
    Handle<WasmInstanceObject> wasm_instance_;
    bool at_to_number_conversion_;
528
    wasm::WasmCode* const code_;
529 530
    int code_offset_;
  };
531

532 533 534 535
#define FRAME_SUMMARY_CONS(kind, type, field, desc) \
  FrameSummary(type summ) : field(summ) {}  // NOLINT
  FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_CONS)
#undef FRAME_SUMMARY_CONS
536

537
  ~FrameSummary();
538

539 540
  static FrameSummary GetTop(const StandardFrame* frame);
  static FrameSummary GetBottom(const StandardFrame* frame);
541
  static FrameSummary GetSingle(const StandardFrame* frame);
542
  static FrameSummary Get(const StandardFrame* frame, int index);
543

544
  void EnsureSourcePositionsAvailable();
545
  bool AreSourcePositionsAvailable() const;
546

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  // Dispatched accessors.
  Handle<Object> receiver() const;
  int code_offset() const;
  bool is_constructor() const;
  bool is_subject_to_debugging() const;
  Handle<Object> script() const;
  int SourcePosition() const;
  int SourceStatementPosition() const;
  Handle<String> FunctionName() const;
  Handle<Context> native_context() const;

#define FRAME_SUMMARY_CAST(kind_, type, field, desc)      \
  bool Is##desc() const { return base_.kind() == kind_; } \
  const type& As##desc() const {                          \
    DCHECK_EQ(base_.kind(), kind_);                       \
    return field;                                         \
  }
  FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_CAST)
#undef FRAME_SUMMARY_CAST

567
 private:
568 569 570 571 572
#define FRAME_SUMMARY_FIELD(kind, type, field, desc) type field;
  union {
    FrameSummaryBase base_;
    FRAME_SUMMARY_VARIANTS(FRAME_SUMMARY_FIELD)
  };
573
#undef FRAME_SUMMARY_FIELD
574
};
575

576
class StandardFrame : public StackFrame {
577 578
 public:
  // Testers.
579
  bool is_standard() const override { return true; }
580 581

  // Accessors.
582
  virtual Object receiver() const;
583
  virtual Script script() const;
584
  virtual Object context() const;
585
  virtual int position() const;
586 587

  // Access the expressions in the stack frame including locals.
588 589
  inline Object GetExpression(int index) const;
  inline void SetExpression(int index, Object value);
590 591
  int ComputeExpressionsCount() const;

592
  // Access the parameters.
593
  virtual Object GetParameter(int index) const;
594 595 596 597 598
  virtual int ComputeParametersCount() const;

  // Check if this frame is a constructor frame invoked through 'new'.
  virtual bool IsConstructor() const;

599
  // Build a list with summaries for this frame including all inlined frames.
600 601
  // The functions are ordered bottom-to-top (i.e. summaries.last() is the
  // top-most activation; caller comes before callee).
602
  virtual void Summarize(std::vector<FrameSummary>* frames) const;
603

604
  static StandardFrame* cast(StackFrame* frame) {
605
    DCHECK(frame->is_standard());
606 607 608 609
    return static_cast<StandardFrame*>(frame);
  }

 protected:
610
  inline explicit StandardFrame(StackFrameIteratorBase* iterator);
611

612
  void ComputeCallerState(State* state) const override;
613 614 615 616 617 618 619 620 621

  // Accessors.
  inline Address caller_fp() const;
  inline Address caller_pc() const;

  // Computes the address of the PC field in the standard frame given
  // by the provided frame pointer.
  static inline Address ComputePCAddress(Address fp);

622 623 624 625
  // Computes the address of the constant pool  field in the standard
  // frame given by the provided frame pointer.
  static inline Address ComputeConstantPoolAddress(Address fp);

626 627
  // Iterate over expression stack including stack handlers, locals,
  // and parts of the fixed part including context and code fields.
628
  void IterateExpressions(RootVisitor* v) const;
629 630

  // Returns the address of the n'th expression stack element.
631
  virtual Address GetExpressionAddress(int n) const;
632 633 634 635 636

  // Determines if the standard frame for the given frame pointer is
  // an arguments adaptor frame.
  static inline bool IsArgumentsAdaptorFrame(Address fp);

637 638 639
  // Determines if the standard frame for the given frame pointer is a
  // construct frame.
  static inline bool IsConstructFrame(Address fp);
640

641
  // Used by OptimizedFrames and StubFrames.
642
  void IterateCompiledFrame(RootVisitor* v) const;
643

644 645
 private:
  friend class StackFrame;
646
  friend class SafeStackFrameIterator;
647 648
};

649
class JavaScriptFrame : public StandardFrame {
650
 public:
651
  Type type() const override = 0;
652

653
  void Summarize(std::vector<FrameSummary>* frames) const override;
654 655

  // Accessors.
656
  virtual JSFunction function() const;
657 658 659
  Object unchecked_function() const;
  Object receiver() const override;
  Object context() const override;
660
  Script script() const override;
661

662
  inline void set_receiver(Object value);
663 664

  // Access the parameters.
665
  inline Address GetParameterSlot(int index) const;
666
  Object GetParameter(int index) const override;
667
  int ComputeParametersCount() const override;
668
  Handle<FixedArray> GetParameters() const;
669

670
  // Debugger access.
671
  void SetParameterValue(int index, Object value) const;
672

673
  // Check if this frame is a constructor frame invoked through 'new'.
674
  bool IsConstructor() const override;
675

676 677
  // Determines whether this frame includes inlined activations. To get details
  // about the inlined frames use {GetFunctions} and {Summarize}.
678
  bool HasInlinedFrames() const;
679

680 681 682 683 684
  // Check if this frame has "adapted" arguments in the sense that the
  // actual passed arguments are available in an arguments adaptor
  // frame below it on the stack.
  inline bool has_adapted_arguments() const;

685
  // Garbage collection support.
686
  void Iterate(RootVisitor* v) const override;
687 688

  // Printing support.
689 690
  void Print(StringStream* accumulator, PrintMode mode,
             int index) const override;
691 692

  // Determine the code for the frame.
693
  Code unchecked_code() const override;
694

695
  // Return a list with {SharedFunctionInfo} objects of this frame.
696
  virtual void GetFunctions(std::vector<SharedFunctionInfo>* functions) const;
697

698
  void GetFunctions(std::vector<Handle<SharedFunctionInfo>>* functions) const;
699

700
  // Lookup exception handler for current {pc}, returns -1 if none found. Also
701
  // returns data associated with the handler site specific to the frame type:
702
  //  - OptimizedFrame  : Data is not used and will not return a value.
703
  //  - InterpretedFrame: Data is the register index holding the context.
704
  virtual int LookupExceptionHandlerInTable(
705
      int* data, HandlerTable::CatchPrediction* prediction);
706

707 708 709
  // Architecture-specific register description.
  static Register fp_register();
  static Register context_register();
710
  static Register constant_pool_pointer_register();
711

712
  static JavaScriptFrame* cast(StackFrame* frame) {
713
    DCHECK(frame->is_java_script());
714 715 716
    return static_cast<JavaScriptFrame*>(frame);
  }

717
  static void PrintFunctionAndOffset(JSFunction function, AbstractCode code,
718
                                     int code_offset, FILE* file,
719 720 721
                                     bool print_line_number);

  static void PrintTop(Isolate* isolate, FILE* file, bool print_args,
722
                       bool print_line_number);
723

724
  static void CollectFunctionAndOffsetForICStats(JSFunction function,
725
                                                 AbstractCode code,
726 727
                                                 int code_offset);

728
 protected:
729
  inline explicit JavaScriptFrame(StackFrameIteratorBase* iterator);
730

731
  Address GetCallerStackPointer() const override;
732

733 734
  virtual void PrintFrameKind(StringStream* accumulator) const {}

735
 private:
736
  inline Object function_slot_object() const;
737

738
  friend class StackFrameIteratorBase;
739 740
};

741 742
class StubFrame : public StandardFrame {
 public:
743
  Type type() const override { return STUB; }
744 745

  // GC support.
746
  void Iterate(RootVisitor* v) const override;
747 748

  // Determine the code for the frame.
749
  Code unchecked_code() const override;
750

751
  // Lookup exception handler for current {pc}, returns -1 if none found. Only
752 753
  // TurboFan stub frames are supported.
  int LookupExceptionHandlerInTable();
754

755
 protected:
756
  inline explicit StubFrame(StackFrameIteratorBase* iterator);
757

758
  Address GetCallerStackPointer() const override;
759

760
  friend class StackFrameIteratorBase;
761 762
};

763
class OptimizedFrame : public JavaScriptFrame {
764
 public:
765
  Type type() const override { return OPTIMIZED; }
766 767

  // GC support.
768
  void Iterate(RootVisitor* v) const override;
769

770
  // Return a list with {SharedFunctionInfo} objects of this frame.
771 772
  // The functions are ordered bottom-to-top (i.e. functions.last()
  // is the top-most activation)
773
  void GetFunctions(std::vector<SharedFunctionInfo>* functions) const override;
774

775
  void Summarize(std::vector<FrameSummary>* frames) const override;
776

777
  // Lookup exception handler for current {pc}, returns -1 if none found.
778
  int LookupExceptionHandlerInTable(
779
      int* data, HandlerTable::CatchPrediction* prediction) override;
780

781
  DeoptimizationData GetDeoptimizationData(int* deopt_index) const;
782

783 784 785
#ifndef V8_REVERSE_JSARGS
  // When the arguments are reversed in the stack, receiver() is
  // inherited from JavaScriptFrame.
786
  Object receiver() const override;
787
#endif
788
  int ComputeParametersCount() const override;
789

790 791
  static int StackSlotOffsetRelativeToFp(int slot_index);

792
 protected:
793
  inline explicit OptimizedFrame(StackFrameIteratorBase* iterator);
794 795

 private:
796
  friend class StackFrameIteratorBase;
797

798
  Object StackSlotAt(int index) const;
799 800
};

801
class InterpretedFrame : public JavaScriptFrame {
802
 public:
803
  Type type() const override { return INTERPRETED; }
804

805 806 807
  // Accessors.
  int position() const override;

808
  // Lookup exception handler for current {pc}, returns -1 if none found.
809
  int LookupExceptionHandlerInTable(
810
      int* data, HandlerTable::CatchPrediction* prediction) override;
811 812 813 814 815 816 817 818

  // Returns the current offset into the bytecode stream.
  int GetBytecodeOffset() const;

  // Updates the current offset into the bytecode stream, mainly used for stack
  // unwinding to continue execution at a different bytecode offset.
  void PatchBytecodeOffset(int new_offset);

819
  // Returns the frame's current bytecode array.
820
  BytecodeArray GetBytecodeArray() const;
821

822 823
  // Updates the frame's BytecodeArray with |bytecode_array|. Used by the
  // debugger to swap execution onto a BytecodeArray patched with breakpoints.
824
  void PatchBytecodeArray(BytecodeArray bytecode_array);
825

826
  // Access to the interpreter register file for this frame.
827 828
  Object ReadInterpreterRegister(int register_index) const;
  void WriteInterpreterRegister(int register_index, Object value);
829

830
  // Build a list with summaries for this frame including all inlined frames.
831
  void Summarize(std::vector<FrameSummary>* frames) const override;
832

833 834
  static int GetBytecodeOffset(Address fp);

835 836 837 838 839
  static InterpretedFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_interpreted());
    return static_cast<InterpretedFrame*>(frame);
  }

840 841 842
 protected:
  inline explicit InterpretedFrame(StackFrameIteratorBase* iterator);

843 844
  Address GetExpressionAddress(int n) const override;

845 846 847 848
 private:
  friend class StackFrameIteratorBase;
};

849 850 851
// Arguments adaptor frames are automatically inserted below
// JavaScript frames when the actual number of parameters does not
// match the formal number of parameters.
852
class ArgumentsAdaptorFrame : public JavaScriptFrame {
853
 public:
854
  Type type() const override { return ARGUMENTS_ADAPTOR; }
855 856

  // Determine the code for the frame.
857
  Code unchecked_code() const override;
858 859

  static ArgumentsAdaptorFrame* cast(StackFrame* frame) {
860
    DCHECK(frame->is_arguments_adaptor());
861 862 863
    return static_cast<ArgumentsAdaptorFrame*>(frame);
  }

864 865
  int ComputeParametersCount() const override;

866
  // Printing support.
867 868
  void Print(StringStream* accumulator, PrintMode mode,
             int index) const override;
869

870
 protected:
871
  inline explicit ArgumentsAdaptorFrame(StackFrameIteratorBase* iterator);
872

873 874 875 876 877 878 879 880 881 882 883 884 885 886
 private:
  friend class StackFrameIteratorBase;
};

// Builtin frames are built for builtins with JavaScript linkage, such as
// various standard library functions (i.e. Math.asin, Math.floor, etc.).
class BuiltinFrame final : public JavaScriptFrame {
 public:
  Type type() const final { return BUILTIN; }

  static BuiltinFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_builtin());
    return static_cast<BuiltinFrame*>(frame);
  }
887
  int ComputeParametersCount() const final;
888 889 890 891

 protected:
  inline explicit BuiltinFrame(StackFrameIteratorBase* iterator);

892
  void PrintFrameKind(StringStream* accumulator) const override;
893 894

 private:
895
  friend class StackFrameIteratorBase;
896 897
};

898
class WasmFrame : public StandardFrame {
899
 public:
900
  Type type() const override { return WASM; }
901 902

  // GC support.
903
  void Iterate(RootVisitor* v) const override;
904 905 906 907 908

  // Printing support.
  void Print(StringStream* accumulator, PrintMode mode,
             int index) const override;

909 910
  // Lookup exception handler for current {pc}, returns -1 if none found.
  int LookupExceptionHandlerInTable();
911

912
  // Determine the code for the frame.
913
  Code unchecked_code() const override;
914

915
  // Accessors.
916
  V8_EXPORT_PRIVATE WasmInstanceObject wasm_instance() const;
917
  V8_EXPORT_PRIVATE wasm::NativeModule* native_module() const;
918
  wasm::WasmCode* wasm_code() const;
919
  uint32_t function_index() const;
920
  Script script() const override;
921
  // Byte position in the module, or asm.js source position.
922
  int position() const override;
923
  Object context() const override;
924
  bool at_to_number_conversion() const;
925 926
  // Byte offset in the function.
  int byte_offset() const;
927
  bool is_inspectable() const;
928

929
  void Summarize(std::vector<FrameSummary>* frames) const override;
930

931 932 933
  static WasmFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_wasm());
    return static_cast<WasmFrame*>(frame);
934 935 936
  }

 protected:
937
  inline explicit WasmFrame(StackFrameIteratorBase* iterator);
938 939 940 941 942

  Address GetCallerStackPointer() const override;

 private:
  friend class StackFrameIteratorBase;
943
  WasmModuleObject module_object() const;
944 945
};

946
class WasmExitFrame : public WasmFrame {
947 948 949 950 951 952 953 954 955 956 957
 public:
  Type type() const override { return WASM_EXIT; }
  static Address ComputeStackPointer(Address fp);

 protected:
  inline explicit WasmExitFrame(StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
};

958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
class WasmDebugBreakFrame final : public StandardFrame {
 public:
  Type type() const override { return WASM_DEBUG_BREAK; }

  // GC support.
  void Iterate(RootVisitor* v) const override;

  Code unchecked_code() const override;

  void Print(StringStream* accumulator, PrintMode mode,
             int index) const override;

  static WasmDebugBreakFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_wasm_debug_break());
    return static_cast<WasmDebugBreakFrame*>(frame);
  }

 protected:
  inline explicit WasmDebugBreakFrame(StackFrameIteratorBase*);

  Address GetCallerStackPointer() const override;

 private:
  friend class StackFrameIteratorBase;
};

984
class WasmToJsFrame : public StubFrame {
985 986 987 988 989 990 991 992 993 994
 public:
  Type type() const override { return WASM_TO_JS; }

 protected:
  inline explicit WasmToJsFrame(StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
};

995
class JsToWasmFrame : public StubFrame {
996 997 998 999 1000
 public:
  Type type() const override { return JS_TO_WASM; }

 protected:
  inline explicit JsToWasmFrame(StackFrameIteratorBase* iterator);
1001 1002 1003 1004 1005

 private:
  friend class StackFrameIteratorBase;
};

1006 1007 1008 1009 1010 1011 1012 1013 1014
class CWasmEntryFrame : public StubFrame {
 public:
  Type type() const override { return C_WASM_ENTRY; }

 protected:
  inline explicit CWasmEntryFrame(StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
1015
  Type GetCallerState(State* state) const override;
1016 1017
};

1018 1019 1020 1021
class WasmCompileLazyFrame : public StandardFrame {
 public:
  Type type() const override { return WASM_COMPILE_LAZY; }

1022
  Code unchecked_code() const override;
1023
  WasmInstanceObject wasm_instance() const;
1024
  FullObjectSlot wasm_instance_slot() const;
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042

  // Garbage collection support.
  void Iterate(RootVisitor* v) const override;

  static WasmCompileLazyFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_wasm_compile_lazy());
    return static_cast<WasmCompileLazyFrame*>(frame);
  }

 protected:
  inline explicit WasmCompileLazyFrame(StackFrameIteratorBase* iterator);

  Address GetCallerStackPointer() const override;

 private:
  friend class StackFrameIteratorBase;
};

1043
class InternalFrame : public StandardFrame {
1044
 public:
1045
  Type type() const override { return INTERNAL; }
1046

1047
  // Garbage collection support.
1048
  void Iterate(RootVisitor* v) const override;
1049 1050

  // Determine the code for the frame.
1051
  Code unchecked_code() const override;
1052 1053

  static InternalFrame* cast(StackFrame* frame) {
1054
    DCHECK(frame->is_internal());
1055 1056 1057 1058
    return static_cast<InternalFrame*>(frame);
  }

 protected:
1059
  inline explicit InternalFrame(StackFrameIteratorBase* iterator);
1060

1061
  Address GetCallerStackPointer() const override;
1062 1063

 private:
1064
  friend class StackFrameIteratorBase;
1065 1066
};

1067 1068
// Construct frames are special trampoline frames introduced to handle
// function invocations through 'new'.
1069
class ConstructFrame : public InternalFrame {
1070
 public:
1071
  Type type() const override { return CONSTRUCT; }
1072 1073

  static ConstructFrame* cast(StackFrame* frame) {
1074
    DCHECK(frame->is_construct());
1075 1076 1077 1078
    return static_cast<ConstructFrame*>(frame);
  }

 protected:
1079
  inline explicit ConstructFrame(StackFrameIteratorBase* iterator);
1080 1081

 private:
1082
  friend class StackFrameIteratorBase;
1083 1084
};

1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
class BuiltinContinuationFrame : public InternalFrame {
 public:
  Type type() const override { return BUILTIN_CONTINUATION; }

  static BuiltinContinuationFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_builtin_continuation());
    return static_cast<BuiltinContinuationFrame*>(frame);
  }

 protected:
  inline explicit BuiltinContinuationFrame(StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
};

class JavaScriptBuiltinContinuationFrame : public JavaScriptFrame {
 public:
  Type type() const override { return JAVA_SCRIPT_BUILTIN_CONTINUATION; }

  static JavaScriptBuiltinContinuationFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_java_script_builtin_continuation());
    return static_cast<JavaScriptBuiltinContinuationFrame*>(frame);
  }

  int ComputeParametersCount() const override;
1111
  intptr_t GetSPToFPDelta() const;
1112

1113
  Object context() const override;
1114

1115 1116 1117 1118 1119 1120 1121
 protected:
  inline explicit JavaScriptBuiltinContinuationFrame(
      StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
};
1122

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
class JavaScriptBuiltinContinuationWithCatchFrame
    : public JavaScriptBuiltinContinuationFrame {
 public:
  Type type() const override {
    return JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH;
  }

  static JavaScriptBuiltinContinuationWithCatchFrame* cast(StackFrame* frame) {
    DCHECK(frame->is_java_script_builtin_with_catch_continuation());
    return static_cast<JavaScriptBuiltinContinuationWithCatchFrame*>(frame);
  }

  // Patch in the exception object at the appropriate location into the stack
  // frame.
1137
  void SetException(Object exception);
1138 1139 1140 1141 1142 1143 1144 1145 1146

 protected:
  inline explicit JavaScriptBuiltinContinuationWithCatchFrame(
      StackFrameIteratorBase* iterator);

 private:
  friend class StackFrameIteratorBase;
};

1147
class StackFrameIteratorBase {
1148
 public:
1149 1150
  Isolate* isolate() const { return isolate_; }

1151
  bool done() const { return frame_ == nullptr; }
1152

1153 1154 1155
 protected:
  // An iterator that iterates over a given thread's stack.
  StackFrameIteratorBase(Isolate* isolate, bool can_access_heap_objects);
1156

1157
  Isolate* isolate_;
1158 1159 1160 1161 1162
#define DECLARE_SINGLETON(ignore, type) type type##_;
  STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON)
#undef DECLARE_SINGLETON
  StackFrame* frame_;
  StackHandler* handler_;
1163
  const bool can_access_heap_objects_;
1164 1165

  StackHandler* handler() const {
1166
    DCHECK(!done());
1167 1168 1169 1170 1171
    return handler_;
  }

  // Get the type-specific frame singleton in a given state.
  StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state);
1172
  // A helper function, can return a nullptr pointer.
1173 1174
  StackFrame* SingletonFor(StackFrame::Type type);

1175
 private:
1176
  friend class StackFrame;
1177 1178 1179
  DISALLOW_COPY_AND_ASSIGN(StackFrameIteratorBase);
};

1180
class StackFrameIterator : public StackFrameIteratorBase {
1181 1182
 public:
  // An iterator that iterates over the isolate's current thread's stack,
1183
  V8_EXPORT_PRIVATE explicit StackFrameIterator(Isolate* isolate);
1184
  // An iterator that iterates over a given thread's stack.
1185
  V8_EXPORT_PRIVATE StackFrameIterator(Isolate* isolate, ThreadLocalTop* t);
1186 1187

  StackFrame* frame() const {
1188
    DCHECK(!done());
1189 1190
    return frame_;
  }
1191
  V8_EXPORT_PRIVATE void Advance();
1192 1193 1194 1195 1196

 private:
  // Go back to the first frame.
  void Reset(ThreadLocalTop* top);

1197
  DISALLOW_COPY_AND_ASSIGN(StackFrameIterator);
1198 1199 1200
};

// Iterator that supports iterating through all JavaScript frames.
1201
class JavaScriptFrameIterator {
1202
 public:
1203 1204
  inline explicit JavaScriptFrameIterator(Isolate* isolate);
  inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top);
1205

1206 1207 1208
  inline JavaScriptFrame* frame() const;

  bool done() const { return iterator_.done(); }
1209
  V8_EXPORT_PRIVATE void Advance();
1210
  void AdvanceOneFrame() { iterator_.Advance(); }
1211

1212
 private:
1213
  StackFrameIterator iterator_;
1214 1215
};

1216
// NOTE: The stack trace frame iterator is an iterator that only traverse proper
1217 1218
// JavaScript frames that have proper JavaScript functions and WebAssembly
// frames.
1219
class V8_EXPORT_PRIVATE StackTraceFrameIterator {
1220
 public:
1221
  explicit StackTraceFrameIterator(Isolate* isolate);
1222
  // Skip frames until the frame with the given id is reached.
1223
  StackTraceFrameIterator(Isolate* isolate, StackFrameId id);
1224
  bool done() const { return iterator_.done(); }
1225
  void Advance();
1226
  void AdvanceOneFrame() { iterator_.Advance(); }
1227

1228 1229 1230 1231 1232 1233
  inline StandardFrame* frame() const;

  inline bool is_javascript() const;
  inline bool is_wasm() const;
  inline JavaScriptFrame* javascript_frame() const;

1234
 private:
1235 1236
  StackFrameIterator iterator_;
  bool IsValidFrame(StackFrame* frame) const;
1237 1238
};

1239
class SafeStackFrameIterator : public StackFrameIteratorBase {
1240
 public:
1241 1242
  SafeStackFrameIterator(Isolate* isolate, Address pc, Address fp, Address sp,
                         Address lr, Address js_entry_sp);
1243

1244
  inline StackFrame* frame() const;
1245 1246
  void Advance();

1247
  StackFrame::Type top_frame_type() const { return top_frame_type_; }
1248
  Address top_context_address() const { return top_context_address_; }
1249

1250
 private:
1251 1252
  void AdvanceOneFrame();

1253
  bool IsValidStackAddress(Address addr) const {
1254
    return low_bound_ <= addr && addr <= high_bound_;
1255
  }
1256 1257
  bool IsValidFrame(StackFrame* frame) const;
  bool IsValidCaller(StackFrame* frame);
1258 1259
  bool IsValidExitFrame(Address fp) const;
  bool IsValidTop(ThreadLocalTop* top) const;
1260

1261 1262 1263 1264 1265 1266 1267 1268
  // Returns true if the pc points to a bytecode handler and the frame pointer
  // doesn't seem to be a bytecode handler's frame, which implies that the
  // bytecode handler has an elided frame. This is not precise and might give
  // false negatives since it relies on checks to the frame's type marker,
  // which might be uninitialized.
  bool IsNoFrameBytecodeHandlerPc(Isolate* isolate, Address pc,
                                  Address fp) const;

1269 1270
  const Address low_bound_;
  const Address high_bound_;
1271
  StackFrame::Type top_frame_type_;
1272
  Address top_context_address_;
1273
  ExternalCallbackScope* external_callback_scope_;
1274
  Address top_link_register_;
1275
};
1276 1277 1278 1279 1280 1281 1282 1283

// Frame layout helper classes. Used by the deoptimizer and instruction
// selector.
// -------------------------------------------------------------------------

// How to calculate the frame layout information. Precise, when all information
// is available during deoptimization. Conservative, when an overapproximation
// is fine.
1284 1285 1286 1287 1288 1289 1290
// TODO(jgruber): Investigate whether the conservative kind can be removed. It
// seems possible: 1. is_topmost should be known through the outer_state chain
// of FrameStateDescriptor; 2. the deopt_kind may be a property of the bailout
// id; 3. for continuation_mode, we only care whether it is a mode with catch,
// and that is likewise known at compile-time.
// There is nothing specific blocking this, the investigation just requires time
// and it is not that important to get the exact frame height at compile-time.
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
enum class FrameInfoKind {
  kPrecise,
  kConservative,
};

// Used by the deoptimizer. Corresponds to frame kinds:
enum class BuiltinContinuationMode {
  STUB,                        // BuiltinContinuationFrame
  JAVASCRIPT,                  // JavaScriptBuiltinContinuationFrame
  JAVASCRIPT_WITH_CATCH,       // JavaScriptBuiltinContinuationWithCatchFrame
  JAVASCRIPT_HANDLE_EXCEPTION  // JavaScriptBuiltinContinuationWithCatchFrame
};

class InterpretedFrameInfo {
 public:
  static InterpretedFrameInfo Precise(int parameters_count_with_receiver,
                                      int translation_height, bool is_topmost) {
    return {parameters_count_with_receiver, translation_height, is_topmost,
            FrameInfoKind::kPrecise};
  }

1312 1313 1314 1315 1316 1317
  static InterpretedFrameInfo Conservative(int parameters_count_with_receiver,
                                           int locals_count) {
    return {parameters_count_with_receiver, locals_count, false,
            FrameInfoKind::kConservative};
  }

1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
  uint32_t register_stack_slot_count() const {
    return register_stack_slot_count_;
  }
  uint32_t frame_size_in_bytes_without_fixed() const {
    return frame_size_in_bytes_without_fixed_;
  }
  uint32_t frame_size_in_bytes() const { return frame_size_in_bytes_; }

 private:
  InterpretedFrameInfo(int parameters_count_with_receiver,
                       int translation_height, bool is_topmost,
                       FrameInfoKind frame_info_kind);

  uint32_t register_stack_slot_count_;
  uint32_t frame_size_in_bytes_without_fixed_;
  uint32_t frame_size_in_bytes_;
};

class ArgumentsAdaptorFrameInfo {
 public:
  static ArgumentsAdaptorFrameInfo Precise(int translation_height) {
    return ArgumentsAdaptorFrameInfo{translation_height};
  }

1342 1343 1344 1345
  static ArgumentsAdaptorFrameInfo Conservative(int parameters_count) {
    return ArgumentsAdaptorFrameInfo{parameters_count};
  }

1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
  uint32_t frame_size_in_bytes_without_fixed() const {
    return frame_size_in_bytes_without_fixed_;
  }
  uint32_t frame_size_in_bytes() const { return frame_size_in_bytes_; }

 private:
  explicit ArgumentsAdaptorFrameInfo(int translation_height);

  uint32_t frame_size_in_bytes_without_fixed_;
  uint32_t frame_size_in_bytes_;
};

class ConstructStubFrameInfo {
 public:
  static ConstructStubFrameInfo Precise(int translation_height,
                                        bool is_topmost) {
    return {translation_height, is_topmost, FrameInfoKind::kPrecise};
  }

1365 1366 1367 1368
  static ConstructStubFrameInfo Conservative(int parameters_count) {
    return {parameters_count, false, FrameInfoKind::kConservative};
  }

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
  uint32_t frame_size_in_bytes_without_fixed() const {
    return frame_size_in_bytes_without_fixed_;
  }
  uint32_t frame_size_in_bytes() const { return frame_size_in_bytes_; }

 private:
  ConstructStubFrameInfo(int translation_height, bool is_topmost,
                         FrameInfoKind frame_info_kind);

  uint32_t frame_size_in_bytes_without_fixed_;
  uint32_t frame_size_in_bytes_;
};

// Used by BuiltinContinuationFrameInfo.
class CallInterfaceDescriptor;
class RegisterConfiguration;

class BuiltinContinuationFrameInfo {
 public:
  static BuiltinContinuationFrameInfo Precise(
      int translation_height,
      const CallInterfaceDescriptor& continuation_descriptor,
      const RegisterConfiguration* register_config, bool is_topmost,
      DeoptimizeKind deopt_kind, BuiltinContinuationMode continuation_mode) {
    return {translation_height,
            continuation_descriptor,
            register_config,
            is_topmost,
            deopt_kind,
            continuation_mode,
            FrameInfoKind::kPrecise};
  }

1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
  static BuiltinContinuationFrameInfo Conservative(
      int parameters_count,
      const CallInterfaceDescriptor& continuation_descriptor,
      const RegisterConfiguration* register_config) {
    // It doesn't matter what we pass as is_topmost, deopt_kind and
    // continuation_mode; these values are ignored in conservative mode.
    return {parameters_count,
            continuation_descriptor,
            register_config,
            false,
            DeoptimizeKind::kEager,
            BuiltinContinuationMode::STUB,
            FrameInfoKind::kConservative};
  }

1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
  bool frame_has_result_stack_slot() const {
    return frame_has_result_stack_slot_;
  }
  uint32_t translated_stack_parameter_count() const {
    return translated_stack_parameter_count_;
  }
  uint32_t stack_parameter_count() const { return stack_parameter_count_; }
  uint32_t frame_size_in_bytes() const { return frame_size_in_bytes_; }
  uint32_t frame_size_in_bytes_above_fp() const {
    return frame_size_in_bytes_above_fp_;
  }

 private:
  BuiltinContinuationFrameInfo(
      int translation_height,
      const CallInterfaceDescriptor& continuation_descriptor,
      const RegisterConfiguration* register_config, bool is_topmost,
      DeoptimizeKind deopt_kind, BuiltinContinuationMode continuation_mode,
      FrameInfoKind frame_info_kind);

  bool frame_has_result_stack_slot_;
  uint32_t translated_stack_parameter_count_;
  uint32_t stack_parameter_count_;
  uint32_t frame_size_in_bytes_;
  uint32_t frame_size_in_bytes_above_fp_;
};

1444 1445
}  // namespace internal
}  // namespace v8
1446

1447
#endif  // V8_EXECUTION_FRAMES_H_