tor-browser

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

WarpOracle.h (3311B)


      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_WarpOracle_h
      8 #define jit_WarpOracle_h
      9 
     10 #include "jit/JitAllocPolicy.h"
     11 #include "jit/JitContext.h"
     12 #include "jit/WarpSnapshot.h"
     13 
     14 namespace js {
     15 namespace jit {
     16 
     17 class MIRGenerator;
     18 
     19 // WarpOracle creates a WarpSnapshot data structure that's used by WarpBuilder
     20 // to generate the MIR graph off-thread.
     21 class MOZ_STACK_CLASS WarpOracle {
     22  JSContext* cx_;
     23  MIRGenerator& mirGen_;
     24  TempAllocator& alloc_;
     25  HandleScript outerScript_;
     26  WarpBailoutInfo bailoutInfo_;
     27  WarpScriptSnapshotList scriptSnapshots_;
     28  WarpZoneStubsSnapshot zoneStubs_{};
     29  size_t accumulatedBytecodeSize_ = 0;
     30 #ifdef DEBUG
     31  mozilla::HashNumber runningScriptHash_ = 0;
     32 #endif
     33 
     34  // List of nursery objects to copy to the snapshot. See WarpObjectField.
     35  // The HashMap is used to de-duplicate the Vector. It maps each object to the
     36  // corresponding nursery index (index into the Vector).
     37  // Note: this stores raw object pointers because WarpOracle can't GC.
     38  Vector<JSObject*, 8, SystemAllocPolicy> nurseryObjects_;
     39  using NurseryObjectsMap =
     40      HashMap<JSObject*, uint32_t, DefaultHasher<JSObject*>, SystemAllocPolicy>;
     41  NurseryObjectsMap nurseryObjectsMap_;
     42 
     43  // Like nurseryObjects_/nurseryObjectsMap_ but for boxed Values.
     44  // Use mozilla::Vector because js::Vector asserts it's not used for JS::Value.
     45  mozilla::Vector<Value, 8, SystemAllocPolicy> nurseryValues_;
     46  using NurseryValuesMap =
     47      HashMap<gc::Cell*, uint32_t, DefaultHasher<gc::Cell*>, SystemAllocPolicy>;
     48  NurseryValuesMap nurseryValuesMap_;
     49 
     50 public:
     51  WarpOracle(JSContext* cx, MIRGenerator& mirGen, HandleScript outerScript);
     52  ~WarpOracle() { scriptSnapshots_.clear(); }
     53 
     54  MIRGenerator& mirGen() { return mirGen_; }
     55  WarpBailoutInfo& bailoutInfo() { return bailoutInfo_; }
     56 
     57  [[nodiscard]] bool registerNurseryObject(JSObject* obj,
     58                                           uint32_t* nurseryIndex);
     59  [[nodiscard]] bool registerNurseryValue(Value v, uint32_t* nurseryIndex);
     60 
     61  [[nodiscard]] bool snapshotJitZoneStub(JitZone::StubKind kind);
     62 
     63  [[nodiscard]] bool addFuseDependency(RealmFuses::FuseIndex fuseIndex,
     64                                       bool* stillValid);
     65 
     66  [[nodiscard]] bool addFuseDependency(RuntimeFuses::FuseIndex fuseIndex,
     67                                       bool* stillValid);
     68 
     69  AbortReasonOr<WarpSnapshot*> createSnapshot();
     70 
     71  mozilla::GenericErrorResult<AbortReason> abort(HandleScript script,
     72                                                 AbortReason r);
     73  mozilla::GenericErrorResult<AbortReason> abort(HandleScript script,
     74                                                 AbortReason r,
     75                                                 const char* message, ...);
     76  void addScriptSnapshot(WarpScriptSnapshot* scriptSnapshot, ICScript* icScript,
     77                         size_t bytecodeLength);
     78 
     79  size_t accumulatedBytecodeSize() { return accumulatedBytecodeSize_; }
     80  void ignoreFailedICHash();
     81 };
     82 
     83 }  // namespace jit
     84 }  // namespace js
     85 
     86 #endif /* jit_WarpOracle_h */