Adopt the new WebAssembly.Global system
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2019 01:36:56 +0000 (01:36 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2019 01:36:56 +0000 (01:36 +0000)
commit7d52c0911b16b976498bd038a5dce833e417b76d
tree37309f3b7b280af3c69a056d19129ea61bc2603f
parent02ca9cd295cad6ef8b48a90a8864035be19bf34d
Adopt the new WebAssembly.Global system
https://bugs.webkit.org/show_bug.cgi?id=186552

Reviewed by Keith Miller.

JSTests:

1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness.
2. Add WebAssembly.Global tests.

* wasm/js-api/global-error.js:
(assert.throws.new.WebAssembly.Module.bin):
(new.WebAssembly.Module):
(assert.throws):
* wasm/js-api/global-external-init-from-import.js:
* wasm/js-api/globals-export.js:
* wasm/modules/js-wasm-global-namespace.js:
(assert.throws):
* wasm/modules/js-wasm-global.js:
(assert.throws):
* wasm/modules/wasm-import-wasm-export-i64-error.js:
* wasm/references/anyref_globals.js:
* wasm/references/func_ref.js:
(assert.eq.instance.exports.fix):
* wasm/spec-harness.js:
(getGlobal):
(let.console.log):
* wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js.
(reinitializeRegistry.let.handler.get return):
(module):
* wasm/spec-tests/call.wast.js:
* wasm/spec-tests/exports.wast.js:
* wasm/spec-tests/globals.wast.js:
* wasm/spec-tests/if.wast.js:
* wasm/spec-tests/imports.wast.js:
* wasm/spec-tests/linking.wast.js:
* wasm/spec-tests/memory.wast.js:
* wasm/stress/immutable-globals.js: Added.
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32):
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq):
* wasm/stress/mutable-globals-cross.js: Added.
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1):
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2):
* wasm/stress/mutable-globals.js: Added.
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64):

LayoutTests/imported/w3c:

* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt:
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt:
* web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/global/toString.any-expected.txt:
* web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt:
* web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt:
* web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt:
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt:
* web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/interface.any-expected.txt:
* web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt:
* web-platform-tests/wasm/jsapi/module/exports.any-expected.txt:
* web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt:

Source/JavaScriptCore:

This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in
staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around
"global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through
this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules.

To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance,
we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in
Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference.
And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to
have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings'
storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode.
So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings
are Portable and requires one additional dereference.

To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`,
and `set_global_ref_portable_binding`.

This patch improves WPT wasm coverage significantly.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* bytecode/BytecodeList.rb:
* heap/HeapCell.cpp:
(JSC::keepAlive):
(JSC::HeapCell::use const): Deleted.
* heap/HeapCell.h:
(JSC::keepAlive):
(JSC::HeapCell::use const):
* llint/WebAssembly.asm:
* runtime/JSGlobalObject.cpp:
* runtime/JSGlobalObject.h:
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:
* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::getGlobal):
(JSC::Wasm::AirIRGenerator::setGlobal):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::getGlobal):
(JSC::Wasm::B3IRGenerator::setGlobal):
* wasm/WasmFormat.h:
* wasm/WasmGlobal.cpp: Added.
(JSC::Wasm::Global::get const):
(JSC::Wasm::Global::set):
(JSC::Wasm::Global::visitAggregate):
* wasm/WasmGlobal.h: Added.
* wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::Instance):
(JSC::Wasm::Instance::setGlobal):
(JSC::Wasm::Instance::linkGlobal):
* wasm/WasmInstance.h:
(JSC::Wasm::Instance::loadI32Global const):
(JSC::Wasm::Instance::loadI64Global const):
(JSC::Wasm::Instance::setGlobal):
(JSC::Wasm::Instance::globalsToBinding):
(JSC::Wasm::Instance::getGlobalBinding):
* wasm/WasmLLIntGenerator.cpp:
(JSC::Wasm::LLIntGenerator::getGlobal):
(JSC::Wasm::LLIntGenerator::setGlobal):
* wasm/WasmModuleInformation.h:
* wasm/WasmOperations.cpp:
(JSC::Wasm::operationWasmWriteBarrierSlowPath):
* wasm/WasmOperations.h:
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseImport):
(JSC::Wasm::SectionParser::parseGlobal):
(JSC::Wasm::SectionParser::parseExport):
(JSC::Wasm::SectionParser::parseInitExpr):
(JSC::Wasm::SectionParser::parseGlobalType):
* wasm/WasmSectionParser.h:
* wasm/WasmSlowPaths.cpp:
(JSC::LLInt::WASM_SLOW_PATH_DECL):
* wasm/WasmSlowPaths.h:
* wasm/WasmValidate.cpp:
(JSC::Wasm::Validate::setGlobal):
* wasm/js/JSWebAssembly.cpp:
* wasm/js/JSWebAssemblyGlobal.cpp: Added.
(JSC::JSWebAssemblyGlobal::create):
(JSC::JSWebAssemblyGlobal::createStructure):
(JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal):
(JSC::JSWebAssemblyGlobal::finishCreation):
(JSC::JSWebAssemblyGlobal::destroy):
(JSC::JSWebAssemblyGlobal::visitChildren):
* wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h.
* wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::visitChildren):
* wasm/js/JSWebAssemblyInstance.h:
* wasm/js/JSWebAssemblyMemory.cpp:
(JSC::JSWebAssemblyMemory::destroy):
* wasm/js/JSWebAssemblyMemory.h:
* wasm/js/JSWebAssemblyModule.h:
* wasm/js/JSWebAssemblyTable.h:
* wasm/js/WebAssemblyGlobalConstructor.cpp: Added.
(JSC::constructJSWebAssemblyGlobal):
(JSC::callJSWebAssemblyGlobal):
(JSC::WebAssemblyGlobalConstructor::create):
(JSC::WebAssemblyGlobalConstructor::createStructure):
(JSC::WebAssemblyGlobalConstructor::finishCreation):
(JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor):
* wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h.
* wasm/js/WebAssemblyGlobalPrototype.cpp: Added.
(JSC::getGlobal):
(JSC::webAssemblyGlobalProtoFuncValueOf):
(JSC::webAssemblyGlobalProtoGetterFuncValue):
(JSC::webAssemblyGlobalProtoSetterFuncValue):
(JSC::WebAssemblyGlobalPrototype::create):
(JSC::WebAssemblyGlobalPrototype::createStructure):
(JSC::WebAssemblyGlobalPrototype::finishCreation):
(JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype):
* wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h.
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::link):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
95 files changed:
JSTests/ChangeLog
JSTests/wasm.yaml
JSTests/wasm/js-api/global-error.js
JSTests/wasm/js-api/global-external-init-from-import.js
JSTests/wasm/js-api/globals-export.js
JSTests/wasm/modules/js-wasm-global-namespace.js
JSTests/wasm/modules/js-wasm-global.js
JSTests/wasm/modules/wasm-import-wasm-export-i64-error.js
JSTests/wasm/multi-value-spec-tests/block.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/br.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/br_if.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/call.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/call_indirect.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/func.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/if.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/loop.wast.js [new file with mode: 0644]
JSTests/wasm/multi-value-spec-tests/type.wast.js [new file with mode: 0644]
JSTests/wasm/references/anyref_globals.js
JSTests/wasm/references/func_ref.js
JSTests/wasm/spec-harness.js
JSTests/wasm/spec-harness/async_index.js [new file with mode: 0644]
JSTests/wasm/spec-harness/sync_index.js [moved from JSTests/wasm/spec-harness/index.js with 90% similarity]
JSTests/wasm/spec-tests/call.wast.js
JSTests/wasm/spec-tests/globals.wast.js
JSTests/wasm/spec-tests/if.wast.js
JSTests/wasm/spec-tests/imports.wast.js
JSTests/wasm/spec-tests/linking.wast.js
JSTests/wasm/spec-tests/memory.wast.js
JSTests/wasm/stress/immutable-globals.js [new file with mode: 0644]
JSTests/wasm/stress/mutable-globals-cross.js [new file with mode: 0644]
JSTests/wasm/stress/mutable-globals.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources-input.xcfilelist
Source/JavaScriptCore/DerivedSources-output.xcfilelist
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/bytecode/BytecodeList.rb
Source/JavaScriptCore/heap/HeapCell.cpp
Source/JavaScriptCore/heap/HeapCell.h
Source/JavaScriptCore/llint/WebAssembly.asm
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmFormat.h
Source/JavaScriptCore/wasm/WasmGlobal.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmGlobal.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmInstance.cpp
Source/JavaScriptCore/wasm/WasmInstance.h
Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp
Source/JavaScriptCore/wasm/WasmModuleInformation.h
Source/JavaScriptCore/wasm/WasmOperations.cpp
Source/JavaScriptCore/wasm/WasmOperations.h
Source/JavaScriptCore/wasm/WasmSectionParser.cpp
Source/JavaScriptCore/wasm/WasmSectionParser.h
Source/JavaScriptCore/wasm/WasmSlowPaths.cpp
Source/JavaScriptCore/wasm/WasmSlowPaths.h
Source/JavaScriptCore/wasm/WasmValidate.cpp
Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/JSWebAssemblyGlobal.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h
Source/JavaScriptCore/wasm/js/WebAssemblyGlobalConstructor.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/WebAssemblyGlobalConstructor.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/WebAssemblyGlobalPrototype.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/WebAssemblyGlobalPrototype.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp