Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] deps: V8: backport 20 CPU profiler commits from upstream #21558

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions deps/v8/include/v8-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ class V8_EXPORT CpuProfile {
void Delete();
};

enum CpuProfilingMode {
// In the resulting CpuProfile tree, intermediate nodes in a stack trace
// (from the root to a leaf) will have line numbers that point to the start
// line of the function, rather than the line of the callsite of the child.
kLeafNodeLineNumbers,
// In the resulting CpuProfile tree, nodes are separated based on the line
// number of their callsite in their parent.
kCallerLineNumbers,
};

/**
* Interface for controlling CPU profiling. Instance of the
* profiler can be created using v8::CpuProfiler::New method.
Expand Down Expand Up @@ -309,6 +319,13 @@ class V8_EXPORT CpuProfiler {
* |record_samples| parameter controls whether individual samples should
* be recorded in addition to the aggregated tree.
*/
void StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples = false);
/**
* The same as StartProfiling above, but the CpuProfilingMode defaults to
* kLeafNodeLineNumbers mode, which was the previous default behavior of the
* profiler.
*/
void StartProfiling(Local<String> title, bool record_samples = false);

/**
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 2
#define V8_BUILD_NUMBER 414
#define V8_PATCH_LEVEL 66
#define V8_PATCH_LEVEL 67

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
21 changes: 9 additions & 12 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8418,7 +8418,7 @@ HeapProfiler* Isolate::GetHeapProfiler() {

CpuProfiler* Isolate::GetCpuProfiler() {
i::CpuProfiler* cpu_profiler =
reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
reinterpret_cast<i::Isolate*>(this)->EnsureCpuProfiler();
return reinterpret_cast<CpuProfiler*>(cpu_profiler);
}

Expand Down Expand Up @@ -10138,15 +10138,7 @@ Local<String> CpuProfileNode::GetFunctionName() const {
const i::CodeEntry* entry = node->entry();
i::Handle<i::String> name =
isolate->factory()->InternalizeUtf8String(entry->name());
if (!entry->has_name_prefix()) {
return ToApiHandle<String>(name);
} else {
// We do not expect this to fail. Change this if it does.
i::Handle<i::String> cons = isolate->factory()->NewConsString(
isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
name).ToHandleChecked();
return ToApiHandle<String>(cons);
}
return ToApiHandle<String>(name);
}

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

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


Expand Down Expand Up @@ -10370,9 +10362,14 @@ void CpuProfiler::CollectSample() {

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

void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples) {
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), record_samples, mode);
}

CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
return reinterpret_cast<CpuProfile*>(
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/code-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CodeEventListener {
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
virtual void CodeMoveEvent(AbstractCode* from, AbstractCode* to) = 0;
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
virtual void CodeMovingGCEvent() = 0;
virtual void CodeDisableOptEvent(AbstractCode* code,
Expand Down Expand Up @@ -163,7 +163,7 @@ class CodeEventDispatcher {
void RegExpCodeCreateEvent(AbstractCode* code, String* source) {
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
}
void CodeMoveEvent(AbstractCode* from, Address to) {
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
}
void SharedFunctionInfoMoveEvent(Address from, Address to) {
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/compilation-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
// Collect source positions for optimized code when profiling or if debugger
// is active, to be able to get more precise source positions at the price of
// more memory consumption.
if (isolate_->NeedsSourcePositionsForProfiling()) {
if (isolate_->NeedsDetailedOptimizedCodeLineInfo()) {
MarkAsSourcePositionsEnabled();
}
}
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ DEFINE_BOOL(log_source_code, false, "Log source code.")
DEFINE_BOOL(prof, false,
"Log statistical profiling information (implies --log-code).")

DEFINE_BOOL(detailed_line_info, true,
"Always generate detailed line information for CPU profiling.")

#if defined(ANDROID)
// Phones and tablets have processors that are much slower than desktop
// and laptop computers for which current heuristics are tuned.
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/heap/mark-compact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ class ProfilingMigrationObserver final : public MigrationObserver {
int size) final {
if (dest == CODE_SPACE || (dest == OLD_SPACE && dst->IsBytecodeArray())) {
PROFILE(heap_->isolate(),
CodeMoveEvent(AbstractCode::cast(src), dst->address()));
CodeMoveEvent(AbstractCode::cast(src), AbstractCode::cast(dst)));
}
heap_->OnMoveEvent(dst, src, size);
}
Expand Down
12 changes: 11 additions & 1 deletion deps/v8/src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,6 @@ bool Isolate::Init(StartupDeserializer* des) {
call_descriptor_data_ =
new CallInterfaceDescriptorData[CallDescriptors::NUMBER_OF_DESCRIPTORS];
access_compiler_data_ = new AccessCompilerData();
cpu_profiler_ = new CpuProfiler(this);
heap_profiler_ = new HeapProfiler(heap());
interpreter_ = new interpreter::Interpreter(this);
compiler_dispatcher_ =
Expand Down Expand Up @@ -2962,6 +2961,10 @@ bool Isolate::use_optimizer() {
!is_precise_count_code_coverage() && !is_block_count_code_coverage();
}

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

bool Isolate::NeedsSourcePositionsForProfiling() const {
return FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph ||
FLAG_turbo_profiling || FLAG_perf_prof || is_profiling() ||
Expand Down Expand Up @@ -3686,6 +3689,13 @@ void Isolate::PrintWithTimestamp(const char* format, ...) {
va_end(arguments);
}

CpuProfiler* Isolate::EnsureCpuProfiler() {
if (!cpu_profiler_) {
cpu_profiler_ = new CpuProfiler(this);
}
return cpu_profiler_;
}

bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR
Expand Down
4 changes: 3 additions & 1 deletion deps/v8/src/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ class Isolate {

bool NeedsSourcePositionsForProfiling() const;

bool NeedsDetailedOptimizedCodeLineInfo() const;

bool is_best_effort_code_coverage() const {
return code_coverage_mode() == debug::Coverage::kBestEffort;
}
Expand Down Expand Up @@ -1449,7 +1451,7 @@ class Isolate {

// TODO(alph): Remove along with the deprecated GetCpuProfiler().
friend v8::CpuProfiler* v8::Isolate::GetCpuProfiler();
CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
CpuProfiler* EnsureCpuProfiler();

base::Atomic32 id_;
EntryStackItem* entry_stack_;
Expand Down
48 changes: 11 additions & 37 deletions deps/v8/src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "src/log-utils.h"
#include "src/macro-assembler.h"
#include "src/perf-jit.h"
#include "src/profiler/profiler-listener.h"
#include "src/profiler/tick-sample.h"
#include "src/runtime-profiler.h"
#include "src/source-position-table.h"
Expand Down Expand Up @@ -218,7 +217,7 @@ class PerfBasicLogger : public CodeEventLogger {
PerfBasicLogger();
~PerfBasicLogger() override;

void CodeMoveEvent(AbstractCode* from, Address to) override {}
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}

Expand Down Expand Up @@ -287,7 +286,7 @@ class LowLevelLogger : public CodeEventLogger {
explicit LowLevelLogger(const char* file_name);
~LowLevelLogger() override;

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}
void SnapshotPositionEvent(HeapObject* obj, int pos);
Expand Down Expand Up @@ -393,11 +392,10 @@ void LowLevelLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*,
code->instruction_size());
}

void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
CodeMoveStruct event;
event.from_address = from->instruction_start();
size_t header_size = from->instruction_start() - from->address();
event.to_address = to + header_size;
event.to_address = to->instruction_start();
LogWriteStruct(event);
}

Expand All @@ -419,7 +417,7 @@ class JitLogger : public CodeEventLogger {
public:
explicit JitLogger(JitCodeEventHandler code_event_handler);

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}
void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset,
Expand Down Expand Up @@ -460,19 +458,14 @@ void JitLogger::LogRecordedBuffer(AbstractCode* code,
code_event_handler_(&event);
}

void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void JitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
base::LockGuard<base::Mutex> guard(&logger_mutex_);

JitCodeEvent event;
event.type = JitCodeEvent::CODE_MOVED;
event.code_start = from->instruction_start();
event.code_start = reinterpret_cast<void*>(from->instruction_start());
event.code_len = from->instruction_size();

// Calculate the header size.
const size_t header_size = from->instruction_start() - from->address();

// Calculate the new start address of the instructions.
event.new_code_start = to + header_size;
event.new_code_start = reinterpret_cast<void*>(to->instruction_start());

code_event_handler_(&event);
}
Expand Down Expand Up @@ -739,7 +732,6 @@ Logger::Logger(Isolate* isolate)
perf_jit_logger_(NULL),
ll_logger_(NULL),
jit_logger_(NULL),
listeners_(5),
is_initialized_(false) {}

Logger::~Logger() {
Expand Down Expand Up @@ -1297,9 +1289,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) {
msg.WriteToLogFile();
}

void Logger::CodeMoveEvent(AbstractCode* from, Address to) {
void Logger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
if (!is_logging_code_events()) return;
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to);
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(),
to->address());
}

void Logger::CodeLinePosInfoRecordEvent(AbstractCode* code,
Expand Down Expand Up @@ -1876,8 +1869,6 @@ bool Logger::SetUp(Isolate* isolate) {
profiler_->Engage();
}

profiler_listener_.reset();

if (is_logging_) {
addCodeEventListener(this);
}
Expand Down Expand Up @@ -1905,19 +1896,6 @@ void Logger::SetCodeEventHandler(uint32_t options,
}
}

void Logger::SetUpProfilerListener() {
if (!is_initialized_) return;
if (profiler_listener_.get() == nullptr) {
profiler_listener_.reset(new ProfilerListener(isolate_));
}
addCodeEventListener(profiler_listener_.get());
}

void Logger::TearDownProfilerListener() {
if (profiler_listener_->HasObservers()) return;
removeCodeEventListener(profiler_listener_.get());
}

sampler::Sampler* Logger::sampler() {
return ticker_;
}
Expand Down Expand Up @@ -1961,10 +1939,6 @@ FILE* Logger::TearDown() {
jit_logger_ = NULL;
}

if (profiler_listener_.get() != nullptr) {
removeCodeEventListener(profiler_listener_.get());
}

return log_->Close();
}

Expand Down
14 changes: 1 addition & 13 deletions deps/v8/src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class LowLevelLogger;
class PerfBasicLogger;
class PerfJitLogger;
class Profiler;
class ProfilerListener;
class RuntimeCallTimer;
class Ticker;

Expand Down Expand Up @@ -102,16 +101,8 @@ class Logger : public CodeEventListener {
void SetCodeEventHandler(uint32_t options,
JitCodeEventHandler event_handler);

// Sets up ProfilerListener.
void SetUpProfilerListener();

// Tear down ProfilerListener if it has no observers.
void TearDownProfilerListener();

sampler::Sampler* sampler();

ProfilerListener* profiler_listener() { return profiler_listener_.get(); }

// Frees resources acquired in SetUp.
// When a temporary file is used for the log, returns its stream descriptor,
// leaving the file open.
Expand Down Expand Up @@ -177,7 +168,7 @@ class Logger : public CodeEventListener {
// Emits a code create event for a RegExp.
void RegExpCodeCreateEvent(AbstractCode* code, String* source);
// Emits a code move event.
void CodeMoveEvent(AbstractCode* from, Address to);
void CodeMoveEvent(AbstractCode* from, AbstractCode* to);
// Emits a code line info record event.
void CodeLinePosInfoRecordEvent(AbstractCode* code,
ByteArray* source_position_table);
Expand Down Expand Up @@ -316,8 +307,6 @@ class Logger : public CodeEventListener {
PerfJitLogger* perf_jit_logger_;
LowLevelLogger* ll_logger_;
JitLogger* jit_logger_;
std::unique_ptr<ProfilerListener> profiler_listener_;
List<CodeEventListener*> listeners_;
std::set<int> logged_source_code_;
uint32_t next_source_info_id_ = 0;

Expand Down Expand Up @@ -400,7 +389,6 @@ class CodeEventLogger : public CodeEventListener {
NameBuffer* name_buffer_;
};


} // namespace internal
} // namespace v8

Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/perf-jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
LogWriteBytes(padding_bytes, static_cast<int>(padding_size));
}

void PerfJitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void PerfJitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
// Code relocation not supported.
UNREACHABLE();
}
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/perf-jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PerfJitLogger : public CodeEventLogger {
PerfJitLogger();
virtual ~PerfJitLogger();

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}

Expand Down Expand Up @@ -113,7 +113,7 @@ class PerfJitLogger : public CodeEventLogger {
// PerfJitLogger is only implemented on Linux
class PerfJitLogger : public CodeEventLogger {
public:
void CodeMoveEvent(AbstractCode* from, Address to) override {
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {
UNIMPLEMENTED();
}

Expand Down
Loading