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
8
#include "
src/base/export-template.h
"
9
#include "
src/base/vector.h
"
10
#include "
src/codegen/source-position.h
"
11
#include "
src/common/assert-scope.h
"
12
#include "
src/common/checks.h
"
13
#include "
src/common/globals.h
"
14
#include "
src/zone/zone-containers.h
"
15
16
namespace
v8
{
17
namespace
internal
{
18
19
class
TrustedByteArray
;
20
class
Zone
;
21
22
struct
PositionTableEntry
{
23
PositionTableEntry
()
24
:
source_position
(0),
25
code_offset
(
kFunctionEntryBytecodeOffset
),
26
is_statement
(false) {}
27
PositionTableEntry
(
int
offset
, int64_t source,
bool
statement
)
28
:
source_position
(source),
code_offset
(
offset
),
is_statement
(
statement
) {}
29
30
int64_t
source_position
;
31
int
code_offset
;
32
bool
is_statement
;
33
};
34
35
class
V8_EXPORT_PRIVATE
SourcePositionTableBuilder
{
36
public
:
37
enum
RecordingMode
{
38
// Indicates that source positions are never to be generated. (Resulting in
39
// an empty table).
40
OMIT_SOURCE_POSITIONS
,
41
// Indicates that source positions are not currently required, but may be
42
// generated later.
43
LAZY_SOURCE_POSITIONS
,
44
// Indicates that source positions should be immediately generated.
45
RECORD_SOURCE_POSITIONS
46
};
47
48
explicit
SourcePositionTableBuilder
(
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>
55
EXPORT_TEMPLATE_DECLARE
(
V8_EXPORT_PRIVATE
)
56
Handle<TrustedByteArray>
ToSourcePositionTable(IsolateT* isolate);
57
base::OwnedVector<uint8_t>
ToSourcePositionTableVector
();
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
65
RecordingMode
mode_
;
66
ZoneVector<uint8_t>
bytes_
;
67
#ifdef ENABLE_SLOW_DCHECKS
68
ZoneVector<PositionTableEntry>
raw_entries_;
69
#endif
70
PositionTableEntry
previous_
;
// Previously written entry, to compute delta.
71
};
72
73
class
V8_EXPORT_PRIVATE
SourcePositionTableIterator
{
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.
81
enum
FunctionEntryFilter
{
82
kSkipFunctionEntry = 0,
83
kDontSkipFunctionEntry = 1
84
};
85
86
// Used for saving/restoring the iterator.
87
struct
IndexAndPositionState
{
88
int
index_
;
89
PositionTableEntry
position_
;
90
IterationFilter
iteration_filter_
;
91
FunctionEntryFilter
function_entry_filter_
;
92
};
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.
99
explicit
SourcePositionTableIterator
(
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.
107
explicit
SourcePositionTableIterator
(
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.
114
explicit
SourcePositionTableIterator
(
115
base::Vector<const uint8_t>
bytes,
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
}
125
SourcePosition
source_position
()
const
{
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
135
IndexAndPositionState
GetState
()
const
{
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
153
base::Vector<const uint8_t>
raw_table_
;
154
Handle<TrustedByteArray>
table_
;
155
int
index_
= 0;
156
PositionTableEntry
current_
;
157
IterationFilter
iteration_filter_
;
158
FunctionEntryFilter
function_entry_filter_
;
159
DISALLOW_GARBAGE_COLLECTION
(no_gc)
160
};
161
162
}
// namespace internal
163
}
// namespace v8
164
165
#endif
// V8_CODEGEN_SOURCE_POSITION_TABLE_H_
Zone
friend Zone
Definition
asm-types.cc:195
assert-scope.h
DISALLOW_GARBAGE_COLLECTION
#define DISALLOW_GARBAGE_COLLECTION(name)
Definition
assert-scope.h:262
checks.h
v8::base::OwnedVector
Definition
vector.h:209
v8::base::Vector
Definition
zone-list.h:15
v8::internal::Handle
Definition
handles.h:149
v8::internal::SourcePositionTableBuilder
Definition
source-position-table.h:35
v8::internal::SourcePositionTableBuilder::Lazy
bool Lazy() const
Definition
source-position-table.h:60
v8::internal::SourcePositionTableBuilder::previous_
PositionTableEntry previous_
Definition
source-position-table.h:70
v8::internal::SourcePositionTableBuilder::mode_
RecordingMode mode_
Definition
source-position-table.h:65
v8::internal::SourcePositionTableBuilder::ToSourcePositionTableVector
base::OwnedVector< uint8_t > ToSourcePositionTableVector()
v8::internal::SourcePositionTableBuilder::bytes_
ZoneVector< uint8_t > bytes_
Definition
source-position-table.h:66
v8::internal::SourcePositionTableBuilder::Omit
bool Omit() const
Definition
source-position-table.h:59
v8::internal::SourcePositionTableBuilder::RecordingMode
RecordingMode
Definition
source-position-table.h:37
v8::internal::SourcePositionTableBuilder::LAZY_SOURCE_POSITIONS
@ LAZY_SOURCE_POSITIONS
Definition
source-position-table.h:43
v8::internal::SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS
@ OMIT_SOURCE_POSITIONS
Definition
source-position-table.h:40
v8::internal::SourcePositionTableIterator
Definition
source-position-table.h:73
v8::internal::SourcePositionTableIterator::function_entry_filter_
FunctionEntryFilter function_entry_filter_
Definition
source-position-table.h:158
v8::internal::SourcePositionTableIterator::done
bool done() const
Definition
source-position-table.h:133
v8::internal::SourcePositionTableIterator::is_statement
bool is_statement() const
Definition
source-position-table.h:129
v8::internal::SourcePositionTableIterator::RestoreState
void RestoreState(const IndexAndPositionState &saved_state)
Definition
source-position-table.h:139
v8::internal::SourcePositionTableIterator::current_
PositionTableEntry current_
Definition
source-position-table.h:156
v8::internal::SourcePositionTableIterator::table_
Handle< TrustedByteArray > table_
Definition
source-position-table.h:154
v8::internal::SourcePositionTableIterator::IterationFilter
IterationFilter
Definition
source-position-table.h:77
v8::internal::SourcePositionTableIterator::raw_table_
base::Vector< const uint8_t > raw_table_
Definition
source-position-table.h:153
v8::internal::SourcePositionTableIterator::FunctionEntryFilter
FunctionEntryFilter
Definition
source-position-table.h:81
v8::internal::SourcePositionTableIterator::source_position
SourcePosition source_position() const
Definition
source-position-table.h:125
v8::internal::SourcePositionTableIterator::GetState
IndexAndPositionState GetState() const
Definition
source-position-table.h:135
v8::internal::SourcePositionTableIterator::iteration_filter_
IterationFilter iteration_filter_
Definition
source-position-table.h:157
v8::internal::SourcePositionTableIterator::code_offset
int code_offset() const
Definition
source-position-table.h:121
v8::internal::SourcePosition
Definition
source-position.h:45
v8::internal::Tagged
Definition
waiter-queue-node.h:21
v8::internal::ZoneVector
Definition
zone-containers.h:53
v8::internal::Zone
Definition
zone.h:43
mode_
RecordWriteMode const mode_
Definition
code-generator-arm.cc:224
index_
Register const index_
Definition
code-generator-mips64.cc:188
globals.h
export-template.h
EXPORT_TEMPLATE_DECLARE
#define EXPORT_TEMPLATE_DECLARE(export)
Definition
export-template.h:61
offset
int32_t offset
Definition
instruction-selector-ia32.cc:67
v8::internal::kFunctionEntryBytecodeOffset
constexpr int kFunctionEntryBytecodeOffset
Definition
globals.h:854
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8::internal::TrustedByteArray
TrustedByteArray
Definition
js-regexp-inl.h:121
v8
Definition
api-arguments-inl.h:19
current_
base::uc32 current_
Definition
regexp-parser.cc:641
source-position.h
DCHECK
#define DCHECK(condition)
Definition
logging.h:482
V8_EXPORT_PRIVATE
#define V8_EXPORT_PRIVATE
Definition
macros.h:460
v8::internal::PositionTableEntry
Definition
source-position-table.h:22
v8::internal::PositionTableEntry::source_position
int64_t source_position
Definition
source-position-table.h:30
v8::internal::PositionTableEntry::PositionTableEntry
PositionTableEntry(int offset, int64_t source, bool statement)
Definition
source-position-table.h:27
v8::internal::PositionTableEntry::is_statement
bool is_statement
Definition
source-position-table.h:32
v8::internal::PositionTableEntry::code_offset
int code_offset
Definition
source-position-table.h:31
v8::internal::PositionTableEntry::PositionTableEntry
PositionTableEntry()
Definition
source-position-table.h:23
v8::internal::SourcePositionTableIterator::IndexAndPositionState
Definition
source-position-table.h:87
v8::internal::SourcePositionTableIterator::IndexAndPositionState::position_
PositionTableEntry position_
Definition
source-position-table.h:89
v8::internal::SourcePositionTableIterator::IndexAndPositionState::iteration_filter_
IterationFilter iteration_filter_
Definition
source-position-table.h:90
v8::internal::SourcePositionTableIterator::IndexAndPositionState::function_entry_filter_
FunctionEntryFilter function_entry_filter_
Definition
source-position-table.h:91
v8::internal::SourcePositionTableIterator::IndexAndPositionState::index_
int index_
Definition
source-position-table.h:88
statement
Symbol statement
Definition
torque-parser.cc:2801
vector.h
zone-containers.h
src
codegen
source-position-table.h
Generated on Sun Apr 6 2025 21:08:51 for v8 by
1.12.0