-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathICStats.h
More file actions
308 lines (270 loc) · 9.89 KB
/
ICStats.h
File metadata and controls
308 lines (270 loc) · 9.89 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
* Copyright (C) 2016-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "CacheableIdentifierInlines.h"
#include "ClassInfo.h"
#include "Identifier.h"
#include <wtf/Condition.h>
#include <wtf/Lock.h>
#include <wtf/Noncopyable.h>
#include <wtf/PrintStream.h>
#include <wtf/Spectrum.h>
#include <wtf/TZoneMalloc.h>
namespace JSC {
namespace ICStatsInternal {
static constexpr bool traceHandlerChains = false;
}
#define FOR_EACH_ICEVENT_KIND(macro) \
macro(InvalidKind) \
macro(GetByAddAccessCase) \
macro(GetByReplaceWithJump) \
macro(GetBySelfPatch) \
macro(InAddAccessCase) \
macro(InReplaceWithJump) \
macro(InReplaceWithGeneric) \
macro(InstanceOfAddAccessCase) \
macro(InstanceOfReplaceWithJump) \
macro(OperationGetByIdGaveUp) \
macro(OperationGetByIdGeneric) \
macro(OperationGetByIdBuildList) \
macro(OperationGetByIdOptimize) \
macro(OperationGetByValOptimize) \
macro(OperationGetByIdWithThisOptimize) \
macro(OperationGetByIdWithThisGaveUp) \
macro(OperationGetByIdWithThisGeneric) \
macro(OperationGetByValWithThisOptimize) \
macro(OperationGenericIn) \
macro(OperationInByIdGeneric) \
macro(OperationInByIdOptimize) \
macro(OperationPutByIdStrictGaveUp) \
macro(OperationPutByIdSloppyGaveUp) \
macro(OperationPutByIdDirectStrictGaveUp) \
macro(OperationPutByIdDirectSloppyGaveUp) \
macro(OperationPutByIdStrictOptimize) \
macro(OperationPutByIdSloppyOptimize) \
macro(OperationPutByIdDirectStrictOptimize) \
macro(OperationPutByIdDirectSloppyOptimize) \
macro(OperationPutByIdStrictBuildList) \
macro(OperationPutByIdSloppyBuildList) \
macro(OperationPutByIdDefinePrivateFieldStrictOptimize) \
macro(OperationPutByIdPutPrivateFieldStrictOptimize) \
macro(PutByAddAccessCase) \
macro(PutByReplaceWithJump) \
macro(PutBySelfPatch) \
macro(InBySelfPatch) \
macro(DelByReplaceWithJump) \
macro(DelByReplaceWithGeneric) \
macro(OperationGetPrivateNameOptimize) \
macro(OperationGetPrivateNameById) \
macro(OperationGetPrivateNameByIdOptimize) \
macro(OperationGetPrivateNameByIdGeneric) \
macro(CheckPrivateBrandAddAccessCase) \
macro(SetPrivateBrandAddAccessCase) \
macro(CheckPrivateBrandReplaceWithJump) \
macro(SetPrivateBrandReplaceWithJump) \
macro(OperationPutByIdSetPrivateFieldStrictOptimize) \
macro(OperationPutByIdDefinePrivateFieldStrictGaveUp) \
macro(OperationPutByIdSetPrivateFieldStrictGaveUp) \
macro(OperationGetByValGaveUp) \
macro(OperationGetByValGeneric) \
macro(OperationGetByValWithThisGaveUp) \
macro(OperationGetByValWithThisGeneric) \
macro(OperationPutByValStrictGaveUp) \
macro(OperationPutByValStrictGeneric) \
macro(OperationPutByValSloppyGaveUp) \
macro(OperationPutByValSloppyGeneric) \
macro(OperationPutByValDefinePrivateFieldGaveUp) \
macro(OperationPutByValDefinePrivateFieldGeneric) \
macro(OperationPutByValSetPrivateFieldGaveUp) \
macro(OperationPutByValSetPrivateFieldGeneric) \
/* JIT execution tracing events */ \
/* Slow path handlers */ \
macro(GetByIdSlowPath) \
macro(GetByIdWithThisSlowPath) \
macro(GetByValSlowPath) \
macro(GetPrivateNameSlowPath) \
macro(GetByValWithThisSlowPath) \
macro(PutByIdSlowPath) \
macro(PutByValSlowPath) \
macro(InstanceOfSlowPath) \
macro(DeleteByIdSlowPath) \
macro(DeleteByValSlowPath) \
/* GetById handlers */ \
macro(GetByIdLoadOwnPropertyHandler) \
macro(GetByIdLoadPrototypePropertyHandler) \
macro(GetByIdMissHandler) \
macro(GetByIdCustomAccessorHandler) \
macro(GetByIdCustomValueHandler) \
macro(GetByIdGetterHandler) \
macro(GetByIdProxyObjectLoadHandler) \
macro(GetByIdModuleNamespaceLoadHandler) \
/* PutById handlers */ \
macro(PutByIdReplaceHandler) \
macro(PutByIdTransitionHandler) \
macro(PutByIdTransitionReallocatingOutOfLineHandler) \
macro(PutByIdCustomAccessorHandler) \
macro(PutByIdCustomValueHandler) \
macro(PutByIdStrictSetterHandler) \
macro(PutByIdSloppySetterHandler) \
/* InById handlers */ \
macro(InByIdHitHandler) \
macro(InByIdMissHandler) \
/* DeleteById handlers */ \
macro(DeleteByIdDeleteHandler) \
macro(DeleteByIdMissHandler) \
macro(DeleteByIdNonConfigurableHandler) \
/* InstanceOf handlers */ \
macro(InstanceOfHitHandler) \
macro(InstanceOfMissHandler) \
/* GetByVal handlers */ \
macro(GetByValLoadOwnPropertyHandler) \
macro(GetByValLoadPrototypePropertyHandler) \
macro(GetByValMissHandler) \
macro(GetByValCustomAccessorHandler) \
macro(GetByValCustomValueHandler) \
macro(GetByValGetterHandler) \
/* PutByVal handlers */ \
macro(PutByValReplaceHandler) \
macro(PutByValTransitionHandler) \
macro(PutByValTransitionOutOfLineHandler) \
macro(PutByValCustomAccessorHandler) \
macro(PutByValCustomValueHandler) \
macro(PutByValStrictSetterHandler) \
macro(PutByValSloppySetterHandler) \
/* InByVal handlers */ \
macro(InByValHitHandler) \
macro(InByValMissHandler) \
/* DeleteByVal handlers */ \
macro(DeleteByValDeleteHandler) \
macro(DeleteByValMissHandler) \
macro(DeleteByValNonConfigurableHandler) \
/* Other handlers */ \
macro(CheckPrivateBrandHandler) \
macro(SetPrivateBrandHandler) \
macro(CompiledHandler) \
macro(DOMJITHandler)
class ICEvent {
public:
enum Kind {
#define ICEVENT_KIND_DECLARATION(name) name,
FOR_EACH_ICEVENT_KIND(ICEVENT_KIND_DECLARATION)
#undef ICEVENT_KIND_DECLARATION
};
enum PropertyLocation {
Unknown,
BaseObject,
ProtoLookup
};
ICEvent() = default;
explicit ICEvent(Kind kind)
: m_kind(kind)
, m_propertyLocation(Unknown)
{
ASSERT(kind != InvalidKind);
}
ICEvent(Kind kind, const ClassInfo* classInfo)
: m_kind(kind)
, m_classInfo(classInfo)
, m_propertyLocation(Unknown)
{
ASSERT(kind != InvalidKind);
}
ICEvent(Kind kind, const ClassInfo* classInfo, bool isBaseProperty)
: m_kind(kind)
, m_classInfo(classInfo)
, m_propertyLocation(isBaseProperty ? BaseObject : ProtoLookup)
{
ASSERT(kind != InvalidKind);
}
ICEvent(WTF::HashTableDeletedValueType)
: m_kind(InvalidKind)
, m_propertyLocation(BaseObject)
{
}
bool operator==(const ICEvent& other) const
{
return m_kind == other.m_kind
&& m_classInfo == other.m_classInfo
&& m_propertyLocation == other.m_propertyLocation;
}
bool operator<(const ICEvent& other) const;
bool operator>(const ICEvent& other) const { return other < *this; }
bool operator<=(const ICEvent& other) const { return !(*this > other); }
bool operator>=(const ICEvent& other) const { return !(*this < other); }
explicit operator bool() const
{
return *this != ICEvent();
}
Kind kind() const { return m_kind; }
const ClassInfo* classInfo() const { return m_classInfo; }
unsigned hash() const
{
return static_cast<unsigned>(m_kind) + static_cast<unsigned>(m_propertyLocation) + WTF::PtrHash<const ClassInfo*>::hash(m_classInfo);
}
bool isHashTableDeletedValue() const
{
return *this == ICEvent(WTF::HashTableDeletedValue);
}
static constexpr bool safeToCompareToHashTableEmptyOrDeletedValue = true;
void dump(PrintStream&) const;
void log() const;
private:
Kind m_kind { InvalidKind };
const ClassInfo* m_classInfo { nullptr };
PropertyLocation m_propertyLocation { Unknown };
};
} // namespace JSC
namespace WTF {
void printInternal(PrintStream&, JSC::ICEvent::Kind);
template<typename T> struct HashTraits;
template<> struct HashTraits<JSC::ICEvent> : SimpleClassHashTraits<JSC::ICEvent> {
static constexpr bool emptyValueIsZero = false;
};
} // namespace WTF
namespace JSC {
class ICStats {
WTF_MAKE_NONCOPYABLE(ICStats);
WTF_MAKE_TZONE_ALLOCATED(ICStats);
public:
ICStats();
~ICStats();
void add(const ICEvent& event);
static ICStats& singleton();
void startNewChain(unsigned totalNumberOfHandlersInChain);
void appendToCurrentChain(ICEvent::Kind);
void dumpChains();
private:
Spectrum<ICEvent, uint64_t> m_spectrum;
RefPtr<Thread> m_thread;
Lock m_lock;
Condition m_condition;
bool m_shouldStop { false };
static Atomic<ICStats*> s_instance;
};
#define LOG_IC(arguments) do { \
if (Options::useICStats()) \
(ICEvent arguments).log(); \
} while (false)
} // namespace JSC