1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef vm_InvalidatingFuse_h
#define vm_InvalidatingFuse_h
#include "gc/Barrier.h"
#include "gc/SweepingAPI.h"
#include "vm/GuardFuse.h"
class JSScript;
namespace js {
// [SMDOC] Invalidating Fuses
//
// An invalidating fuse will invalidate a set of dependent IonScripts when the
// fuse is popped. In this way Ion can choose to ignore fuse guarded
// possibilities when doing compilation.
class InvalidatingFuse : public GuardFuse {
public:
// Register a script's IonScript as having a dependency on this fuse.
virtual bool addFuseDependency(JSContext* cx, Handle<JSScript*> script) = 0;
};
// [SMDOC] Invalidating Runtime Fuses
//
// A specialized sublass for handling runtime wide fuses. This provides a
// version of addFuseDependency which records scripts into sets associated with
// their home zone, and invalidates all sets across all zones linked to this
// specific fuse.
class InvalidatingRuntimeFuse : public InvalidatingFuse {
public:
virtual bool addFuseDependency(JSContext* cx,
Handle<JSScript*> script) override;
virtual void popFuse(JSContext* cx) override;
};
// A (weak) set of scripts which are dependent on an associated fuse.
//
// Because it uses JS::WeakCache, GC tracing is taken care of without any need
// for tracing in this class.
class DependentScriptSet {
public:
DependentScriptSet(JSContext* cx, InvalidatingFuse* fuse);
InvalidatingFuse* associatedFuse;
bool addScriptForFuse(InvalidatingFuse* fuse, Handle<JSScript*> script);
void invalidateForFuse(JSContext* cx, InvalidatingFuse* fuse);
private:
using WeakScriptSet = GCHashSet<WeakHeapPtr<JSScript*>,
StableCellHasher<WeakHeapPtr<JSScript*>>,
js::SystemAllocPolicy>;
js::WeakCache<WeakScriptSet> weakScripts;
};
class DependentScriptGroup {
// A dependent script set pairs a fuse with a set of scripts which depend
// on said fuse; this is a vector of script sets because the expectation for
// now is that the number of runtime wide invalidating fuses will be small.
// This will need to be revisited (convert to HashMap?) should that no
// longer be the case
//
// Note: This isn't traced through the zone, but rather through the use
// of JS::WeakCache.
Vector<DependentScriptSet, 1, SystemAllocPolicy> dependencies;
public:
DependentScriptSet* getOrCreateDependentScriptSet(JSContext* cx,
InvalidatingFuse* fuse);
DependentScriptSet* begin() { return dependencies.begin(); }
DependentScriptSet* end() { return dependencies.end(); }
};
} // namespace js
#endif // vm_InvalidatingFuse_h
|