< prev index next >

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/types/TypeKlass.java

Print this page
rev 53171 : 8158646: [jittester] generated tests may not compile by javac
Reviewed-by: duke


   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.types;
  25 
  26 import java.util.Collection;
  27 import java.util.HashSet;

  28 import java.util.TreeSet;
  29 import jdk.test.lib.jittester.ProductionParams;
  30 import jdk.test.lib.jittester.Symbol;
  31 import jdk.test.lib.jittester.SymbolTable;
  32 import jdk.test.lib.jittester.Type;
  33 import jdk.test.lib.jittester.TypeList;
  34 
  35 public class TypeKlass extends Type {
  36     private TypeKlass parentKlass;
  37     private final HashSet<String> parentsList;
  38     private final HashSet<String> childrenList;
  39     private final HashSet<Symbol> symbolsSet;
  40     private int flags;
  41 
  42     public static final int NONE = 0x00;
  43     public static final int FINAL = 0x01;
  44     public static final int INTERFACE = 0x02;
  45     public static final int ABSTRACT = 0x04;
  46 
  47 


 107     }
 108 
 109     public HashSet<String> getChildrenNames() {
 110         return childrenList;
 111     }
 112 
 113     @Override
 114     public boolean canCompareTo(Type t) {
 115         return false;
 116     }
 117 
 118     @Override
 119     public boolean canEquateTo(Type t) {
 120         return true;
 121     }
 122 
 123     public TreeSet<TypeKlass> getAllParents() {
 124         TreeSet<TypeKlass> result = new TreeSet<>();
 125         parentsList.stream()
 126                 .map(TypeList::find)
 127                 .filter(parentKlass -> parentKlass != null)
 128                 .map(parentKlass -> (TypeKlass) parentKlass)
 129                 .forEach(parentKlass -> {
 130                     result.add(parentKlass);
 131                     result.addAll(parentKlass.getAllParents());

 132         });
 133         return result;
 134     }
 135 
 136     public TreeSet<TypeKlass> getAllChildren() {
 137         TreeSet<TypeKlass> r = new TreeSet<>();
 138         childrenList.stream()
 139                 .map(TypeList::find)
 140                 .filter(childKlass -> childKlass != null)
 141                 .map(childKlass -> (TypeKlass) childKlass)
 142                 .forEach(childKlass -> {
 143                     r.add(childKlass);
 144                     r.addAll(childKlass.getAllChildren());

 145         });
 146         return r;
 147     }
 148 
 149     @Override
 150     public boolean canImplicitlyCastTo(Type t) {
 151         // We can implicitly cast to anything up the hierarchy and to self
 152         if (t instanceof TypeKlass) {
 153             return equals(t) || getAllParents().contains(t);
 154         }
 155         return false;
 156     }
 157 
 158     // If canExplicitlyCastTo() returns true in this case it doesn't mean that
 159     // it would really be successful. Since explicit casts are inherintly dynamic
 160     // we cannot guarantee that no exception will occur.
 161     @Override
 162     public boolean canExplicitlyCastTo(Type t) {
 163         if (equals(t)) {
 164             return true;
 165         }
 166         if (t instanceof TypeKlass && !ProductionParams.disableDowncasts.value()) {




   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.types;
  25 
  26 import java.util.Collection;
  27 import java.util.HashSet;
  28 import java.util.Objects;
  29 import java.util.TreeSet;
  30 import jdk.test.lib.jittester.ProductionParams;
  31 import jdk.test.lib.jittester.Symbol;
  32 import jdk.test.lib.jittester.SymbolTable;
  33 import jdk.test.lib.jittester.Type;
  34 import jdk.test.lib.jittester.TypeList;
  35 
  36 public class TypeKlass extends Type {
  37     private TypeKlass parentKlass;
  38     private final HashSet<String> parentsList;
  39     private final HashSet<String> childrenList;
  40     private final HashSet<Symbol> symbolsSet;
  41     private int flags;
  42 
  43     public static final int NONE = 0x00;
  44     public static final int FINAL = 0x01;
  45     public static final int INTERFACE = 0x02;
  46     public static final int ABSTRACT = 0x04;
  47 
  48 


 108     }
 109 
 110     public HashSet<String> getChildrenNames() {
 111         return childrenList;
 112     }
 113 
 114     @Override
 115     public boolean canCompareTo(Type t) {
 116         return false;
 117     }
 118 
 119     @Override
 120     public boolean canEquateTo(Type t) {
 121         return true;
 122     }
 123 
 124     public TreeSet<TypeKlass> getAllParents() {
 125         TreeSet<TypeKlass> result = new TreeSet<>();
 126         parentsList.stream()
 127                 .map(TypeList::find)
 128                 .filter(Objects::nonNull)
 129                 .map(k -> (TypeKlass) k)
 130                 .forEach(k -> {
 131                     if (result.add(k)) {
 132                         result.addAll(k.getAllParents());
 133                     }
 134         });
 135         return result;
 136     }
 137 
 138     public TreeSet<TypeKlass> getAllChildren() {
 139         TreeSet<TypeKlass> result = new TreeSet<>();
 140         childrenList.stream()
 141                 .map(TypeList::find)
 142                 .filter(Objects::nonNull)
 143                 .map(k -> (TypeKlass) k)
 144                 .forEach(k -> {
 145                     if (result.add(k)) {
 146                         result.addAll(k.getAllChildren());
 147                     }
 148         });
 149         return result;
 150     }
 151 
 152     @Override
 153     public boolean canImplicitlyCastTo(Type t) {
 154         // We can implicitly cast to anything up the hierarchy and to self
 155         if (t instanceof TypeKlass) {
 156             return equals(t) || getAllParents().contains(t);
 157         }
 158         return false;
 159     }
 160 
 161     // If canExplicitlyCastTo() returns true in this case it doesn't mean that
 162     // it would really be successful. Since explicit casts are inherintly dynamic
 163     // we cannot guarantee that no exception will occur.
 164     @Override
 165     public boolean canExplicitlyCastTo(Type t) {
 166         if (equals(t)) {
 167             return true;
 168         }
 169         if (t instanceof TypeKlass && !ProductionParams.disableDowncasts.value()) {


< prev index next >