Changeset 59064 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
May 9, 2010, 6:41:07 PM (15 years ago)
Author:
[email protected]
Message:

2010-05-09 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.

Reserve a large-ish initial capacity for Lexer::m_buffer16.

SunSpider says 0.3% faster.

m_buffer16 is used when parsing complex strings -- for example, strings
with escape sequences in them. These kinds of strings can be really long,
and we want to avoid repeatedly copying as we grow m_buffer16.

The net memory cost is quite low, since it's proporitional to source
code we already have in memory, and we throw away m_buffer16 right when
we're done parsing.

  • parser/Lexer.cpp: (JSC::Lexer::Lexer): No need to reserve initial capacity in our constructor, since setCode will be called before we're asked to lex anything. (JSC::Lexer::setCode): Reserve enough space to lex half the source code as a complex string without having to copy. (JSC::Lexer::clear): No need to reserve initial capacity here either, since setCode will be called before we're asked to lex anything.

2010-05-09 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

REGRESSION(r57955): RegExp literals should not actually be cached, so r57955 should be rolled out.
https://bugs.webkit.org/show_bug.cgi?id=38828

Replace incorrect test for caching regexp literals with ones that tests that they are not cached.

  • fast/js/regexp-literals-are-constants-expected.txt: Removed.
  • fast/js/regexp-literals-are-constants.html: Removed.
  • fast/js/regexp-literals-arent-constants-expected.txt: Added.
  • fast/js/regexp-literals-arent-constants.html: Added.
  • fast/js/script-tests/regexp-literals-are-constants.js: Removed.
  • fast/js/script-tests/regexp-literals-arent-constants.js: Added. (test1): (returnRegExpLiteral): (returnConditionalRegExpLiteral):
Location:
trunk/JavaScriptCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r59061 r59064  
    3434
    3535        * JavaScriptCore.pri:
     36
     372010-05-09  Oliver Hunt  <[email protected]>
     38
     39        Reviewed by Gavin Barraclough.
     40
     41        REGRESSION(r57955): RegExp literals should not actually be cached, so r57955 should be rolled out.
     42        https://bugs.webkit.org/show_bug.cgi?id=38828
     43        <rdar://problem/7961634>
     44
     45        Rollout r57955
     46
     47        * bytecode/CodeBlock.cpp:
     48        (JSC::regexpToSourceString):
     49        (JSC::regexpName):
     50        (JSC::CodeBlock::dump):
     51        (JSC::CodeBlock::shrinkToFit):
     52        * bytecode/CodeBlock.h:
     53        (JSC::CodeBlock::addRegExp):
     54        (JSC::CodeBlock::regexp):
     55        * bytecode/Opcode.h:
     56        * bytecompiler/BytecodeGenerator.cpp:
     57        (JSC::BytecodeGenerator::addRegExp):
     58        (JSC::BytecodeGenerator::emitNewRegExp):
     59        * bytecompiler/BytecodeGenerator.h:
     60        * bytecompiler/NodesCodegen.cpp:
     61        (JSC::RegExpNode::emitBytecode):
     62        * interpreter/Interpreter.cpp:
     63        (JSC::Interpreter::privateExecute):
     64        * jit/JIT.cpp:
     65        (JSC::JIT::privateCompileMainPass):
     66        * jit/JIT.h:
     67        * jit/JITOpcodes.cpp:
     68        (JSC::JIT::emit_op_new_regexp):
     69        * jit/JITStubs.cpp:
     70        (JSC::DEFINE_STUB_FUNCTION):
     71        * jit/JITStubs.h:
     72        (JSC::):
    3673
    37742010-05-09  Oliver Hunt  <[email protected]>
  • trunk/JavaScriptCore/bytecode/CodeBlock.cpp

    r58986 r59064  
    9090}
    9191
     92static UString regexpToSourceString(RegExp* regExp)
     93{
     94    char postfix[5] = { '/', 0, 0, 0, 0 };
     95    int index = 1;
     96    if (regExp->global())
     97        postfix[index++] = 'g';
     98    if (regExp->ignoreCase())
     99        postfix[index++] = 'i';
     100    if (regExp->multiline())
     101        postfix[index] = 'm';
     102
     103    return makeString("/", regExp->pattern(), postfix);
     104}
     105
     106static CString regexpName(int re, RegExp* regexp)
     107{
     108    return makeString(regexpToSourceString(regexp), "(@re", UString::from(re), ")").UTF8String();
     109}
     110
    92111static UString pointerToSourceString(void* p)
    93112{
     
    350369    }
    351370
     371    if (m_rareData && !m_rareData->m_regexps.isEmpty()) {
     372        printf("\nm_regexps:\n");
     373        size_t i = 0;
     374        do {
     375            printf("  re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_rareData->m_regexps[i].get()).ascii());
     376            ++i;
     377        } while (i < m_rareData->m_regexps.size());
     378    }
     379
    352380#if ENABLE(JIT)
    353381    if (!m_globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty())
     
    485513            int argc = (++it)->u.operand;
    486514            printf("[%4d] new_array\t %s, %s, %d\n", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc);
     515            break;
     516        }
     517        case op_new_regexp: {
     518            int r0 = (++it)->u.operand;
     519            int re0 = (++it)->u.operand;
     520            printf("[%4d] new_regexp\t %s, %s\n", location, registerName(exec, r0).data(), regexpName(re0, regexp(re0)).data());
    487521            break;
    488522        }
     
    16961730    if (m_rareData) {
    16971731        m_rareData->m_exceptionHandlers.shrinkToFit();
     1732        m_rareData->m_regexps.shrinkToFit();
    16981733        m_rareData->m_immediateSwitchJumpTables.shrinkToFit();
    16991734        m_rareData->m_characterSwitchJumpTables.shrinkToFit();
  • trunk/JavaScriptCore/bytecode/CodeBlock.h

    r57955 r59064  
    459459        FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
    460460
     461        unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; }
     462        RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
     463
     464
    461465        // Jump Tables
    462466
     
    553557            Vector<HandlerInfo> m_exceptionHandlers;
    554558
     559            // Rare Constants
     560            Vector<RefPtr<RegExp> > m_regexps;
     561
    555562            // Jump Tables
    556563            Vector<SimpleJumpTable> m_immediateSwitchJumpTables;
  • trunk/JavaScriptCore/bytecode/Opcode.h

    r58986 r59064  
    4747        macro(op_new_object, 2) \
    4848        macro(op_new_array, 4) \
     49        macro(op_new_regexp, 3) \
    4950        macro(op_mov, 3) \
    5051        \
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r59005 r59064  
    3535#include "JSFunction.h"
    3636#include "Interpreter.h"
    37 #include "RegExp.h"
    38 #include "RegExpObject.h"
    3937#include "UString.h"
    4038
     
    828826
    829827    return &m_constantPoolRegisters[index];
     828}
     829
     830unsigned BytecodeGenerator::addRegExp(RegExp* r)
     831{
     832    return m_codeBlock->addRegExp(r);
    830833}
    831834
     
    980983}
    981984
    982 RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, RegExp* regExp)
    983 {
    984     JSValue jsRegExp = new (globalData()) RegExpObject(m_scopeChain->globalObject()->regExpStructure(), regExp);
    985     return emitLoad(dst, jsRegExp);
    986 }
    987 
    988985RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, JSValue v)
    989986{
     
    13811378}
    13821379
     1380RegisterID* BytecodeGenerator::emitNewRegExp(RegisterID* dst, RegExp* regExp)
     1381{
     1382    emitOpcode(op_new_regexp);
     1383    instructions().append(dst->index());
     1384    instructions().append(addRegExp(regExp));
     1385    return dst;
     1386}
     1387
     1388
    13831389RegisterID* BytecodeGenerator::emitNewFunctionExpression(RegisterID* r0, FuncExprNode* n)
    13841390{
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r58986 r59064  
    265265        RegisterID* emitLoad(RegisterID* dst, double);
    266266        RegisterID* emitLoad(RegisterID* dst, const Identifier&);
    267         RegisterID* emitLoad(RegisterID* dst, RegExp* regExp);
    268267        RegisterID* emitLoad(RegisterID* dst, JSValue);
    269268
     
    278277        RegisterID* emitNewFunction(RegisterID* dst, FunctionBodyNode* body);
    279278        RegisterID* emitNewFunctionExpression(RegisterID* dst, FuncExprNode* func);
     279        RegisterID* emitNewRegExp(RegisterID* dst, RegExp* regExp);
    280280
    281281        RegisterID* emitMove(RegisterID* dst, RegisterID* src);
     
    447447        unsigned addConstant(const Identifier&);
    448448        RegisterID* addConstantValue(JSValue);
     449        unsigned addRegExp(RegExp*);
    449450
    450451        PassRefPtr<FunctionExecutable> makeFunction(ExecState* exec, FunctionBodyNode* body)
  • trunk/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r58986 r59064  
    150150    if (dst == generator.ignoredResult())
    151151        return 0;
    152     return generator.emitLoad(generator.finalDestination(dst), regExp.get());
     152    return generator.emitNewRegExp(generator.finalDestination(dst), regExp.get());
    153153}
    154154
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r58986 r59064  
    13051305
    13061306        vPC += OPCODE_LENGTH(op_new_array);
     1307        NEXT_INSTRUCTION();
     1308    }
     1309    DEFINE_OPCODE(op_new_regexp) {
     1310        /* new_regexp dst(r) regExp(re)
     1311
     1312           Constructs a new RegExp instance using the original
     1313           constructor from regexp regExp, and puts the result in
     1314           register dst.
     1315        */
     1316        int dst = vPC[1].u.operand;
     1317        int regExp = vPC[2].u.operand;
     1318        callFrame->r(dst) = JSValue(new (globalData) RegExpObject(callFrame->scopeChain()->globalObject->regExpStructure(), callFrame->codeBlock()->regexp(regExp)));
     1319
     1320        vPC += OPCODE_LENGTH(op_new_regexp);
    13071321        NEXT_INSTRUCTION();
    13081322    }
  • trunk/JavaScriptCore/jit/JIT.cpp

    r58986 r59064  
    276276        DEFINE_OP(op_new_func_exp)
    277277        DEFINE_OP(op_new_object)
     278        DEFINE_OP(op_new_regexp)
    278279        DEFINE_OP(op_next_pname)
    279280        DEFINE_OP(op_not)
  • trunk/JavaScriptCore/jit/JIT.h

    r59056 r59064  
    695695        void emit_op_new_func_exp(Instruction*);
    696696        void emit_op_new_object(Instruction*);
     697        void emit_op_new_regexp(Instruction*);
    697698        void emit_op_get_pnames(Instruction*);
    698699        void emit_op_next_pname(Instruction*);
  • trunk/JavaScriptCore/jit/JITOpcodes.cpp

    r59056 r59064  
    964964}
    965965
     966void JIT::emit_op_new_regexp(Instruction* currentInstruction)
     967{
     968    JITStubCall stubCall(this, cti_op_new_regexp);
     969    stubCall.addArgument(ImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand)));
     970    stubCall.call(currentInstruction[1].u.operand);
     971}
     972
    966973void JIT::emit_op_bitor(Instruction* currentInstruction)
    967974{
     
    16301637}
    16311638
     1639void JIT::emit_op_new_regexp(Instruction* currentInstruction)
     1640{
     1641    JITStubCall stubCall(this, cti_op_new_regexp);
     1642    stubCall.addArgument(ImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand)));
     1643    stubCall.call(currentInstruction[1].u.operand);
     1644}
     1645
    16321646// For both JSValue32_64 and JSValue32
    16331647#if ENABLE(JIT_OPTIMIZE_MOD)
  • trunk/JavaScriptCore/jit/JITStubs.cpp

    r59055 r59064  
    28712871}
    28722872
     2873DEFINE_STUB_FUNCTION(JSObject*, op_new_regexp)
     2874{
     2875    STUB_INIT_STACK_FRAME(stackFrame);
     2876
     2877    return new (stackFrame.globalData) RegExpObject(stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), stackFrame.args[0].regExp());
     2878}
     2879
    28732880DEFINE_STUB_FUNCTION(EncodedJSValue, op_bitor)
    28742881{
  • trunk/JavaScriptCore/jit/JITStubs.h

    r58986 r59064  
    358358    JSObject* JIT_STUB cti_op_new_func_exp(STUB_ARGS_DECLARATION);
    359359    JSObject* JIT_STUB cti_op_new_object(STUB_ARGS_DECLARATION);
     360    JSObject* JIT_STUB cti_op_new_regexp(STUB_ARGS_DECLARATION);
    360361    JSObject* JIT_STUB cti_op_push_activation(STUB_ARGS_DECLARATION);
    361362    JSObject* JIT_STUB cti_op_push_new_scope(STUB_ARGS_DECLARATION);
Note: See TracChangeset for help on using the changeset viewer.