Commit 60ecc6ce authored by Daniel Lehmann's avatar Daniel Lehmann Committed by V8 LUCI CQ

[wasm] Fix write-protection performance for lazy asm.js

Similar to https://crrev.com/c/2912786, this fixes a high number of
page permission switches (incuring mprotect syscall and lock contention
overhead) by pulling a {NativeModuleModificationScope} outside of a
loop (and across a function boundary).

R=clemensb@chromium.org
CC=​​​jkummerow@chromium.org

Cq-Include-Trybots: luci.v8.try:v8_linux64_fyi_rel_ng
Bug: v8:11663, chromium:932033
Change-Id: I2ec47f3eeeb2ab9624d2eaea9b4e776738871c97
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2928504Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Daniel Lehmann <dlehmann@google.com>
Cr-Commit-Position: refs/heads/master@{#74906}
parent 336f10c4
......@@ -1427,6 +1427,8 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
uint32_t start = module->num_imported_functions;
uint32_t end = start + module->num_declared_functions;
base::Optional<NativeModuleModificationScope>
lazy_native_module_modification_scope;
for (uint32_t func_index = start; func_index < end; func_index++) {
if (prefer_liftoff) {
builder.AddRecompilationUnit(func_index, ExecutionTier::kLiftoff);
......@@ -1434,14 +1436,21 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
}
CompileStrategy strategy = GetCompileStrategy(
module, native_module->enabled_features(), func_index, lazy_module);
if (strategy == CompileStrategy::kLazy) {
native_module->UseLazyStub(func_index);
} else if (strategy == CompileStrategy::kLazyBaselineEagerTopTier) {
builder.AddTopTierUnit(func_index);
native_module->UseLazyStub(func_index);
} else {
DCHECK_EQ(strategy, CompileStrategy::kEager);
if (strategy == CompileStrategy::kEager) {
builder.AddUnits(func_index);
} else {
// Open a single scope for all following calls to {UseLazyStub()}, instead
// of flipping page permissions for each {func_index} individually.
if (!lazy_native_module_modification_scope.has_value()) {
lazy_native_module_modification_scope.emplace(native_module);
}
if (strategy == CompileStrategy::kLazy) {
native_module->UseLazyStub(func_index);
} else {
DCHECK_EQ(strategy, CompileStrategy::kLazyBaselineEagerTopTier);
builder.AddTopTierUnit(func_index);
native_module->UseLazyStub(func_index);
}
}
}
int num_import_wrappers = AddImportWrapperUnits(native_module, &builder);
......
......@@ -974,6 +974,12 @@ class V8_NODISCARD NativeModuleModificationScope final {
explicit NativeModuleModificationScope(NativeModule* native_module);
~NativeModuleModificationScope();
// Disable copy constructor and copy-assignment operator, since this manages
// a resource and implicit copying of the scope can yield surprising errors.
NativeModuleModificationScope(const NativeModuleModificationScope&) = delete;
NativeModuleModificationScope& operator=(
const NativeModuleModificationScope&) = delete;
private:
NativeModule* native_module_;
};
......
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