tor-browser

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

Invalidation.h (2253B)


      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_Invalidation_h
      8 #define jit_Invalidation_h
      9 
     10 #include "jit/IonTypes.h"
     11 #include "js/AllocPolicy.h"
     12 #include "js/GCVector.h"
     13 
     14 namespace js {
     15 namespace jit {
     16 
     17 class IonScript;
     18 
     19 // Used to reference a specific IonScript created for a JSScript, without
     20 // keeping that IonScript alive. It can be swept (by traceWeak) when the
     21 // JSScript no longer has an IonScript with the given IonCompilationId.
     22 class IonScriptKey {
     23  JSScript* script_;
     24  IonCompilationId id_;
     25 
     26 public:
     27  IonScriptKey(JSScript* script, IonCompilationId id)
     28      : script_(script), id_(id) {}
     29 
     30  JSScript* script() const { return script_; }
     31 
     32  // Returns nullptr if the script no longer has an IonScript with this
     33  // IonCompilationId.
     34  IonScript* maybeIonScriptToInvalidate() const;
     35 
     36  bool traceWeak(JSTracer* trc);
     37 
     38  bool operator==(const IonScriptKey& other) const {
     39    return script_ == other.script_ && id_ == other.id_;
     40  }
     41  bool operator!=(const IonScriptKey& other) const {
     42    return !operator==(other);
     43  }
     44 };
     45 
     46 // IonScriptKeyVector has a MinInlineCapacity of one so that invalidating a
     47 // single IonScript doesn't require an allocation.
     48 using IonScriptKeyVector = JS::GCVector<IonScriptKey, 1, SystemAllocPolicy>;
     49 
     50 // Called from Zone::discardJitCode().
     51 void InvalidateAll(JS::GCContext* gcx, JS::Zone* zone);
     52 void FinishInvalidation(JS::GCContext* gcx, JSScript* script);
     53 
     54 // Add compilations involving |script| (outer script or inlined) to the vector.
     55 void AddPendingInvalidation(jit::IonScriptKeyVector& invalid, JSScript* script);
     56 
     57 // Walk the stack and invalidate active Ion frames for the invalid scripts.
     58 void Invalidate(JSContext* cx, const IonScriptKeyVector& invalid,
     59                bool resetUses = true, bool cancelOffThread = true);
     60 void Invalidate(JSContext* cx, JSScript* script, bool resetUses = true,
     61                bool cancelOffThread = true);
     62 
     63 }  // namespace jit
     64 }  // namespace js
     65 
     66 #endif /* jit_Invalidation_h */