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/. */
7 #ifndef vm_InvalidatingFuse_h
8 #define vm_InvalidatingFuse_h
10 #include "gc/Barrier.h"
11 #include "gc/SweepingAPI.h"
12 #include "vm/GuardFuse.h"
17 // [SMDOC] Invalidating Fuses
19 // An invalidating fuse will invalidate a set of dependent IonScripts when the
20 // fuse is popped. In this way Ion can choose to ignore fuse guarded
21 // possibilities when doing compilation.
22 class InvalidatingFuse
: public GuardFuse
{
24 // Register a script's IonScript as having a dependency on this fuse.
25 virtual bool addFuseDependency(JSContext
* cx
, Handle
<JSScript
*> script
) = 0;
28 // [SMDOC] Invalidating Runtime Fuses
30 // A specialized sublass for handling runtime wide fuses. This provides a
31 // version of addFuseDependency which records scripts into sets associated with
32 // their home zone, and invalidates all sets across all zones linked to this
34 class InvalidatingRuntimeFuse
: public InvalidatingFuse
{
36 virtual bool addFuseDependency(JSContext
* cx
,
37 Handle
<JSScript
*> script
) override
;
38 virtual void popFuse(JSContext
* cx
) override
;
41 // A (weak) set of scripts which are dependent on an associated fuse.
43 // Because it uses JS::WeakCache, GC tracing is taken care of without any need
44 // for tracing in this class.
45 class DependentScriptSet
{
47 DependentScriptSet(JSContext
* cx
, InvalidatingFuse
* fuse
);
49 InvalidatingFuse
* associatedFuse
;
50 bool addScriptForFuse(InvalidatingFuse
* fuse
, Handle
<JSScript
*> script
);
51 void invalidateForFuse(JSContext
* cx
, InvalidatingFuse
* fuse
);
54 using WeakScriptSet
= GCHashSet
<WeakHeapPtr
<JSScript
*>,
55 StableCellHasher
<WeakHeapPtr
<JSScript
*>>,
56 js::SystemAllocPolicy
>;
57 js::WeakCache
<WeakScriptSet
> weakScripts
;
60 class DependentScriptGroup
{
61 // A dependent script set pairs a fuse with a set of scripts which depend
62 // on said fuse; this is a vector of script sets because the expectation for
63 // now is that the number of runtime wide invalidating fuses will be small.
64 // This will need to be revisited (convert to HashMap?) should that no
67 // Note: This isn't traced through the zone, but rather through the use
69 Vector
<DependentScriptSet
, 1, SystemAllocPolicy
> dependencies
;
72 DependentScriptSet
* getOrCreateDependentScriptSet(JSContext
* cx
,
73 InvalidatingFuse
* fuse
);
74 DependentScriptSet
* begin() { return dependencies
.begin(); }
75 DependentScriptSet
* end() { return dependencies
.end(); }
80 #endif // vm_InvalidatingFuse_h