| 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, Handle<JSScript*> script) = 0; |
| 28 |
}; |
| 29 |
|
| 30 |
// [SMDOC] Invalidating Runtime Fuses |
| 31 |
// |
| 32 |
// A specialized sublass for handling runtime wide fuses. This provides a |
| 33 |
// version of addFuseDependency which records scripts into sets associated with |
| 34 |
// their home zone, and invalidates all sets across all zones linked to this |
| 35 |
// specific fuse. |
| 36 |
class InvalidatingRuntimeFuse : public InvalidatingFuse { |
| 37 |
public: |
| 38 |
virtual bool addFuseDependency(JSContext* cx, |
| 39 |
Handle<JSScript*> script) override; |
| 40 |
virtual void popFuse(JSContext* cx) override; |
| 41 |
}; |
| 42 |
|
| 43 |
// A (weak) set of scripts which are dependent on an associated fuse. |
| 44 |
// |
| 45 |
// Because it uses JS::WeakCache, GC tracing is taken care of without any need |
| 46 |
// for tracing in this class. |
| 47 |
class DependentScriptSet { |
| 48 |
public: |
| 49 |
DependentScriptSet(JSContext* cx, InvalidatingFuse* fuse); |
| 50 |
|
| 51 |
InvalidatingFuse* associatedFuse; |
| 52 |
bool addScriptForFuse(InvalidatingFuse* fuse, Handle<JSScript*> script); |
| 53 |
void invalidateForFuse(JSContext* cx, InvalidatingFuse* fuse); |
| 54 |
|
| 55 |
void removeScript(JSScript* script) { |
| 56 |
jit::RemoveFromScriptSet(weakScripts, script); |
| 57 |
} |
| 58 |
|
| 59 |
private: |
| 60 |
js::jit::WeakScriptCache weakScripts; |
| 61 |
}; |
| 62 |
|
| 63 |
class DependentScriptGroup { |
| 64 |
// A dependent script set pairs a fuse with a set of scripts which depend |
| 65 |
// on said fuse; this is a vector of script sets because the expectation for |
| 66 |
// now is that the number of runtime wide invalidating fuses will be small. |
| 67 |
// This will need to be revisited (convert to HashMap?) should that no |
| 68 |
// longer be the case |
| 69 |
// |
| 70 |
// Note: This isn't traced through the zone, but rather through the use |
| 71 |
// of JS::WeakCache. |
| 72 |
Vector<DependentScriptSet, 1, SystemAllocPolicy> dependencies; |
| 73 |
|
| 74 |
public: |
| 75 |
DependentScriptSet* getOrCreateDependentScriptSet(JSContext* cx, |
| 76 |
InvalidatingFuse* fuse); |
| 77 |
DependentScriptSet* begin() { return dependencies.begin(); } |
| 78 |
DependentScriptSet* end() { return dependencies.end(); } |
| 79 |
|
| 80 |
void removeScript(JSScript* script) { |
| 81 |
for (auto& set : dependencies) { |
| 82 |
set.removeScript(script); |
| 83 |
} |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
} // namespace js |
| 88 |
|
| 89 |
#endif // vm_InvalidatingFuse_h |