Skip to content

Commit ef69e7b

Browse files
hashseedBridgeAR
authored andcommitted
deps: backport 073073b4f1 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} PR-URL: #24274 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Peter Marshall <petermarshall@chromium.org> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent fbd0b03 commit ef69e7b

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

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

+41
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,46 @@ TEST(MultipleProfilers) {
25442545
profiler2->StopProfiling("2");
25452546
}
25462547

2548+
UNINITIALIZED_TEST(DetailedSourcePositionAPI) {
2549+
i::FLAG_detailed_line_info = false;
2550+
i::FLAG_allow_natives_syntax = true;
2551+
v8::Isolate::CreateParams create_params;
2552+
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
2553+
v8::Isolate* isolate = v8::Isolate::New(create_params);
2554+
2555+
const char* source =
2556+
"function fib(i) {"
2557+
" if (i <= 1) return 1; "
2558+
" return fib(i - 1) +"
2559+
" fib(i - 2);"
2560+
"}"
2561+
"fib(5);"
2562+
"%OptimizeFunctionOnNextCall(fib);"
2563+
"fib(5);"
2564+
"fib";
2565+
{
2566+
v8::Isolate::Scope isolate_scope(isolate);
2567+
v8::HandleScope handle_scope(isolate);
2568+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2569+
v8::Context::Scope context_scope(context);
2570+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2571+
2572+
CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo());
2573+
2574+
int non_detailed_positions = GetSourcePositionEntryCount(i_isolate, source);
2575+
2576+
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
2577+
CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo());
2578+
2579+
int detailed_positions = GetSourcePositionEntryCount(i_isolate, source);
2580+
2581+
CHECK((non_detailed_positions == -1 && detailed_positions == -1) ||
2582+
non_detailed_positions < detailed_positions);
2583+
}
2584+
2585+
isolate->Dispose();
2586+
}
2587+
25472588
} // namespace test_cpu_profiler
25482589
} // namespace internal
25492590
} // namespace v8

0 commit comments

Comments
 (0)