Changeset 163027 in webkit for trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
- Timestamp:
- Jan 29, 2014, 11:18:54 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r162711 r163027 66 66 #include "Register.h" 67 67 #include "SamplingTool.h" 68 #include "StackAlignment.h" 68 69 #include "StackVisitor.h" 69 70 #include "StrictEvalActivation.h" … … 75 76 #include <stdio.h> 76 77 #include <wtf/StackStats.h> 78 #include <wtf/StdLibExtras.h> 77 79 #include <wtf/StringPrintStream.h> 78 80 #include <wtf/Threading.h> … … 89 91 90 92 namespace JSC { 91 92 Interpreter::ErrorHandlingMode::ErrorHandlingMode(ExecState *exec)93 : m_interpreter(*exec->interpreter())94 {95 if (!m_interpreter.m_errorHandlingModeReentry)96 m_interpreter.stack().enableErrorStackReserve();97 m_interpreter.m_errorHandlingModeReentry++;98 }99 100 Interpreter::ErrorHandlingMode::~ErrorHandlingMode()101 {102 m_interpreter.m_errorHandlingModeReentry--;103 ASSERT(m_interpreter.m_errorHandlingModeReentry >= 0);104 if (!m_interpreter.m_errorHandlingModeReentry)105 m_interpreter.stack().disableErrorStackReserve();106 }107 93 108 94 JSValue eval(CallFrame* callFrame) … … 153 139 } 154 140 155 CallFrame* size AndAllocFrameForVarargs(CallFrame* callFrame, JSStack* stack, JSValue arguments, int firstFreeRegister)141 CallFrame* sizeFrameForVarargs(CallFrame* callFrame, JSStack* stack, JSValue arguments, int firstFreeRegister) 156 142 { 157 143 if (!arguments) { // f.apply(x, arguments), with arguments unmodified. 158 144 unsigned argumentCountIncludingThis = callFrame->argumentCountIncludingThis(); 159 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister - argumentCountIncludingThis - JSStack::CallFrameHeaderSize - 1); 160 if (argumentCountIncludingThis > Arguments::MaxArguments + 1 || !stack->grow(newCallFrame->registers())) { 161 callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame)); 145 unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + argumentCountIncludingThis + JSStack::CallFrameHeaderSize + 1); 146 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset); 147 if (argumentCountIncludingThis > Arguments::MaxArguments + 1 || !stack->ensureCapacityFor(newCallFrame->registers())) { 148 throwStackOverflowError(callFrame); 162 149 return 0; 163 150 } … … 166 153 167 154 if (arguments.isUndefinedOrNull()) { 168 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister - 1 - JSStack::CallFrameHeaderSize - 1); 169 if (!stack->grow(newCallFrame->registers())) { 170 callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame)); 155 unsigned argumentCountIncludingThis = 1; 156 unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + argumentCountIncludingThis + JSStack::CallFrameHeaderSize + 1); 157 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset); 158 if (!stack->ensureCapacityFor(newCallFrame->registers())) { 159 throwStackOverflowError(callFrame); 171 160 return 0; 172 161 } … … 182 171 Arguments* argsObject = asArguments(arguments); 183 172 unsigned argCount = argsObject->length(callFrame); 184 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1)); 185 if (argCount > Arguments::MaxArguments || !stack->grow(newCallFrame->registers())) { 186 callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame)); 173 unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1)); 174 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset); 175 if (argCount > Arguments::MaxArguments || !stack->ensureCapacityFor(newCallFrame->registers())) { 176 throwStackOverflowError(callFrame); 187 177 return 0; 188 178 } … … 193 183 JSArray* array = asArray(arguments); 194 184 unsigned argCount = array->length(); 195 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1)); 196 if (argCount > Arguments::MaxArguments || !stack->grow(newCallFrame->registers())) { 197 callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame)); 185 unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1)); 186 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset); 187 if (argCount > Arguments::MaxArguments || !stack->ensureCapacityFor(newCallFrame->registers())) { 188 throwStackOverflowError(callFrame); 198 189 return 0; 199 190 } … … 203 194 JSObject* argObject = asObject(arguments); 204 195 unsigned argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame); 205 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1)); 206 if (argCount > Arguments::MaxArguments || !stack->grow(newCallFrame->registers())) { 207 callFrame->vm().throwException(callFrame, createStackOverflowError(callFrame)); 196 unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1)); 197 CallFrame* newCallFrame = CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset); 198 if (argCount > Arguments::MaxArguments || !stack->ensureCapacityFor(newCallFrame->registers())) { 199 throwStackOverflowError(callFrame); 208 200 return 0; 209 201 } … … 422 414 CallFrame* callFrame = visitor->callFrame(); 423 415 CodeBlock* codeBlock = visitor->codeBlock(); 424 CodeBlock* oldCodeBlock = codeBlock;425 416 JSScope* scope = callFrame->scope(); 426 417 … … 433 424 434 425 JSValue activation; 435 if ( oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->needsActivation()) {426 if (codeBlock->codeType() == FunctionCode && codeBlock->needsActivation()) { 436 427 #if ENABLE(DFG_JIT) 437 428 RELEASE_ASSERT(!visitor->isInlinedFrame()); 438 429 #endif 439 activation = callFrame->uncheckedR( oldCodeBlock->activationRegister().offset()).jsValue();430 activation = callFrame->uncheckedR(codeBlock->activationRegister().offset()).jsValue(); 440 431 if (activation) 441 432 jsCast<JSActivation*>(activation)->tearOff(*scope->vm()); 442 433 } 443 434 444 if ( oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->usesArguments()) {435 if (codeBlock->codeType() == FunctionCode && codeBlock->usesArguments()) { 445 436 if (Arguments* arguments = visitor->existingArguments()) { 446 437 if (activation) … … 456 447 457 448 CallFrame* callerFrame = callFrame->callerFrame(); 458 if (callerFrame->isVMEntrySentinel()) { 459 callFrame->vm().topCallFrame = callerFrame->vmEntrySentinelCallerFrame(); 460 return false; 461 } 462 return true; 449 return !callerFrame->isVMEntrySentinel(); 463 450 } 464 451 … … 663 650 NEVER_INLINE HandlerInfo* Interpreter::unwind(CallFrame*& callFrame, JSValue& exceptionValue) 664 651 { 652 if (callFrame->isVMEntrySentinel()) { 653 // This happens when we throw stack overflow in a function that is called 654 // directly from callToJavaScript. Stack overflow throws the exception in the 655 // context of the caller. In that case the caller is the sentinel frame. The 656 // right thing to do is to pretend that the exception is uncaught so that we 657 // go to the uncaught exception handler, which returns through callToJavaScript. 658 return 0; 659 } 660 665 661 CodeBlock* codeBlock = callFrame->codeBlock(); 662 ASSERT(codeBlock); 666 663 bool isTermination = false; 667 664 … … 768 765 return jsNull(); 769 766 770 VMEntryScope entryScope(vm, scope->globalObject());771 767 if (!vm.isSafeToRecurse()) 772 768 return checkedReturn(throwStackOverflowError(callFrame)); … … 875 871 // object. 876 872 873 VMEntryScope entryScope(vm, scope->globalObject()); 874 877 875 // Compile source to bytecode if necessary: 878 876 if (JSObject* error = program->initializeGlobalProperties(vm, callFrame, scope)) … … 889 887 ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'. 890 888 891 if (UNLIKELY(!m_stack.entryCheck(codeBlock, 1)))892 return checkedReturn(throwStackOverflowError(callFrame));893 894 889 ProtoCallFrame protoCallFrame; 895 890 protoCallFrame.init(codeBlock, scope, 0, thisObj, 1); … … 904 899 Watchdog::Scope watchdogScope(vm.watchdog); 905 900 906 result = program->generatedJITCode()->execute(&vm, &protoCallFrame , m_stack.getTopOfStack());901 result = program->generatedJITCode()->execute(&vm, &protoCallFrame); 907 902 } 908 903 … … 952 947 return throwTerminatedExecutionException(callFrame); 953 948 954 if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount)))955 return checkedReturn(throwStackOverflowError(callFrame));956 957 949 ProtoCallFrame protoCallFrame; 958 950 protoCallFrame.init(newCodeBlock, scope, function, thisValue, argsCount, args.data()); … … 968 960 // Execute the code: 969 961 if (isJSCall) 970 result = callData.js.functionExecutable->generatedJITCodeForCall()->execute(&vm, &protoCallFrame, m_stack.getTopOfStack()); 971 else 972 result = JSValue::decode(callToNativeFunction(reinterpret_cast<void*>(callData.native.function), &vm.topCallFrame, &protoCallFrame, m_stack.getTopOfStack())); 962 result = callData.js.functionExecutable->generatedJITCodeForCall()->execute(&vm, &protoCallFrame); 963 else { 964 result = JSValue::decode(callToNativeFunction(reinterpret_cast<void*>(callData.native.function), &vm, &protoCallFrame)); 965 if (callFrame->hadException()) 966 result = jsNull(); 967 } 973 968 } 974 969 … … 1020 1015 return throwTerminatedExecutionException(callFrame); 1021 1016 1022 if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount)))1023 return checkedReturn(throwStackOverflowError(callFrame));1024 1025 1017 ProtoCallFrame protoCallFrame; 1026 1018 protoCallFrame.init(newCodeBlock, scope, constructor, jsUndefined(), argsCount, args.data()); … … 1036 1028 // Execute the code. 1037 1029 if (isJSConstruct) 1038 result = constructData.js.functionExecutable->generatedJITCodeForConstruct()->execute(&vm, &protoCallFrame , m_stack.getTopOfStack());1030 result = constructData.js.functionExecutable->generatedJITCodeForConstruct()->execute(&vm, &protoCallFrame); 1039 1031 else { 1040 result = JSValue::decode(callToNativeFunction(reinterpret_cast<void*>(constructData.native.function), &vm .topCallFrame, &protoCallFrame, m_stack.getTopOfStack()));1032 result = JSValue::decode(callToNativeFunction(reinterpret_cast<void*>(constructData.native.function), &vm, &protoCallFrame)); 1041 1033 1042 1034 if (!callFrame->hadException()) … … 1072 1064 1073 1065 size_t argsCount = argumentCountIncludingThis; 1074 1075 if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount))) {1076 throwStackOverflowError(callFrame);1077 return CallFrameClosure();1078 }1079 1066 1080 1067 protoCallFrame->init(newCodeBlock, scope, function, jsUndefined(), argsCount, args); … … 1108 1095 Watchdog::Scope watchdogScope(vm.watchdog); 1109 1096 1110 result = closure.functionExecutable->generatedJITCodeForCall()->execute(&vm, closure.protoCallFrame , m_stack.getTopOfStack());1097 result = closure.functionExecutable->generatedJITCodeForCall()->execute(&vm, closure.protoCallFrame); 1111 1098 } 1112 1099 … … 1179 1166 ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'. 1180 1167 1181 if (UNLIKELY(!m_stack.entryCheck(codeBlock, 1)))1182 return checkedReturn(throwStackOverflowError(callFrame));1183 1184 1168 ProtoCallFrame protoCallFrame; 1185 1169 protoCallFrame.init(codeBlock, scope, 0, thisValue, 1); … … 1194 1178 Watchdog::Scope watchdogScope(vm.watchdog); 1195 1179 1196 result = eval->generatedJITCode()->execute(&vm, &protoCallFrame , m_stack.getTopOfStack());1180 result = eval->generatedJITCode()->execute(&vm, &protoCallFrame); 1197 1181 } 1198 1182
Note:
See TracChangeset
for help on using the changeset viewer.