< prev index next >

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

Print this page




 755         return null;
 756     }
 757 
 758     private static boolean isHiddenFromReflection(ResolvedJavaField f) {
 759         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) {
 760             return true;
 761         }
 762         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) {
 763             return true;
 764         }
 765         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class)) && f.getName().equals("classLoader")) {
 766             return true;
 767         }
 768         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Lookup.class))) {
 769             return f.getName().equals("allowedModes") || f.getName().equals("lookupClass");
 770         }
 771         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ClassLoader.class)) ||
 772             f.getDeclaringClass().equals(metaAccess.lookupJavaType(AccessibleObject.class)) ||
 773             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Constructor.class)) ||
 774             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Field.class)) ||
 775             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Method.class))) {

 776             return true;
 777         }
 778         return false;
 779     }
 780 
 781     @Test
 782     public void getInstanceFieldsTest() {
 783         for (Class<?> c : classes) {
 784             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 785             for (boolean includeSuperclasses : new boolean[]{true, false}) {
 786                 Set<Field> expected = getInstanceFields(c, includeSuperclasses);
 787                 ResolvedJavaField[] actual = type.getInstanceFields(includeSuperclasses);
 788                 for (Field f : expected) {
 789                     assertNotNull(lookupField(actual, f));
 790                 }
 791                 for (ResolvedJavaField rf : actual) {
 792                     if (!isHiddenFromReflection(rf)) {
 793                         assertEquals(rf.toString(), lookupField(expected, rf) != null, !rf.isInternal());
 794                     }
 795                 }




 755         return null;
 756     }
 757 
 758     private static boolean isHiddenFromReflection(ResolvedJavaField f) {
 759         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) {
 760             return true;
 761         }
 762         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) {
 763             return true;
 764         }
 765         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class)) && f.getName().equals("classLoader")) {
 766             return true;
 767         }
 768         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Lookup.class))) {
 769             return f.getName().equals("allowedModes") || f.getName().equals("lookupClass");
 770         }
 771         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ClassLoader.class)) ||
 772             f.getDeclaringClass().equals(metaAccess.lookupJavaType(AccessibleObject.class)) ||
 773             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Constructor.class)) ||
 774             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Field.class)) ||
 775             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Method.class)) ||
 776             f.getDeclaringClass().equals(metaAccess.lookupJavaType(Module.class))) {
 777             return true;
 778         }
 779         return false;
 780     }
 781 
 782     @Test
 783     public void getInstanceFieldsTest() {
 784         for (Class<?> c : classes) {
 785             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 786             for (boolean includeSuperclasses : new boolean[]{true, false}) {
 787                 Set<Field> expected = getInstanceFields(c, includeSuperclasses);
 788                 ResolvedJavaField[] actual = type.getInstanceFields(includeSuperclasses);
 789                 for (Field f : expected) {
 790                     assertNotNull(lookupField(actual, f));
 791                 }
 792                 for (ResolvedJavaField rf : actual) {
 793                     if (!isHiddenFromReflection(rf)) {
 794                         assertEquals(rf.toString(), lookupField(expected, rf) != null, !rf.isInternal());
 795                     }
 796                 }


< prev index next >