Line data Source code
1 : // Copyright 2017 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_OBJECTS_FRAME_ARRAY_H_
6 : #define V8_OBJECTS_FRAME_ARRAY_H_
7 :
8 : #include "src/objects.h"
9 : #include "src/wasm/wasm-objects.h"
10 :
11 : // Has to be the last include (doesn't have include guards):
12 : #include "src/objects/object-macros.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : template <typename T>
18 : class Handle;
19 :
20 : #define FRAME_ARRAY_FIELD_LIST(V) \
21 : V(WasmInstance, WasmInstanceObject) \
22 : V(WasmFunctionIndex, Smi) \
23 : V(WasmCodeObject, Object) \
24 : V(Receiver, Object) \
25 : V(Function, JSFunction) \
26 : V(Code, AbstractCode) \
27 : V(Offset, Smi) \
28 : V(Flags, Smi) \
29 : V(Parameters, FixedArray)
30 :
31 : // Container object for data collected during simple stack trace captures.
32 : class FrameArray : public FixedArray {
33 : public:
34 : #define DECL_FRAME_ARRAY_ACCESSORS(name, type) \
35 : inline type name(int frame_ix) const; \
36 : inline void Set##name(int frame_ix, type value);
37 : FRAME_ARRAY_FIELD_LIST(DECL_FRAME_ARRAY_ACCESSORS)
38 : #undef DECL_FRAME_ARRAY_ACCESSORS
39 :
40 : inline bool IsWasmFrame(int frame_ix) const;
41 : inline bool IsWasmInterpretedFrame(int frame_ix) const;
42 : inline bool IsAsmJsWasmFrame(int frame_ix) const;
43 : inline bool IsAnyWasmFrame(int frame_ix) const;
44 : inline int FrameCount() const;
45 :
46 : void ShrinkToFit(Isolate* isolate);
47 :
48 : // Flags.
49 : enum Flag {
50 : kIsWasmFrame = 1 << 0,
51 : kIsWasmInterpretedFrame = 1 << 1,
52 : kIsAsmJsWasmFrame = 1 << 2,
53 : kIsStrict = 1 << 3,
54 : kIsConstructor = 1 << 4,
55 : kAsmJsAtNumberConversion = 1 << 5,
56 : kIsAsync = 1 << 6,
57 : kIsPromiseAll = 1 << 7
58 : };
59 :
60 : static Handle<FrameArray> AppendJSFrame(Handle<FrameArray> in,
61 : Handle<Object> receiver,
62 : Handle<JSFunction> function,
63 : Handle<AbstractCode> code, int offset,
64 : int flags,
65 : Handle<FixedArray> parameters);
66 : static Handle<FrameArray> AppendWasmFrame(
67 : Handle<FrameArray> in, Handle<WasmInstanceObject> wasm_instance,
68 : int wasm_function_index, wasm::WasmCode* code, int offset, int flags);
69 :
70 : DECL_CAST(FrameArray)
71 :
72 : private:
73 : // The underlying fixed array embodies a captured stack trace. Frame i
74 : // occupies indices
75 : //
76 : // kFirstIndex + 1 + [i * kElementsPerFrame, (i + 1) * kElementsPerFrame[,
77 : //
78 : // with internal offsets as below:
79 :
80 : static const int kWasmInstanceOffset = 0;
81 : static const int kWasmFunctionIndexOffset = 1;
82 : static const int kWasmCodeObjectOffset = 2;
83 :
84 : static const int kReceiverOffset = 0;
85 : static const int kFunctionOffset = 1;
86 :
87 : static const int kCodeOffset = 2;
88 : static const int kOffsetOffset = 3;
89 :
90 : static const int kFlagsOffset = 4;
91 :
92 : static const int kParametersOffset = 5;
93 :
94 : static const int kElementsPerFrame = 6;
95 :
96 : // Array layout indices.
97 :
98 : static const int kFrameCountIndex = 0;
99 : static const int kFirstIndex = 1;
100 :
101 : static int LengthFor(int frame_count) {
102 7797499 : return kFirstIndex + frame_count * kElementsPerFrame;
103 : }
104 :
105 : static Handle<FrameArray> EnsureSpace(Isolate* isolate,
106 : Handle<FrameArray> array, int length);
107 :
108 : friend class Factory;
109 : OBJECT_CONSTRUCTORS(FrameArray, FixedArray);
110 : };
111 :
112 : } // namespace internal
113 : } // namespace v8
114 :
115 : #include "src/objects/object-macros-undef.h"
116 :
117 : #endif // V8_OBJECTS_FRAME_ARRAY_H_
|