Ignore:
Timestamp:
May 24, 2016, 5:04:35 AM (9 years ago)
Author:
Yusuke Suzuki
Message:

ThisTDZMode is no longer needed
https://bugs.webkit.org/show_bug.cgi?id=157209

Reviewed by Saam Barati.

ThisTDZMode is no longer needed because we have ConstructorKind
and DerivedContextType. The value of ThisTDZMode is strictly less
expressive than the combination of those two values. We were
using those values anyways, and this patch just makes it official
by removing ThisTDZMode.

This patch also cleans up caching keys. We extract SourceCodeFlags
from SourceCodeKey and use it in EvalCodeCache. It correctly
contains needed cache attributes: EvalContextType, DerivedContextType,
etc. Here, we still use specialized keys for EvalCodeCache instead
of SourceCodeKey for performance; it does not include name String and
does not allocate SourceCode.

  • bytecode/EvalCodeCache.h:

(JSC::EvalCodeCache::CacheKey::CacheKey):
(JSC::EvalCodeCache::CacheKey::operator==):
(JSC::EvalCodeCache::CacheKey::Hash::equal):
(JSC::EvalCodeCache::tryGet):
(JSC::EvalCodeCache::getSlow):

  • bytecompiler/NodesCodegen.cpp:

(JSC::ThisNode::emitBytecode): Deleted.

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::evaluateWithScopeExtension):

  • interpreter/Interpreter.cpp:

(JSC::eval):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createThisExpr):

  • parser/NodeConstructors.h:

(JSC::ThisNode::ThisNode):

  • parser/Nodes.h:
  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parsePrimaryExpression):

  • parser/Parser.h:

(JSC::parse):

  • parser/ParserModes.h:
  • parser/SourceCodeKey.h:

(JSC::SourceCodeFlags::SourceCodeFlags):
(JSC::SourceCodeFlags::operator==):
(JSC::SourceCodeKey::SourceCodeKey):
(JSC::SourceCodeKey::Hash::hash):
(JSC::SourceCodeKey::Hash::equal):
(JSC::SourceCodeKey::HashTraits::isEmptyValue):
(JSC::SourceCodeKeyHash::hash): Deleted.
(JSC::SourceCodeKeyHash::equal): Deleted.
(JSC::SourceCodeKeyHashTraits::isEmptyValue): Deleted.

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createThisExpr):

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getProgramCodeBlock):
(JSC::CodeCache::getEvalCodeBlock):
(JSC::CodeCache::getModuleProgramCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):

  • runtime/CodeCache.h:
  • runtime/Executable.cpp:

(JSC::EvalExecutable::create):

  • runtime/Executable.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::createEvalCodeBlock):

  • runtime/JSGlobalObject.h:
  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEval):

  • tests/stress/code-cache-incorrect-caching.js: Added.

(shouldBe):
(hello):
(catch):
(shouldBe.test.hello):
(globalEval.ok):
(global.hello.hello):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SourceCodeKey.h

    r194017 r201328  
    3434namespace JSC {
    3535
     36enum class SourceCodeType { EvalType, ProgramType, FunctionType, ModuleType };
     37
     38class SourceCodeFlags {
     39public:
     40    SourceCodeFlags() = default;
     41
     42    SourceCodeFlags(SourceCodeType codeType, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, DerivedContextType derivedContextType, EvalContextType evalContextType, bool isArrowFunctionContext)
     43        : m_flags(
     44            (static_cast<unsigned>(isArrowFunctionContext) << 7) |
     45            (static_cast<unsigned>(evalContextType) << 6) |
     46            (static_cast<unsigned>(derivedContextType) << 4) |
     47            (static_cast<unsigned>(codeType) << 2) |
     48            (static_cast<unsigned>(builtinMode) << 1) |
     49            (static_cast<unsigned>(strictMode))
     50        )
     51    {
     52    }
     53
     54    inline bool operator==(const SourceCodeFlags& rhs) const
     55    {
     56        return m_flags == rhs.m_flags;
     57    }
     58
     59private:
     60    unsigned m_flags { 0 };
     61};
     62
    3663class SourceCodeKey {
    3764public:
    38     enum CodeType { EvalType, ProgramType, FunctionType, ModuleType };
    39 
    4065    SourceCodeKey()
    4166    {
    4267    }
    4368
    44     SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded)
     69    SourceCodeKey(const SourceCode& sourceCode, const String& name, SourceCodeType codeType, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, DerivedContextType derivedContextType, EvalContextType evalContextType, bool isArrowFunctionContext)
    4570        : m_sourceCode(sourceCode)
    4671        , m_name(name)
    47         , m_flags((static_cast<unsigned>(codeType) << 3) | (static_cast<unsigned>(builtinMode) << 2) | (static_cast<unsigned>(strictMode) << 1) | static_cast<unsigned>(thisTDZMode))
     72        , m_flags(codeType, builtinMode, strictMode, derivedContextType, evalContextType, isArrowFunctionContext)
    4873        , m_hash(sourceCode.hash())
    4974    {
     
    76101    }
    77102
     103    struct Hash {
     104        static unsigned hash(const SourceCodeKey& key) { return key.hash(); }
     105        static bool equal(const SourceCodeKey& a, const SourceCodeKey& b) { return a == b; }
     106        static const bool safeToCompareToEmptyOrDeleted = false;
     107    };
     108
     109    struct HashTraits : SimpleClassHashTraits<SourceCodeKey> {
     110        static const bool hasIsEmptyValueFunction = true;
     111        static bool isEmptyValue(const SourceCodeKey& key) { return key.isNull(); }
     112    };
     113
    78114private:
    79115    SourceCode m_sourceCode;
    80116    String m_name;
    81     unsigned m_flags;
     117    SourceCodeFlags m_flags;
    82118    unsigned m_hash;
    83 };
    84 
    85 struct SourceCodeKeyHash {
    86     static unsigned hash(const SourceCodeKey& key) { return key.hash(); }
    87     static bool equal(const SourceCodeKey& a, const SourceCodeKey& b) { return a == b; }
    88     static const bool safeToCompareToEmptyOrDeleted = false;
    89 };
    90 
    91 struct SourceCodeKeyHashTraits : SimpleClassHashTraits<SourceCodeKey> {
    92     static const bool hasIsEmptyValueFunction = true;
    93     static bool isEmptyValue(const SourceCodeKey& sourceCodeKey) { return sourceCodeKey.isNull(); }
    94119};
    95120
Note: See TracChangeset for help on using the changeset viewer.