This commit is contained in:
Dmitrij Pochepko 2016-06-23 15:41:33 +00:00
commit ac81dcb779
5 changed files with 66 additions and 38 deletions

View File

@ -74,11 +74,16 @@ public class IsMatureTest {
}
methodData = WB.getMethodData(method);
isMature = CompilerToVMHelper.isMature(methodData);
Asserts.assertNE(methodData, 0L,
"Multiple times invoked method should have method data");
/* a method is not mature for -Xcomp and -Tiered,
see NonTieredCompPolicy::is_mature */
Asserts.assertEQ(isMature, !(IS_XCOMP && !TIERED),
"Unexpected isMature state for multiple times invoked method");
int compLevel = WB.getMethodCompilationLevel(method);
// methodData doesn't necessarily exist for interpreter and compilation level 1
if (compLevel != CompilerWhiteBoxTest.COMP_LEVEL_NONE
&& compLevel != CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE) {
Asserts.assertNE(methodData, 0L,
"Multiple times invoked method should have method data");
/* a method is not mature in Xcomp mode with tiered compilation disabled,
see NonTieredCompPolicy::is_mature */
Asserts.assertEQ(isMature, !(IS_XCOMP && !TIERED),
"Unexpected isMature state for multiple times invoked method");
}
}
}

View File

@ -78,7 +78,7 @@ class ByteCodeGenerator extends TestsGenerator {
} catch (Throwable t) {
Path errFile = generatorDir.resolve(mainClassName + ".err");
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(errFile,
StandardOpenOption.CREATE_NEW))) {
StandardOpenOption.CREATE, StandardOpenOption.WRITE))) {
t.printStackTrace(pw);
} catch (IOException e) {
t.printStackTrace();

View File

@ -198,6 +198,31 @@ public abstract class IRNode {
return result;
}
public static long getModifiableNodesCount(List<IRNode> nodes) {
return nodes.stream()
.map(IRNode::getStackableLeaves)
.mapToInt(List::size)
.filter(i -> i > 0)
.count();
}
public static boolean tryToReduceNodesDepth(List<IRNode> nodes, int maxDepth) {
boolean allSucceed = true;
for (IRNode child : nodes) {
for (IRNode leaf : child.getDeviantBlocks(Math.max(child.countDepth(), maxDepth + 1))) {
if (child.countDepth() > maxDepth) {
// doesn't remove control deviation block. Just some parts.
leaf.removeSelf();
boolean successfull = child.countDepth() > maxDepth;
allSucceed &= successfull;
} else {
break;
}
}
}
return allSucceed;
}
// TODO: add field instead this function
public boolean isCFDeviation() {
return this instanceof If || this instanceof Switch

View File

@ -102,11 +102,16 @@ class ClassDefinitionBlockFactory extends Factory<ClassDefinitionBlock> {
addMoreChildren(childs, content, minDepth);
}
private void addMoreChildren(List<IRNode> childs, Collection<IRNode> content, int minDepth)
throws ProductionFailedException {
while (!childs.isEmpty() && IRNode.countDepth(content) < minDepth) {
PseudoRandom.shuffle(childs);
IRNode randomChild = childs.get(0);
private void addMoreChildren(List<IRNode> children, Collection<IRNode> content, int minDepth)
throws ProductionFailedException {
/* 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(content) < minDepth) {
PseudoRandom.shuffle(children);
IRNode randomChild = children.get(0);
List<IRNode> leaves = randomChild.getStackableLeaves();
if (!leaves.isEmpty()) {
Block randomLeaf = (Block) leaves.get(PseudoRandom.randomNotNegative(leaves.size()));
@ -131,18 +136,11 @@ class ClassDefinitionBlockFactory extends Factory<ClassDefinitionBlock> {
private void ensureMaxDepth(Collection<IRNode> content) {
int maxDepth = ProductionParams.maxCfgDepth.value();
List<IRNode> childs = content.stream()
List<IRNode> childrenClasses = content.stream()
.filter(c -> c instanceof Klass && c.countDepth() > maxDepth)
.collect(Collectors.toList());
for (IRNode ch : childs) {
List<IRNode> leaves;
do {
long depth = Math.max(ch.countDepth(), maxDepth + 1);
leaves = ch.getDeviantBlocks(depth);
if(leaves.size() > 0) {
leaves.get(0).removeSelf();
}
} while (!leaves.isEmpty() && ch.countDepth() > maxDepth);
}
/* now attempt to reduce depth by removing optional parts of control deviation
blocks in case IRTree has oversized depth */
IRNode.tryToReduceNodesDepth(childrenClasses, maxDepth);
}
}

View File

@ -112,19 +112,14 @@ class MainKlassFactory extends Factory<MainKlass> {
functionDefinitions, testFunction, printVariables);
}
private void ensureMaxDepth(List<IRNode> childs) {
private void ensureMaxDepth(List<IRNode> children) {
int maxDepth = ProductionParams.maxCfgDepth.value();
List<IRNode> filtered = childs.stream()
.filter(c -> c.isCFDeviation() && c.countDepth() > maxDepth)
.collect(Collectors.toList());
for (IRNode child : filtered) {
List<IRNode> 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<IRNode> 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<IRNode> childs, IRNodeBuilder builder)
@ -134,10 +129,15 @@ class MainKlassFactory extends Factory<MainKlass> {
addMoreChildren(filtered, minDepth, builder);
}
private void addMoreChildren(List<IRNode> childs, int minDepth, IRNodeBuilder builder)
private void addMoreChildren(List<IRNode> 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<IRNode> leaves = randomChild.getStackableLeaves();
if (!leaves.isEmpty()) {
Block randomLeaf = (Block) leaves.get(PseudoRandom.randomNotNegative(leaves.size()));