Skip to content

Commit

Permalink
[JSC] Insert more DFG safepoints during DFG ByteCodeParser
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265559
rdar://118959478

Reviewed by Mark Lam.

This patch adds more DFG safepoints into DFG ByteCodeParser so that
we can stop DFG compiler threads when GC requests.

* Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::pruneUnreachableNodes):
(JSC::DFG::ByteCodeParser::parse):
(JSC::DFG::parse):
* Source/JavaScriptCore/dfg/DFGByteCodeParser.h:
* Source/JavaScriptCore/dfg/DFGPlan.cpp:
(JSC::DFG::Plan::compileInThreadImpl):

Canonical link: https://commits.webkit.org/271320@main
  • Loading branch information
Constellation committed Nov 30, 2023
1 parent 907be25 commit b217c0b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
79 changes: 52 additions & 27 deletions Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "DFGClobberize.h"
#include "DFGClobbersExitState.h"
#include "DFGGraph.h"
#include "DFGGraphSafepoint.h"
#include "DFGLiveCatchVariablePreservationPhase.h"
#include "DOMJITGetterSetter.h"
#include "DeleteByStatus.h"
Expand Down Expand Up @@ -135,7 +136,7 @@ class ByteCodeParser {
}

// Parse a full CodeBlock of bytecode.
void parse();
bool parse();

private:
struct InlineStackEntry;
Expand Down Expand Up @@ -1199,6 +1200,8 @@ class ByteCodeParser {

bool needsDynamicLookup(ResolveType, OpcodeID);

void pruneUnreachableNodes();

VM* const m_vm;
CodeBlock* const m_codeBlock;
CodeBlock* const m_profiledBlock;
Expand Down Expand Up @@ -9829,31 +9832,8 @@ void ByteCodeParser::handleCreateInternalFieldObject(const ClassInfo* classInfo,
set(VirtualRegister(bytecode.m_dst), addToGraph(createOp, callee));
}

void ByteCodeParser::parse()
void ByteCodeParser::pruneUnreachableNodes()
{
// Set during construction.
ASSERT(!m_currentIndex.offset());

VERBOSE_LOG("Parsing ", *m_codeBlock, "\n");

InlineStackEntry inlineStackEntry(
this, m_codeBlock, m_profiledBlock, nullptr, VirtualRegister(), VirtualRegister(),
m_codeBlock->numParameters(), InlineCallFrame::Call, nullptr);

parseCodeBlock();
linkBlocks(inlineStackEntry.m_unlinkedBlocks, inlineStackEntry.m_blockLinkingTargets);

// We insert catch variable preservation here to show all bytecode
// uses to the subsequent backward propagation phase.
performLiveCatchVariablePreservationPhase(m_graph);

// We run backwards propagation now because the soundness of that phase
// relies on seeing the graph as if it were an IR over bytecode, since
// the spec-correctness of that phase relies on seeing all bytecode uses.
// Therefore, we run this pass before we do any pruning of the graph
// after ForceOSRExit sites.
performBackwardsPropagation(m_graph);

if (m_hasAnyForceOSRExits) {
BlockSet blocksToIgnore;
for (BasicBlock* block : m_graph.blocksInNaturalOrder()) {
Expand Down Expand Up @@ -9959,10 +9939,52 @@ void ByteCodeParser::parse()
RELEASE_ASSERT(node->op() != ForceOSRExit);
}
}
}

#define RUN_ANALYSIS(code) \
do { \
if (Options::safepointBeforeEachPhase()) { \
Safepoint::Result safepointResult; \
{ \
GraphSafepoint safepoint(m_graph, safepointResult); \
} \
if (safepointResult.didGetCancelled()) \
return false; \
} \
(code); \
} while (false); \

bool ByteCodeParser::parse()
{
// Set during construction.
ASSERT(!m_currentIndex.offset());

VERBOSE_LOG("Parsing ", *m_codeBlock, "\n");

InlineStackEntry inlineStackEntry(
this, m_codeBlock, m_profiledBlock, nullptr, VirtualRegister(), VirtualRegister(),
m_codeBlock->numParameters(), InlineCallFrame::Call, nullptr);

parseCodeBlock();
linkBlocks(inlineStackEntry.m_unlinkedBlocks, inlineStackEntry.m_blockLinkingTargets);

// We insert catch variable preservation here to show all bytecode
// uses to the subsequent backward propagation phase.
RUN_ANALYSIS(performLiveCatchVariablePreservationPhase(m_graph));

// We run backwards propagation now because the soundness of that phase
// relies on seeing the graph as if it were an IR over bytecode, since
// the spec-correctness of that phase relies on seeing all bytecode uses.
// Therefore, we run this pass before we do any pruning of the graph
// after ForceOSRExit sites.
RUN_ANALYSIS(performBackwardsPropagation(m_graph));

RUN_ANALYSIS(pruneUnreachableNodes());

m_graph.determineReachability();
m_graph.killUnreachableBlocks();

#if ASSERT_ENABLED
for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
BasicBlock* block = m_graph.block(blockIndex);
if (!block)
Expand All @@ -9972,15 +9994,18 @@ void ByteCodeParser::parse()
ASSERT(block->variablesAtTail.numberOfLocals() == m_graph.block(0)->variablesAtHead.numberOfLocals());
ASSERT(block->variablesAtTail.numberOfArguments() == m_graph.block(0)->variablesAtHead.numberOfArguments());
}
#endif

m_graph.m_tmps = m_numTmps;
m_graph.m_localVars = m_numLocals;
m_graph.m_parameterSlots = m_parameterSlots;

return true;
}

void parse(Graph& graph)
bool parse(Graph& graph)
{
ByteCodeParser(graph).parse();
return ByteCodeParser(graph).parse();
}

} } // namespace JSC::DFG
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/dfg/DFGByteCodeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace JSC { namespace DFG {

class Graph;

void parse(Graph&);
bool parse(Graph&);

} } // namespace JSC::DFG

Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/dfg/DFGPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ Plan::CompilationPath Plan::compileInThreadImpl()

{
CompilerTimingScope timingScope("DFG", "bytecode parser");
parse(dfg);
if (!parse(dfg))
return CancelPath;
}

bool changed = false;
Expand Down

0 comments on commit b217c0b

Please sign in to comment.