v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
source-position-table.h
Go to the documentation of this file.
1// Copyright 2016 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_CODEGEN_SOURCE_POSITION_TABLE_H_
6#define V8_CODEGEN_SOURCE_POSITION_TABLE_H_
7
9#include "src/base/vector.h"
12#include "src/common/checks.h"
13#include "src/common/globals.h"
15
16namespace v8 {
17namespace internal {
18
20class Zone;
21
34
36 public:
38 // Indicates that source positions are never to be generated. (Resulting in
39 // an empty table).
41 // Indicates that source positions are not currently required, but may be
42 // generated later.
44 // Indicates that source positions should be immediately generated.
45 RECORD_SOURCE_POSITIONS
46 };
47
49 Zone* zone, RecordingMode mode = RECORD_SOURCE_POSITIONS);
50
51 void AddPosition(size_t code_offset, SourcePosition source_position,
52 bool is_statement);
53
54 template <typename IsolateT>
56 Handle<TrustedByteArray> ToSourcePositionTable(IsolateT* isolate);
58
59 inline bool Omit() const { return mode_ != RECORD_SOURCE_POSITIONS; }
60 inline bool Lazy() const { return mode_ == LAZY_SOURCE_POSITIONS; }
61
62 private:
63 void AddEntry(const PositionTableEntry& entry);
64
67#ifdef ENABLE_SLOW_DCHECKS
69#endif
70 PositionTableEntry previous_; // Previously written entry, to compute delta.
71};
72
74 public:
75 // Filter that applies when advancing the iterator. If the filter isn't
76 // satisfied, we advance the iterator again.
77 enum IterationFilter { kJavaScriptOnly = 0, kExternalOnly = 1, kAll = 2 };
78 // Filter that applies only to the first entry of the source position table.
79 // If it is kSkipFunctionEntry, it will skip the FunctionEntry entry if it
80 // exists.
82 kSkipFunctionEntry = 0,
83 kDontSkipFunctionEntry = 1
84 };
85
86 // Used for saving/restoring the iterator.
93
94 // We expose three flavours of the iterator, depending on the argument passed
95 // to the constructor:
96
97 // Handlified iterator allows allocation, but it needs a handle (and thus
98 // a handle scope). This is the preferred version.
100 Handle<TrustedByteArray> byte_array,
101 IterationFilter iteration_filter = kJavaScriptOnly,
102 FunctionEntryFilter function_entry_filter = kSkipFunctionEntry);
103
104 // Non-handlified iterator does not need a handle scope, but it disallows
105 // allocation during its lifetime. This is useful if there is no handle
106 // scope around.
108 Tagged<TrustedByteArray> byte_array,
109 IterationFilter iteration_filter = kJavaScriptOnly,
110 FunctionEntryFilter function_entry_filter = kSkipFunctionEntry);
111
112 // Handle-safe iterator based on an a vector located outside the garbage
113 // collected heap, allows allocation during its lifetime.
116 IterationFilter iteration_filter = kJavaScriptOnly,
117 FunctionEntryFilter function_entry_filter = kSkipFunctionEntry);
118
119 void Advance();
120
121 int code_offset() const {
122 DCHECK(!done());
123 return current_.code_offset;
124 }
126 DCHECK(!done());
127 return SourcePosition::FromRaw(current_.source_position);
128 }
129 bool is_statement() const {
130 DCHECK(!done());
131 return current_.is_statement;
132 }
133 bool done() const { return index_ == kDone; }
134
136 return {index_, current_, iteration_filter_, function_entry_filter_};
137 }
138
139 void RestoreState(const IndexAndPositionState& saved_state) {
140 index_ = saved_state.index_;
141 current_ = saved_state.position_;
142 iteration_filter_ = saved_state.iteration_filter_;
143 function_entry_filter_ = saved_state.function_entry_filter_;
144 }
145
146 private:
147 // Initializes the source position interator with the first valid bytecode.
148 // Also sets the FunctionEntry SourcePosition if it exists.
149 void Initialize();
150
151 static const int kDone = -1;
152
155 int index_ = 0;
160};
161
162} // namespace internal
163} // namespace v8
164
165#endif // V8_CODEGEN_SOURCE_POSITION_TABLE_H_
friend Zone
Definition asm-types.cc:195
#define DISALLOW_GARBAGE_COLLECTION(name)
base::OwnedVector< uint8_t > ToSourcePositionTableVector()
void RestoreState(const IndexAndPositionState &saved_state)
RecordWriteMode const mode_
Register const index_
#define EXPORT_TEMPLATE_DECLARE(export)
int32_t offset
constexpr int kFunctionEntryBytecodeOffset
Definition globals.h:854
base::uc32 current_
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460
PositionTableEntry(int offset, int64_t source, bool statement)
Symbol statement