Skip to content

Commit ad96437

Browse files
committed
[JSC] LLInt should not poll the JIT worklist on every execution while a baseline compile is in flight
https://bugs.webkit.org/show_bug.cgi?id=327603 rdar://190060754 Reviewed by Vassili Bykov. When LLInt execution counter crossed the threshold and enqueueing Baseline JIT compilation, we keep this counter crossed. As a result, we end up running this slow path every time until Baseline JIT code is installed. If Baseline JIT code takes long time to be compiled, it makes LLInt much slower. We follow to what DFG is doing for Baseline JIT. We reset the counter, and we make it fired when Baseline JIT code is installed. * Source/JavaScriptCore/bytecode/CodeBlock.cpp: (JSC::CodeBlock::checkIfJITThresholdReached): * Source/JavaScriptCore/bytecode/CodeBlock.h: (JSC::CodeBlock::checkIfJITThresholdReached): Deleted. * Source/JavaScriptCore/dfg/DFGPlan.h: * Source/JavaScriptCore/jit/BaselineJITPlan.cpp: (JSC::BaselineJITPlan::notifyReady): (JSC::BaselineJITPlan::finalize): * Source/JavaScriptCore/jit/BaselineJITPlan.h: * Source/JavaScriptCore/llint/LLIntSlowPaths.cpp: (JSC::LLInt::jitCompileAndSetHeuristics): Canonical link: https://commits.webkit.org/323860@main
1 parent a54d5f7 commit ad96437

6 files changed

Lines changed: 49 additions & 19 deletions

File tree

‎Source/JavaScriptCore/bytecode/CodeBlock.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,6 +3580,17 @@ std::optional<BytecodeIndex> CodeBlock::bytecodeIndexFromCallSiteIndex(CallSiteI
35803580
return bytecodeIndex;
35813581
}
35823582

3583+
bool CodeBlock::checkIfJITThresholdReached()
3584+
{
3585+
#if ENABLE(JIT)
3586+
if (JITWorklist* worklist = JITWorklist::existingGlobalWorklistOrNull()) {
3587+
if (worklist->compilationState(*m_vm, JITCompilationKey(m_unlinkedCode.get(), JITCompilationMode::Baseline)) == JITWorklist::Compiled)
3588+
return true;
3589+
}
3590+
#endif
3591+
return m_unlinkedCode->llintExecuteCounter().checkIfThresholdCrossedAndSet(this);
3592+
}
3593+
35833594
void CodeBlock::jitSoon()
35843595
{
35853596
m_unlinkedCode->llintExecuteCounter().setNewThreshold(unlinkedCodeBlock()->thresholdForJIT(Options::thresholdForJITSoon()), this);

‎Source/JavaScriptCore/bytecode/CodeBlock.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,7 @@ class CodeBlock : public JSCell {
600600
// Functions for controlling when JITting kicks in, in a mixed mode
601601
// execution world.
602602

603-
bool checkIfJITThresholdReached()
604-
{
605-
return m_unlinkedCode->llintExecuteCounter().checkIfThresholdCrossedAndSet(this);
606-
}
603+
bool checkIfJITThresholdReached();
607604

608605
void dontJITAnytimeSoon()
609606
{

‎Source/JavaScriptCore/dfg/DFGPlan.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Plan final : public JITPlan {
6565

6666
size_t codeSize() const final;
6767
void reconcileWeakReferencesAtGCEnd() final;
68-
CompilationResult finalize() override;
68+
CompilationResult finalize() final;
6969

7070
void notifyReady() final;
7171
void cancel() final;
@@ -106,7 +106,7 @@ class Plan final : public JITPlan {
106106
std::unique_ptr<JITData> tryFinalizeJITData(const DFG::JITCode&);
107107

108108
private:
109-
CompilationPath compileInThreadImpl() override;
109+
CompilationPath compileInThreadImpl() final;
110110
void finalizeInThread(Ref<JSC::JITCode>);
111111

112112
bool isStillValidCodeBlock();

‎Source/JavaScriptCore/jit/BaselineJITPlan.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ size_t BaselineJITPlan::codeSize() const
8282
return 0;
8383
}
8484

85+
void BaselineJITPlan::notifyReady()
86+
{
87+
Base::notifyReady();
88+
m_codeBlock->unlinkedCodeBlock()->llintExecuteCounter().forceSlowPathConcurrently();
89+
}
90+
8591
bool BaselineJITPlan::isKnownToBeLiveAfterGC()
8692
{
8793
// If stage is not JITPlanStage::Canceled, we should keep this alive and mark underlying CodeBlock anyway.
@@ -110,7 +116,8 @@ CompilationResult BaselineJITPlan::finalize()
110116
WTF::crossModifyingCodeFence();
111117
dataLogLnIf(Options::verboseOSR(), " JIT compilation successful.");
112118
m_codeBlock->ownerExecutable()->installCode(m_codeBlock);
113-
m_codeBlock->jitSoon();
119+
// Frames still in LLInt (entered before the install, or arriving via OSR exit) should switch at their next check.
120+
m_codeBlock->jitNextInvocation();
114121
break;
115122
default:
116123
RELEASE_ASSERT_NOT_REACHED();

‎Source/JavaScriptCore/jit/BaselineJITPlan.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class BaselineJITPlan final : public JITPlan {
4343

4444
CompilationPath compileInThreadImpl() final;
4545
size_t codeSize() const final;
46-
CompilationResult finalize() override;
46+
void notifyReady() final;
47+
CompilationResult finalize() final;
4748

4849
CompilationPath compileSync(JITCompilationEffort);
4950

‎Source/JavaScriptCore/llint/LLIntSlowPaths.cpp‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,35 +383,49 @@ static inline bool jitCompileAndSetHeuristics(VM& vm, CodeBlock* codeBlock)
383383
DeferGCForAWhile deferGC(vm); // My callers don't set top callframe, so we don't want to GC here at all.
384384
ASSERT(Options::useJIT());
385385

386-
if (codeBlock->jitType() != JITType::BaselineJIT) {
387-
if (RefPtr<BaselineJITCode> baselineRef = codeBlock->unlinkedCodeBlock()->m_unlinkedBaselineCode) {
388-
codeBlock->setupWithUnlinkedBaselineCode(baselineRef.releaseNonNull());
389-
codeBlock->ownerExecutable()->installCode(codeBlock);
390-
codeBlock->jitNextInvocation();
391-
return true;
392-
}
393-
}
386+
auto installSharedBaselineCode = [&] {
387+
RefPtr<BaselineJITCode> baselineRef = codeBlock->unlinkedCodeBlock()->m_unlinkedBaselineCode;
388+
if (!baselineRef)
389+
return false;
390+
codeBlock->setupWithUnlinkedBaselineCode(baselineRef.releaseNonNull());
391+
codeBlock->ownerExecutable()->installCode(codeBlock);
392+
codeBlock->jitNextInvocation();
393+
return true;
394+
};
395+
396+
if (codeBlock->jitType() != JITType::BaselineJIT && installSharedBaselineCode())
397+
return true;
394398

395399
if (!codeBlock->checkIfJITThresholdReached()) {
396400
CODEBLOCK_LOG_EVENT(codeBlock, "delayJITCompile", ("threshold not reached, counter = ", codeBlock->llintExecuteCounter()));
397401
dataLogLnIf(Options::verboseOSR(), " JIT threshold should be lifted.");
398402
return false;
399403
}
400404

405+
// Must precede the worklist query so that a plan becoming ready afterwards can still force the slow path. finalize() overrides it.
406+
codeBlock->jitSoon();
407+
401408
JITWorklist::State worklistState = JITWorklist::ensureGlobalWorklist().completeAllReadyPlansForVM(vm, JITCompilationKey(codeBlock->unlinkedCodeBlock(), JITCompilationMode::Baseline));
402409

403410
if (codeBlock->jitType() == JITType::BaselineJIT) {
404411
dataLogLnIf(Options::verboseOSR(), " Code was already compiled.");
405-
codeBlock->jitSoon();
412+
codeBlock->jitNextInvocation();
406413
return true;
407414
}
408415

409-
if (worklistState == JITWorklist::NotKnown) {
416+
switch (worklistState) {
417+
case JITWorklist::NotKnown: {
410418
Ref<BaselineJITPlan> plan = adoptRef(*new BaselineJITPlan(codeBlock));
411419
JITWorklist::ensureGlobalWorklist().enqueue(WTF::move(plan));
412420
return codeBlock->jitType() == JITType::BaselineJIT;
413421
}
414-
422+
case JITWorklist::Compiled:
423+
// Either our compile failed, or the plan belonged to another CodeBlock sharing this UnlinkedCodeBlock.
424+
return installSharedBaselineCode();
425+
case JITWorklist::Compiling:
426+
return false;
427+
}
428+
RELEASE_ASSERT_NOT_REACHED();
415429
return false;
416430
}
417431

0 commit comments

Comments
 (0)