21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.loops; 25 26 import java.util.List; 27 import jdk.test.lib.jittester.Block; 28 import jdk.test.lib.jittester.IRNode; 29 import jdk.test.lib.jittester.visitors.Visitor; 30 31 public class While extends IRNode { 32 33 public Loop getLoop() { 34 return loop; 35 } 36 public enum WhilePart { 37 HEADER, 38 BODY1, 39 BODY2, 40 BODY3, 41 }; 42 43 private final Loop loop; 44 // int counter = x; 45 // header; // [subblock] 46 // while (condition) { 47 // body1; // [subblock with breaks] 48 // mutate(counter); 49 // body2; // [subblock with breaks and continues] 50 // body3; // [subblock with breaks] 51 // } 52 private final long thisLoopIterLimit; 53 54 public While(int level, Loop loop, long thisLoopIterLimit, IRNode header, 55 IRNode body1, IRNode body2, IRNode body3) { 56 this.loop = loop; 57 this.level = level; 58 this.thisLoopIterLimit = thisLoopIterLimit; 59 resizeUpChildren(WhilePart.values().length); 60 getChildren().set(WhilePart.HEADER.ordinal(), header); 61 getChildren().set(WhilePart.BODY1.ordinal(), body1); 62 getChildren().set(WhilePart.BODY2.ordinal(), body2); 63 getChildren().set(WhilePart.BODY3.ordinal(), body3); 64 } 65 66 @Override 67 public long complexity() { 68 IRNode header = getChildren().get(WhilePart.HEADER.ordinal()); 69 IRNode body1 = getChildren().get(WhilePart.BODY1.ordinal()); 70 IRNode body2 = getChildren().get(WhilePart.BODY2.ordinal()); 71 IRNode body3 = getChildren().get(WhilePart.BODY3.ordinal()); 72 return loop.initialization.complexity() 73 + header.complexity() 74 + thisLoopIterLimit * (loop.condition.complexity() 75 + body1.complexity() 76 + loop.manipulator.complexity() 77 + body2.complexity() 78 + body3.complexity()); 79 } 80 81 @Override 82 public long countDepth() { 83 return Long.max(level, super.countDepth()); 84 } 85 86 @Override 87 public boolean removeSelf() { 88 IRNode header = getChildren().get(WhilePart.HEADER.ordinal()); 89 List<IRNode> siblings = getParent().getChildren(); 90 int index = siblings.indexOf(this); 91 if (header instanceof Block) { 92 siblings.remove(this); 93 siblings.addAll(index, header.getChildren()); 94 } else { 95 siblings.set(index, header); 96 } 97 siblings.add(index + header.getChildren().size(), loop.initialization); 98 return true; 99 } 100 101 @Override 102 public<T> T accept(Visitor<T> v) { 103 return v.visit(this); 104 } 105 } | 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.loops; 25 26 import java.util.List; 27 import jdk.test.lib.jittester.Block; 28 import jdk.test.lib.jittester.IRNode; 29 import jdk.test.lib.jittester.visitors.Visitor; 30 31 public class While extends IRNode { 32 33 public Loop getLoop() { 34 return loop; 35 } 36 public enum WhilePart { 37 HEADER, 38 BODY1, 39 BODY2, 40 BODY3, 41 } 42 43 private final Loop loop; 44 // int counter = x; 45 // header; // [subblock] 46 // while (condition) { 47 // body1; // [subblock with breaks] 48 // mutate(counter); 49 // body2; // [subblock with breaks and continues] 50 // body3; // [subblock with breaks] 51 // } 52 private final long thisLoopIterLimit; 53 54 public While(int level, Loop loop, long thisLoopIterLimit, Block header, 55 Block body1, Block body2, Block body3) { 56 super(body1.getResultType()); 57 this.loop = loop; 58 this.level = level; 59 this.thisLoopIterLimit = thisLoopIterLimit; 60 resizeUpChildren(WhilePart.values().length); 61 getChildren().set(WhilePart.HEADER.ordinal(), header); 62 getChildren().set(WhilePart.BODY1.ordinal(), body1); 63 getChildren().set(WhilePart.BODY2.ordinal(), body2); 64 getChildren().set(WhilePart.BODY3.ordinal(), body3); 65 } 66 67 @Override 68 public long complexity() { 69 IRNode header = getChildren().get(WhilePart.HEADER.ordinal()); 70 IRNode body1 = getChildren().get(WhilePart.BODY1.ordinal()); 71 IRNode body2 = getChildren().get(WhilePart.BODY2.ordinal()); 72 IRNode body3 = getChildren().get(WhilePart.BODY3.ordinal()); 73 return loop.initialization.complexity() 74 + header.complexity() 75 + thisLoopIterLimit * (loop.condition.complexity() 76 + body1.complexity() 77 + loop.manipulator.complexity() 78 + body2.complexity() 79 + body3.complexity()); 80 } 81 82 @Override 83 public long countDepth() { 84 return Long.max(level, super.countDepth()); 85 } 86 87 @Override 88 public boolean removeSelf() { 89 IRNode header = getChildren().get(WhilePart.HEADER.ordinal()); 90 List<IRNode> siblings = getParent().getChildren(); 91 int index = siblings.indexOf(this); 92 siblings.set(index++, loop.initialization); 93 if (header instanceof Block) { 94 siblings.addAll(index, header.getChildren()); 95 } else { 96 siblings.add(index, header); 97 } 98 return true; 99 } 100 101 @Override 102 public<T> T accept(Visitor<T> v) { 103 return v.visit(this); 104 } 105 } |