Skip to content

Commit

Permalink
v8: fix stack overflow in recursive method
Browse files Browse the repository at this point in the history
HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock()
used to self-recurse before this commit, causing stack overflows on
systems with small stack sizes.  Make it non-recursive by storing
intermediate results in a heap-allocated list.

Fixes: #11991
Refs: #12460

Backport-PR-URL: #14574
Backport-Reviewed-By: Anna Henningsen <[email protected]>
Backport-Reviewed-By: Refael Ackermann <[email protected]>

PR-URL: #14004
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
bnoordhuis authored and addaleax committed Aug 2, 2017
1 parent 160e2f0 commit 357873d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions deps/v8/src/crankshaft/hydrogen-gvn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "src/crankshaft/hydrogen-gvn.h"

#include "src/crankshaft/hydrogen.h"
#include "src/list.h"
#include "src/list-inl.h"
#include "src/objects-inl.h"
#include "src/v8.h"

Expand Down Expand Up @@ -651,19 +653,23 @@ SideEffects
HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock(
HBasicBlock* dominator, HBasicBlock* dominated) {
SideEffects side_effects;
for (int i = 0; i < dominated->predecessors()->length(); ++i) {
HBasicBlock* block = dominated->predecessors()->at(i);
if (dominator->block_id() < block->block_id() &&
block->block_id() < dominated->block_id() &&
!visited_on_paths_.Contains(block->block_id())) {
visited_on_paths_.Add(block->block_id());
side_effects.Add(block_side_effects_[block->block_id()]);
if (block->IsLoopHeader()) {
side_effects.Add(loop_side_effects_[block->block_id()]);
List<HBasicBlock*> blocks;
for (;;) {
for (int i = 0; i < dominated->predecessors()->length(); ++i) {
HBasicBlock* block = dominated->predecessors()->at(i);
if (dominator->block_id() < block->block_id() &&
block->block_id() < dominated->block_id() &&
!visited_on_paths_.Contains(block->block_id())) {
visited_on_paths_.Add(block->block_id());
side_effects.Add(block_side_effects_[block->block_id()]);
if (block->IsLoopHeader()) {
side_effects.Add(loop_side_effects_[block->block_id()]);
}
blocks.Add(block);
}
side_effects.Add(CollectSideEffectsOnPathsToDominatedBlock(
dominator, block));
}
if (blocks.is_empty()) break;
dominated = blocks.RemoveLast();
}
return side_effects;
}
Expand Down

0 comments on commit 357873d

Please sign in to comment.