Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48f31bd

Browse filesBrowse files
psmarshallBethGriggs
authored andcommitted
deps: V8: backport 20 CPU profiler commits from upstream
[cpu-profiler] Fix bugs and add tests for JITLineInfoTable https://chromium.googlesource.com/v8/v8/+/4feb5ce7fd5ef8c933f3f5dff2eca1173f85c1e9 [cpu-profiler] Fix incorrect line number calculation. https://chromium.googlesource.com/v8/v8/+/ddb2856f39632f9e9f623d3cdb4600e636172031 [cpu-profiler] Use std::unordered_map for hashmaps. https://chromium.googlesource.com/v8/v8/+/35985ce6abc80b85264fe3b87b246fed5f1806e6 [cpu-profiler] Do not store CodeEntries between profiling sessions. https://chromium.googlesource.com/v8/v8.git/+/8ec48b2117b8092c4956f1ee11a0c85bec3ba1f8 [cpu-profiler] Remove name_prefix field from CodeEntry https://chromium.googlesource.com/v8/v8.git/+/6f72af25fe43218b60c68129073ddcddb631566e [cpu-profiler] Extract rare used fields of CodeEntry to an optional object. https://chromium.googlesource.com/v8/v8.git/+/fcc1ebb55aab38013855834f556f6e874e0eb8b3 [profiler] Refactoring: decouple StringsStorage from Heap object. https://chromium.googlesource.com/v8/v8/+/a31320f59c911a277566d6c2fa0b0f2ac83e0748 [cpu-profiler] Add a HandleScope to limit memory consumption. https://chromium.googlesource.com/v8/v8.git/+/3e9f8a4f635e2d946651d6a4df81378266f32dc9 [cpu-profiler] Lazily create CPU profiler. https://chromium.googlesource.com/v8/v8/+/1426ea1d6d45be0b4d9476bdb5bf3f27cfe578a0 [cpu-profiler] turn several std::map's into unordered_map's. https://chromium.googlesource.com/v8/v8/+/3ed5dfb8a3cbc7aa0017bd01c2fdd6227485b8ad [cpu-profiler] Eagerly delete not used CodeEntry'es https://chromium.googlesource.com/v8/v8.git/+/c6c28f7a412a88df12055e953630a9e93cc64d49 [cpu-profiler] Move bailout reason into rare_info struct https://chromium.googlesource.com/v8/v8.git/+/29ea4d1ef5360e71c61ecf8db6a5a0a0c3391fd1 [cpu-profiler] Save space in the SourcePositionTable by using a vector. https://chromium.googlesource.com/v8/v8.git/+/1cb19f0e0a93adbac8c11bc906f951bd8098722d [cpu-profiler] Only store deopt inline frames for functions that need it https://chromium.googlesource.com/v8/v8.git/+/0bfcbdd4726920755e51dab28c18ab93e050819b [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] Use instruction start as the key for the CodeMap https://chromium.googlesource.com/v8/v8.git/+/ba752ea4c50713dff1e94f45a79db3ba968a8d66 [cpu-profiler] Add flag to always generate accurate line info. https://chromium.googlesource.com/v8/v8/+/56baf56790de439b3f69e887e94beb3b301ed77c [cpu-profiler] Turn on detailed line info for optimized code https://chromium.googlesource.com/v8/v8/+/84894ce6d2af7feb9e1f5574409355120887326c [cpu-profiler] Separate the flags for generating extra line information https://chromium.googlesource.com/v8/v8/+/30ff6719db441cc7ef220d449970cc169067e256 Backport-PR-URL: #21558 PR-URL: #21558 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 534bc82 commit 48f31bd
Copy full SHA for 48f31bd
Expand file treeCollapse file tree

29 files changed

+852
-562
lines changed
Open diff view settings
Collapse file

‎deps/v8/include/v8-profiler.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-profiler.h
+17Lines 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.
@@ -309,6 +319,13 @@ class V8_EXPORT CpuProfiler {
309319
* |record_samples| parameter controls whether individual samples should
310320
* be recorded in addition to the aggregated tree.
311321
*/
322+
void StartProfiling(Local<String> title, CpuProfilingMode mode,
323+
bool record_samples = false);
324+
/**
325+
* The same as StartProfiling above, but the CpuProfilingMode defaults to
326+
* kLeafNodeLineNumbers mode, which was the previous default behavior of the
327+
* profiler.
328+
*/
312329
void StartProfiling(Local<String> title, bool record_samples = false);
313330

314331
/**
Collapse file

‎deps/v8/include/v8-version.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-version.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 2
1313
#define V8_BUILD_NUMBER 414
14-
#define V8_PATCH_LEVEL 67
14+
#define V8_PATCH_LEVEL 68
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)
Collapse file

‎deps/v8/src/api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/api.cc
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8418,7 +8418,7 @@ HeapProfiler* Isolate::GetHeapProfiler() {
84188418

84198419
CpuProfiler* Isolate::GetCpuProfiler() {
84208420
i::CpuProfiler* cpu_profiler =
8421-
reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
8421+
reinterpret_cast<i::Isolate*>(this)->EnsureCpuProfiler();
84228422
return reinterpret_cast<CpuProfiler*>(cpu_profiler);
84238423
}
84248424

@@ -10138,15 +10138,7 @@ Local<String> CpuProfileNode::GetFunctionName() const {
1013810138
const i::CodeEntry* entry = node->entry();
1013910139
i::Handle<i::String> name =
1014010140
isolate->factory()->InternalizeUtf8String(entry->name());
10141-
if (!entry->has_name_prefix()) {
10142-
return ToApiHandle<String>(name);
10143-
} else {
10144-
// We do not expect this to fail. Change this if it does.
10145-
i::Handle<i::String> cons = isolate->factory()->NewConsString(
10146-
isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
10147-
name).ToHandleChecked();
10148-
return ToApiHandle<String>(cons);
10149-
}
10141+
return ToApiHandle<String>(name);
1015010142
}
1015110143

1015210144
int debug::Coverage::BlockData::StartOffset() const { return block_->start; }
@@ -10237,7 +10229,7 @@ const char* CpuProfileNode::GetScriptResourceNameStr() const {
1023710229
}
1023810230

1023910231
int CpuProfileNode::GetLineNumber() const {
10240-
return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
10232+
return reinterpret_cast<const i::ProfileNode*>(this)->line_number();
1024110233
}
1024210234

1024310235

@@ -10370,9 +10362,14 @@ void CpuProfiler::CollectSample() {
1037010362

1037110363
void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
1037210364
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
10373-
*Utils::OpenHandle(*title), record_samples);
10365+
*Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
1037410366
}
1037510367

10368+
void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
10369+
bool record_samples) {
10370+
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
10371+
*Utils::OpenHandle(*title), record_samples, mode);
10372+
}
1037610373

1037710374
CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
1037810375
return reinterpret_cast<CpuProfile*>(
Collapse file

‎deps/v8/src/code-events.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/code-events.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CodeEventListener {
101101
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
102102
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
103103
virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
104-
virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
104+
virtual void CodeMoveEvent(AbstractCode* from, AbstractCode* to) = 0;
105105
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
106106
virtual void CodeMovingGCEvent() = 0;
107107
virtual void CodeDisableOptEvent(AbstractCode* code,
@@ -163,7 +163,7 @@ class CodeEventDispatcher {
163163
void RegExpCodeCreateEvent(AbstractCode* code, String* source) {
164164
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
165165
}
166-
void CodeMoveEvent(AbstractCode* from, Address to) {
166+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
167167
CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
168168
}
169169
void SharedFunctionInfoMoveEvent(Address from, Address to) {
Collapse file

‎deps/v8/src/compilation-info.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/compilation-info.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
5151
// Collect source positions for optimized code when profiling or if debugger
5252
// is active, to be able to get more precise source positions at the price of
5353
// more memory consumption.
54-
if (isolate_->NeedsSourcePositionsForProfiling()) {
54+
if (isolate_->NeedsDetailedOptimizedCodeLineInfo()) {
5555
MarkAsSourcePositionsEnabled();
5656
}
5757
}
Collapse file

‎deps/v8/src/flag-definitions.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/flag-definitions.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ DEFINE_BOOL(log_source_code, false, "Log source code.")
10821082
DEFINE_BOOL(prof, false,
10831083
"Log statistical profiling information (implies --log-code).")
10841084

1085+
DEFINE_BOOL(detailed_line_info, true,
1086+
"Always generate detailed line information for CPU profiling.")
1087+
10851088
#if defined(ANDROID)
10861089
// Phones and tablets have processors that are much slower than desktop
10871090
// and laptop computers for which current heuristics are tuned.
Collapse file

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

Copy file name to clipboardExpand all lines: deps/v8/src/heap/mark-compact.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ class ProfilingMigrationObserver final : public MigrationObserver {
14841484
int size) final {
14851485
if (dest == CODE_SPACE || (dest == OLD_SPACE && dst->IsBytecodeArray())) {
14861486
PROFILE(heap_->isolate(),
1487-
CodeMoveEvent(AbstractCode::cast(src), dst->address()));
1487+
CodeMoveEvent(AbstractCode::cast(src), AbstractCode::cast(dst)));
14881488
}
14891489
heap_->OnMoveEvent(dst, src, size);
14901490
}
Collapse file

‎deps/v8/src/isolate.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/isolate.cc
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,6 @@ bool Isolate::Init(StartupDeserializer* des) {
26972697
call_descriptor_data_ =
26982698
new CallInterfaceDescriptorData[CallDescriptors::NUMBER_OF_DESCRIPTORS];
26992699
access_compiler_data_ = new AccessCompilerData();
2700-
cpu_profiler_ = new CpuProfiler(this);
27012700
heap_profiler_ = new HeapProfiler(heap());
27022701
interpreter_ = new interpreter::Interpreter(this);
27032702
compiler_dispatcher_ =
@@ -2970,6 +2969,10 @@ bool Isolate::use_optimizer() {
29702969
!is_precise_count_code_coverage() && !is_block_count_code_coverage();
29712970
}
29722971

2972+
bool Isolate::NeedsDetailedOptimizedCodeLineInfo() const {
2973+
return NeedsSourcePositionsForProfiling() || FLAG_detailed_line_info;
2974+
}
2975+
29732976
bool Isolate::NeedsSourcePositionsForProfiling() const {
29742977
return FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph ||
29752978
FLAG_turbo_profiling || FLAG_perf_prof || is_profiling() ||
@@ -3694,6 +3697,13 @@ void Isolate::PrintWithTimestamp(const char* format, ...) {
36943697
va_end(arguments);
36953698
}
36963699

3700+
CpuProfiler* Isolate::EnsureCpuProfiler() {
3701+
if (!cpu_profiler_) {
3702+
cpu_profiler_ = new CpuProfiler(this);
3703+
}
3704+
return cpu_profiler_;
3705+
}
3706+
36973707
bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
36983708
StackGuard* stack_guard = isolate_->stack_guard();
36993709
#ifdef USE_SIMULATOR
Collapse file

‎deps/v8/src/isolate.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/isolate.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ class Isolate {
10191019

10201020
bool NeedsSourcePositionsForProfiling() const;
10211021

1022+
bool NeedsDetailedOptimizedCodeLineInfo() const;
1023+
10221024
bool is_best_effort_code_coverage() const {
10231025
return code_coverage_mode() == debug::Coverage::kBestEffort;
10241026
}
@@ -1449,7 +1451,7 @@ class Isolate {
14491451

14501452
// TODO(alph): Remove along with the deprecated GetCpuProfiler().
14511453
friend v8::CpuProfiler* v8::Isolate::GetCpuProfiler();
1452-
CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
1454+
CpuProfiler* EnsureCpuProfiler();
14531455

14541456
base::Atomic32 id_;
14551457
EntryStackItem* entry_stack_;
Collapse file

‎deps/v8/src/log.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/log.cc
+11-37Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "src/log-utils.h"
2323
#include "src/macro-assembler.h"
2424
#include "src/perf-jit.h"
25-
#include "src/profiler/profiler-listener.h"
2625
#include "src/profiler/tick-sample.h"
2726
#include "src/runtime-profiler.h"
2827
#include "src/source-position-table.h"
@@ -218,7 +217,7 @@ class PerfBasicLogger : public CodeEventLogger {
218217
PerfBasicLogger();
219218
~PerfBasicLogger() override;
220219

221-
void CodeMoveEvent(AbstractCode* from, Address to) override {}
220+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
222221
void CodeDisableOptEvent(AbstractCode* code,
223222
SharedFunctionInfo* shared) override {}
224223

@@ -287,7 +286,7 @@ class LowLevelLogger : public CodeEventLogger {
287286
explicit LowLevelLogger(const char* file_name);
288287
~LowLevelLogger() override;
289288

290-
void CodeMoveEvent(AbstractCode* from, Address to) override;
289+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
291290
void CodeDisableOptEvent(AbstractCode* code,
292291
SharedFunctionInfo* shared) override {}
293292
void SnapshotPositionEvent(HeapObject* obj, int pos);
@@ -393,11 +392,10 @@ void LowLevelLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*,
393392
code->instruction_size());
394393
}
395394

396-
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) {
395+
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
397396
CodeMoveStruct event;
398397
event.from_address = from->instruction_start();
399-
size_t header_size = from->instruction_start() - from->address();
400-
event.to_address = to + header_size;
398+
event.to_address = to->instruction_start();
401399
LogWriteStruct(event);
402400
}
403401

@@ -419,7 +417,7 @@ class JitLogger : public CodeEventLogger {
419417
public:
420418
explicit JitLogger(JitCodeEventHandler code_event_handler);
421419

422-
void CodeMoveEvent(AbstractCode* from, Address to) override;
420+
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
423421
void CodeDisableOptEvent(AbstractCode* code,
424422
SharedFunctionInfo* shared) override {}
425423
void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset,
@@ -460,19 +458,14 @@ void JitLogger::LogRecordedBuffer(AbstractCode* code,
460458
code_event_handler_(&event);
461459
}
462460

463-
void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
461+
void JitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
464462
base::LockGuard<base::Mutex> guard(&logger_mutex_);
465463

466464
JitCodeEvent event;
467465
event.type = JitCodeEvent::CODE_MOVED;
468-
event.code_start = from->instruction_start();
466+
event.code_start = reinterpret_cast<void*>(from->instruction_start());
469467
event.code_len = from->instruction_size();
470-
471-
// Calculate the header size.
472-
const size_t header_size = from->instruction_start() - from->address();
473-
474-
// Calculate the new start address of the instructions.
475-
event.new_code_start = to + header_size;
468+
event.new_code_start = reinterpret_cast<void*>(to->instruction_start());
476469

477470
code_event_handler_(&event);
478471
}
@@ -739,7 +732,6 @@ Logger::Logger(Isolate* isolate)
739732
perf_jit_logger_(NULL),
740733
ll_logger_(NULL),
741734
jit_logger_(NULL),
742-
listeners_(5),
743735
is_initialized_(false) {}
744736

745737
Logger::~Logger() {
@@ -1297,9 +1289,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) {
12971289
msg.WriteToLogFile();
12981290
}
12991291

1300-
void Logger::CodeMoveEvent(AbstractCode* from, Address to) {
1292+
void Logger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
13011293
if (!is_logging_code_events()) return;
1302-
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to);
1294+
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(),
1295+
to->address());
13031296
}
13041297

13051298
void Logger::CodeLinePosInfoRecordEvent(AbstractCode* code,
@@ -1876,8 +1869,6 @@ bool Logger::SetUp(Isolate* isolate) {
18761869
profiler_->Engage();
18771870
}
18781871

1879-
profiler_listener_.reset();
1880-
18811872
if (is_logging_) {
18821873
addCodeEventListener(this);
18831874
}
@@ -1905,19 +1896,6 @@ void Logger::SetCodeEventHandler(uint32_t options,
19051896
}
19061897
}
19071898

1908-
void Logger::SetUpProfilerListener() {
1909-
if (!is_initialized_) return;
1910-
if (profiler_listener_.get() == nullptr) {
1911-
profiler_listener_.reset(new ProfilerListener(isolate_));
1912-
}
1913-
addCodeEventListener(profiler_listener_.get());
1914-
}
1915-
1916-
void Logger::TearDownProfilerListener() {
1917-
if (profiler_listener_->HasObservers()) return;
1918-
removeCodeEventListener(profiler_listener_.get());
1919-
}
1920-
19211899
sampler::Sampler* Logger::sampler() {
19221900
return ticker_;
19231901
}
@@ -1961,10 +1939,6 @@ FILE* Logger::TearDown() {
19611939
jit_logger_ = NULL;
19621940
}
19631941

1964-
if (profiler_listener_.get() != nullptr) {
1965-
removeCodeEventListener(profiler_listener_.get());
1966-
}
1967-
19681942
return log_->Close();
19691943
}
19701944

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.