Ignore:
Timestamp:
Jul 13, 2010, 1:34:11 PM (15 years ago)
Author:
[email protected]
Message:

Bug 42182 - Change how numeric compare functions are detected

Reviewed by Oliver Hunt.

JavaScriptCore:

There are three problems with the current mechanism:

  • It requires that a function executable be bytecode compiled without being JIT generated (in order to copy the bytecode from the numeric compare function). This is a problem since we have an invariant when running with the JIT that functions are never bytecode compiled without also being JIT generated (after checking the codeblock we assume the function has JIT code). To help maintain this invariant
  • This implementation will prevent us from experimenting with alternate compilation paths which do not compile via bytecode.
  • It doesn't work. Functions passing more than two arguments will match if they are comparing their last two arguments, not the first two. Generally the mapping back from bytecode to semantics may be more complex then initially expected.
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::setIsNumericCompareFunction):
(JSC::BytecodeGenerator::argumentNumberFor):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::BlockNode::singleStatement):
(JSC::FunctionBodyNode::emitBytecode):

  • parser/Nodes.h:

(JSC::ExpressionNode::isSubtract):
(JSC::BinaryOpNode::lhs):
(JSC::BinaryOpNode::rhs):
(JSC::SubNode::isSubtract):
(JSC::ReturnNode::value):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h:

LayoutTests:

Test case.

  • fast/js/array-sort-numericCompare-expected.txt: Added.
  • fast/js/array-sort-numericCompare.html: Added.
  • fast/js/script-tests/array-sort-numericCompare.js: Added.

(doSort):
(dontSort):

File:
1 edited

Legend:

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

    r62896 r63244  
    153153    if ((m_codeType == FunctionCode && !m_codeBlock->needsFullScopeChain() && !m_codeBlock->usesArguments()) || m_codeType == EvalCode)
    154154        symbolTable().clear();
    155        
    156     m_codeBlock->setIsNumericCompareFunction(instructions() == m_globalData->numericCompareFunction(m_scopeChain->globalObject()->globalExec()));
    157155
    158156#if !ENABLE(OPCODE_SAMPLING)
     
    20462044}
    20472045
     2046void BytecodeGenerator::setIsNumericCompareFunction(bool isNumericCompareFunction)
     2047{
     2048    m_codeBlock->setIsNumericCompareFunction(isNumericCompareFunction);
     2049}
     2050
     2051int BytecodeGenerator::argumentNumberFor(const Identifier& ident)
     2052{
     2053    int parameterCount = m_parameters.size(); // includes 'this'
     2054    int index = registerFor(ident)->index() + RegisterFile::CallFrameHeaderSize + parameterCount;
     2055    return (index > 0 && index < parameterCount) ? index : 0;
     2056}
     2057
    20482058} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.