Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "jit/Ion.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace js; |
michael@0 | 10 | using namespace js::jit; |
michael@0 | 11 | |
michael@0 | 12 | JSRuntime * |
michael@0 | 13 | CompileRuntime::runtime() |
michael@0 | 14 | { |
michael@0 | 15 | return reinterpret_cast<JSRuntime *>(this); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | /* static */ CompileRuntime * |
michael@0 | 19 | CompileRuntime::get(JSRuntime *rt) |
michael@0 | 20 | { |
michael@0 | 21 | return reinterpret_cast<CompileRuntime *>(rt); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | bool |
michael@0 | 25 | CompileRuntime::onMainThread() |
michael@0 | 26 | { |
michael@0 | 27 | return js::CurrentThreadCanAccessRuntime(runtime()); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | js::PerThreadData * |
michael@0 | 31 | CompileRuntime::mainThread() |
michael@0 | 32 | { |
michael@0 | 33 | JS_ASSERT(onMainThread()); |
michael@0 | 34 | return &runtime()->mainThread; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | const void * |
michael@0 | 38 | CompileRuntime::addressOfIonTop() |
michael@0 | 39 | { |
michael@0 | 40 | return &runtime()->mainThread.ionTop; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | const void * |
michael@0 | 44 | CompileRuntime::addressOfJitStackLimit() |
michael@0 | 45 | { |
michael@0 | 46 | return &runtime()->mainThread.jitStackLimit; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | const void * |
michael@0 | 50 | CompileRuntime::addressOfJSContext() |
michael@0 | 51 | { |
michael@0 | 52 | return &runtime()->mainThread.jitJSContext; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | const void * |
michael@0 | 56 | CompileRuntime::addressOfActivation() |
michael@0 | 57 | { |
michael@0 | 58 | return runtime()->mainThread.addressOfActivation(); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | const void * |
michael@0 | 62 | CompileRuntime::addressOfLastCachedNativeIterator() |
michael@0 | 63 | { |
michael@0 | 64 | return &runtime()->nativeIterCache.last; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | #ifdef JS_GC_ZEAL |
michael@0 | 68 | const void * |
michael@0 | 69 | CompileRuntime::addressOfGCZeal() |
michael@0 | 70 | { |
michael@0 | 71 | return &runtime()->gcZeal_; |
michael@0 | 72 | } |
michael@0 | 73 | #endif |
michael@0 | 74 | |
michael@0 | 75 | const void * |
michael@0 | 76 | CompileRuntime::addressOfInterrupt() |
michael@0 | 77 | { |
michael@0 | 78 | return &runtime()->interrupt; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | #ifdef JS_THREADSAFE |
michael@0 | 82 | const void * |
michael@0 | 83 | CompileRuntime::addressOfInterruptPar() |
michael@0 | 84 | { |
michael@0 | 85 | return &runtime()->interruptPar; |
michael@0 | 86 | } |
michael@0 | 87 | #endif |
michael@0 | 88 | |
michael@0 | 89 | const void * |
michael@0 | 90 | CompileRuntime::addressOfThreadPool() |
michael@0 | 91 | { |
michael@0 | 92 | return &runtime()->threadPool; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | const JitRuntime * |
michael@0 | 96 | CompileRuntime::jitRuntime() |
michael@0 | 97 | { |
michael@0 | 98 | return runtime()->jitRuntime(); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | SPSProfiler & |
michael@0 | 102 | CompileRuntime::spsProfiler() |
michael@0 | 103 | { |
michael@0 | 104 | return runtime()->spsProfiler; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | bool |
michael@0 | 108 | CompileRuntime::signalHandlersInstalled() |
michael@0 | 109 | { |
michael@0 | 110 | return runtime()->signalHandlersInstalled(); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | bool |
michael@0 | 114 | CompileRuntime::jitSupportsFloatingPoint() |
michael@0 | 115 | { |
michael@0 | 116 | return runtime()->jitSupportsFloatingPoint; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | bool |
michael@0 | 120 | CompileRuntime::hadOutOfMemory() |
michael@0 | 121 | { |
michael@0 | 122 | return runtime()->hadOutOfMemory; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | const JSAtomState & |
michael@0 | 126 | CompileRuntime::names() |
michael@0 | 127 | { |
michael@0 | 128 | return *runtime()->commonNames; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | const StaticStrings & |
michael@0 | 132 | CompileRuntime::staticStrings() |
michael@0 | 133 | { |
michael@0 | 134 | return *runtime()->staticStrings; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | const Value & |
michael@0 | 138 | CompileRuntime::NaNValue() |
michael@0 | 139 | { |
michael@0 | 140 | return runtime()->NaNValue; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | const Value & |
michael@0 | 144 | CompileRuntime::positiveInfinityValue() |
michael@0 | 145 | { |
michael@0 | 146 | return runtime()->positiveInfinityValue; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | #ifdef DEBUG |
michael@0 | 150 | bool |
michael@0 | 151 | CompileRuntime::isInsideNursery(gc::Cell *cell) |
michael@0 | 152 | { |
michael@0 | 153 | return UninlinedIsInsideNursery(runtime(), cell); |
michael@0 | 154 | } |
michael@0 | 155 | #endif |
michael@0 | 156 | |
michael@0 | 157 | const DOMCallbacks * |
michael@0 | 158 | CompileRuntime::DOMcallbacks() |
michael@0 | 159 | { |
michael@0 | 160 | return GetDOMCallbacks(runtime()); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | const MathCache * |
michael@0 | 164 | CompileRuntime::maybeGetMathCache() |
michael@0 | 165 | { |
michael@0 | 166 | return runtime()->maybeGetMathCache(); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | #ifdef JSGC_GENERATIONAL |
michael@0 | 170 | const Nursery & |
michael@0 | 171 | CompileRuntime::gcNursery() |
michael@0 | 172 | { |
michael@0 | 173 | return runtime()->gcNursery; |
michael@0 | 174 | } |
michael@0 | 175 | #endif |
michael@0 | 176 | |
michael@0 | 177 | Zone * |
michael@0 | 178 | CompileZone::zone() |
michael@0 | 179 | { |
michael@0 | 180 | return reinterpret_cast<Zone *>(this); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | /* static */ CompileZone * |
michael@0 | 184 | CompileZone::get(Zone *zone) |
michael@0 | 185 | { |
michael@0 | 186 | return reinterpret_cast<CompileZone *>(zone); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | const void * |
michael@0 | 190 | CompileZone::addressOfNeedsBarrier() |
michael@0 | 191 | { |
michael@0 | 192 | return zone()->addressOfNeedsBarrier(); |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | const void * |
michael@0 | 196 | CompileZone::addressOfFreeListFirst(gc::AllocKind allocKind) |
michael@0 | 197 | { |
michael@0 | 198 | return &zone()->allocator.arenas.getFreeList(allocKind)->first; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | const void * |
michael@0 | 202 | CompileZone::addressOfFreeListLast(gc::AllocKind allocKind) |
michael@0 | 203 | { |
michael@0 | 204 | return &zone()->allocator.arenas.getFreeList(allocKind)->last; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | JSCompartment * |
michael@0 | 208 | CompileCompartment::compartment() |
michael@0 | 209 | { |
michael@0 | 210 | return reinterpret_cast<JSCompartment *>(this); |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | /* static */ CompileCompartment * |
michael@0 | 214 | CompileCompartment::get(JSCompartment *comp) |
michael@0 | 215 | { |
michael@0 | 216 | return reinterpret_cast<CompileCompartment *>(comp); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | CompileZone * |
michael@0 | 220 | CompileCompartment::zone() |
michael@0 | 221 | { |
michael@0 | 222 | return CompileZone::get(compartment()->zone()); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | CompileRuntime * |
michael@0 | 226 | CompileCompartment::runtime() |
michael@0 | 227 | { |
michael@0 | 228 | return CompileRuntime::get(compartment()->runtimeFromAnyThread()); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | const void * |
michael@0 | 232 | CompileCompartment::addressOfEnumerators() |
michael@0 | 233 | { |
michael@0 | 234 | return &compartment()->enumerators; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | const CallsiteCloneTable & |
michael@0 | 238 | CompileCompartment::callsiteClones() |
michael@0 | 239 | { |
michael@0 | 240 | return compartment()->callsiteClones; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | const JitCompartment * |
michael@0 | 244 | CompileCompartment::jitCompartment() |
michael@0 | 245 | { |
michael@0 | 246 | return compartment()->jitCompartment(); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | bool |
michael@0 | 250 | CompileCompartment::hasObjectMetadataCallback() |
michael@0 | 251 | { |
michael@0 | 252 | return compartment()->hasObjectMetadataCallback(); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | // Note: This function is thread-safe because setSingletonAsValue sets a boolean |
michael@0 | 256 | // variable to false, and this boolean variable has no way to be resetted to |
michael@0 | 257 | // true. So even if there is a concurrent write, this concurrent write will |
michael@0 | 258 | // always have the same value. If there is a concurrent read, then we will |
michael@0 | 259 | // clone a singleton instead of using the value which is baked in the JSScript, |
michael@0 | 260 | // and this would be an unfortunate allocation, but this will not change the |
michael@0 | 261 | // semantics of the JavaScript code which is executed. |
michael@0 | 262 | void |
michael@0 | 263 | CompileCompartment::setSingletonsAsValues() |
michael@0 | 264 | { |
michael@0 | 265 | return JS::CompartmentOptionsRef(compartment()).setSingletonsAsValues(); |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | JitCompileOptions::JitCompileOptions() |
michael@0 | 269 | : cloneSingletons_(false), |
michael@0 | 270 | spsSlowAssertionsEnabled_(false) |
michael@0 | 271 | { |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | JitCompileOptions::JitCompileOptions(JSContext *cx) |
michael@0 | 275 | { |
michael@0 | 276 | JS::CompartmentOptions &options = cx->compartment()->options(); |
michael@0 | 277 | cloneSingletons_ = options.cloneSingletons(cx); |
michael@0 | 278 | spsSlowAssertionsEnabled_ = cx->runtime()->spsProfiler.enabled() && |
michael@0 | 279 | cx->runtime()->spsProfiler.slowAssertionsEnabled(); |
michael@0 | 280 | } |