--- old/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/MainKlassFactory.java 2016-06-20 20:25:17.220105659 +0300 +++ new/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/MainKlassFactory.java 2016-06-20 20:25:17.176105659 +0300 @@ -112,19 +112,14 @@ functionDefinitions, testFunction, printVariables); } - private void ensureMaxDepth(List childs) { + private void ensureMaxDepth(List children) { int maxDepth = ProductionParams.maxCfgDepth.value(); - List filtered = childs.stream() - .filter(c -> c.isCFDeviation() && c.countDepth() > maxDepth) - .collect(Collectors.toList()); - for (IRNode child : filtered) { - List leaves; - do { - long depth = Math.max(child.countDepth(), maxDepth + 1); - leaves = child.getDeviantBlocks(depth); - leaves.get(0).removeSelf(); - } while (!leaves.isEmpty() && child.countDepth() > maxDepth); - } + List filtered = children.stream() + .filter(c -> c.isCFDeviation() && c.countDepth() > maxDepth) + .collect(Collectors.toList()); + /* Now attempt to reduce depth by removing optional parts of control deviation + blocks in case IRTree has oversized depth */ + IRNode.tryToReduceNodesDepth(filtered, maxDepth); } private void ensureMinDepth(List childs, IRNodeBuilder builder) @@ -134,10 +129,15 @@ addMoreChildren(filtered, minDepth, builder); } - private void addMoreChildren(List childs, int minDepth, IRNodeBuilder builder) + private void addMoreChildren(List children, int minDepth, IRNodeBuilder builder) throws ProductionFailedException { - while (!childs.isEmpty() && IRNode.countDepth(childs) < minDepth) { - IRNode randomChild = childs.get(PseudoRandom.randomNotNegative(childs.size())); + /* check situation when no stackable leaves available in all children */ + if (IRNode.getModifiableNodesCount(children) == 0L) { + return; + } + /* now let's try to add children */ + while (!children.isEmpty() && IRNode.countDepth(children) < minDepth) { + IRNode randomChild = children.get(PseudoRandom.randomNotNegative(children.size())); List leaves = randomChild.getStackableLeaves(); if (!leaves.isEmpty()) { Block randomLeaf = (Block) leaves.get(PseudoRandom.randomNotNegative(leaves.size()));