Skip to content

Commit cd506b1

Browse files
committed
[JSC] Object allocation sinking should escape allocations without recursion
https://bugs.webkit.org/show_bug.cgi?id=328024 Reviewed by Yusuke Suzuki. LocalHeap::escapeAllocation called itself for each field of the escaping allocation, so the recursion was as deep as the chain of allocations. A function that creates a few thousand nested objects overflowed the stack of the thread compiling it. This patch uses a worklist instead. Test: JSTests/stress/allocation-sinking-escape-long-chain-of-allocations.js * JSTests/stress/allocation-sinking-escape-long-chain-of-allocations.js: Added. (runNearStackLimit.t): (runNearStackLimit): (let.object.runNearStackLimit): * Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp: Canonical link: https://commits.webkit.org/324187@main
1 parent 9f224fe commit cd506b1

2 files changed

Lines changed: 47 additions & 9 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ skip if $buildType == "debug" or not $jitTests
2+
//@ runFTLNoCJIT("--jitPolicyScale=0.001", "--maxDFGNodesInBasicBlockForPreciseAnalysis=1000", "--maxPerThreadStackUsage=1073741824")
3+
4+
function runNearStackLimit(f) {
5+
function t() {
6+
try {
7+
return t();
8+
} catch (e) {
9+
return f();
10+
}
11+
}
12+
return t();
13+
}
14+
15+
const length = 1200;
16+
const test = new Function("value", `
17+
let object = { next: value };
18+
${"object = { next: object };".repeat(length - 1)}
19+
return object;
20+
`);
21+
noInline(test);
22+
23+
let object = runNearStackLimit(() => {
24+
let result;
25+
for (let i = 0; i < testLoopCount; i++)
26+
result = test(i);
27+
return result;
28+
});
29+
30+
for (let i = 0; i < length; i++)
31+
object = object.next;
32+
if (object !== testLoopCount - 1)
33+
throw new Error(object);

‎Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,18 +735,23 @@ class LocalHeap {
735735

736736
void escapeAllocation(Node* identifier)
737737
{
738-
Allocation& allocation = getAllocation(identifier);
739-
if (allocation.isEscapedAllocation())
740-
return;
738+
Vector<Node*, 16> worklist;
739+
worklist.append(identifier);
741740

742-
Allocation unescaped = WTF::move(allocation);
743-
allocation = Allocation(unescaped.identifier(), Allocation::Kind::Escaped);
741+
while (!worklist.isEmpty()) {
742+
Allocation& allocation = getAllocation(worklist.takeLast());
743+
if (allocation.isEscapedAllocation())
744+
continue;
744745

745-
for (const auto& entry : unescaped.fields())
746-
escapeAllocation(entry.value);
746+
Allocation unescaped = WTF::move(allocation);
747+
allocation = Allocation(unescaped.identifier(), Allocation::Kind::Escaped);
747748

748-
if (m_wantEscapees)
749-
m_escapees.add(unescaped.identifier(), WTF::move(unescaped));
749+
for (const auto& entry : unescaped.fields())
750+
worklist.append(entry.value);
751+
752+
if (m_wantEscapees)
753+
m_escapees.add(unescaped.identifier(), WTF::move(unescaped));
754+
}
750755
}
751756

752757
void prune()

0 commit comments

Comments
 (0)