Changeset 89954 in webkit


Ignore:
Timestamp:
Jun 28, 2011 1:21:37 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-06-28 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

Make constant array optimisation less strict about what constitutes a constant
https://bugs.webkit.org/show_bug.cgi?id=63554

Now allow string constants in array literals to actually be considered constant,
and so avoid codegen in array literals with strings in them.

  • bytecode/CodeBlock.h: (JSC::CodeBlock::addConstantBuffer): (JSC::CodeBlock::constantBuffer):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::addConstantBuffer): (JSC::BytecodeGenerator::addStringConstant): (JSC::BytecodeGenerator::emitNewArray):
  • bytecompiler/BytecodeGenerator.h:
  • interpreter/Interpreter.cpp: (JSC::Interpreter::privateExecute):
  • jit/JITStubs.cpp: (JSC::DEFINE_STUB_FUNCTION):
Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r89946 r89954  
     12011-06-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Make constant array optimisation less strict about what constitutes a constant
     6        https://bugs.webkit.org/show_bug.cgi?id=63554
     7
     8        Now allow string constants in array literals to actually be considered constant,
     9        and so avoid codegen in array literals with strings in them.
     10
     11        * bytecode/CodeBlock.h:
     12        (JSC::CodeBlock::addConstantBuffer):
     13        (JSC::CodeBlock::constantBuffer):
     14        * bytecompiler/BytecodeGenerator.cpp:
     15        (JSC::BytecodeGenerator::addConstantBuffer):
     16        (JSC::BytecodeGenerator::addStringConstant):
     17        (JSC::BytecodeGenerator::emitNewArray):
     18        * bytecompiler/BytecodeGenerator.h:
     19        * interpreter/Interpreter.cpp:
     20        (JSC::Interpreter::privateExecute):
     21        * jit/JITStubs.cpp:
     22        (JSC::DEFINE_STUB_FUNCTION):
     23
    1242011-06-28  Gavin Barraclough  <barraclough@apple.com>
    225
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r89885 r89954  
    478478        RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
    479479
    480         unsigned addImmediateBuffer(unsigned length)
     480        unsigned addConstantBuffer(unsigned length)
    481481        {
    482482            createRareDataIfNecessary();
    483             unsigned size = m_rareData->m_immediateBuffers.size();
    484             m_rareData->m_immediateBuffers.append(Vector<JSValue>(length));
     483            unsigned size = m_rareData->m_constantBuffers.size();
     484            m_rareData->m_constantBuffers.append(Vector<JSValue>(length));
    485485            return size;
    486486        }
    487487
    488         JSValue* immediateBuffer(unsigned index)
     488        JSValue* constantBuffer(unsigned index)
    489489        {
    490490            ASSERT(m_rareData);
    491             return m_rareData->m_immediateBuffers[index].data();
     491            return m_rareData->m_constantBuffers[index].data();
    492492        }
    493493
     
    596596
    597597            // Buffers used for large array literals
    598             Vector<Vector<JSValue> > m_immediateBuffers;
     598            Vector<Vector<JSValue> > m_constantBuffers;
    599599           
    600600            // Jump Tables
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r89465 r89954  
    15091509}
    15101510
    1511 unsigned BytecodeGenerator::addImmediateBuffer(unsigned length)
    1512 {
    1513     return m_codeBlock->addImmediateBuffer(length);
     1511unsigned BytecodeGenerator::addConstantBuffer(unsigned length)
     1512{
     1513    return m_codeBlock->addConstantBuffer(length);
     1514}
     1515
     1516JSString* BytecodeGenerator::addStringConstant(const Identifier& identifier)
     1517{
     1518    JSString*& stringInMap = m_stringMap.add(identifier.impl(), 0).first->second;
     1519    if (!stringInMap) {
     1520        stringInMap = jsString(globalData(), identifier.ustring());
     1521        addConstantValue(stringInMap);
     1522    }
     1523    return stringInMap;
    15141524}
    15151525
     
    15191529    unsigned checkLength = 0;
    15201530#endif
    1521     bool hadNonNumber = false;
     1531    bool hadVariableExpression = false;
    15221532    if (length) {
    15231533        for (ElementNode* n = elements; n; n = n->next()) {
    1524             if (!n->value()->isNumber()) {
    1525                 hadNonNumber = true;
     1534            if (!n->value()->isNumber() && !n->value()->isString()) {
     1535                hadVariableExpression = true;
    15261536                break;
    15271537            }
     
    15321542#endif
    15331543        }
    1534         if (!hadNonNumber) {
     1544        if (!hadVariableExpression) {
    15351545            ASSERT(length == checkLength);
    1536             unsigned immediateBufferIndex = addImmediateBuffer(length);
    1537             JSValue* immediateBuffer = m_codeBlock->immediateBuffer(immediateBufferIndex);
     1546            unsigned constantBufferIndex = addConstantBuffer(length);
     1547            JSValue* constantBuffer = m_codeBlock->constantBuffer(constantBufferIndex);
    15381548            unsigned index = 0;
    1539             for (ElementNode* n = elements; index < length; n = n->next())
    1540                 immediateBuffer[index++] = jsNumber(static_cast<NumberNode*>(n->value())->value());
     1549            for (ElementNode* n = elements; index < length; n = n->next()) {
     1550                if (n->value()->isNumber())
     1551                    constantBuffer[index++] = jsNumber(static_cast<NumberNode*>(n->value())->value());
     1552                else {
     1553                    ASSERT(n->value()->isString());
     1554                    constantBuffer[index++] = addStringConstant(static_cast<StringNode*>(n->value())->value());
     1555                }
     1556            }
    15411557            emitOpcode(op_new_array_buffer);
    15421558            instructions().append(dst->index());
    1543             instructions().append(immediateBufferIndex);
     1559            instructions().append(constantBufferIndex);
    15441560            instructions().append(length);
    15451561            return dst;
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r89465 r89954  
    470470        unsigned addRegExp(RegExp*);
    471471
    472         unsigned addImmediateBuffer(unsigned length);
     472        unsigned addConstantBuffer(unsigned length);
    473473       
    474474        FunctionExecutable* makeFunction(ExecState* exec, FunctionBodyNode* body)
     
    481481            return FunctionExecutable::create(globalData, body->ident(), body->source(), body->usesArguments(), body->parameters(), body->isStrictMode(), body->lineNo(), body->lastLine());
    482482        }
     483
     484        JSString* addStringConstant(const Identifier&);
    483485
    484486        void addLineInfo(unsigned lineNo)
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r89465 r89954  
    16071607         Constructs a new Array instance using the original
    16081608         constructor, and puts the result in register dst.
    1609          The array be initialized with the values from immediateBuffer[index]
     1609         The array be initialized with the values from constantBuffer[index]
    16101610         */
    16111611        int dst = vPC[1].u.operand;
    16121612        int firstArg = vPC[2].u.operand;
    16131613        int argCount = vPC[3].u.operand;
    1614         ArgList args(codeBlock->immediateBuffer(firstArg), argCount);
     1614        ArgList args(codeBlock->constantBufferfirstArg), argCount);
    16151615        callFrame->uncheckedR(dst) = JSValue(constructArray(callFrame, args));
    16161616       
  • trunk/Source/JavaScriptCore/jit/JITStubs.cpp

    r88873 r89954  
    22652265    STUB_INIT_STACK_FRAME(stackFrame);
    22662266   
    2267     ArgList argList(stackFrame.callFrame->codeBlock()->immediateBuffer(stackFrame.args[0].int32()), stackFrame.args[1].int32());
     2267    ArgList argList(stackFrame.callFrame->codeBlock()->constantBuffer(stackFrame.args[0].int32()), stackFrame.args[1].int32());
    22682268    return constructArray(stackFrame.callFrame, argList);
    22692269}
Note: See TracChangeset for help on using the changeset viewer.