Commit 7daf10ad authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Annotate global handles for debuggability

This change adds labels to the various global handles used by the wasm
compilation. Labels show up in retaining path information when
debugging lifetime issues.

Change-Id: I9aee20647868b5b758412d231c817909e4130d8c
Reviewed-on: https://chromium-review.googlesource.com/c/1372124Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58229}
parent 8a5c0095
...@@ -68,7 +68,9 @@ class WasmTranslation::TranslatorImpl { ...@@ -68,7 +68,9 @@ class WasmTranslation::TranslatorImpl {
}; };
TranslatorImpl(v8::Isolate* isolate, v8::Local<v8::debug::WasmScript> script) TranslatorImpl(v8::Isolate* isolate, v8::Local<v8::debug::WasmScript> script)
: script_(isolate, script) {} : script_(isolate, script) {
script_.AnnotateStrongRetainer(kGlobalScriptHandleLabel);
}
void Init(v8::Isolate* isolate, WasmTranslation* translation, void Init(v8::Isolate* isolate, WasmTranslation* translation,
V8DebuggerAgentImpl* agent) { V8DebuggerAgentImpl* agent) {
...@@ -244,6 +246,9 @@ class WasmTranslation::TranslatorImpl { ...@@ -244,6 +246,9 @@ class WasmTranslation::TranslatorImpl {
return GetSourceInformation(isolate, func_index).reverse_offset_table; return GetSourceInformation(isolate, func_index).reverse_offset_table;
} }
static constexpr char kGlobalScriptHandleLabel[] =
"WasmTranslation::TranslatorImpl::script_";
v8::Global<v8::debug::WasmScript> script_; v8::Global<v8::debug::WasmScript> script_;
// We assume to only disassemble a subset of the functions, so store them in a // We assume to only disassemble a subset of the functions, so store them in a
...@@ -251,6 +256,8 @@ class WasmTranslation::TranslatorImpl { ...@@ -251,6 +256,8 @@ class WasmTranslation::TranslatorImpl {
std::unordered_map<int, WasmSourceInformation> source_informations_; std::unordered_map<int, WasmSourceInformation> source_informations_;
}; };
constexpr char WasmTranslation::TranslatorImpl::kGlobalScriptHandleLabel[];
WasmTranslation::WasmTranslation(v8::Isolate* isolate) : isolate_(isolate) {} WasmTranslation::WasmTranslation(v8::Isolate* isolate) : isolate_(isolate) {}
WasmTranslation::~WasmTranslation() { Clear(); } WasmTranslation::~WasmTranslation() { Clear(); }
......
...@@ -236,7 +236,10 @@ namespace { ...@@ -236,7 +236,10 @@ namespace {
class AsyncCompilationResolver : public i::wasm::CompilationResultResolver { class AsyncCompilationResolver : public i::wasm::CompilationResultResolver {
public: public:
AsyncCompilationResolver(i::Isolate* isolate, i::Handle<i::JSPromise> promise) AsyncCompilationResolver(i::Isolate* isolate, i::Handle<i::JSPromise> promise)
: promise_(isolate->global_handles()->Create(*promise)) {} : promise_(isolate->global_handles()->Create(*promise)) {
i::GlobalHandles::AnnotateStrongRetainer(promise_.location(),
kGlobalPromiseHandle);
}
~AsyncCompilationResolver() override { ~AsyncCompilationResolver() override {
i::GlobalHandles::Destroy(promise_.location()); i::GlobalHandles::Destroy(promise_.location());
...@@ -261,10 +264,14 @@ class AsyncCompilationResolver : public i::wasm::CompilationResultResolver { ...@@ -261,10 +264,14 @@ class AsyncCompilationResolver : public i::wasm::CompilationResultResolver {
} }
private: private:
static constexpr char kGlobalPromiseHandle[] =
"AsyncCompilationResolver::promise_";
bool finished_ = false; bool finished_ = false;
i::Handle<i::JSPromise> promise_; i::Handle<i::JSPromise> promise_;
}; };
constexpr char AsyncCompilationResolver::kGlobalPromiseHandle[];
// This class resolves the result of WebAssembly.instantiate(module, imports). // This class resolves the result of WebAssembly.instantiate(module, imports).
// It just places the instantiation result in the supplied {promise}. // It just places the instantiation result in the supplied {promise}.
class InstantiateModuleResultResolver class InstantiateModuleResultResolver
...@@ -272,7 +279,10 @@ class InstantiateModuleResultResolver ...@@ -272,7 +279,10 @@ class InstantiateModuleResultResolver
public: public:
InstantiateModuleResultResolver(i::Isolate* isolate, InstantiateModuleResultResolver(i::Isolate* isolate,
i::Handle<i::JSPromise> promise) i::Handle<i::JSPromise> promise)
: promise_(isolate->global_handles()->Create(*promise)) {} : promise_(isolate->global_handles()->Create(*promise)) {
i::GlobalHandles::AnnotateStrongRetainer(promise_.location(),
kGlobalPromiseHandle);
}
~InstantiateModuleResultResolver() override { ~InstantiateModuleResultResolver() override {
i::GlobalHandles::Destroy(promise_.location()); i::GlobalHandles::Destroy(promise_.location());
...@@ -294,9 +304,13 @@ class InstantiateModuleResultResolver ...@@ -294,9 +304,13 @@ class InstantiateModuleResultResolver
} }
private: private:
static constexpr char kGlobalPromiseHandle[] =
"InstantiateModuleResultResolver::promise_";
i::Handle<i::JSPromise> promise_; i::Handle<i::JSPromise> promise_;
}; };
constexpr char InstantiateModuleResultResolver::kGlobalPromiseHandle[];
// This class resolves the result of WebAssembly.instantiate(bytes, imports). // This class resolves the result of WebAssembly.instantiate(bytes, imports).
// For that it creates a new {JSObject} which contains both the provided // For that it creates a new {JSObject} which contains both the provided
// {WasmModuleObject} and the resulting {WebAssemblyInstanceObject} itself. // {WasmModuleObject} and the resulting {WebAssemblyInstanceObject} itself.
...@@ -308,7 +322,12 @@ class InstantiateBytesResultResolver ...@@ -308,7 +322,12 @@ class InstantiateBytesResultResolver
i::Handle<i::WasmModuleObject> module) i::Handle<i::WasmModuleObject> module)
: isolate_(isolate), : isolate_(isolate),
promise_(isolate_->global_handles()->Create(*promise)), promise_(isolate_->global_handles()->Create(*promise)),
module_(isolate_->global_handles()->Create(*module)) {} module_(isolate_->global_handles()->Create(*module)) {
i::GlobalHandles::AnnotateStrongRetainer(promise_.location(),
kGlobalPromiseHandle);
i::GlobalHandles::AnnotateStrongRetainer(module_.location(),
kGlobalModuleHandle);
}
~InstantiateBytesResultResolver() override { ~InstantiateBytesResultResolver() override {
i::GlobalHandles::Destroy(promise_.location()); i::GlobalHandles::Destroy(promise_.location());
...@@ -354,11 +373,18 @@ class InstantiateBytesResultResolver ...@@ -354,11 +373,18 @@ class InstantiateBytesResultResolver
} }
private: private:
static constexpr char kGlobalPromiseHandle[] =
"InstantiateBytesResultResolver::promise_";
static constexpr char kGlobalModuleHandle[] =
"InstantiateBytesResultResolver::module_";
i::Isolate* isolate_; i::Isolate* isolate_;
i::Handle<i::JSPromise> promise_; i::Handle<i::JSPromise> promise_;
i::Handle<i::WasmModuleObject> module_; i::Handle<i::WasmModuleObject> module_;
}; };
constexpr char InstantiateBytesResultResolver::kGlobalPromiseHandle[];
constexpr char InstantiateBytesResultResolver::kGlobalModuleHandle[];
// This class is the {CompilationResultResolver} for // This class is the {CompilationResultResolver} for
// WebAssembly.instantiate(bytes, imports). When compilation finishes, // WebAssembly.instantiate(bytes, imports). When compilation finishes,
// {AsyncInstantiate} is started on the compilation result. // {AsyncInstantiate} is started on the compilation result.
...@@ -373,7 +399,14 @@ class AsyncInstantiateCompileResultResolver ...@@ -373,7 +399,14 @@ class AsyncInstantiateCompileResultResolver
maybe_imports_(maybe_imports.is_null() maybe_imports_(maybe_imports.is_null()
? maybe_imports ? maybe_imports
: isolate_->global_handles()->Create( : isolate_->global_handles()->Create(
*maybe_imports.ToHandleChecked())) {} *maybe_imports.ToHandleChecked())) {
i::GlobalHandles::AnnotateStrongRetainer(promise_.location(),
kGlobalPromiseHandle);
if (!maybe_imports_.is_null()) {
i::GlobalHandles::AnnotateStrongRetainer(
maybe_imports_.ToHandleChecked().location(), kGlobalImportsHandle);
}
}
~AsyncInstantiateCompileResultResolver() override { ~AsyncInstantiateCompileResultResolver() override {
i::GlobalHandles::Destroy(promise_.location()); i::GlobalHandles::Destroy(promise_.location());
...@@ -401,12 +434,18 @@ class AsyncInstantiateCompileResultResolver ...@@ -401,12 +434,18 @@ class AsyncInstantiateCompileResultResolver
} }
private: private:
static constexpr char kGlobalPromiseHandle[] =
"AsyncInstantiateCompileResultResolver::promise_";
static constexpr char kGlobalImportsHandle[] =
"AsyncInstantiateCompileResultResolver::module_";
bool finished_ = false; bool finished_ = false;
i::Isolate* isolate_; i::Isolate* isolate_;
i::Handle<i::JSPromise> promise_; i::Handle<i::JSPromise> promise_;
i::MaybeHandle<i::JSReceiver> maybe_imports_; i::MaybeHandle<i::JSReceiver> maybe_imports_;
}; };
constexpr char AsyncInstantiateCompileResultResolver::kGlobalPromiseHandle[];
constexpr char AsyncInstantiateCompileResultResolver::kGlobalImportsHandle[];
} // namespace } // namespace
// Web IDL: '[EnforceRange] unsigned long' // Web IDL: '[EnforceRange] unsigned long'
......
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