8153852: [jittester] move TypeUtil to utils package
authorppunegov
Wed, 13 Apr 2016 18:56:51 +0300
changeset 38039 7be60c99abcf
parent 38038 5dd389a7d673
child 38040 4dc4b97c2bf1
8153852: [jittester] move TypeUtil to utils package Summary: rewrite TypeUtil and move to utils package Reviewed-by: kvn
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TypeUtil.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/AssignmentOperatorImplFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryArithmeticOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryBitwiseOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryShiftOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BitwiseInversionOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BlockFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundArithmeticAssignmentOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundBitwiseAssignmentOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundShiftAssignmentOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CounterInitializerFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/SwitchFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TernaryOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TryCatchBlockFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/UnaryPlusMinusOperatorFactory.java
hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/utils/TypeUtil.java
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/TypeUtil.java	Wed Apr 13 18:31:43 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.test.lib.jittester;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-
-public class TypeUtil {
-
-    public static Collection<Type> getImplicitlyCastable(Collection<Type> types, Type type) {
-        ArrayList<Type> result = new ArrayList<>(types);
-        Iterator<Type> iterator = result.iterator();
-        while (iterator.hasNext()) {
-            if (!iterator.next().canImplicitlyCastTo(type)) {
-                iterator.remove();
-            }
-        }
-        return result;
-    }
-
-    public static Collection<Type> getExplicitlyCastable(Collection<Type> types, Type type) {
-        ArrayList<Type> result = new ArrayList<>(types);
-        Iterator<Type> iterator = result.iterator();
-        while (iterator.hasNext()) {
-            if (!iterator.next().canExplicitlyCastTo(type)) {
-                iterator.remove();
-            }
-        }
-        return result;
-    }
-
-    public static List<Type> getMoreCapatiousThan(Collection<Type> types, BuiltInType type) {
-        ArrayList<Type> result = new ArrayList<>();
-        Iterator<Type> iterator = types.iterator();
-        while (iterator.hasNext()) {
-            try {
-                BuiltInType builtInType = (BuiltInType) iterator.next();
-                if (builtInType.isMoreCapaciousThan(type)) {
-                    result.add(builtInType);
-                }
-            } catch (Exception e) {
-            }
-        }
-        return result;
-    }
-
-    public static List<Type> getLessCapatiousOrEqualThan(Collection<Type> types, BuiltInType type) {
-        ArrayList<Type> result = new ArrayList<>();
-        Iterator<Type> iterator = types.iterator();
-        while (iterator.hasNext()) {
-            try {
-                BuiltInType builtInType = (BuiltInType) iterator.next();
-                if (!builtInType.isMoreCapaciousThan(type) || builtInType.equals(type)) {
-                    result.add(builtInType);
-                }
-            } catch (Exception e) {
-            }
-        }
-        return result;
-    }
-}
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/AssignmentOperatorImplFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/AssignmentOperatorImplFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -31,7 +31,7 @@
 import jdk.test.lib.jittester.Rule;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.VariableBase;
 import jdk.test.lib.jittester.VariableInfo;
 import jdk.test.lib.jittester.types.TypeKlass;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryArithmeticOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryArithmeticOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -29,7 +29,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeInt;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.utils.PseudoRandom;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryBitwiseOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryBitwiseOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -28,7 +28,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeBoolean;
 import jdk.test.lib.jittester.types.TypeInt;
 import jdk.test.lib.jittester.types.TypeKlass;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryShiftOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BinaryShiftOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -28,11 +28,11 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
 import jdk.test.lib.jittester.types.TypeInt;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.types.TypeLong;
 import jdk.test.lib.jittester.utils.PseudoRandom;
+import jdk.test.lib.jittester.utils.TypeUtil;
 
 class BinaryShiftOperatorFactory extends BinaryOperatorFactory {
     BinaryShiftOperatorFactory(OperatorKind opKind, long complexityLimit, int operatorLimit,
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BitwiseInversionOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BitwiseInversionOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -28,7 +28,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.UnaryOperator;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.types.TypeInt;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BlockFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/BlockFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -33,7 +33,7 @@
 import jdk.test.lib.jittester.SymbolTable;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.loops.DoWhile;
 import jdk.test.lib.jittester.loops.For;
 import jdk.test.lib.jittester.loops.While;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundArithmeticAssignmentOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundArithmeticAssignmentOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -30,7 +30,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeBoolean;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.utils.PseudoRandom;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundBitwiseAssignmentOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundBitwiseAssignmentOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -30,7 +30,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.utils.PseudoRandom;
 
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundShiftAssignmentOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CompoundShiftAssignmentOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -30,7 +30,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.types.TypeBoolean;
 import jdk.test.lib.jittester.utils.PseudoRandom;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CounterInitializerFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/CounterInitializerFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -30,7 +30,7 @@
 import jdk.test.lib.jittester.SymbolTable;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.VariableInfo;
 import jdk.test.lib.jittester.loops.CounterInitializer;
 import jdk.test.lib.jittester.types.TypeKlass;
@@ -48,7 +48,7 @@
 
     @Override
     protected IRNode sproduce() throws ProductionFailedException {
-        List<Type> types = TypeUtil.getMoreCapatiousThan(TypeList.getBuiltIn(), new TypeInt());
+        List<Type> types = TypeUtil.getMoreCapaciousThan(TypeList.getBuiltIn(), new TypeInt());
         types.add(new TypeInt());
         final Type selectedType = PseudoRandom.randomElement(types);
         IRNode init = new LiteralInitializer(counterValue, selectedType);
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/SwitchFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/SwitchFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -34,7 +34,7 @@
 import jdk.test.lib.jittester.Rule;
 import jdk.test.lib.jittester.Switch;
 import jdk.test.lib.jittester.Type;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.types.TypeByte;
 import jdk.test.lib.jittester.types.TypeChar;
@@ -63,7 +63,7 @@
     @Override
     protected IRNode sproduce() throws ProductionFailedException {
         if (statementLimit > 0 && complexityLimit > 0) {
-            ArrayList<Type> switchTypes = new ArrayList<>();
+            List<Type> switchTypes = new ArrayList<>();
             switchTypes.add(new TypeChar());
             switchTypes.add(new TypeByte());
             switchTypes.add(new TypeShort());
@@ -78,8 +78,8 @@
                     .setCanHaveReturn(canHaveReturn);
             MAIN_LOOP:
             for (Type type : switchTypes) {
-                ArrayList<IRNode> caseConsts = new ArrayList<>();
-                ArrayList<IRNode> caseBlocks = new ArrayList<>();
+                List<IRNode> caseConsts = new ArrayList<>();
+                List<IRNode> caseBlocks = new ArrayList<>();
                 try {
                     int accumulatedStatements = 0;
                     int currentStatementsLimit = 0;
@@ -94,10 +94,10 @@
                             .getLimitedExpressionFactory()
                             .produce();
                     accumulatedComplexity += currentComplexityLimit;
-                    ArrayList<Type> caseTypes = new ArrayList<>();
+                    List<Type> caseTypes = new ArrayList<>();
                     caseTypes.add(new TypeByte());
                     caseTypes.add(new TypeChar());
-                    caseTypes = new ArrayList<>(TypeUtil.getLessCapatiousOrEqualThan(caseTypes,
+                    caseTypes = new ArrayList<>(TypeUtil.getLessCapaciousOrEqualThan(caseTypes,
                             (BuiltInType) type));
                     if (PseudoRandom.randomBoolean()) { // "default"
                         currentStatementsLimit = (int) (PseudoRandom.random()
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TernaryOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TernaryOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -30,7 +30,7 @@
 import jdk.test.lib.jittester.TernaryOperator;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.types.TypeBoolean;
 import jdk.test.lib.jittester.utils.PseudoRandom;
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TryCatchBlockFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/TryCatchBlockFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -31,7 +31,7 @@
 import jdk.test.lib.jittester.TryCatchBlock;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.types.TypeKlass;
 import jdk.test.lib.jittester.utils.PseudoRandom;
 
--- a/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/UnaryPlusMinusOperatorFactory.java	Wed Apr 13 18:31:43 2016 +0300
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/UnaryPlusMinusOperatorFactory.java	Wed Apr 13 18:56:51 2016 +0300
@@ -29,7 +29,7 @@
 import jdk.test.lib.jittester.ProductionFailedException;
 import jdk.test.lib.jittester.Type;
 import jdk.test.lib.jittester.TypeList;
-import jdk.test.lib.jittester.TypeUtil;
+import jdk.test.lib.jittester.utils.TypeUtil;
 import jdk.test.lib.jittester.UnaryOperator;
 import jdk.test.lib.jittester.types.TypeBoolean;
 import jdk.test.lib.jittester.types.TypeInt;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary/jittester/src/jdk/test/lib/jittester/utils/TypeUtil.java	Wed Apr 13 18:56:51 2016 +0300
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.test.lib.jittester.utils;
+
+import jdk.test.lib.jittester.BuiltInType;
+import jdk.test.lib.jittester.Type;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Utility functions for type system
+ */
+public class TypeUtil {
+    /**
+     * Gets a list of implicitly castable types to a given one from the collection of types
+     *
+     * @param types a collection to get types from
+     * @param type  a target type which result type could be implicitly cast to
+     * @return      a result collection of types that match given conditions
+     */
+    public static Collection<Type> getImplicitlyCastable(Collection<Type> types, Type type) {
+        return types.stream()
+                .filter(t -> t.canImplicitlyCastTo(type))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Gets a list of explicitly castable types to a given one from the collection of types
+     *
+     * @param types a collection to get types from
+     * @param type  a target type which result type could be explicitly cast to
+     * @return      a result collection of types that match given conditions
+     */
+    public static Collection<Type> getExplicitlyCastable(Collection<Type> types, Type type) {
+        return types.stream()
+                .filter(t -> t.canExplicitlyCastTo(type))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Gets a list of more capacious types than a given one from the collection of types
+     *
+     * @param types a collection to get types from
+     * @param type  a type to filter given types by capacity
+     * @return      a result collection of types that match given conditions
+     */
+    public static List<Type> getMoreCapaciousThan(Collection<Type> types, BuiltInType type) {
+        return types.stream()
+                .filter(t -> ((BuiltInType) t).isMoreCapaciousThan(type))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Gets a list of less or equal capacious types than a given one from the collection of types
+     *
+     * @param types a collection to get types from
+     * @param type  a type to filter given types by capacity
+     * @return      a result collection of types that match given conditions
+     */
+    public static List<Type> getLessCapaciousOrEqualThan(Collection<Type> types, BuiltInType type) {
+        return types.stream()
+                .filter(t -> !((BuiltInType) t).isMoreCapaciousThan(type) || t.equals(type))
+                .collect(Collectors.toList());
+    }
+}