Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / jit / CompileWrappers.cpp
blob602ff61cc7745601c28d7ad648d5b26a4a5e53dc
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/CompileWrappers.h"
9 #include "gc/Heap.h"
10 #include "gc/Zone.h"
11 #include "jit/Ion.h"
12 #include "jit/JitRuntime.h"
13 #include "vm/Realm.h"
15 using namespace js;
16 using namespace js::jit;
18 JSRuntime* CompileRuntime::runtime() {
19 return reinterpret_cast<JSRuntime*>(this);
22 /* static */
23 CompileRuntime* CompileRuntime::get(JSRuntime* rt) {
24 return reinterpret_cast<CompileRuntime*>(rt);
27 #ifdef JS_GC_ZEAL
28 const uint32_t* CompileRuntime::addressOfGCZealModeBits() {
29 return runtime()->gc.addressOfZealModeBits();
31 #endif
33 const JitRuntime* CompileRuntime::jitRuntime() {
34 return runtime()->jitRuntime();
37 GeckoProfilerRuntime& CompileRuntime::geckoProfiler() {
38 return runtime()->geckoProfiler();
41 bool CompileRuntime::hadOutOfMemory() { return runtime()->hadOutOfMemory; }
43 bool CompileRuntime::profilingScripts() { return runtime()->profilingScripts; }
45 const JSAtomState& CompileRuntime::names() { return *runtime()->commonNames; }
47 const PropertyName* CompileRuntime::emptyString() {
48 return runtime()->emptyString;
51 const StaticStrings& CompileRuntime::staticStrings() {
52 return *runtime()->staticStrings;
55 const WellKnownSymbols& CompileRuntime::wellKnownSymbols() {
56 return *runtime()->wellKnownSymbols;
59 const JSClass* CompileRuntime::maybeWindowProxyClass() {
60 return runtime()->maybeWindowProxyClass();
63 const void* CompileRuntime::mainContextPtr() {
64 return runtime()->mainContextFromAnyThread();
67 const void* CompileRuntime::addressOfJitStackLimit() {
68 return runtime()->mainContextFromAnyThread()->addressOfJitStackLimit();
71 const void* CompileRuntime::addressOfInterruptBits() {
72 return runtime()->mainContextFromAnyThread()->addressOfInterruptBits();
75 const void* CompileRuntime::addressOfZone() {
76 return runtime()->mainContextFromAnyThread()->addressOfZone();
79 const void* CompileRuntime::addressOfMegamorphicCache() {
80 return &runtime()->caches().megamorphicCache;
83 const void* CompileRuntime::addressOfMegamorphicSetPropCache() {
84 return runtime()->caches().megamorphicSetPropCache.get();
87 const void* CompileRuntime::addressOfStringToAtomCache() {
88 return &runtime()->caches().stringToAtomCache;
91 const void* CompileRuntime::addressOfLastBufferedWholeCell() {
92 return runtime()->gc.addressOfLastBufferedWholeCell();
95 const DOMCallbacks* CompileRuntime::DOMcallbacks() {
96 return runtime()->DOMcallbacks;
99 bool CompileRuntime::runtimeMatches(JSRuntime* rt) { return rt == runtime(); }
101 Zone* CompileZone::zone() { return reinterpret_cast<Zone*>(this); }
103 /* static */
104 CompileZone* CompileZone::get(Zone* zone) {
105 return reinterpret_cast<CompileZone*>(zone);
108 CompileRuntime* CompileZone::runtime() {
109 return CompileRuntime::get(zone()->runtimeFromAnyThread());
112 bool CompileZone::isAtomsZone() { return zone()->isAtomsZone(); }
114 #ifdef DEBUG
115 const void* CompileRuntime::addressOfIonBailAfterCounter() {
116 return runtime()->jitRuntime()->addressOfIonBailAfterCounter();
118 #endif
120 const uint32_t* CompileZone::addressOfNeedsIncrementalBarrier() {
121 // Cast away relaxed atomic wrapper for JIT access to barrier state.
122 const mozilla::Atomic<uint32_t, mozilla::Relaxed>* ptr =
123 zone()->addressOfNeedsIncrementalBarrier();
124 return reinterpret_cast<const uint32_t*>(ptr);
127 uint32_t* CompileZone::addressOfTenuredAllocCount() {
128 return zone()->addressOfTenuredAllocCount();
131 gc::FreeSpan** CompileZone::addressOfFreeList(gc::AllocKind allocKind) {
132 return zone()->arenas.addressOfFreeList(allocKind);
135 bool CompileZone::allocNurseryObjects() {
136 return zone()->allocNurseryObjects();
139 bool CompileZone::allocNurseryStrings() {
140 return zone()->allocNurseryStrings();
143 bool CompileZone::allocNurseryBigInts() {
144 return zone()->allocNurseryBigInts();
147 void* CompileZone::addressOfNurseryPosition() {
148 return zone()->runtimeFromAnyThread()->gc.addressOfNurseryPosition();
151 void* CompileZone::addressOfNurseryAllocatedSites() {
152 JSRuntime* rt = zone()->runtimeFromAnyThread();
153 return rt->gc.nursery().addressOfNurseryAllocatedSites();
156 bool CompileZone::canNurseryAllocateStrings() {
157 return zone()->allocNurseryStrings();
160 bool CompileZone::canNurseryAllocateBigInts() {
161 return zone()->allocNurseryBigInts();
164 gc::AllocSite* CompileZone::catchAllAllocSite(JS::TraceKind traceKind,
165 gc::CatchAllAllocSite siteKind) {
166 if (siteKind == gc::CatchAllAllocSite::Optimized) {
167 return zone()->optimizedAllocSite();
169 return zone()->unknownAllocSite(traceKind);
172 JS::Realm* CompileRealm::realm() { return reinterpret_cast<JS::Realm*>(this); }
174 /* static */
175 CompileRealm* CompileRealm::get(JS::Realm* realm) {
176 return reinterpret_cast<CompileRealm*>(realm);
179 CompileZone* CompileRealm::zone() { return CompileZone::get(realm()->zone()); }
181 CompileRuntime* CompileRealm::runtime() {
182 return CompileRuntime::get(realm()->runtimeFromAnyThread());
185 const mozilla::non_crypto::XorShift128PlusRNG*
186 CompileRealm::addressOfRandomNumberGenerator() {
187 return realm()->addressOfRandomNumberGenerator();
190 const JitZone* CompileZone::jitZone() { return zone()->jitZone(); }
192 const GlobalObject* CompileRealm::maybeGlobal() {
193 // This uses unsafeUnbarrieredMaybeGlobal() so as not to trigger the read
194 // barrier on the global from off thread. This is safe because we
195 // abort Ion compilation when we GC.
196 return realm()->unsafeUnbarrieredMaybeGlobal();
199 const uint32_t* CompileRealm::addressOfGlobalWriteBarriered() {
200 return &realm()->globalWriteBarriered;
203 bool CompileZone::hasRealmWithAllocMetadataBuilder() {
204 return zone()->hasRealmWithAllocMetadataBuilder();
207 JitCompileOptions::JitCompileOptions()
208 : profilerSlowAssertionsEnabled_(false),
209 offThreadCompilationAvailable_(false) {}
211 JitCompileOptions::JitCompileOptions(JSContext* cx) {
212 profilerSlowAssertionsEnabled_ =
213 cx->runtime()->geckoProfiler().enabled() &&
214 cx->runtime()->geckoProfiler().slowAssertionsEnabled();
215 offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx);
216 #ifdef DEBUG
217 ionBailAfterEnabled_ = cx->runtime()->jitRuntime()->ionBailAfterEnabled();
218 #endif