Skip to content

Commit

Permalink
Merge r220556 - Apply the UNLIKELY macro to some unlikely things.
Browse files Browse the repository at this point in the history
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):
  • Loading branch information
Mark Lam authored and carlosgcampos committed Aug 14, 2017
1 parent 324261f commit f3cd1e8
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 32 deletions.
44 changes: 44 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,47 @@
2017-08-10 Mark Lam <mark.lam@apple.com>

Apply the UNLIKELY macro to some unlikely things.
https://bugs.webkit.org/show_bug.cgi?id=175440
<rdar://problem/33834767>

Reviewed by Yusuke Suzuki.

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

2017-08-09 Yusuke Suzuki <utatane.tea@gmail.com>

[WTF] ThreadSpecific should not introduce additional indirection
Expand Down
5 changes: 3 additions & 2 deletions Source/JavaScriptCore/bytecode/CodeBlock.cpp
Expand Up @@ -839,7 +839,7 @@ bool CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, Unlink

CodeBlock::~CodeBlock()
{
if (m_vm->m_perBytecodeProfiler)
if (UNLIKELY(m_vm->m_perBytecodeProfiler))
m_vm->m_perBytecodeProfiler->notifyDestruction(this);

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

#if ENABLE(DFG_JIT)
if (reason != Profiler::JettisonDueToOldAge) {
if (Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get())
Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get();
if (UNLIKELY(compilation))
compilation->setJettisonReason(reason, detail);

// This accomplishes (1), and does its own book-keeping about whether it has already happened.
Expand Down
22 changes: 11 additions & 11 deletions Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Expand Up @@ -1316,7 +1316,7 @@ ByteCodeParser::Terminality ByteCodeParser::handleCall(
unsigned nextOffset = m_currentIndex + instructionSize;

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

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

if (getById != TryGetById && getByIdStatus.isModuleNamespace()) {
if (handleModuleNamespaceLoad(destinationOperand, prediction, base, getByIdStatus)) {
if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedGetById();
return;
}
Expand All @@ -3731,7 +3731,7 @@ void ByteCodeParser::handleGetById(
GetByIdVariant variant = getByIdStatus[0];
ASSERT(variant.domAttribute());
if (handleDOMJITGetter(destinationOperand, variant, base, identifierNumber, prediction)) {
if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedGetById();
return;
}
Expand Down Expand Up @@ -3782,7 +3782,7 @@ void ByteCodeParser::handleGetById(
cases.append(MultiGetByOffsetCase(*m_graph.addStructureSet(variant.structureSet()), method));
}

if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedGetById();

// 2) Emit a MultiGetByOffset
Expand All @@ -3804,7 +3804,7 @@ void ByteCodeParser::handleGetById(
return;
}

if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedGetById();

ASSERT(type == AccessType::Get || !variant.callLinkStatus());
Expand Down Expand Up @@ -3903,7 +3903,7 @@ void ByteCodeParser::handlePutById(
}
}

if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedPutById();

for (const PutByIdVariant& variant : putByIdStatus.variants()) {
Expand All @@ -3927,7 +3927,7 @@ void ByteCodeParser::handlePutById(
switch (variant.kind()) {
case PutByIdVariant::Replace: {
store(base, identifierNumber, variant, value);
if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedPutById();
return;
}
Expand Down Expand Up @@ -3994,7 +3994,7 @@ void ByteCodeParser::handlePutById(
// https://bugs.webkit.org/show_bug.cgi?id=142924.
addToGraph(PutStructure, OpInfo(transition), base);

if (m_graph.compilation())
if (UNLIKELY(m_graph.compilation()))
m_graph.compilation()->noticeInlinedPutById();
return;
}
Expand Down Expand Up @@ -4124,7 +4124,7 @@ bool ByteCodeParser::parseBlock(unsigned limit)
if (Options::verboseDFGByteCodeParsing())
dataLog(" parsing ", currentCodeOrigin(), ": ", opcodeID, "\n");

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

CodeBlock* codeBlock = m_inlineStackTop->m_codeBlock;

if (m_graph.compilation()) {
if (UNLIKELY(m_graph.compilation())) {
m_graph.compilation()->addProfiledBytecodes(
*m_vm->m_perBytecodeProfiler, m_inlineStackTop->m_profiledBlock);
}
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/dfg/DFGJITCompiler.cpp
Expand Up @@ -56,7 +56,7 @@ JITCompiler::JITCompiler(Graph& dfg)
, m_blockHeads(dfg.numBlocks())
, m_pcToCodeOriginMapBuilder(dfg.m_vm)
{
if (shouldDumpDisassembly() || m_graph.m_vm.m_perBytecodeProfiler)
if (UNLIKELY(shouldDumpDisassembly() || m_graph.m_vm.m_perBytecodeProfiler))
m_disassembler = std::make_unique<Disassembler>(dfg);
#if ENABLE(FTL_JIT)
m_jitCode->tierUpInLoopHierarchy = WTFMove(m_graph.m_plan.tierUpInLoopHierarchy);
Expand All @@ -72,7 +72,7 @@ JITCompiler::~JITCompiler()
void JITCompiler::linkOSRExits()
{
ASSERT(m_jitCode->osrExit.size() == m_exitCompilationInfo.size());
if (m_graph.compilation()) {
if (UNLIKELY(m_graph.compilation())) {
for (unsigned i = 0; i < m_jitCode->osrExit.size(); ++i) {
OSRExitCompilationInfo& info = m_exitCompilationInfo[i];
Vector<Label> labels;
Expand Down Expand Up @@ -317,7 +317,7 @@ void JITCompiler::link(LinkBuffer& linkBuffer)
}
}

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

if (m_graph.m_plan.compilation)
if (UNLIKELY(m_graph.m_plan.compilation))
m_disassembler->reportToProfiler(m_graph.m_plan.compilation.get(), linkBuffer);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp
Expand Up @@ -90,7 +90,7 @@ void JITFinalizer::finalizeCommon()
m_jitCode->optimizeAfterWarmUp(m_plan.codeBlock);
#endif // ENABLE(FTL_JIT)

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

if (!m_plan.willTryToTierUp)
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/dfg/DFGOSRExit.cpp
Expand Up @@ -196,7 +196,7 @@ void JIT_OPERATION OSRExit::compileOSRExit(ExecState* exec)

jit.jitAssertHasValidCallFrame();

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

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/dfg/DFGPlan.cpp
Expand Up @@ -144,7 +144,7 @@ Plan::Plan(CodeBlock* passedCodeBlock, CodeBlock* profiledDFGCodeBlock,
, mode(mode)
, osrEntryBytecodeIndex(osrEntryBytecodeIndex)
, mustHandleValues(mustHandleValues)
, compilation(vm->m_perBytecodeProfiler ? adoptRef(new Profiler::Compilation(vm->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock), profilerCompilationKindForMode(mode))) : 0)
, compilation(UNLIKELY(vm->m_perBytecodeProfiler) ? adoptRef(new Profiler::Compilation(vm->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock), profilerCompilationKindForMode(mode))) : nullptr)
, inlineCallFrames(adoptRef(new InlineCallFrameSet()))
, identifiers(codeBlock)
, weakReferences(codeBlock)
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp
Expand Up @@ -89,7 +89,7 @@ bool JITFinalizer::finalizeCommon()

m_plan.codeBlock->setJITCode(*jitCode);

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

return true;
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/ftl/FTLLink.cpp
Expand Up @@ -68,7 +68,8 @@ void link(State& state)
CCallHelpers::Address frame = CCallHelpers::Address(
CCallHelpers::stackPointerRegister, -static_cast<int32_t>(AssemblyHelpers::prologueStackPointerDelta()));

if (Profiler::Compilation* compilation = graph.compilation()) {
Profiler::Compilation* compilation = graph.compilation();
if (UNLIKELY(compilation)) {
compilation->addDescription(
Profiler::OriginStack(),
toCString("Generated FTL JIT code for ", CodeBlockWithJITType(codeBlock, JITCode::FTLJIT), ", instruction count = ", graph.m_codeBlock->instructionCount(), ":\n"));
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp
Expand Up @@ -248,7 +248,7 @@ static void compileStub(
jit.popToRestore(GPRInfo::regT0);
jit.checkStackPointerAlignment();

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

Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/jit/JIT.cpp
Expand Up @@ -243,7 +243,7 @@ void JIT::privateCompileMainPass()

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

if (m_compilation) {
if (UNLIKELY(m_compilation)) {
add64(
TrustedImm32(1),
AbsoluteAddress(m_compilation->executionCounterFor(Profiler::OriginStack(Profiler::Origin(
Expand Down Expand Up @@ -611,9 +611,9 @@ void JIT::compileWithoutLinking(JITCompilationEffort effort)
break;
}

if (Options::dumpDisassembly() || (m_vm->m_perBytecodeProfiler && Options::disassembleBaselineForProfiler()))
if (UNLIKELY(Options::dumpDisassembly() || (m_vm->m_perBytecodeProfiler && Options::disassembleBaselineForProfiler())))
m_disassembler = std::make_unique<JITDisassembler>(m_codeBlock);
if (m_vm->m_perBytecodeProfiler) {
if (UNLIKELY(m_vm->m_perBytecodeProfiler)) {
m_compilation = adoptRef(
new Profiler::Compilation(
m_vm->m_perBytecodeProfiler->ensureBytecodesFor(m_codeBlock),
Expand Down Expand Up @@ -841,7 +841,7 @@ CompilationResult JIT::link()
m_disassembler->dump(patchBuffer);
patchBuffer.didAlreadyDisassemble();
}
if (m_compilation) {
if (UNLIKELY(m_compilation)) {
if (Options::disassembleBaselineForProfiler())
m_disassembler->reportToProfiler(m_compilation.get(), patchBuffer);
m_vm->m_perBytecodeProfiler->addCompilation(m_codeBlock, *m_compilation);
Expand Down
7 changes: 4 additions & 3 deletions Source/JavaScriptCore/runtime/ScriptExecutable.cpp
Expand Up @@ -151,13 +151,14 @@ void ScriptExecutable::installCode(VM& vm, CodeBlock* genericCodeBlock, CodeType
RELEASE_ASSERT(genericCodeBlock->ownerExecutable() == this);
RELEASE_ASSERT(JITCode::isExecutableScript(genericCodeBlock->jitType()));

if (Options::verboseOSR())
if (UNLIKELY(Options::verboseOSR()))
dataLog("Installing ", *genericCodeBlock, "\n");

if (vm.m_perBytecodeProfiler)
if (UNLIKELY(vm.m_perBytecodeProfiler))
vm.m_perBytecodeProfiler->ensureBytecodesFor(genericCodeBlock);

if (Debugger* debugger = genericCodeBlock->globalObject()->debugger())
Debugger* debugger = genericCodeBlock->globalObject()->debugger();
if (UNLIKELY(debugger))
debugger->registerCodeBlock(genericCodeBlock);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/VM.cpp
Expand Up @@ -300,7 +300,7 @@ VM::VM(VMType vmType, HeapType heapType)

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

if (Options::useProfiler()) {
if (UNLIKELY(Options::useProfiler())) {
m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*this);

StringPrintStream pathOut;
Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,14 @@
2017-08-10 Mark Lam <mark.lam@apple.com>

Apply the UNLIKELY macro to some unlikely things.
https://bugs.webkit.org/show_bug.cgi?id=175440
<rdar://problem/33834767>

Reviewed by Yusuke Suzuki.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getBytecodeProfile):

2017-08-10 Tim Horton <timothy_horton@apple.com>

Remove some unused lambda captures so that WebKit builds with -Wunused-lambda-capture
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/WebPage.cpp
Expand Up @@ -5703,7 +5703,7 @@ void WebPage::updateCachedDocumentLoader(WebDocumentLoader& documentLoader, Fram

void WebPage::getBytecodeProfile(CallbackID callbackID)
{
if (!commonVM().m_perBytecodeProfiler) {
if (LIKELY(!commonVM().m_perBytecodeProfiler)) {
send(Messages::WebPageProxy::StringCallback(String(), callbackID));
return;
}
Expand Down

0 comments on commit f3cd1e8

Please sign in to comment.