InvalidatingFuse.h (2967B)
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 vm_InvalidatingFuse_h 8 #define vm_InvalidatingFuse_h 9 10 #include "gc/Barrier.h" 11 #include "jit/InvalidationScriptSet.h" 12 #include "js/SweepingAPI.h" 13 14 #include "vm/GuardFuse.h" 15 class JSScript; 16 17 namespace js { 18 19 // [SMDOC] Invalidating Fuses 20 // 21 // An invalidating fuse will invalidate a set of dependent IonScripts when the 22 // fuse is popped. In this way Ion can choose to ignore fuse guarded 23 // possibilities when doing compilation. 24 class InvalidatingFuse : public GuardFuse { 25 public: 26 // Register a script's IonScript as having a dependency on this fuse. 27 virtual bool addFuseDependency(JSContext* cx, 28 const jit::IonScriptKey& ionScript) = 0; 29 }; 30 31 // [SMDOC] Invalidating Runtime Fuses 32 // 33 // A specialized sublass for handling runtime wide fuses. This provides a 34 // version of addFuseDependency which records scripts into sets associated with 35 // their home zone, and invalidates all sets across all zones linked to this 36 // specific fuse. 37 class InvalidatingRuntimeFuse : public InvalidatingFuse { 38 public: 39 virtual bool addFuseDependency(JSContext* cx, 40 const jit::IonScriptKey& ionScript) override; 41 virtual void popFuse(JSContext* cx) override; 42 }; 43 44 // A (weak) set of scripts which are dependent on an associated fuse. 45 // 46 // Because it uses JS::WeakCache, GC tracing is taken care of without any need 47 // for tracing in this class. 48 class FuseDependentIonScriptSet { 49 public: 50 FuseDependentIonScriptSet(JSContext* cx, InvalidatingFuse* fuse); 51 52 InvalidatingFuse* associatedFuse; 53 bool addScriptForFuse(InvalidatingFuse* fuse, 54 const jit::IonScriptKey& ionScript); 55 void invalidateForFuse(JSContext* cx, InvalidatingFuse* fuse); 56 57 private: 58 JS::WeakCache<js::jit::DependentIonScriptSet> ionScripts; 59 }; 60 61 class DependentIonScriptGroup { 62 // A dependent script set pairs a fuse with a set of scripts which depend 63 // on said fuse; this is a vector of script sets because the expectation for 64 // now is that the number of runtime wide invalidating fuses will be small. 65 // This will need to be revisited (convert to HashMap?) should that no 66 // longer be the case 67 // 68 // Note: This isn't traced through the zone, but rather through the use 69 // of JS::WeakCache. 70 Vector<FuseDependentIonScriptSet, 1, SystemAllocPolicy> dependencies; 71 72 public: 73 FuseDependentIonScriptSet* getOrCreateDependentScriptSet( 74 JSContext* cx, InvalidatingFuse* fuse); 75 FuseDependentIonScriptSet* begin() { return dependencies.begin(); } 76 FuseDependentIonScriptSet* end() { return dependencies.end(); } 77 }; 78 79 } // namespace js 80 81 #endif // vm_InvalidatingFuse_h