1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "jit/JitContext.h"
9 #include "mozilla/Assertions.h"
10 #include "mozilla/ThreadLocal.h"
14 #include "jit/CacheIRSpewer.h"
15 #include "jit/CompileWrappers.h"
17 #include "jit/JitCode.h"
18 #include "jit/JitOptions.h"
19 #include "jit/JitSpewer.h"
20 #include "jit/MacroAssembler.h"
21 #include "jit/PerfSpewer.h"
22 #include "js/HeapAPI.h"
23 #include "vm/JSContext.h"
25 #ifdef JS_CODEGEN_ARM64
26 # include "jit/arm64/vixl/Cpu-vixl.h"
30 # include <sys/system_properties.h>
34 using namespace js::jit
;
40 // Assert that JitCode is gc::Cell aligned.
41 static_assert(sizeof(JitCode
) % gc::CellAlignBytes
== 0);
43 static MOZ_THREAD_LOCAL(JitContext
*) TlsJitContext
;
45 static JitContext
* CurrentJitContext() {
46 if (!TlsJitContext
.init()) {
49 return TlsJitContext
.get();
52 void jit::SetJitContext(JitContext
* ctx
) {
53 MOZ_ASSERT(!TlsJitContext
.get());
54 TlsJitContext
.set(ctx
);
57 JitContext
* jit::GetJitContext() {
58 MOZ_ASSERT(CurrentJitContext());
59 return CurrentJitContext();
62 JitContext
* jit::MaybeGetJitContext() { return CurrentJitContext(); }
64 JitContext::JitContext(CompileRuntime
* rt
) : runtime(rt
) {
69 JitContext::JitContext(JSContext
* cx
)
70 : cx(cx
), runtime(CompileRuntime::get(cx
->runtime())) {
74 JitContext::JitContext() {
76 isCompilingWasm_
= true;
81 JitContext::~JitContext() {
82 MOZ_ASSERT(TlsJitContext
.get() == this);
83 TlsJitContext
.set(nullptr);
86 bool jit::InitializeJit() {
87 if (!TlsJitContext
.init()) {
93 #ifdef JS_CACHEIR_SPEW
94 const char* env
= getenv("CACHEIR_LOGS");
95 if (env
&& env
[0] && env
[0] != '0') {
96 CacheIRSpewer::singleton().init(env
);
100 #if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
102 js::jit::CPUInfo::ComputeFlags();
105 #if defined(JS_CODEGEN_ARM)
109 #ifdef JS_CODEGEN_ARM64
110 // Initialize instruction cache flushing.
114 #ifndef JS_CODEGEN_NONE
115 MOZ_ASSERT(js::jit::CPUFlagsHaveBeenComputed());
118 // Note: jit flags need to be initialized after the InitARMFlags call above.
119 // This is the final point where we can set disableJitBackend = true, before
120 // we use this flag below with the HasJitBackend call.
121 if (!MacroAssembler::SupportsFloatingPoint()) {
122 JitOptions
.disableJitBackend
= true;
124 JitOptions
.supportsUnalignedAccesses
=
125 MacroAssembler::SupportsUnalignedAccesses();
127 if (HasJitBackend()) {
128 if (!InitProcessExecutableMemory()) {
137 void jit::ShutdownJit() {
138 if (HasJitBackend() && !JSRuntime::hasLiveRuntimes()) {
139 ReleaseProcessExecutableMemory();
143 bool jit::JitSupportsWasmSimd() {
144 #if defined(ENABLE_WASM_SIMD)
145 return js::jit::MacroAssembler::SupportsWasmSimd();
151 bool jit::JitSupportsAtomics() {
152 #if defined(JS_CODEGEN_ARM)
153 // Bug 1146902, bug 1077318: Enable Ion inlining of Atomics
154 // operations on ARM only when the CPU has byte, halfword, and
155 // doubleword load-exclusive and store-exclusive instructions,
156 // until we can add support for systems that don't have those.
157 return js::jit::HasLDSTREXBHD();