Ignore:
Timestamp:
Oct 11, 2021, 9:58:40 AM (4 years ago)
Author:
[email protected]
Message:

SourceID should have a type name and only be 32-bits
https://bugs.webkit.org/show_bug.cgi?id=231436

Reviewed by Filip Pizlo.

This patch gives SourceID a proper type name and shrinks it to
32-bits on 64-bit systems. Shrinking the size makes room on
SourceProvider for metadata in a future patch I'm working on.
It's also pretty unlikely that any system has more than ~4 billion
script tags, evals, wasm modules so shinking the size is unlikely
to cause any debugger/profiling issues.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/TypeLocation.h:
  • debugger/Debugger.cpp:

(JSC::Debugger::toggleBreakpoint):
(JSC::Debugger::pauseIfNeeded):

  • debugger/DebuggerLocation.h:

(JSC::DebuggerLocation::DebuggerLocation):

  • debugger/DebuggerPrimitives.h:
  • inspector/JavaScriptCallFrame.h:

(Inspector::JavaScriptCallFrame::sourceID const):

  • inspector/ScriptCallStackFactory.cpp:

(Inspector::CreateScriptCallStackFunctor::operator() const):
(Inspector::createScriptCallStackFromException):

  • interpreter/StackVisitor.cpp:

(JSC::StackVisitor::Frame::sourceID):

  • interpreter/StackVisitor.h:
  • parser/Nodes.h:

(JSC::ScopeNode::sourceID const):

  • parser/SourceCode.h:

(JSC::SourceCode::SourceCode):
(JSC::SourceCode::firstLine const):
(JSC::SourceCode::startColumn const):
(JSC::SourceCode::providerID const):
(JSC::SourceCode::provider const):
(JSC::SourceCode::operator== const):
(JSC::SourceCode::operator!= const):
(JSC::makeSource):
(JSC::SourceCode::subExpression const):

  • parser/SourceProvider.cpp:

(JSC::SourceProvider::getID):

  • parser/SourceProvider.h:

(JSC::SourceProvider::asID):

  • runtime/ControlFlowProfiler.cpp:

(JSC::ControlFlowProfiler::getBasicBlockLocation):
(JSC::ControlFlowProfiler::getBasicBlocksForSourceID const):
(JSC::ControlFlowProfiler::hasBasicBlockAtTextOffsetBeenExecuted):
(JSC::ControlFlowProfiler::basicBlockExecutionCountAtTextOffset):

  • runtime/ControlFlowProfiler.h:
  • runtime/FunctionHasExecutedCache.cpp:

(JSC::FunctionHasExecutedCache::hasExecutedAtOffset):
(JSC::FunctionHasExecutedCache::insertUnexecutedRange):
(JSC::FunctionHasExecutedCache::removeUnexecutedRange):
(JSC::FunctionHasExecutedCache::getFunctionRanges):

  • runtime/FunctionHasExecutedCache.h:
  • runtime/SamplingProfiler.cpp:

(JSC::SamplingProfiler::StackFrame::sourceID):

  • runtime/SamplingProfiler.h:
  • runtime/ScriptExecutable.h:

(JSC::ScriptExecutable::sourceID const):

  • runtime/StackFrame.cpp:

(JSC::StackFrame::sourceID const):

  • runtime/StackFrame.h:
  • runtime/TypeLocationCache.cpp:

(JSC::TypeLocationCache::getTypeLocation):

  • runtime/TypeLocationCache.h:
  • runtime/TypeProfiler.cpp:

(JSC::TypeProfiler::typeInformationForExpressionAtOffset):
(JSC::TypeProfiler::findLocation):

  • runtime/TypeProfiler.h:

(JSC::QueryKey::QueryKey):
(JSC::QueryKey::isHashTableDeletedValue const):

File:
1 edited

Legend:

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

    r264304 r283903  
    3333namespace JSC {
    3434
    35     class SourceCode : public UnlinkedSourceCode {
    36         friend class CachedSourceCode;
    37         friend class CachedSourceCodeWithoutProvider;
     35class SourceCode : public UnlinkedSourceCode {
     36    friend class CachedSourceCode;
     37    friend class CachedSourceCodeWithoutProvider;
    3838
    39     public:
    40         SourceCode()
    41             : UnlinkedSourceCode()
    42             , m_firstLine(OrdinalNumber::beforeFirst())
    43             , m_startColumn(OrdinalNumber::beforeFirst())
    44         {
    45         }
    46 
    47         SourceCode(Ref<SourceProvider>&& provider)
    48             : UnlinkedSourceCode(WTFMove(provider))
    49         {
    50         }
    51 
    52         SourceCode(Ref<SourceProvider>&& provider, int firstLine, int startColumn)
    53             : UnlinkedSourceCode(WTFMove(provider))
    54             , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
    55             , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
    56         {
    57         }
    58 
    59         SourceCode(RefPtr<SourceProvider>&& provider, int startOffset, int endOffset, int firstLine, int startColumn)
    60             : UnlinkedSourceCode(WTFMove(provider), startOffset, endOffset)
    61             , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
    62             , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
    63         {
    64         }
    65 
    66         OrdinalNumber firstLine() const { return m_firstLine; }
    67         OrdinalNumber startColumn() const { return m_startColumn; }
    68 
    69         intptr_t providerID() const
    70         {
    71             if (!m_provider)
    72                 return SourceProvider::nullID;
    73             return m_provider->asID();
    74         }
    75 
    76         SourceProvider* provider() const { return m_provider.get(); }
    77 
    78         SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn) const;
    79 
    80         bool operator==(const SourceCode& other) const
    81         {
    82             return m_firstLine == other.m_firstLine
    83                 && m_startColumn == other.m_startColumn
    84                 && m_provider == other.m_provider
    85                 && m_startOffset == other.m_startOffset
    86                 && m_endOffset == other.m_endOffset;
    87         }
    88 
    89         bool operator!=(const SourceCode& other) const
    90         {
    91             return !(*this == other);
    92         }
    93 
    94     private:
    95         OrdinalNumber m_firstLine;
    96         OrdinalNumber m_startColumn;
    97     };
    98 
    99     inline SourceCode makeSource(const String& source, const SourceOrigin& sourceOrigin, String filename = String(), const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)
     39public:
     40    SourceCode()
     41        : UnlinkedSourceCode()
     42        , m_firstLine(OrdinalNumber::beforeFirst())
     43        , m_startColumn(OrdinalNumber::beforeFirst())
    10044    {
    101         return SourceCode(StringSourceProvider::create(source, sourceOrigin, WTFMove(filename), startPosition, sourceType), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt());
    102     }
    103    
    104     inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn) const
    105     {
    106         startColumn += 1; // Convert to base 1.
    107         return SourceCode(RefPtr<SourceProvider> { provider() }, openBrace, closeBrace + 1, firstLine, startColumn);
    10845    }
    10946
     47    SourceCode(Ref<SourceProvider>&& provider)
     48        : UnlinkedSourceCode(WTFMove(provider))
     49    {
     50    }
     51
     52    SourceCode(Ref<SourceProvider>&& provider, int firstLine, int startColumn)
     53        : UnlinkedSourceCode(WTFMove(provider))
     54        , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
     55        , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
     56    {
     57    }
     58
     59    SourceCode(RefPtr<SourceProvider>&& provider, int startOffset, int endOffset, int firstLine, int startColumn)
     60        : UnlinkedSourceCode(WTFMove(provider), startOffset, endOffset)
     61        , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
     62        , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
     63    {
     64    }
     65
     66    OrdinalNumber firstLine() const { return m_firstLine; }
     67    OrdinalNumber startColumn() const { return m_startColumn; }
     68
     69    SourceID providerID() const
     70    {
     71        if (!m_provider)
     72            return SourceProvider::nullID;
     73        return m_provider->asID();
     74    }
     75
     76    SourceProvider* provider() const { return m_provider.get(); }
     77
     78    SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn) const;
     79
     80    bool operator==(const SourceCode& other) const
     81    {
     82        return m_firstLine == other.m_firstLine
     83            && m_startColumn == other.m_startColumn
     84            && m_provider == other.m_provider
     85            && m_startOffset == other.m_startOffset
     86            && m_endOffset == other.m_endOffset;
     87    }
     88
     89    bool operator!=(const SourceCode& other) const
     90    {
     91        return !(*this == other);
     92    }
     93
     94private:
     95    OrdinalNumber m_firstLine;
     96    OrdinalNumber m_startColumn;
     97};
     98
     99inline SourceCode makeSource(const String& source, const SourceOrigin& sourceOrigin, String filename = String(), const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)
     100{
     101    return SourceCode(StringSourceProvider::create(source, sourceOrigin, WTFMove(filename), startPosition, sourceType), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt());
     102}
     103
     104inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn) const
     105{
     106    startColumn += 1; // Convert to base 1.
     107    return SourceCode(RefPtr<SourceProvider> { provider() }, openBrace, closeBrace + 1, firstLine, startColumn);
     108}
     109
    110110} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.