Skip to content

Commit 213ac5a

Browse files
committed
[JSC] Remove remaining LIKELY / UNLIKELY
https://bugs.webkit.org/show_bug.cgi?id=292517 rdar://150658311 Reviewed by Chris Dumez. Remove remaining LIKELY / UNLIKELY in JSC code. * Source/JavaScriptCore/KeywordLookupGenerator.py: (Trie.printSubTreeAsC): * Source/JavaScriptCore/assembler/LinkBuffer.h: * Source/JavaScriptCore/assembler/MacroAssemblerX86_64.h: (JSC::MacroAssemblerX86_64::sub64): * Source/JavaScriptCore/bytecode/ArrayAllocationProfile.h: (JSC::ArrayAllocationProfile::vectorLengthHint): * Source/JavaScriptCore/dfg/DFGPlan.cpp: (JSC::DFG::Plan::Plan): * Source/JavaScriptCore/heap/Heap.cpp: (JSC::Heap::deprecatedReportExtraMemorySlowCase): (JSC::Heap::extraMemorySize): (JSC::Heap::reportExtraMemoryVisited): * Source/JavaScriptCore/heap/HeapInlines.h: (JSC::Heap::decrementDeferralDepthAndGCIfNeeded): * Source/JavaScriptCore/parser/Lexer.cpp: (JSC::Lexer<T>::atEnd const): (JSC::Lexer<CharacterType>::parseUnicodeEscape): (JSC::Lexer<T>::parseString): (JSC::Lexer<T>::parseComplexEscape): (JSC::Lexer<T>::parseStringSlowCase): (JSC::Lexer<T>::parseTemplateLiteral): (JSC::Lexer<T>::parseMultilineComment): (JSC::Lexer<CharacterType>::parseCommentDirectiveValue): (JSC::Lexer<T>::lexWithoutClearingLineTerminator): (JSC::Lexer<T>::scanRegExp): * Source/JavaScriptCore/parser/Parser.h: (JSC::Parser::isPossiblyEscapedLet): (JSC::Parser::isPossiblyEscapedAwait): (JSC::Parser::isPossiblyEscapedYield): * Source/JavaScriptCore/parser/ParserArena.h: (JSC::ParserArena::identifierArena): * Source/JavaScriptCore/runtime/CommonSlowPaths.h: (JSC::CommonSlowPaths::opEnumeratorGetByVal): * Source/JavaScriptCore/runtime/IteratorOperations.cpp: (JSC::iteratorClose): * Source/JavaScriptCore/runtime/ObjectInitializationScope.cpp: (JSC::ObjectInitializationScope::verifyPropertiesAreInitialized): Canonical link: https://commits.webkit.org/294497@main
1 parent 036de82 commit 213ac5a

13 files changed

Lines changed: 68 additions & 30 deletions

‎Source/JavaScriptCore/KeywordLookupGenerator.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def printSubTreeAsC(self, typeName, indent):
140140
str = makePadding(indent)
141141

142142
if self.value != None:
143-
print(str + "if (LIKELY(cannotBeIdentPartOrEscapeStart(code[%d]))) {" % (len(self.fullPrefix)))
143+
print(str + "if (cannotBeIdentPartOrEscapeStart(code[%d])) [[likely]] {" % (len(self.fullPrefix)))
144144
print(str + " internalShift<%d>();" % len(self.fullPrefix))
145145
print(str + " if (shouldCreateIdentifier)")
146146
print(str + (" data->ident = &m_vm.propertyNames->%sKeyword;" % self.fullPrefix))

‎Source/JavaScriptCore/assembler/LinkBuffer.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,11 @@ ALLOW_NONLITERAL_FORMAT_END
417417
};
418418

419419
#define FINALIZE_CODE_IF(condition, linkBufferReference, resultPtrTag, simpleName, ...) \
420-
(UNLIKELY((condition) || JSC::Options::logJIT()) \
421-
? (linkBufferReference).finalizeCodeWithDisassembly<resultPtrTag>((condition), simpleName, __VA_ARGS__) \
422-
: (linkBufferReference).finalizeCodeWithoutDisassembly<resultPtrTag>(simpleName))
420+
([&]() { \
421+
if ((condition) || JSC::Options::logJIT()) [[unlikely]] \
422+
return (linkBufferReference).finalizeCodeWithDisassembly<resultPtrTag>((condition), simpleName, __VA_ARGS__); \
423+
return (linkBufferReference).finalizeCodeWithoutDisassembly<resultPtrTag>(simpleName); \
424+
}())
423425

424426
#define FINALIZE_CODE_FOR(codeBlock, linkBufferReference, resultPtrTag, simpleName, ...) \
425427
FINALIZE_CODE_IF((shouldDumpDisassemblyFor(codeBlock) || Options::asyncDisassembly()), linkBufferReference, resultPtrTag, simpleName, __VA_ARGS__)

‎Source/JavaScriptCore/assembler/MacroAssemblerX86_64.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5661,12 +5661,14 @@ class MacroAssemblerX86_64 : public AbstractMacroAssembler<Assembler> {
56615661
return;
56625662
}
56635663

5664-
if (isRepresentableAs<int32_t>(imm.m_value) && LIKELY(imm.m_value != INT32_MIN))
5665-
m_assembler.leaq_mr(-imm.m_value, src, dest);
5666-
else {
5667-
move(src, dest);
5668-
sub64(imm, dest);
5664+
if (isRepresentableAs<int32_t>(imm.m_value)) {
5665+
if (imm.m_value != INT32_MIN) [[likely]] {
5666+
m_assembler.leaq_mr(-imm.m_value, src, dest);
5667+
return;
5668+
}
56695669
}
5670+
move(src, dest);
5671+
sub64(imm, dest);
56705672
}
56715673

56725674
void sub64(TrustedImm32 imm, Address address)

‎Source/JavaScriptCore/bytecode/ArrayAllocationProfile.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class ArrayAllocationProfile {
6868
ASSERT(!isCompilationThread());
6969
JSArray* lastArray = m_storage.pointer();
7070
unsigned largestSeenVectorLength = current().vectorLength();
71-
if (lastArray && (largestSeenVectorLength != BASE_CONTIGUOUS_VECTOR_LEN_MAX) && UNLIKELY(lastArray->getVectorLength() > largestSeenVectorLength))
72-
updateProfile();
71+
if (lastArray && (largestSeenVectorLength != BASE_CONTIGUOUS_VECTOR_LEN_MAX)) {
72+
if (lastArray->getVectorLength() > largestSeenVectorLength) [[unlikely]]
73+
updateProfile();
74+
}
7375
return current().vectorLength();
7476
}
7577

‎Source/JavaScriptCore/dfg/DFGPlan.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Plan::Plan(CodeBlock* passedCodeBlock, CodeBlock* profiledDFGCodeBlock,
137137
, m_profiledDFGCodeBlock(profiledDFGCodeBlock)
138138
, m_mustHandleValues(WTFMove(mustHandleValues))
139139
, m_osrEntryBytecodeIndex(osrEntryBytecodeIndex)
140-
, m_compilation(UNLIKELY(m_vm->m_perBytecodeProfiler) ? adoptRef(new Profiler::Compilation(m_vm->m_perBytecodeProfiler->ensureBytecodesFor(m_codeBlock), profilerCompilationKindForMode(mode))) : nullptr)
140+
, m_compilation(m_vm->m_perBytecodeProfiler ? adoptRef(new Profiler::Compilation(m_vm->m_perBytecodeProfiler->ensureBytecodesFor(m_codeBlock), profilerCompilationKindForMode(mode))) : nullptr)
141141
, m_inlineCallFrames(adoptRef(new InlineCallFrameSet()))
142142
, m_identifiers(m_codeBlock)
143143
, m_transitions(m_codeBlock)

‎Source/JavaScriptCore/heap/Heap.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,10 @@ void Heap::deprecatedReportExtraMemorySlowCase(size_t size)
666666
// https://bugs.webkit.org/show_bug.cgi?id=170411
667667
CheckedSize checkedNewSize = m_deprecatedExtraMemorySize;
668668
checkedNewSize += size;
669-
m_deprecatedExtraMemorySize = UNLIKELY(checkedNewSize.hasOverflowed()) ? std::numeric_limits<size_t>::max() : checkedNewSize.value();
669+
size_t newSize = std::numeric_limits<size_t>::max();
670+
if (!checkedNewSize.hasOverflowed()) [[likely]]
671+
newSize = checkedNewSize.value();
672+
m_deprecatedExtraMemorySize = newSize;
670673
reportExtraMemoryAllocatedSlowCase(nullptr, nullptr, size);
671674
}
672675

@@ -995,7 +998,9 @@ size_t Heap::extraMemorySize()
995998
CheckedSize checkedTotal = m_extraMemorySize;
996999
checkedTotal += m_deprecatedExtraMemorySize;
9971000
checkedTotal += m_arrayBuffers.size();
998-
size_t total = UNLIKELY(checkedTotal.hasOverflowed()) ? std::numeric_limits<size_t>::max() : checkedTotal.value();
1001+
size_t total = std::numeric_limits<size_t>::max();
1002+
if (!checkedTotal.hasOverflowed()) [[likely]]
1003+
total = checkedTotal.value();
9991004

10001005
// It would be nice to have `ASSERT(m_objectSpace.capacity() >= m_objectSpace.size());` here but `m_objectSpace.size()`
10011006
// requires having heap access which thread might not. Specifically, we might be called from the resource usage thread.
@@ -2768,7 +2773,9 @@ void Heap::reportExtraMemoryVisited(size_t size)
27682773
// https://bugs.webkit.org/show_bug.cgi?id=170411
27692774
CheckedSize checkedNewSize = oldSize;
27702775
checkedNewSize += size;
2771-
size_t newSize = UNLIKELY(checkedNewSize.hasOverflowed()) ? std::numeric_limits<size_t>::max() : checkedNewSize.value();
2776+
size_t newSize = std::numeric_limits<size_t>::max();
2777+
if (!checkedNewSize.hasOverflowed()) [[likely]]
2778+
newSize = checkedNewSize.value();
27722779
if (WTF::atomicCompareExchangeWeakRelaxed(counter, oldSize, newSize))
27732780
return;
27742781
}

‎Source/JavaScriptCore/heap/HeapInlines.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ inline void Heap::decrementDeferralDepthAndGCIfNeeded()
186186
ASSERT(!Thread::mayBeGCThread() || m_worldIsStopped);
187187
m_deferralDepth--;
188188

189-
if (UNLIKELY(m_didDeferGCWork) || Options::forceDidDeferGCWork()) {
189+
if (m_didDeferGCWork || Options::forceDidDeferGCWork()) [[unlikely]] {
190190
decrementDeferralDepthAndGCIfNeededSlow();
191191

192192
// Here are the possible relationships between m_deferralDepth and m_didDeferGCWork.

‎Source/JavaScriptCore/parser/Lexer.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ template <typename T>
611611
ALWAYS_INLINE bool Lexer<T>::atEnd() const
612612
{
613613
ASSERT(!m_current || m_code < m_codeEnd);
614-
return UNLIKELY(UNLIKELY(!m_current) && m_code == m_codeEnd);
614+
if (m_current) [[likely]]
615+
return false;
616+
if (m_code == m_codeEnd) [[unlikely]]
617+
return true;
618+
return false;
615619
}
616620

617621
template <typename T>

‎Source/JavaScriptCore/parser/Parser.h‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,11 @@ class Parser {
19231923

19241924
ALWAYS_INLINE bool isPossiblyEscapedLet(const JSToken& token)
19251925
{
1926-
return token.m_type == LET || UNLIKELY(token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->letKeyword);
1926+
if (token.m_type == LET)
1927+
return true;
1928+
if (token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->letKeyword) [[unlikely]]
1929+
return true;
1930+
return false;
19271931
}
19281932

19291933
bool isDisallowedIdentifierAwait(const JSToken& token)
@@ -1938,7 +1942,11 @@ class Parser {
19381942

19391943
ALWAYS_INLINE bool isPossiblyEscapedAwait(const JSToken& token)
19401944
{
1941-
return token.m_type == AWAIT || UNLIKELY(token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->awaitKeyword);
1945+
if (token.m_type == AWAIT)
1946+
return true;
1947+
if (token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->awaitKeyword) [[unlikely]]
1948+
return true;
1949+
return false;
19421950
}
19431951

19441952
ALWAYS_INLINE bool canUseIdentifierAwait()
@@ -1958,7 +1966,11 @@ class Parser {
19581966

19591967
ALWAYS_INLINE bool isPossiblyEscapedYield(const JSToken& token)
19601968
{
1961-
return token.m_type == YIELD || UNLIKELY(token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->yieldKeyword);
1969+
if (token.m_type == YIELD)
1970+
return true;
1971+
if (token.m_type == ESCAPED_KEYWORD && *token.m_data.ident == m_vm.propertyNames->yieldKeyword) [[unlikely]]
1972+
return true;
1973+
return false;
19621974
}
19631975

19641976
ALWAYS_INLINE bool canUseIdentifierYield()

‎Source/JavaScriptCore/parser/ParserArena.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace JSC {
191191

192192
IdentifierArena& identifierArena()
193193
{
194-
if (UNLIKELY (!m_identifierArena))
194+
if (!m_identifierArena) [[unlikely]]
195195
m_identifierArena = makeUnique<IdentifierArena>();
196196
return *m_identifierArena;
197197
}

0 commit comments

Comments
 (0)