Bug 1899862 - Enable JS PI for arm64 simulator. r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D212166
This commit is contained in:
Yury Delendik 2024-06-18 13:10:23 +00:00
parent 3337cbff84
commit 940b74cd02
3 changed files with 56 additions and 11 deletions

View File

@ -800,7 +800,7 @@ def default_wasm_jspi(
tail_calls,
target,
):
if not jit_enabled or simulator:
if not jit_enabled:
return
if not gc or not tail_calls:
@ -809,6 +809,9 @@ def default_wasm_jspi(
if not is_nightly:
return
if simulator and (simulator[0] == "arm64"):
return True
if target.cpu in ("x86_64", "aarch64"):
return True
@ -842,8 +845,8 @@ def wasm_jspi(value, jit_enabled, simulator, gc, tail_calls, no_experimental, ta
if not tail_calls:
die("--enable-wasm-jspi requires --enable-wasm-tail-calls")
if simulator:
die("--enable-wasm-jspi is not supported for simulators")
if simulator and (simulator[0] != "arm64"):
die("--enable-wasm-jspi is only supported for arm64 simulator")
if target.cpu in ("x86_64", "aarch64"):
return True

View File

@ -36,6 +36,10 @@
#include "wasm/WasmGcObject-inl.h"
#include "wasm/WasmInstance-inl.h"
#ifdef JS_CODEGEN_ARM64
# include "jit/arm64/vixl/Simulator-vixl.h"
#endif
#ifdef XP_WIN
# include "util/WindowsWrapper.h"
#endif
@ -78,6 +82,26 @@ void SuspenderObjectData::restoreTIBStackFields() {
}
# endif
# ifdef JS_SIMULATOR_ARM64
void SuspenderObjectData::switchSimulatorToMain() {
auto* sim = Simulator::Current();
suspendableSP_ = (void*)sim->xreg(Registers::sp, vixl::Reg31IsStackPointer);
suspendableFP_ = (void*)sim->xreg(Registers::fp);
sim->set_xreg(Registers::sp, (int64_t)mainSP_, vixl::Debugger::LogRegWrites,
vixl::Reg31IsStackPointer);
sim->set_xreg(Registers::fp, (int64_t)mainFP_);
}
void SuspenderObjectData::switchSimulatorToSuspendable() {
auto* sim = Simulator::Current();
mainSP_ = (void*)sim->xreg(Registers::sp, vixl::Reg31IsStackPointer);
mainFP_ = (void*)sim->xreg(Registers::fp);
sim->set_xreg(Registers::sp, (int64_t)suspendableSP_,
vixl::Debugger::LogRegWrites, vixl::Reg31IsStackPointer);
sim->set_xreg(Registers::fp, (int64_t)suspendableFP_);
}
# endif
// Slots that used in various JSFunctionExtended below.
const size_t SUSPENDER_SLOT = 0;
const size_t WRAPPED_FN_SLOT = 1;
@ -397,16 +421,28 @@ bool CallImportOnMainThread(JSContext* cx, Instance* instance,
MOZ_ASSERT(suspender->state() == SuspenderState::Active);
suspender->setSuspended(cx);
# ifdef JS_SIMULATOR
# ifdef JS_SIMULATOR_ARM64
// The simulator is using its own stack, however switching is needed for
// virtual registers.
stacks->switchSimulatorToMain();
bool res = CallImportData::Call(&data);
stacks->switchSimulatorToSuspendable();
# else
# error "not supported"
# endif
# else
// The platform specific code below inserts offsets as strings into inline
// assembly. CHECK_OFFSETS verifies the specified literals in macros below.
# define CHECK_OFFSETS(MAIN_FP_OFFSET, MAIN_SP_OFFSET, SUSPENDABLE_FP_OFFSET, \
SUSPENDABLE_SP_OFFSET) \
static_assert((MAIN_FP_OFFSET) == SuspenderObjectData::offsetOfMainFP() && \
(MAIN_SP_OFFSET) == SuspenderObjectData::offsetOfMainSP() && \
(SUSPENDABLE_FP_OFFSET) == \
SuspenderObjectData::offsetOfSuspendableFP() && \
(SUSPENDABLE_SP_OFFSET) == \
SuspenderObjectData::offsetOfSuspendableSP());
# define CHECK_OFFSETS(MAIN_FP_OFFSET, MAIN_SP_OFFSET, \
SUSPENDABLE_FP_OFFSET, SUSPENDABLE_SP_OFFSET) \
static_assert( \
(MAIN_FP_OFFSET) == SuspenderObjectData::offsetOfMainFP() && \
(MAIN_SP_OFFSET) == SuspenderObjectData::offsetOfMainSP() && \
(SUSPENDABLE_FP_OFFSET) == \
SuspenderObjectData::offsetOfSuspendableFP() && \
(SUSPENDABLE_SP_OFFSET) == \
SuspenderObjectData::offsetOfSuspendableSP());
// The following assembly code temporarily switches FP/SP pointers to be on
// main stack, while maintaining frames linking. After
@ -532,6 +568,7 @@ bool CallImportOnMainThread(JSContext* cx, Instance* instance,
MOZ_CRASH("Not supported for this platform");
# endif
// clang-format on
# endif
bool ok = res;
suspender->setActive(cx);

View File

@ -178,6 +178,11 @@ class SuspenderObjectData
void restoreTIBStackFields();
#endif
#if defined(JS_SIMULATOR_ARM64)
void switchSimulatorToMain();
void switchSimulatorToSuspendable();
#endif
static constexpr size_t offsetOfMainFP() {
return offsetof(SuspenderObjectData, mainFP_);
}