Skip to content

Commit

Permalink
deps: backport 073073b4f1 from upstream V8
Browse files Browse the repository at this point in the history
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.

  [email protected]

  Change-Id: Ie74ea41f600cf6e31acbe802116df4976ccf1c75
  Reviewed-on: https://chromium-review.googlesource.com/c/1319757
  Commit-Queue: Yang Guo <[email protected]>
  Reviewed-by: Peter Marshall <[email protected]>
  Cr-Commit-Position: refs/heads/master@{#57380}

PR-URL: nodejs#24274
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Peter Marshall <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
hashseed authored and Trott committed Nov 14, 2018
1 parent c1d18a0 commit 715bbb9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
6 changes: 6 additions & 0 deletions deps/v8/include/v8-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ class V8_EXPORT CpuProfiler {
V8_DEPRECATED("Use Isolate::SetIdle(bool) instead.",
void SetIdle(bool is_idle));

/**
* Generate more detailed source positions to code objects. This results in
* better results when mapping profiling samples to script source.
*/
static void UseDetailedSourcePositionsForProfiling(Isolate* isolate);

private:
CpuProfiler();
~CpuProfiler();
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10132,6 +10132,11 @@ void CpuProfiler::SetIdle(bool is_idle) {
isolate->SetIdle(is_idle);
}

void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)
->set_detailed_source_positions_for_profiling(true);
}

uintptr_t CodeEvent::GetCodeStartAddress() {
return reinterpret_cast<i::CodeEvent*>(this)->code_start_address;
}
Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,8 @@ bool Isolate::use_optimizer() {
}

bool Isolate::NeedsDetailedOptimizedCodeLineInfo() const {
return NeedsSourcePositionsForProfiling() || FLAG_detailed_line_info;
return NeedsSourcePositionsForProfiling() ||
detailed_source_positions_for_profiling();
}

bool Isolate::NeedsSourcePositionsForProfiling() const {
Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ typedef std::vector<HeapObject*> DebugObjectCache;
V(int, last_console_context_id, 0) \
V(v8_inspector::V8Inspector*, inspector, nullptr) \
V(bool, next_v8_call_is_safe_for_termination, false) \
V(bool, only_terminate_in_safe_scope, false)
V(bool, only_terminate_in_safe_scope, false) \
V(bool, detailed_source_positions_for_profiling, FLAG_detailed_line_info)

#define THREAD_LOCAL_TOP_ACCESSOR(type, name) \
inline void set_##name(type v) { thread_local_top_.name##_ = v; } \
Expand Down
41 changes: 41 additions & 0 deletions deps/v8/test/cctest/test-cpu-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "src/objects-inl.h"
#include "src/profiler/cpu-profiler-inl.h"
#include "src/profiler/profiler-listener.h"
#include "src/source-position-table.h"
#include "src/utils.h"
#include "test/cctest/cctest.h"
#include "test/cctest/profiler-extension.h"
Expand Down Expand Up @@ -2544,6 +2545,46 @@ TEST(MultipleProfilers) {
profiler2->StopProfiling("2");
}

UNINITIALIZED_TEST(DetailedSourcePositionAPI) {
i::FLAG_detailed_line_info = false;
i::FLAG_allow_natives_syntax = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);

const char* source =
"function fib(i) {"
" if (i <= 1) return 1; "
" return fib(i - 1) +"
" fib(i - 2);"
"}"
"fib(5);"
"%OptimizeFunctionOnNextCall(fib);"
"fib(5);"
"fib";
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);

CHECK(!i_isolate->NeedsDetailedOptimizedCodeLineInfo());

int non_detailed_positions = GetSourcePositionEntryCount(i_isolate, source);

v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
CHECK(i_isolate->NeedsDetailedOptimizedCodeLineInfo());

int detailed_positions = GetSourcePositionEntryCount(i_isolate, source);

CHECK((non_detailed_positions == -1 && detailed_positions == -1) ||
non_detailed_positions < detailed_positions);
}

isolate->Dispose();
}

} // namespace test_cpu_profiler
} // namespace internal
} // namespace v8

0 comments on commit 715bbb9

Please sign in to comment.