6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.factories; 25 26 import jdk.test.lib.jittester.IRNode; 27 import jdk.test.lib.jittester.If; 28 import jdk.test.lib.jittester.ProductionFailedException; 29 import jdk.test.lib.jittester.Type; 30 import jdk.test.lib.jittester.types.TypeKlass; 31 import jdk.test.lib.jittester.types.TypeBoolean; 32 import jdk.test.lib.jittester.utils.PseudoRandom; 33 34 class IfFactory extends SafeFactory { 35 protected long complexityLimit; 36 protected int statementLimit; 37 protected int operatorLimit; 38 protected boolean canHaveBreaks; 39 protected boolean canHaveContinues; 40 protected boolean canHaveReturn; 41 protected final TypeKlass ownerClass; 42 protected final Type returnType; 43 protected final int level; 44 45 IfFactory(TypeKlass ownerClass, Type returnType, long complexityLimit, int statementLimit, 46 int operatorLimit, int level, boolean canHaveBreaks, boolean canHaveContinues, 47 boolean canHaveReturn) { 48 this.ownerClass = ownerClass; 49 this.returnType = returnType; 50 this.complexityLimit = complexityLimit; 51 this.statementLimit = statementLimit; 52 this.operatorLimit = operatorLimit; 53 this.level = level; 54 this.canHaveBreaks = canHaveBreaks; 55 this.canHaveContinues = canHaveContinues; 56 this.canHaveReturn = canHaveReturn; 57 } 58 59 @Override 60 public IRNode sproduce() throws ProductionFailedException { 61 // resizeUpChildren(If.IfPart.values().length); 62 if (statementLimit > 0 && complexityLimit > 0) { 63 long conditionComplLimit = (long) (0.01 * PseudoRandom.random() * (complexityLimit - 1)); 64 IRNodeBuilder builder = new IRNodeBuilder() 65 .setOwnerKlass(ownerClass) 66 .setOperatorLimit(operatorLimit); 67 IRNode condition = builder.setComplexityLimit(conditionComplLimit) 68 .setResultType(new TypeBoolean()) 69 .setExceptionSafe(false) 70 .setNoConsts(false) 71 .getLimitedExpressionFactory() 72 .produce(); 73 // setChild(If.IfPart.CONDITION.ordinal(), condition); 74 long remainder = complexityLimit - 1 - condition.complexity(); 75 long ifBlockComplLimit = (long) (PseudoRandom.random() * remainder); 76 long elseBlockComplLimit = remainder - ifBlockComplLimit; 77 int ifBlockLimit = (int) (PseudoRandom.random() * statementLimit); 78 int elseBlockLimit = statementLimit - ifBlockLimit; 79 If.IfPart controlDeviation; 80 if (ifBlockLimit > 0 && elseBlockLimit <= 0) { 81 controlDeviation = If.IfPart.THEN; 82 } else { 83 controlDeviation = PseudoRandom.randomBoolean() ? If.IfPart.THEN : If.IfPart.ELSE; 84 } 85 if (ifBlockLimit > 0 && ifBlockComplLimit > 0) { 86 IRNode thenBlock = null; 87 builder.setResultType(returnType) 88 .setLevel(level) 89 .setComplexityLimit(ifBlockComplLimit) 90 .setStatementLimit(ifBlockLimit); 91 if (controlDeviation == If.IfPart.THEN) { 92 thenBlock = builder.setSubBlock(false) 93 .setCanHaveBreaks(canHaveBreaks) 94 .setCanHaveContinues(canHaveContinues) 95 .setCanHaveReturn(canHaveReturn) 96 .getBlockFactory() 97 .produce(); 98 } else { 99 thenBlock = builder.setSubBlock(false) 100 .setCanHaveBreaks(false) 101 .setCanHaveContinues(false) 102 .setCanHaveReturn(false) 103 .getBlockFactory() 104 .produce(); 105 } 106 // setChild(If.IfPart.THEN.ordinal(), thenBlock); 107 IRNode elseBlock = null; 108 if (elseBlockLimit > 0 && elseBlockComplLimit > 0) { 109 builder.setComplexityLimit(elseBlockComplLimit) 110 .setStatementLimit(elseBlockLimit); 111 if (controlDeviation == If.IfPart.ELSE) { 112 elseBlock = builder.setSubBlock(false) 113 .setCanHaveBreaks(canHaveBreaks) 114 .setCanHaveContinues(canHaveContinues) 115 .setCanHaveReturn(canHaveReturn) 116 .getBlockFactory() 117 .produce(); 118 } else { 119 elseBlock = builder.setSubBlock(false) 120 .setCanHaveBreaks(false) 121 .setCanHaveContinues(false) 122 .setCanHaveReturn(false) 123 .getBlockFactory() 124 .produce(); 125 } 126 } 127 // setChild(If.IfPart.ELSE.ordinal(), elseBlock); | 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.factories; 25 26 import jdk.test.lib.jittester.Block; 27 import jdk.test.lib.jittester.IRNode; 28 import jdk.test.lib.jittester.If; 29 import jdk.test.lib.jittester.ProductionFailedException; 30 import jdk.test.lib.jittester.Type; 31 import jdk.test.lib.jittester.TypeList; 32 import jdk.test.lib.jittester.types.TypeKlass; 33 import jdk.test.lib.jittester.utils.PseudoRandom; 34 35 class IfFactory extends SafeFactory<If> { 36 protected final long complexityLimit; 37 protected final int statementLimit; 38 protected final int operatorLimit; 39 protected final boolean canHaveBreaks; 40 protected final boolean canHaveContinues; 41 protected final boolean canHaveReturn; 42 protected final TypeKlass ownerClass; 43 protected final Type returnType; 44 protected final int level; 45 46 IfFactory(TypeKlass ownerClass, Type returnType, long complexityLimit, int statementLimit, 47 int operatorLimit, int level, boolean canHaveBreaks, boolean canHaveContinues, 48 boolean canHaveReturn) { 49 this.ownerClass = ownerClass; 50 this.returnType = returnType; 51 this.complexityLimit = complexityLimit; 52 this.statementLimit = statementLimit; 53 this.operatorLimit = operatorLimit; 54 this.level = level; 55 this.canHaveBreaks = canHaveBreaks; 56 this.canHaveContinues = canHaveContinues; 57 this.canHaveReturn = canHaveReturn; 58 } 59 60 @Override 61 public If sproduce() throws ProductionFailedException { 62 // resizeUpChildren(If.IfPart.values().length); 63 if (statementLimit > 0 && complexityLimit > 0) { 64 long conditionComplLimit = (long) (0.01 * PseudoRandom.random() * (complexityLimit - 1)); 65 IRNodeBuilder builder = new IRNodeBuilder() 66 .setOwnerKlass(ownerClass) 67 .setOperatorLimit(operatorLimit); 68 IRNode condition = builder.setComplexityLimit(conditionComplLimit) 69 .setResultType(TypeList.BOOLEAN) 70 .setExceptionSafe(false) 71 .setNoConsts(false) 72 .getLimitedExpressionFactory() 73 .produce(); 74 // setChild(If.IfPart.CONDITION.ordinal(), condition); 75 long remainder = complexityLimit - 1 - condition.complexity(); 76 long ifBlockComplLimit = (long) (PseudoRandom.random() * remainder); 77 long elseBlockComplLimit = remainder - ifBlockComplLimit; 78 int ifBlockLimit = (int) (PseudoRandom.random() * statementLimit); 79 int elseBlockLimit = statementLimit - ifBlockLimit; 80 If.IfPart controlDeviation; 81 if (ifBlockLimit > 0 && elseBlockLimit <= 0) { 82 controlDeviation = If.IfPart.THEN; 83 } else { 84 controlDeviation = PseudoRandom.randomBoolean() ? If.IfPart.THEN : If.IfPart.ELSE; 85 } 86 if (ifBlockLimit > 0 && ifBlockComplLimit > 0) { 87 Block thenBlock; 88 builder.setResultType(returnType) 89 .setLevel(level) 90 .setComplexityLimit(ifBlockComplLimit) 91 .setStatementLimit(ifBlockLimit); 92 if (controlDeviation == If.IfPart.THEN) { 93 thenBlock = builder.setSubBlock(false) 94 .setCanHaveBreaks(canHaveBreaks) 95 .setCanHaveContinues(canHaveContinues) 96 .setCanHaveReturn(canHaveReturn) 97 .getBlockFactory() 98 .produce(); 99 } else { 100 thenBlock = builder.setSubBlock(false) 101 .setCanHaveBreaks(false) 102 .setCanHaveContinues(false) 103 .setCanHaveReturn(false) 104 .getBlockFactory() 105 .produce(); 106 } 107 // setChild(If.IfPart.THEN.ordinal(), thenBlock); 108 Block elseBlock = null; 109 if (elseBlockLimit > 0 && elseBlockComplLimit > 0) { 110 builder.setComplexityLimit(elseBlockComplLimit) 111 .setStatementLimit(elseBlockLimit); 112 if (controlDeviation == If.IfPart.ELSE) { 113 elseBlock = builder.setSubBlock(false) 114 .setCanHaveBreaks(canHaveBreaks) 115 .setCanHaveContinues(canHaveContinues) 116 .setCanHaveReturn(canHaveReturn) 117 .getBlockFactory() 118 .produce(); 119 } else { 120 elseBlock = builder.setSubBlock(false) 121 .setCanHaveBreaks(false) 122 .setCanHaveContinues(false) 123 .setCanHaveReturn(false) 124 .getBlockFactory() 125 .produce(); 126 } 127 } 128 // setChild(If.IfPart.ELSE.ordinal(), elseBlock); |