Commit 75cc932a authored by msaboff@apple.com's avatar msaboff@apple.com

Split sizing of VarArgs frames from loading arguments for the frame

https://bugs.webkit.org/show_bug.cgi?id=125331

Reviewed by Filip Pizlo.

Split loadVarargs into sizeAndAllocFrameForVarargs() and loadVarargs() in
preparation for moving onto the C stack.  sizeAndAllocFrameForVarargs() will
compute the size of the callee frame and allocate it, while loadVarargs()
actually loads the argument values.

As part of moving onto the C stack, sizeAndAllocFrameForVarargs() will be
changed to a function that just computes the size.  The caller will use that
size to allocate the new frame on the stack before calling loadVargs() and
actually making the call.

* interpreter/Interpreter.cpp:
(JSC::sizeAndAllocFrameForVarargs):
(JSC::loadVarargs):
* interpreter/Interpreter.h:
* jit/JIT.h:
* jit/JITCall.cpp:
(JSC::JIT::compileLoadVarargs):
* jit/JITCall32_64.cpp:
(JSC::JIT::compileLoadVarargs):
* jit/JITInlines.h:
(JSC::JIT::callOperation):
* jit/JITOperations.cpp:
* jit/JITOperations.h:
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* llint/LLIntSlowPaths.h:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
* runtime/VM.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160244 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3b5bb143
2013-12-06 Michael Saboff <msaboff@apple.com>
Split sizing of VarArgs frames from loading arguments for the frame
https://bugs.webkit.org/show_bug.cgi?id=125331
Reviewed by Filip Pizlo.
Split loadVarargs into sizeAndAllocFrameForVarargs() and loadVarargs() in
preparation for moving onto the C stack. sizeAndAllocFrameForVarargs() will
compute the size of the callee frame and allocate it, while loadVarargs()
actually loads the argument values.
As part of moving onto the C stack, sizeAndAllocFrameForVarargs() will be
changed to a function that just computes the size. The caller will use that
size to allocate the new frame on the stack before calling loadVargs() and
actually making the call.
* interpreter/Interpreter.cpp:
(JSC::sizeAndAllocFrameForVarargs):
(JSC::loadVarargs):
* interpreter/Interpreter.h:
* jit/JIT.h:
* jit/JITCall.cpp:
(JSC::JIT::compileLoadVarargs):
* jit/JITCall32_64.cpp:
(JSC::JIT::compileLoadVarargs):
* jit/JITInlines.h:
(JSC::JIT::callOperation):
* jit/JITOperations.cpp:
* jit/JITOperations.h:
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* llint/LLIntSlowPaths.h:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
* runtime/VM.h:
2013-12-06 Filip Pizlo <fpizlo@apple.com>
FTL should support all of ValueToInt32
......
......@@ -152,7 +152,7 @@ JSValue eval(CallFrame* callFrame)
return interpreter->execute(eval, callFrame, thisValue, callerScopeChain);
}
CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue, JSValue arguments, int firstFreeRegister)
CallFrame* sizeAndAllocFrameForVarargs(CallFrame* callFrame, JSStack* stack, JSValue arguments, int firstFreeRegister)
{
if (!arguments) { // f.apply(x, arguments), with arguments unmodified.
unsigned argumentCountIncludingThis = callFrame->argumentCountIncludingThis();
......@@ -161,11 +161,6 @@ CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue,
callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame));
return 0;
}
newCallFrame->setArgumentCountIncludingThis(argumentCountIncludingThis);
newCallFrame->setThisValue(thisValue);
for (size_t i = 0; i < callFrame->argumentCount(); ++i)
newCallFrame->setArgument(i, callFrame->argumentAfterCapture(i));
return newCallFrame;
}
......@@ -175,8 +170,6 @@ CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue,
callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame));
return 0;
}
newCallFrame->setArgumentCountIncludingThis(1);
newCallFrame->setThisValue(thisValue);
return newCallFrame;
}
......@@ -193,9 +186,6 @@ CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue,
callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame));
return 0;
}
newCallFrame->setArgumentCountIncludingThis(argCount + 1);
newCallFrame->setThisValue(thisValue);
argsObject->copyToArguments(callFrame, newCallFrame, argCount);
return newCallFrame;
}
......@@ -207,9 +197,6 @@ CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue,
callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame));
return 0;
}
newCallFrame->setArgumentCountIncludingThis(argCount + 1);
newCallFrame->setThisValue(thisValue);
array->copyToArguments(callFrame, newCallFrame, argCount);
return newCallFrame;
}
......@@ -220,14 +207,54 @@ CallFrame* loadVarargs(CallFrame* callFrame, JSStack* stack, JSValue thisValue,
callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame));
return 0;
}
return newCallFrame;
}
void loadVarargs(CallFrame* callFrame, CallFrame* newCallFrame, JSValue thisValue, JSValue arguments)
{
if (!arguments) { // f.apply(x, arguments), with arguments unmodified.
unsigned argumentCountIncludingThis = callFrame->argumentCountIncludingThis();
newCallFrame->setArgumentCountIncludingThis(argumentCountIncludingThis);
newCallFrame->setThisValue(thisValue);
for (size_t i = 0; i < callFrame->argumentCount(); ++i)
newCallFrame->setArgument(i, callFrame->argumentAfterCapture(i));
return;
}
if (arguments.isUndefinedOrNull()) {
newCallFrame->setArgumentCountIncludingThis(1);
newCallFrame->setThisValue(thisValue);
return;
}
if (asObject(arguments)->classInfo() == Arguments::info()) {
Arguments* argsObject = asArguments(arguments);
unsigned argCount = argsObject->length(callFrame);
newCallFrame->setArgumentCountIncludingThis(argCount + 1);
newCallFrame->setThisValue(thisValue);
argsObject->copyToArguments(callFrame, newCallFrame, argCount);
return;
}
if (isJSArray(arguments)) {
JSArray* array = asArray(arguments);
unsigned argCount = array->length();
newCallFrame->setArgumentCountIncludingThis(argCount + 1);
newCallFrame->setThisValue(thisValue);
array->copyToArguments(callFrame, newCallFrame, argCount);
return;
}
JSObject* argObject = asObject(arguments);
unsigned argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
newCallFrame->setArgumentCountIncludingThis(argCount + 1);
newCallFrame->setThisValue(thisValue);
for (size_t i = 0; i < argCount; ++i) {
newCallFrame->setArgument(i, asObject(arguments)->get(callFrame, i));
if (UNLIKELY(callFrame->vm().exception()))
return 0;
return;
}
return newCallFrame;
}
Interpreter::Interpreter(VM& vm)
......
......@@ -286,8 +286,8 @@ namespace JSC {
};
JSValue eval(CallFrame*);
CallFrame* loadVarargs(CallFrame*, JSStack*, JSValue thisValue, JSValue arguments, int firstFreeRegister);
CallFrame* sizeAndAllocFrameForVarargs(CallFrame*, JSStack*, JSValue, int);
void loadVarargs(CallFrame*, CallFrame*, JSValue, JSValue);
} // namespace JSC
#endif // Interpreter_h
......@@ -670,7 +670,7 @@ namespace JSC {
MacroAssembler::Call callOperation(C_JITOperation_EO, GPRReg);
MacroAssembler::Call callOperation(C_JITOperation_ESt, Structure*);
MacroAssembler::Call callOperation(C_JITOperation_EZ, int32_t);
MacroAssembler::Call callOperation(F_JITOperation_EJJZ, GPRReg, GPRReg, int32_t);
MacroAssembler::Call callOperation(F_JITOperation_EJZ, GPRReg, int32_t);
MacroAssembler::Call callOperation(J_JITOperation_E, int);
MacroAssembler::Call callOperation(J_JITOperation_EAapJ, int, ArrayAllocationProfile*, GPRReg);
MacroAssembler::Call callOperation(J_JITOperation_EAapJcpZ, int, ArrayAllocationProfile*, GPRReg, int32_t);
......@@ -711,6 +711,7 @@ namespace JSC {
#endif
MacroAssembler::Call callOperation(V_JITOperation_EJIdJJ, RegisterID, const Identifier*, RegisterID, RegisterID);
#if USE(JSVALUE64)
MacroAssembler::Call callOperation(F_JITOperation_EFJJ, RegisterID, RegisterID, RegisterID);
MacroAssembler::Call callOperation(V_JITOperation_ESsiJJI, StructureStubInfo*, RegisterID, RegisterID, StringImpl*);
#else
MacroAssembler::Call callOperation(V_JITOperation_ESsiJJI, StructureStubInfo*, RegisterID, RegisterID, RegisterID, RegisterID, StringImpl*);
......@@ -724,7 +725,8 @@ namespace JSC {
MacroAssembler::Call callOperationWithCallFrameRollbackOnException(V_JITOperation_ECb, CodeBlock*);
MacroAssembler::Call callOperationWithCallFrameRollbackOnException(Z_JITOperation_E);
#if USE(JSVALUE32_64)
MacroAssembler::Call callOperation(F_JITOperation_EJJZ, GPRReg, GPRReg, GPRReg, GPRReg, int32_t);
MacroAssembler::Call callOperation(F_JITOperation_EFJJ, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID);
MacroAssembler::Call callOperation(F_JITOperation_EJZ, GPRReg, GPRReg, int32_t);
MacroAssembler::Call callOperation(J_JITOperation_EAapJ, int, ArrayAllocationProfile*, GPRReg, GPRReg);
MacroAssembler::Call callOperation(J_JITOperation_EJ, int, GPRReg, GPRReg);
MacroAssembler::Call callOperation(J_JITOperation_EJIdc, int, GPRReg, GPRReg, const Identifier*);
......
......@@ -104,9 +104,11 @@ void JIT::compileLoadVarargs(Instruction* instruction)
if (canOptimize)
slowCase.link(this);
emitGetVirtualRegister(thisValue, regT0);
emitGetVirtualRegister(arguments, regT1);
callOperation(operationLoadVarargs, regT0, regT1, firstFreeRegister);
callOperation(operationSizeAndAllocFrameForVarargs, regT1, firstFreeRegister);
emitGetVirtualRegister(thisValue, regT1);
emitGetVirtualRegister(arguments, regT2);
callOperation(operationLoadVarargs, returnValueGPR, regT1, regT2);
move(returnValueGPR, regT1);
if (canOptimize)
......
......@@ -184,9 +184,12 @@ void JIT::compileLoadVarargs(Instruction* instruction)
if (canOptimize)
slowCase.link(this);
emitLoad(arguments, regT1, regT0);
callOperation(operationSizeAndAllocFrameForVarargs, regT1, regT0, firstFreeRegister);
move(returnValueGPR, regT5);
emitLoad(thisValue, regT1, regT0);
emitLoad(arguments, regT3, regT2);
callOperation(operationLoadVarargs, regT1, regT0, regT3, regT2, firstFreeRegister);
callOperation(operationLoadVarargs, regT5, regT1, regT0, regT3, regT2);
move(returnValueGPR, regT3);
if (canOptimize)
......
......@@ -285,9 +285,15 @@ ALWAYS_INLINE MacroAssembler::Call JIT::callOperationWithCallFrameRollbackOnExce
#if USE(JSVALUE64)
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EJJZ operation, GPRReg arg1, GPRReg arg2, int32_t arg3)
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EJZ operation, GPRReg arg1, int32_t arg3)
{
setupArgumentsWithExecState(arg1, arg2, TrustedImm32(arg3));
setupArgumentsWithExecState(arg1, TrustedImm32(arg3));
return appendCallWithExceptionCheck(operation);
}
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EFJJ operation, GPRReg arg1, GPRReg arg2, GPRReg arg3)
{
setupArgumentsWithExecState(arg1, arg2, arg3);
return appendCallWithExceptionCheck(operation);
}
......@@ -420,17 +426,23 @@ ALWAYS_INLINE MacroAssembler::Call JIT::callOperationNoExceptionCheck(V_JITOpera
return appendCall(operation);
}
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EJJZ operation, GPRReg arg1Tag, GPRReg arg1Payload, GPRReg arg2Tag, GPRReg arg2Payload, int32_t arg3)
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EJZ operation, GPRReg arg1Tag, GPRReg arg1Payload, int32_t arg2)
{
#if CPU(SH4)
// We have to put arg3 in the 4th argument register (r7) as 64-bit value arg2 will be put on stack for sh4 architecure.
setupArgumentsWithExecState(arg1Payload, arg1Tag, TrustedImm32(arg3), arg2Payload, arg2Tag);
setupArgumentsWithExecState(arg1Payload, arg1Tag, TrustedImm32(arg2));
#else
setupArgumentsWithExecState(EABI_32BIT_DUMMY_ARG arg1Payload, arg1Tag, arg2Payload, arg2Tag, TrustedImm32(arg3));
setupArgumentsWithExecState(EABI_32BIT_DUMMY_ARG arg1Payload, arg1Tag, TrustedImm32(arg2));
#endif
return appendCallWithExceptionCheck(operation);
}
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(F_JITOperation_EFJJ operation, GPRReg arg1, GPRReg arg2Tag, GPRReg arg2Payload, GPRReg arg3Tag, GPRReg arg3Payload)
{
setupArgumentsWithExecState(arg1, arg2Payload, arg2Tag, arg3Payload, arg3Tag);
return appendCallWithExceptionCheck(operation);
}
ALWAYS_INLINE MacroAssembler::Call JIT::callOperation(J_JITOperation_EAapJ operation, int dst, ArrayAllocationProfile* arg1, GPRReg arg2Tag, GPRReg arg2Payload)
{
setupArgumentsWithExecState(TrustedImmPtr(arg1), arg2Payload, arg2Tag);
......
......@@ -1526,14 +1526,23 @@ EncodedJSValue JIT_OPERATION operationInstanceOf(ExecState* exec, EncodedJSValue
return JSValue::encode(jsBoolean(result));
}
CallFrame* JIT_OPERATION operationLoadVarargs(ExecState* exec, EncodedJSValue encodedThis, EncodedJSValue encodedArguments, int32_t firstFreeRegister)
CallFrame* JIT_OPERATION operationSizeAndAllocFrameForVarargs(ExecState* exec, EncodedJSValue encodedArguments, int32_t firstFreeRegister)
{
VM& vm = exec->vm();
NativeCallFrameTracer tracer(&vm, exec);
JSStack* stack = &exec->interpreter()->stack();
JSValue arguments = JSValue::decode(encodedArguments);
CallFrame* newCallFrame = sizeAndAllocFrameForVarargs(exec, stack, arguments, firstFreeRegister);
return newCallFrame;
}
CallFrame* JIT_OPERATION operationLoadVarargs(ExecState* exec, CallFrame* newCallFrame, EncodedJSValue encodedThis, EncodedJSValue encodedArguments)
{
VM& vm = exec->vm();
NativeCallFrameTracer tracer(&vm, exec);
JSValue thisValue = JSValue::decode(encodedThis);
JSValue arguments = JSValue::decode(encodedArguments);
CallFrame* newCallFrame = loadVarargs(exec, stack, thisValue, arguments, firstFreeRegister);
loadVarargs(exec, newCallFrame, thisValue, arguments);
return newCallFrame;
}
......
......@@ -79,7 +79,9 @@ extern "C" {
Vws: VariableWatchpointSet*
Z: int32_t
*/
typedef CallFrame* JIT_OPERATION (*F_JITOperation_EJJZ)(ExecState*, EncodedJSValue, EncodedJSValue, int32_t);
typedef CallFrame* JIT_OPERATION (*F_JITOperation_EFJJ)(ExecState*, CallFrame*, EncodedJSValue, EncodedJSValue);
typedef CallFrame* JIT_OPERATION (*F_JITOperation_EJZ)(ExecState*, EncodedJSValue, int32_t);
typedef EncodedJSValue JIT_OPERATION (*J_JITOperation_E)(ExecState*);
typedef EncodedJSValue JIT_OPERATION (*J_JITOperation_EA)(ExecState*, JSArray*);
typedef EncodedJSValue JIT_OPERATION (*J_JITOperation_EAZ)(ExecState*, JSArray*, int32_t);
......@@ -264,7 +266,8 @@ void JIT_OPERATION operationTearOffArguments(ExecState*, JSCell*, JSCell*) WTF_I
EncodedJSValue JIT_OPERATION operationDeleteById(ExecState*, EncodedJSValue base, const Identifier*) WTF_INTERNAL;
JSCell* JIT_OPERATION operationGetPNames(ExecState*, JSObject*) WTF_INTERNAL;
EncodedJSValue JIT_OPERATION operationInstanceOf(ExecState*, EncodedJSValue, EncodedJSValue proto) WTF_INTERNAL;
CallFrame* JIT_OPERATION operationLoadVarargs(ExecState*, EncodedJSValue thisValue, EncodedJSValue arguments, int32_t firstFreeRegister) WTF_INTERNAL;
CallFrame* JIT_OPERATION operationSizeAndAllocFrameForVarargs(ExecState*, EncodedJSValue arguments, int32_t firstFreeRegister) WTF_INTERNAL;
CallFrame* JIT_OPERATION operationLoadVarargs(ExecState*, CallFrame*, EncodedJSValue thisValue, EncodedJSValue arguments) WTF_INTERNAL;
EncodedJSValue JIT_OPERATION operationToObject(ExecState*, EncodedJSValue) WTF_INTERNAL;
char* JIT_OPERATION operationSwitchCharWithUnknownKeyType(ExecState*, EncodedJSValue key, size_t tableIndex) WTF_INTERNAL;
......
......@@ -1105,19 +1105,33 @@ LLINT_SLOW_PATH_DECL(slow_path_construct)
return genericCall(exec, pc, CodeForConstruct);
}
LLINT_SLOW_PATH_DECL(slow_path_call_varargs)
LLINT_SLOW_PATH_DECL(slow_path_size_and_alloc_frame_for_varargs)
{
LLINT_BEGIN();
// This needs to:
// - Set up a call frame while respecting the variable arguments.
ExecState* execCallee = sizeAndAllocFrameForVarargs(exec, &vm.interpreter->stack(),
LLINT_OP_C(4).jsValue(), pc[5].u.operand);
LLINT_CALL_CHECK_EXCEPTION(exec);
vm.newCallFrameReturnValue = execCallee;
LLINT_END();
}
LLINT_SLOW_PATH_DECL(slow_path_call_varargs)
{
LLINT_BEGIN_NO_SET_PC();
// This needs to:
// - Figure out what to call and compile it if necessary.
// - Return a tuple of machine code address to call and the new call frame.
JSValue calleeAsValue = LLINT_OP_C(2).jsValue();
ExecState* execCallee = loadVarargs(
exec, &vm.interpreter->stack(),
LLINT_OP_C(3).jsValue(), LLINT_OP_C(4).jsValue(), pc[5].u.operand);
ExecState* execCallee = vm.newCallFrameReturnValue;
loadVarargs(exec, execCallee, LLINT_OP_C(3).jsValue(), LLINT_OP_C(4).jsValue());
LLINT_CALL_CHECK_EXCEPTION(exec);
execCallee->uncheckedR(JSStack::Callee) = calleeAsValue;
......
......@@ -100,6 +100,7 @@ LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_new_func);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_new_func_exp);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_call);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_construct);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_size_and_alloc_frame_for_varargs);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_call_varargs);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_call_eval);
LLINT_SLOW_PATH_HIDDEN_DECL(slow_path_tear_off_activation);
......
......@@ -723,6 +723,8 @@ _llint_op_construct:
_llint_op_call_varargs:
traceExecution()
callSlowPath(_llint_slow_path_size_and_alloc_frame_for_varargs)
branchIfException(_llint_throw_from_slow_path_trampoline)
slowPathForCall(_llint_slow_path_call_varargs)
......
......@@ -551,6 +551,14 @@ macro functionArityCheck(doneLabel, slow_path)
end
macro branchIfException(label)
loadp ScopeChain[cfr], t3
andp MarkedBlockMask, t3
loadp MarkedBlock::m_weakSet + WeakSet::m_vm[t3], t3
bineq VM::m_exception + TagOffset[t3], EmptyValueTag, label
end
# Instruction implementations
_llint_op_enter:
......
......@@ -389,6 +389,14 @@ macro functionArityCheck(doneLabel, slow_path)
end
macro branchIfException(label)
loadp ScopeChain[cfr], t3
andp MarkedBlockMask, t3
loadp MarkedBlock::m_weakSet + WeakSet::m_vm[t3], t3
btqnz VM::m_exception[t3], label
end
# Instruction implementations
_llint_op_enter:
......
......@@ -383,6 +383,7 @@ namespace JSC {
ReturnAddressPtr exceptionLocation;
JSValue hostCallReturnValue;
ExecState* newCallFrameReturnValue;
ExecState* callFrameForThrow;
void* targetMachinePCForThrow;
Instruction* targetInterpreterPCForThrow;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment