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,
}
if (event_handler) {
isolate_->wasm_engine()->EnableCodeLogging(isolate_);
jit_logger_.reset(new JitLogger(isolate_, event_handler));
AddCodeEventListener(jit_logger_.get());
if (options & kJitCodeEventEnumExisting) {
......
......@@ -17,6 +17,7 @@
#include "src/log.h"
#include "src/profiler/cpu-profiler-inl.h"
#include "src/vm-state-inl.h"
#include "src/wasm/wasm-engine.h"
namespace v8 {
namespace internal {
......@@ -367,6 +368,7 @@ void CpuProfiler::StartProcessorIfNotStarted() {
processor_->AddCurrentStack();
return;
}
isolate_->wasm_engine()->EnableCodeLogging(isolate_);
Logger* logger = isolate_->logger();
// Disable logging when using the new implementation.
saved_is_logging_ = logger->is_logging();
......
......@@ -148,6 +148,9 @@ void WasmCode::RegisterTrapHandlerData() {
bool WasmCode::HasTrapHandlerIndex() const { return trap_handler_index_ >= 0; }
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() ||
isolate->is_profiling();
}
......
......@@ -83,7 +83,8 @@ class LogCodesTask : public Task {
} // namespace
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::Platform* platform = V8::GetCurrentPlatform();
foreground_task_runner = platform->GetForegroundTaskRunner(v8_isolate);
......@@ -93,6 +94,9 @@ struct WasmEngine::IsolateInfo {
// grows, never shrinks).
std::set<NativeModule*> native_modules;
// Caches whether code needs to be logged on this isolate.
bool log_codes;
// The currently scheduled LogCodesTask.
LogCodesTask* log_codes_task = nullptr;
......@@ -467,6 +471,7 @@ void WasmEngine::LogCode(WasmCode* code) {
for (Isolate* isolate : isolates_per_native_module_[native_module]) {
DCHECK_EQ(1, isolates_.count(isolate));
IsolateInfo* info = isolates_[isolate].get();
if (info->log_codes == false) continue;
if (info->log_codes_task == nullptr) {
auto new_task = base::make_unique<LogCodesTask>(
&mutex_, &info->log_codes_task, isolate);
......@@ -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(
Isolate* isolate, const WasmFeatures& enabled, size_t code_size_estimate,
bool can_request_more, std::shared_ptr<const WasmModule> module) {
......
......@@ -158,6 +158,11 @@ class V8_EXPORT_PRIVATE WasmEngine {
// background threads.
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
// lifetime. The native module will be given some memory for code,
// 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