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

[wasm][gc] Add missing code refs for code logging

We are missing wasm code ref scopes, and fail layout tests:
https://ci.chromium.org/p/chromium/builders/try/linux-rel/69013
This CL fixes this by managing ref counts explicitly in the
LogCodesTask.

R=mstarzinger@chromium.org

Bug: v8:8217
Change-Id: I86ee09da7b36abf184c5a64a5b0648a3e39c1bb4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1565902
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60850}
parent 225c062d
......@@ -476,6 +476,7 @@ void NativeModule::LogWasmCodes(Isolate* isolate) {
// here, but they should be included somehow.
int start = module()->num_imported_functions;
int end = start + module()->num_declared_functions;
WasmCodeRefScope code_ref_scope;
for (int func_index = start; func_index < end; ++func_index) {
if (WasmCode* code = GetCode(func_index)) code->LogCode(isolate);
}
......
......@@ -23,6 +23,8 @@ namespace internal {
namespace wasm {
namespace {
// A task to log a set of {WasmCode} objects in an isolate. Explicitly manages
// ref counts of the contained code objects.
class LogCodesTask : public Task {
public:
LogCodesTask(base::Mutex* mutex, LogCodesTask** task_slot, Isolate* isolate)
......@@ -35,10 +37,16 @@ class LogCodesTask : public Task {
// If the platform deletes this task before executing it, we also deregister
// it to avoid use-after-free from still-running background threads.
if (!cancelled()) DeregisterTask();
// TODO(clemensh): Move ref-count management to WasmEngine, i.e. store
// std::vector<WasmCode> there instead of in this task.
clear();
}
// Hold the {mutex_} when calling this method.
void AddCode(WasmCode* code) { code_to_log_.push_back(code); }
void AddCode(WasmCode* code) {
code_to_log_.push_back(code);
code->IncRef();
}
void Run() override {
if (cancelled()) return;
......@@ -48,12 +56,14 @@ class LogCodesTask : public Task {
for (WasmCode* code : code_to_log_) {
code->LogCode(isolate_);
}
clear();
}
void Cancel() {
// Cancel will only be called on Isolate shutdown, which happens on the
// Isolate's foreground thread. Thus no synchronization needed.
isolate_ = nullptr;
clear();
}
bool cancelled() const { return isolate_ == nullptr; }
......@@ -72,6 +82,11 @@ class LogCodesTask : public Task {
}
private:
void clear() {
WasmCode::DecrementRefCount(VectorOf(code_to_log_));
code_to_log_.clear();
}
// The mutex of the WasmEngine.
base::Mutex* const mutex_;
// The slot in the WasmEngine where this LogCodesTask is stored. This is
......
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