tor-browser

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

InvalidationScriptSet.h (1576B)


      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_InvalidationScriptSet_h
      8 #define jit_InvalidationScriptSet_h
      9 
     10 #include "mozilla/MemoryReporting.h"
     11 
     12 #include "gc/Barrier.h"
     13 #include "jit/Invalidation.h"
     14 #include "jit/IonTypes.h"
     15 #include "js/AllocPolicy.h"
     16 #include "js/GCVector.h"
     17 #include "js/SweepingAPI.h"
     18 
     19 namespace js::jit {
     20 
     21 // A set of Ion scripts that will be invalidated simultaneously.
     22 //
     23 // When using this class, make sure the traceWeak method is called by the GC to
     24 // sweep dead scripts.
     25 class DependentIonScriptSet {
     26  IonScriptKeyVector ionScripts_;
     27 
     28  // To avoid keeping a lot of stale entries for invalidated IonScripts between
     29  // GCs, we compact the vector when it grows too large.
     30  size_t lengthAfterLastCompaction_ = 0;
     31 
     32 public:
     33  [[nodiscard]] bool addToSet(const IonScriptKey& ionScript);
     34  void invalidateAndClear(JSContext* cx, const char* reason);
     35 
     36  bool empty() const { return ionScripts_.empty(); }
     37 
     38  bool traceWeak(JSTracer* trc) {
     39    bool res = ionScripts_.traceWeak(trc);
     40    lengthAfterLastCompaction_ = ionScripts_.length();
     41    return res;
     42  }
     43 
     44  size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
     45    return ionScripts_.sizeOfExcludingThis(mallocSizeOf);
     46  }
     47 };
     48 
     49 }  // namespace js::jit
     50 
     51 #endif /* jit_InvalidationScriptSet_h */