Skip to content

Commit a5c0bc4

Browse files
psmarshalltargos
authored andcommitted
deps: backport 4 CPU profiler commits from upstream V8
[cpu-profiler] Add a new profiling mode with a more detailed call tree. https://chromium.googlesource.com/v8/v8.git/+/ecae80cdb350dde1e654c531b56f5b6c44dc8c77 [cpu-profiler] Reuse free slots in code_entries_ https://chromium.googlesource.com/v8/v8.git/+/3e1126bf15e62c433c4e9cb21316d182f691c63a [cpu-profiler] Only store deopt inline frames for functions that need it https://chromium.googlesource.com/v8/v8.git/+/0bfcbdd4726920755e51dab28c18ab93e050819b [cpu-profiler] Use instruction start as the key for the CodeMap https://chromium.googlesource.com/v8/v8.git/+/ba752ea4c50713dff1e94f45a79db3ba968a8d66 PR-URL: #22028 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
1 parent 7a70dce commit a5c0bc4

21 files changed

+469
-204
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Reset this number to 0 on major V8 upgrades.
3131
# Increment by one for each non-official patch applied to deps/v8.
32-
'v8_embedder_string': '-node.22',
32+
'v8_embedder_string': '-node.23',
3333

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/include/v8-profiler.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ class V8_EXPORT CpuProfile {
273273
void Delete();
274274
};
275275

276+
enum CpuProfilingMode {
277+
// In the resulting CpuProfile tree, intermediate nodes in a stack trace
278+
// (from the root to a leaf) will have line numbers that point to the start
279+
// line of the function, rather than the line of the callsite of the child.
280+
kLeafNodeLineNumbers,
281+
// In the resulting CpuProfile tree, nodes are separated based on the line
282+
// number of their callsite in their parent.
283+
kCallerLineNumbers,
284+
};
285+
276286
/**
277287
* Interface for controlling CPU profiling. Instance of the
278288
* profiler can be created using v8::CpuProfiler::New method.
@@ -316,6 +326,13 @@ class V8_EXPORT CpuProfiler {
316326
* |record_samples| parameter controls whether individual samples should
317327
* be recorded in addition to the aggregated tree.
318328
*/
329+
void StartProfiling(Local<String> title, CpuProfilingMode mode,
330+
bool record_samples = false);
331+
/**
332+
* The same as StartProfiling above, but the CpuProfilingMode defaults to
333+
* kLeafNodeLineNumbers mode, which was the previous default behavior of the
334+
* profiler.
335+
*/
319336
void StartProfiling(Local<String> title, bool record_samples = false);
320337

321338
/**

deps/v8/src/api.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10005,7 +10005,7 @@ const char* CpuProfileNode::GetScriptResourceNameStr() const {
1000510005
}
1000610006

1000710007
int CpuProfileNode::GetLineNumber() const {
10008-
return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
10008+
return reinterpret_cast<const i::ProfileNode*>(this)->line_number();
1000910009
}
1001010010

1001110011

@@ -10143,9 +10143,14 @@ void CpuProfiler::CollectSample() {
1014310143

1014410144
void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
1014510145
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
10146-
*Utils::OpenHandle(*title), record_samples);
10146+
*Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
1014710147
}
1014810148

10149+
void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
10150+
bool record_samples) {
10151+
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
10152+
*Utils::OpenHandle(*title), record_samples, mode);
10153+
}
1014910154

1015010155
CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
1015110156
return reinterpret_cast<CpuProfile*>(

deps/v8/src/code-events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CodeEventListener {
8383
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
8484
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
8585
virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
86-
virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
86+
virtual void CodeMoveEvent(AbstractCode* from, AbstractCode* to) = 0;
8787
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
8888
virtual void CodeMovingGCEvent() = 0;
8989
virtual void CodeDisableOptEvent(AbstractCode* code,
@@ -155,7 +155,7 @@ class CodeEventDispatcher {
155155
void RegExpCodeCreateEvent(AbstractCode* code, String* source) {
156156
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
157157
}
158-
void CodeMoveEvent(AbstractCode* from, Address to) {
158+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
159159
CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
160160
}
161161
void SharedFunctionInfoMoveEvent(Address from, Address to) {

deps/v8/src/heap/mark-compact.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ class ProfilingMigrationObserver final : public MigrationObserver {
11361136
int size) final {
11371137
if (dest == CODE_SPACE || (dest == OLD_SPACE && dst->IsBytecodeArray())) {
11381138
PROFILE(heap_->isolate(),
1139-
CodeMoveEvent(AbstractCode::cast(src), dst->address()));
1139+
CodeMoveEvent(AbstractCode::cast(src), AbstractCode::cast(dst)));
11401140
}
11411141
heap_->OnMoveEvent(dst, src, size);
11421142
}

deps/v8/src/log.cc

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class PerfBasicLogger : public CodeEventLogger {
270270
PerfBasicLogger();
271271
~PerfBasicLogger() override;
272272

273-
void CodeMoveEvent(AbstractCode* from, Address to) override {}
273+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
274274
void CodeDisableOptEvent(AbstractCode* code,
275275
SharedFunctionInfo* shared) override {}
276276

@@ -492,7 +492,7 @@ class LowLevelLogger : public CodeEventLogger {
492492
explicit LowLevelLogger(const char* file_name);
493493
~LowLevelLogger() override;
494494

495-
void CodeMoveEvent(AbstractCode* from, Address to) override;
495+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
496496
void CodeDisableOptEvent(AbstractCode* code,
497497
SharedFunctionInfo* shared) override {}
498498
void SnapshotPositionEvent(HeapObject* obj, int pos);
@@ -610,11 +610,10 @@ void LowLevelLogger::LogRecordedBuffer(const wasm::WasmCode* code,
610610
code->instructions().length());
611611
}
612612

613-
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) {
613+
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
614614
CodeMoveStruct event;
615615
event.from_address = from->InstructionStart();
616-
size_t header_size = from->InstructionStart() - from->address();
617-
event.to_address = to + header_size;
616+
event.to_address = to->InstructionStart();
618617
LogWriteStruct(event);
619618
}
620619

@@ -636,7 +635,7 @@ class JitLogger : public CodeEventLogger {
636635
public:
637636
explicit JitLogger(JitCodeEventHandler code_event_handler);
638637

639-
void CodeMoveEvent(AbstractCode* from, Address to) override;
638+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
640639
void CodeDisableOptEvent(AbstractCode* code,
641640
SharedFunctionInfo* shared) override {}
642641
void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset,
@@ -694,7 +693,7 @@ void JitLogger::LogRecordedBuffer(const wasm::WasmCode* code, const char* name,
694693
code_event_handler_(&event);
695694
}
696695

697-
void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
696+
void JitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
698697
base::LockGuard<base::Mutex> guard(&logger_mutex_);
699698

700699
JitCodeEvent event;
@@ -703,12 +702,7 @@ void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
703702
from->IsCode() ? JitCodeEvent::JIT_CODE : JitCodeEvent::BYTE_CODE;
704703
event.code_start = reinterpret_cast<void*>(from->InstructionStart());
705704
event.code_len = from->InstructionSize();
706-
707-
// Calculate the header size.
708-
const size_t header_size = from->InstructionStart() - from->address();
709-
710-
// Calculate the new start address of the instructions.
711-
event.new_code_start = reinterpret_cast<void*>(to + header_size);
705+
event.new_code_start = reinterpret_cast<void*>(to->InstructionStart());
712706

713707
code_event_handler_(&event);
714708
}
@@ -1450,9 +1444,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) {
14501444
msg.WriteToLogFile();
14511445
}
14521446

1453-
void Logger::CodeMoveEvent(AbstractCode* from, Address to) {
1447+
void Logger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
14541448
if (!is_listening_to_code_events()) return;
1455-
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to);
1449+
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(),
1450+
to->address());
14561451
}
14571452

14581453
namespace {

deps/v8/src/log.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Logger : public CodeEventListener {
209209
// Emits a code create event for a RegExp.
210210
void RegExpCodeCreateEvent(AbstractCode* code, String* source);
211211
// Emits a code move event.
212-
void CodeMoveEvent(AbstractCode* from, Address to);
212+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to);
213213
// Emits a code line info record event.
214214
void CodeLinePosInfoRecordEvent(Address code_start,
215215
ByteArray* source_position_table);
@@ -466,7 +466,7 @@ class ExternalCodeEventListener : public CodeEventListener {
466466
void GetterCallbackEvent(Name* name, Address entry_point) override {}
467467
void SetterCallbackEvent(Name* name, Address entry_point) override {}
468468
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
469-
void CodeMoveEvent(AbstractCode* from, Address to) override {}
469+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
470470
void CodeDisableOptEvent(AbstractCode* code,
471471
SharedFunctionInfo* shared) override {}
472472
void CodeMovingGCEvent() override {}

deps/v8/src/perf-jit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
419419
LogWriteBytes(padding_bytes, static_cast<int>(padding_size));
420420
}
421421

422-
void PerfJitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
422+
void PerfJitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
423423
// We may receive a CodeMove event if a BytecodeArray object moves. Otherwise
424424
// code relocation is not supported.
425425
CHECK(from->IsBytecodeArray());

deps/v8/src/perf-jit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PerfJitLogger : public CodeEventLogger {
4141
PerfJitLogger();
4242
virtual ~PerfJitLogger();
4343

44-
void CodeMoveEvent(AbstractCode* from, Address to) override;
44+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
4545
void CodeDisableOptEvent(AbstractCode* code,
4646
SharedFunctionInfo* shared) override {}
4747

@@ -118,7 +118,7 @@ class PerfJitLogger : public CodeEventLogger {
118118
// PerfJitLogger is only implemented on Linux
119119
class PerfJitLogger : public CodeEventLogger {
120120
public:
121-
void CodeMoveEvent(AbstractCode* from, Address to) override {
121+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {
122122
UNIMPLEMENTED();
123123
}
124124

deps/v8/src/profiler/cpu-profiler-inl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,35 @@ namespace v8 {
1616
namespace internal {
1717

1818
void CodeCreateEventRecord::UpdateCodeMap(CodeMap* code_map) {
19-
code_map->AddCode(start, entry, size);
19+
code_map->AddCode(instruction_start, entry, instruction_size);
2020
}
2121

2222

2323
void CodeMoveEventRecord::UpdateCodeMap(CodeMap* code_map) {
24-
code_map->MoveCode(from, to);
24+
code_map->MoveCode(from_instruction_start, to_instruction_start);
2525
}
2626

2727

2828
void CodeDisableOptEventRecord::UpdateCodeMap(CodeMap* code_map) {
29-
CodeEntry* entry = code_map->FindEntry(start);
29+
CodeEntry* entry = code_map->FindEntry(instruction_start);
3030
if (entry != nullptr) {
3131
entry->set_bailout_reason(bailout_reason);
3232
}
3333
}
3434

3535

3636
void CodeDeoptEventRecord::UpdateCodeMap(CodeMap* code_map) {
37-
CodeEntry* entry = code_map->FindEntry(start);
38-
if (entry != nullptr) entry->set_deopt_info(deopt_reason, deopt_id);
37+
CodeEntry* entry = code_map->FindEntry(instruction_start);
38+
if (entry == nullptr) return;
39+
std::vector<CpuProfileDeoptFrame> frames_vector(
40+
deopt_frames, deopt_frames + deopt_frame_count);
41+
entry->set_deopt_info(deopt_reason, deopt_id, std::move(frames_vector));
42+
delete[] deopt_frames;
3943
}
4044

4145

4246
void ReportBuiltinEventRecord::UpdateCodeMap(CodeMap* code_map) {
43-
CodeEntry* entry = code_map->FindEntry(start);
47+
CodeEntry* entry = code_map->FindEntry(instruction_start);
4448
if (!entry) {
4549
// Code objects for builtins should already have been added to the map but
4650
// some of them have been filtered out by CpuProfiler.

0 commit comments

Comments
 (0)