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/runtime/JSGlobalData.cpp

    r62847 r63244  
    141141#endif
    142142    , heap(this)
    143     , initializingLazyNumericCompareFunction(false)
    144143    , head(0)
    145144    , dynamicGlobalObject(0)
     
    258257}
    259258
    260 // FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
    261 const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
    262 {
    263     if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
    264         initializingLazyNumericCompareFunction = true;
    265         RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
    266         lazyNumericCompareFunction = function->bytecodeForCall(exec, exec->scopeChain())->instructions();
    267         initializingLazyNumericCompareFunction = false;
    268     }
    269 
    270     return lazyNumericCompareFunction;
    271 }
    272 
    273259#if ENABLE(JIT)
    274260PassRefPtr<NativeExecutable> JSGlobalData::getHostFunction(NativeFunction function)
Note: See TracChangeset for help on using the changeset viewer.