Browse Source

v8: fix stack overflow in recursive method

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: https://github.com/nodejs/node/issues/11991
PR-URL: https://github.com/nodejs/node/pull/12460
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
v6
Ben Noordhuis 8 years ago
parent
commit
30989d30db
  1. 10
      deps/v8/src/crankshaft/hydrogen-gvn.cc

10
deps/v8/src/crankshaft/hydrogen-gvn.cc

@ -5,6 +5,8 @@
#include "src/crankshaft/hydrogen-gvn.h" #include "src/crankshaft/hydrogen-gvn.h"
#include "src/crankshaft/hydrogen.h" #include "src/crankshaft/hydrogen.h"
#include "src/list.h"
#include "src/list-inl.h"
#include "src/v8.h" #include "src/v8.h"
namespace v8 { namespace v8 {
@ -650,6 +652,8 @@ SideEffects
HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock( HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock(
HBasicBlock* dominator, HBasicBlock* dominated) { HBasicBlock* dominator, HBasicBlock* dominated) {
SideEffects side_effects; SideEffects side_effects;
List<HBasicBlock*> blocks;
for (;;) {
for (int i = 0; i < dominated->predecessors()->length(); ++i) { for (int i = 0; i < dominated->predecessors()->length(); ++i) {
HBasicBlock* block = dominated->predecessors()->at(i); HBasicBlock* block = dominated->predecessors()->at(i);
if (dominator->block_id() < block->block_id() && if (dominator->block_id() < block->block_id() &&
@ -660,10 +664,12 @@ HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock(
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
side_effects.Add(loop_side_effects_[block->block_id()]); side_effects.Add(loop_side_effects_[block->block_id()]);
} }
side_effects.Add(CollectSideEffectsOnPathsToDominatedBlock( blocks.Add(block);
dominator, block));
} }
} }
if (blocks.is_empty()) break;
dominated = blocks.RemoveLast();
}
return side_effects; return side_effects;
} }

Loading…
Cancel
Save