summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi-tests/testsJit.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /js/src/jsapi-tests/testsJit.cpp
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jsapi-tests/testsJit.cpp')
-rw-r--r--js/src/jsapi-tests/testsJit.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testsJit.cpp b/js/src/jsapi-tests/testsJit.cpp
new file mode 100644
index 0000000000..2ad96c8e5d
--- /dev/null
+++ b/js/src/jsapi-tests/testsJit.cpp
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "jsapi-tests/testsJit.h"
+
+#include "jit/JitCommon.h"
+#include "jit/Linker.h"
+
+#include "jit/MacroAssembler-inl.h"
+
+// On entry to the JIT code, save every register.
+void PrepareJit(js::jit::MacroAssembler& masm) {
+ using namespace js::jit;
+#if defined(JS_CODEGEN_ARM64)
+ masm.Mov(PseudoStackPointer64, sp);
+ masm.SetStackPointer64(PseudoStackPointer64);
+#endif
+ AllocatableRegisterSet regs(RegisterSet::All());
+ LiveRegisterSet save(regs.asLiveSet());
+#if defined(JS_CODEGEN_ARM)
+ save.add(js::jit::d15);
+#endif
+#if defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64) || \
+ defined(JS_CODEGEN_LOONG64) || defined(JS_CODEGEN_RISCV64)
+ save.add(js::jit::ra);
+#elif defined(JS_USE_LINK_REGISTER)
+ save.add(js::jit::lr);
+#endif
+ masm.PushRegsInMask(save);
+}
+
+// Generate the exit path of the JIT code, which restores every register. Then,
+// make it executable and run it.
+bool ExecuteJit(JSContext* cx, js::jit::MacroAssembler& masm) {
+ using namespace js::jit;
+ AllocatableRegisterSet regs(RegisterSet::All());
+ LiveRegisterSet save(regs.asLiveSet());
+#if defined(JS_CODEGEN_ARM)
+ save.add(js::jit::d15);
+#endif
+#if defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64) || \
+ defined(JS_CODEGEN_LOONG64) || defined(JS_CODEGEN_RISCV64)
+ save.add(js::jit::ra);
+#elif defined(JS_USE_LINK_REGISTER)
+ save.add(js::jit::lr);
+#endif
+ masm.PopRegsInMask(save);
+#if defined(JS_CODEGEN_ARM64)
+ // Return using the value popped into x30.
+ masm.abiret();
+
+ // Reset stack pointer.
+ masm.SetStackPointer64(PseudoStackPointer64);
+#else
+ // Exit the JIT-ed code using the ABI return style.
+ masm.abiret();
+#endif
+
+ if (masm.oom()) {
+ return false;
+ }
+
+ Linker linker(masm);
+ JitCode* code = linker.newCode(cx, CodeKind::Other);
+ if (!code) {
+ return false;
+ }
+ if (!ExecutableAllocator::makeExecutableAndFlushICache(code->raw(),
+ code->bufferSize())) {
+ return false;
+ }
+
+ JS::AutoSuppressGCAnalysis suppress;
+ EnterTest test = code->as<EnterTest>();
+ CALL_GENERATED_0(test);
+ return true;
+}