Skip to content

Commit 8a2e816

Browse files
committed
Some CachedCall cleanup, in preparation for reversing argument order.
Reviewed by Gavin Barraclough. * bytecode/CodeBlock.cpp: (JSC::CodeBlock::stronglyVisitWeakReferences): A build fix for the interpreter, so I can test it. * interpreter/CachedCall.h: (JSC::CachedCall::CachedCall): Renamed argCount to argumentCount because we are not that desperate for character saving. (JSC::CachedCall::setThis): (JSC::CachedCall::setArgument): Adopted new 0-based argument indexing for CallFrameClosure. * interpreter/CallFrameClosure.h: (JSC::CallFrameClosure::setThis): (JSC::CallFrameClosure::setArgument): (JSC::CallFrameClosure::resetCallFrame): Provide 0-based argument indexing, with an explicit setter for 'this', since that's how most clients think. * interpreter/Interpreter.cpp: (JSC::Interpreter::prepareForRepeatCall): * interpreter/Interpreter.h: Change argCount to argumentCountIncludingThis, for clarity. Canonical link: https://commits.webkit.org/89056@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100540 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 0b1b1af commit 8a2e816

6 files changed

Lines changed: 61 additions & 23 deletions

File tree

Source/JavaScriptCore/ChangeLog

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
2011-11-16 Geoffrey Garen <ggaren@apple.com>
2+
3+
Some CachedCall cleanup, in preparation for reversing argument order.
4+
5+
Reviewed by Gavin Barraclough.
6+
7+
* bytecode/CodeBlock.cpp:
8+
(JSC::CodeBlock::stronglyVisitWeakReferences): A build fix for the interpreter,
9+
so I can test it.
10+
11+
* interpreter/CachedCall.h:
12+
(JSC::CachedCall::CachedCall): Renamed argCount to argumentCount because
13+
we are not that desperate for character saving.
14+
15+
(JSC::CachedCall::setThis):
16+
(JSC::CachedCall::setArgument): Adopted new 0-based argument indexing for
17+
CallFrameClosure.
18+
19+
* interpreter/CallFrameClosure.h:
20+
(JSC::CallFrameClosure::setThis):
21+
(JSC::CallFrameClosure::setArgument):
22+
(JSC::CallFrameClosure::resetCallFrame): Provide 0-based argument indexing,
23+
with an explicit setter for 'this', since that's how most clients think.
24+
25+
* interpreter/Interpreter.cpp:
26+
(JSC::Interpreter::prepareForRepeatCall):
27+
* interpreter/Interpreter.h: Change argCount to argumentCountIncludingThis,
28+
for clarity.
29+
130
2011-11-16 Mark Hahnenberg <mhahnenberg@apple.com>
231

332
De-virtualize ScriptExecutable::unlinkCalls

Source/JavaScriptCore/bytecode/CodeBlock.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,12 @@ void CodeBlock::visitAggregate(SlotVisitor& visitor)
16601660

16611661
void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
16621662
{
1663+
UNUSED_PARAM(visitor);
1664+
1665+
#if ENABLE(DFG_JIT)
16631666
if (!m_dfgData)
16641667
return;
1665-
1668+
16661669
for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
16671670
if (!!m_dfgData->transitions[i].m_codeOrigin)
16681671
visitor.append(&m_dfgData->transitions[i].m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
@@ -1672,6 +1675,7 @@ void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
16721675

16731676
for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i)
16741677
visitor.append(&m_dfgData->weakReferences[i]);
1678+
#endif
16751679
}
16761680

16771681
HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset)

Source/JavaScriptCore/interpreter/CachedCall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ namespace JSC {
3535
class CachedCall {
3636
WTF_MAKE_NONCOPYABLE(CachedCall); WTF_MAKE_FAST_ALLOCATED;
3737
public:
38-
CachedCall(CallFrame* callFrame, JSFunction* function, int argCount)
38+
CachedCall(CallFrame* callFrame, JSFunction* function, int argumentCount)
3939
: m_valid(false)
4040
, m_interpreter(callFrame->interpreter())
4141
, m_globalObjectScope(callFrame->globalData(), function->scope()->globalObject.get())
4242
{
4343
ASSERT(!function->isHostFunction());
44-
m_closure = m_interpreter->prepareForRepeatCall(function->jsExecutable(), callFrame, function, argCount, function->scope());
44+
m_closure = m_interpreter->prepareForRepeatCall(function->jsExecutable(), callFrame, function, argumentCount + 1, function->scope());
4545
m_valid = !callFrame->hadException();
4646
}
4747

@@ -50,8 +50,8 @@ namespace JSC {
5050
ASSERT(m_valid);
5151
return m_interpreter->execute(m_closure);
5252
}
53-
void setThis(JSValue v) { m_closure.setArgument(0, v); }
54-
void setArgument(int n, JSValue v) { m_closure.setArgument(n + 1, v); }
53+
void setThis(JSValue v) { m_closure.setThis(v); }
54+
void setArgument(int n, JSValue v) { m_closure.setArgument(n, v); }
5555

5656
CallFrame* newCallFrame(ExecState* exec)
5757
{

Source/JavaScriptCore/interpreter/CallFrameClosure.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,30 @@ struct CallFrameClosure {
3636
JSGlobalData* globalData;
3737
Register* oldEnd;
3838
ScopeChainNode* scopeChain;
39-
int expectedParams;
40-
int providedParams;
39+
int parameterCountIncludingThis;
40+
int argumentCountIncludingThis;
4141

42-
void setArgument(int arg, JSValue value)
42+
void setThis(JSValue value)
4343
{
44-
if (arg < expectedParams)
45-
newCallFrame[arg - RegisterFile::CallFrameHeaderSize - expectedParams] = value;
44+
newCallFrame[-RegisterFile::CallFrameHeaderSize - parameterCountIncludingThis] = value;
45+
if (argumentCountIncludingThis > parameterCountIncludingThis)
46+
newCallFrame[-RegisterFile::CallFrameHeaderSize - parameterCountIncludingThis - argumentCountIncludingThis] = value;
47+
}
48+
49+
void setArgument(int argument, JSValue value)
50+
{
51+
if (argument + 1 < parameterCountIncludingThis)
52+
newCallFrame[argument + 1 - RegisterFile::CallFrameHeaderSize - parameterCountIncludingThis] = value;
4653

47-
if (providedParams > expectedParams)
48-
newCallFrame[arg - RegisterFile::CallFrameHeaderSize - expectedParams - providedParams] = value;
54+
if (argumentCountIncludingThis > parameterCountIncludingThis)
55+
newCallFrame[argument + 1 - RegisterFile::CallFrameHeaderSize - parameterCountIncludingThis - argumentCountIncludingThis] = value;
4956
}
5057

5158
void resetCallFrame()
5259
{
5360
newCallFrame->setScopeChain(scopeChain);
54-
for (int i = providedParams; i < expectedParams; ++i)
55-
newCallFrame[i - RegisterFile::CallFrameHeaderSize - expectedParams] = jsUndefined();
61+
for (int i = argumentCountIncludingThis; i < parameterCountIncludingThis; ++i)
62+
newCallFrame[i - RegisterFile::CallFrameHeaderSize - parameterCountIncludingThis] = jsUndefined();
5663
}
5764
};
5865

Source/JavaScriptCore/interpreter/Interpreter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ JSObject* Interpreter::executeConstruct(CallFrame* callFrame, JSObject* construc
12171217
return checkedReturn(asObject(result));
12181218
}
12191219

1220-
CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionExecutable, CallFrame* callFrame, JSFunction* function, int argCount, ScopeChainNode* scopeChain)
1220+
CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionExecutable, CallFrame* callFrame, JSFunction* function, int argumentCountIncludingThis, ScopeChainNode* scopeChain)
12211221
{
12221222
ASSERT(!scopeChain->globalData->exception);
12231223

@@ -1229,17 +1229,15 @@ CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionE
12291229
}
12301230

12311231
Register* oldEnd = m_registerFile.end();
1232-
int argc = 1 + argCount; // implicit "this" parameter
1233-
1234-
if (!m_registerFile.grow(oldEnd + argc)) {
1232+
if (!m_registerFile.grow(oldEnd + argumentCountIncludingThis)) {
12351233
throwStackOverflowError(callFrame);
12361234
return CallFrameClosure();
12371235
}
12381236

12391237
CallFrame* newCallFrame = CallFrame::create(oldEnd);
12401238
// We initialise |this| unnecessarily here for the sake of code clarity
12411239
size_t dst = 0;
1242-
for (int i = 0; i < argc; ++i)
1240+
for (int i = 0; i < argumentCountIncludingThis; ++i)
12431241
newCallFrame->uncheckedR(dst++) = jsUndefined();
12441242

12451243
JSObject* error = FunctionExecutable->compileForCall(callFrame, scopeChain);
@@ -1250,15 +1248,15 @@ CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionE
12501248
}
12511249
CodeBlock* codeBlock = &FunctionExecutable->generatedBytecodeForCall();
12521250

1253-
newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
1251+
newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argumentCountIncludingThis + RegisterFile::CallFrameHeaderSize, argumentCountIncludingThis);
12541252
if (UNLIKELY(!newCallFrame)) {
12551253
throwStackOverflowError(callFrame);
12561254
m_registerFile.shrink(oldEnd);
12571255
return CallFrameClosure();
12581256
}
1259-
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), argc, function);
1257+
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), argumentCountIncludingThis, function);
12601258
scopeChain->globalData->topCallFrame = newCallFrame;
1261-
CallFrameClosure result = { callFrame, newCallFrame, function, FunctionExecutable, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argc };
1259+
CallFrameClosure result = { callFrame, newCallFrame, function, FunctionExecutable, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argumentCountIncludingThis };
12621260
return result;
12631261
}
12641262

Source/JavaScriptCore/interpreter/Interpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace JSC {
141141
private:
142142
enum ExecutionFlag { Normal, InitializeAndReturn };
143143

144-
CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, JSFunction*, int argCount, ScopeChainNode*);
144+
CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, JSFunction*, int argumentCountIncludingThis, ScopeChainNode*);
145145
void endRepeatCall(CallFrameClosure&);
146146
JSValue execute(CallFrameClosure&);
147147

0 commit comments

Comments
 (0)