forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecref-profile.h
More file actions
201 lines (170 loc) · 5.75 KB
/
Copy pathdecref-profile.h
File metadata and controls
201 lines (170 loc) · 5.75 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
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#pragma once
#include "hphp/runtime/base/datatype.h"
#include "hphp/runtime/vm/jit/ir-instruction.h"
#include "hphp/runtime/vm/jit/prof-data-serialize.h"
#include "hphp/runtime/vm/jit/shared-profile.h"
#include "hphp/runtime/vm/jit/type.h"
#include <folly/dynamic.h>
namespace HPHP::jit {
///////////////////////////////////////////////////////////////////////////////
/*
* Profile the frequency of the 4 possible different behaviors of a DecRef
* instruction. Each execution of a DecRef must fall into exactly one of these
* categories:
*
* 1) Uncounted:
* the type was uncounted
* 2) Persistent:
* the type was refcounted and the value was persistent (so no dec happens)
* 3) Destroyed:
* the type was refcounted and the value was destroyed (ie. the count was 1)
* 4) Survived:
* the type was refcounted, non-persistent, but wasn't destroyed (count > 1)
*
*/
constexpr DataType kNoDataTypesSeen = kExtraInvalidDataType;
constexpr DataType kMultipleDataTypesSeen = kInvalidDataType;
enum class DecRefProfileId {
Default = -1,
// Necessary to prevent collisions of DecRefProfileIds generated by casting
// an int to this enum.
AKExistsArr = 10000,
AKExistsKey,
AtArr,
AtKey,
CmpLhs,
CmpRhs,
ConcatSrc1,
ConcatSrc2,
ConcatSrc3,
ConcatSrc4,
ConcatStr1,
ConcatStr2,
ConcatStr3,
GeneratorReturnOldKey,
GeneratorReturnOldValue,
IdxDef,
IdxKey,
IdxBase,
InstanceOfSrc1,
InstanceOfSrc2,
IsTypeStructCc,
IsTypeStructCa,
IsTypeStructCTc,
ProfiledArraySet,
ResumableOldKey,
ResumableOldValue,
SelectIfBranch,
SelectElseBranch,
SetOpSLhs,
SetOpSRhs,
ShiftBase,
ShiftAmount,
};
// Necessary because profile data is 0-initialized.
static_assert(static_cast<int>(kNoDataTypesSeen) == 0);
struct DecRefProfile {
uint32_t uncounted() const {
auto const result = int(total) - int(refcounted);
return safe_cast<uint32_t>(std::max(result, 0));
}
uint32_t persistent() const {
auto const result = int(refcounted) - int(released) - int(decremented);
return safe_cast<uint32_t>(std::max(result, 0));
}
uint32_t destroyed() const {
return released;
}
uint32_t survived() const {
return decremented;
}
uint32_t arrayOfUncountedReleasedCount() const {
return arrayOfUncountedReleaseCount;
}
float percent(uint32_t value) const {
return total ? 100.0 * value / total : 0.0;
}
void serialize(ProfDataSerializer& ser) const {
write_raw(ser, total);
write_raw(ser, refcounted);
write_raw(ser, released);
write_raw(ser, decremented);
write_raw(ser, arrayOfUncountedReleaseCount);
write_raw(ser, datatype);
}
void deserialize(ProfDataDeserializer& ser) {
read_raw(ser, total);
read_raw(ser, refcounted);
read_raw(ser, released);
read_raw(ser, decremented);
read_raw(ser, arrayOfUncountedReleaseCount);
read_raw(ser, datatype);
}
/*
* Update the profile for a dec-ref on tv.
*/
void update(TypedValue tv);
void updateDataType(DataType newDT);
static void reduce(DecRefProfile& a, const DecRefProfile& b);
folly::dynamic toDynamic() const;
std::string toString() const;
/*
* The total number of times this DecRef was executed.
*/
uint32_t total;
/*
* The number of times this DecRef made it at least as far as the static
* check (meaning it was given a refcounted DataType).
*/
uint32_t refcounted;
/*
* The number of times this DecRef went to zero and called the release method.
*/
uint32_t released;
/*
* The number of times this DecRef actually decremented the count (meaning it
* got a non-persistent, refcounted value with count > 1).
*/
uint32_t decremented;
/*
* The number of times an array of uncounted elements was released.
*/
uint32_t arrayOfUncountedReleaseCount;
/*
* 'datatype' is populated with a unique datatype, if we see one, during
* profiling. It is initialized to 0 (kNoDataTypesSeen) before any datatypes
* are seen. If non-unique datatypes are seen, it is set to
* kMultipleDataTypesSeen.
*/
DataType datatype;
/*
* To ensure that `update` is constant time, we examine at most this many
* values when checking when the input is an array of uncounted values.
* Arrays with a large number of values are usually monotyped, so we don't
* get much benefit from examining more.
*/
static constexpr size_t kMaxNumProfiledElements = 16;
};
const StringData* decRefProfileKey(int locId);
const StringData* decRefProfileKey(const IRInstruction* inst);
SharedProfile<DecRefProfile> decRefProfile(
const TransContext& context, const IRInstruction* inst);
SharedProfile<DecRefProfile> decRefProfile(
const TransContext& context, const BCMarker& marker, int locId);
///////////////////////////////////////////////////////////////////////////////
}