| 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/. */ |
| 6 |
|
| 7 |
#include "jit/CompileWrappers.h" |
| 8 |
|
| 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" |
| 14 |
|
| 15 |
using namespace js; |
| 16 |
using namespace js::jit; |
| 17 |
|
| 18 |
JSRuntime* CompileRuntime::runtime() { |
| 19 |
return reinterpret_cast<JSRuntime*>(this); |
| 20 |
} |
| 21 |
|
| 22 |
/* static */ |
| 23 |
CompileRuntime* CompileRuntime::get(JSRuntime* rt) { |
| 24 |
return reinterpret_cast<CompileRuntime*>(rt); |
| 25 |
} |
| 26 |
|
| 27 |
#ifdef JS_GC_ZEAL |
| 28 |
const uint32_t* CompileRuntime::addressOfGCZealModeBits() { |
| 29 |
return runtime()->gc.addressOfZealModeBits(); |
| 30 |
} |
| 31 |
#endif |
| 32 |
|
| 33 |
const JitRuntime* CompileRuntime::jitRuntime() { |
| 34 |
return runtime()->jitRuntime(); |
| 35 |
} |
| 36 |
|
| 37 |
const GeckoProfilerRuntime& CompileRuntime::geckoProfiler() { |
| 38 |
return runtime()->geckoProfiler(); |
| 39 |
} |
| 40 |
|
| 41 |
bool CompileRuntime::hadOutOfMemory() { return runtime()->hadOutOfMemory; } |
| 42 |
|
| 43 |
bool CompileRuntime::profilingScripts() { return runtime()->profilingScripts; } |
| 44 |
|
| 45 |
const JSAtomState& CompileRuntime::names() { return *runtime()->commonNames; } |
| 46 |
|
| 47 |
const PropertyName* CompileRuntime::emptyString() { |
| 48 |
return runtime()->emptyString; |
| 49 |
} |
| 50 |
|
| 51 |
const StaticStrings& CompileRuntime::staticStrings() { |
| 52 |
return *runtime()->staticStrings; |
| 53 |
} |
| 54 |
|
| 55 |
const WellKnownSymbols& CompileRuntime::wellKnownSymbols() { |
| 56 |
return *runtime()->wellKnownSymbols; |
| 57 |
} |
| 58 |
|
| 59 |
const JSClass* CompileRuntime::maybeWindowProxyClass() { |
| 60 |
return runtime()->maybeWindowProxyClass(); |
| 61 |
} |
| 62 |
|
| 63 |
const void* CompileRuntime::mainContextPtr() { |
| 64 |
return runtime()->mainContextFromAnyThread(); |
| 65 |
} |
| 66 |
|
| 67 |
const void* CompileRuntime::addressOfJitActivation() { |
| 68 |
return runtime()->mainContextFromAnyThread()->addressOfJitActivation(); |
| 69 |
} |
| 70 |
|
| 71 |
const void* CompileRuntime::addressOfJitStackLimit() { |
| 72 |
return runtime()->mainContextFromAnyThread()->addressOfJitStackLimit(); |
| 73 |
} |
| 74 |
|
| 75 |
const void* CompileRuntime::addressOfInterruptBits() { |
| 76 |
return runtime()->mainContextFromAnyThread()->addressOfInterruptBits(); |
| 77 |
} |
| 78 |
|
| 79 |
const void* CompileRuntime::addressOfInlinedICScript() { |
| 80 |
return runtime()->mainContextFromAnyThread()->addressOfInlinedICScript(); |
| 81 |
} |
| 82 |
|
| 83 |
const void* CompileRuntime::addressOfRealm() { |
| 84 |
return runtime()->mainContextFromAnyThread()->addressOfRealm(); |
| 85 |
} |
| 86 |
|
| 87 |
const void* CompileRuntime::addressOfZone() { |
| 88 |
return runtime()->mainContextFromAnyThread()->addressOfZone(); |
| 89 |
} |
| 90 |
|
| 91 |
const void* CompileRuntime::addressOfMegamorphicCache() { |
| 92 |
return &runtime()->caches().megamorphicCache; |
| 93 |
} |
| 94 |
|
| 95 |
const void* CompileRuntime::addressOfMegamorphicSetPropCache() { |
| 96 |
return runtime()->caches().megamorphicSetPropCache.get(); |
| 97 |
} |
| 98 |
|
| 99 |
const void* CompileRuntime::addressOfStringToAtomCache() { |
| 100 |
return &runtime()->caches().stringToAtomCache; |
| 101 |
} |
| 102 |
|
| 103 |
const void* CompileRuntime::addressOfLastBufferedWholeCell() { |
| 104 |
return runtime()->gc.addressOfLastBufferedWholeCell(); |
| 105 |
} |
| 106 |
|
| 107 |
const void* CompileRuntime::addressOfHasSeenObjectEmulateUndefinedFuse() { |
| 108 |
// We're merely accessing the address of the fuse here, and so we don't need |
| 109 |
// the MainThreadData check here. |
| 110 |
return runtime()->hasSeenObjectEmulateUndefinedFuse.refNoCheck().fuseRef(); |
| 111 |
} |
| 112 |
|
| 113 |
bool CompileRuntime::hasSeenObjectEmulateUndefinedFuseIntact() { |
| 114 |
// Note: This accesses the bit; this would be unsafe off-thread, however |
| 115 |
// this should only be accessed by CompileInfo in its constructor on main |
| 116 |
// thread and so should be safe. |
| 117 |
// |
| 118 |
// (This value is also checked by ref() rather than skipped like the address |
| 119 |
// call above.) |
| 120 |
return runtime()->hasSeenObjectEmulateUndefinedFuse.ref().intact(); |
| 121 |
} |
| 122 |
|
| 123 |
bool CompileRuntime::hasSeenArrayExceedsInt32LengthFuseIntact() { |
| 124 |
return runtime()->hasSeenArrayExceedsInt32LengthFuse.ref().intact(); |
| 125 |
} |
| 126 |
|
| 127 |
const DOMCallbacks* CompileRuntime::DOMcallbacks() { |
| 128 |
return runtime()->DOMcallbacks; |
| 129 |
} |
| 130 |
|
| 131 |
bool CompileRuntime::runtimeMatches(JSRuntime* rt) { return rt == runtime(); } |
| 132 |
|
| 133 |
Zone* CompileZone::zone() { return reinterpret_cast<Zone*>(this); } |
| 134 |
|
| 135 |
/* static */ |
| 136 |
CompileZone* CompileZone::get(Zone* zone) { |
| 137 |
return reinterpret_cast<CompileZone*>(zone); |
| 138 |
} |
| 139 |
|
| 140 |
CompileRuntime* CompileZone::runtime() { |
| 141 |
return CompileRuntime::get(zone()->runtimeFromAnyThread()); |
| 142 |
} |
| 143 |
|
| 144 |
bool CompileZone::isAtomsZone() { return zone()->isAtomsZone(); } |
| 145 |
|
| 146 |
#ifdef DEBUG |
| 147 |
const void* CompileRuntime::addressOfIonBailAfterCounter() { |
| 148 |
return runtime()->jitRuntime()->addressOfIonBailAfterCounter(); |
| 149 |
} |
| 150 |
#endif |
| 151 |
|
| 152 |
const uint32_t* CompileZone::addressOfNeedsIncrementalBarrier() { |
| 153 |
// Cast away relaxed atomic wrapper for JIT access to barrier state. |
| 154 |
const mozilla::Atomic<uint32_t, mozilla::Relaxed>* ptr = |
| 155 |
zone()->addressOfNeedsIncrementalBarrier(); |
| 156 |
return reinterpret_cast<const uint32_t*>(ptr); |
| 157 |
} |
| 158 |
|
| 159 |
uint32_t* CompileZone::addressOfTenuredAllocCount() { |
| 160 |
return zone()->addressOfTenuredAllocCount(); |
| 161 |
} |
| 162 |
|
| 163 |
gc::FreeSpan** CompileZone::addressOfFreeList(gc::AllocKind allocKind) { |
| 164 |
return zone()->arenas.addressOfFreeList(allocKind); |
| 165 |
} |
| 166 |
|
| 167 |
bool CompileZone::allocNurseryObjects() { |
| 168 |
return zone()->allocNurseryObjects(); |
| 169 |
} |
| 170 |
|
| 171 |
bool CompileZone::allocNurseryStrings() { |
| 172 |
return zone()->allocNurseryStrings(); |
| 173 |
} |
| 174 |
|
| 175 |
bool CompileZone::allocNurseryBigInts() { |
| 176 |
return zone()->allocNurseryBigInts(); |
| 177 |
} |
| 178 |
|
| 179 |
void* CompileZone::addressOfNurseryPosition() { |
| 180 |
return zone()->runtimeFromAnyThread()->gc.addressOfNurseryPosition(); |
| 181 |
} |
| 182 |
|
| 183 |
void* CompileZone::addressOfNurseryAllocatedSites() { |
| 184 |
JSRuntime* rt = zone()->runtimeFromAnyThread(); |
| 185 |
return rt->gc.addressOfNurseryAllocatedSites(); |
| 186 |
} |
| 187 |
|
| 188 |
bool CompileZone::canNurseryAllocateStrings() { |
| 189 |
return zone()->allocNurseryStrings(); |
| 190 |
} |
| 191 |
|
| 192 |
bool CompileZone::canNurseryAllocateBigInts() { |
| 193 |
return zone()->allocNurseryBigInts(); |
| 194 |
} |
| 195 |
|
| 196 |
gc::AllocSite* CompileZone::catchAllAllocSite(JS::TraceKind traceKind, |
| 197 |
gc::CatchAllAllocSite siteKind) { |
| 198 |
if (siteKind == gc::CatchAllAllocSite::Optimized) { |
| 199 |
return zone()->optimizedAllocSite(); |
| 200 |
} |
| 201 |
return zone()->unknownAllocSite(traceKind); |
| 202 |
} |
| 203 |
|
| 204 |
gc::AllocSite* CompileZone::tenuringAllocSite() { |
| 205 |
return zone()->tenuringAllocSite(); |
| 206 |
} |
| 207 |
|
| 208 |
JS::Realm* CompileRealm::realm() { return reinterpret_cast<JS::Realm*>(this); } |
| 209 |
|
| 210 |
/* static */ |
| 211 |
CompileRealm* CompileRealm::get(JS::Realm* realm) { |
| 212 |
return reinterpret_cast<CompileRealm*>(realm); |
| 213 |
} |
| 214 |
|
| 215 |
CompileZone* CompileRealm::zone() { return CompileZone::get(realm()->zone()); } |
| 216 |
|
| 217 |
CompileRuntime* CompileRealm::runtime() { |
| 218 |
return CompileRuntime::get(realm()->runtimeFromAnyThread()); |
| 219 |
} |
| 220 |
|
| 221 |
const mozilla::non_crypto::XorShift128PlusRNG* |
| 222 |
CompileRealm::addressOfRandomNumberGenerator() { |
| 223 |
return realm()->addressOfRandomNumberGenerator(); |
| 224 |
} |
| 225 |
|
| 226 |
const GlobalObject* CompileRealm::maybeGlobal() { |
| 227 |
// This uses unsafeUnbarrieredMaybeGlobal() so as not to trigger the read |
| 228 |
// barrier on the global from off thread. This is safe because we |
| 229 |
// abort Ion compilation when we GC. |
| 230 |
return realm()->unsafeUnbarrieredMaybeGlobal(); |
| 231 |
} |
| 232 |
|
| 233 |
const uint32_t* CompileRealm::addressOfGlobalWriteBarriered() { |
| 234 |
return &realm()->globalWriteBarriered; |
| 235 |
} |
| 236 |
|
| 237 |
bool CompileZone::hasRealmWithAllocMetadataBuilder() { |
| 238 |
return zone()->hasRealmWithAllocMetadataBuilder(); |
| 239 |
} |
| 240 |
|
| 241 |
JitCompileOptions::JitCompileOptions() |
| 242 |
: profilerSlowAssertionsEnabled_(false), |
| 243 |
offThreadCompilationAvailable_(false) {} |
| 244 |
|
| 245 |
JitCompileOptions::JitCompileOptions(JSContext* cx) { |
| 246 |
profilerSlowAssertionsEnabled_ = |
| 247 |
cx->runtime()->geckoProfiler().enabled() && |
| 248 |
cx->runtime()->geckoProfiler().slowAssertionsEnabled(); |
| 249 |
offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx); |
| 250 |
#ifdef DEBUG |
| 251 |
ionBailAfterEnabled_ = cx->runtime()->jitRuntime()->ionBailAfterEnabled(); |
| 252 |
#endif |
| 253 |
} |