#include "jit/CompileWrappers.h"
#include "gc/GC.h"
#include "jit/Ion.h"
#include "jit/JitRealm.h"
#include "vm/Realm-inl.h"
using namespace js;
using namespace js::jit;
JSRuntime* CompileRuntime::runtime() {
return reinterpret_cast<JSRuntime*>(this);
}
CompileRuntime* CompileRuntime::get(JSRuntime* rt) {
return reinterpret_cast<CompileRuntime*>(rt);
}
#ifdef JS_GC_ZEAL
const uint32_t* CompileRuntime::addressOfGCZealModeBits() {
return runtime()->gc.addressOfZealModeBits();
}
#endif
const JitRuntime* CompileRuntime::jitRuntime() {
return runtime()->jitRuntime();
}
GeckoProfilerRuntime& CompileRuntime::geckoProfiler() {
return runtime()->geckoProfiler();
}
bool CompileRuntime::jitSupportsFloatingPoint() {
return runtime()->jitSupportsFloatingPoint;
}
bool CompileRuntime::hadOutOfMemory() { return runtime()->hadOutOfMemory; }
bool CompileRuntime::profilingScripts() { return runtime()->profilingScripts; }
const JSAtomState& CompileRuntime::names() { return *runtime()->commonNames; }
const PropertyName* CompileRuntime::emptyString() {
return runtime()->emptyString;
}
const StaticStrings& CompileRuntime::staticStrings() {
return *runtime()->staticStrings;
}
const Value& CompileRuntime::NaNValue() { return runtime()->NaNValue; }
const Value& CompileRuntime::positiveInfinityValue() {
return runtime()->positiveInfinityValue;
}
const WellKnownSymbols& CompileRuntime::wellKnownSymbols() {
return *runtime()->wellKnownSymbols;
}
const void* CompileRuntime::mainContextPtr() {
return runtime()->mainContextFromAnyThread();
}
uint32_t* CompileRuntime::addressOfTenuredAllocCount() {
return runtime()->mainContextFromAnyThread()->addressOfTenuredAllocCount();
}
const void* CompileRuntime::addressOfJitStackLimit() {
return runtime()->mainContextFromAnyThread()->addressOfJitStackLimit();
}
const void* CompileRuntime::addressOfInterruptBits() {
return runtime()->mainContextFromAnyThread()->addressOfInterruptBits();
}
const void* CompileRuntime::addressOfZone() {
return runtime()->mainContextFromAnyThread()->addressOfZone();
}
#ifdef DEBUG
bool CompileRuntime::isInsideNursery(gc::Cell* cell) {
return UninlinedIsInsideNursery(cell);
}
#endif
const DOMCallbacks* CompileRuntime::DOMcallbacks() {
return runtime()->DOMcallbacks;
}
bool CompileRuntime::runtimeMatches(JSRuntime* rt) { return rt == runtime(); }
Zone* CompileZone::zone() { return reinterpret_cast<Zone*>(this); }
CompileZone* CompileZone::get(Zone* zone) {
return reinterpret_cast<CompileZone*>(zone);
}
CompileRuntime* CompileZone::runtime() {
return CompileRuntime::get(zone()->runtimeFromAnyThread());
}
bool CompileZone::isAtomsZone() { return zone()->isAtomsZone(); }
#ifdef DEBUG
const void* CompileZone::addressOfIonBailAfter() {
return zone()->runtimeFromAnyThread()->jitRuntime()->addressOfIonBailAfter();
}
#endif
const uint32_t* CompileZone::addressOfNeedsIncrementalBarrier() {
return zone()->addressOfNeedsIncrementalBarrier();
}
gc::FreeSpan** CompileZone::addressOfFreeList(gc::AllocKind allocKind) {
return zone()->arenas.addressOfFreeList(allocKind);
}
void* CompileZone::addressOfNurseryPosition() {
return zone()->runtimeFromAnyThread()->gc.addressOfNurseryPosition();
}
void* CompileZone::addressOfStringNurseryPosition() {
return zone()->runtimeFromAnyThread()->gc.addressOfNurseryPosition();
}
const void* CompileZone::addressOfNurseryCurrentEnd() {
return zone()->runtimeFromAnyThread()->gc.addressOfNurseryCurrentEnd();
}
const void* CompileZone::addressOfStringNurseryCurrentEnd() {
return zone()->runtimeFromAnyThread()->gc.addressOfStringNurseryCurrentEnd();
}
uint32_t* CompileZone::addressOfNurseryAllocCount() {
return zone()->runtimeFromAnyThread()->gc.addressOfNurseryAllocCount();
}
bool CompileZone::canNurseryAllocateStrings() {
return nurseryExists() &&
zone()->runtimeFromAnyThread()->gc.nursery().canAllocateStrings() &&
zone()->allocNurseryStrings;
}
bool CompileZone::nurseryExists() {
return zone()->runtimeFromAnyThread()->gc.nursery().exists();
}
void CompileZone::setMinorGCShouldCancelIonCompilations() {
MOZ_ASSERT(CurrentThreadCanAccessZone(zone()));
JSRuntime* rt = zone()->runtimeFromMainThread();
rt->gc.storeBuffer().setShouldCancelIonCompilations();
}
JS::Realm* CompileRealm::realm() { return reinterpret_cast<JS::Realm*>(this); }
CompileRealm* CompileRealm::get(JS::Realm* realm) {
return reinterpret_cast<CompileRealm*>(realm);
}
CompileZone* CompileRealm::zone() { return CompileZone::get(realm()->zone()); }
CompileRuntime* CompileRealm::runtime() {
return CompileRuntime::get(realm()->runtimeFromAnyThread());
}
const mozilla::non_crypto::XorShift128PlusRNG*
CompileRealm::addressOfRandomNumberGenerator() {
return realm()->addressOfRandomNumberGenerator();
}
const JitRealm* CompileRealm::jitRealm() { return realm()->jitRealm(); }
const GlobalObject* CompileRealm::maybeGlobal() {
return realm()->unsafeUnbarrieredMaybeGlobal();
}
const uint32_t* CompileRealm::addressOfGlobalWriteBarriered() {
return &realm()->globalWriteBarriered;
}
bool CompileRealm::hasAllocationMetadataBuilder() {
return realm()->hasAllocationMetadataBuilder();
}
void CompileRealm::setSingletonsAsValues() {
realm()->behaviors().setSingletonsAsValues();
}
JitCompileOptions::JitCompileOptions()
: cloneSingletons_(false),
profilerSlowAssertionsEnabled_(false),
offThreadCompilationAvailable_(false) {}
JitCompileOptions::JitCompileOptions(JSContext* cx) {
cloneSingletons_ = cx->realm()->creationOptions().cloneSingletons();
profilerSlowAssertionsEnabled_ =
cx->runtime()->geckoProfiler().enabled() &&
cx->runtime()->geckoProfiler().slowAssertionsEnabled();
offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx);
}