frame-array.h 3.46 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_FRAME_ARRAY_H_
#define V8_OBJECTS_FRAME_ARRAY_H_

8
#include "src/objects/objects.h"
9
#include "src/wasm/wasm-objects.h"
10 11 12 13 14 15 16 17 18 19

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

template <typename T>
class Handle;

20 21 22
#define FRAME_ARRAY_FIELD_LIST(V)     \
  V(WasmInstance, WasmInstanceObject) \
  V(WasmFunctionIndex, Smi)           \
23
  V(WasmCodeObject, Object)           \
24 25 26 27
  V(Receiver, Object)                 \
  V(Function, JSFunction)             \
  V(Code, AbstractCode)               \
  V(Offset, Smi)                      \
28 29
  V(Flags, Smi)                       \
  V(Parameters, FixedArray)
30 31

// Container object for data collected during simple stack trace captures.
32
class FrameArray : public FixedArray {
33
 public:
34 35 36
#define DECL_FRAME_ARRAY_ACCESSORS(name, type) \
  inline type name(int frame_ix) const;        \
  inline void Set##name(int frame_ix, type value);
37 38
  FRAME_ARRAY_FIELD_LIST(DECL_FRAME_ARRAY_ACCESSORS)
#undef DECL_FRAME_ARRAY_ACCESSORS
39 40 41

  inline bool IsWasmFrame(int frame_ix) const;
  inline bool IsAsmJsWasmFrame(int frame_ix) const;
42
  inline bool IsAnyWasmFrame(int frame_ix) const;
43 44
  inline int FrameCount() const;

45
  void ShrinkToFit(Isolate* isolate);
46 47 48

  // Flags.
  enum Flag {
49
    kIsWasmFrame = 1 << 0,
50 51 52 53 54
    kIsAsmJsWasmFrame = 1 << 1,
    kIsStrict = 1 << 2,
    kIsConstructor = 1 << 3,
    kAsmJsAtNumberConversion = 1 << 4,
    kIsAsync = 1 << 5,
55 56
    kIsPromiseAll = 1 << 6,
    kIsPromiseAny = 1 << 7
57 58 59 60 61 62
  };

  static Handle<FrameArray> AppendJSFrame(Handle<FrameArray> in,
                                          Handle<Object> receiver,
                                          Handle<JSFunction> function,
                                          Handle<AbstractCode> code, int offset,
63 64
                                          int flags,
                                          Handle<FixedArray> parameters);
65 66
  static Handle<FrameArray> AppendWasmFrame(
      Handle<FrameArray> in, Handle<WasmInstanceObject> wasm_instance,
67
      int wasm_function_index, wasm::WasmCode* code, int offset, int flags);
68

69
  DECL_CAST(FrameArray)
70 71 72 73 74 75 76 77 78 79 80

 private:
  // The underlying fixed array embodies a captured stack trace. Frame i
  // occupies indices
  //
  // kFirstIndex + 1 + [i * kElementsPerFrame, (i + 1) * kElementsPerFrame[,
  //
  // with internal offsets as below:

  static const int kWasmInstanceOffset = 0;
  static const int kWasmFunctionIndexOffset = 1;
81
  static const int kWasmCodeObjectOffset = 2;
82 83 84 85 86 87 88 89 90

  static const int kReceiverOffset = 0;
  static const int kFunctionOffset = 1;

  static const int kCodeOffset = 2;
  static const int kOffsetOffset = 3;

  static const int kFlagsOffset = 4;

91 92 93
  static const int kParametersOffset = 5;

  static const int kElementsPerFrame = 6;
94 95 96 97 98 99 100 101 102 103

  // Array layout indices.

  static const int kFrameCountIndex = 0;
  static const int kFirstIndex = 1;

  static int LengthFor(int frame_count) {
    return kFirstIndex + frame_count * kElementsPerFrame;
  }

104 105
  static Handle<FrameArray> EnsureSpace(Isolate* isolate,
                                        Handle<FrameArray> array, int length);
106 107

  friend class Factory;
108
  OBJECT_CONSTRUCTORS(FrameArray, FixedArray);
109 110 111 112 113 114 115 116
};

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_FRAME_ARRAY_H_