This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCallLinkInfo.cpp
More file actions
288 lines (249 loc) · 8.58 KB
/
CallLinkInfo.cpp
File metadata and controls
288 lines (249 loc) · 8.58 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
/*
* Copyright (C) 2012-2018 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.
*/
#include "config.h"
#include "CallLinkInfo.h"
#include "CallFrameShuffleData.h"
#include "FunctionCodeBlock.h"
#include "JSCellInlines.h"
#include "Opcode.h"
#include "Repatch.h"
#include <wtf/ListDump.h>
#if ENABLE(JIT)
namespace JSC {
CallLinkInfo::CallType CallLinkInfo::callTypeFor(OpcodeID opcodeID)
{
switch (opcodeID) {
case op_tail_call_varargs:
case op_tail_call_forward_arguments:
return TailCallVarargs;
case op_call:
case op_call_eval:
case op_iterator_open:
case op_iterator_next:
return Call;
case op_call_varargs:
return CallVarargs;
case op_construct:
return Construct;
case op_construct_varargs:
return ConstructVarargs;
case op_tail_call:
return TailCall;
default:
break;
}
RELEASE_ASSERT_NOT_REACHED();
return Call;
}
CallLinkInfo::CallLinkInfo(CodeOrigin codeOrigin)
: m_codeOrigin(codeOrigin)
, m_hasSeenShouldRepatch(false)
, m_hasSeenClosure(false)
, m_clearedByGC(false)
, m_clearedByVirtual(false)
, m_allowStubs(true)
, m_clearedByJettison(false)
, m_callType(None)
{
}
CallLinkInfo::~CallLinkInfo()
{
clearStub();
if (isOnList())
remove();
}
void CallLinkInfo::clearStub()
{
if (!stub())
return;
m_stub->clearCallNodesFor(this);
m_stub = nullptr;
}
void CallLinkInfo::unlink(VM& vm)
{
// We could be called even if we're not linked anymore because of how polymorphic calls
// work. Each callsite within the polymorphic call stub may separately ask us to unlink().
if (isLinked())
unlinkFor(vm, *this);
// Either we were unlinked, in which case we should not have been on any list, or we unlinked
// ourselves so that we're not on any list anymore.
RELEASE_ASSERT(!isOnList());
}
CodeLocationNearCall<JSInternalPtrTag> CallLinkInfo::callReturnLocation()
{
RELEASE_ASSERT(!isDirect());
return CodeLocationNearCall<JSInternalPtrTag>(m_callReturnLocationOrPatchableJump, NearCallMode::Regular);
}
CodeLocationJump<JSInternalPtrTag> CallLinkInfo::patchableJump()
{
RELEASE_ASSERT(callType() == DirectTailCall);
return CodeLocationJump<JSInternalPtrTag>(m_callReturnLocationOrPatchableJump);
}
CodeLocationDataLabelPtr<JSInternalPtrTag> CallLinkInfo::hotPathBegin()
{
RELEASE_ASSERT(!isDirect());
return CodeLocationDataLabelPtr<JSInternalPtrTag>(m_hotPathBeginOrSlowPathStart);
}
CodeLocationLabel<JSInternalPtrTag> CallLinkInfo::slowPathStart()
{
RELEASE_ASSERT(isDirect());
return m_hotPathBeginOrSlowPathStart;
}
void CallLinkInfo::setCallee(VM& vm, JSCell* owner, JSObject* callee)
{
RELEASE_ASSERT(!isDirect());
m_calleeOrCodeBlock.set(vm, owner, callee);
}
void CallLinkInfo::clearCallee()
{
RELEASE_ASSERT(!isDirect());
m_calleeOrCodeBlock.clear();
}
JSObject* CallLinkInfo::callee()
{
RELEASE_ASSERT(!isDirect());
return jsCast<JSObject*>(m_calleeOrCodeBlock.get());
}
void CallLinkInfo::setCodeBlock(VM& vm, JSCell* owner, FunctionCodeBlock* codeBlock)
{
RELEASE_ASSERT(isDirect());
m_calleeOrCodeBlock.setMayBeNull(vm, owner, codeBlock);
}
void CallLinkInfo::clearCodeBlock()
{
RELEASE_ASSERT(isDirect());
m_calleeOrCodeBlock.clear();
}
FunctionCodeBlock* CallLinkInfo::codeBlock()
{
RELEASE_ASSERT(isDirect());
return jsCast<FunctionCodeBlock*>(m_calleeOrCodeBlock.get());
}
void CallLinkInfo::setLastSeenCallee(VM& vm, const JSCell* owner, JSObject* callee)
{
RELEASE_ASSERT(!isDirect());
m_lastSeenCalleeOrExecutable.set(vm, owner, callee);
}
void CallLinkInfo::clearLastSeenCallee()
{
RELEASE_ASSERT(!isDirect());
m_lastSeenCalleeOrExecutable.clear();
}
JSObject* CallLinkInfo::lastSeenCallee() const
{
RELEASE_ASSERT(!isDirect());
return jsCast<JSObject*>(m_lastSeenCalleeOrExecutable.get());
}
bool CallLinkInfo::haveLastSeenCallee() const
{
RELEASE_ASSERT(!isDirect());
return !!m_lastSeenCalleeOrExecutable;
}
void CallLinkInfo::setExecutableDuringCompilation(ExecutableBase* executable)
{
RELEASE_ASSERT(isDirect());
m_lastSeenCalleeOrExecutable.setWithoutWriteBarrier(executable);
}
ExecutableBase* CallLinkInfo::executable()
{
RELEASE_ASSERT(isDirect());
return jsCast<ExecutableBase*>(m_lastSeenCalleeOrExecutable.get());
}
void CallLinkInfo::setMaxArgumentCountIncludingThis(unsigned value)
{
RELEASE_ASSERT(isDirect());
RELEASE_ASSERT(value);
m_maxArgumentCountIncludingThis = value;
}
void CallLinkInfo::visitWeak(VM& vm)
{
auto handleSpecificCallee = [&] (JSFunction* callee) {
if (vm.heap.isMarked(callee->executable()))
m_hasSeenClosure = true;
else
m_clearedByGC = true;
};
if (isLinked()) {
if (stub()) {
if (!stub()->visitWeak(vm)) {
if (UNLIKELY(Options::verboseOSR())) {
dataLog(
"At ", m_codeOrigin, ", ", RawPointer(this), ": clearing call stub to ",
listDump(stub()->variants()), ", stub routine ", RawPointer(stub()),
".\n");
}
unlink(vm);
m_clearedByGC = true;
}
} else if (!vm.heap.isMarked(m_calleeOrCodeBlock.get())) {
if (isDirect()) {
if (UNLIKELY(Options::verboseOSR())) {
dataLog(
"Clearing call to ", RawPointer(codeBlock()), " (",
pointerDump(codeBlock()), ").\n");
}
} else {
if (callee()->type() == JSFunctionType) {
if (UNLIKELY(Options::verboseOSR())) {
dataLog(
"Clearing call to ",
RawPointer(callee()), " (",
static_cast<JSFunction*>(callee())->executable()->hashFor(specializationKind()),
").\n");
}
handleSpecificCallee(static_cast<JSFunction*>(callee()));
} else {
if (UNLIKELY(Options::verboseOSR()))
dataLog("Clearing call to ", RawPointer(callee()), ".\n");
m_clearedByGC = true;
}
}
unlink(vm);
} else if (isDirect() && !vm.heap.isMarked(m_lastSeenCalleeOrExecutable.get())) {
if (UNLIKELY(Options::verboseOSR())) {
dataLog(
"Clearing call to ", RawPointer(executable()),
" because the executable is dead.\n");
}
unlink(vm);
// We should only get here once the owning CodeBlock is dying, since the executable must
// already be in the owner's weak references.
m_lastSeenCalleeOrExecutable.clear();
}
}
if (!isDirect() && haveLastSeenCallee() && !vm.heap.isMarked(lastSeenCallee())) {
if (lastSeenCallee()->type() == JSFunctionType)
handleSpecificCallee(jsCast<JSFunction*>(lastSeenCallee()));
else
m_clearedByGC = true;
clearLastSeenCallee();
}
}
void CallLinkInfo::setFrameShuffleData(const CallFrameShuffleData& shuffleData)
{
m_frameShuffleData = makeUnique<CallFrameShuffleData>(shuffleData);
}
} // namespace JSC
#endif // ENABLE(JIT)