Commit e637154b authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[wasm] Fix compiled-module-management lifetime issues.

This makes sure the test in question does not rely on specific lifetime
characteristics for local variables within a function. Note that these
lifetimes are not specified by JavaScript and are not observable within
JavaScript proper. The natives syntax however makes it observable.

BUG=v8:5345
TEST=mjsunit/wasm/compiled-module-management
R=mtrofin@chromium.org

Review-Url: https://codereview.chromium.org/2474053002
Cr-Commit-Position: refs/heads/master@{#40733}
parent eaac3f0d
...@@ -2,15 +2,21 @@ ...@@ -2,15 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO (mtrofin): re-enable ignition (v8:5345)
// Flags: --no-turbo --no-ignition --no-ignition-staging
// Flags: --expose-wasm --expose-gc --allow-natives-syntax // Flags: --expose-wasm --expose-gc --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/wasm-module-builder.js");
// Use global variables for all values where the test wants to maintain strict
// control over value lifetime. Using local variables would not give sufficient
// guarantees of the value lifetime.
var module;
var instance1;
var instance2;
var instance3;
var instance4;
(function CompiledModuleInstancesAreGCed() { (function CompiledModuleInstancesInitialize1to3() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
...@@ -20,31 +26,46 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -20,31 +26,46 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprCallFunction, 0 kExprCallFunction, 0
]).exportFunc(); ]).exportFunc();
var module = new WebAssembly.Module(builder.toBuffer()); module = new WebAssembly.Module(builder.toBuffer());
%ValidateWasmModuleState(module); %ValidateWasmModuleState(module);
%ValidateWasmInstancesChain(module, 0); %ValidateWasmInstancesChain(module, 0);
var i1 = new WebAssembly.Instance(module, {getValue: () => 1}); instance1 = new WebAssembly.Instance(module, {getValue: () => 1});
%ValidateWasmInstancesChain(module, 1); %ValidateWasmInstancesChain(module, 1);
var i2 = new WebAssembly.Instance(module, {getValue: () => 2}); instance2 = new WebAssembly.Instance(module, {getValue: () => 2});
%ValidateWasmInstancesChain(module, 2); %ValidateWasmInstancesChain(module, 2);
var i3 = new WebAssembly.Instance(module, {getValue: () => 3}); instance3 = new WebAssembly.Instance(module, {getValue: () => 3});
%ValidateWasmInstancesChain(module, 3); %ValidateWasmInstancesChain(module, 3);
})();
assertEquals(1, i1.exports.f()); (function CompiledModuleInstancesClear1() {
i1 = null; assertEquals(1, instance1.exports.f());
gc(); instance1 = null;
%ValidateWasmInstancesChain(module, 2); })();
assertEquals(3, i3.exports.f());
i3 = null; gc();
gc(); %ValidateWasmInstancesChain(module, 2);
%ValidateWasmInstancesChain(module, 1);
assertEquals(2, i2.exports.f()); (function CompiledModuleInstancesClear3() {
i2 = null; assertEquals(3, instance3.exports.f());
gc(); instance3 = null;
%ValidateWasmModuleState(module); })();
var i4 = new WebAssembly.Instance(module, {getValue: () => 4});
assertEquals(4, i4.exports.f()); gc();
%ValidateWasmInstancesChain(module, 1);
(function CompiledModuleInstancesClear2() {
assertEquals(2, instance2.exports.f());
instance2 = null;
})();
gc();
%ValidateWasmModuleState(module);
(function CompiledModuleInstancesInitialize4AndClearModule() {
instance4 = new WebAssembly.Instance(module, {getValue: () => 4});
assertEquals(4, instance4.exports.f());
module = null; module = null;
gc();
%ValidateWasmOrphanedInstance(i4);
})(); })();
gc();
%ValidateWasmOrphanedInstance(instance4);
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