Commit eae6bf2d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Cache whether code should be logged

Creating the LogCodesTask and adding the code objects to it adds 10-20%
to Liftoff compilation time. Thus cache whether code logging is needed
per isolate, and avoid the overhead if that flag is false.

R=mstarzinger@chromium.org

Bug: v8:8783, chromium:928722
Change-Id: I059266da3309a4b1ed316016d0a55fa34f139057
Reviewed-on: https://chromium-review.googlesource.com/c/1454484
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59400}
parent e0f0d60c
...@@ -1930,6 +1930,7 @@ void Logger::SetCodeEventHandler(uint32_t options, ...@@ -1930,6 +1930,7 @@ void Logger::SetCodeEventHandler(uint32_t options,
} }
if (event_handler) { if (event_handler) {
isolate_->wasm_engine()->EnableCodeLogging(isolate_);
jit_logger_.reset(new JitLogger(isolate_, event_handler)); jit_logger_.reset(new JitLogger(isolate_, event_handler));
AddCodeEventListener(jit_logger_.get()); AddCodeEventListener(jit_logger_.get());
if (options & kJitCodeEventEnumExisting) { if (options & kJitCodeEventEnumExisting) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "src/log.h" #include "src/log.h"
#include "src/profiler/cpu-profiler-inl.h" #include "src/profiler/cpu-profiler-inl.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#include "src/wasm/wasm-engine.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -367,6 +368,7 @@ void CpuProfiler::StartProcessorIfNotStarted() { ...@@ -367,6 +368,7 @@ void CpuProfiler::StartProcessorIfNotStarted() {
processor_->AddCurrentStack(); processor_->AddCurrentStack();
return; return;
} }
isolate_->wasm_engine()->EnableCodeLogging(isolate_);
Logger* logger = isolate_->logger(); Logger* logger = isolate_->logger();
// Disable logging when using the new implementation. // Disable logging when using the new implementation.
saved_is_logging_ = logger->is_logging(); saved_is_logging_ = logger->is_logging();
......
...@@ -148,6 +148,9 @@ void WasmCode::RegisterTrapHandlerData() { ...@@ -148,6 +148,9 @@ void WasmCode::RegisterTrapHandlerData() {
bool WasmCode::HasTrapHandlerIndex() const { return trap_handler_index_ >= 0; } bool WasmCode::HasTrapHandlerIndex() const { return trap_handler_index_ >= 0; }
bool WasmCode::ShouldBeLogged(Isolate* isolate) { bool WasmCode::ShouldBeLogged(Isolate* isolate) {
// The return value is cached in {WasmEngine::IsolateData::log_codes}. Ensure
// to call {WasmEngine::EnableCodeLogging} if this return value would change
// for any isolate. Otherwise we might lose code events.
return isolate->logger()->is_listening_to_code_events() || return isolate->logger()->is_listening_to_code_events() ||
isolate->is_profiling(); isolate->is_profiling();
} }
......
...@@ -83,7 +83,8 @@ class LogCodesTask : public Task { ...@@ -83,7 +83,8 @@ class LogCodesTask : public Task {
} // namespace } // namespace
struct WasmEngine::IsolateInfo { struct WasmEngine::IsolateInfo {
explicit IsolateInfo(Isolate* isolate) { explicit IsolateInfo(Isolate* isolate)
: log_codes(WasmCode::ShouldBeLogged(isolate)) {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::Platform* platform = V8::GetCurrentPlatform(); v8::Platform* platform = V8::GetCurrentPlatform();
foreground_task_runner = platform->GetForegroundTaskRunner(v8_isolate); foreground_task_runner = platform->GetForegroundTaskRunner(v8_isolate);
...@@ -93,6 +94,9 @@ struct WasmEngine::IsolateInfo { ...@@ -93,6 +94,9 @@ struct WasmEngine::IsolateInfo {
// grows, never shrinks). // grows, never shrinks).
std::set<NativeModule*> native_modules; std::set<NativeModule*> native_modules;
// Caches whether code needs to be logged on this isolate.
bool log_codes;
// The currently scheduled LogCodesTask. // The currently scheduled LogCodesTask.
LogCodesTask* log_codes_task = nullptr; LogCodesTask* log_codes_task = nullptr;
...@@ -467,6 +471,7 @@ void WasmEngine::LogCode(WasmCode* code) { ...@@ -467,6 +471,7 @@ void WasmEngine::LogCode(WasmCode* code) {
for (Isolate* isolate : isolates_per_native_module_[native_module]) { for (Isolate* isolate : isolates_per_native_module_[native_module]) {
DCHECK_EQ(1, isolates_.count(isolate)); DCHECK_EQ(1, isolates_.count(isolate));
IsolateInfo* info = isolates_[isolate].get(); IsolateInfo* info = isolates_[isolate].get();
if (info->log_codes == false) continue;
if (info->log_codes_task == nullptr) { if (info->log_codes_task == nullptr) {
auto new_task = base::make_unique<LogCodesTask>( auto new_task = base::make_unique<LogCodesTask>(
&mutex_, &info->log_codes_task, isolate); &mutex_, &info->log_codes_task, isolate);
...@@ -477,6 +482,13 @@ void WasmEngine::LogCode(WasmCode* code) { ...@@ -477,6 +482,13 @@ void WasmEngine::LogCode(WasmCode* code) {
} }
} }
void WasmEngine::EnableCodeLogging(Isolate* isolate) {
base::MutexGuard guard(&mutex_);
auto it = isolates_.find(isolate);
DCHECK_NE(isolates_.end(), it);
it->second->log_codes = true;
}
std::unique_ptr<NativeModule> WasmEngine::NewNativeModule( std::unique_ptr<NativeModule> WasmEngine::NewNativeModule(
Isolate* isolate, const WasmFeatures& enabled, size_t code_size_estimate, Isolate* isolate, const WasmFeatures& enabled, size_t code_size_estimate,
bool can_request_more, std::shared_ptr<const WasmModule> module) { bool can_request_more, std::shared_ptr<const WasmModule> module) {
......
...@@ -158,6 +158,11 @@ class V8_EXPORT_PRIVATE WasmEngine { ...@@ -158,6 +158,11 @@ class V8_EXPORT_PRIVATE WasmEngine {
// background threads. // background threads.
void LogCode(WasmCode*); void LogCode(WasmCode*);
// Enable code logging for the given Isolate. Initially, code logging is
// enabled if {WasmCode::ShouldBeLogged(Isolate*)} returns true during
// {AddIsolate}.
void EnableCodeLogging(Isolate*);
// Create a new NativeModule. The caller is responsible for its // Create a new NativeModule. The caller is responsible for its
// lifetime. The native module will be given some memory for code, // lifetime. The native module will be given some memory for code,
// which will be page size aligned. The size of the initial memory // which will be page size aligned. The size of the initial memory
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment