Commit bdb22362 authored by Ng Zhi An's avatar Ng Zhi An Committed by V8 LUCI CQ

[wasm] Log code without holding lock

We snapshot all the code first, then log it without holding the lock.

Change-Id: I8c18b2db56678a9320ea6b63cd06290453c0a66a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3097472
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76354}
parent 39fb4e14
......@@ -1035,12 +1035,9 @@ void NativeModule::LogWasmCodes(Isolate* isolate, Script script) {
// Log all owned code, not just the current entries in the code table. This
// will also include import wrappers.
base::RecursiveMutexGuard lock(&allocation_mutex_);
for (auto& owned_entry : owned_code_) {
owned_entry.second->LogCode(isolate, source_url.get(), script.id());
}
for (auto& owned_entry : new_owned_code_) {
owned_entry->LogCode(isolate, source_url.get(), script.id());
WasmCodeRefScope code_ref_scope;
for (auto& code : SnapshotAllOwnedCode()) {
code->LogCode(isolate, source_url.get(), script.id());
}
}
......@@ -1431,6 +1428,17 @@ std::vector<WasmCode*> NativeModule::SnapshotCodeTable() const {
return std::vector<WasmCode*>{start, end};
}
std::vector<WasmCode*> NativeModule::SnapshotAllOwnedCode() const {
base::RecursiveMutexGuard lock(&allocation_mutex_);
if (!new_owned_code_.empty()) TransferNewOwnedCodeLocked();
std::vector<WasmCode*> all_code(owned_code_.size());
std::transform(owned_code_.begin(), owned_code_.end(), all_code.begin(),
[](auto& entry) { return entry.second.get(); });
std::for_each(all_code.begin(), all_code.end(), WasmCodeRefScope::AddRef);
return all_code;
}
WasmCode* NativeModule::GetCode(uint32_t index) const {
base::RecursiveMutexGuard guard(&allocation_mutex_);
WasmCode* code = code_table_[declared_function_index(module(), index)];
......
......@@ -637,6 +637,9 @@ class V8_EXPORT_PRIVATE NativeModule final {
// Creates a snapshot of the current state of the code table. This is useful
// to get a consistent view of the table (e.g. used by the serializer).
std::vector<WasmCode*> SnapshotCodeTable() const;
// Creates a snapshot of all {owned_code_}, will transfer new code (if any) to
// {owned_code_}.
std::vector<WasmCode*> SnapshotAllOwnedCode() const;
WasmCode* GetCode(uint32_t index) const;
bool HasCode(uint32_t index) const;
......
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