Changeset 170109 in webkit


Ignore:
Timestamp:
Jun 18, 2014 11:57:12 AM (10 years ago)
Author:
mark.lam@apple.com
Message:

DFGGraph::m_doubleConstantMap will not map 0 values correctly.
<https://webkit.org/b/133994>

Reviewed by Geoffrey Garen.

DFGGraph::m_doubleConstantsMap should not use a double as a key to its HashMap,
because it means two unfortunate things:

  • It will probably break for zero.
  • It will think that -0 is the same as +0 under some circumstances, size -0==+0 even though they are distinct values (for example 1/-0 != 1/+0).

The fix is to use std::unordered_map which does not require special empty
and deleted values, and to use the raw bits instead of the double value as
the key.

  • dfg/DFGGraph.h:
  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::addressOfDoubleConstant):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r170107 r170109  
     12014-06-18  Mark Lam  <mark.lam@apple.com>
     2
     3        DFGGraph::m_doubleConstantMap will not map 0 values correctly.
     4        <https://webkit.org/b/133994>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        DFGGraph::m_doubleConstantsMap should not use a double as a key to its HashMap,
     9        because it means two unfortunate things:
     10        - It will probably break for zero.
     11        - It will think that -0 is the same as +0 under some circumstances, size
     12          -0==+0 even though they are distinct values (for example 1/-0 != 1/+0).
     13
     14        The fix is to use std::unordered_map which does not require special empty
     15        and deleted values, and to use the raw bits instead of the double value as
     16        the key.
     17
     18        * dfg/DFGGraph.h:
     19        * dfg/DFGJITCompiler.cpp:
     20        (JSC::DFG::JITCompiler::addressOfDoubleConstant):
     21
    1222014-06-18  Alex Christensen  <achristensen@webkit.org>
    223
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.h

    r170086 r170109  
    4242#include "JSStack.h"
    4343#include "MethodOfGettingAValueProfile.h"
     44#include <unordered_map>
    4445#include <wtf/BitVector.h>
    4546#include <wtf/HashMap.h>
     
    855856
    856857#if USE(JSVALUE32_64)
    857     HashMap<double, double*> m_doubleConstantsMap;
     858    std::unordered_map<int64_t, double*> m_doubleConstantsMap;
    858859    std::unique_ptr<Bag<double>> m_doubleConstants;
    859860#endif
  • trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp

    r170086 r170109  
    445445
    446446    double value = jsvalue.asDouble();
    447     auto it = m_graph.m_doubleConstantsMap.find(value);
     447    int64_t valueBits = bitwise_cast<int64_t>(value);
     448    auto it = m_graph.m_doubleConstantsMap.find(valueBits);
    448449    if (it != m_graph.m_doubleConstantsMap.end())
    449         return it->value;
     450        return it->second;
    450451
    451452    if (!m_graph.m_doubleConstants)
     
    454455    double* addressInConstantPool = m_graph.m_doubleConstants->add();
    455456    *addressInConstantPool = value;
    456     m_graph.m_doubleConstantsMap.add(value, addressInConstantPool);
     457    m_graph.m_doubleConstantsMap[valueBits] = addressInConstantPool;
    457458    return addressInConstantPool;
    458459}
Note: See TracChangeset for help on using the changeset viewer.