Ignore:
Timestamp:
May 18, 2010, 10:10:11 PM (15 years ago)
Author:
[email protected]
Message:

JavaScriptCore: Simplified handling of 'arguments' -- 1.2% SunSpider speedup
https://bugs.webkit.org/show_bug.cgi?id=39200

Reviewed by Darin Adler.

Removed the reserved OptionalCalleeArguments slot from the CallFrame.
Now, slots for 'arguments' are allocated and initialized only by
functions that might need them.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dump): Updated for new bytecode operands.

(JSC::CodeBlock::CodeBlock):

  • bytecode/CodeBlock.h:

(JSC::unmodifiedArgumentsRegister): Added a helper function for mapping
from the arguments register to its unmodified counterpart.

(JSC::CodeBlock::setArgumentsRegister):
(JSC::CodeBlock::argumentsRegister):
(JSC::CodeBlock::usesArguments): Changed from a "usesArguments" bool to
an optional int index representing the arguments register.

  • bytecode/Opcode.h: Updated for new bytecode operands.
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::addVar): Factored out a helper function for
allocating an anonymous var.

(JSC::BytecodeGenerator::BytecodeGenerator): Merged / simplified some
arguments vs activation logic, and added code to allocate the arguments
registers when needed.

(JSC::BytecodeGenerator::createArgumentsIfNecessary): Updated for new bytecode operands.

(JSC::BytecodeGenerator::emitCallEval): No need to create the arguments
object before calling eval; the activation object will lazily create the
arguments object if eval resolves it.

(JSC::BytecodeGenerator::emitReturn): Updated for new bytecode operands.

(JSC::BytecodeGenerator::emitPushScope):
(JSC::BytecodeGenerator::emitPushNewScope): Ditto emitCallEval.

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::addVar): Factored out a helper function for
allocating an anonymous var.

(JSC::BytecodeGenerator::registerFor): No more need for special handling
of the arguments registers; they're allocated just like normal registers
now.

  • interpreter/CallFrame.h:

(JSC::ExecState::callerFrame):
(JSC::ExecState::init):

  • interpreter/CallFrameClosure.h:

(JSC::CallFrameClosure::resetCallFrame): Nixed optionalCalleeArguments.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::dumpRegisters):
(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::privateExecute):
(JSC::Interpreter::retrieveArguments): Opcodes accessing 'arguments' now
take operands specifying registers, just like all other opcodes.
JSActivation::copyRegisters is no longer responsible for tearing off the
arguments object; instead, the VM is responsible for both.

Also, a behavior change: Each access to f.arguments creates a new object,
unless f itself uses 'arguments'. This matches Chrome, and is necessary
for the optimization. f.arguments is a nonstandard, deprecated feature,
so high fidelity to a given implementation is not necessarily a goal.
Also, as illustrated by the new test case, the identity of f.arguments
has been broken since 2008, except in the case where f itself accesses
f.arguments -- but nobody seemed to notice. So, hopefully this change won't
break the web.

  • interpreter/Register.h: Nixed the special arguments accessor. It's no

longer needed.

  • interpreter/RegisterFile.h:

(JSC::RegisterFile::):

  • jit/JITCall.cpp:

(JSC::JIT::compileOpCallInitializeCallFrame):
(JSC::JIT::compileOpCall):

  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_tear_off_activation):
(JSC::JIT::emit_op_tear_off_arguments):
(JSC::JIT::emit_op_create_arguments):
(JSC::JIT::emit_op_init_arguments):

  • jit/JITOpcodes32_64.cpp:

(JSC::JIT::emit_op_tear_off_activation):
(JSC::JIT::emit_op_tear_off_arguments):
(JSC::JIT::emit_op_create_arguments):
(JSC::JIT::emit_op_init_arguments): The actual optimization: Removed
OptionalCalleeArguments from the callframe slot. Now, it doesn't need
to be initialized for most calls.

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::): Updated stubs to support arbitrary 'arguments' registers,
instead of hard-coding something in the call frame.

  • runtime/Arguments.h:

(JSC::JSActivation::copyRegisters): Removed some obfuscatory abstraction.

  • runtime/Executable.h:

(JSC::FunctionExecutable::generatedByteCode): Added a helper for accessing
the 'arguments' register. In a future patch, that kind of data should
probably move out of CodeBlock and into Executable.

  • runtime/JSActivation.cpp:

(JSC::JSActivation::getOwnPropertySlot):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h: Simplified / fixed access to 'arguments' via

the activation object. It now implements the same behavior implemented
by optimized variable access in the VM. This simplifies some other
things, too -- like eval code generation.

LayoutTests: Simplified handling of 'arguments' -- 1.2% SunSpider speedup
https://bugs.webkit.org/show_bug.cgi?id=39200

Reviewed by Darin Adler.

  • fast/js/function-dot-arguments-expected.txt:
  • fast/js/script-tests/function-dot-arguments.js:

(argumentsIdentity): Updated to match new behavior.

  • fast/js/function-dot-arguments2-expected.txt:
  • fast/js/function-dot-arguments2.html: New tests for some things that

weren't covered before.

  • fast/js/global-recursion-on-full-stack.html: Rejiggered the stack

usage in this test. Since stack usage is more efficient now, you
need a slightly different usage pattern to hit the exact thing this
test wanted to test.

  • fast/js/kde/script-tests/function_arguments.js:

(f): Updated to more specifically test what this was trying to test,
to avoid just testing the identity of f.arguments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r59064 r59742  
    175175    }
    176176
    177     ++m_codeBlock->m_numVars;
    178     r0 = newRegister();
     177    r0 = addVar();
    179178    return true;
    180179}
     
    296295    , m_scopeNode(functionBody)
    297296    , m_codeBlock(codeBlock)
     297    , m_activationRegister(0)
    298298    , m_finallyDepth(0)
    299299    , m_dynamicScopeDepth(0)
     
    313313    codeBlock->setGlobalData(m_globalData);
    314314
    315     bool usesArguments = functionBody->usesArguments();
    316     codeBlock->setUsesArguments(usesArguments);
    317     if (usesArguments) {
    318         m_argumentsRegister.setIndex(RegisterFile::OptionalCalleeArguments);
    319         addVar(propertyNames().arguments, false);
    320     }
    321 
    322315    if (m_codeBlock->needsFullScopeChain()) {
    323         ++m_codeBlock->m_numVars;
    324         m_activationRegisterIndex = newRegister()->index();
     316        m_activationRegister = addVar();
    325317        emitOpcode(op_enter_with_activation);
    326         instructions().append(m_activationRegisterIndex);
     318        instructions().append(m_activationRegister->index());
    327319    } else
    328320        emitOpcode(op_enter);
    329321
    330     if (usesArguments) {
     322    // Both op_tear_off_activation and op_tear_off_arguments tear off the 'arguments'
     323    // object, if created.
     324    if (m_codeBlock->needsFullScopeChain() || functionBody->usesArguments()) {
     325        RegisterID* unmodifiedArgumentsRegister = addVar(); // Anonymous, so it can't be modified by user code.
     326        RegisterID* argumentsRegister = addVar(propertyNames().arguments, false); // Can be changed by assigning to 'arguments'.
     327
     328        // We can save a little space by hard-coding the knowledge that the two
     329        // 'arguments' values are stored in consecutive registers, and storing
     330        // only the index of the assignable one.
     331        codeBlock->setArgumentsRegister(argumentsRegister->index());
     332        ASSERT_UNUSED(unmodifiedArgumentsRegister, unmodifiedArgumentsRegister->index() == JSC::unmodifiedArgumentsRegister(codeBlock->argumentsRegister()));
     333
    331334        emitOpcode(op_init_arguments);
     335        instructions().append(argumentsRegister->index());
    332336
    333337        // The debugger currently retrieves the arguments object from an activation rather than pulling
    334338        // it from a call frame.  In the long-term it should stop doing that (<rdar://problem/6911886>),
    335339        // but for now we force eager creation of the arguments object when debugging.
    336         if (m_shouldEmitDebugHooks)
     340        if (m_shouldEmitDebugHooks) {
    337341            emitOpcode(op_create_arguments);
     342            instructions().append(argumentsRegister->index());
     343        }
    338344    }
    339345
     
    13861392}
    13871393
    1388 
    13891394RegisterID* BytecodeGenerator::emitNewFunctionExpression(RegisterID* r0, FuncExprNode* n)
    13901395{
     
    14051410void BytecodeGenerator::createArgumentsIfNecessary()
    14061411{
    1407     if (m_codeBlock->usesArguments() && m_codeType == FunctionCode)
    1408         emitOpcode(op_create_arguments);
     1412    if (m_codeType != FunctionCode)
     1413        return;
     1414    ASSERT(m_codeBlock->usesArguments());
     1415
     1416    emitOpcode(op_create_arguments);
     1417    instructions().append(m_codeBlock->argumentsRegister());
    14091418}
    14101419
    14111420RegisterID* BytecodeGenerator::emitCallEval(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, ArgumentsNode* argumentsNode, unsigned divot, unsigned startOffset, unsigned endOffset)
    14121421{
    1413     createArgumentsIfNecessary();
    14141422    return emitCall(op_call_eval, dst, func, thisRegister, argumentsNode, divot, startOffset, endOffset);
    14151423}
     
    15271535    if (m_codeBlock->needsFullScopeChain()) {
    15281536        emitOpcode(op_tear_off_activation);
    1529         instructions().append(m_activationRegisterIndex);
    1530     } else if (m_codeBlock->usesArguments() && m_codeBlock->m_numParameters > 1)
     1537        instructions().append(m_activationRegister->index());
     1538        instructions().append(m_codeBlock->argumentsRegister());
     1539    } else if (m_codeBlock->usesArguments() && m_codeBlock->m_numParameters > 1) { // If there are no named parameters, there's nothing to tear off, since extra / unnamed parameters get copied to the arguments object at construct time.
    15311540        emitOpcode(op_tear_off_arguments);
     1541        instructions().append(m_codeBlock->argumentsRegister());
     1542    }
    15321543
    15331544    return emitUnaryNoDstOp(op_ret, src);
     
    16361647    m_scopeContextStack.append(context);
    16371648    m_dynamicScopeDepth++;
    1638     createArgumentsIfNecessary();
    16391649
    16401650    return emitUnaryNoDstOp(op_push_scope, scope);
     
    19001910    m_scopeContextStack.append(context);
    19011911    m_dynamicScopeDepth++;
    1902    
    1903     createArgumentsIfNecessary();
    19041912
    19051913    emitOpcode(op_push_new_scope);
Note: See TracChangeset for help on using the changeset viewer.