Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSC] Cache softStackLimit in Wasm::Instance #14267

Conversation

Constellation
Copy link
Member

@Constellation Constellation commented May 23, 2023

5be4a1f

[JSC] Cache softStackLimit in Wasm::Instance
https://bugs.webkit.org/show_bug.cgi?id=257230
rdar://109740794

Reviewed by Justin Michaud.

Let's store m_softStackLimit in Wasm::Instance directly. Wasm::Instance is strictly tied to one VM.
This patch associates Wasm::Instance to VM, and we update this field of Instance when VM's m_softStackLimit
changes (this is very rare). So we do not need to do double-load to stack overflow check in each prologue
of wasm functions.

* Source/JavaScriptCore/jit/AssemblyHelpers.cpp:
(JSC::AssemblyHelpers::checkWasmStackOverflow):
* Source/JavaScriptCore/llint/WebAssembly.asm:
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::updateStackLimits):
(JSC::VM::registerWasmInstance):
* Source/JavaScriptCore/runtime/VM.h:
* Source/JavaScriptCore/wasm/WasmBBQJIT.cpp:
(JSC::Wasm::BBQJIT::addTopLevel):
(JSC::Wasm::BBQJIT::addLoopOSREntrypoint):
* Source/JavaScriptCore/wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::Instance):
* Source/JavaScriptCore/wasm/WasmInstance.h:
(JSC::Wasm::Instance::offsetOfSoftStackLimit):
(JSC::Wasm::Instance::updateSoftStackLimit):

Canonical link: https://commits.webkit.org/264531@main

b6592ad

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc-arm64 βœ… πŸ›  tv ❌ πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-armv7
βœ… πŸ›  tv-sim βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  watch βœ… πŸ›  jsc-mips
βœ… πŸ›  πŸ§ͺ unsafe-merge βœ… πŸ›  watch-sim βœ… πŸ§ͺ jsc-mips-tests

@Constellation Constellation self-assigned this May 23, 2023
@Constellation Constellation added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label May 23, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@Constellation Constellation force-pushed the eng/JSC-Cache-softStackLimit-in-WasmInstance branch from 45858db to b6592ad Compare May 24, 2023 22:43
@Constellation Constellation marked this pull request as ready for review May 24, 2023 22:43
@Constellation Constellation requested a review from a team as a code owner May 24, 2023 22:43
@@ -1086,6 +1094,9 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {
Ref<Waiter> m_syncWaiter;

Vector<Function<void()>> m_didPopListeners;
#if ENABLE(WEBASSEMBLY)
ThreadSafeWeakHashSet<Wasm::Instance> m_wasmInstances;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is WeakHashSet. So Wasm::Instance will be removed automatically when it dies.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: there is a 1 to 1 correspondence between VM and WasmInstance, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. WasmInstance -> VM. But no VM -> WasmInstance.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part I want to make sure of is that a WasmInstance can only be associated with 1 VM, correct? It is never associated with more than 1 VM at the same time, correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. Yusuke pointed out offline that the commit msg already addressed this: "Wasm::Instance is strictly tied to one VM."

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2023
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label May 25, 2023
Copy link
Contributor

@justinmichaud justinmichaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label May 25, 2023
https://bugs.webkit.org/show_bug.cgi?id=257230
rdar://109740794

Reviewed by Justin Michaud.

Let's store m_softStackLimit in Wasm::Instance directly. Wasm::Instance is strictly tied to one VM.
This patch associates Wasm::Instance to VM, and we update this field of Instance when VM's m_softStackLimit
changes (this is very rare). So we do not need to do double-load to stack overflow check in each prologue
of wasm functions.

* Source/JavaScriptCore/jit/AssemblyHelpers.cpp:
(JSC::AssemblyHelpers::checkWasmStackOverflow):
* Source/JavaScriptCore/llint/WebAssembly.asm:
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::updateStackLimits):
(JSC::VM::registerWasmInstance):
* Source/JavaScriptCore/runtime/VM.h:
* Source/JavaScriptCore/wasm/WasmBBQJIT.cpp:
(JSC::Wasm::BBQJIT::addTopLevel):
(JSC::Wasm::BBQJIT::addLoopOSREntrypoint):
* Source/JavaScriptCore/wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::Instance):
* Source/JavaScriptCore/wasm/WasmInstance.h:
(JSC::Wasm::Instance::offsetOfSoftStackLimit):
(JSC::Wasm::Instance::updateSoftStackLimit):

Canonical link: https://commits.webkit.org/264531@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/JSC-Cache-softStackLimit-in-WasmInstance branch from b6592ad to 5be4a1f Compare May 25, 2023 19:02
@webkit-commit-queue
Copy link
Collaborator

Committed 264531@main (5be4a1f): https://commits.webkit.org/264531@main

Reviewed commits have been landed. Closing PR #14267 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 5be4a1f into WebKit:main May 25, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label May 25, 2023
@Constellation Constellation deleted the eng/JSC-Cache-softStackLimit-in-WasmInstance branch May 25, 2023 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
6 participants