tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CompileWrappers.h (4776B)


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