Skip to content

Commit 167235e

Browse files
Apply the UNLIKELY macro to some unlikely things.
https://bugs.webkit.org/show_bug.cgi?id=175440 <rdar://problem/33834767> Reviewed by Yusuke Suzuki. Source/JavaScriptCore: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::~CodeBlock): (JSC::CodeBlock::jettison): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleCall): (JSC::DFG::ByteCodeParser::handleVarargsCall): (JSC::DFG::ByteCodeParser::handleGetById): (JSC::DFG::ByteCodeParser::handlePutById): (JSC::DFG::ByteCodeParser::parseBlock): (JSC::DFG::ByteCodeParser::parseCodeBlock): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::JITCompiler): (JSC::DFG::JITCompiler::linkOSRExits): (JSC::DFG::JITCompiler::link): (JSC::DFG::JITCompiler::disassemble): * dfg/DFGJITFinalizer.cpp: (JSC::DFG::JITFinalizer::finalizeCommon): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::Plan): * ftl/FTLJITFinalizer.cpp: (JSC::FTL::JITFinalizer::finalizeCommon): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): (JSC::JIT::compileWithoutLinking): (JSC::JIT::link): * runtime/ScriptExecutable.cpp: (JSC::ScriptExecutable::installCode): * runtime/VM.cpp: (JSC::VM::VM): Source/WebKit: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::getBytecodeProfile): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@220556 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 99b5b1d commit 167235e

15 files changed

+90
-32
lines changed

Source/JavaScriptCore/ChangeLog

+44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
2017-08-10 Mark Lam <[email protected]>
2+
3+
Apply the UNLIKELY macro to some unlikely things.
4+
https://bugs.webkit.org/show_bug.cgi?id=175440
5+
<rdar://problem/33834767>
6+
7+
Reviewed by Yusuke Suzuki.
8+
9+
* bytecode/CodeBlock.cpp:
10+
(JSC::CodeBlock::~CodeBlock):
11+
(JSC::CodeBlock::jettison):
12+
* dfg/DFGByteCodeParser.cpp:
13+
(JSC::DFG::ByteCodeParser::handleCall):
14+
(JSC::DFG::ByteCodeParser::handleVarargsCall):
15+
(JSC::DFG::ByteCodeParser::handleGetById):
16+
(JSC::DFG::ByteCodeParser::handlePutById):
17+
(JSC::DFG::ByteCodeParser::parseBlock):
18+
(JSC::DFG::ByteCodeParser::parseCodeBlock):
19+
* dfg/DFGJITCompiler.cpp:
20+
(JSC::DFG::JITCompiler::JITCompiler):
21+
(JSC::DFG::JITCompiler::linkOSRExits):
22+
(JSC::DFG::JITCompiler::link):
23+
(JSC::DFG::JITCompiler::disassemble):
24+
* dfg/DFGJITFinalizer.cpp:
25+
(JSC::DFG::JITFinalizer::finalizeCommon):
26+
* dfg/DFGOSRExit.cpp:
27+
(JSC::DFG::OSRExit::compileOSRExit):
28+
* dfg/DFGPlan.cpp:
29+
(JSC::DFG::Plan::Plan):
30+
* ftl/FTLJITFinalizer.cpp:
31+
(JSC::FTL::JITFinalizer::finalizeCommon):
32+
* ftl/FTLLink.cpp:
33+
(JSC::FTL::link):
34+
* ftl/FTLOSRExitCompiler.cpp:
35+
(JSC::FTL::compileStub):
36+
* jit/JIT.cpp:
37+
(JSC::JIT::privateCompileMainPass):
38+
(JSC::JIT::compileWithoutLinking):
39+
(JSC::JIT::link):
40+
* runtime/ScriptExecutable.cpp:
41+
(JSC::ScriptExecutable::installCode):
42+
* runtime/VM.cpp:
43+
(JSC::VM::VM):
44+
145
2017-08-09 Yusuke Suzuki <[email protected]>
246

347
[WTF] ThreadSpecific should not introduce additional indirection

Source/JavaScriptCore/bytecode/CodeBlock.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink
839839

840840
CodeBlock::~CodeBlock()
841841
{
842-
if (m_vm->m_perBytecodeProfiler)
842+
if (UNLIKELY(m_vm->m_perBytecodeProfiler))
843843
m_vm->m_perBytecodeProfiler->notifyDestruction(this);
844844

845845
if (unlinkedCodeBlock()->didOptimize() == MixedTriState)
@@ -1917,7 +1917,8 @@ void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mod
19171917

19181918
#if ENABLE(DFG_JIT)
19191919
if (reason != Profiler::JettisonDueToOldAge) {
1920-
if (Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get())
1920+
Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get();
1921+
if (UNLIKELY(compilation))
19211922
compilation->setJettisonReason(reason, detail);
19221923

19231924
// This accomplishes (1), and does its own book-keeping about whether it has already happened.

Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ ByteCodeParser::Terminality ByteCodeParser::handleCall(
13161316
unsigned nextOffset = m_currentIndex + instructionSize;
13171317

13181318
if (handleInlining(callTarget, result, callLinkStatus, registerOffset, virtualRegisterForArgument(0, registerOffset), VirtualRegister(), 0, argumentCountIncludingThis, nextOffset, op, kind, prediction)) {
1319-
if (m_graph.compilation())
1319+
if (UNLIKELY(m_graph.compilation()))
13201320
m_graph.compilation()->noticeInlinedCall();
13211321
return NonTerminal;
13221322
}
@@ -1354,7 +1354,7 @@ ByteCodeParser::Terminality ByteCodeParser::handleVarargsCall(Instruction* pc, N
13541354

13551355
if (callLinkStatus.canOptimize()
13561356
&& handleInlining(callTarget, result, callLinkStatus, firstFreeReg, VirtualRegister(thisReg), VirtualRegister(arguments), firstVarArgOffset, 0, m_currentIndex + OPCODE_LENGTH(op_call_varargs), op, InlineCallFrame::varargsKindFor(callMode), prediction)) {
1357-
if (m_graph.compilation())
1357+
if (UNLIKELY(m_graph.compilation()))
13581358
m_graph.compilation()->noticeInlinedCall();
13591359
return NonTerminal;
13601360
}
@@ -3717,7 +3717,7 @@ void ByteCodeParser::handleGetById(
37173717

37183718
if (getById != TryGetById && getByIdStatus.isModuleNamespace()) {
37193719
if (handleModuleNamespaceLoad(destinationOperand, prediction, base, getByIdStatus)) {
3720-
if (m_graph.compilation())
3720+
if (UNLIKELY(m_graph.compilation()))
37213721
m_graph.compilation()->noticeInlinedGetById();
37223722
return;
37233723
}
@@ -3731,7 +3731,7 @@ void ByteCodeParser::handleGetById(
37313731
GetByIdVariant variant = getByIdStatus[0];
37323732
ASSERT(variant.domAttribute());
37333733
if (handleDOMJITGetter(destinationOperand, variant, base, identifierNumber, prediction)) {
3734-
if (m_graph.compilation())
3734+
if (UNLIKELY(m_graph.compilation()))
37353735
m_graph.compilation()->noticeInlinedGetById();
37363736
return;
37373737
}
@@ -3782,7 +3782,7 @@ void ByteCodeParser::handleGetById(
37823782
cases.append(MultiGetByOffsetCase(*m_graph.addStructureSet(variant.structureSet()), method));
37833783
}
37843784

3785-
if (m_graph.compilation())
3785+
if (UNLIKELY(m_graph.compilation()))
37863786
m_graph.compilation()->noticeInlinedGetById();
37873787

37883788
// 2) Emit a MultiGetByOffset
@@ -3804,7 +3804,7 @@ void ByteCodeParser::handleGetById(
38043804
return;
38053805
}
38063806

3807-
if (m_graph.compilation())
3807+
if (UNLIKELY(m_graph.compilation()))
38083808
m_graph.compilation()->noticeInlinedGetById();
38093809

38103810
ASSERT(type == AccessType::Get || !variant.callLinkStatus());
@@ -3903,7 +3903,7 @@ void ByteCodeParser::handlePutById(
39033903
}
39043904
}
39053905

3906-
if (m_graph.compilation())
3906+
if (UNLIKELY(m_graph.compilation()))
39073907
m_graph.compilation()->noticeInlinedPutById();
39083908

39093909
for (const PutByIdVariant& variant : putByIdStatus.variants()) {
@@ -3927,7 +3927,7 @@ void ByteCodeParser::handlePutById(
39273927
switch (variant.kind()) {
39283928
case PutByIdVariant::Replace: {
39293929
store(base, identifierNumber, variant, value);
3930-
if (m_graph.compilation())
3930+
if (UNLIKELY(m_graph.compilation()))
39313931
m_graph.compilation()->noticeInlinedPutById();
39323932
return;
39333933
}
@@ -3994,7 +3994,7 @@ void ByteCodeParser::handlePutById(
39943994
// https://bugs.webkit.org/show_bug.cgi?id=142924.
39953995
addToGraph(PutStructure, OpInfo(transition), base);
39963996

3997-
if (m_graph.compilation())
3997+
if (UNLIKELY(m_graph.compilation()))
39983998
m_graph.compilation()->noticeInlinedPutById();
39993999
return;
40004000
}
@@ -4124,7 +4124,7 @@ bool ByteCodeParser::parseBlock(unsigned limit)
41244124
if (Options::verboseDFGByteCodeParsing())
41254125
dataLog(" parsing ", currentCodeOrigin(), ": ", opcodeID, "\n");
41264126

4127-
if (m_graph.compilation()) {
4127+
if (UNLIKELY(m_graph.compilation())) {
41284128
addToGraph(CountExecution, OpInfo(m_graph.compilation()->executionCounterFor(
41294129
Profiler::OriginStack(*m_vm->m_perBytecodeProfiler, m_codeBlock, currentCodeOrigin()))));
41304130
}
@@ -6061,7 +6061,7 @@ void ByteCodeParser::parseCodeBlock()
60616061

60626062
CodeBlock* codeBlock = m_inlineStackTop->m_codeBlock;
60636063

6064-
if (m_graph.compilation()) {
6064+
if (UNLIKELY(m_graph.compilation())) {
60656065
m_graph.compilation()->addProfiledBytecodes(
60666066
*m_vm->m_perBytecodeProfiler, m_inlineStackTop->m_profiledBlock);
60676067
}

Source/JavaScriptCore/dfg/DFGJITCompiler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ JITCompiler::JITCompiler(Graph& dfg)
5656
, m_blockHeads(dfg.numBlocks())
5757
, m_pcToCodeOriginMapBuilder(dfg.m_vm)
5858
{
59-
if (shouldDumpDisassembly() || m_graph.m_vm.m_perBytecodeProfiler)
59+
if (UNLIKELY(shouldDumpDisassembly() || m_graph.m_vm.m_perBytecodeProfiler))
6060
m_disassembler = std::make_unique<Disassembler>(dfg);
6161
#if ENABLE(FTL_JIT)
6262
m_jitCode->tierUpInLoopHierarchy = WTFMove(m_graph.m_plan.tierUpInLoopHierarchy);
@@ -72,7 +72,7 @@ JITCompiler::~JITCompiler()
7272
void JITCompiler::linkOSRExits()
7373
{
7474
ASSERT(m_jitCode->osrExit.size() == m_exitCompilationInfo.size());
75-
if (m_graph.compilation()) {
75+
if (UNLIKELY(m_graph.compilation())) {
7676
for (unsigned i = 0; i < m_jitCode->osrExit.size(); ++i) {
7777
OSRExitCompilationInfo& info = m_exitCompilationInfo[i];
7878
Vector<Label> labels;
@@ -317,7 +317,7 @@ void JITCompiler::link(LinkBuffer& linkBuffer)
317317
}
318318
}
319319

320-
if (m_graph.compilation()) {
320+
if (UNLIKELY(m_graph.compilation())) {
321321
ASSERT(m_exitSiteLabels.size() == m_jitCode->osrExit.size());
322322
for (unsigned i = 0; i < m_exitSiteLabels.size(); ++i) {
323323
Vector<Label>& labels = m_exitSiteLabels[i];
@@ -528,7 +528,7 @@ void JITCompiler::disassemble(LinkBuffer& linkBuffer)
528528
linkBuffer.didAlreadyDisassemble();
529529
}
530530

531-
if (m_graph.m_plan.compilation)
531+
if (UNLIKELY(m_graph.m_plan.compilation))
532532
m_disassembler->reportToProfiler(m_graph.m_plan.compilation.get(), linkBuffer);
533533
}
534534

Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void JITFinalizer::finalizeCommon()
9090
m_jitCode->optimizeAfterWarmUp(m_plan.codeBlock);
9191
#endif // ENABLE(FTL_JIT)
9292

93-
if (m_plan.compilation)
93+
if (UNLIKELY(m_plan.compilation))
9494
m_plan.vm->m_perBytecodeProfiler->addCompilation(m_plan.codeBlock, *m_plan.compilation);
9595

9696
if (!m_plan.willTryToTierUp)

Source/JavaScriptCore/dfg/DFGOSRExit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void JIT_OPERATION OSRExit::compileOSRExit(ExecState* exec)
196196

197197
jit.jitAssertHasValidCallFrame();
198198

199-
if (vm->m_perBytecodeProfiler && codeBlock->jitCode()->dfgCommon()->compilation) {
199+
if (UNLIKELY(vm->m_perBytecodeProfiler && codeBlock->jitCode()->dfgCommon()->compilation)) {
200200
Profiler::Database& database = *vm->m_perBytecodeProfiler;
201201
Profiler::Compilation* compilation = codeBlock->jitCode()->dfgCommon()->compilation.get();
202202

Source/JavaScriptCore/dfg/DFGPlan.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Plan::Plan(CodeBlock* passedCodeBlock, CodeBlock* profiledDFGCodeBlock,
144144
, mode(mode)
145145
, osrEntryBytecodeIndex(osrEntryBytecodeIndex)
146146
, mustHandleValues(mustHandleValues)
147-
, compilation(vm->m_perBytecodeProfiler ? adoptRef(new Profiler::Compilation(vm->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock), profilerCompilationKindForMode(mode))) : 0)
147+
, compilation(UNLIKELY(vm->m_perBytecodeProfiler) ? adoptRef(new Profiler::Compilation(vm->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock), profilerCompilationKindForMode(mode))) : nullptr)
148148
, inlineCallFrames(adoptRef(new InlineCallFrameSet()))
149149
, identifiers(codeBlock)
150150
, weakReferences(codeBlock)

Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool JITFinalizer::finalizeCommon()
8989

9090
m_plan.codeBlock->setJITCode(*jitCode);
9191

92-
if (m_plan.compilation)
92+
if (UNLIKELY(m_plan.compilation))
9393
m_plan.vm->m_perBytecodeProfiler->addCompilation(m_plan.codeBlock, *m_plan.compilation);
9494

9595
return true;

Source/JavaScriptCore/ftl/FTLLink.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void link(State& state)
6868
CCallHelpers::Address frame = CCallHelpers::Address(
6969
CCallHelpers::stackPointerRegister, -static_cast<int32_t>(AssemblyHelpers::prologueStackPointerDelta()));
7070

71-
if (Profiler::Compilation* compilation = graph.compilation()) {
71+
Profiler::Compilation* compilation = graph.compilation();
72+
if (UNLIKELY(compilation)) {
7273
compilation->addDescription(
7374
Profiler::OriginStack(),
7475
toCString("Generated FTL JIT code for ", CodeBlockWithJITType(codeBlock, JITCode::FTLJIT), ", instruction count = ", graph.m_codeBlock->instructionCount(), ":\n"));

Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static void compileStub(
248248
jit.popToRestore(GPRInfo::regT0);
249249
jit.checkStackPointerAlignment();
250250

251-
if (vm->m_perBytecodeProfiler && jitCode->dfgCommon()->compilation) {
251+
if (UNLIKELY(vm->m_perBytecodeProfiler && jitCode->dfgCommon()->compilation)) {
252252
Profiler::Database& database = *vm->m_perBytecodeProfiler;
253253
Profiler::Compilation* compilation = jitCode->dfgCommon()->compilation.get();
254254

Source/JavaScriptCore/jit/JIT.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void JIT::privateCompileMainPass()
243243

244244
OpcodeID opcodeID = Interpreter::getOpcodeID(currentInstruction->u.opcode);
245245

246-
if (m_compilation) {
246+
if (UNLIKELY(m_compilation)) {
247247
add64(
248248
TrustedImm32(1),
249249
AbsoluteAddress(m_compilation->executionCounterFor(Profiler::OriginStack(Profiler::Origin(
@@ -611,9 +611,9 @@ void JIT::compileWithoutLinking(JITCompilationEffort effort)
611611
break;
612612
}
613613

614-
if (Options::dumpDisassembly() || (m_vm->m_perBytecodeProfiler && Options::disassembleBaselineForProfiler()))
614+
if (UNLIKELY(Options::dumpDisassembly() || (m_vm->m_perBytecodeProfiler && Options::disassembleBaselineForProfiler())))
615615
m_disassembler = std::make_unique<JITDisassembler>(m_codeBlock);
616-
if (m_vm->m_perBytecodeProfiler) {
616+
if (UNLIKELY(m_vm->m_perBytecodeProfiler)) {
617617
m_compilation = adoptRef(
618618
new Profiler::Compilation(
619619
m_vm->m_perBytecodeProfiler->ensureBytecodesFor(m_codeBlock),
@@ -841,7 +841,7 @@ CompilationResult JIT::link()
841841
m_disassembler->dump(patchBuffer);
842842
patchBuffer.didAlreadyDisassemble();
843843
}
844-
if (m_compilation) {
844+
if (UNLIKELY(m_compilation)) {
845845
if (Options::disassembleBaselineForProfiler())
846846
m_disassembler->reportToProfiler(m_compilation.get(), patchBuffer);
847847
m_vm->m_perBytecodeProfiler->addCompilation(m_codeBlock, *m_compilation);

Source/JavaScriptCore/runtime/ScriptExecutable.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ void ScriptExecutable::installCode(VM& vm, CodeBlock* genericCodeBlock, CodeType
151151
RELEASE_ASSERT(genericCodeBlock->ownerExecutable() == this);
152152
RELEASE_ASSERT(JITCode::isExecutableScript(genericCodeBlock->jitType()));
153153

154-
if (Options::verboseOSR())
154+
if (UNLIKELY(Options::verboseOSR()))
155155
dataLog("Installing ", *genericCodeBlock, "\n");
156156

157-
if (vm.m_perBytecodeProfiler)
157+
if (UNLIKELY(vm.m_perBytecodeProfiler))
158158
vm.m_perBytecodeProfiler->ensureBytecodesFor(genericCodeBlock);
159159

160-
if (Debugger* debugger = genericCodeBlock->globalObject()->debugger())
160+
Debugger* debugger = genericCodeBlock->globalObject()->debugger();
161+
if (UNLIKELY(debugger))
161162
debugger->registerCodeBlock(genericCodeBlock);
162163
}
163164

Source/JavaScriptCore/runtime/VM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ VM::VM(VMType vmType, HeapType heapType)
300300

301301
LLInt::Data::performAssertions(*this);
302302

303-
if (Options::useProfiler()) {
303+
if (UNLIKELY(Options::useProfiler())) {
304304
m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*this);
305305

306306
StringPrintStream pathOut;

Source/WebKit/ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2017-08-10 Mark Lam <[email protected]>
2+
3+
Apply the UNLIKELY macro to some unlikely things.
4+
https://bugs.webkit.org/show_bug.cgi?id=175440
5+
<rdar://problem/33834767>
6+
7+
Reviewed by Yusuke Suzuki.
8+
9+
* WebProcess/WebPage/WebPage.cpp:
10+
(WebKit::WebPage::getBytecodeProfile):
11+
112
2017-08-10 Chris Dumez <[email protected]>
213

314
Turn on support for Beacon API by default in STP

Source/WebKit/WebProcess/WebPage/WebPage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,7 @@ void WebPage::updateCachedDocumentLoader(WebDocumentLoader& documentLoader, Fram
57095709

57105710
void WebPage::getBytecodeProfile(CallbackID callbackID)
57115711
{
5712-
if (!commonVM().m_perBytecodeProfiler) {
5712+
if (LIKELY(!commonVM().m_perBytecodeProfiler)) {
57135713
send(Messages::WebPageProxy::StringCallback(String(), callbackID));
57145714
return;
57155715
}

0 commit comments

Comments
 (0)