Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / jit / JitContext.cpp
blobb8f52307d76cfa60602a80da4536e048fd91a7ea
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"
12 #include <stdlib.h>
14 #include "jit/CacheIRSpewer.h"
15 #include "jit/CompileWrappers.h"
16 #include "jit/Ion.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"
27 #endif
29 #if defined(ANDROID)
30 # include <sys/system_properties.h>
31 #endif
33 using namespace js;
34 using namespace js::jit;
36 namespace js::jit {
37 class TempAllocator;
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()) {
47 return nullptr;
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) {
65 MOZ_ASSERT(rt);
66 SetJitContext(this);
69 JitContext::JitContext(JSContext* cx)
70 : cx(cx), runtime(CompileRuntime::get(cx->runtime())) {
71 SetJitContext(this);
74 JitContext::JitContext() {
75 #ifdef DEBUG
76 isCompilingWasm_ = true;
77 #endif
78 SetJitContext(this);
81 JitContext::~JitContext() {
82 MOZ_ASSERT(TlsJitContext.get() == this);
83 TlsJitContext.set(nullptr);
86 bool jit::InitializeJit() {
87 if (!TlsJitContext.init()) {
88 return false;
91 CheckLogging();
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);
98 #endif
100 #if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
101 // Compute flags.
102 js::jit::CPUInfo::ComputeFlags();
103 #endif
105 #if defined(JS_CODEGEN_ARM)
106 InitARMFlags();
107 #endif
109 #ifdef JS_CODEGEN_ARM64
110 // Initialize instruction cache flushing.
111 vixl::CPU::SetUp();
112 #endif
114 #ifndef JS_CODEGEN_NONE
115 MOZ_ASSERT(js::jit::CPUFlagsHaveBeenComputed());
116 #endif
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()) {
129 return false;
133 PerfSpewer::Init();
134 return true;
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();
146 #else
147 return false;
148 #endif
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();
158 #else
159 return true;
160 #endif