< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2012, 2015, 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  */


  51 
  52 import java.lang.annotation.Annotation;
  53 import java.lang.reflect.Field;
  54 import java.lang.reflect.Method;
  55 import java.lang.reflect.Modifier;
  56 import java.util.Arrays;
  57 import java.util.Collections;
  58 import java.util.HashMap;
  59 import java.util.HashSet;
  60 import java.util.Map;
  61 import java.util.Set;
  62 
  63 import jdk.vm.ci.common.JVMCIError;
  64 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  65 import jdk.vm.ci.meta.JavaConstant;
  66 import jdk.vm.ci.meta.JavaKind;
  67 import jdk.vm.ci.meta.ModifiersProvider;
  68 import jdk.vm.ci.meta.ResolvedJavaField;
  69 import jdk.vm.ci.meta.ResolvedJavaMethod;
  70 import jdk.vm.ci.meta.ResolvedJavaType;
  71 import jdk.vm.ci.meta.TrustedInterface;
  72 
  73 import org.junit.Test;
  74 
  75 import jdk.internal.reflect.ConstantPool;
  76 
  77 /**
  78  * Tests for {@link ResolvedJavaType}.
  79  */
  80 public class TestResolvedJavaType extends TypeUniverse {
  81 
  82     public TestResolvedJavaType() {
  83     }
  84 
  85     @Test
  86     public void findInstanceFieldWithOffsetTest() {
  87         for (Class<?> c : classes) {
  88             ResolvedJavaType type = metaAccess.lookupJavaType(c);
  89             Set<Field> reflectionFields = getInstanceFields(c, true);
  90             for (Field f : reflectionFields) {
  91                 ResolvedJavaField rf = lookupField(type.getInstanceFields(true), f);


 820     public void getAnnotationTest() {
 821         for (Class<?> c : classes) {
 822             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 823             for (Annotation a : c.getAnnotations()) {
 824                 assertEquals(a, type.getAnnotation(a.annotationType()));
 825             }
 826         }
 827     }
 828 
 829     @Test
 830     public void memberClassesTest() {
 831         for (Class<?> c : classes) {
 832             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 833             assertEquals(c.isLocalClass(), type.isLocal());
 834             assertEquals(c.isMemberClass(), type.isMember());
 835             Class<?> enclc = c.getEnclosingClass();
 836             ResolvedJavaType enclt = type.getEnclosingType();
 837             assertFalse(enclc == null ^ enclt == null);
 838             if (enclc != null) {
 839                 assertEquals(enclt, metaAccess.lookupJavaType(enclc));
 840             }
 841         }
 842     }
 843 
 844     @Test
 845     public void isTrustedInterfaceTypeTest() {
 846         for (Class<?> c : classes) {
 847             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 848             if (TrustedInterface.class.isAssignableFrom(c)) {
 849                 assertTrue(type.isTrustedInterfaceType());
 850             }
 851         }
 852     }
 853 
 854     @Test
 855     public void isLeafTest() {
 856         for (Class<?> c : classes) {
 857             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 858             ResolvedJavaType arrayType = c != void.class ? metaAccess.lookupJavaType(getArrayClass(c)) : null;
 859             if (c.isPrimitive()) {
 860                 assertTrue(type.isLeaf());
 861                 assertTrue(arrayType == null || arrayType.isLeaf());
 862             } else {
 863                 assertTrue(c.toString(), type.isLeaf() == arrayType.isLeaf());
 864                 if (!c.isArray()) {
 865                     assertTrue(c.toString(), type.isLeaf() == Modifier.isFinal(c.getModifiers()));
 866                 }
 867             }
 868         }
 869     }


   1 /*
   2  * Copyright (c) 2012, 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  */


  51 
  52 import java.lang.annotation.Annotation;
  53 import java.lang.reflect.Field;
  54 import java.lang.reflect.Method;
  55 import java.lang.reflect.Modifier;
  56 import java.util.Arrays;
  57 import java.util.Collections;
  58 import java.util.HashMap;
  59 import java.util.HashSet;
  60 import java.util.Map;
  61 import java.util.Set;
  62 
  63 import jdk.vm.ci.common.JVMCIError;
  64 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  65 import jdk.vm.ci.meta.JavaConstant;
  66 import jdk.vm.ci.meta.JavaKind;
  67 import jdk.vm.ci.meta.ModifiersProvider;
  68 import jdk.vm.ci.meta.ResolvedJavaField;
  69 import jdk.vm.ci.meta.ResolvedJavaMethod;
  70 import jdk.vm.ci.meta.ResolvedJavaType;

  71 
  72 import org.junit.Test;
  73 
  74 import jdk.internal.reflect.ConstantPool;
  75 
  76 /**
  77  * Tests for {@link ResolvedJavaType}.
  78  */
  79 public class TestResolvedJavaType extends TypeUniverse {
  80 
  81     public TestResolvedJavaType() {
  82     }
  83 
  84     @Test
  85     public void findInstanceFieldWithOffsetTest() {
  86         for (Class<?> c : classes) {
  87             ResolvedJavaType type = metaAccess.lookupJavaType(c);
  88             Set<Field> reflectionFields = getInstanceFields(c, true);
  89             for (Field f : reflectionFields) {
  90                 ResolvedJavaField rf = lookupField(type.getInstanceFields(true), f);


 819     public void getAnnotationTest() {
 820         for (Class<?> c : classes) {
 821             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 822             for (Annotation a : c.getAnnotations()) {
 823                 assertEquals(a, type.getAnnotation(a.annotationType()));
 824             }
 825         }
 826     }
 827 
 828     @Test
 829     public void memberClassesTest() {
 830         for (Class<?> c : classes) {
 831             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 832             assertEquals(c.isLocalClass(), type.isLocal());
 833             assertEquals(c.isMemberClass(), type.isMember());
 834             Class<?> enclc = c.getEnclosingClass();
 835             ResolvedJavaType enclt = type.getEnclosingType();
 836             assertFalse(enclc == null ^ enclt == null);
 837             if (enclc != null) {
 838                 assertEquals(enclt, metaAccess.lookupJavaType(enclc));










 839             }
 840         }
 841     }
 842 
 843     @Test
 844     public void isLeafTest() {
 845         for (Class<?> c : classes) {
 846             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 847             ResolvedJavaType arrayType = c != void.class ? metaAccess.lookupJavaType(getArrayClass(c)) : null;
 848             if (c.isPrimitive()) {
 849                 assertTrue(type.isLeaf());
 850                 assertTrue(arrayType == null || arrayType.isLeaf());
 851             } else {
 852                 assertTrue(c.toString(), type.isLeaf() == arrayType.isLeaf());
 853                 if (!c.isArray()) {
 854                     assertTrue(c.toString(), type.isLeaf() == Modifier.isFinal(c.getModifiers()));
 855                 }
 856             }
 857         }
 858     }


< prev index next >