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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/* -*- 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_RealmFuses_h
#define vm_RealmFuses_h
#include "vm/GuardFuse.h"
#include "vm/InvalidatingFuse.h"
namespace js {
class NativeObject;
struct RealmFuses;
// [SMDOC] RealmFuses:
//
// Realm fuses are fuses associated with a specific realm. As a result,
// popFuse for realmFuses has another argument, the set of realmFuses related to
// the fuse being popped. This is used to find any dependent fuses in the realm
// (rather than using the context).
class RealmFuse : public GuardFuse {
public:
virtual void popFuse(JSContext* cx, RealmFuses& realmFuses) { popFuse(cx); }
protected:
virtual void popFuse(JSContext* cx) override { GuardFuse::popFuse(cx); }
};
class InvalidatingRealmFuse : public InvalidatingFuse {
public:
virtual void popFuse(JSContext* cx, RealmFuses& realmFuses);
virtual bool addFuseDependency(JSContext* cx,
Handle<JSScript*> script) override;
protected:
virtual void popFuse(JSContext* cx) override {
InvalidatingFuse::popFuse(cx);
}
};
struct OptimizeGetIteratorFuse final : public InvalidatingRealmFuse {
virtual const char* name() override { return "OptimizeGetIteratorFuse"; }
virtual bool checkInvariant(JSContext* cx) override;
};
struct PopsOptimizedGetIteratorFuse : public RealmFuse {
virtual void popFuse(JSContext* cx, RealmFuses& realmFuses) override;
};
struct ArrayPrototypeIteratorFuse final : public PopsOptimizedGetIteratorFuse {
virtual const char* name() override { return "ArrayPrototypeIteratorFuse"; }
virtual bool checkInvariant(JSContext* cx) override;
};
struct ArrayPrototypeIteratorNextFuse final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "ArrayPrototypeIteratorNextFuse";
}
virtual bool checkInvariant(JSContext* cx) override;
};
// This fuse covers ArrayIteratorPrototype not having a return property;
// however the fuse doesn't pop if a prototype acquires the return property.
struct ArrayIteratorPrototypeHasNoReturnProperty final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "ArrayIteratorPrototypeHasNoReturnProperty";
}
virtual bool checkInvariant(JSContext* cx) override;
};
// This fuse covers IteratorPrototype not having a return property;
// however the fuse doesn't pop if a prototype acquires the return property.
struct IteratorPrototypeHasNoReturnProperty final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "IteratorPrototypeHasNoReturnProperty";
}
virtual bool checkInvariant(JSContext* cx) override;
};
struct ArrayIteratorPrototypeHasIteratorProto final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "ArrayIteratorPrototypeHasIteratorProto";
}
virtual bool checkInvariant(JSContext* cx) override;
};
struct IteratorPrototypeHasObjectProto final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "IteratorPrototypeHasObjectProto";
}
virtual bool checkInvariant(JSContext* cx) override;
};
struct ObjectPrototypeHasNoReturnProperty final
: public PopsOptimizedGetIteratorFuse {
virtual const char* name() override {
return "ObjectPrototypeHasNoReturnProperty";
}
virtual bool checkInvariant(JSContext* cx) override;
};
#define FOR_EACH_REALM_FUSE(FUSE) \
FUSE(OptimizeGetIteratorFuse, optimizeGetIteratorFuse) \
FUSE(ArrayPrototypeIteratorFuse, arrayPrototypeIteratorFuse) \
FUSE(ArrayPrototypeIteratorNextFuse, arrayPrototypeIteratorNextFuse) \
FUSE(ArrayIteratorPrototypeHasNoReturnProperty, \
arrayIteratorPrototypeHasNoReturnProperty) \
FUSE(IteratorPrototypeHasNoReturnProperty, \
iteratorPrototypeHasNoReturnProperty) \
FUSE(ArrayIteratorPrototypeHasIteratorProto, \
arrayIteratorPrototypeHasIteratorProto) \
FUSE(IteratorPrototypeHasObjectProto, iteratorPrototypeHasObjectProto) \
FUSE(ObjectPrototypeHasNoReturnProperty, objectPrototypeHasNoReturnProperty)
struct RealmFuses {
RealmFuses() = default;
#define FUSE(Name, LowerName) Name LowerName{};
FOR_EACH_REALM_FUSE(FUSE)
#undef FUSE
void assertInvariants(JSContext* cx) {
// Generate the invariant checking calls.
#define FUSE(Name, LowerName) LowerName.assertInvariant(cx);
FOR_EACH_REALM_FUSE(FUSE)
#undef FUSE
}
// Code Generation Code:
enum class FuseIndex : uint8_t {
// Generate Fuse Indexes
#define FUSE(Name, LowerName) Name,
FOR_EACH_REALM_FUSE(FUSE)
#undef FUSE
LastFuseIndex
};
GuardFuse* getFuseByIndex(FuseIndex index) {
switch (index) {
// Return fuses.
#define FUSE(Name, LowerName) \
case FuseIndex::Name: \
return &this->LowerName;
FOR_EACH_REALM_FUSE(FUSE)
#undef FUSE
default:
break;
}
MOZ_CRASH("Fuse Not Found");
}
DependentScriptGroup fuseDependencies;
static int32_t fuseOffsets[];
static const char* fuseNames[];
static int32_t offsetOfFuseWordRelativeToRealm(FuseIndex index);
static const char* getFuseName(FuseIndex index);
};
} // namespace js
#endif
|