Commit b7a7e2fb authored by Ben Smith's avatar Ben Smith Committed by Commit Bot

[wasm] Call OnAfterCompile when cloning Module

The debugger should be notified whenever a new Module is created so it
displayed properly. Without this change, the Module is only displayed once,
regardless of the number of times it is referenced (by other Workers, say).
That is potentially reasonable behavior, but it doesn't match the way
JavaScript does it.

With this change, the debugger will display the sources like this:

```
▼ top
   localhost
  ▼ wasm
    ▼ wasm-82570336
        wasm-82570336-0

▼ worker.js
   localhost
  ▼ wasm
     wasm-82570336
```

Change-Id: I61177e8a07e36ea8e2234aa25e75b1489c9da95f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1666616Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Ben Smith <binji@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62297}
parent 8d821550
......@@ -1153,6 +1153,19 @@ RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {
return *module_object;
}
// Create a new Module object using the same NativeModule.
RUNTIME_FUNCTION(Runtime_CloneWasmModule) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_object, 0);
Handle<WasmModuleObject> new_module_object =
wasm::WasmEngine::GetWasmEngine()->ImportNativeModule(
isolate, module_object->shared_native_module());
return *new_module_object;
}
RUNTIME_FUNCTION(Runtime_HeapObjectVerify) {
HandleScope shs(isolate);
DCHECK_EQ(1, args.length());
......
......@@ -434,6 +434,7 @@ namespace internal {
F(Abort, 1, 1) \
F(AbortJS, 1, 1) \
F(ClearFunctionFeedback, 1, 1) \
F(CloneWasmModule, 1, 1) \
F(CompleteInobjectSlackTracking, 1, 1) \
F(ConstructConsString, 2, 1) \
F(ConstructSlicedString, 2, 1) \
......
......@@ -453,6 +453,9 @@ Handle<WasmModuleObject> WasmEngine::ImportNativeModule(
DCHECK_EQ(1, native_modules_.count(native_module));
native_modules_[native_module]->isolates.insert(isolate);
}
// Finish the Wasm script now and make it public to the debugger.
isolate->debug()->OnAfterCompile(script);
return module_object;
}
......
......@@ -645,6 +645,8 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
// Log the code within the generated module for profiling.
native_module->LogWasmCodes(isolate);
// Finish the Wasm script now and make it public to the debugger.
isolate->debug()->OnAfterCompile(script);
return module_object;
}
......
Tests that cloning a module notifies the debugger
Got URL: wasm://wasm/wasm-cae8f226/wasm-cae8f226-0
Got URL: wasm://wasm/wasm-cae8f226/wasm-cae8f226-0
Got URL: wasm://wasm/wasm-cae8f226/wasm-cae8f226-0
Done!
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests that cloning a module notifies the debugger');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addFunction('f', kSig_v_v).addBody([]).exportAs('f');
let moduleBytes = JSON.stringify(builder.toArray());
contextGroup.addScript(`
function test(moduleBytes) {
let wireBytes = new Uint8Array(moduleBytes);
let module = new WebAssembly.Module(wireBytes.buffer);
let serialized = %SerializeWasmModule(module);
let module2 = %DeserializeWasmModule(serialized, wireBytes);
let module3 = %CloneWasmModule(module);
}
`);
let scriptsSeen = 0;
Protocol.Debugger.onScriptParsed(msg => {
let url = msg.params.url;
if (url.startsWith('wasm://')) {
InspectorTest.log(`Got URL: ${url}`);
if (++scriptsSeen == 3) {
InspectorTest.log('Done!');
InspectorTest.completeTest();
}
}
});
Protocol.Debugger.enable();
Protocol.Runtime.evaluate({expression: `test(${moduleBytes});`});
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