< prev index next >

test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TypeUniverse.java

Print this page


   1 /*
   2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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  */


  35 import java.util.ArrayList;
  36 import java.util.Collection;
  37 import java.util.Collections;
  38 import java.util.HashMap;
  39 import java.util.HashSet;
  40 import java.util.IdentityHashMap;
  41 import java.util.LinkedHashMap;
  42 import java.util.LinkedList;
  43 import java.util.List;
  44 import java.util.Map;
  45 import java.util.Queue;
  46 import java.util.Set;
  47 import java.util.TreeMap;
  48 import java.util.stream.Collectors;
  49 
  50 import jdk.vm.ci.meta.ConstantReflectionProvider;
  51 import jdk.vm.ci.meta.JavaConstant;
  52 import jdk.vm.ci.meta.MetaAccessProvider;
  53 import jdk.vm.ci.meta.ResolvedJavaField;
  54 import jdk.vm.ci.meta.ResolvedJavaType;
  55 import jdk.vm.ci.meta.TrustedInterface;
  56 import jdk.vm.ci.runtime.JVMCI;
  57 
  58 import org.junit.Test;
  59 
  60 import jdk.internal.misc.Unsafe;
  61 
  62 //JaCoCo Exclude
  63 
  64 /**
  65  * Context for type related tests.
  66  */
  67 public class TypeUniverse {
  68 
  69     public static final Unsafe unsafe;
  70     public static final double JAVA_VERSION = Double.valueOf(System.getProperty("java.specification.version"));
  71 
  72     public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
  73     public static final ConstantReflectionProvider constantReflection = JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection();
  74     public static final Collection<Class<?>> classes = new HashSet<>();
  75     public static final Set<ResolvedJavaType> javaTypes;


  99 
 100     static {
 101         Unsafe theUnsafe = null;
 102         try {
 103             theUnsafe = Unsafe.getUnsafe();
 104         } catch (Exception e) {
 105             try {
 106                 Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
 107                 theUnsafeField.setAccessible(true);
 108                 theUnsafe = (Unsafe) theUnsafeField.get(null);
 109             } catch (Exception e1) {
 110                 throw (InternalError) new InternalError("unable to initialize unsafe").initCause(e1);
 111             }
 112         }
 113         unsafe = theUnsafe;
 114 
 115         Class<?>[] initialClasses = {void.class, boolean.class, byte.class, short.class, char.class, int.class, float.class, long.class, double.class, Object.class, Class.class, boolean[].class,
 116                         byte[].class, short[].class, char[].class, int[].class, float[].class, long[].class, double[].class, Object[].class, Class[].class, List[].class, boolean[][].class,
 117                         byte[][].class, short[][].class, char[][].class, int[][].class, float[][].class, long[][].class, double[][].class, Object[][].class, Class[][].class, List[][].class,
 118                         ClassLoader.class, String.class, Serializable.class, Cloneable.class, Test.class, TestMetaAccessProvider.class, List.class, Collection.class, Map.class, Queue.class,
 119                         HashMap.class, LinkedHashMap.class, IdentityHashMap.class, AbstractCollection.class, AbstractList.class, ArrayList.class, TrustedInterface.class, InnerClass.class,
 120                         InnerStaticClass.class, InnerStaticFinalClass.class, PrivateInnerClass.class, ProtectedInnerClass.class};
 121         for (Class<?> c : initialClasses) {
 122             addClass(c);
 123         }
 124 
 125         javaTypes = Collections.unmodifiableSet(classes.stream().map(c -> metaAccess.lookupJavaType(c)).collect(Collectors.toSet()));
 126     }
 127 
 128     static class ConstantsUniverse {
 129         static final Object[] ARRAYS = classes.stream().map(c -> c != void.class && !c.isArray() ? Array.newInstance(c, 42) : null).filter(o -> o != null).collect(Collectors.toList()).toArray();
 130         static final Object CONST1 = new ArrayList<>();
 131         static final Object CONST2 = new ArrayList<>();
 132         static final Object CONST3 = new IdentityHashMap<>();
 133         static final Object CONST4 = new LinkedHashMap<>();
 134         static final Object CONST5 = new TreeMap<>();
 135         static final Object CONST6 = new ArrayDeque<>();
 136         static final Object CONST7 = new LinkedList<>();
 137         static final Object CONST8 = "a string";
 138         static final Object CONST9 = 42;
 139         static final Object CONST10 = String.class;
 140         static final Object CONST11 = String[].class;


   1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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  */


  35 import java.util.ArrayList;
  36 import java.util.Collection;
  37 import java.util.Collections;
  38 import java.util.HashMap;
  39 import java.util.HashSet;
  40 import java.util.IdentityHashMap;
  41 import java.util.LinkedHashMap;
  42 import java.util.LinkedList;
  43 import java.util.List;
  44 import java.util.Map;
  45 import java.util.Queue;
  46 import java.util.Set;
  47 import java.util.TreeMap;
  48 import java.util.stream.Collectors;
  49 
  50 import jdk.vm.ci.meta.ConstantReflectionProvider;
  51 import jdk.vm.ci.meta.JavaConstant;
  52 import jdk.vm.ci.meta.MetaAccessProvider;
  53 import jdk.vm.ci.meta.ResolvedJavaField;
  54 import jdk.vm.ci.meta.ResolvedJavaType;

  55 import jdk.vm.ci.runtime.JVMCI;
  56 
  57 import org.junit.Test;
  58 
  59 import jdk.internal.misc.Unsafe;
  60 
  61 //JaCoCo Exclude
  62 
  63 /**
  64  * Context for type related tests.
  65  */
  66 public class TypeUniverse {
  67 
  68     public static final Unsafe unsafe;
  69     public static final double JAVA_VERSION = Double.valueOf(System.getProperty("java.specification.version"));
  70 
  71     public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
  72     public static final ConstantReflectionProvider constantReflection = JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection();
  73     public static final Collection<Class<?>> classes = new HashSet<>();
  74     public static final Set<ResolvedJavaType> javaTypes;


  98 
  99     static {
 100         Unsafe theUnsafe = null;
 101         try {
 102             theUnsafe = Unsafe.getUnsafe();
 103         } catch (Exception e) {
 104             try {
 105                 Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
 106                 theUnsafeField.setAccessible(true);
 107                 theUnsafe = (Unsafe) theUnsafeField.get(null);
 108             } catch (Exception e1) {
 109                 throw (InternalError) new InternalError("unable to initialize unsafe").initCause(e1);
 110             }
 111         }
 112         unsafe = theUnsafe;
 113 
 114         Class<?>[] initialClasses = {void.class, boolean.class, byte.class, short.class, char.class, int.class, float.class, long.class, double.class, Object.class, Class.class, boolean[].class,
 115                         byte[].class, short[].class, char[].class, int[].class, float[].class, long[].class, double[].class, Object[].class, Class[].class, List[].class, boolean[][].class,
 116                         byte[][].class, short[][].class, char[][].class, int[][].class, float[][].class, long[][].class, double[][].class, Object[][].class, Class[][].class, List[][].class,
 117                         ClassLoader.class, String.class, Serializable.class, Cloneable.class, Test.class, TestMetaAccessProvider.class, List.class, Collection.class, Map.class, Queue.class,
 118                         HashMap.class, LinkedHashMap.class, IdentityHashMap.class, AbstractCollection.class, AbstractList.class, ArrayList.class, InnerClass.class, InnerStaticClass.class,
 119                         InnerStaticFinalClass.class, PrivateInnerClass.class, ProtectedInnerClass.class};
 120         for (Class<?> c : initialClasses) {
 121             addClass(c);
 122         }
 123 
 124         javaTypes = Collections.unmodifiableSet(classes.stream().map(c -> metaAccess.lookupJavaType(c)).collect(Collectors.toSet()));
 125     }
 126 
 127     static class ConstantsUniverse {
 128         static final Object[] ARRAYS = classes.stream().map(c -> c != void.class && !c.isArray() ? Array.newInstance(c, 42) : null).filter(o -> o != null).collect(Collectors.toList()).toArray();
 129         static final Object CONST1 = new ArrayList<>();
 130         static final Object CONST2 = new ArrayList<>();
 131         static final Object CONST3 = new IdentityHashMap<>();
 132         static final Object CONST4 = new LinkedHashMap<>();
 133         static final Object CONST5 = new TreeMap<>();
 134         static final Object CONST6 = new ArrayDeque<>();
 135         static final Object CONST7 = new LinkedList<>();
 136         static final Object CONST8 = "a string";
 137         static final Object CONST9 = 42;
 138         static final Object CONST10 = String.class;
 139         static final Object CONST11 = String[].class;


< prev index next >