JavaScriptCore should discard optimized code after some time
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Sep 2015 16:08:39 +0000 (16:08 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Sep 2015 16:08:39 +0000 (16:08 +0000)
commit5817c23875083be72f8c8752027dab33b52b8db1
tree32bcb08c1e73dcfd877bd5dc2608f85e774b711c
parent089e14eb448c76e11d1fc9101097f56a691432e3
JavaScriptCore should discard optimized code after some time
https://bugs.webkit.org/show_bug.cgi?id=149048

Reviewed by Michael Saboff.

This patch adds a new jettison type -- JettisonDueToOldAge -- and starts
using it for DFG and FTL code. Baseline and LLInt code will come in a
follow-up patch.

The primary goal is to save memory. Some popular websites leave about 10MB
of dead code sitting around immediately after they finish loading.

Throwing away code periodically might also save us from profiling
pathologies that lead to performance dead ends.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::visitAggregate): Updated for rename, and removed a
stale comment.

(JSC::CodeBlock::shouldVisitStrongly): Renamed to shouldVisitStrongly
because the practical effect of this function is to trigger a call to
visitStrongly.

(JSC::CodeBlock::isKnownToBeLiveDuringGC): Check the
m_visitStronglyHasBeenCalled flag instead of
shouldImmediatelyAssumeLivenessDuringScan / shouldVisitStrongly because
m_visitStronglyHasBeenCalled can be set by anybody even if the CodeBlock
would not otherwise visit itself strongly.

(JSC::CodeBlock::shouldJettisonDueToWeakReference): New helper function
for readability.

(JSC::CodeBlock::shouldJettisonDueToOldAge): New helper function that
tells if a CodeBlock is old enough for deletion.

(JSC::CodeBlock::determineLiveness): There's no need to check
shouldImmediatelyAssumeLivenessDuringScan here because we will not call
this function if shouldImmediatelyAssumeLivenessDuringScan is true.
Also, it's just not clear -- if someone chooses to call this function --
that it would be safe to ignore them simply because
shouldImmediatelyAssumeLivenessDuringScan was true.

(JSC::CodeBlock::finalizeLLIntInlineCaches): Moved code out into a helper
function to make the main function more readable.

(JSC::CodeBlock::finalizeBaselineJITInlineCaches): Ditto.

(JSC::CodeBlock::finalizeUnconditionally): Added code for jettisoning a
CodeBlock if it is too old. Moved large sections of code into helper
functions to aid readability in this function.

(JSC::CodeBlock::jettison): Account for the fact that we might jettison
a CodeBlock without OSR exit and without requiring a stack shoot-down.

* bytecode/CodeBlock.h:
(JSC::CodeBlock::setInstallTime):
(JSC::CodeBlock::timeSinceInstall): Track CodeBlock age to help us
decide when to delete.

* jit/JITCode.h:
(JSC::JITCode::timeToLive): Static limits on CodeBlock lifetime. I got
these numbers from the place where numbers come from.

* profiler/ProfilerJettisonReason.cpp:
(WTF::printInternal):
* profiler/ProfilerJettisonReason.h: Updated for new jettison type.

* runtime/Executable.cpp:
(JSC::ScriptExecutable::installCode): Record install time so that we
can measure how old a CodeBlock is.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189620 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/jit/JITCode.h
Source/JavaScriptCore/profiler/ProfilerJettisonReason.cpp
Source/JavaScriptCore/profiler/ProfilerJettisonReason.h
Source/JavaScriptCore/runtime/Executable.cpp