Skip to content

Commit

Permalink
[JSC] Dump liveness / fullness rate of ValueProfile in bytecode profiler
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259967
rdar://113609160

Reviewed by Mark Lam.

This patch adds liveness / fullness rate information of ValueProfiles to bytecode profiler
to analyze this information.

* Source/JavaScriptCore/bytecode/CodeBlock.cpp:
(JSC::CodeBlock::shouldOptimizeNowFromBaseline):
(JSC::CodeBlock::shouldOptimizeNow): Deleted.
* Source/JavaScriptCore/bytecode/CodeBlock.h:
* Source/JavaScriptCore/jit/JITOperations.cpp:
(JSC::JSC_DEFINE_JIT_OPERATION):

Canonical link: https://commits.webkit.org/266731@main
  • Loading branch information
Constellation committed Aug 9, 2023
1 parent aa54e69 commit 3604d4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
22 changes: 15 additions & 7 deletions Source/JavaScriptCore/bytecode/CodeBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2942,7 +2942,7 @@ void CodeBlock::updateAllPredictions()
}
}

bool CodeBlock::shouldOptimizeNow()
bool CodeBlock::shouldOptimizeNowFromBaseline()
{
dataLogLnIf(Options::verboseOSR(), "Considering optimizing ", *this, "...");

Expand All @@ -2961,20 +2961,28 @@ bool CodeBlock::shouldOptimizeNow()
}
}

double livenessRate = 1.0;
if (numberOfNonArgumentValueProfiles())
livenessRate = static_cast<double>(numberOfLiveNonArgumentValueProfiles) / numberOfNonArgumentValueProfiles();
double fullnessRate = 1.0;
if (totalNumberOfValueProfiles())
fullnessRate = static_cast<double>(numberOfSamplesInProfiles) / ValueProfile::numberOfBuckets / totalNumberOfValueProfiles();

if (Options::verboseOSR()) {
dataLogF(
"Profile hotness: %lf (%u / %u), %lf (%u / %u)\n",
(double)numberOfLiveNonArgumentValueProfiles / numberOfNonArgumentValueProfiles(),
livenessRate,
numberOfLiveNonArgumentValueProfiles, numberOfNonArgumentValueProfiles(),
(double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / numberOfNonArgumentValueProfiles(),
fullnessRate,
numberOfSamplesInProfiles, ValueProfile::numberOfBuckets * numberOfNonArgumentValueProfiles());
}

if ((!numberOfNonArgumentValueProfiles() || (double)numberOfLiveNonArgumentValueProfiles / numberOfNonArgumentValueProfiles() >= Options::desiredProfileLivenessRate())
&& (!totalNumberOfValueProfiles() || (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / totalNumberOfValueProfiles() >= Options::desiredProfileFullnessRate())
&& static_cast<unsigned>(m_optimizationDelayCounter) + 1 >= Options::minimumOptimizationDelay())
if (livenessRate >= Options::desiredProfileLivenessRate() && fullnessRate >= Options::desiredProfileFullnessRate() && static_cast<unsigned>(m_optimizationDelayCounter) + 1 >= Options::minimumOptimizationDelay())
return true;


auto* codeBlock = this;
CODEBLOCK_LOG_EVENT(codeBlock, "delayOptimizeToDFG", ("insufficient profiling (", livenessRate, " / ", fullnessRate, ") for ", numberOfNonArgumentValueProfiles(), " ", totalNumberOfValueProfiles()));

ASSERT(m_optimizationDelayCounter < std::numeric_limits<uint8_t>::max());
m_optimizationDelayCounter++;
optimizeAfterWarmUp();
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/bytecode/CodeBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ class CodeBlock : public JSCell {
unsigned numberOfDFGCompiles() { return 0; }
#endif

bool shouldOptimizeNow();
bool shouldOptimizeNowFromBaseline();
void updateAllNonLazyValueProfilePredictions(const ConcurrentJSLocker&);
void updateAllLazyValueProfilePredictions(const ConcurrentJSLocker&);
void updateAllArrayProfilePredictions(const ConcurrentJSLocker&);
Expand Down
3 changes: 1 addition & 2 deletions Source/JavaScriptCore/jit/JITOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2281,8 +2281,7 @@ JSC_DEFINE_JIT_OPERATION(operationOptimize, UGPRPair, (VM* vmPointer, uint32_t b
return encodeResult(nullptr, nullptr);
}
} else {
if (!codeBlock->shouldOptimizeNow()) {
CODEBLOCK_LOG_EVENT(codeBlock, "delayOptimizeToDFG", ("insufficient profiling"));
if (!codeBlock->shouldOptimizeNowFromBaseline()) {
dataLogLnIf(Options::verboseOSR(),
"Delaying optimization for ", *codeBlock,
" because of insufficient profiling.");
Expand Down

0 comments on commit 3604d4d

Please sign in to comment.