Skip to content

Commit d582015

Browse files
rmcilroyCommit bot
authored andcommitted
[Interpreter] Log source positions for bytecode arrays.
Add support to log source position offsets to the profiler. As part of this change PositionsRecorder is split into two, with the subset needed by log.cc moved into log.h and the remainder kept in assembler.h as AssemblerPositionsRecorder. The interpreter's source position table builder is updated to log positions when the profiler is active. BUG=v8:4766 LOG=N Review URL: https://codereview.chromium.org/1737043002 Cr-Commit-Position: refs/heads/master@{#34416}
1 parent cb028ac commit d582015

17 files changed

Lines changed: 115 additions & 71 deletions

src/arm/assembler-arm.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,9 @@ class Assembler : public AssemblerBase {
13901390
// Emits the address of the code stub's first instruction.
13911391
void emit_code_stub_address(Code* stub);
13921392

1393-
PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1393+
AssemblerPositionsRecorder* positions_recorder() {
1394+
return &positions_recorder_;
1395+
}
13941396

13951397
// Read/patch instructions
13961398
Instr instr_at(int pos) { return *reinterpret_cast<Instr*>(buffer_ + pos); }
@@ -1637,8 +1639,8 @@ class Assembler : public AssemblerBase {
16371639
friend class RelocInfo;
16381640
friend class CodePatcher;
16391641
friend class BlockConstPoolScope;
1640-
PositionsRecorder positions_recorder_;
1641-
friend class PositionsRecorder;
1642+
AssemblerPositionsRecorder positions_recorder_;
1643+
friend class AssemblerPositionsRecorder;
16421644
friend class EnsureSpace;
16431645
};
16441646

src/arm64/assembler-arm64.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,9 @@ class Assembler : public AssemblerBase {
922922
}
923923

924924
// Debugging ----------------------------------------------------------------
925-
PositionsRecorder* positions_recorder() { return &positions_recorder_; }
925+
AssemblerPositionsRecorder* positions_recorder() {
926+
return &positions_recorder_;
927+
}
926928
void RecordComment(const char* msg);
927929

928930
// Record a deoptimization reason that can be used by a log or cpu profiler.
@@ -2135,8 +2137,8 @@ class Assembler : public AssemblerBase {
21352137
void DeleteUnresolvedBranchInfoForLabelTraverse(Label* label);
21362138

21372139
private:
2138-
PositionsRecorder positions_recorder_;
2139-
friend class PositionsRecorder;
2140+
AssemblerPositionsRecorder positions_recorder_;
2141+
friend class AssemblerPositionsRecorder;
21402142
friend class EnsureSpace;
21412143
friend class ConstPool;
21422144
};

src/assembler.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,8 +1648,7 @@ std::ostream& operator<<(std::ostream& os, ExternalReference reference) {
16481648
return os;
16491649
}
16501650

1651-
1652-
void PositionsRecorder::RecordPosition(int pos) {
1651+
void AssemblerPositionsRecorder::RecordPosition(int pos) {
16531652
DCHECK(pos != RelocInfo::kNoPosition);
16541653
DCHECK(pos >= 0);
16551654
state_.current_position = pos;
@@ -1659,8 +1658,7 @@ void PositionsRecorder::RecordPosition(int pos) {
16591658
pos));
16601659
}
16611660

1662-
1663-
void PositionsRecorder::RecordStatementPosition(int pos) {
1661+
void AssemblerPositionsRecorder::RecordStatementPosition(int pos) {
16641662
DCHECK(pos != RelocInfo::kNoPosition);
16651663
DCHECK(pos >= 0);
16661664
state_.current_statement_position = pos;
@@ -1671,8 +1669,7 @@ void PositionsRecorder::RecordStatementPosition(int pos) {
16711669
pos));
16721670
}
16731671

1674-
1675-
bool PositionsRecorder::WriteRecordedPositions() {
1672+
bool AssemblerPositionsRecorder::WriteRecordedPositions() {
16761673
bool written = false;
16771674

16781675
// Write the statement position if it is different from what was written last

src/assembler.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "src/allocation.h"
3939
#include "src/builtins.h"
4040
#include "src/isolate.h"
41+
#include "src/log.h"
4142
#include "src/runtime/runtime.h"
4243

4344
namespace v8 {
@@ -1085,23 +1086,11 @@ struct PositionState {
10851086
int written_statement_position;
10861087
};
10871088

1088-
1089-
class PositionsRecorder BASE_EMBEDDED {
1089+
class AssemblerPositionsRecorder : public PositionsRecorder {
10901090
public:
1091-
explicit PositionsRecorder(Assembler* assembler)
1092-
: assembler_(assembler) {
1093-
jit_handler_data_ = NULL;
1094-
}
1095-
1096-
void AttachJITHandlerData(void* user_data) {
1097-
jit_handler_data_ = user_data;
1098-
}
1091+
explicit AssemblerPositionsRecorder(Assembler* assembler)
1092+
: assembler_(assembler) {}
10991093

1100-
void* DetachJITHandlerData() {
1101-
void* old_data = jit_handler_data_;
1102-
jit_handler_data_ = NULL;
1103-
return old_data;
1104-
}
11051094
// Set current position to pos.
11061095
void RecordPosition(int pos);
11071096

@@ -1121,11 +1110,7 @@ class PositionsRecorder BASE_EMBEDDED {
11211110
Assembler* assembler_;
11221111
PositionState state_;
11231112

1124-
// Currently jit_handler_data_ is used to store JITHandler-specific data
1125-
// over the lifetime of a PositionsRecorder
1126-
void* jit_handler_data_;
1127-
1128-
DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
1113+
DISALLOW_COPY_AND_ASSIGN(AssemblerPositionsRecorder);
11291114
};
11301115

11311116

src/ia32/assembler-ia32.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,9 @@ class Assembler : public AssemblerBase {
14351435

14361436
static bool IsNop(Address addr);
14371437

1438-
PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1438+
AssemblerPositionsRecorder* positions_recorder() {
1439+
return &positions_recorder_;
1440+
}
14391441

14401442
int relocation_writer_size() {
14411443
return (buffer_ + buffer_size_) - reloc_info_writer.pos();
@@ -1542,8 +1544,8 @@ class Assembler : public AssemblerBase {
15421544
// code generation
15431545
RelocInfoWriter reloc_info_writer;
15441546

1545-
PositionsRecorder positions_recorder_;
1546-
friend class PositionsRecorder;
1547+
AssemblerPositionsRecorder positions_recorder_;
1548+
friend class AssemblerPositionsRecorder;
15471549
};
15481550

15491551

src/interpreter/bytecode-array-builder.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone,
9191
return_position_ =
9292
literal ? std::max(literal->start_position(), literal->end_position() - 1)
9393
: RelocInfo::kNoPosition;
94+
LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent(
95+
source_position_table_builder()));
9496
}
9597

9698
BytecodeArrayBuilder::~BytecodeArrayBuilder() { DCHECK_EQ(0, unbound_jumps_); }
@@ -130,13 +132,18 @@ Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() {
130132
Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable();
131133
Handle<ByteArray> source_position_table =
132134
source_position_table_builder()->ToSourcePositionTable();
133-
Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray(
135+
Handle<BytecodeArray> bytecode_array = isolate_->factory()->NewBytecodeArray(
134136
bytecode_size, &bytecodes_.front(), frame_size, parameter_count(),
135137
constant_pool);
136-
output->set_handler_table(*handler_table);
137-
output->set_source_position_table(*source_position_table);
138+
bytecode_array->set_handler_table(*handler_table);
139+
bytecode_array->set_source_position_table(*source_position_table);
140+
141+
void* line_info = source_position_table_builder()->DetachJITHandlerData();
142+
LOG_CODE_EVENT(isolate_, CodeEndLinePosInfoRecordEvent(
143+
AbstractCode::cast(*bytecode_array), line_info));
144+
138145
bytecode_generated_ = true;
139-
return output;
146+
return bytecode_array;
140147
}
141148

142149

src/interpreter/source-position-table.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,20 @@ void DecodeEntry(ByteArray* bytes, int* index, PositionTableEntry* entry) {
117117

118118
void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset,
119119
int source_position) {
120-
AddEntry({static_cast<int>(bytecode_offset), source_position, true});
120+
int offset = static_cast<int>(bytecode_offset);
121+
AddEntry({offset, source_position, true});
122+
LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddStatementPositionEvent(
123+
jit_handler_data_, offset, source_position));
124+
LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent(
125+
jit_handler_data_, offset, source_position));
121126
}
122127

123128
void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset,
124129
int source_position) {
125-
AddEntry({static_cast<int>(bytecode_offset), source_position, false});
130+
int offset = static_cast<int>(bytecode_offset);
131+
AddEntry({offset, source_position, false});
132+
LOG_CODE_EVENT(isolate_, CodeLinePosInfoAddPositionEvent(
133+
jit_handler_data_, offset, source_position));
126134
}
127135

128136
void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) {

src/interpreter/source-position-table.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "src/assert-scope.h"
99
#include "src/checks.h"
1010
#include "src/handles.h"
11+
#include "src/log.h"
1112
#include "src/zone-containers.h"
1213

1314
namespace v8 {
@@ -33,7 +34,7 @@ struct PositionTableEntry {
3334
bool is_statement;
3435
};
3536

36-
class SourcePositionTableBuilder {
37+
class SourcePositionTableBuilder : public PositionsRecorder {
3738
public:
3839
explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone)
3940
: isolate_(isolate),

src/log.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,26 @@ class TimerEventScope {
441441
Isolate* isolate_;
442442
};
443443

444+
class PositionsRecorder BASE_EMBEDDED {
445+
public:
446+
PositionsRecorder() { jit_handler_data_ = NULL; }
447+
448+
void AttachJITHandlerData(void* user_data) { jit_handler_data_ = user_data; }
449+
450+
void* DetachJITHandlerData() {
451+
void* old_data = jit_handler_data_;
452+
jit_handler_data_ = NULL;
453+
return old_data;
454+
}
455+
456+
protected:
457+
// Currently jit_handler_data_ is used to store JITHandler-specific data
458+
// over the lifetime of a PositionsRecorder
459+
void* jit_handler_data_;
460+
461+
private:
462+
DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
463+
};
444464

445465
class CodeEventListener {
446466
public:

src/mips/assembler-mips.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,9 @@ class Assembler : public AssemblerBase {
10481048
void dp(uintptr_t data) { dd(data); }
10491049
void dd(Label* label);
10501050

1051-
PositionsRecorder* positions_recorder() { return &positions_recorder_; }
1051+
AssemblerPositionsRecorder* positions_recorder() {
1052+
return &positions_recorder_;
1053+
}
10521054

10531055
// Postpone the generation of the trampoline pool for the specified number of
10541056
// instructions.
@@ -1441,8 +1443,8 @@ class Assembler : public AssemblerBase {
14411443
friend class CodePatcher;
14421444
friend class BlockTrampolinePoolScope;
14431445

1444-
PositionsRecorder positions_recorder_;
1445-
friend class PositionsRecorder;
1446+
AssemblerPositionsRecorder positions_recorder_;
1447+
friend class AssemblerPositionsRecorder;
14461448
friend class EnsureSpace;
14471449
};
14481450

0 commit comments

Comments
 (0)