Ignore:
Timestamp:
Jan 29, 2014, 11:18:54 AM (12 years ago)
Author:
[email protected]
Message:

Merge the jsCStack branch
https://bugs.webkit.org/show_bug.cgi?id=127763

Reviewed by Mark Hahnenberg.

Source/JavaScriptCore:

Changes from http://svn.webkit.org/repository/webkit/branches/jsCStack
up to changeset 162958.

Source/WebCore:

Changes from http://svn.webkit.org/repository/webkit/branches/jsCStack
up to changeset 162958.

Source/WTF:

Changes from http://svn.webkit.org/repository/webkit/branches/jsCStack
up to changeset 162958.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r162711 r163027  
    6666#include "Register.h"
    6767#include "SamplingTool.h"
     68#include "StackAlignment.h"
    6869#include "StackVisitor.h"
    6970#include "StrictEvalActivation.h"
     
    7576#include <stdio.h>
    7677#include <wtf/StackStats.h>
     78#include <wtf/StdLibExtras.h>
    7779#include <wtf/StringPrintStream.h>
    7880#include <wtf/Threading.h>
     
    8991
    9092namespace 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 }
    10793
    10894JSValue eval(CallFrame* callFrame)
     
    153139}
    154140
    155 CallFrame* sizeAndAllocFrameForVarargs(CallFrame* callFrame, JSStack* stack, JSValue arguments, int firstFreeRegister)
     141CallFrame* sizeFrameForVarargs(CallFrame* callFrame, JSStack* stack, JSValue arguments, int firstFreeRegister)
    156142{
    157143    if (!arguments) { // f.apply(x, arguments), with arguments unmodified.
    158144        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);
    162149            return 0;
    163150        }
     
    166153
    167154    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);
    171160            return 0;
    172161        }
     
    182171        Arguments* argsObject = asArguments(arguments);
    183172        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);
    187177            return 0;
    188178        }
     
    193183        JSArray* array = asArray(arguments);
    194184        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);
    198189            return 0;
    199190        }
     
    203194    JSObject* argObject = asObject(arguments);
    204195    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);
    208200        return 0;
    209201    }
     
    422414    CallFrame* callFrame = visitor->callFrame();
    423415    CodeBlock* codeBlock = visitor->codeBlock();
    424     CodeBlock* oldCodeBlock = codeBlock;
    425416    JSScope* scope = callFrame->scope();
    426417
     
    433424
    434425    JSValue activation;
    435     if (oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->needsActivation()) {
     426    if (codeBlock->codeType() == FunctionCode && codeBlock->needsActivation()) {
    436427#if ENABLE(DFG_JIT)
    437428        RELEASE_ASSERT(!visitor->isInlinedFrame());
    438429#endif
    439         activation = callFrame->uncheckedR(oldCodeBlock->activationRegister().offset()).jsValue();
     430        activation = callFrame->uncheckedR(codeBlock->activationRegister().offset()).jsValue();
    440431        if (activation)
    441432            jsCast<JSActivation*>(activation)->tearOff(*scope->vm());
    442433    }
    443434
    444     if (oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->usesArguments()) {
     435    if (codeBlock->codeType() == FunctionCode && codeBlock->usesArguments()) {
    445436        if (Arguments* arguments = visitor->existingArguments()) {
    446437            if (activation)
     
    456447
    457448    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();
    463450}
    464451
     
    663650NEVER_INLINE HandlerInfo* Interpreter::unwind(CallFrame*& callFrame, JSValue& exceptionValue)
    664651{
     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   
    665661    CodeBlock* codeBlock = callFrame->codeBlock();
     662    ASSERT(codeBlock);
    666663    bool isTermination = false;
    667664
     
    768765        return jsNull();
    769766
    770     VMEntryScope entryScope(vm, scope->globalObject());
    771767    if (!vm.isSafeToRecurse())
    772768        return checkedReturn(throwStackOverflowError(callFrame));
     
    875871    // object.
    876872
     873    VMEntryScope entryScope(vm, scope->globalObject());
     874
    877875    // Compile source to bytecode if necessary:
    878876    if (JSObject* error = program->initializeGlobalProperties(vm, callFrame, scope))
     
    889887    ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
    890888
    891     if (UNLIKELY(!m_stack.entryCheck(codeBlock, 1)))
    892         return checkedReturn(throwStackOverflowError(callFrame));
    893 
    894889    ProtoCallFrame protoCallFrame;
    895890    protoCallFrame.init(codeBlock, scope, 0, thisObj, 1);
     
    904899        Watchdog::Scope watchdogScope(vm.watchdog);
    905900
    906         result = program->generatedJITCode()->execute(&vm, &protoCallFrame, m_stack.getTopOfStack());
     901        result = program->generatedJITCode()->execute(&vm, &protoCallFrame);
    907902    }
    908903
     
    952947        return throwTerminatedExecutionException(callFrame);
    953948
    954     if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount)))
    955         return checkedReturn(throwStackOverflowError(callFrame));
    956 
    957949    ProtoCallFrame protoCallFrame;
    958950    protoCallFrame.init(newCodeBlock, scope, function, thisValue, argsCount, args.data());
     
    968960        // Execute the code:
    969961        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        }
    973968    }
    974969
     
    10201015        return throwTerminatedExecutionException(callFrame);
    10211016
    1022     if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount)))
    1023         return checkedReturn(throwStackOverflowError(callFrame));
    1024 
    10251017    ProtoCallFrame protoCallFrame;
    10261018    protoCallFrame.init(newCodeBlock, scope, constructor, jsUndefined(), argsCount, args.data());
     
    10361028        // Execute the code.
    10371029        if (isJSConstruct)
    1038             result = constructData.js.functionExecutable->generatedJITCodeForConstruct()->execute(&vm, &protoCallFrame, m_stack.getTopOfStack());
     1030            result = constructData.js.functionExecutable->generatedJITCodeForConstruct()->execute(&vm, &protoCallFrame);
    10391031        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));
    10411033
    10421034            if (!callFrame->hadException())
     
    10721064
    10731065    size_t argsCount = argumentCountIncludingThis;
    1074 
    1075     if (UNLIKELY(!m_stack.entryCheck(newCodeBlock, argsCount))) {
    1076         throwStackOverflowError(callFrame);
    1077         return CallFrameClosure();
    1078     }
    10791066
    10801067    protoCallFrame->init(newCodeBlock, scope, function, jsUndefined(), argsCount, args);
     
    11081095        Watchdog::Scope watchdogScope(vm.watchdog);
    11091096
    1110         result = closure.functionExecutable->generatedJITCodeForCall()->execute(&vm, closure.protoCallFrame, m_stack.getTopOfStack());
     1097        result = closure.functionExecutable->generatedJITCodeForCall()->execute(&vm, closure.protoCallFrame);
    11111098    }
    11121099
     
    11791166    ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
    11801167
    1181     if (UNLIKELY(!m_stack.entryCheck(codeBlock, 1)))
    1182         return checkedReturn(throwStackOverflowError(callFrame));
    1183 
    11841168    ProtoCallFrame protoCallFrame;
    11851169    protoCallFrame.init(codeBlock, scope, 0, thisValue, 1);
     
    11941178        Watchdog::Scope watchdogScope(vm.watchdog);
    11951179
    1196         result = eval->generatedJITCode()->execute(&vm, &protoCallFrame, m_stack.getTopOfStack());
     1180        result = eval->generatedJITCode()->execute(&vm, &protoCallFrame);
    11971181    }
    11981182
Note: See TracChangeset for help on using the changeset viewer.