< prev index next >

test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/ForFactory.java

Print this page

        

@@ -21,34 +21,36 @@
  * questions.
  */
 
 package jdk.test.lib.jittester.factories;
 
+import jdk.test.lib.jittester.Block;
 import jdk.test.lib.jittester.IRNode;
-import jdk.test.lib.jittester.Initialization;
 import jdk.test.lib.jittester.Literal;
 import jdk.test.lib.jittester.LocalVariable;
 import jdk.test.lib.jittester.Nothing;
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Rule;
+import jdk.test.lib.jittester.Statement;
 import jdk.test.lib.jittester.SymbolTable;
 import jdk.test.lib.jittester.Type;
+import jdk.test.lib.jittester.TypeList;
 import jdk.test.lib.jittester.loops.For;
 import jdk.test.lib.jittester.loops.Loop;
 import jdk.test.lib.jittester.types.TypeKlass;
-import jdk.test.lib.jittester.types.TypeInt;
 import jdk.test.lib.jittester.utils.PseudoRandom;
 
-class ForFactory extends SafeFactory {
+import java.util.LinkedList;
+
+class ForFactory extends SafeFactory<For> {
     private final Loop loop;
     private final long complexityLimit;
     private final int statementLimit;
     private final int operatorLimit;
     private final TypeKlass ownerClass;
     private final Type returnType;
     private final int level;
-    private long thisLoopIterLimit = 0;
     private final boolean canHaveReturn;
 
     ForFactory(TypeKlass ownerClass, Type returnType, long complexityLimit, int statementLimit,
             int operatorLimit, int level, boolean canHaveReturn) {
         this.ownerClass = ownerClass;

@@ -60,11 +62,12 @@
         loop = new Loop();
         this.canHaveReturn = canHaveReturn;
     }
 
     @Override
-    protected IRNode sproduce() throws ProductionFailedException {
+    protected For sproduce() throws ProductionFailedException {
+        Block emptyBlock = new Block(ownerClass, returnType, new LinkedList<>(), level - 1);
         if (statementLimit <= 0 || complexityLimit <= 0) {
             throw new ProductionFailedException();
         }
         IRNodeBuilder builder = new IRNodeBuilder()
                 .setOwnerKlass(ownerClass)

@@ -79,11 +82,11 @@
         complexity -= headerComplLimit;
         int headerStatementLimit = PseudoRandom.randomNotZero((int) (statementLimit / 4.0));
         long statement1ComplLimit = (long) (0.005 * complexity * PseudoRandom.random());
         complexity -= statement1ComplLimit;
         // Loop body parameters
-        thisLoopIterLimit = (long) (0.0001 * complexity * PseudoRandom.random());
+        long thisLoopIterLimit = (long) (0.0001 * complexity * PseudoRandom.random());
         if (thisLoopIterLimit > Integer.MAX_VALUE || thisLoopIterLimit == 0) {
             throw new ProductionFailedException();
         }
         complexity = thisLoopIterLimit > 0 ? complexity / thisLoopIterLimit : 0;
         long condComplLimit = (long) (complexity * PseudoRandom.random());

@@ -98,11 +101,11 @@
         int body2StatementLimit = PseudoRandom.randomNotZero((int) (statementLimit / 4.0));
         long body3ComplLimit = complexity;
         int body3StatementLimit = PseudoRandom.randomNotZero((int) (statementLimit / 4.0));
         // Production
         loop.initialization = builder.getCounterInitializerFactory(0).produce();
-        IRNode header;
+        Block header;
         try {
             header = builder.setComplexityLimit(headerComplLimit)
                     .setStatementLimit(headerStatementLimit)
                     .setLevel(level - 1)
                     .setSubBlock(true)

@@ -110,16 +113,16 @@
                     .setCanHaveContinues(false)
                     .setCanHaveReturn(false)
                     .getBlockFactory()
                     .produce();
         } catch (ProductionFailedException e) {
-            header = new Nothing();
+            header = emptyBlock;
         }
         SymbolTable.push();
         IRNode statement1;
         try {
-            Rule rule = new Rule("statement1");
+            Rule<IRNode> rule = new Rule<>("statement1");
             builder.setComplexityLimit(statement1ComplLimit);
             rule.add("assignment", builder.getAssignmentOperatorFactory());
             rule.add("function", builder.getFunctionFactory(), 0.1);
             rule.add("initialization", builder.setIsConstant(false)
                     .setIsStatic(false)

@@ -127,12 +130,12 @@
                     .getVariableInitializationFactory());
             statement1 = rule.produce();
         } catch (ProductionFailedException e) {
             statement1 = new Nothing();
         }
-        LocalVariable counter = new LocalVariable(((Initialization) loop.initialization).get());
-        Literal limiter = new Literal(Integer.valueOf((int) thisLoopIterLimit), new TypeInt());
+        LocalVariable counter = new LocalVariable(loop.initialization.getVariableInfo());
+        Literal limiter = new Literal((int) thisLoopIterLimit, TypeList.INT);
         loop.condition = builder.setComplexityLimit(condComplLimit)
                 .setLocalVariable(counter)
                 .getLoopingConditionFactory(limiter)
                 .produce();
         IRNode statement2;

@@ -140,11 +143,11 @@
             statement2 =  builder.setComplexityLimit(statement2ComplLimit)
                     .getAssignmentOperatorFactory().produce();
         } catch (ProductionFailedException e) {
             statement2 = new Nothing();
         }
-        IRNode body1;
+        Block body1;
         try {
             body1 = builder.setComplexityLimit(body1ComplLimit)
                     .setStatementLimit(body1StatementLimit)
                     .setLevel(level)
                     .setSubBlock(true)

@@ -152,14 +155,14 @@
                     .setCanHaveContinues(false)
                     .setCanHaveReturn(false)
                     .getBlockFactory()
                     .produce();
         } catch (ProductionFailedException e) {
-            body1 = new Nothing();
+            body1 = emptyBlock;
         }
         loop.manipulator = builder.setLocalVariable(counter).getCounterManipulatorFactory().produce();
-        IRNode body2;
+        Block body2;
         try {
             body2 = builder.setComplexityLimit(body2ComplLimit)
                     .setStatementLimit(body2StatementLimit)
                     .setLevel(level)
                     .setSubBlock(true)

@@ -167,13 +170,13 @@
                     .setCanHaveContinues(true)
                     .setCanHaveReturn(false)
                     .getBlockFactory()
                     .produce();
         } catch (ProductionFailedException e) {
-            body2 = new Nothing();
+            body2 = emptyBlock;
         }
-        IRNode body3;
+        Block body3;
         try {
             body3 = builder.setComplexityLimit(body3ComplLimit)
                     .setStatementLimit(body3StatementLimit)
                     .setLevel(level)
                     .setSubBlock(true)

@@ -181,12 +184,15 @@
                     .setCanHaveContinues(false)
                     .setCanHaveReturn(canHaveReturn)
                     .getBlockFactory()
                     .produce();
         } catch (ProductionFailedException e) {
-            body3 = new Nothing();
+            body3 = emptyBlock;
         }
         SymbolTable.pop();
-        return new For(level, loop, thisLoopIterLimit, header, statement1, statement2, body1,
+        return new For(level, loop, thisLoopIterLimit, header,
+                new Statement(statement1, false),
+                new Statement(statement2, false),
+                body1,
                 body2, body3);
     }
 }
< prev index next >