diff --git a/common.gypi b/common.gypi index 5e39ad3f096fb1..d01f284f0e2d68 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.12', + 'v8_embedder_string': '-node.13', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/compiler/backend/code-generator.cc b/deps/v8/src/compiler/backend/code-generator.cc index 23967760aa34ec..b5306da150926d 100644 --- a/deps/v8/src/compiler/backend/code-generator.cc +++ b/deps/v8/src/compiler/backend/code-generator.cc @@ -440,7 +440,7 @@ void CodeGenerator::AssembleCode() { } } - // The LinuxPerfJitLogger logs code up until here, excluding the safepoint + // The PerfJitLogger logs code up until here, excluding the safepoint // table. Resolve the unwinding info now so it is aware of the same code // size as reported by perf. unwinding_info_writer_.Finish(masm()->pc_offset()); diff --git a/deps/v8/src/diagnostics/perf-jit.cc b/deps/v8/src/diagnostics/perf-jit.cc index 2423c8a9e79b05..832fbe80ac1190 100644 --- a/deps/v8/src/diagnostics/perf-jit.cc +++ b/deps/v8/src/diagnostics/perf-jit.cc @@ -30,8 +30,8 @@ #include "src/common/assert-scope.h" #include "src/flags/flags.h" -// Only compile the {LinuxPerfJitLogger} on Linux. -#if V8_OS_LINUX +// Only compile the {PerfJitLogger} on Linux & Darwin. +#if V8_OS_LINUX || V8_OS_DARWIN #include #include @@ -118,22 +118,22 @@ struct PerfJitCodeUnwindingInfo : PerfJitBase { // Followed by size_ - sizeof(PerfJitCodeUnwindingInfo) bytes of data. }; -const char LinuxPerfJitLogger::kFilenameFormatString[] = "%s/jit-%d.dump"; +const char PerfJitLogger::kFilenameFormatString[] = "%s/jit-%d.dump"; // Extra padding for the PID in the filename -const int LinuxPerfJitLogger::kFilenameBufferPadding = 16; +const int PerfJitLogger::kFilenameBufferPadding = 16; static const char kStringTerminator[] = {'\0'}; // The following static variables are protected by // GetFileMutex(). -int LinuxPerfJitLogger::process_id_ = 0; -uint64_t LinuxPerfJitLogger::reference_count_ = 0; -void* LinuxPerfJitLogger::marker_address_ = nullptr; -uint64_t LinuxPerfJitLogger::code_index_ = 0; -FILE* LinuxPerfJitLogger::perf_output_handle_ = nullptr; +int PerfJitLogger::process_id_ = 0; +uint64_t PerfJitLogger::reference_count_ = 0; +void* PerfJitLogger::marker_address_ = nullptr; +uint64_t PerfJitLogger::code_index_ = 0; +FILE* PerfJitLogger::perf_output_handle_ = nullptr; -void LinuxPerfJitLogger::OpenJitDumpFile() { +void PerfJitLogger::OpenJitDumpFile() { // Open the perf JIT dump file. perf_output_handle_ = nullptr; @@ -153,8 +153,17 @@ void LinuxPerfJitLogger::OpenJitDumpFile() { if (v8_flags.perf_prof_delete_file) CHECK_EQ(0, unlink(perf_dump_name.begin())); + // On Linux, call OpenMarkerFile so that perf knows about the file path via + // an MMAP record. + // On macOS, don't call OpenMarkerFile because samply has already detected + // the file path during the call to `open` above (it interposes `open` with + // a preloaded library), and because the mmap call can be slow. +#if V8_OS_DARWIN + marker_address_ = nullptr; +#else marker_address_ = OpenMarkerFile(fd); if (marker_address_ == nullptr) return; +#endif perf_output_handle_ = fdopen(fd, "w+"); if (perf_output_handle_ == nullptr) return; @@ -162,13 +171,13 @@ void LinuxPerfJitLogger::OpenJitDumpFile() { setvbuf(perf_output_handle_, nullptr, _IOFBF, kLogBufferSize); } -void LinuxPerfJitLogger::CloseJitDumpFile() { +void PerfJitLogger::CloseJitDumpFile() { if (perf_output_handle_ == nullptr) return; base::Fclose(perf_output_handle_); perf_output_handle_ = nullptr; } -void* LinuxPerfJitLogger::OpenMarkerFile(int fd) { +void* PerfJitLogger::OpenMarkerFile(int fd) { long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) if (page_size == -1) return nullptr; @@ -180,15 +189,14 @@ void* LinuxPerfJitLogger::OpenMarkerFile(int fd) { return (marker_address == MAP_FAILED) ? nullptr : marker_address; } -void LinuxPerfJitLogger::CloseMarkerFile(void* marker_address) { +void PerfJitLogger::CloseMarkerFile(void* marker_address) { if (marker_address == nullptr) return; long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) if (page_size == -1) return; munmap(marker_address, page_size); } -LinuxPerfJitLogger::LinuxPerfJitLogger(Isolate* isolate) - : CodeEventLogger(isolate) { +PerfJitLogger::PerfJitLogger(Isolate* isolate) : CodeEventLogger(isolate) { base::LockGuard guard_file(GetFileMutex().Pointer()); process_id_ = base::OS::GetCurrentProcessId(); @@ -201,7 +209,7 @@ LinuxPerfJitLogger::LinuxPerfJitLogger(Isolate* isolate) } } -LinuxPerfJitLogger::~LinuxPerfJitLogger() { +PerfJitLogger::~PerfJitLogger() { base::LockGuard guard_file(GetFileMutex().Pointer()); reference_count_--; @@ -211,16 +219,11 @@ LinuxPerfJitLogger::~LinuxPerfJitLogger() { } } -uint64_t LinuxPerfJitLogger::GetTimestamp() { - struct timespec ts; - int result = clock_gettime(CLOCK_MONOTONIC, &ts); - DCHECK_EQ(0, result); - USE(result); - static const uint64_t kNsecPerSec = 1000000000; - return (ts.tv_sec * kNsecPerSec) + ts.tv_nsec; +uint64_t PerfJitLogger::GetTimestamp() { + return base::TimeTicks::Now().since_origin().InNanoseconds(); } -void LinuxPerfJitLogger::LogRecordedBuffer( +void PerfJitLogger::LogRecordedBuffer( Tagged abstract_code, MaybeHandle maybe_sfi, const char* name, int length) { DisallowGarbageCollection no_gc; @@ -263,8 +266,8 @@ void LinuxPerfJitLogger::LogRecordedBuffer( } #if V8_ENABLE_WEBASSEMBLY -void LinuxPerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code, - const char* name, int length) { +void PerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code, + const char* name, int length) { base::LockGuard guard_file(GetFileMutex().Pointer()); if (perf_output_handle_ == nullptr) return; @@ -276,10 +279,9 @@ void LinuxPerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code, } #endif // V8_ENABLE_WEBASSEMBLY -void LinuxPerfJitLogger::WriteJitCodeLoadEntry(const uint8_t* code_pointer, - uint32_t code_size, - const char* name, - int name_length) { +void PerfJitLogger::WriteJitCodeLoadEntry(const uint8_t* code_pointer, + uint32_t code_size, const char* name, + int name_length) { PerfJitCodeLoad code_load; code_load.event_ = PerfJitCodeLoad::kLoad; code_load.size_ = sizeof(code_load) + name_length + 1 + code_size; @@ -342,8 +344,8 @@ SourcePositionInfo GetSourcePositionInfo(Isolate* isolate, Tagged code, } // namespace -void LinuxPerfJitLogger::LogWriteDebugInfo(Tagged code, - Handle shared) { +void PerfJitLogger::LogWriteDebugInfo(Tagged code, + Handle shared) { // Line ends of all scripts have been initialized prior to this. DisallowGarbageCollection no_gc; // The WasmToJS wrapper stubs have source position entries. @@ -426,7 +428,7 @@ void LinuxPerfJitLogger::LogWriteDebugInfo(Tagged code, } #if V8_ENABLE_WEBASSEMBLY -void LinuxPerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) { +void PerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) { if (code->IsAnonymous()) { return; } @@ -498,7 +500,7 @@ void LinuxPerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) { } #endif // V8_ENABLE_WEBASSEMBLY -void LinuxPerfJitLogger::LogWriteUnwindingInfo(Tagged code) { +void PerfJitLogger::LogWriteUnwindingInfo(Tagged code) { PerfJitCodeUnwindingInfo unwinding_info_header; unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo; unwinding_info_header.time_stamp_ = GetTimestamp(); @@ -533,13 +535,13 @@ void LinuxPerfJitLogger::LogWriteUnwindingInfo(Tagged code) { LogWriteBytes(padding_bytes, static_cast(padding_size)); } -void LinuxPerfJitLogger::LogWriteBytes(const char* bytes, int size) { +void PerfJitLogger::LogWriteBytes(const char* bytes, int size) { size_t rv = fwrite(bytes, 1, size, perf_output_handle_); DCHECK(static_cast(size) == rv); USE(rv); } -void LinuxPerfJitLogger::LogWriteHeader() { +void PerfJitLogger::LogWriteHeader() { DCHECK_NOT_NULL(perf_output_handle_); PerfJitHeader header; @@ -560,4 +562,4 @@ void LinuxPerfJitLogger::LogWriteHeader() { } // namespace internal } // namespace v8 -#endif // V8_OS_LINUX +#endif // V8_OS_LINUX || V8_OS_DARWIN diff --git a/deps/v8/src/diagnostics/perf-jit.h b/deps/v8/src/diagnostics/perf-jit.h index 294c0cd32da4b6..4e8da6fd88def6 100644 --- a/deps/v8/src/diagnostics/perf-jit.h +++ b/deps/v8/src/diagnostics/perf-jit.h @@ -30,8 +30,8 @@ #include "include/v8config.h" -// {LinuxPerfJitLogger} is only implemented on Linux. -#if V8_OS_LINUX +// {PerfJitLogger} is only implemented on Linux & Darwin. +#if V8_OS_LINUX || V8_OS_DARWIN #include "src/logging/log.h" @@ -39,10 +39,10 @@ namespace v8 { namespace internal { // Linux perf tool logging support. -class LinuxPerfJitLogger : public CodeEventLogger { +class PerfJitLogger : public CodeEventLogger { public: - explicit LinuxPerfJitLogger(Isolate* isolate); - ~LinuxPerfJitLogger() override; + explicit PerfJitLogger(Isolate* isolate); + ~PerfJitLogger() override; void CodeMoveEvent(Tagged from, Tagged to) override { @@ -142,6 +142,6 @@ class LinuxPerfJitLogger : public CodeEventLogger { } // namespace internal } // namespace v8 -#endif // V8_OS_LINUX +#endif // V8_OS_LINUX || V8_OS_DARWIN #endif // V8_DIAGNOSTICS_PERF_JIT_H_ diff --git a/deps/v8/src/flags/flag-definitions.h b/deps/v8/src/flags/flag-definitions.h index 61e859ccb3109a..b5658e3d31f2dc 100644 --- a/deps/v8/src/flags/flag-definitions.h +++ b/deps/v8/src/flags/flag-definitions.h @@ -3072,7 +3072,7 @@ DEFINE_IMPLICATION(prof, log_code) DEFINE_BOOL(ll_prof, false, "Enable low-level linux profiler.") -#if V8_OS_LINUX +#if V8_OS_LINUX || V8_OS_DARWIN #define DEFINE_PERF_PROF_BOOL(nam, cmt) DEFINE_BOOL(nam, false, cmt) #define DEFINE_PERF_PROF_IMPLICATION DEFINE_IMPLICATION #else @@ -3089,7 +3089,7 @@ DEFINE_BOOL(ll_prof, false, "Enable low-level linux profiler.") #endif DEFINE_PERF_PROF_BOOL(perf_basic_prof, - "Enable perf linux profiler (basic support).") + "Enable basic support for perf profiler.") DEFINE_NEG_IMPLICATION(perf_basic_prof, compact_code_space) DEFINE_STRING(perf_basic_prof_path, DEFAULT_PERF_BASIC_PROF_PATH, "directory to write perf-.map symbol file to") @@ -3098,8 +3098,8 @@ DEFINE_PERF_PROF_BOOL( "Only report function code ranges to perf (i.e. no stubs).") DEFINE_PERF_PROF_IMPLICATION(perf_basic_prof_only_functions, perf_basic_prof) -DEFINE_PERF_PROF_BOOL( - perf_prof, "Enable perf linux profiler (experimental annotate support).") +DEFINE_PERF_PROF_BOOL(perf_prof, + "Enable experimental annotate support for perf profiler.") DEFINE_STRING(perf_prof_path, DEFAULT_PERF_PROF_PATH, "directory to write jit-.dump symbol file to") DEFINE_PERF_PROF_BOOL( diff --git a/deps/v8/src/logging/log.cc b/deps/v8/src/logging/log.cc index 8db7fb67c5d359..20b1f2971b8cde 100644 --- a/deps/v8/src/logging/log.cc +++ b/deps/v8/src/logging/log.cc @@ -337,12 +337,12 @@ void CodeEventLogger::RegExpCodeCreateEvent(Handle code, name_buffer_->get(), name_buffer_->size()); } -// Linux perf tool logging support. -#if V8_OS_LINUX -class LinuxPerfBasicLogger : public CodeEventLogger { +// Linux & Darwin perf tool logging support. +#if V8_OS_LINUX || V8_OS_DARWIN +class PerfBasicLogger : public CodeEventLogger { public: - explicit LinuxPerfBasicLogger(Isolate* isolate); - ~LinuxPerfBasicLogger() override; + explicit PerfBasicLogger(Isolate* isolate); + ~PerfBasicLogger() override; void CodeMoveEvent(Tagged from, Tagged to) override {} @@ -375,21 +375,20 @@ class LinuxPerfBasicLogger : public CodeEventLogger { }; // Extra space for the "perf-%d.map" filename, including the PID. -const int LinuxPerfBasicLogger::kFilenameBufferPadding = 32; +const int PerfBasicLogger::kFilenameBufferPadding = 32; // static -base::LazyRecursiveMutex& LinuxPerfBasicLogger::GetFileMutex() { +base::LazyRecursiveMutex& PerfBasicLogger::GetFileMutex() { static base::LazyRecursiveMutex file_mutex = LAZY_RECURSIVE_MUTEX_INITIALIZER; return file_mutex; } // The following static variables are protected by -// LinuxPerfBasicLogger::GetFileMutex(). -uint64_t LinuxPerfBasicLogger::reference_count_ = 0; -FILE* LinuxPerfBasicLogger::perf_output_handle_ = nullptr; +// PerfBasicLogger::GetFileMutex(). +uint64_t PerfBasicLogger::reference_count_ = 0; +FILE* PerfBasicLogger::perf_output_handle_ = nullptr; -LinuxPerfBasicLogger::LinuxPerfBasicLogger(Isolate* isolate) - : CodeEventLogger(isolate) { +PerfBasicLogger::PerfBasicLogger(Isolate* isolate) : CodeEventLogger(isolate) { base::LockGuard guard_file(GetFileMutex().Pointer()); int process_id_ = base::OS::GetCurrentProcessId(); reference_count_++; @@ -411,7 +410,7 @@ LinuxPerfBasicLogger::LinuxPerfBasicLogger(Isolate* isolate) } } -LinuxPerfBasicLogger::~LinuxPerfBasicLogger() { +PerfBasicLogger::~PerfBasicLogger() { base::LockGuard guard_file(GetFileMutex().Pointer()); reference_count_--; @@ -423,9 +422,9 @@ LinuxPerfBasicLogger::~LinuxPerfBasicLogger() { } } -void LinuxPerfBasicLogger::WriteLogRecordedBuffer(uintptr_t address, int size, - const char* name, - int name_length) { +void PerfBasicLogger::WriteLogRecordedBuffer(uintptr_t address, int size, + const char* name, + int name_length) { // Linux perf expects hex literals without a leading 0x, while some // implementations of printf might prepend one when using the %p format // for pointers, leading to wrongly formatted JIT symbols maps. On the other @@ -442,9 +441,9 @@ void LinuxPerfBasicLogger::WriteLogRecordedBuffer(uintptr_t address, int size, #endif } -void LinuxPerfBasicLogger::LogRecordedBuffer(Tagged code, - MaybeHandle, - const char* name, int length) { +void PerfBasicLogger::LogRecordedBuffer(Tagged code, + MaybeHandle, + const char* name, int length) { DisallowGarbageCollection no_gc; PtrComprCageBase cage_base(isolate_); if (v8_flags.perf_basic_prof_only_functions && @@ -458,13 +457,13 @@ void LinuxPerfBasicLogger::LogRecordedBuffer(Tagged code, } #if V8_ENABLE_WEBASSEMBLY -void LinuxPerfBasicLogger::LogRecordedBuffer(const wasm::WasmCode* code, - const char* name, int length) { +void PerfBasicLogger::LogRecordedBuffer(const wasm::WasmCode* code, + const char* name, int length) { WriteLogRecordedBuffer(static_cast(code->instruction_start()), code->instructions().length(), name, length); } #endif // V8_ENABLE_WEBASSEMBLY -#endif // V8_OS_LINUX +#endif // V8_OS_LINUX || V8_OS_DARWIN // External LogEventListener ExternalLogEventListener::ExternalLogEventListener(Isolate* isolate) @@ -2291,14 +2290,14 @@ bool V8FileLogger::SetUp(Isolate* isolate) { PrepareLogFileName(log_file_name, isolate, v8_flags.logfile); log_file_ = std::make_unique(this, log_file_name.str()); -#if V8_OS_LINUX +#if V8_OS_LINUX || V8_OS_DARWIN if (v8_flags.perf_basic_prof) { - perf_basic_logger_ = std::make_unique(isolate); + perf_basic_logger_ = std::make_unique(isolate); CHECK(logger()->AddListener(perf_basic_logger_.get())); } if (v8_flags.perf_prof) { - perf_jit_logger_ = std::make_unique(isolate); + perf_jit_logger_ = std::make_unique(isolate); CHECK(logger()->AddListener(perf_jit_logger_.get())); } #else @@ -2436,7 +2435,7 @@ FILE* V8FileLogger::TearDownAndGetLogFile() { ticker_.reset(); timer_.Stop(); -#if V8_OS_LINUX +#if V8_OS_LINUX || V8_OS_DARWIN if (perf_basic_logger_) { CHECK(logger()->RemoveListener(perf_basic_logger_.get())); perf_basic_logger_.reset(); diff --git a/deps/v8/src/logging/log.h b/deps/v8/src/logging/log.h index 2617789fac5803..a3e0a34d01e265 100644 --- a/deps/v8/src/logging/log.h +++ b/deps/v8/src/logging/log.h @@ -63,8 +63,8 @@ class Isolate; class JitLogger; class LogFile; class LowLevelLogger; -class LinuxPerfBasicLogger; -class LinuxPerfJitLogger; +class PerfBasicLogger; +class PerfJitLogger; class Profiler; class SourcePosition; class Ticker; @@ -357,9 +357,9 @@ class V8FileLogger : public LogEventListener { std::atomic is_logging_; std::unique_ptr log_file_; -#if V8_OS_LINUX - std::unique_ptr perf_basic_logger_; - std::unique_ptr perf_jit_logger_; +#if V8_OS_LINUX || V8_OS_DARWIN + std::unique_ptr perf_basic_logger_; + std::unique_ptr perf_jit_logger_; #endif std::unique_ptr ll_logger_; std::unique_ptr jit_logger_;