source: webkit/trunk/Source/JavaScriptCore/parser/SourceCode.h

Last change on this file was 283903, checked in by [email protected], 4 years ago

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):

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
2 * Copyright (C) 2008, 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#include "UnlinkedSourceCode.h"
32
33namespace JSC {
34
35class SourceCode : public UnlinkedSourceCode {
36 friend class CachedSourceCode;
37 friend class CachedSourceCodeWithoutProvider;
38
39public:
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 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
110} // namespace JSC
Note: See TracBrowser for help on using the repository browser.