Skip to content

Commit 61179e6

Browse files
hashseedrvagg
authored andcommitted
deps: cherry-pick 073073b from upstream V8
Original commit message: [profiler] introduce API to enable detailed source positions This allows Node.js to enable detailed source positions for optimized code early on, without having to pass a flag string. R=petermarshall@chromium.org Change-Id: Ie74ea41f600cf6e31acbe802116df4976ccf1c75 Reviewed-on: https://chromium-review.googlesource.com/c/1319757 Commit-Queue: Yang Guo <yangguo@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org> Cr-Commit-Position: refs/heads/master@{#57380} Refs: v8/v8@073073b PR-URL: #24515 Refs: #24274 Refs: #24394 Refs: #24393 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Peter Marshall <petermarshall@chromium.org> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 9bf2659 commit 61179e6

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Reset this number to 0 on major V8 upgrades.
3232
# Increment by one for each non-official patch applied to deps/v8.
33-
'v8_embedder_string': '-node.11',
33+
'v8_embedder_string': '-node.12',
3434

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

deps/v8/include/v8-profiler.h

+6
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ class V8_EXPORT CpuProfiler {
341341
V8_DEPRECATED("Use Isolate::SetIdle(bool) instead.",
342342
void SetIdle(bool is_idle));
343343

344+
/**
345+
* Generate more detailed source positions to code objects. This results in
346+
* better results when mapping profiling samples to script source.
347+
*/
348+
static void UseDetailedSourcePositionsForProfiling(Isolate* isolate);
349+
344350
private:
345351
CpuProfiler();
346352
~CpuProfiler();

deps/v8/src/api.cc

+5
Original file line numberDiff line numberDiff line change
@@ -10132,6 +10132,11 @@ void CpuProfiler::SetIdle(bool is_idle) {
1013210132
isolate->SetIdle(is_idle);
1013310133
}
1013410134

10135+
void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
10136+
reinterpret_cast<i::Isolate*>(isolate)
10137+
->set_detailed_source_positions_for_profiling(true);
10138+
}
10139+
1013510140
uintptr_t CodeEvent::GetCodeStartAddress() {
1013610141
return reinterpret_cast<i::CodeEvent*>(this)->code_start_address;
1013710142
}

deps/v8/src/isolate.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,8 @@ bool Isolate::use_optimizer() {
32573257
}
32583258

32593259
bool Isolate::NeedsDetailedOptimizedCodeLineInfo() const {
3260-
return NeedsSourcePositionsForProfiling() || FLAG_detailed_line_info;
3260+
return NeedsSourcePositionsForProfiling() ||
3261+
detailed_source_positions_for_profiling();
32613262
}
32623263

32633264
bool Isolate::NeedsSourcePositionsForProfiling() const {

deps/v8/src/isolate.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ typedef std::vector<HeapObject*> DebugObjectCache;
553553
V(int, last_console_context_id, 0) \
554554
V(v8_inspector::V8Inspector*, inspector, nullptr) \
555555
V(bool, next_v8_call_is_safe_for_termination, false) \
556-
V(bool, only_terminate_in_safe_scope, false)
556+
V(bool, only_terminate_in_safe_scope, false) \
557+
V(bool, detailed_source_positions_for_profiling, FLAG_detailed_line_info)
557558

558559
#define THREAD_LOCAL_TOP_ACCESSOR(type, name) \
559560
inline void set_##name(type v) { thread_local_top_.name##_ = v; } \

deps/v8/test/cctest/test-cpu-profiler.cc

+56
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "src/objects-inl.h"
4141
#include "src/profiler/cpu-profiler-inl.h"
4242
#include "src/profiler/profiler-listener.h"
43+
#include "src/source-position-table.h"
4344
#include "src/utils.h"
4445
#include "test/cctest/cctest.h"
4546
#include "test/cctest/profiler-extension.h"
@@ -2544,6 +2545,61 @@ TEST(MultipleProfilers) {
25442545
profiler2->StopProfiling("2");
25452546
}
25462547

2548+
int GetSourcePositionEntryCount(i::Isolate* isolate, const char* source) {
2549+
i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast(
2550+
v8::Utils::OpenHandle(*CompileRun(source)));
2551+
if (function->IsInterpreted()) return -1;
2552+
i::Handle<i::Code> code(function->code(), isolate);
2553+
i::SourcePositionTableIterator iterator(
2554+
ByteArray::cast(code->source_position_table()));
2555+
int count = 0;
2556+
while (!iterator.done()) {
2557+
count++;
2558+
iterator.Advance();
2559+
}
2560+
return count;
2561+
}
2562+
2563+
UNINITIALIZED_TEST(DetailedSourcePositionAPI) {
2564+
i::FLAG_detailed_line_info = false;
2565+
i::FLAG_allow_natives_syntax = true;
2566+
v8::Isolate::CreateParams create_params;
2567+
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
2568+
v8::Isolate* isolate = v8::Isolate::New(create_params);
2569+
2570+
const char* source =
2571+
"function fib(i) {"
2572+
" if (i <= 1) return 1; "
2573+
" return fib(i - 1) +"
2574+
" fib(i - 2);"
2575+
"}"
2576+
"fib(5);"
2577+
"%OptimizeFunctionOnNextCall(fib);"
2578+
"fib(5);"
2579+
"fib";
2580+
{
2581+
v8::Isolate::Scope isolate_scope(isolate);
2582+
v8::HandleScope handle_scope(isolate);
2583+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2584+
v8::Context::Scope context_scope(context);
2585+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2586+
2587+
CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo());
2588+
2589+
int non_detailed_positions = GetSourcePositionEntryCount(i_isolate, source);
2590+
2591+
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
2592+
CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo());
2593+
2594+
int detailed_positions = GetSourcePositionEntryCount(i_isolate, source);
2595+
2596+
CHECK((non_detailed_positions == -1 && detailed_positions == -1) ||
2597+
non_detailed_positions < detailed_positions);
2598+
}
2599+
2600+
isolate->Dispose();
2601+
}
2602+
25472603
} // namespace test_cpu_profiler
25482604
} // namespace internal
25492605
} // namespace v8

0 commit comments

Comments
 (0)