| 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 |
#ifndef jit_CompileWrappers_h |
| 8 |
#define jit_CompileWrappers_h |
| 9 |
|
| 10 |
#include <stdint.h> |
| 11 |
|
| 12 |
#include "gc/Pretenuring.h" |
| 13 |
#include "js/TypeDecls.h" |
| 14 |
#include "vm/Realm.h" |
| 15 |
#include "vm/RealmFuses.h" |
| 16 |
|
| 17 |
struct JSAtomState; |
| 18 |
|
| 19 |
namespace mozilla::non_crypto { |
| 20 |
class XorShift128PlusRNG; |
| 21 |
} |
| 22 |
|
| 23 |
namespace JS { |
| 24 |
enum class TraceKind; |
| 25 |
} |
| 26 |
|
| 27 |
namespace js { |
| 28 |
|
| 29 |
class GeckoProfilerRuntime; |
| 30 |
class GlobalObject; |
| 31 |
struct JSDOMCallbacks; |
| 32 |
class PropertyName; |
| 33 |
class StaticStrings; |
| 34 |
struct WellKnownSymbols; |
| 35 |
|
| 36 |
using DOMCallbacks = struct JSDOMCallbacks; |
| 37 |
|
| 38 |
namespace gc { |
| 39 |
|
| 40 |
enum class AllocKind : uint8_t; |
| 41 |
|
| 42 |
class FreeSpan; |
| 43 |
|
| 44 |
} // namespace gc |
| 45 |
|
| 46 |
namespace jit { |
| 47 |
|
| 48 |
class JitRuntime; |
| 49 |
|
| 50 |
// During offthread compilation we need access to various bits of the current |
| 51 |
// compartment, runtime and so forth. However, since compilation can run off |
| 52 |
// thread while the main thread is mutating the VM, this access needs |
| 53 |
// to be restricted. The classes below give the compiler an interface to access |
| 54 |
// all necessary information in a threadsafe fashion. |
| 55 |
|
| 56 |
class CompileRuntime { |
| 57 |
JSRuntime* runtime(); |
| 58 |
|
| 59 |
public: |
| 60 |
static CompileRuntime* get(JSRuntime* rt); |
| 61 |
|
| 62 |
#ifdef JS_GC_ZEAL |
| 63 |
const uint32_t* addressOfGCZealModeBits(); |
| 64 |
#endif |
| 65 |
|
| 66 |
const JitRuntime* jitRuntime(); |
| 67 |
|
| 68 |
const GeckoProfilerRuntime& geckoProfiler(); |
| 69 |
|
| 70 |
bool hadOutOfMemory(); |
| 71 |
bool profilingScripts(); |
| 72 |
|
| 73 |
const JSAtomState& names(); |
| 74 |
const PropertyName* emptyString(); |
| 75 |
const StaticStrings& staticStrings(); |
| 76 |
const WellKnownSymbols& wellKnownSymbols(); |
| 77 |
const JSClass* maybeWindowProxyClass(); |
| 78 |
|
| 79 |
const void* mainContextPtr(); |
| 80 |
const void* addressOfJitActivation(); |
| 81 |
const void* addressOfJitStackLimit(); |
| 82 |
const void* addressOfInterruptBits(); |
| 83 |
const void* addressOfInlinedICScript(); |
| 84 |
const void* addressOfRealm(); |
| 85 |
const void* addressOfZone(); |
| 86 |
const void* addressOfMegamorphicCache(); |
| 87 |
const void* addressOfMegamorphicSetPropCache(); |
| 88 |
const void* addressOfStringToAtomCache(); |
| 89 |
const void* addressOfLastBufferedWholeCell(); |
| 90 |
|
| 91 |
bool hasSeenObjectEmulateUndefinedFuseIntact(); |
| 92 |
const void* addressOfHasSeenObjectEmulateUndefinedFuse(); |
| 93 |
|
| 94 |
bool hasSeenArrayExceedsInt32LengthFuseIntact(); |
| 95 |
|
| 96 |
#ifdef DEBUG |
| 97 |
const void* addressOfIonBailAfterCounter(); |
| 98 |
#endif |
| 99 |
|
| 100 |
// DOM callbacks must be threadsafe (and will hopefully be removed soon). |
| 101 |
const DOMCallbacks* DOMcallbacks(); |
| 102 |
|
| 103 |
bool runtimeMatches(JSRuntime* rt); |
| 104 |
}; |
| 105 |
|
| 106 |
class JitZone; |
| 107 |
|
| 108 |
class CompileZone { |
| 109 |
friend class MacroAssembler; |
| 110 |
JS::Zone* zone(); |
| 111 |
|
| 112 |
public: |
| 113 |
static CompileZone* get(JS::Zone* zone); |
| 114 |
|
| 115 |
CompileRuntime* runtime(); |
| 116 |
bool isAtomsZone(); |
| 117 |
|
| 118 |
const uint32_t* addressOfNeedsIncrementalBarrier(); |
| 119 |
uint32_t* addressOfTenuredAllocCount(); |
| 120 |
gc::FreeSpan** addressOfFreeList(gc::AllocKind allocKind); |
| 121 |
bool allocNurseryObjects(); |
| 122 |
bool allocNurseryStrings(); |
| 123 |
bool allocNurseryBigInts(); |
| 124 |
void* addressOfNurseryPosition(); |
| 125 |
|
| 126 |
void* addressOfNurseryAllocatedSites(); |
| 127 |
|
| 128 |
bool canNurseryAllocateStrings(); |
| 129 |
bool canNurseryAllocateBigInts(); |
| 130 |
|
| 131 |
gc::AllocSite* catchAllAllocSite(JS::TraceKind traceKind, |
| 132 |
gc::CatchAllAllocSite siteKind); |
| 133 |
gc::AllocSite* tenuringAllocSite(); |
| 134 |
|
| 135 |
bool hasRealmWithAllocMetadataBuilder(); |
| 136 |
}; |
| 137 |
|
| 138 |
class CompileRealm { |
| 139 |
JS::Realm* realm(); |
| 140 |
|
| 141 |
public: |
| 142 |
static CompileRealm* get(JS::Realm* realm); |
| 143 |
|
| 144 |
CompileZone* zone(); |
| 145 |
CompileRuntime* runtime(); |
| 146 |
|
| 147 |
const void* realmPtr() { return realm(); } |
| 148 |
|
| 149 |
RealmFuses& realmFuses() { return realm()->realmFuses; } |
| 150 |
|
| 151 |
const mozilla::non_crypto::XorShift128PlusRNG* |
| 152 |
addressOfRandomNumberGenerator(); |
| 153 |
|
| 154 |
const GlobalObject* maybeGlobal(); |
| 155 |
const uint32_t* addressOfGlobalWriteBarriered(); |
| 156 |
}; |
| 157 |
|
| 158 |
class JitCompileOptions { |
| 159 |
public: |
| 160 |
JitCompileOptions(); |
| 161 |
explicit JitCompileOptions(JSContext* cx); |
| 162 |
|
| 163 |
bool profilerSlowAssertionsEnabled() const { |
| 164 |
return profilerSlowAssertionsEnabled_; |
| 165 |
} |
| 166 |
|
| 167 |
bool offThreadCompilationAvailable() const { |
| 168 |
return offThreadCompilationAvailable_; |
| 169 |
} |
| 170 |
|
| 171 |
#ifdef DEBUG |
| 172 |
bool ionBailAfterEnabled() const { return ionBailAfterEnabled_; } |
| 173 |
#endif |
| 174 |
|
| 175 |
private: |
| 176 |
bool profilerSlowAssertionsEnabled_; |
| 177 |
bool offThreadCompilationAvailable_; |
| 178 |
#ifdef DEBUG |
| 179 |
bool ionBailAfterEnabled_ = false; |
| 180 |
#endif |
| 181 |
}; |
| 182 |
|
| 183 |
} // namespace jit |
| 184 |
} // namespace js |
| 185 |
|
| 186 |
#endif // jit_CompileWrappers_h |